blob: 6387b6dc7f508f3db97bb08f522bb9c99618abfb [file] [log] [blame]
sfricke-samsung486a51e2021-01-02 00:10:15 -08001/* Copyright (c) 2015-2021 The Khronos Group Inc.
2 * Copyright (c) 2015-2021 Valve Corporation
3 * Copyright (c) 2015-2021 LunarG, Inc.
4 * Copyright (C) 2015-2021 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
John Zulauf64ffe552021-02-06 10:25:07 -070088std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetSharedAttachmentViews(
89 const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
90 auto get_fn = [this](VkImageView handle) { return this->GetShared<IMAGE_VIEW_STATE>(handle); };
91 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 Gebbenfc6f8152021-03-18 16:58:55 -0600117 ahb_ext_formats_map.emplace(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 Gebbenbc9aacf2021-09-23 11:57:37 -0600175 imageMap[*pImage] = 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) {
179 if (!image) return;
180 IMAGE_STATE *image_state = GetImageState(image);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600181 if (!image_state) return;
182
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600183 image_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600184 imageMap.erase(image);
185}
186
187void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
188 VkImageLayout imageLayout, const VkClearColorValue *pColor,
189 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600190
191 if (disabled[command_buffer_state]) return;
192
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600193 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600194 if (cb_node) {
195 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600196 }
197}
198
199void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
200 VkImageLayout imageLayout,
201 const VkClearDepthStencilValue *pDepthStencil,
202 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600203 if (disabled[command_buffer_state]) return;
204
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600205 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600206 if (cb_node) {
207 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600208 }
209}
210
211void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
212 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
213 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600214 if (disabled[command_buffer_state]) return;
215
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600216 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600217 cb_node->RecordTransferCmd(CMD_COPYIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600218}
219
Jeff Leger178b1e52020-10-05 12:22:23 -0400220void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
221 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600222 if (disabled[command_buffer_state]) return;
223
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600224 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600225 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, GetImageState(pCopyImageInfo->srcImage), GetImageState(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400226}
227
locke-lunargd556cc32019-09-17 01:21:23 -0600228void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
229 VkImageLayout srcImageLayout, VkImage dstImage,
230 VkImageLayout dstImageLayout, uint32_t regionCount,
231 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600232 if (disabled[command_buffer_state]) return;
233
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600234 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600235 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600236}
237
Jeff Leger178b1e52020-10-05 12:22:23 -0400238void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
239 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600240 if (disabled[command_buffer_state]) return;
241
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600242 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600243 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, GetImageState(pResolveImageInfo->srcImage),
244 GetImageState(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400245}
246
locke-lunargd556cc32019-09-17 01:21:23 -0600247void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
248 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
249 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600250 if (disabled[command_buffer_state]) return;
251
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600252 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600253 cb_node->RecordTransferCmd(CMD_BLITIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600254}
255
Jeff Leger178b1e52020-10-05 12:22:23 -0400256void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
257 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600258 if (disabled[command_buffer_state]) return;
259
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600260 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600261 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, GetImageState(pBlitImageInfo->srcImage), GetImageState(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400262}
263
locke-lunargd556cc32019-09-17 01:21:23 -0600264void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
265 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
266 VkResult result) {
267 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600268
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600269 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600270
James Rumble2f6e7bb2021-07-13 15:21:20 +0100271 if (pCreateInfo) {
272 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
273 if (opaque_capture_address) {
274 // address is used for GPU-AV and ray tracing buffer validation
275 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
276 buffer_address_map_.emplace(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
277 }
278 }
Jeremy Gebbencbf22862021-03-03 12:01:22 -0700279 bufferMap.emplace(*pBuffer, std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600280}
281
282void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
283 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
284 VkResult result) {
285 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600286
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500287 auto buffer_state = GetBufferShared(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600288
289 VkFormatProperties format_properties;
290 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
locke-lunarg25b6c352020-08-06 17:44:18 -0600291
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600292 bufferViewMap[*pView] =
293 std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures);
locke-lunargd556cc32019-09-17 01:21:23 -0600294}
295
296void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
297 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
298 VkResult result) {
299 if (result != VK_SUCCESS) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500300 auto image_state = GetImageShared(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700301
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600302 VkFormatFeatureFlags format_features = 0;
303 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700304 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600305 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700306 } else {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600307 format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format,
308 image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700309 }
310
locke-lunarg9939d4b2020-10-26 20:11:08 -0600311 // 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 -0600312 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600313 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700314 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600315 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700316 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600317 image_format_info.type = image_state->createInfo.imageType;
318 image_format_info.format = image_state->createInfo.format;
319 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600320 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
321 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600322 image_format_info.flags = image_state->createInfo.flags;
323
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600324 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600325
326 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
327 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600328
329 imageViewMap[*pView] =
330 std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props);
locke-lunargd556cc32019-09-17 01:21:23 -0600331}
332
333void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
334 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600335 if (disabled[command_buffer_state]) return;
336
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600337 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600338 cb_node->RecordTransferCmd(CMD_COPYBUFFER, GetBufferState(srcBuffer), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600339}
340
Jeff Leger178b1e52020-10-05 12:22:23 -0400341void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600342 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600343 if (disabled[command_buffer_state]) return;
344
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600345 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600346 cb_node->RecordTransferCmd(CMD_COPYBUFFER2KHR, GetBufferState(pCopyBufferInfo->srcBuffer),
347 GetBufferState(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400348}
349
locke-lunargd556cc32019-09-17 01:21:23 -0600350void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
351 const VkAllocationCallbacks *pAllocator) {
352 IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView);
353 if (!image_view_state) return;
locke-lunargd556cc32019-09-17 01:21:23 -0600354
355 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600356 image_view_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600357 imageViewMap.erase(imageView);
358}
359
360void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
361 if (!buffer) return;
362 auto buffer_state = GetBufferState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600363
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600364 buffer_state->Destroy();
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600365 bufferMap.erase(buffer_state->buffer());
locke-lunargd556cc32019-09-17 01:21:23 -0600366}
367
368void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
369 const VkAllocationCallbacks *pAllocator) {
370 if (!bufferView) return;
371 auto buffer_view_state = GetBufferViewState(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600372
373 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600374 buffer_view_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -0600375 bufferViewMap.erase(bufferView);
376}
377
378void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
379 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600380 if (disabled[command_buffer_state]) return;
381
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600382 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600383 cb_node->RecordTransferCmd(CMD_FILLBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600384}
385
386void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
387 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
388 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600389 if (disabled[command_buffer_state]) return;
390
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600391 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600392
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600393 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, GetImageState(srcImage), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600394}
395
Jeff Leger178b1e52020-10-05 12:22:23 -0400396void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
397 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600398 if (disabled[command_buffer_state]) return;
399
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600400 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600401 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, GetImageState(pCopyImageToBufferInfo->srcImage),
402 GetBufferState(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400403}
404
locke-lunargd556cc32019-09-17 01:21:23 -0600405void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
406 VkImageLayout dstImageLayout, uint32_t regionCount,
407 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600408 if (disabled[command_buffer_state]) return;
409
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600410 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600411 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, GetBufferState(srcBuffer), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600412}
413
Jeff Leger178b1e52020-10-05 12:22:23 -0400414void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
415 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600416
417 if (disabled[command_buffer_state]) return;
418
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600419 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600420 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, GetBufferState(pCopyBufferToImageInfo->srcBuffer),
421 GetImageState(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400422}
423
locke-lunargd556cc32019-09-17 01:21:23 -0600424// Return ptr to memory binding for given handle of specified type
425template <typename State, typename Result>
426static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) {
427 switch (typed_handle.type) {
428 case kVulkanObjectTypeImage:
429 return state->GetImageState(typed_handle.Cast<VkImage>());
430 case kVulkanObjectTypeBuffer:
431 return state->GetBufferState(typed_handle.Cast<VkBuffer>());
432 case kVulkanObjectTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -0700433 return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -0600434 default:
435 break;
436 }
437 return nullptr;
438}
439
440const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const {
441 return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle);
442}
443
444BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) {
445 return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle);
446}
447
locke-lunargd556cc32019-09-17 01:21:23 -0600448// For given object struct return a ptr of BASE_NODE type for its wrapping struct
449BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) {
Jeff Bolzadbfa852019-10-04 13:53:30 -0500450 if (object_struct.node) {
451#ifdef _DEBUG
452 // assert that lookup would find the same object
453 VulkanTypedHandle other = object_struct;
454 other.node = nullptr;
455 assert(object_struct.node == GetStateStructPtrFromObject(other));
456#endif
457 return object_struct.node;
458 }
locke-lunargd556cc32019-09-17 01:21:23 -0600459 BASE_NODE *base_ptr = nullptr;
460 switch (object_struct.type) {
461 case kVulkanObjectTypeDescriptorSet: {
462 base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>());
463 break;
464 }
465 case kVulkanObjectTypeSampler: {
466 base_ptr = GetSamplerState(object_struct.Cast<VkSampler>());
467 break;
468 }
469 case kVulkanObjectTypeQueryPool: {
470 base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>());
471 break;
472 }
473 case kVulkanObjectTypePipeline: {
474 base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>());
475 break;
476 }
477 case kVulkanObjectTypeBuffer: {
478 base_ptr = GetBufferState(object_struct.Cast<VkBuffer>());
479 break;
480 }
481 case kVulkanObjectTypeBufferView: {
482 base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>());
483 break;
484 }
485 case kVulkanObjectTypeImage: {
486 base_ptr = GetImageState(object_struct.Cast<VkImage>());
487 break;
488 }
489 case kVulkanObjectTypeImageView: {
490 base_ptr = GetImageViewState(object_struct.Cast<VkImageView>());
491 break;
492 }
493 case kVulkanObjectTypeEvent: {
494 base_ptr = GetEventState(object_struct.Cast<VkEvent>());
495 break;
496 }
497 case kVulkanObjectTypeDescriptorPool: {
498 base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>());
499 break;
500 }
501 case kVulkanObjectTypeCommandPool: {
502 base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>());
503 break;
504 }
505 case kVulkanObjectTypeFramebuffer: {
506 base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>());
507 break;
508 }
509 case kVulkanObjectTypeRenderPass: {
510 base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>());
511 break;
512 }
513 case kVulkanObjectTypeDeviceMemory: {
514 base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>());
515 break;
516 }
517 case kVulkanObjectTypeAccelerationStructureNV: {
sourav parmarcd5fb182020-07-17 12:58:44 -0700518 base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>());
519 break;
520 }
521 case kVulkanObjectTypeAccelerationStructureKHR: {
522 base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>());
locke-lunargd556cc32019-09-17 01:21:23 -0600523 break;
524 }
Jeff Bolzadbfa852019-10-04 13:53:30 -0500525 case kVulkanObjectTypeUnknown:
526 // This can happen if an element of the object_bindings vector has been
527 // zeroed out, after an object is destroyed.
528 break;
locke-lunargd556cc32019-09-17 01:21:23 -0600529 default:
530 // TODO : Any other objects to be handled here?
531 assert(0);
532 break;
533 }
534 return base_ptr;
535}
536
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700537// Gets union of all features defined by Potential Format Features
538// 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 -0700539VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
540 VkFormatFeatureFlags format_features = 0;
541
542 if (format != VK_FORMAT_UNDEFINED) {
543 VkFormatProperties format_properties;
544 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
545 format_features |= format_properties.linearTilingFeatures;
546 format_features |= format_properties.optimalTilingFeatures;
sfricke-samsung45996a42021-09-16 13:45:27 -0700547 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700548 // VK_KHR_get_physical_device_properties2 is required in this case
549 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
550 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
551 nullptr};
552 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100553
554 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700555 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100556
557 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
558 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
559 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
560
561 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
562 // compatible with the queried format
563 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
564
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700565 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
566 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
567 }
568 }
569 }
570
571 return format_features;
572}
573
locke-lunargd556cc32019-09-17 01:21:23 -0600574void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
575 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
576 VkResult result) {
577 if (VK_SUCCESS != result) return;
578
Locke Linf3873542021-04-26 11:25:10 -0600579 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
580 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
581 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
582
locke-lunargd556cc32019-09-17 01:21:23 -0600583 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
584 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700585 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600586 if (features2) {
587 enabled_features_found = &(features2->features);
588 }
589 }
590
locke-lunargd556cc32019-09-17 01:21:23 -0600591 if (nullptr == enabled_features_found) {
592 state_tracker->enabled_features.core = {};
593 } else {
594 state_tracker->enabled_features.core = *enabled_features_found;
595 }
596
locke-lunargd556cc32019-09-17 01:21:23 -0600597 // Save local link to this device's physical device state
Jeremy Gebben383b9a32021-09-08 16:31:33 -0600598 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu);
locke-lunargd556cc32019-09-17 01:21:23 -0600599
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700600 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700601 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700602 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700603 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700604 // Set Extension Feature Aliases to false as there is no struct to check
605 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
606 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
607 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
608 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
609 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
610 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800611 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700612
613 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700614
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700615 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700616 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700617 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
618 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
619 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
620 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700621 }
622
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700623 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700624 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700625 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
626 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700627 }
628
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700629 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700630 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700631 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
632 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
633 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
634 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
635 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
636 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
637 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
638 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
639 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
640 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
641 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
642 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
643 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
644 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
645 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
646 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
647 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
648 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
649 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
650 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
651 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
652 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
653 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
654 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
655 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
656 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
657 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
658 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
659 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
660 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
661 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
662 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
663 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
664 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
665 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
666 descriptor_indexing_features->descriptorBindingPartiallyBound;
667 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
668 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
669 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700670 }
671
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700672 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700673 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700674 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700675 }
676
677 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700678 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700679 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700680 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700681 }
682
683 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700684 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700685 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700686 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
687 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700688 }
689
690 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700691 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700692 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700693 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
694 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700695 }
696
697 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700698 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700699 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700700 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
701 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 }
703
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700704 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700705 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700706 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700707 }
708
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700709 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700710 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700711 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700712 }
713
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700714 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700715 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700716 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
717 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
718 buffer_device_address->bufferDeviceAddressCaptureReplay;
719 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
720 buffer_device_address->bufferDeviceAddressMultiDevice;
721 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800722
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700723 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800724 if (atomic_int64_features) {
725 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
726 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
727 }
728
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700729 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800730 if (memory_model_features) {
731 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
732 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
733 memory_model_features->vulkanMemoryModelDeviceScope;
734 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
735 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
736 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 }
738
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700739 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700740 if (vulkan_11_features) {
741 state_tracker->enabled_features.core11 = *vulkan_11_features;
742 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700743 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700744
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700745 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700746 if (sixteen_bit_storage_features) {
747 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
748 sixteen_bit_storage_features->storageBuffer16BitAccess;
749 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
750 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
751 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
752 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
753 }
754
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700755 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700756 if (multiview_features) {
757 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
758 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
759 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
760 }
761
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700762 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700763 if (variable_pointers_features) {
764 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
765 variable_pointers_features->variablePointersStorageBuffer;
766 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
767 }
768
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700769 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700770 if (protected_memory_features) {
771 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
772 }
773
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700774 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700775 if (ycbcr_conversion_features) {
776 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
777 }
778
779 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700780 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700781 if (shader_draw_parameters_features) {
782 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700783 }
784 }
785
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700786 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600787 if (device_group_ci) {
788 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
789 state_tracker->device_group_create_info = *device_group_ci;
790 } else {
791 state_tracker->physical_device_count = 1;
792 }
locke-lunargd556cc32019-09-17 01:21:23 -0600793
sfricke-samsung828e59d2021-08-22 23:20:49 -0700794 // Features from other extensions passesd in create info
795 {
796 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
797 if (exclusive_scissor_features) {
798 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
799 }
locke-lunargd556cc32019-09-17 01:21:23 -0600800
sfricke-samsung828e59d2021-08-22 23:20:49 -0700801 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
802 if (shading_rate_image_features) {
803 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
804 }
locke-lunargd556cc32019-09-17 01:21:23 -0600805
sfricke-samsung828e59d2021-08-22 23:20:49 -0700806 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
807 if (mesh_shader_features) {
808 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
809 }
locke-lunargd556cc32019-09-17 01:21:23 -0600810
sfricke-samsung828e59d2021-08-22 23:20:49 -0700811 const auto *inline_uniform_block_features =
812 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
813 if (inline_uniform_block_features) {
814 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
815 }
locke-lunargd556cc32019-09-17 01:21:23 -0600816
sfricke-samsung828e59d2021-08-22 23:20:49 -0700817 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
818 if (transform_feedback_features) {
819 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
820 }
locke-lunargd556cc32019-09-17 01:21:23 -0600821
sfricke-samsung828e59d2021-08-22 23:20:49 -0700822 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
823 if (vtx_attrib_div_features) {
824 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
825 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700826
sfricke-samsung828e59d2021-08-22 23:20:49 -0700827 const auto *buffer_device_address_ext_features =
828 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
829 if (buffer_device_address_ext_features) {
830 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
831 }
locke-lunargd556cc32019-09-17 01:21:23 -0600832
sfricke-samsung828e59d2021-08-22 23:20:49 -0700833 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
834 if (cooperative_matrix_features) {
835 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
836 }
locke-lunargd556cc32019-09-17 01:21:23 -0600837
sfricke-samsung828e59d2021-08-22 23:20:49 -0700838 const auto *compute_shader_derivatives_features =
839 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
840 if (compute_shader_derivatives_features) {
841 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
842 }
locke-lunargd556cc32019-09-17 01:21:23 -0600843
sfricke-samsung828e59d2021-08-22 23:20:49 -0700844 const auto *fragment_shader_barycentric_features =
845 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
846 if (fragment_shader_barycentric_features) {
847 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
848 }
locke-lunargd556cc32019-09-17 01:21:23 -0600849
sfricke-samsung828e59d2021-08-22 23:20:49 -0700850 const auto *shader_image_footprint_features =
851 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
852 if (shader_image_footprint_features) {
853 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
854 }
locke-lunargd556cc32019-09-17 01:21:23 -0600855
sfricke-samsung828e59d2021-08-22 23:20:49 -0700856 const auto *fragment_shader_interlock_features =
857 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
858 if (fragment_shader_interlock_features) {
859 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
860 }
locke-lunargd556cc32019-09-17 01:21:23 -0600861
sfricke-samsung828e59d2021-08-22 23:20:49 -0700862 const auto *demote_to_helper_invocation_features =
863 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
864 if (demote_to_helper_invocation_features) {
865 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
866 }
locke-lunargd556cc32019-09-17 01:21:23 -0600867
sfricke-samsung828e59d2021-08-22 23:20:49 -0700868 const auto *texel_buffer_alignment_features =
869 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
870 if (texel_buffer_alignment_features) {
871 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
872 }
locke-lunargd556cc32019-09-17 01:21:23 -0600873
sfricke-samsung828e59d2021-08-22 23:20:49 -0700874 const auto *pipeline_exe_props_features =
875 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
876 if (pipeline_exe_props_features) {
877 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
878 }
locke-lunargd556cc32019-09-17 01:21:23 -0600879
sfricke-samsung828e59d2021-08-22 23:20:49 -0700880 const auto *dedicated_allocation_image_aliasing_features =
881 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
882 if (dedicated_allocation_image_aliasing_features) {
883 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
884 *dedicated_allocation_image_aliasing_features;
885 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500886
sfricke-samsung828e59d2021-08-22 23:20:49 -0700887 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
888 if (performance_query_features) {
889 state_tracker->enabled_features.performance_query_features = *performance_query_features;
890 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100891
sfricke-samsung828e59d2021-08-22 23:20:49 -0700892 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
893 if (device_coherent_memory_features) {
894 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
895 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000896
sfricke-samsung828e59d2021-08-22 23:20:49 -0700897 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
898 if (ycbcr_image_array_features) {
899 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
900 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800901
sfricke-samsung828e59d2021-08-22 23:20:49 -0700902 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
903 if (ray_query_features) {
904 state_tracker->enabled_features.ray_query_features = *ray_query_features;
905 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700906
sfricke-samsung828e59d2021-08-22 23:20:49 -0700907 const auto *ray_tracing_pipeline_features =
908 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
909 if (ray_tracing_pipeline_features) {
910 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
911 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *ray_tracing_acceleration_structure_features =
914 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
915 if (ray_tracing_acceleration_structure_features) {
916 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
917 *ray_tracing_acceleration_structure_features;
918 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500919
sfricke-samsung828e59d2021-08-22 23:20:49 -0700920 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
921 if (robustness2_features) {
922 state_tracker->enabled_features.robustness2_features = *robustness2_features;
923 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500924
sfricke-samsung828e59d2021-08-22 23:20:49 -0700925 const auto *fragment_density_map_features =
926 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
927 if (fragment_density_map_features) {
928 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
929 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200930
sfricke-samsung828e59d2021-08-22 23:20:49 -0700931 const auto *fragment_density_map_features2 =
932 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
933 if (fragment_density_map_features2) {
934 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
935 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200936
sfricke-samsung828e59d2021-08-22 23:20:49 -0700937 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
938 if (astc_decode_features) {
939 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
940 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -0700941
sfricke-samsung828e59d2021-08-22 23:20:49 -0700942 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
943 if (custom_border_color_features) {
944 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
945 }
Tony-LunarG7337b312020-04-15 16:40:25 -0600946
sfricke-samsung828e59d2021-08-22 23:20:49 -0700947 const auto *pipeline_creation_cache_control_features =
948 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
949 if (pipeline_creation_cache_control_features) {
950 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
951 }
sfricke-samsungfd661d62020-05-16 00:57:27 -0700952
sfricke-samsung828e59d2021-08-22 23:20:49 -0700953 const auto *fragment_shading_rate_features =
954 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
955 if (fragment_shading_rate_features) {
956 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
957 }
Tobias Hector6663c9b2020-11-05 10:18:02 +0000958
sfricke-samsung828e59d2021-08-22 23:20:49 -0700959 const auto *extended_dynamic_state_features =
960 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
961 if (extended_dynamic_state_features) {
962 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
963 }
Piers Daniell39842ee2020-07-10 16:42:33 -0600964
sfricke-samsung828e59d2021-08-22 23:20:49 -0700965 const auto *extended_dynamic_state2_features =
966 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
967 if (extended_dynamic_state2_features) {
968 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
969 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -0700970
sfricke-samsung828e59d2021-08-22 23:20:49 -0700971 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
972 if (multiview_features) {
973 state_tracker->enabled_features.multiview_features = *multiview_features;
974 }
locke-lunarg3fa463a2020-10-23 16:39:04 -0600975
sfricke-samsung828e59d2021-08-22 23:20:49 -0700976 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
977 if (portability_features) {
978 state_tracker->enabled_features.portability_subset_features = *portability_features;
979 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -0700980
sfricke-samsung828e59d2021-08-22 23:20:49 -0700981 const auto *shader_integer_functions2_features =
982 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
983 if (shader_integer_functions2_features) {
984 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
985 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800986
sfricke-samsung828e59d2021-08-22 23:20:49 -0700987 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
988 if (shader_sm_builtins_features) {
989 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
990 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800991
sfricke-samsung828e59d2021-08-22 23:20:49 -0700992 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
993 if (shader_atomic_float_features) {
994 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
995 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800996
sfricke-samsung828e59d2021-08-22 23:20:49 -0700997 const auto *shader_image_atomic_int64_features =
998 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
999 if (shader_image_atomic_int64_features) {
1000 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1001 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001002
sfricke-samsung828e59d2021-08-22 23:20:49 -07001003 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1004 if (shader_clock_features) {
1005 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1006 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *conditional_rendering_features =
1009 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1010 if (conditional_rendering_features) {
1011 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1012 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001013
sfricke-samsung828e59d2021-08-22 23:20:49 -07001014 const auto *workgroup_memory_explicit_layout_features =
1015 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1016 if (workgroup_memory_explicit_layout_features) {
1017 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1018 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001019
sfricke-samsung828e59d2021-08-22 23:20:49 -07001020 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
1021 if (synchronization2_features) {
1022 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
1023 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001024
sfricke-samsung828e59d2021-08-22 23:20:49 -07001025 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1026 if (provoking_vertex_features) {
1027 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1028 }
Locke Linf3873542021-04-26 11:25:10 -06001029
sfricke-samsung828e59d2021-08-22 23:20:49 -07001030 const auto *vertex_input_dynamic_state_features =
1031 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1032 if (vertex_input_dynamic_state_features) {
1033 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1034 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001035
sfricke-samsung828e59d2021-08-22 23:20:49 -07001036 const auto *inherited_viewport_scissor_features =
1037 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1038 if (inherited_viewport_scissor_features) {
1039 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1040 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001041
sfricke-samsung828e59d2021-08-22 23:20:49 -07001042 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1043 if (multi_draw_features) {
1044 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1045 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001046
sfricke-samsung828e59d2021-08-22 23:20:49 -07001047 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1048 if (color_write_features) {
1049 state_tracker->enabled_features.color_write_features = *color_write_features;
1050 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001051
sfricke-samsung828e59d2021-08-22 23:20:49 -07001052 const auto *shader_atomic_float2_features =
1053 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1054 if (shader_atomic_float2_features) {
1055 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1056 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001057
sfricke-samsung828e59d2021-08-22 23:20:49 -07001058 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1059 if (present_id_features) {
1060 state_tracker->enabled_features.present_id_features = *present_id_features;
1061 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1064 if (present_wait_features) {
1065 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1066 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001067
1068 const auto *ray_tracing_motion_blur_features =
1069 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1070 if (ray_tracing_motion_blur_features) {
1071 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1072 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001073
1074 const auto *shader_integer_dot_product_features =
1075 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
1076 if (shader_integer_dot_product_features) {
1077 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
1078 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001079
1080 const auto *primitive_topology_list_restart_features =
1081 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1082 if (primitive_topology_list_restart_features) {
1083 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1084 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -07001085
1086 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
1087 if (rgba10x6_formats_features) {
1088 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
1089 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -07001090
1091 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
1092 if (maintenance4_features) {
1093 state_tracker->enabled_features.maintenance4_features = *maintenance4_features;
1094 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001095 }
1096
ziga-lunarg73163742021-08-25 13:15:29 +02001097 const auto *subgroup_size_control_features = LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeaturesEXT>(pCreateInfo->pNext);
1098 if (subgroup_size_control_features) {
1099 state_tracker->enabled_features.subgroup_size_control_features = *subgroup_size_control_features;
1100 }
1101
locke-lunargd556cc32019-09-17 01:21:23 -06001102 // Store physical device properties and physical device mem limits into CoreChecks structs
1103 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1104 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1105
1106 const auto &dev_ext = state_tracker->device_extensions;
1107 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1108
sfricke-samsung828e59d2021-08-22 23:20:49 -07001109 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
sfricke-samsung45996a42021-09-16 13:45:27 -07001110 if (dev_ext.vk_feature_version_1_2) {
1111 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1112 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001113 } else {
1114 // VkPhysicalDeviceVulkan11Properties
1115 //
1116 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1117
1118 if (dev_ext.vk_khr_multiview) {
1119 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1120 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1121 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1122 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1123 }
1124
1125 if (dev_ext.vk_khr_maintenance3) {
1126 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1127 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1128 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1129 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1130 }
1131
1132 // Some 1.1 properties were added to core without previous extensions
1133 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1134 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1135 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1136 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1137 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1138
1139 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1140 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1141 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1142 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1143
1144 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1145 }
1146
1147 // VkPhysicalDeviceVulkan12Properties
1148 //
1149 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1150
1151 if (dev_ext.vk_ext_descriptor_indexing) {
1152 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1153 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1154 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1155 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1156 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1157 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1158 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1159 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1160 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1161 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1162 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1163 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1164 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1165 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1166 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1167 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1168 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1169 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1170 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1171 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1172 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1173 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1174 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1175 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1176 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1177 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1178 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1179 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1180 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1181 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1182 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1183 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1184 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1185 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1186 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1187 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1188 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1189 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1190 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1191 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1192 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1193 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1194 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1195 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1196 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1197 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1198 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1199 }
1200
1201 if (dev_ext.vk_khr_depth_stencil_resolve) {
1202 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1203 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1204 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1205 depth_stencil_resolve_props.supportedDepthResolveModes;
1206 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1207 depth_stencil_resolve_props.supportedStencilResolveModes;
1208 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1209 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1210 }
1211
1212 if (dev_ext.vk_khr_timeline_semaphore) {
1213 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1214 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1215 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1216 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1217 }
1218
1219 if (dev_ext.vk_ext_sampler_filter_minmax) {
1220 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1221 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1222 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1223 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1224 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1225 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1226 }
1227
1228 if (dev_ext.vk_khr_shader_float_controls) {
1229 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1230 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1231 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1232 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1233 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1234 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1235 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1236 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1237 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1238 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1239 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1240 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1241 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1242 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1243 float_controls_props.shaderDenormFlushToZeroFloat16;
1244 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1245 float_controls_props.shaderDenormFlushToZeroFloat32;
1246 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1247 float_controls_props.shaderDenormFlushToZeroFloat64;
1248 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1249 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1250 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1251 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1252 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1253 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1254 }
locke-lunargd556cc32019-09-17 01:21:23 -06001255 }
1256
sfricke-samsung828e59d2021-08-22 23:20:49 -07001257 // Extensions with properties to extract to DeviceExtensionProperties
1258 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001259 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1260 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1261 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1262 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001263 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001264 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001265 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1266 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001267 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1268 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001269 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001270 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001271 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001272 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001273 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001274 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001275 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001276 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001277 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001278 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001279 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001280 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001281 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001282
sfricke-samsung45996a42021-09-16 13:45:27 -07001283 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001284 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001285 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1286 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001287 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1288 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1289
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001290 uint32_t num_cooperative_matrix_properties = 0;
1291 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1292 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001293 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001294
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001295 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001296 state_tracker->cooperative_matrix_properties.data());
1297 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001298
locke-lunargd556cc32019-09-17 01:21:23 -06001299 // Store queue family data
1300 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001301 uint32_t total_count = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001302 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001303 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001304 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1305 state_tracker->device_queue_info_list.push_back(
1306 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001307 total_count += queue_create_info.queueCount;
1308 }
1309 queueMap.reserve(total_count);
1310 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1311 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1312 VkQueue queue = VK_NULL_HANDLE;
1313 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1314 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1315 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1316 get_info.flags = queue_info.flags;
1317 get_info.queueFamilyIndex = queue_info.queue_family_index;
1318 get_info.queueIndex = i;
1319 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1320 } else {
1321 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1322 }
1323 assert(queue != VK_NULL_HANDLE);
1324 state_tracker->queueMap.emplace(queue, std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index));
1325 }
locke-lunargd556cc32019-09-17 01:21:23 -06001326 }
1327 }
1328}
1329
1330void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1331 if (!device) return;
1332
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001333 commandPoolMap.clear();
1334 assert(commandBufferMap.empty());
Jeff Bolzadbfa852019-10-04 13:53:30 -05001335 pipelineMap.clear();
1336 renderPassMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001337
1338 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06001339 descriptorPoolMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001340 // All sets should be removed
1341 assert(setMap.empty());
1342 descriptorSetLayoutMap.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001343 // Because swapchains are associated with Surfaces, which are at instance level,
1344 // they need to be explicitly destroyed here to avoid continued references to
1345 // the device we're destroying.
1346 for (auto &entry : swapchainMap) {
1347 entry.second->Destroy();
1348 }
1349 swapchainMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001350 imageViewMap.clear();
1351 imageMap.clear();
1352 bufferViewMap.clear();
1353 bufferMap.clear();
1354 // Queues persist until device is destroyed
1355 queueMap.clear();
1356}
1357
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001358void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1359 VkFence fence, VkResult result) {
1360 if (result != VK_SUCCESS) return;
1361 auto queue_state = GetQueueState(queue);
1362
Jeremy Gebben57642982021-09-14 14:14:55 -06001363 uint64_t early_retire_seq = 0;
1364
1365 if (submitCount == 0) {
1366 CB_SUBMISSION submission;
1367 submission.AddFence(GetShared<FENCE_STATE>(fence));
1368 early_retire_seq = queue_state->Submit(std::move(submission));
1369 }
locke-lunargd556cc32019-09-17 01:21:23 -06001370
1371 // Now process each individual submit
1372 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001373 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001374 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001375 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001376 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001377 uint64_t value = 0;
1378 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1379 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1380 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1381 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001382 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001383 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001384
locke-lunargd556cc32019-09-17 01:21:23 -06001385 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001386 uint64_t value = 0;
1387 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1388 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1389 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1390 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001391 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001392 }
1393
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001394 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001395 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001396
locke-lunargd556cc32019-09-17 01:21:23 -06001397 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001398 submission.AddCommandBuffer(GetShared<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001399 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001400 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
1401 submission.AddFence(GetShared<FENCE_STATE>(fence));
1402 }
1403 auto submit_seq = queue_state->Submit(std::move(submission));
1404 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001405 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001406
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001407 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001408 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001409 }
1410}
1411
1412void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1413 VkFence fence, VkResult result) {
1414 if (result != VK_SUCCESS) return;
1415 auto queue_state = GetQueueState(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001416 uint64_t early_retire_seq = 0;
1417 if (submitCount == 0) {
1418 CB_SUBMISSION submission;
1419 submission.AddFence(GetShared<FENCE_STATE>(fence));
1420 early_retire_seq = queue_state->Submit(std::move(submission));
1421 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001422
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001423 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1424 CB_SUBMISSION submission;
1425 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001426 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1427 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben57642982021-09-14 14:14:55 -06001428 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001429 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001430 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1431 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben57642982021-09-14 14:14:55 -06001432 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001433 }
1434 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1435 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1436
1437 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001438 submission.AddCommandBuffer(GetShared<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001439 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001440 if (submit_idx == (submitCount - 1)) {
1441 submission.AddFence(GetShared<FENCE_STATE>(fence));
1442 }
1443 auto submit_seq = queue_state->Submit(std::move(submission));
1444 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001445 }
locke-lunargd556cc32019-09-17 01:21:23 -06001446 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001447 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001448 }
1449}
1450
1451void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1452 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1453 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001454 if (VK_SUCCESS != result) {
1455 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001456 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001457 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1458 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1459 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1460
1461 layer_data::optional<DedicatedBinding> dedicated_binding;
1462
1463 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1464 if (dedicated) {
1465 if (dedicated->buffer) {
1466 const auto *buffer_state = GetBufferState(dedicated->buffer);
1467 assert(buffer_state);
1468 if (!buffer_state) {
1469 return;
1470 }
1471 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1472 } else if (dedicated->image) {
1473 const auto *image_state = GetImageState(dedicated->image);
1474 assert(image_state);
1475 if (!image_state) {
1476 return;
1477 }
1478 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1479 }
1480 }
1481 memObjMap[*pMemory] = std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
ziga-lunarg9663f4f2021-09-30 17:24:01 +02001482 std::move(dedicated_binding), physical_device_count);
locke-lunargd556cc32019-09-17 01:21:23 -06001483 return;
1484}
1485
1486void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
1487 if (!mem) return;
1488 DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001489 if (!mem_info) return;
locke-lunargd556cc32019-09-17 01:21:23 -06001490 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001491 mem_info->Destroy();
John Zulauf79952712020-04-07 11:25:54 -06001492 fake_memory.Free(mem_info->fake_base_address);
locke-lunargd556cc32019-09-17 01:21:23 -06001493 memObjMap.erase(mem);
1494}
1495
1496void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1497 VkFence fence, VkResult result) {
1498 if (result != VK_SUCCESS) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001499 auto queue_state = GetQueueState(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001500
Jeremy Gebben57642982021-09-14 14:14:55 -06001501 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001502
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001503 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1504 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001505 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001506 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1507 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1508 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001509 auto buffer_state = GetBufferState(bind_info.pBufferBinds[j].buffer);
1510 auto mem_state = GetDevMemShared(sparse_binding.memory);
1511 if (buffer_state && mem_state) {
1512 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1513 }
locke-lunargd556cc32019-09-17 01:21:23 -06001514 }
1515 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001516 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1517 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1518 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001519 auto image_state = GetImageState(bind_info.pImageOpaqueBinds[j].image);
1520 auto mem_state = GetDevMemShared(sparse_binding.memory);
1521 if (image_state && mem_state) {
1522 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1523 }
locke-lunargd556cc32019-09-17 01:21:23 -06001524 }
1525 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001526 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1527 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1528 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001529 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1530 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001531 auto image_state = GetImageState(bind_info.pImageBinds[j].image);
1532 auto mem_state = GetDevMemShared(sparse_binding.memory);
1533 if (image_state && mem_state) {
1534 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1535 }
locke-lunargd556cc32019-09-17 01:21:23 -06001536 }
1537 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001538 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001539 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001540 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001541 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001542 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001543 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001544 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001545 if (bind_idx == (bindInfoCount - 1)) {
1546 submission.AddFence(GetShared<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001547 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001548 auto submit_seq = queue_state->Submit(std::move(submission));
1549 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001550 }
1551
1552 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001553 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001554 }
1555}
1556
1557void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1558 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1559 VkResult result) {
1560 if (VK_SUCCESS != result) return;
Jeremy Gebben57642982021-09-14 14:14:55 -06001561 semaphoreMap[*pSemaphore] =
1562 std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext));
locke-lunargd556cc32019-09-17 01:21:23 -06001563}
1564
Mike Schuchardt2df08912020-12-15 16:28:09 -08001565void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1566 VkSemaphoreImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06001567 SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore);
1568 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001569 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06001570 sema_node->scope == kSyncScopeInternal) {
1571 sema_node->scope = kSyncScopeExternalTemporary;
1572 } else {
1573 sema_node->scope = kSyncScopeExternalPermanent;
1574 }
1575 }
1576}
1577
Mike Schuchardt2df08912020-12-15 16:28:09 -08001578void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001579 VkResult result) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001580 auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore);
1581 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001582}
1583
locke-lunargd556cc32019-09-17 01:21:23 -06001584void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
1585 auto mem_info = GetDevMemState(mem);
1586 if (mem_info) {
1587 mem_info->mapped_range.offset = offset;
1588 mem_info->mapped_range.size = size;
1589 mem_info->p_driver_data = *ppData;
1590 }
1591}
1592
locke-lunargd556cc32019-09-17 01:21:23 -06001593void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1594 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1595 if (VK_SUCCESS != result) return;
1596
1597 // When we know that all fences are complete we can clean/remove their CBs
1598 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1599 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001600 auto fence_state = GetFenceState(pFences[i]);
1601 if (fence_state) {
1602 fence_state->Retire();
1603 }
locke-lunargd556cc32019-09-17 01:21:23 -06001604 }
1605 }
1606 // NOTE : Alternate case not handled here is when some fences have completed. In
1607 // this case for app to guarantee which fences completed it will have to call
1608 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1609}
1610
John Zulauff89de662020-04-13 18:57:34 -06001611void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1612 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001613 if (VK_SUCCESS != result) return;
1614
1615 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001616 auto semaphore_state = GetSemaphoreState(pWaitInfo->pSemaphores[i]);
1617 if (semaphore_state) {
1618 semaphore_state->Retire(pWaitInfo->pValues[i]);
1619 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001620 }
1621}
1622
John Zulauff89de662020-04-13 18:57:34 -06001623void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1624 VkResult result) {
1625 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1626}
1627
1628void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1629 uint64_t timeout, VkResult result) {
1630 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1631}
1632
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001633void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1634 VkResult result) {
1635 if (VK_SUCCESS != result) return;
1636
Jeremy Gebben57642982021-09-14 14:14:55 -06001637 auto semaphore_state = GetSemaphoreState(semaphore);
1638 if (semaphore_state) {
1639 semaphore_state->Retire(*pValue);
1640 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001641}
1642
1643void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1644 VkResult result) {
1645 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1646}
1647void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1648 VkResult result) {
1649 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1650}
1651
locke-lunargd556cc32019-09-17 01:21:23 -06001652void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1653 if (VK_SUCCESS != result) return;
Jeremy Gebben57642982021-09-14 14:14:55 -06001654 auto fence_state = GetFenceState(fence);
1655 if (fence_state) {
1656 fence_state->Retire();
1657 }
locke-lunargd556cc32019-09-17 01:21:23 -06001658}
1659
locke-lunargd556cc32019-09-17 01:21:23 -06001660void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1661 if (VK_SUCCESS != result) return;
1662 QUEUE_STATE *queue_state = GetQueueState(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001663 if (queue_state) {
1664 queue_state->Retire();
1665 }
locke-lunargd556cc32019-09-17 01:21:23 -06001666}
1667
1668void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1669 if (VK_SUCCESS != result) return;
1670 for (auto &queue : queueMap) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001671 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001672 }
1673}
1674
1675void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
1676 if (!fence) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001677 auto fence_state = GetFenceState(fence);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001678 fence_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001679 fenceMap.erase(fence);
1680}
1681
1682void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1683 const VkAllocationCallbacks *pAllocator) {
1684 if (!semaphore) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001685 auto semaphore_state = GetSemaphoreState(semaphore);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001686 semaphore_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001687 semaphoreMap.erase(semaphore);
1688}
1689
1690void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
1691 if (!event) return;
John Zulauf48057322020-12-02 11:59:31 -07001692 EVENT_STATE *event_state = Get<EVENT_STATE>(event);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001693 event_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001694 eventMap.erase(event);
1695}
1696
1697void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1698 const VkAllocationCallbacks *pAllocator) {
1699 if (!queryPool) return;
1700 QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001701 qp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001702 queryPoolMap.erase(queryPool);
1703}
1704
locke-lunargd556cc32019-09-17 01:21:23 -06001705void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
1706 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1707 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001708 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001709 auto mem_state = GetDevMemShared(mem);
1710 if (mem_state) {
1711 buffer_state->SetMemBinding(mem_state, memoryOffset);
1712 }
locke-lunargd556cc32019-09-17 01:21:23 -06001713 }
1714}
1715
1716void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1717 VkDeviceSize memoryOffset, VkResult result) {
1718 if (VK_SUCCESS != result) return;
1719 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1720}
1721
1722void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001723 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001724 for (uint32_t i = 0; i < bindInfoCount; i++) {
1725 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1726 }
1727}
1728
1729void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001730 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001731 for (uint32_t i = 0; i < bindInfoCount; i++) {
1732 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1733 }
1734}
1735
Spencer Fricke6c127102020-04-16 06:25:20 -07001736void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
locke-lunargd556cc32019-09-17 01:21:23 -06001737 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1738 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001739 buffer_state->memory_requirements_checked = true;
1740 }
1741}
1742
1743void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1744 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001745 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001746}
1747
1748void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001749 const VkBufferMemoryRequirementsInfo2 *pInfo,
1750 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001751 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001752}
1753
1754void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001755 const VkBufferMemoryRequirementsInfo2 *pInfo,
1756 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001757 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001758}
1759
Spencer Fricke6c127102020-04-16 06:25:20 -07001760void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001761 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001762 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001763 IMAGE_STATE *image_state = GetImageState(image);
1764 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001765 if (plane_info != nullptr) {
1766 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001767 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001768 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001769 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001770 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001771 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001772 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001773 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001774 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001775 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001776 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001777 }
locke-lunargd556cc32019-09-17 01:21:23 -06001778 }
1779}
1780
1781void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1782 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001783 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001784}
1785
1786void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1787 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001788 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001789}
1790
1791void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1792 const VkImageMemoryRequirementsInfo2 *pInfo,
1793 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001794 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001795}
1796
locke-lunargd556cc32019-09-17 01:21:23 -06001797void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1798 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1799 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
1800 auto image_state = GetImageState(image);
1801 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001802}
1803
1804void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001805 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1806 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06001807 auto image_state = GetImageState(pInfo->image);
1808 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001809}
1810
1811void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001812 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1813 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06001814 auto image_state = GetImageState(pInfo->image);
1815 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001816}
1817
1818void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1819 const VkAllocationCallbacks *pAllocator) {
1820 if (!shaderModule) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001821 auto shader_module_state = GetShaderModuleState(shaderModule);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001822 shader_module_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001823 shaderModuleMap.erase(shaderModule);
1824}
1825
1826void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1827 const VkAllocationCallbacks *pAllocator) {
1828 if (!pipeline) return;
1829 PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001830 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001831 pipeline_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001832 pipelineMap.erase(pipeline);
1833}
1834
1835void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1836 const VkAllocationCallbacks *pAllocator) {
1837 if (!pipelineLayout) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001838 auto pipeline_layout_state = GetPipelineLayout(pipelineLayout);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001839 pipeline_layout_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001840 pipelineLayoutMap.erase(pipelineLayout);
1841}
1842
1843void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1844 const VkAllocationCallbacks *pAllocator) {
1845 if (!sampler) return;
1846 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001847 // Any bound cmd buffers are now invalid
1848 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001849 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1850 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1851 custom_border_color_sampler_count--;
1852 }
1853
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001854 sampler_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001855 }
1856 samplerMap.erase(sampler);
1857}
1858
1859void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1860 const VkAllocationCallbacks *pAllocator) {
1861 if (!descriptorSetLayout) return;
1862 auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout);
1863 if (layout_it != descriptorSetLayoutMap.end()) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001864 layout_it->second.get()->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001865 descriptorSetLayoutMap.erase(layout_it);
1866 }
1867}
1868
1869void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1870 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06001871 auto *desc_pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001872 if (desc_pool_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001873 desc_pool_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001874 descriptorPoolMap.erase(descriptorPool);
1875 }
1876}
1877
locke-lunargd556cc32019-09-17 01:21:23 -06001878void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1879 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001880 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1881 if (pool) {
1882 pool->Free(commandBufferCount, pCommandBuffers);
1883 }
locke-lunargd556cc32019-09-17 01:21:23 -06001884}
1885
1886void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1887 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1888 VkResult result) {
1889 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001890 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001891 commandPoolMap[*pCommandPool] = std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags);
locke-lunargd556cc32019-09-17 01:21:23 -06001892}
1893
1894void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1895 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1896 VkResult result) {
1897 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001898
1899 uint32_t index_count = 0, n_perf_pass = 0;
1900 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001901 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001902 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001903 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001904
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001905 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001906 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1907 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1908 switch (counter.scope) {
1909 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001910 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001911 break;
1912 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001913 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001914 break;
1915 default:
1916 break;
1917 }
1918 }
1919
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001920 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001921 }
1922
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001923 queryPoolMap[*pQueryPool] =
1924 std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb);
locke-lunargd556cc32019-09-17 01:21:23 -06001925
1926 QueryObject query_obj{*pQueryPool, 0u};
1927 for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) {
1928 query_obj.query = i;
1929 queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN;
1930 }
1931}
1932
1933void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1934 const VkAllocationCallbacks *pAllocator) {
1935 if (!commandPool) return;
1936 COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool);
1937 // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers
1938 // "When a pool is destroyed, all command buffers allocated from the pool are freed."
1939 if (cp_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001940 cp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001941 commandPoolMap.erase(commandPool);
1942 }
1943}
1944
1945void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
1946 VkCommandPoolResetFlags flags, VkResult result) {
1947 if (VK_SUCCESS != result) return;
1948 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001949 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1950 if (pool) {
1951 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001952 }
1953}
1954
1955void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1956 VkResult result) {
1957 for (uint32_t i = 0; i < fenceCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001958 auto fence_state = GetFenceState(pFences[i]);
1959 if (fence_state) {
1960 if (fence_state->scope == kSyncScopeInternal) {
1961 fence_state->state = FENCE_UNSIGNALED;
1962 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
1963 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06001964 }
1965 }
1966 }
1967}
1968
locke-lunargd556cc32019-09-17 01:21:23 -06001969void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
1970 const VkAllocationCallbacks *pAllocator) {
1971 if (!framebuffer) return;
1972 FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001973 framebuffer_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001974 frameBufferMap.erase(framebuffer);
1975}
1976
1977void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
1978 const VkAllocationCallbacks *pAllocator) {
1979 if (!renderPass) return;
1980 RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001981 rp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001982 renderPassMap.erase(renderPass);
1983}
1984
1985void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
1986 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
1987 if (VK_SUCCESS != result) return;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001988 fenceMap[*pFence] = std::make_shared<FENCE_STATE>(*pFence, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001989}
1990
1991bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1992 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1993 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001994 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001995 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
1996 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1997 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1998 cgpl_state->pipe_state.reserve(count);
1999 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002000 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2001 GetRenderPassShared(pCreateInfos[i].renderPass),
2002 GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002003 }
2004 return false;
2005}
2006
2007void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2008 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2009 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2010 VkResult result, void *cgpl_state_data) {
2011 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2012 // This API may create pipelines regardless of the return value
2013 for (uint32_t i = 0; i < count; i++) {
2014 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002015 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002016 pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]);
2017 }
2018 }
2019 cgpl_state->pipe_state.clear();
2020}
2021
2022bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2023 const VkComputePipelineCreateInfo *pCreateInfos,
2024 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002025 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002026 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2027 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2028 ccpl_state->pipe_state.reserve(count);
2029 for (uint32_t i = 0; i < count; i++) {
2030 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002031 ccpl_state->pipe_state.push_back(
2032 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002033 }
2034 return false;
2035}
2036
2037void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2038 const VkComputePipelineCreateInfo *pCreateInfos,
2039 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2040 VkResult result, void *ccpl_state_data) {
2041 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2042
2043 // This API may create pipelines regardless of the return value
2044 for (uint32_t i = 0; i < count; i++) {
2045 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002046 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002047 pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]);
2048 }
2049 }
2050 ccpl_state->pipe_state.clear();
2051}
2052
2053bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2054 uint32_t count,
2055 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2056 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002057 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002058 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2059 crtpl_state->pipe_state.reserve(count);
2060 for (uint32_t i = 0; i < count; i++) {
2061 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002062 crtpl_state->pipe_state.push_back(
2063 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002064 }
2065 return false;
2066}
2067
2068void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2069 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2070 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2071 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2072 // This API may create pipelines regardless of the return value
2073 for (uint32_t i = 0; i < count; i++) {
2074 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002075 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002076 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2077 }
2078 }
2079 crtpl_state->pipe_state.clear();
2080}
2081
sourav parmarcd5fb182020-07-17 12:58:44 -07002082bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2083 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002084 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2085 const VkAllocationCallbacks *pAllocator,
2086 VkPipeline *pPipelines, void *crtpl_state_data) const {
2087 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2088 crtpl_state->pipe_state.reserve(count);
2089 for (uint32_t i = 0; i < count; i++) {
2090 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002091 crtpl_state->pipe_state.push_back(
2092 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002093 }
2094 return false;
2095}
2096
sourav parmarcd5fb182020-07-17 12:58:44 -07002097void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2098 VkPipelineCache pipelineCache, uint32_t count,
2099 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2100 const VkAllocationCallbacks *pAllocator,
2101 VkPipeline *pPipelines, VkResult result,
2102 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002103 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2104 // This API may create pipelines regardless of the return value
2105 for (uint32_t i = 0; i < count; i++) {
2106 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002107 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002108 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2109 }
2110 }
2111 crtpl_state->pipe_state.clear();
2112}
2113
locke-lunargd556cc32019-09-17 01:21:23 -06002114void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2115 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2116 VkResult result) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002117 samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002118 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2119 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002120 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002121 }
locke-lunargd556cc32019-09-17 01:21:23 -06002122}
2123
2124void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2125 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2126 const VkAllocationCallbacks *pAllocator,
2127 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2128 if (VK_SUCCESS != result) return;
2129 descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout);
2130}
2131
locke-lunargd556cc32019-09-17 01:21:23 -06002132void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2133 const VkAllocationCallbacks *pAllocator,
2134 VkPipelineLayout *pPipelineLayout, VkResult result) {
2135 if (VK_SUCCESS != result) return;
2136
Jeremy Gebbene6e45542021-08-05 16:39:49 -06002137 pipelineLayoutMap[*pPipelineLayout] = std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002138}
2139
2140void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2141 const VkAllocationCallbacks *pAllocator,
2142 VkDescriptorPool *pDescriptorPool, VkResult result) {
2143 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002144 descriptorPoolMap.emplace(*pDescriptorPool, std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002145}
2146
2147void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2148 VkDescriptorPoolResetFlags flags, VkResult result) {
2149 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002150 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2151 if (pool) {
2152 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002153 }
locke-lunargd556cc32019-09-17 01:21:23 -06002154}
2155
2156bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2157 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002158 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002159 // Always update common data
2160 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2161 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2162 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2163
2164 return false;
2165}
2166
2167// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2168void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2169 VkDescriptorSet *pDescriptorSets, VkResult result,
2170 void *ads_state_data) {
2171 if (VK_SUCCESS != result) return;
2172 // All the updates are contained in a single cvdescriptorset function
2173 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2174 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002175 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2176 if (pool_state) {
2177 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2178 }
locke-lunargd556cc32019-09-17 01:21:23 -06002179}
2180
2181void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2182 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002183 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2184 if (pool_state) {
2185 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002186 }
2187}
2188
2189void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2190 const VkWriteDescriptorSet *pDescriptorWrites,
2191 uint32_t descriptorCopyCount,
2192 const VkCopyDescriptorSet *pDescriptorCopies) {
2193 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2194 pDescriptorCopies);
2195}
2196
2197void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002198 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002199 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002200 auto pool = GetCommandPoolShared(pCreateInfo->commandPool);
2201 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002202 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002203 }
2204}
2205
locke-lunargd556cc32019-09-17 01:21:23 -06002206void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2207 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002208 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002209 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002210
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002211 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002212}
2213
2214void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002215 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002216 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002217
2218 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002219}
2220
2221void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2222 VkResult result) {
2223 if (VK_SUCCESS == result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002224 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002225 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002226 }
2227}
2228
2229CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2230 // initially assume everything is static state
2231 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2232
2233 if (ds) {
2234 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002235 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002236 }
2237 }
locke-lunargd556cc32019-09-17 01:21:23 -06002238 return flags;
2239}
2240
2241// Validation cache:
2242// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002243
2244void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2245 VkPipeline pipeline) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002246 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002247 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002248 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002249
2250 auto pipe_state = GetPipelineState(pipeline);
2251 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002252 const auto &create_info = pipe_state->create_info.graphics;
2253 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2254 const auto *viewport_state = create_info.pViewportState;
2255 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002256 cb_state->status &= ~cb_state->static_status;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002257 cb_state->static_status = MakeStaticStateMask(dynamic_state->ptr());
locke-lunargd556cc32019-09-17 01:21:23 -06002258 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002259 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002260
2261 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002262 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2263 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002264 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002265 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002266 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002267 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002268 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002269 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002270
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002271 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002272 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2273 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2274 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002275 if (!has_dynamic_viewport_count) {
2276 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002277 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002278 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2279 // should become = ~uint32_t(0) if the other interpretation is correct.
2280 }
2281 }
2282 if (!has_dynamic_scissor_count) {
2283 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002284 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002285 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2286 // should become = ~uint32_t(0) if the other interpretation is correct.
2287 }
2288 }
locke-lunargd556cc32019-09-17 01:21:23 -06002289 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002290 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2291 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002292 if (!disabled[command_buffer_state]) {
2293 cb_state->AddChild(pipe_state);
2294 }
locke-lunargb8be8222020-10-20 00:34:37 -06002295 for (auto &slot : pipe_state->active_slots) {
2296 for (auto &req : slot.second) {
2297 for (auto &sampler : req.second.samplers_used_by_image) {
2298 for (auto &des : sampler) {
2299 des.second = nullptr;
2300 }
2301 }
2302 }
2303 }
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002304 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
locke-lunargd556cc32019-09-17 01:21:23 -06002305}
2306
2307void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2308 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002309 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002310 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002311 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2312 cb_state->viewportMask |= bits;
2313 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002314
2315 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2316 for (size_t i = 0; i < viewportCount; ++i) {
2317 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2318 }
locke-lunargd556cc32019-09-17 01:21:23 -06002319}
2320
2321void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2322 uint32_t exclusiveScissorCount,
2323 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002324 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002325 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002326 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2327 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002328}
2329
2330void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2331 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002332 if (disabled[command_buffer_state]) return;
2333
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002334 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002335 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002336
2337 if (imageView != VK_NULL_HANDLE) {
2338 auto view_state = GetImageViewState(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002339 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002340 }
2341}
2342
2343void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2344 uint32_t viewportCount,
2345 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002346 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002347 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002348 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2349 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002350}
2351
2352void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2353 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2354 const VkAllocationCallbacks *pAllocator,
2355 VkAccelerationStructureNV *pAccelerationStructure,
2356 VkResult result) {
2357 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002358 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002359
2360 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002361 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002362 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002363 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002364 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2365
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002366 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002367 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002368 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002369 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2370 &as_state->build_scratch_memory_requirements);
2371
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002372 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002373 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002374 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002375 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2376 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002377 as_state->allocator = pAllocator;
locke-lunargd556cc32019-09-17 01:21:23 -06002378 accelerationStructureMap[*pAccelerationStructure] = std::move(as_state);
2379}
2380
Jeff Bolz95176d02020-04-01 00:36:16 -05002381void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2382 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2383 const VkAllocationCallbacks *pAllocator,
2384 VkAccelerationStructureKHR *pAccelerationStructure,
2385 VkResult result) {
2386 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002387 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002388 as_state->allocator = pAllocator;
sourav parmarcd5fb182020-07-17 12:58:44 -07002389 accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state);
Jeff Bolz95176d02020-04-01 00:36:16 -05002390}
2391
sourav parmarcd5fb182020-07-17 12:58:44 -07002392void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2393 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2394 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002395 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002396 if (cb_state == nullptr) {
2397 return;
2398 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002399 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002400 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002401 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002402 if (dst_as_state != nullptr) {
2403 dst_as_state->built = true;
2404 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002405 if (!disabled[command_buffer_state]) {
2406 cb_state->AddChild(dst_as_state);
2407 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002408 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002409 if (!disabled[command_buffer_state]) {
2410 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2411 if (src_as_state != nullptr) {
2412 cb_state->AddChild(src_as_state);
2413 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002414 }
2415 }
2416 cb_state->hasBuildAccelerationStructureCmd = true;
2417}
2418
2419void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2420 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2421 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2422 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002423 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002424 if (cb_state == nullptr) {
2425 return;
2426 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002427 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002428 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002429 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002430 if (dst_as_state != nullptr) {
2431 dst_as_state->built = true;
2432 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002433 if (!disabled[command_buffer_state]) {
2434 cb_state->AddChild(dst_as_state);
2435 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002436 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002437 if (!disabled[command_buffer_state]) {
2438 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2439 if (src_as_state != nullptr) {
2440 cb_state->AddChild(src_as_state);
2441 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002442 }
2443 }
2444 cb_state->hasBuildAccelerationStructureCmd = true;
2445}
locke-lunargd556cc32019-09-17 01:21:23 -06002446void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002447 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002448 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002449 if (as_state != nullptr) {
2450 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2451 as_state->memory_requirements = *pMemoryRequirements;
2452 as_state->memory_requirements_checked = true;
2453 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2454 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2455 as_state->build_scratch_memory_requirements_checked = true;
2456 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2457 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2458 as_state->update_scratch_memory_requirements_checked = true;
2459 }
2460 }
2461}
2462
sourav parmarcd5fb182020-07-17 12:58:44 -07002463void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2464 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002465 if (VK_SUCCESS != result) return;
2466 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002467 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002468
sourav parmarcd5fb182020-07-17 12:58:44 -07002469 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002470 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002471 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002472 auto mem_state = GetDevMemShared(info.memory);
2473 if (mem_state) {
2474 as_state->SetMemBinding(mem_state, info.memoryOffset);
2475 }
locke-lunargd556cc32019-09-17 01:21:23 -06002476
2477 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002478 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002479 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002480 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2481 }
2482 }
2483 }
2484}
2485
2486void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2487 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2488 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002489 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002490 if (cb_state == nullptr) {
2491 return;
2492 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002493 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002494
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002495 auto *dst_as_state = GetAccelerationStructureStateNV(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002496 if (dst_as_state != nullptr) {
2497 dst_as_state->built = true;
2498 dst_as_state->build_info.initialize(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002499 if (!disabled[command_buffer_state]) {
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002500 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002501 }
locke-lunargd556cc32019-09-17 01:21:23 -06002502 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002503 if (!disabled[command_buffer_state]) {
2504 auto *src_as_state = GetAccelerationStructureStateNV(src);
2505 if (src_as_state != nullptr) {
2506 cb_state->AddChild(src_as_state);
2507 }
locke-lunargd556cc32019-09-17 01:21:23 -06002508 }
2509 cb_state->hasBuildAccelerationStructureCmd = true;
2510}
2511
2512void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2513 VkAccelerationStructureNV dst,
2514 VkAccelerationStructureNV src,
2515 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002516 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002517 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002518 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
2519 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002520 if (!disabled[command_buffer_state]) {
2521 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2522 }
locke-lunargd556cc32019-09-17 01:21:23 -06002523 if (dst_as_state != nullptr && src_as_state != nullptr) {
2524 dst_as_state->built = true;
2525 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002526 }
2527 }
2528}
2529
Jeff Bolz95176d02020-04-01 00:36:16 -05002530void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2531 VkAccelerationStructureKHR accelerationStructure,
2532 const VkAllocationCallbacks *pAllocator) {
locke-lunargd556cc32019-09-17 01:21:23 -06002533 if (!accelerationStructure) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002534 auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002535 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002536 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002537 accelerationStructureMap_khr.erase(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002538 }
2539}
2540
Jeff Bolz95176d02020-04-01 00:36:16 -05002541void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2542 VkAccelerationStructureNV accelerationStructure,
2543 const VkAllocationCallbacks *pAllocator) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002544 if (!accelerationStructure) return;
2545 auto *as_state = GetAccelerationStructureStateNV(accelerationStructure);
2546 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002547 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002548 accelerationStructureMap.erase(accelerationStructure);
2549 }
Jeff Bolz95176d02020-04-01 00:36:16 -05002550}
2551
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002552void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2553 uint32_t viewportCount,
2554 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002555 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002556 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002557}
2558
locke-lunargd556cc32019-09-17 01:21:23 -06002559void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002560 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002561 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002562}
2563
2564void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2565 uint16_t lineStipplePattern) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002566 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002567 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002568}
2569
2570void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2571 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002572 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002573 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002574}
2575
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002576void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2577 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002578 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002579 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002580 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2581 cb_state->scissorMask |= bits;
2582 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002583}
2584
locke-lunargd556cc32019-09-17 01:21:23 -06002585void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002586 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002587 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002588}
2589
2590void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2591 float maxDepthBounds) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002592 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002593 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002594}
2595
2596void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2597 uint32_t compareMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002598 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002599 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002600}
2601
2602void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2603 uint32_t writeMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002604 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002605 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002606}
2607
2608void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2609 uint32_t reference) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002610 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002611 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002612}
2613
locke-lunargd556cc32019-09-17 01:21:23 -06002614
2615// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2616void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2617 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2618 uint32_t firstSet, uint32_t setCount,
2619 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2620 const uint32_t *pDynamicOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002621 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002622 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
locke-lunargd556cc32019-09-17 01:21:23 -06002623 auto pipeline_layout = GetPipelineLayout(layout);
2624
2625 // Resize binding arrays
2626 uint32_t last_set_index = firstSet + setCount - 1;
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002627 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2628 if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) {
2629 cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06002630 }
2631
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002632 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr,
2633 dynamicOffsetCount, pDynamicOffsets);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002634 cb_state->lastBound[lv_bind_point].pipeline_layout = layout;
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002635 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002636}
2637
locke-lunargd556cc32019-09-17 01:21:23 -06002638void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2639 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2640 uint32_t set, uint32_t descriptorWriteCount,
2641 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002642 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002643 auto pipeline_layout = GetPipelineLayout(layout);
2644 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout, set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002645}
2646
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002647void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2648 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2649 const void *pValues) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002650 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002651 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002652 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002653 cb_state->ResetPushConstantDataIfIncompatible(GetPipelineLayout(layout));
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002654
2655 auto &push_constant_data = cb_state->push_constant_data;
2656 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2657 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002658 cb_state->push_constant_pipeline_layout_set = layout;
2659
2660 auto flags = stageFlags;
2661 uint32_t bit_shift = 0;
2662 while (flags) {
2663 if (flags & 1) {
2664 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2665 const auto it = cb_state->push_constant_data_update.find(flag);
2666
2667 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002668 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002669 }
2670 }
2671 flags = flags >> 1;
2672 ++bit_shift;
2673 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002674 }
2675}
2676
locke-lunargd556cc32019-09-17 01:21:23 -06002677void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2678 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002679 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002680
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002681 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002682 cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer);
2683 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002684 cb_state->index_buffer_binding.offset = offset;
2685 cb_state->index_buffer_binding.index_type = indexType;
2686 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002687 if (!disabled[command_buffer_state]) {
2688 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state.get());
2689 }
locke-lunargd556cc32019-09-17 01:21:23 -06002690}
2691
2692void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2693 uint32_t bindingCount, const VkBuffer *pBuffers,
2694 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002695 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002696 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002697
2698 uint32_t end = firstBinding + bindingCount;
2699 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2700 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2701 }
2702
2703 for (uint32_t i = 0; i < bindingCount; ++i) {
2704 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07002705 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002706 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002707 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2708 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002709 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002710 if (pBuffers[i] && !disabled[command_buffer_state]) {
2711 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Jeff Bolz165818a2020-05-08 11:19:03 -05002712 }
locke-lunargd556cc32019-09-17 01:21:23 -06002713 }
2714}
2715
2716void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2717 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002718 if (disabled[command_buffer_state]) return;
2719
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002720 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002721 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002722}
2723
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002724void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2725 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002726 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2727 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002728}
2729
2730void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2731 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002732 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002733 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2734
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002735 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2736 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002737}
2738
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002739void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2740 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002741 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2742 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002743}
2744
2745void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2746 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002747 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2748 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002749}
2750
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002751void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2752 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2753 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2754 uint32_t bufferMemoryBarrierCount,
2755 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2756 uint32_t imageMemoryBarrierCount,
2757 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002758 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2759 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
2760 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2761 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002762}
2763
2764void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2765 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002766 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2767 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06002768 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002769 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06002770 }
2771}
2772
2773void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2774 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2775 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2776 uint32_t bufferMemoryBarrierCount,
2777 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2778 uint32_t imageMemoryBarrierCount,
2779 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002780 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2781 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2782 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2783 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002784}
2785
2786void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2787 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002788 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2789 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2790 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002791}
2792
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002793QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
2794 uint32_t perfPass) const {
2795 QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002796
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002797 auto iter = localQueryToStateMap->find(query);
2798 if (iter != localQueryToStateMap->end()) return iter->second;
Jeff Bolz310775c2019-10-09 00:46:33 -05002799
Jeff Bolz310775c2019-10-09 00:46:33 -05002800 return QUERYSTATE_UNKNOWN;
locke-lunargd556cc32019-09-17 01:21:23 -06002801}
2802
locke-lunargd556cc32019-09-17 01:21:23 -06002803void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2804 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002805 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002806
locke-lunargd556cc32019-09-17 01:21:23 -06002807 QueryObject query = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002808 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002809 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002810 if (!disabled[query_validation]) {
2811 cb_state->BeginQuery(query);
2812 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002813 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002814 auto pool_state = GetQueryPoolState(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002815 cb_state->AddChild(pool_state);
2816 }
locke-lunargd556cc32019-09-17 01:21:23 -06002817}
2818
2819void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002820 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002821 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002822 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002823 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002824 if (!disabled[query_validation]) {
2825 cb_state->EndQuery(query_obj);
2826 }
2827 if (!disabled[command_buffer_state]) {
2828 auto pool_state = GetQueryPoolState(query_obj.pool);
2829 cb_state->AddChild(pool_state);
2830 }
locke-lunargd556cc32019-09-17 01:21:23 -06002831}
2832
2833void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2834 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002835 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002836 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002837
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002838 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002839 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002840
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002841 if (!disabled[command_buffer_state]) {
2842 auto pool_state = GetQueryPoolState(queryPool);
2843 cb_state->AddChild(pool_state);
2844 }
locke-lunargd556cc32019-09-17 01:21:23 -06002845}
2846
2847void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2848 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2849 VkDeviceSize dstOffset, VkDeviceSize stride,
2850 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002851 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2852
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002853 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002854 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
locke-lunargd556cc32019-09-17 01:21:23 -06002855 auto dst_buff_state = GetBufferState(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002856 cb_state->AddChild(dst_buff_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05002857 auto pool_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002858 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002859}
2860
2861void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2862 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002863 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2864 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002865}
2866
2867void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2868 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2869 uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002870 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2871 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002872}
2873
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002874void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2875 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2876 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2877 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002878 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002879 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002880 if (!disabled[command_buffer_state]) {
2881 auto pool_state = GetQueryPoolState(queryPool);
2882 cb_state->AddChild(pool_state);
2883 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002884 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002885}
2886
locke-lunargd556cc32019-09-17 01:21:23 -06002887void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2888 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2889 VkResult result) {
2890 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002891
Jeremy Gebben88f58142021-06-01 10:07:52 -06002892 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002893 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002894 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002895
locke-lunargd556cc32019-09-17 01:21:23 -06002896 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002897 views[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002898 }
2899 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002900
2901 frameBufferMap[*pFramebuffer] = std::make_shared<FRAMEBUFFER_STATE>(
2902 *pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass), std::move(views));
locke-lunargd556cc32019-09-17 01:21:23 -06002903}
2904
locke-lunargd556cc32019-09-17 01:21:23 -06002905void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2906 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2907 VkResult result) {
2908 if (VK_SUCCESS != result) return;
Jeremy Gebben88f58142021-06-01 10:07:52 -06002909 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002910}
2911
Mike Schuchardt2df08912020-12-15 16:28:09 -08002912void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002913 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2914 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002915 if (VK_SUCCESS != result) return;
2916
2917 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07002918}
2919
Mike Schuchardt2df08912020-12-15 16:28:09 -08002920void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002921 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2922 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002923 if (VK_SUCCESS != result) return;
2924
2925 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07002926}
2927
locke-lunargd556cc32019-09-17 01:21:23 -06002928void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
2929 const VkRenderPassBeginInfo *pRenderPassBegin,
2930 VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002931 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2932 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002933}
2934
2935void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
2936 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002937 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002938 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002939 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002940}
2941
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002942void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2943 uint32_t counterBufferCount,
2944 const VkBuffer *pCounterBuffers,
2945 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002946 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002947
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002948 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002949 cb_state->transform_feedback_active = true;
2950}
2951
2952void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2953 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
2954 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002955 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002956
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002957 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002958 cb_state->transform_feedback_active = false;
2959}
2960
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002961void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
2962 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06002963 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002964
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002965 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002966 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002967 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
2968 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002969}
2970
2971void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06002972 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002973
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002974 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002975 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002976 cb_state->conditional_rendering_inside_render_pass = false;
2977 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002978}
2979
Tony-LunarG977448c2019-12-02 14:52:02 -07002980void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
2981 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002982 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002983 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2984 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07002985}
2986
locke-lunargd556cc32019-09-17 01:21:23 -06002987
2988void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002989 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2990 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002991}
2992
2993void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002994 const VkSubpassBeginInfo *pSubpassBeginInfo,
2995 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002996 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002997 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002998}
2999
Tony-LunarG977448c2019-12-02 14:52:02 -07003000void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003001 const VkSubpassBeginInfo *pSubpassBeginInfo,
3002 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003003 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003004 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003005}
3006
3007void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003008 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3009 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003010}
3011
3012void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003013 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003014 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003015 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003016}
3017
Tony-LunarG977448c2019-12-02 14:52:02 -07003018void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003019 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003020 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3021 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003022}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003023
locke-lunargd556cc32019-09-17 01:21:23 -06003024void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3025 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003026 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003027
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003028 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003029}
3030
3031void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3032 VkFlags flags, void **ppData, VkResult result) {
3033 if (VK_SUCCESS != result) return;
3034 RecordMappedMemory(mem, offset, size, ppData);
3035}
3036
3037void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
3038 auto mem_info = GetDevMemState(mem);
3039 if (mem_info) {
3040 mem_info->mapped_range = MemRange();
3041 mem_info->p_driver_data = nullptr;
3042 }
3043}
3044
3045void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben8ee02af2021-07-16 10:15:55 -06003046 auto image_state = GetShared<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003047 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003048 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3049 // See: VUID-vkGetImageSubresourceLayout-image-01895
3050 image_state->fragment_encoder =
3051 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003052 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003053 if (swapchain_info) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003054 auto swapchain = GetShared<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003055 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003056 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003057
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003058 if (!swapchain_image.fake_base_address) {
3059 auto size = image_state->fragment_encoder->TotalSize();
3060 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003061 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003062 // All images bound to this swapchain and index are aliases
3063 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003064 }
3065 } else {
3066 // Track bound memory range information
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003067 auto mem_info = GetDevMemShared(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003068 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003069 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003070 }
locke-lunargd556cc32019-09-17 01:21:23 -06003071 }
locke-lunargd556cc32019-09-17 01:21:23 -06003072 }
3073}
3074
3075void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3076 VkDeviceSize memoryOffset, VkResult result) {
3077 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003078 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003079 bind_info.image = image;
3080 bind_info.memory = mem;
3081 bind_info.memoryOffset = memoryOffset;
3082 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003083}
3084
3085void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003086 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003087 if (VK_SUCCESS != result) return;
3088 for (uint32_t i = 0; i < bindInfoCount; i++) {
3089 UpdateBindImageMemoryState(pBindInfos[i]);
3090 }
3091}
3092
3093void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003094 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003095 if (VK_SUCCESS != result) return;
3096 for (uint32_t i = 0; i < bindInfoCount; i++) {
3097 UpdateBindImageMemoryState(pBindInfos[i]);
3098 }
3099}
3100
3101void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
3102 auto event_state = GetEventState(event);
3103 if (event_state) {
3104 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3105 }
locke-lunargd556cc32019-09-17 01:21:23 -06003106}
3107
3108void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3109 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3110 VkResult result) {
3111 if (VK_SUCCESS != result) return;
3112 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3113 pImportSemaphoreFdInfo->flags);
3114}
3115
3116void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003117 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003118 SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08003119 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003120 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
3121 semaphore_state->scope = kSyncScopeExternalPermanent;
3122 }
3123}
3124
3125#ifdef VK_USE_PLATFORM_WIN32_KHR
3126void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3127 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3128 if (VK_SUCCESS != result) return;
3129 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3130 pImportSemaphoreWin32HandleInfo->flags);
3131}
3132
3133void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3134 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3135 HANDLE *pHandle, VkResult result) {
3136 if (VK_SUCCESS != result) return;
3137 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3138}
3139
3140void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3141 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3142 if (VK_SUCCESS != result) return;
3143 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3144 pImportFenceWin32HandleInfo->flags);
3145}
3146
3147void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3148 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3149 HANDLE *pHandle, VkResult result) {
3150 if (VK_SUCCESS != result) return;
3151 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3152}
3153#endif
3154
3155void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3156 VkResult result) {
3157 if (VK_SUCCESS != result) return;
3158 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3159}
3160
Mike Schuchardt2df08912020-12-15 16:28:09 -08003161void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3162 VkFenceImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06003163 FENCE_STATE *fence_node = GetFenceState(fence);
3164 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003165 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06003166 fence_node->scope == kSyncScopeInternal) {
3167 fence_node->scope = kSyncScopeExternalTemporary;
3168 } else {
3169 fence_node->scope = kSyncScopeExternalPermanent;
3170 }
3171 }
3172}
3173
3174void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3175 VkResult result) {
3176 if (VK_SUCCESS != result) return;
3177 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3178}
3179
Mike Schuchardt2df08912020-12-15 16:28:09 -08003180void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003181 FENCE_STATE *fence_state = GetFenceState(fence);
3182 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003183 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003184 // Export with reference transference becomes external
3185 fence_state->scope = kSyncScopeExternalPermanent;
3186 } else if (fence_state->scope == kSyncScopeInternal) {
3187 // Export with copy transference has a side effect of resetting the fence
3188 fence_state->state = FENCE_UNSIGNALED;
3189 }
3190 }
3191}
3192
3193void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3194 VkResult result) {
3195 if (VK_SUCCESS != result) return;
3196 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3197}
3198
3199void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3200 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3201 if (VK_SUCCESS != result) return;
John Zulaufd5115702021-01-18 12:34:33 -07003202 const auto event = *pEvent;
Jeremy Gebbencbf22862021-03-03 12:01:22 -07003203 eventMap.emplace(event, std::make_shared<EVENT_STATE>(event, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003204}
3205
3206void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003207 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003208 SWAPCHAIN_NODE *old_swapchain_state) {
3209 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003210 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003211 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003212 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003213 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3214 surface_state->AddParent(swapchain.get());
3215 surface_state->swapchain = swapchain.get();
3216 swapchain->surface = std::move(surface_state);
3217 swapchainMap[*pSwapchain] = std::move(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003218 } else {
3219 surface_state->swapchain = nullptr;
3220 }
3221 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003222 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003223 if (old_swapchain_state) {
3224 old_swapchain_state->retired = true;
3225 }
3226 return;
3227}
3228
3229void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3230 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3231 VkResult result) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003232 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfo->surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003233 auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003234 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003235}
3236
3237void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3238 const VkAllocationCallbacks *pAllocator) {
3239 if (!swapchain) return;
3240 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003241 if (!swapchain_data) return;
John Zulauffaa7a522021-03-05 12:22:45 -07003242
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003243 swapchain_data->Destroy();
3244 swapchainMap.erase(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003245}
3246
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003247void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3248 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3249 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3250 VkResult result) {
3251 if (VK_SUCCESS != result) return;
3252 if (!pMode) return;
Jeremy Gebben5573a8c2021-06-04 08:55:10 -06003253 display_mode_map[*pMode] = std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice);
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003254}
3255
locke-lunargd556cc32019-09-17 01:21:23 -06003256void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
3257 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3258 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003259 auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]);
3260 if (semaphore_state) {
Jeremy Gebben57642982021-09-14 14:14:55 -06003261 semaphore_state->signaler.queue = nullptr;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003262 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06003263 }
3264 }
3265
Tony-LunarG6f887e52021-07-27 11:23:14 -06003266 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003267 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3268 // 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
3269 // confused itself just as much.
3270 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3271 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3272 // Mark the image as having been released to the WSI
3273 auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003274 if (swapchain_data) {
3275 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003276 if (present_id_info) {
3277 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3278 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3279 }
3280 }
locke-lunargd556cc32019-09-17 01:21:23 -06003281 }
3282 }
3283 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
3284 // its semaphore waits) /never/ participate in any completion proof.
3285}
3286
3287void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3288 const VkSwapchainCreateInfoKHR *pCreateInfos,
3289 const VkAllocationCallbacks *pAllocator,
3290 VkSwapchainKHR *pSwapchains, VkResult result) {
3291 if (pCreateInfos) {
3292 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003293 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfos[i].surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003294 auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003295 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003296 }
3297 }
3298}
3299
3300void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3301 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003302 auto fence_state = GetFenceState(fence);
3303 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003304 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3305 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003306 fence_state->state = FENCE_INFLIGHT;
Jeremy Gebben57642982021-09-14 14:14:55 -06003307 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 -06003308 }
3309
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003310 auto semaphore_state = GetSemaphoreState(semaphore);
3311 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003312 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3313 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003314 semaphore_state->signaled = true;
Jeremy Gebben57642982021-09-14 14:14:55 -06003315 semaphore_state->signaler.queue = nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003316 }
3317
3318 // Mark the image as acquired.
3319 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003320 if (swapchain_data) {
3321 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003322 }
3323}
3324
3325void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3326 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3327 VkResult result) {
3328 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3329 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3330}
3331
3332void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3333 uint32_t *pImageIndex, VkResult result) {
3334 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3335 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3336 pAcquireInfo->fence, pImageIndex);
3337}
3338
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003339std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3340 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3341}
3342
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003343void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3344 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3345 VkResult result) {
3346 if (result != VK_SUCCESS) {
3347 return;
3348 }
3349 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003350 // this can fail if the allocator fails
3351 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3352 if (result != VK_SUCCESS) {
3353 return;
3354 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003355 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003356 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3357 if (result != VK_SUCCESS) {
3358 return;
3359 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003360
3361 physical_device_map.reserve(count);
3362 for (auto physdev : physdev_handles) {
3363 physical_device_map.emplace(physdev, CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003364 }
3365}
3366
3367// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003368static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003369 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003370}
3371
3372void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3373 uint32_t *pQueueFamilyPropertyCount,
3374 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003375 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3376 assert(pd_state);
3377 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003378}
3379
3380void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003381 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003382 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3383 assert(pd_state);
3384 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003385}
3386
3387void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003388 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003389 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3390 assert(pd_state);
3391 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003392}
3393void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3394 const VkAllocationCallbacks *pAllocator) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003395 if (!surface) return;
3396 auto surface_state = GetSurfaceState(surface);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003397 surface_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06003398 surface_map.erase(surface);
3399}
3400
3401void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003402 surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface);
locke-lunargd556cc32019-09-17 01:21:23 -06003403}
3404
3405void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3406 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3407 const VkAllocationCallbacks *pAllocator,
3408 VkSurfaceKHR *pSurface, VkResult result) {
3409 if (VK_SUCCESS != result) return;
3410 RecordVulkanSurface(pSurface);
3411}
3412
3413#ifdef VK_USE_PLATFORM_ANDROID_KHR
3414void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3415 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3416 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3417 VkResult result) {
3418 if (VK_SUCCESS != result) return;
3419 RecordVulkanSurface(pSurface);
3420}
3421#endif // VK_USE_PLATFORM_ANDROID_KHR
3422
3423#ifdef VK_USE_PLATFORM_IOS_MVK
3424void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3425 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3426 VkResult result) {
3427 if (VK_SUCCESS != result) return;
3428 RecordVulkanSurface(pSurface);
3429}
3430#endif // VK_USE_PLATFORM_IOS_MVK
3431
3432#ifdef VK_USE_PLATFORM_MACOS_MVK
3433void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3434 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3435 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3436 VkResult result) {
3437 if (VK_SUCCESS != result) return;
3438 RecordVulkanSurface(pSurface);
3439}
3440#endif // VK_USE_PLATFORM_MACOS_MVK
3441
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003442#ifdef VK_USE_PLATFORM_METAL_EXT
3443void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3444 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3445 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3446 VkResult result) {
3447 if (VK_SUCCESS != result) return;
3448 RecordVulkanSurface(pSurface);
3449}
3450#endif // VK_USE_PLATFORM_METAL_EXT
3451
locke-lunargd556cc32019-09-17 01:21:23 -06003452#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3453void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3454 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3455 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3456 VkResult result) {
3457 if (VK_SUCCESS != result) return;
3458 RecordVulkanSurface(pSurface);
3459}
3460#endif // VK_USE_PLATFORM_WAYLAND_KHR
3461
3462#ifdef VK_USE_PLATFORM_WIN32_KHR
3463void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3464 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3465 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3466 VkResult result) {
3467 if (VK_SUCCESS != result) return;
3468 RecordVulkanSurface(pSurface);
3469}
3470#endif // VK_USE_PLATFORM_WIN32_KHR
3471
3472#ifdef VK_USE_PLATFORM_XCB_KHR
3473void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3474 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3475 VkResult result) {
3476 if (VK_SUCCESS != result) return;
3477 RecordVulkanSurface(pSurface);
3478}
3479#endif // VK_USE_PLATFORM_XCB_KHR
3480
3481#ifdef VK_USE_PLATFORM_XLIB_KHR
3482void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3483 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3484 VkResult result) {
3485 if (VK_SUCCESS != result) return;
3486 RecordVulkanSurface(pSurface);
3487}
3488#endif // VK_USE_PLATFORM_XLIB_KHR
3489
Niklas Haas8b84af12020-04-19 22:20:11 +02003490void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3491 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3492 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3493 VkResult result) {
3494 if (VK_SUCCESS != result) return;
3495 RecordVulkanSurface(pSurface);
3496}
3497
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003498void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3499 VkSurfaceKHR surface,
3500 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3501 VkResult result) {
3502 if (VK_SUCCESS != result) return;
3503 auto surface_state = Get<SURFACE_STATE>(surface);
3504 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3505}
3506
3507void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3508 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3509 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3510 if (VK_SUCCESS != result) return;
3511 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3512 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3513}
3514
3515void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3516 VkSurfaceKHR surface,
3517 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3518 VkResult result) {
3519 auto surface_state = Get<SURFACE_STATE>(surface);
3520 VkSurfaceCapabilitiesKHR caps{
3521 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3522 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3523 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3524 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3525 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3526 };
3527 surface_state->SetCapabilities(physicalDevice, caps);
3528}
3529
locke-lunargd556cc32019-09-17 01:21:23 -06003530void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3531 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3532 VkBool32 *pSupported, VkResult result) {
3533 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003534 auto surface_state = Get<SURFACE_STATE>(surface);
3535 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3536}
3537
3538void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3539 VkSurfaceKHR surface,
3540 uint32_t *pPresentModeCount,
3541 VkPresentModeKHR *pPresentModes,
3542 VkResult result) {
3543 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3544
3545 if (pPresentModes) {
3546 auto surface_state = Get<SURFACE_STATE>(surface);
3547 surface_state->SetPresentModes(physicalDevice,
3548 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3549 }
3550}
3551
3552void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3553 uint32_t *pSurfaceFormatCount,
3554 VkSurfaceFormatKHR *pSurfaceFormats,
3555 VkResult result) {
3556 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3557
3558 if (pSurfaceFormats) {
3559 auto surface_state = Get<SURFACE_STATE>(surface);
3560 surface_state->SetFormats(physicalDevice,
3561 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3562 }
3563}
3564
3565void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3566 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3567 uint32_t *pSurfaceFormatCount,
3568 VkSurfaceFormat2KHR *pSurfaceFormats,
3569 VkResult result) {
3570 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3571
3572 if (pSurfaceFormats) {
3573 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3574 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3575 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3576 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3577 }
3578 surface_state->SetFormats(physicalDevice, std::move(fmts));
3579 }
locke-lunargd556cc32019-09-17 01:21:23 -06003580}
3581
locke-lunargd556cc32019-09-17 01:21:23 -06003582void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3583 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003584 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3585 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003586 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3587}
3588
3589void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003590 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3591 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003592 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3593}
3594
3595void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3596 const VkDebugUtilsLabelEXT *pLabelInfo) {
3597 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3598
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003599 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003600 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3601 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003602 cb_state->debug_label = LoggingLabel(pLabelInfo);
3603}
3604
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003605void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3606 uint32_t queueFamilyIndex,
3607 uint32_t *pCounterCount,
3608 VkPerformanceCounterKHR *pCounters) {
3609 if (NULL == pCounters) return;
3610
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003611 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3612 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003613
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003614 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3615 queue_family_counters->counters.resize(*pCounterCount);
3616 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003617
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003618 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003619}
3620
3621void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3622 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3623 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3624 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3625 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3626}
3627
3628void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3629 VkResult result) {
3630 if (result == VK_SUCCESS) performance_lock_acquired = true;
3631}
3632
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003633void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3634 performance_lock_acquired = false;
3635 for (auto &cmd_buffer : commandBufferMap) {
3636 cmd_buffer.second->performance_lock_released = true;
3637 }
3638}
3639
locke-lunargd556cc32019-09-17 01:21:23 -06003640void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003641 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003642 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003643 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3644 if (template_state) {
3645 template_state->Destroy();
3646 desc_template_map_.erase(descriptorUpdateTemplate);
3647 }
locke-lunargd556cc32019-09-17 01:21:23 -06003648}
3649
3650void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003651 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003652 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003653 auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3654 if (template_state) {
3655 template_state->Destroy();
3656 desc_template_map_.erase(descriptorUpdateTemplate);
3657 }
locke-lunargd556cc32019-09-17 01:21:23 -06003658}
3659
Mike Schuchardt2df08912020-12-15 16:28:09 -08003660void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3661 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003662 desc_template_map_.emplace(*pDescriptorUpdateTemplate,
3663 std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003664}
3665
Mike Schuchardt2df08912020-12-15 16:28:09 -08003666void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3667 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3668 const VkAllocationCallbacks *pAllocator,
3669 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3670 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003671 if (VK_SUCCESS != result) return;
3672 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3673}
3674
3675void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003676 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3677 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003678 if (VK_SUCCESS != result) return;
3679 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3680}
3681
3682void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003683 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003684 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003685 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3686 assert(template_state);
3687 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003688 // TODO: Record template push descriptor updates
3689 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
3690 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData);
3691 }
3692 }
3693}
3694
3695void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3696 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3697 const void *pData) {
3698 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3699}
3700
3701void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003702 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003703 const void *pData) {
3704 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3705}
3706
Mike Schuchardt2df08912020-12-15 16:28:09 -08003707void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3708 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3709 VkPipelineLayout layout, uint32_t set,
3710 const void *pData) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003711 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003712
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003713 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003714 const auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003715 if (template_state) {
3716 auto layout_data = GetPipelineLayout(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003717 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003718 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003719 // Decode the template into a set of write updates
3720 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData,
3721 dsl->GetDescriptorSetLayout());
3722 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data, set,
3723 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3724 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003725 }
3726}
3727
3728void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3729 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003730 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003731 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003732 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003733 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003734 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003735 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003736 }
3737}
3738
3739void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3740 uint32_t *pPropertyCount,
3741 VkDisplayPlanePropertiesKHR *pProperties,
3742 VkResult result) {
3743 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3744 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3745}
3746
3747void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3748 uint32_t *pPropertyCount,
3749 VkDisplayPlaneProperties2KHR *pProperties,
3750 VkResult result) {
3751 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3752 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3753}
3754
3755void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3756 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3757 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003758 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003759 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003760 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003761}
3762
3763void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3764 uint32_t query, uint32_t index) {
3765 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003766 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003767 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003768 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003769}
3770
3771void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3772 VkSamplerYcbcrConversion ycbcr_conversion) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003773 VkFormatFeatureFlags format_features = 0;
3774
3775 if (create_info->format != VK_FORMAT_UNDEFINED) {
3776 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003777 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003778 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3779 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003780 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003781
3782 samplerYcbcrConversionMap[ycbcr_conversion] =
3783 std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features);
locke-lunargd556cc32019-09-17 01:21:23 -06003784}
3785
3786void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3787 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3788 const VkAllocationCallbacks *pAllocator,
3789 VkSamplerYcbcrConversion *pYcbcrConversion,
3790 VkResult result) {
3791 if (VK_SUCCESS != result) return;
3792 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3793}
3794
3795void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3796 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3797 const VkAllocationCallbacks *pAllocator,
3798 VkSamplerYcbcrConversion *pYcbcrConversion,
3799 VkResult result) {
3800 if (VK_SUCCESS != result) return;
3801 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3802}
3803
sfricke-samsungbe3584f2020-04-22 14:58:06 -07003804void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -07003805 auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003806 ycbcr_state->Destroy();
sfricke-samsungbe3584f2020-04-22 14:58:06 -07003807 samplerYcbcrConversionMap.erase(ycbcr_conversion);
3808}
3809
locke-lunargd556cc32019-09-17 01:21:23 -06003810void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3811 const VkAllocationCallbacks *pAllocator) {
3812 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07003813 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003814}
3815
3816void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3817 VkSamplerYcbcrConversion ycbcrConversion,
3818 const VkAllocationCallbacks *pAllocator) {
3819 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07003820 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003821}
3822
Tony-LunarG977448c2019-12-02 14:52:02 -07003823void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3824 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003825 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003826 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003827
3828 // Do nothing if the query pool has been destroyed.
3829 auto query_pool_state = GetQueryPoolState(queryPool);
3830 if (!query_pool_state) return;
3831
3832 // Reset the state of existing entries.
3833 QueryObject query_obj{queryPool, 0};
3834 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3835 for (uint32_t i = 0; i < max_query_count; ++i) {
3836 query_obj.query = firstQuery + i;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003837 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003838 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003839 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
3840 query_obj.perf_pass = pass_index;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003841 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003842 }
3843 }
locke-lunargd556cc32019-09-17 01:21:23 -06003844 }
3845}
3846
Tony-LunarG977448c2019-12-02 14:52:02 -07003847void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3848 uint32_t queryCount) {
3849 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3850}
3851
3852void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3853 uint32_t queryCount) {
3854 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3855}
3856
locke-lunargd556cc32019-09-17 01:21:23 -06003857void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003858 const UPDATE_TEMPLATE_STATE *template_state,
3859 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003860 // Translate the templated update into a normal update for validation...
3861 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3862 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3863 decoded_update.desc_writes.data(), 0, NULL);
3864}
3865
3866// Update the common AllocateDescriptorSetsData
3867void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003868 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003869 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05003870 auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003871 if (layout) {
3872 ds_data->layout_nodes[i] = layout;
3873 // Count total descriptors required per type
3874 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3875 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003876 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3877 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003878 }
3879 }
3880 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3881 }
3882}
3883
locke-lunargd556cc32019-09-17 01:21:23 -06003884void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3885 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003886 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003887 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003888}
3889
Tony-LunarG745150c2021-07-02 15:07:31 -06003890void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3891 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3892 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003893 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003894 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003895}
3896
locke-lunargd556cc32019-09-17 01:21:23 -06003897void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3898 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3899 uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003900 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003901 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003902}
3903
Tony-LunarG745150c2021-07-02 15:07:31 -06003904void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3905 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3906 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3907 const int32_t *pVertexOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003908 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003909 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003910}
3911
locke-lunargd556cc32019-09-17 01:21:23 -06003912void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3913 uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003914 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003915 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003916 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003917 if (!disabled[command_buffer_state]) {
3918 cb_state->AddChild(buffer_state);
3919 }
locke-lunargd556cc32019-09-17 01:21:23 -06003920}
3921
3922void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3923 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003924 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003925 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003926 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003927 if (!disabled[command_buffer_state]) {
3928 cb_state->AddChild(buffer_state);
3929 }
locke-lunargd556cc32019-09-17 01:21:23 -06003930}
3931
3932void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003933 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003934 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003935}
3936
3937void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3938 VkDeviceSize offset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003939 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003940 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003941 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003942 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003943 cb_state->AddChild(buffer_state);
3944 }
locke-lunargd556cc32019-09-17 01:21:23 -06003945}
3946
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003947void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3948 uint32_t, uint32_t) {
3949 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3950 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3951}
3952
3953void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3954 uint32_t, uint32_t) {
3955 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3956 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3957}
3958
Tony-LunarG977448c2019-12-02 14:52:02 -07003959void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3960 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07003961 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003962 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003963 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003964 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003965 BUFFER_STATE *buffer_state = GetBufferState(buffer);
3966 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003967 cb_state->AddChild(buffer_state);
3968 cb_state->AddChild(count_buffer_state);
3969 }
Tony-LunarG977448c2019-12-02 14:52:02 -07003970}
3971
locke-lunargd556cc32019-09-17 01:21:23 -06003972void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3973 VkDeviceSize offset, VkBuffer countBuffer,
3974 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3975 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003976 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003977 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003978}
3979
3980void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3981 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
3982 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003983 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003984 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07003985}
3986
3987void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3988 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07003989 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003990 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003991 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003992 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003993 BUFFER_STATE *buffer_state = GetBufferState(buffer);
3994 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003995 cb_state->AddChild(buffer_state);
3996 cb_state->AddChild(count_buffer_state);
3997 }
locke-lunargd556cc32019-09-17 01:21:23 -06003998}
3999
4000void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4001 VkDeviceSize offset, VkBuffer countBuffer,
4002 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4003 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004004 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004005 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004006}
4007
4008void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4009 VkDeviceSize offset, VkBuffer countBuffer,
4010 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4011 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004012 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004013 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004014}
4015
4016void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4017 uint32_t firstTask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004018 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004019 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004020}
4021
4022void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4023 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004024 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004025 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004026 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004027 if (!disabled[command_buffer_state] && buffer_state) {
4028 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004029 }
4030}
4031
4032void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4033 VkDeviceSize offset, VkBuffer countBuffer,
4034 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4035 uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004036 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004037 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004038 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004039 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4040 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004041 if (buffer_state) {
4042 cb_state->AddChild(buffer_state);
4043 }
4044 if (count_buffer_state) {
4045 cb_state->AddChild(count_buffer_state);
4046 }
locke-lunargd556cc32019-09-17 01:21:23 -06004047 }
4048}
4049
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004050void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4051 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4052 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4053 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4054 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4055 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4056 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004057 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004058 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004059 cb_state->hasTraceRaysCmd = true;
4060}
4061
4062
4063void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4064 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4065 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4066 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4067 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4068 uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004069 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004070 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004071 cb_state->hasTraceRaysCmd = true;
4072}
4073
4074void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4075 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4076 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4077 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4078 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4079 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004080 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004081 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004082 cb_state->hasTraceRaysCmd = true;
4083}
4084
locke-lunargd556cc32019-09-17 01:21:23 -06004085void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4086 const VkAllocationCallbacks *pAllocator,
4087 VkShaderModule *pShaderModule, VkResult result,
4088 void *csm_state_data) {
4089 if (VK_SUCCESS != result) return;
4090 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4091
sfricke-samsung45996a42021-09-16 13:45:27 -07004092 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004093 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004094 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4095 csm_state->unique_shader_id)
4096 : std::make_shared<SHADER_MODULE_STATE>();
locke-lunargd556cc32019-09-17 01:21:23 -06004097 shaderModuleMap[*pShaderModule] = std::move(new_shader_module);
4098}
4099
John Zulauf22b0fbe2019-10-15 06:26:16 -06004100void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4101 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4102 VkResult result) {
4103 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004104 auto swapchain_state = GetShared<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004105
4106 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4107
4108 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004109 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004110 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004111 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004112
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004113 auto format_features =
4114 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
4115 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004116
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06004117 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004118 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004119 if (!swapchain_image.fake_base_address) {
4120 auto size = image_state->fragment_encoder->TotalSize();
4121 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004122 }
4123
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004124 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004125 swapchain_image.image_state = image_state.get();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004126 imageMap[pSwapchainImages[i]] = std::move(image_state);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004127 }
4128 }
4129
4130 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004131 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4132 }
4133}
sourav parmar35e7a002020-06-09 17:58:44 -07004134
sourav parmar35e7a002020-06-09 17:58:44 -07004135void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4136 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004137 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004138 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004139 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07004140 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
4141 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004142 if (dst_as_state != nullptr && src_as_state != nullptr) {
4143 dst_as_state->built = true;
4144 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004145 if (!disabled[command_buffer_state]) {
4146 cb_state->AddChild(dst_as_state);
4147 cb_state->AddChild(src_as_state);
4148 }
sourav parmar35e7a002020-06-09 17:58:44 -07004149 }
4150 }
4151}
Piers Daniell39842ee2020-07-10 16:42:33 -06004152
4153void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004154 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004155 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004156}
4157
4158void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004159 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004160 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004161}
4162
4163void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4164 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004165 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004166 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004167 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004168}
4169
4170void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4171 const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004172 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004173 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004174 uint32_t bits = (1u << viewportCount) - 1u;
4175 cb_state->viewportWithCountMask |= bits;
4176 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004177 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004178 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004179
4180 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4181 for (size_t i = 0; i < viewportCount; ++i) {
4182 cb_state->dynamicViewports[i] = pViewports[i];
4183 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004184}
4185
4186void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4187 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004188 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004189 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004190 uint32_t bits = (1u << scissorCount) - 1u;
4191 cb_state->scissorWithCountMask |= bits;
4192 cb_state->trashedScissorMask &= ~bits;
4193 cb_state->scissorWithCountCount = scissorCount;
4194 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004195}
4196
4197void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4198 uint32_t bindingCount, const VkBuffer *pBuffers,
4199 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4200 const VkDeviceSize *pStrides) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004201 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004202 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004203
4204 uint32_t end = firstBinding + bindingCount;
4205 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4206 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4207 }
4208
4209 for (uint32_t i = 0; i < bindingCount; ++i) {
4210 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07004211 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004212 vertex_buffer_binding.offset = pOffsets[i];
4213 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4214 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4215 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004216 if (!disabled[command_buffer_state] && pBuffers[i]) {
4217 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Piers Daniell39842ee2020-07-10 16:42:33 -06004218 }
4219 }
4220}
4221
4222void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004223 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004224 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004225}
4226
4227void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004228 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004229 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004230}
4231
4232void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004233 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004234 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004235}
4236
4237void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4238 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004239 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004240 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004241}
4242void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004243 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004244 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004245}
4246
4247void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4248 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4249 VkCompareOp compareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004250 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004251 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004252}
locke-lunarg4189aa22020-10-21 00:23:48 -06004253
4254void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4255 uint32_t discardRectangleCount,
4256 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004257 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004258 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004259}
4260
4261void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4262 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004263 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004264 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004265}
4266
4267void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4268 VkCoarseSampleOrderTypeNV sampleOrderType,
4269 uint32_t customSampleOrderCount,
4270 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004271 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004272 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004273}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004274
4275void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004276 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004277 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004278}
4279
4280void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004281 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004282 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004283}
4284
4285void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4286 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004287 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004288 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004289}
4290
4291void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004292 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004293 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004294}
4295
4296void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4297 VkBool32 primitiveRestartEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004298 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004299 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004300}
Piers Daniell924cd832021-05-18 13:48:47 -06004301
4302void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4303 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4304 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4305 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004306 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004307 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4308
4309 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4310 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4311 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004312 if (pipeline_state->create_info.graphics.pDynamicState) {
4313 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4314 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004315 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4316 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4317 break;
4318 }
4319 }
4320 }
4321 }
4322 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004323}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004324
4325void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
4326 BUFFER_STATE *buffer_state = GetBufferState(pInfo->buffer);
4327 if (buffer_state) {
4328 // address is used for GPU-AV and ray tracing buffer validation
4329 buffer_state->deviceAddress = address;
4330 buffer_address_map_.emplace(address, buffer_state);
4331 }
4332}
4333
4334void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4335 VkDeviceAddress address) {
4336 RecordGetBufferDeviceAddress(pInfo, address);
4337}
4338
4339void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4340 VkDeviceAddress address) {
4341 RecordGetBufferDeviceAddress(pInfo, address);
4342}
4343
4344void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4345 VkDeviceAddress address) {
4346 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004347}
4348
4349std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4350 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004351 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004352}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004353
4354std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4355 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004356 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004357 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4358}