blob: 71192216e26ea1cf0a35151f7e9803f7e22e7cd0 [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// Remove set from setMap and delete the set
449void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) {
Jeff Bolz41a1ced2019-10-11 11:40:49 -0500450 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600451 descriptor_set->Destroy();
Jeff Bolz41a1ced2019-10-11 11:40:49 -0500452
locke-lunargd556cc32019-09-17 01:21:23 -0600453 setMap.erase(descriptor_set->GetSet());
454}
455
456// Free all DS Pools including their Sets & related sub-structs
457// NOTE : Calls to this function should be wrapped in mutex
458void ValidationStateTracker::DeleteDescriptorSetPools() {
459 for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) {
460 // Remove this pools' sets from setMap and delete them
John Zulauf79f06582021-02-27 18:38:39 -0700461 for (auto *ds : ii->second->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -0600462 FreeDescriptorSet(ds);
463 }
464 ii->second->sets.clear();
465 ii = descriptorPoolMap.erase(ii);
466 }
467}
468
469// For given object struct return a ptr of BASE_NODE type for its wrapping struct
470BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) {
Jeff Bolzadbfa852019-10-04 13:53:30 -0500471 if (object_struct.node) {
472#ifdef _DEBUG
473 // assert that lookup would find the same object
474 VulkanTypedHandle other = object_struct;
475 other.node = nullptr;
476 assert(object_struct.node == GetStateStructPtrFromObject(other));
477#endif
478 return object_struct.node;
479 }
locke-lunargd556cc32019-09-17 01:21:23 -0600480 BASE_NODE *base_ptr = nullptr;
481 switch (object_struct.type) {
482 case kVulkanObjectTypeDescriptorSet: {
483 base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>());
484 break;
485 }
486 case kVulkanObjectTypeSampler: {
487 base_ptr = GetSamplerState(object_struct.Cast<VkSampler>());
488 break;
489 }
490 case kVulkanObjectTypeQueryPool: {
491 base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>());
492 break;
493 }
494 case kVulkanObjectTypePipeline: {
495 base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>());
496 break;
497 }
498 case kVulkanObjectTypeBuffer: {
499 base_ptr = GetBufferState(object_struct.Cast<VkBuffer>());
500 break;
501 }
502 case kVulkanObjectTypeBufferView: {
503 base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>());
504 break;
505 }
506 case kVulkanObjectTypeImage: {
507 base_ptr = GetImageState(object_struct.Cast<VkImage>());
508 break;
509 }
510 case kVulkanObjectTypeImageView: {
511 base_ptr = GetImageViewState(object_struct.Cast<VkImageView>());
512 break;
513 }
514 case kVulkanObjectTypeEvent: {
515 base_ptr = GetEventState(object_struct.Cast<VkEvent>());
516 break;
517 }
518 case kVulkanObjectTypeDescriptorPool: {
519 base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>());
520 break;
521 }
522 case kVulkanObjectTypeCommandPool: {
523 base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>());
524 break;
525 }
526 case kVulkanObjectTypeFramebuffer: {
527 base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>());
528 break;
529 }
530 case kVulkanObjectTypeRenderPass: {
531 base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>());
532 break;
533 }
534 case kVulkanObjectTypeDeviceMemory: {
535 base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>());
536 break;
537 }
538 case kVulkanObjectTypeAccelerationStructureNV: {
sourav parmarcd5fb182020-07-17 12:58:44 -0700539 base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>());
540 break;
541 }
542 case kVulkanObjectTypeAccelerationStructureKHR: {
543 base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>());
locke-lunargd556cc32019-09-17 01:21:23 -0600544 break;
545 }
Jeff Bolzadbfa852019-10-04 13:53:30 -0500546 case kVulkanObjectTypeUnknown:
547 // This can happen if an element of the object_bindings vector has been
548 // zeroed out, after an object is destroyed.
549 break;
locke-lunargd556cc32019-09-17 01:21:23 -0600550 default:
551 // TODO : Any other objects to be handled here?
552 assert(0);
553 break;
554 }
555 return base_ptr;
556}
557
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700558// Gets union of all features defined by Potential Format Features
559// 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 -0700560VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
561 VkFormatFeatureFlags format_features = 0;
562
563 if (format != VK_FORMAT_UNDEFINED) {
564 VkFormatProperties format_properties;
565 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
566 format_features |= format_properties.linearTilingFeatures;
567 format_features |= format_properties.optimalTilingFeatures;
sfricke-samsung45996a42021-09-16 13:45:27 -0700568 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700569 // VK_KHR_get_physical_device_properties2 is required in this case
570 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
571 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
572 nullptr};
573 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100574
575 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700576 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100577
578 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
579 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
580 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
581
582 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
583 // compatible with the queried format
584 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
585
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700586 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
587 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
588 }
589 }
590 }
591
592 return format_features;
593}
594
locke-lunargd556cc32019-09-17 01:21:23 -0600595void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
596 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
597 VkResult result) {
598 if (VK_SUCCESS != result) return;
599
Locke Linf3873542021-04-26 11:25:10 -0600600 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
601 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
602 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
603
locke-lunargd556cc32019-09-17 01:21:23 -0600604 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
605 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700606 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600607 if (features2) {
608 enabled_features_found = &(features2->features);
609 }
610 }
611
locke-lunargd556cc32019-09-17 01:21:23 -0600612 if (nullptr == enabled_features_found) {
613 state_tracker->enabled_features.core = {};
614 } else {
615 state_tracker->enabled_features.core = *enabled_features_found;
616 }
617
locke-lunargd556cc32019-09-17 01:21:23 -0600618 // Save local link to this device's physical device state
Jeremy Gebben383b9a32021-09-08 16:31:33 -0600619 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu);
locke-lunargd556cc32019-09-17 01:21:23 -0600620
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700621 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700622 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700623 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700624 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700625 // Set Extension Feature Aliases to false as there is no struct to check
626 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
627 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
628 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
629 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
630 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
631 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800632 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700633
634 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700635
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700636 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700637 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700638 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
639 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
640 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
641 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700642 }
643
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700644 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700645 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700646 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
647 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700648 }
649
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700650 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700651 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700652 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
653 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
654 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
655 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
656 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
657 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
658 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
659 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
660 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
661 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
662 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
663 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
664 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
665 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
666 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
667 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
668 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
669 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
670 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
671 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
672 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
673 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
674 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
675 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
676 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
677 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
678 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
679 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
680 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
681 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
682 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
683 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
684 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
685 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
686 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
687 descriptor_indexing_features->descriptorBindingPartiallyBound;
688 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
689 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
690 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700691 }
692
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700693 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700694 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700695 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700696 }
697
698 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700699 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700700 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700701 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700702 }
703
704 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700705 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700706 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700707 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
708 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700709 }
710
711 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700712 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700713 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700714 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
715 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700716 }
717
718 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700719 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700720 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700721 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
722 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700723 }
724
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700725 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700726 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700727 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700728 }
729
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700730 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700731 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700732 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700733 }
734
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700735 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700736 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700737 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
738 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
739 buffer_device_address->bufferDeviceAddressCaptureReplay;
740 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
741 buffer_device_address->bufferDeviceAddressMultiDevice;
742 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800743
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700744 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800745 if (atomic_int64_features) {
746 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
747 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
748 }
749
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700750 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800751 if (memory_model_features) {
752 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
753 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
754 memory_model_features->vulkanMemoryModelDeviceScope;
755 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
756 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
757 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700758 }
759
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700760 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700761 if (vulkan_11_features) {
762 state_tracker->enabled_features.core11 = *vulkan_11_features;
763 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700764 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700765
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700766 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700767 if (sixteen_bit_storage_features) {
768 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
769 sixteen_bit_storage_features->storageBuffer16BitAccess;
770 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
771 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
772 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
773 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
774 }
775
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700776 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700777 if (multiview_features) {
778 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
779 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
780 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
781 }
782
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700783 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700784 if (variable_pointers_features) {
785 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
786 variable_pointers_features->variablePointersStorageBuffer;
787 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
788 }
789
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700790 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700791 if (protected_memory_features) {
792 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
793 }
794
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700795 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700796 if (ycbcr_conversion_features) {
797 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
798 }
799
800 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700801 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700802 if (shader_draw_parameters_features) {
803 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700804 }
805 }
806
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700807 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600808 if (device_group_ci) {
809 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
810 state_tracker->device_group_create_info = *device_group_ci;
811 } else {
812 state_tracker->physical_device_count = 1;
813 }
locke-lunargd556cc32019-09-17 01:21:23 -0600814
sfricke-samsung828e59d2021-08-22 23:20:49 -0700815 // Features from other extensions passesd in create info
816 {
817 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
818 if (exclusive_scissor_features) {
819 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
820 }
locke-lunargd556cc32019-09-17 01:21:23 -0600821
sfricke-samsung828e59d2021-08-22 23:20:49 -0700822 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
823 if (shading_rate_image_features) {
824 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
825 }
locke-lunargd556cc32019-09-17 01:21:23 -0600826
sfricke-samsung828e59d2021-08-22 23:20:49 -0700827 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
828 if (mesh_shader_features) {
829 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
830 }
locke-lunargd556cc32019-09-17 01:21:23 -0600831
sfricke-samsung828e59d2021-08-22 23:20:49 -0700832 const auto *inline_uniform_block_features =
833 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
834 if (inline_uniform_block_features) {
835 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
836 }
locke-lunargd556cc32019-09-17 01:21:23 -0600837
sfricke-samsung828e59d2021-08-22 23:20:49 -0700838 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
839 if (transform_feedback_features) {
840 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
841 }
locke-lunargd556cc32019-09-17 01:21:23 -0600842
sfricke-samsung828e59d2021-08-22 23:20:49 -0700843 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
844 if (vtx_attrib_div_features) {
845 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
846 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700847
sfricke-samsung828e59d2021-08-22 23:20:49 -0700848 const auto *buffer_device_address_ext_features =
849 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
850 if (buffer_device_address_ext_features) {
851 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
852 }
locke-lunargd556cc32019-09-17 01:21:23 -0600853
sfricke-samsung828e59d2021-08-22 23:20:49 -0700854 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
855 if (cooperative_matrix_features) {
856 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
857 }
locke-lunargd556cc32019-09-17 01:21:23 -0600858
sfricke-samsung828e59d2021-08-22 23:20:49 -0700859 const auto *compute_shader_derivatives_features =
860 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
861 if (compute_shader_derivatives_features) {
862 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
863 }
locke-lunargd556cc32019-09-17 01:21:23 -0600864
sfricke-samsung828e59d2021-08-22 23:20:49 -0700865 const auto *fragment_shader_barycentric_features =
866 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
867 if (fragment_shader_barycentric_features) {
868 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
869 }
locke-lunargd556cc32019-09-17 01:21:23 -0600870
sfricke-samsung828e59d2021-08-22 23:20:49 -0700871 const auto *shader_image_footprint_features =
872 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
873 if (shader_image_footprint_features) {
874 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
875 }
locke-lunargd556cc32019-09-17 01:21:23 -0600876
sfricke-samsung828e59d2021-08-22 23:20:49 -0700877 const auto *fragment_shader_interlock_features =
878 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
879 if (fragment_shader_interlock_features) {
880 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
881 }
locke-lunargd556cc32019-09-17 01:21:23 -0600882
sfricke-samsung828e59d2021-08-22 23:20:49 -0700883 const auto *demote_to_helper_invocation_features =
884 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
885 if (demote_to_helper_invocation_features) {
886 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
887 }
locke-lunargd556cc32019-09-17 01:21:23 -0600888
sfricke-samsung828e59d2021-08-22 23:20:49 -0700889 const auto *texel_buffer_alignment_features =
890 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
891 if (texel_buffer_alignment_features) {
892 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
893 }
locke-lunargd556cc32019-09-17 01:21:23 -0600894
sfricke-samsung828e59d2021-08-22 23:20:49 -0700895 const auto *pipeline_exe_props_features =
896 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
897 if (pipeline_exe_props_features) {
898 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
899 }
locke-lunargd556cc32019-09-17 01:21:23 -0600900
sfricke-samsung828e59d2021-08-22 23:20:49 -0700901 const auto *dedicated_allocation_image_aliasing_features =
902 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
903 if (dedicated_allocation_image_aliasing_features) {
904 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
905 *dedicated_allocation_image_aliasing_features;
906 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500907
sfricke-samsung828e59d2021-08-22 23:20:49 -0700908 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
909 if (performance_query_features) {
910 state_tracker->enabled_features.performance_query_features = *performance_query_features;
911 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100912
sfricke-samsung828e59d2021-08-22 23:20:49 -0700913 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
914 if (device_coherent_memory_features) {
915 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
916 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000917
sfricke-samsung828e59d2021-08-22 23:20:49 -0700918 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
919 if (ycbcr_image_array_features) {
920 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
921 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800922
sfricke-samsung828e59d2021-08-22 23:20:49 -0700923 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
924 if (ray_query_features) {
925 state_tracker->enabled_features.ray_query_features = *ray_query_features;
926 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700927
sfricke-samsung828e59d2021-08-22 23:20:49 -0700928 const auto *ray_tracing_pipeline_features =
929 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
930 if (ray_tracing_pipeline_features) {
931 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
932 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700933
sfricke-samsung828e59d2021-08-22 23:20:49 -0700934 const auto *ray_tracing_acceleration_structure_features =
935 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
936 if (ray_tracing_acceleration_structure_features) {
937 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
938 *ray_tracing_acceleration_structure_features;
939 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500940
sfricke-samsung828e59d2021-08-22 23:20:49 -0700941 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
942 if (robustness2_features) {
943 state_tracker->enabled_features.robustness2_features = *robustness2_features;
944 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500945
sfricke-samsung828e59d2021-08-22 23:20:49 -0700946 const auto *fragment_density_map_features =
947 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
948 if (fragment_density_map_features) {
949 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
950 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200951
sfricke-samsung828e59d2021-08-22 23:20:49 -0700952 const auto *fragment_density_map_features2 =
953 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
954 if (fragment_density_map_features2) {
955 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
956 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200957
sfricke-samsung828e59d2021-08-22 23:20:49 -0700958 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
959 if (astc_decode_features) {
960 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
961 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -0700962
sfricke-samsung828e59d2021-08-22 23:20:49 -0700963 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
964 if (custom_border_color_features) {
965 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
966 }
Tony-LunarG7337b312020-04-15 16:40:25 -0600967
sfricke-samsung828e59d2021-08-22 23:20:49 -0700968 const auto *pipeline_creation_cache_control_features =
969 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
970 if (pipeline_creation_cache_control_features) {
971 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
972 }
sfricke-samsungfd661d62020-05-16 00:57:27 -0700973
sfricke-samsung828e59d2021-08-22 23:20:49 -0700974 const auto *fragment_shading_rate_features =
975 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
976 if (fragment_shading_rate_features) {
977 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
978 }
Tobias Hector6663c9b2020-11-05 10:18:02 +0000979
sfricke-samsung828e59d2021-08-22 23:20:49 -0700980 const auto *extended_dynamic_state_features =
981 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
982 if (extended_dynamic_state_features) {
983 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
984 }
Piers Daniell39842ee2020-07-10 16:42:33 -0600985
sfricke-samsung828e59d2021-08-22 23:20:49 -0700986 const auto *extended_dynamic_state2_features =
987 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
988 if (extended_dynamic_state2_features) {
989 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
990 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -0700991
sfricke-samsung828e59d2021-08-22 23:20:49 -0700992 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
993 if (multiview_features) {
994 state_tracker->enabled_features.multiview_features = *multiview_features;
995 }
locke-lunarg3fa463a2020-10-23 16:39:04 -0600996
sfricke-samsung828e59d2021-08-22 23:20:49 -0700997 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
998 if (portability_features) {
999 state_tracker->enabled_features.portability_subset_features = *portability_features;
1000 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001001
sfricke-samsung828e59d2021-08-22 23:20:49 -07001002 const auto *shader_integer_functions2_features =
1003 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1004 if (shader_integer_functions2_features) {
1005 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1006 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001007
sfricke-samsung828e59d2021-08-22 23:20:49 -07001008 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1009 if (shader_sm_builtins_features) {
1010 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
1011 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001012
sfricke-samsung828e59d2021-08-22 23:20:49 -07001013 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1014 if (shader_atomic_float_features) {
1015 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
1016 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001017
sfricke-samsung828e59d2021-08-22 23:20:49 -07001018 const auto *shader_image_atomic_int64_features =
1019 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1020 if (shader_image_atomic_int64_features) {
1021 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
1022 }
sfricke-samsung0065ce02020-12-03 22:46:37 -08001023
sfricke-samsung828e59d2021-08-22 23:20:49 -07001024 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
1025 if (shader_clock_features) {
1026 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
1027 }
sfricke-samsung486a51e2021-01-02 00:10:15 -08001028
sfricke-samsung828e59d2021-08-22 23:20:49 -07001029 const auto *conditional_rendering_features =
1030 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
1031 if (conditional_rendering_features) {
1032 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
1033 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -07001034
sfricke-samsung828e59d2021-08-22 23:20:49 -07001035 const auto *workgroup_memory_explicit_layout_features =
1036 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
1037 if (workgroup_memory_explicit_layout_features) {
1038 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
1039 }
Shannon McPhersondb287d42021-02-02 15:27:32 -07001040
sfricke-samsung828e59d2021-08-22 23:20:49 -07001041 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
1042 if (synchronization2_features) {
1043 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
1044 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001045
sfricke-samsung828e59d2021-08-22 23:20:49 -07001046 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
1047 if (provoking_vertex_features) {
1048 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
1049 }
Locke Linf3873542021-04-26 11:25:10 -06001050
sfricke-samsung828e59d2021-08-22 23:20:49 -07001051 const auto *vertex_input_dynamic_state_features =
1052 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1053 if (vertex_input_dynamic_state_features) {
1054 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
1055 }
Piers Daniellcb6d8032021-04-19 18:51:26 -06001056
sfricke-samsung828e59d2021-08-22 23:20:49 -07001057 const auto *inherited_viewport_scissor_features =
1058 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
1059 if (inherited_viewport_scissor_features) {
1060 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
1061 }
David Zhao Akeley44139b12021-04-26 16:16:13 -07001062
sfricke-samsung828e59d2021-08-22 23:20:49 -07001063 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
1064 if (multi_draw_features) {
1065 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
1066 }
Tony-LunarG4490de42021-06-21 15:49:19 -06001067
sfricke-samsung828e59d2021-08-22 23:20:49 -07001068 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
1069 if (color_write_features) {
1070 state_tracker->enabled_features.color_write_features = *color_write_features;
1071 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +02001072
sfricke-samsung828e59d2021-08-22 23:20:49 -07001073 const auto *shader_atomic_float2_features =
1074 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
1075 if (shader_atomic_float2_features) {
1076 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
1077 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -07001078
sfricke-samsung828e59d2021-08-22 23:20:49 -07001079 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
1080 if (present_id_features) {
1081 state_tracker->enabled_features.present_id_features = *present_id_features;
1082 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001083
sfricke-samsung828e59d2021-08-22 23:20:49 -07001084 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
1085 if (present_wait_features) {
1086 state_tracker->enabled_features.present_wait_features = *present_wait_features;
1087 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -07001088
1089 const auto *ray_tracing_motion_blur_features =
1090 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
1091 if (ray_tracing_motion_blur_features) {
1092 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
1093 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -07001094
1095 const auto *shader_integer_dot_product_features =
1096 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
1097 if (shader_integer_dot_product_features) {
1098 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
1099 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -06001100
1101 const auto *primitive_topology_list_restart_features =
1102 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
1103 if (primitive_topology_list_restart_features) {
1104 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
1105 }
Tony-LunarG6f887e52021-07-27 11:23:14 -06001106 }
1107
ziga-lunarg73163742021-08-25 13:15:29 +02001108 const auto *subgroup_size_control_features = LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeaturesEXT>(pCreateInfo->pNext);
1109 if (subgroup_size_control_features) {
1110 state_tracker->enabled_features.subgroup_size_control_features = *subgroup_size_control_features;
1111 }
1112
locke-lunargd556cc32019-09-17 01:21:23 -06001113 // Store physical device properties and physical device mem limits into CoreChecks structs
1114 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1115 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
1116
1117 const auto &dev_ext = state_tracker->device_extensions;
1118 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1119
sfricke-samsung828e59d2021-08-22 23:20:49 -07001120 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
sfricke-samsung45996a42021-09-16 13:45:27 -07001121 if (dev_ext.vk_feature_version_1_2) {
1122 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
1123 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001124 } else {
1125 // VkPhysicalDeviceVulkan11Properties
1126 //
1127 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
1128
1129 if (dev_ext.vk_khr_multiview) {
1130 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
1131 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
1132 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
1133 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
1134 }
1135
1136 if (dev_ext.vk_khr_maintenance3) {
1137 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
1138 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
1139 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
1140 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
1141 }
1142
1143 // Some 1.1 properties were added to core without previous extensions
1144 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1145 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1146 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1147 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1148 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1149
1150 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1151 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1152 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1153 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1154
1155 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1156 }
1157
1158 // VkPhysicalDeviceVulkan12Properties
1159 //
1160 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1161
1162 if (dev_ext.vk_ext_descriptor_indexing) {
1163 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1164 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1165 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1166 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1167 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1168 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1169 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1170 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1171 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1172 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1173 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1174 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1175 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1176 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1177 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1178 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1179 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1180 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1181 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1182 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1183 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1184 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1185 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1186 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1187 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1188 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1189 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1190 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1191 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1192 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1193 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1194 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1195 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1196 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1197 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1198 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1199 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1200 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1201 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1202 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1203 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1204 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1205 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1206 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1207 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1208 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1209 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1210 }
1211
1212 if (dev_ext.vk_khr_depth_stencil_resolve) {
1213 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1214 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1215 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1216 depth_stencil_resolve_props.supportedDepthResolveModes;
1217 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1218 depth_stencil_resolve_props.supportedStencilResolveModes;
1219 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1220 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1221 }
1222
1223 if (dev_ext.vk_khr_timeline_semaphore) {
1224 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1225 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1226 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1227 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1228 }
1229
1230 if (dev_ext.vk_ext_sampler_filter_minmax) {
1231 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1232 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1233 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1234 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1235 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1236 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1237 }
1238
1239 if (dev_ext.vk_khr_shader_float_controls) {
1240 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1241 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1242 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1243 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1244 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1245 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1246 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1247 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1248 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1249 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1250 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1251 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1252 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1253 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1254 float_controls_props.shaderDenormFlushToZeroFloat16;
1255 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1256 float_controls_props.shaderDenormFlushToZeroFloat32;
1257 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1258 float_controls_props.shaderDenormFlushToZeroFloat64;
1259 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1260 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1261 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1262 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1263 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1264 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1265 }
locke-lunargd556cc32019-09-17 01:21:23 -06001266 }
1267
sfricke-samsung828e59d2021-08-22 23:20:49 -07001268 // Extensions with properties to extract to DeviceExtensionProperties
1269 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001270 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1271 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1272 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1273 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001274 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001275 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001276 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1277 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001278 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1279 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001280 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001281 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001282 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001283 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001284 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001285 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001286 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001287 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001288 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001289 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001290 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001291 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001292 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001293
sfricke-samsung45996a42021-09-16 13:45:27 -07001294 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001295 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001296 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1297 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001298 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1299 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1300
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001301 uint32_t num_cooperative_matrix_properties = 0;
1302 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1303 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001304 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001305
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001306 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001307 state_tracker->cooperative_matrix_properties.data());
1308 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001309
locke-lunargd556cc32019-09-17 01:21:23 -06001310 // Store queue family data
1311 if (pCreateInfo->pQueueCreateInfos != nullptr) {
1312 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001313 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001314 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1315 state_tracker->device_queue_info_list.push_back(
1316 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
locke-lunargd556cc32019-09-17 01:21:23 -06001317 }
1318 }
1319}
1320
1321void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1322 if (!device) return;
1323
locke-lunargd556cc32019-09-17 01:21:23 -06001324 // Reset all command buffers before destroying them, to unlink object_bindings.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001325 for (auto &command_buffer : commandBufferMap) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001326 command_buffer.second->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001327 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05001328 pipelineMap.clear();
1329 renderPassMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001330 commandBufferMap.clear();
1331
1332 // This will also delete all sets in the pool & remove them from setMap
1333 DeleteDescriptorSetPools();
1334 // All sets should be removed
1335 assert(setMap.empty());
1336 descriptorSetLayoutMap.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001337 // Because swapchains are associated with Surfaces, which are at instance level,
1338 // they need to be explicitly destroyed here to avoid continued references to
1339 // the device we're destroying.
1340 for (auto &entry : swapchainMap) {
1341 entry.second->Destroy();
1342 }
1343 swapchainMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001344 imageViewMap.clear();
1345 imageMap.clear();
1346 bufferViewMap.clear();
1347 bufferMap.clear();
1348 // Queues persist until device is destroyed
1349 queueMap.clear();
1350}
1351
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001352void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) {
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001353 layer_data::unordered_map<VkQueue, uint64_t> other_queue_seqs;
1354 layer_data::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters;
locke-lunargd556cc32019-09-17 01:21:23 -06001355
1356 // Roll this queue forward, one submission at a time.
1357 while (pQueue->seq < seq) {
1358 auto &submission = pQueue->submissions.front();
1359
1360 for (auto &wait : submission.waitSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001361 auto semaphore_state = GetSemaphoreState(wait.semaphore);
1362 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001363 semaphore_state->EndUse();
locke-lunargd556cc32019-09-17 01:21:23 -06001364 }
Mike Schuchardt2df08912020-12-15 16:28:09 -08001365 if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001366 auto &last_counter = timeline_semaphore_counters[wait.semaphore];
1367 last_counter = std::max(last_counter, wait.payload);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001368 } else {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001369 auto &last_seq = other_queue_seqs[wait.queue];
1370 last_seq = std::max(last_seq, wait.seq);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001371 }
locke-lunargd556cc32019-09-17 01:21:23 -06001372 }
1373
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01001374 for (auto &signal : submission.signalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001375 auto semaphore_state = GetSemaphoreState(signal.semaphore);
1376 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001377 semaphore_state->EndUse();
Mike Schuchardt2df08912020-12-15 16:28:09 -08001378 if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE && semaphore_state->payload < signal.payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001379 semaphore_state->payload = signal.payload;
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01001380 }
locke-lunargd556cc32019-09-17 01:21:23 -06001381 }
1382 }
1383
1384 for (auto &semaphore : submission.externalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001385 auto semaphore_state = GetSemaphoreState(semaphore);
1386 if (semaphore_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001387 semaphore_state->EndUse();
locke-lunargd556cc32019-09-17 01:21:23 -06001388 }
1389 }
1390
1391 for (auto cb : submission.cbs) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06001392 auto cb_node = Get<CMD_BUFFER_STATE>(cb);
locke-lunargd556cc32019-09-17 01:21:23 -06001393 if (!cb_node) {
1394 continue;
1395 }
1396 // First perform decrement on general case bound objects
locke-lunargd556cc32019-09-17 01:21:23 -06001397 for (auto event : cb_node->writeEventsBeforeWait) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001398 auto event_node = eventMap.find(event);
1399 if (event_node != eventMap.end()) {
John Zulauf48057322020-12-02 11:59:31 -07001400 event_node->second->write_in_use--;
locke-lunargd556cc32019-09-17 01:21:23 -06001401 }
1402 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001403 QueryMap local_query_to_state_map;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001404 VkQueryPool first_pool = VK_NULL_HANDLE;
Jeff Bolz310775c2019-10-09 00:46:33 -05001405 for (auto &function : cb_node->queryUpdates) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001406 function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map);
Jeff Bolz310775c2019-10-09 00:46:33 -05001407 }
1408
John Zulauf79f06582021-02-27 18:38:39 -07001409 for (const auto &query_state_pair : local_query_to_state_map) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001410 if (query_state_pair.second == QUERYSTATE_ENDED) {
1411 queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001412 }
locke-lunargd556cc32019-09-17 01:21:23 -06001413 }
Jeremy Gebben5570abe2021-05-16 18:35:13 -06001414 if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY) {
1415 cb_node->EndUse();
1416 }
locke-lunargd556cc32019-09-17 01:21:23 -06001417 }
1418
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001419 auto fence_state = GetFenceState(submission.fence);
1420 if (fence_state && fence_state->scope == kSyncScopeInternal) {
1421 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06001422 }
1423
1424 pQueue->submissions.pop_front();
1425 pQueue->seq++;
1426 }
1427
1428 // Roll other queues forward to the highest seq we saw a wait for
John Zulauf79f06582021-02-27 18:38:39 -07001429 for (const auto &qs : other_queue_seqs) {
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001430 RetireWorkOnQueue(GetQueueState(qs.first), qs.second);
locke-lunargd556cc32019-09-17 01:21:23 -06001431 }
John Zulauf79f06582021-02-27 18:38:39 -07001432 for (const auto &sc : timeline_semaphore_counters) {
Marshall Drew-Brook03847582020-11-06 15:10:45 -08001433 RetireTimelineSemaphore(sc.first, sc.second);
1434 }
locke-lunargd556cc32019-09-17 01:21:23 -06001435}
1436
1437// Submit a fence to a queue, delimiting previous fences and previous untracked
1438// work by it.
1439static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) {
1440 pFence->state = FENCE_INFLIGHT;
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001441 pFence->signaler.first = pQueue->Queue();
locke-lunargd556cc32019-09-17 01:21:23 -06001442 pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount;
1443}
1444
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001445uint64_t ValidationStateTracker::RecordSubmitFence(QUEUE_STATE *queue_state, VkFence fence, uint32_t submit_count) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001446 auto fence_state = GetFenceState(fence);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001447 uint64_t early_retire_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001448 if (fence_state) {
1449 if (fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06001450 // Mark fence in use
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001451 SubmitFence(queue_state, fence_state, std::max(1u, submit_count));
1452 if (!submit_count) {
locke-lunargd556cc32019-09-17 01:21:23 -06001453 // If no submissions, but just dropping a fence on the end of the queue,
1454 // record an empty submission with just the fence, so we can determine
1455 // its completion.
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001456 CB_SUBMISSION submission;
1457 submission.fence = fence;
1458 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001459 }
1460 } else {
1461 // Retire work up until this fence early, we will not see the wait that corresponds to this signal
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001462 early_retire_seq = queue_state->seq + queue_state->submissions.size();
locke-lunargd556cc32019-09-17 01:21:23 -06001463 }
1464 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001465 return early_retire_seq;
1466}
1467
1468void ValidationStateTracker::RecordSubmitCommandBuffer(CB_SUBMISSION &submission, VkCommandBuffer command_buffer) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06001469 auto cb_node = Get<CMD_BUFFER_STATE>(command_buffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001470 if (cb_node) {
1471 submission.cbs.push_back(command_buffer);
John Zulauf79f06582021-02-27 18:38:39 -07001472 for (auto *secondary_cmd_buffer : cb_node->linkedCommandBuffers) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001473 submission.cbs.push_back(secondary_cmd_buffer->commandBuffer());
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001474 secondary_cmd_buffer->IncrementResources();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001475 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06001476 cb_node->IncrementResources();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06001477 // increment use count for all bound objects including secondary cbs
1478 cb_node->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001479
1480 VkQueryPool first_pool = VK_NULL_HANDLE;
1481 EventToStageMap local_event_to_stage_map;
1482 QueryMap local_query_to_state_map;
1483 for (auto &function : cb_node->queryUpdates) {
1484 function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map);
1485 }
1486
John Zulauf79f06582021-02-27 18:38:39 -07001487 for (const auto &query_state_pair : local_query_to_state_map) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001488 queryToStateMap[query_state_pair.first] = query_state_pair.second;
1489 }
1490
John Zulauf79f06582021-02-27 18:38:39 -07001491 for (const auto &function : cb_node->eventUpdates) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001492 function(nullptr, /*do_validate*/ false, &local_event_to_stage_map);
1493 }
1494
John Zulauf79f06582021-02-27 18:38:39 -07001495 for (const auto &eventStagePair : local_event_to_stage_map) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001496 eventMap[eventStagePair.first]->stageMask = eventStagePair.second;
1497 }
1498 }
1499}
1500
1501void ValidationStateTracker::RecordSubmitWaitSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore,
1502 uint64_t value, uint64_t next_seq) {
1503 auto semaphore_state = GetSemaphoreState(semaphore);
1504 if (semaphore_state) {
1505 if (semaphore_state->scope == kSyncScopeInternal) {
1506 SEMAPHORE_WAIT wait;
1507 wait.semaphore = semaphore;
1508 wait.type = semaphore_state->type;
1509 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
1510 if (semaphore_state->signaler.first != VK_NULL_HANDLE) {
1511 wait.queue = semaphore_state->signaler.first;
1512 wait.seq = semaphore_state->signaler.second;
1513 submission.waitSemaphores.emplace_back(std::move(wait));
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001514 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001515 }
1516 semaphore_state->signaler.first = VK_NULL_HANDLE;
1517 semaphore_state->signaled = false;
1518 } else if (semaphore_state->payload < value) {
1519 wait.queue = queue;
1520 wait.seq = next_seq;
1521 wait.payload = value;
1522 submission.waitSemaphores.emplace_back(std::move(wait));
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001523 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001524 }
1525 } else {
1526 submission.externalSemaphores.push_back(semaphore);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001527 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001528 if (semaphore_state->scope == kSyncScopeExternalTemporary) {
1529 semaphore_state->scope = kSyncScopeInternal;
1530 }
1531 }
1532 }
1533}
1534
1535bool ValidationStateTracker::RecordSubmitSignalSemaphore(CB_SUBMISSION &submission, VkQueue queue, VkSemaphore semaphore,
1536 uint64_t value, uint64_t next_seq) {
1537 bool retire_early = false;
1538 auto semaphore_state = GetSemaphoreState(semaphore);
1539 if (semaphore_state) {
1540 if (semaphore_state->scope == kSyncScopeInternal) {
1541 SEMAPHORE_SIGNAL signal;
1542 signal.semaphore = semaphore;
1543 signal.seq = next_seq;
1544 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
1545 semaphore_state->signaler.first = queue;
1546 semaphore_state->signaler.second = next_seq;
1547 semaphore_state->signaled = true;
1548 } else {
1549 signal.payload = value;
1550 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001551 semaphore_state->BeginUse();
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001552 submission.signalSemaphores.emplace_back(std::move(signal));
1553 } else {
1554 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
1555 retire_early = true;
1556 }
1557 }
1558 return retire_early;
1559}
1560
1561void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1562 VkFence fence, VkResult result) {
1563 if (result != VK_SUCCESS) return;
1564 auto queue_state = GetQueueState(queue);
1565
1566 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount);
locke-lunargd556cc32019-09-17 01:21:23 -06001567
1568 // Now process each individual submit
1569 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001570 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001571 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001572 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001573 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001574 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001575 uint64_t value = 0;
1576 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1577 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1578 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1579 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001580 RecordSubmitWaitSemaphore(submission, queue, submit->pWaitSemaphores[i], value, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001581 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001582
1583 bool retire_early = false;
locke-lunargd556cc32019-09-17 01:21:23 -06001584 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001585 uint64_t value = 0;
1586 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1587 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1588 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1589 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001590 retire_early |= RecordSubmitSignalSemaphore(submission, queue, submit->pSignalSemaphores[i], value, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001591 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001592 if (retire_early) {
1593 early_retire_seq = std::max(early_retire_seq, next_seq);
1594 }
1595
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001596 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001597 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001598
locke-lunargd556cc32019-09-17 01:21:23 -06001599 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001600 RecordSubmitCommandBuffer(submission, submit->pCommandBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06001601 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001602 submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE;
1603 queue_state->submissions.emplace_back(std::move(submission));
1604 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001605
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001606 if (early_retire_seq) {
1607 RetireWorkOnQueue(queue_state, early_retire_seq);
1608 }
1609}
1610
1611void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1612 VkFence fence, VkResult result) {
1613 if (result != VK_SUCCESS) return;
1614 auto queue_state = GetQueueState(queue);
1615
1616 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, submitCount);
1617
1618 // Now process each individual submit
1619 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1620 CB_SUBMISSION submission;
1621 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
1622 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
1623 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1624 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
1625 RecordSubmitWaitSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq);
1626 }
1627 bool retire_early = false;
1628 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1629 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
1630 retire_early |= RecordSubmitSignalSemaphore(submission, queue, sem_info.semaphore, sem_info.value, next_seq);
1631 }
1632 if (retire_early) {
1633 early_retire_seq = std::max(early_retire_seq, next_seq);
1634 }
1635 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1636 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1637
1638 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
1639 RecordSubmitCommandBuffer(submission, submit->pCommandBufferInfos[i].commandBuffer);
1640 }
1641 submission.fence = submit_idx == (submitCount - 1) ? fence : VK_NULL_HANDLE;
1642 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001643 }
1644
1645 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001646 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001647 }
1648}
1649
1650void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1651 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1652 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001653 if (VK_SUCCESS != result) {
1654 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001655 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001656 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1657 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1658 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1659
1660 layer_data::optional<DedicatedBinding> dedicated_binding;
1661
1662 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1663 if (dedicated) {
1664 if (dedicated->buffer) {
1665 const auto *buffer_state = GetBufferState(dedicated->buffer);
1666 assert(buffer_state);
1667 if (!buffer_state) {
1668 return;
1669 }
1670 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1671 } else if (dedicated->image) {
1672 const auto *image_state = GetImageState(dedicated->image);
1673 assert(image_state);
1674 if (!image_state) {
1675 return;
1676 }
1677 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1678 }
1679 }
1680 memObjMap[*pMemory] = std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
ziga-lunarg9663f4f2021-09-30 17:24:01 +02001681 std::move(dedicated_binding), physical_device_count);
locke-lunargd556cc32019-09-17 01:21:23 -06001682 return;
1683}
1684
1685void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
1686 if (!mem) return;
1687 DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001688 if (!mem_info) return;
locke-lunargd556cc32019-09-17 01:21:23 -06001689 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001690 mem_info->Destroy();
John Zulauf79952712020-04-07 11:25:54 -06001691 fake_memory.Free(mem_info->fake_base_address);
locke-lunargd556cc32019-09-17 01:21:23 -06001692 memObjMap.erase(mem);
1693}
1694
1695void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1696 VkFence fence, VkResult result) {
1697 if (result != VK_SUCCESS) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001698 auto queue_state = GetQueueState(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001699
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001700 uint64_t early_retire_seq = RecordSubmitFence(queue_state, fence, bindInfoCount);
locke-lunargd556cc32019-09-17 01:21:23 -06001701
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001702 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1703 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001704 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001705 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1706 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1707 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001708 auto buffer_state = GetBufferState(bind_info.pBufferBinds[j].buffer);
1709 auto mem_state = GetDevMemShared(sparse_binding.memory);
1710 if (buffer_state && mem_state) {
1711 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1712 }
locke-lunargd556cc32019-09-17 01:21:23 -06001713 }
1714 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001715 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1716 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1717 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001718 auto image_state = GetImageState(bind_info.pImageOpaqueBinds[j].image);
1719 auto mem_state = GetDevMemShared(sparse_binding.memory);
1720 if (image_state && mem_state) {
1721 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1722 }
locke-lunargd556cc32019-09-17 01:21:23 -06001723 }
1724 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001725 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1726 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1727 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001728 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1729 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001730 auto image_state = GetImageState(bind_info.pImageBinds[j].image);
1731 auto mem_state = GetDevMemShared(sparse_binding.memory);
1732 if (image_state && mem_state) {
1733 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1734 }
locke-lunargd556cc32019-09-17 01:21:23 -06001735 }
1736 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001737 CB_SUBMISSION submission;
1738 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001739 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001740 RecordSubmitWaitSemaphore(submission, queue, bind_info.pWaitSemaphores[i], 0, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001741 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001742 bool retire_early = false;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001743 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001744 retire_early |= RecordSubmitSignalSemaphore(submission, queue, bind_info.pSignalSemaphores[i], 0, next_seq);
1745 }
1746 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
1747 if (retire_early) {
1748 early_retire_seq = std::max(early_retire_seq, queue_state->seq + queue_state->submissions.size() + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06001749 }
1750
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001751 submission.fence = bind_idx == (bindInfoCount - 1) ? fence : VK_NULL_HANDLE;
1752 queue_state->submissions.emplace_back(std::move(submission));
locke-lunargd556cc32019-09-17 01:21:23 -06001753 }
1754
1755 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001756 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001757 }
1758}
1759
1760void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1761 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1762 VkResult result) {
1763 if (VK_SUCCESS != result) return;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001764 semaphoreMap[*pSemaphore] = std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext));
locke-lunargd556cc32019-09-17 01:21:23 -06001765}
1766
Mike Schuchardt2df08912020-12-15 16:28:09 -08001767void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1768 VkSemaphoreImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06001769 SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore);
1770 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001771 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06001772 sema_node->scope == kSyncScopeInternal) {
1773 sema_node->scope = kSyncScopeExternalTemporary;
1774 } else {
1775 sema_node->scope = kSyncScopeExternalPermanent;
1776 }
1777 }
1778}
1779
Mike Schuchardt2df08912020-12-15 16:28:09 -08001780void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001781 VkResult result) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001782 auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore);
1783 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001784}
1785
locke-lunargd556cc32019-09-17 01:21:23 -06001786void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
1787 auto mem_info = GetDevMemState(mem);
1788 if (mem_info) {
1789 mem_info->mapped_range.offset = offset;
1790 mem_info->mapped_range.size = size;
1791 mem_info->p_driver_data = *ppData;
1792 }
1793}
1794
1795void ValidationStateTracker::RetireFence(VkFence fence) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001796 auto fence_state = GetFenceState(fence);
1797 if (fence_state && fence_state->scope == kSyncScopeInternal) {
1798 if (fence_state->signaler.first != VK_NULL_HANDLE) {
locke-lunargd556cc32019-09-17 01:21:23 -06001799 // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001800 RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second);
locke-lunargd556cc32019-09-17 01:21:23 -06001801 } else {
1802 // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark
1803 // the fence as retired.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001804 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06001805 }
1806 }
1807}
1808
1809void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1810 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1811 if (VK_SUCCESS != result) return;
1812
1813 // When we know that all fences are complete we can clean/remove their CBs
1814 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1815 for (uint32_t i = 0; i < fenceCount; i++) {
1816 RetireFence(pFences[i]);
1817 }
1818 }
1819 // NOTE : Alternate case not handled here is when some fences have completed. In
1820 // this case for app to guarantee which fences completed it will have to call
1821 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1822}
1823
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001824void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001825 auto semaphore_state = GetSemaphoreState(semaphore);
1826 if (semaphore_state) {
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001827 for (const auto &pair : queueMap) {
1828 const auto &queue_state = pair.second;
Tony-LunarG47d5e272020-04-07 15:35:55 -06001829 uint64_t max_seq = 0;
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001830 for (const auto &submission : queue_state->submissions) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001831 for (const auto &signal_semaphore : submission.signalSemaphores) {
1832 if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) {
1833 if (signal_semaphore.seq > max_seq) {
1834 max_seq = signal_semaphore.seq;
Tony-LunarG47d5e272020-04-07 15:35:55 -06001835 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001836 }
1837 }
1838 }
Tony-LunarG47d5e272020-04-07 15:35:55 -06001839 if (max_seq) {
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001840 RetireWorkOnQueue(queue_state.get(), max_seq);
Tony-LunarG47d5e272020-04-07 15:35:55 -06001841 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001842 }
1843 }
1844}
1845
John Zulauff89de662020-04-13 18:57:34 -06001846void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1847 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001848 if (VK_SUCCESS != result) return;
1849
1850 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
1851 RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]);
1852 }
1853}
1854
John Zulauff89de662020-04-13 18:57:34 -06001855void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1856 VkResult result) {
1857 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1858}
1859
1860void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1861 uint64_t timeout, VkResult result) {
1862 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1863}
1864
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001865void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1866 VkResult result) {
1867 if (VK_SUCCESS != result) return;
1868
1869 RetireTimelineSemaphore(semaphore, *pValue);
1870}
1871
1872void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1873 VkResult result) {
1874 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1875}
1876void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1877 VkResult result) {
1878 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1879}
1880
locke-lunargd556cc32019-09-17 01:21:23 -06001881void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1882 if (VK_SUCCESS != result) return;
1883 RetireFence(fence);
1884}
1885
1886void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) {
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001887 queueMap.emplace(queue, std::make_shared<QUEUE_STATE>(queue, queue_family_index));
locke-lunargd556cc32019-09-17 01:21:23 -06001888}
1889
1890void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
1891 VkQueue *pQueue) {
1892 RecordGetDeviceQueueState(queueFamilyIndex, *pQueue);
1893}
1894
1895void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
1896 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue);
1897}
1898
1899void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1900 if (VK_SUCCESS != result) return;
1901 QUEUE_STATE *queue_state = GetQueueState(queue);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05001902 RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06001903}
1904
1905void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1906 if (VK_SUCCESS != result) return;
1907 for (auto &queue : queueMap) {
Jeremy Gebben63f3cb02021-09-07 15:16:32 -06001908 RetireWorkOnQueue(queue.second.get(), queue.second->seq + queue.second->submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06001909 }
1910}
1911
1912void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
1913 if (!fence) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001914 auto fence_state = GetFenceState(fence);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001915 fence_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001916 fenceMap.erase(fence);
1917}
1918
1919void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1920 const VkAllocationCallbacks *pAllocator) {
1921 if (!semaphore) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001922 auto semaphore_state = GetSemaphoreState(semaphore);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001923 semaphore_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001924 semaphoreMap.erase(semaphore);
1925}
1926
1927void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
1928 if (!event) return;
John Zulauf48057322020-12-02 11:59:31 -07001929 EVENT_STATE *event_state = Get<EVENT_STATE>(event);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001930 event_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001931 eventMap.erase(event);
1932}
1933
1934void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1935 const VkAllocationCallbacks *pAllocator) {
1936 if (!queryPool) return;
1937 QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001938 qp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06001939 queryPoolMap.erase(queryPool);
1940}
1941
locke-lunargd556cc32019-09-17 01:21:23 -06001942void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
1943 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1944 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001945 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001946 auto mem_state = GetDevMemShared(mem);
1947 if (mem_state) {
1948 buffer_state->SetMemBinding(mem_state, memoryOffset);
1949 }
locke-lunargd556cc32019-09-17 01:21:23 -06001950 }
1951}
1952
1953void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1954 VkDeviceSize memoryOffset, VkResult result) {
1955 if (VK_SUCCESS != result) return;
1956 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1957}
1958
1959void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001960 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001961 for (uint32_t i = 0; i < bindInfoCount; i++) {
1962 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1963 }
1964}
1965
1966void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001967 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001968 for (uint32_t i = 0; i < bindInfoCount; i++) {
1969 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1970 }
1971}
1972
Spencer Fricke6c127102020-04-16 06:25:20 -07001973void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
locke-lunargd556cc32019-09-17 01:21:23 -06001974 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1975 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001976 buffer_state->memory_requirements_checked = true;
1977 }
1978}
1979
1980void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1981 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001982 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001983}
1984
1985void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001986 const VkBufferMemoryRequirementsInfo2 *pInfo,
1987 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001988 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001989}
1990
1991void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001992 const VkBufferMemoryRequirementsInfo2 *pInfo,
1993 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001994 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001995}
1996
Spencer Fricke6c127102020-04-16 06:25:20 -07001997void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001998 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001999 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002000 IMAGE_STATE *image_state = GetImageState(image);
2001 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002002 if (plane_info != nullptr) {
2003 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002004 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002005 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002006 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002007 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002008 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002009 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002010 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002011 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002012 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002013 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002014 }
locke-lunargd556cc32019-09-17 01:21:23 -06002015 }
2016}
2017
2018void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
2019 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002020 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002021}
2022
2023void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
2024 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002025 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002026}
2027
2028void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
2029 const VkImageMemoryRequirementsInfo2 *pInfo,
2030 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002031 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002032}
2033
locke-lunargd556cc32019-09-17 01:21:23 -06002034void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2035 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2036 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
2037 auto image_state = GetImageState(image);
2038 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002039}
2040
2041void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002042 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2043 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002044 auto image_state = GetImageState(pInfo->image);
2045 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002046}
2047
2048void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002049 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2050 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002051 auto image_state = GetImageState(pInfo->image);
2052 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002053}
2054
2055void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2056 const VkAllocationCallbacks *pAllocator) {
2057 if (!shaderModule) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002058 auto shader_module_state = GetShaderModuleState(shaderModule);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002059 shader_module_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002060 shaderModuleMap.erase(shaderModule);
2061}
2062
2063void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2064 const VkAllocationCallbacks *pAllocator) {
2065 if (!pipeline) return;
2066 PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06002067 // Any bound cmd buffers are now invalid
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002068 pipeline_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002069 pipelineMap.erase(pipeline);
2070}
2071
2072void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2073 const VkAllocationCallbacks *pAllocator) {
2074 if (!pipelineLayout) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002075 auto pipeline_layout_state = GetPipelineLayout(pipelineLayout);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002076 pipeline_layout_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002077 pipelineLayoutMap.erase(pipelineLayout);
2078}
2079
2080void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2081 const VkAllocationCallbacks *pAllocator) {
2082 if (!sampler) return;
2083 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06002084 // Any bound cmd buffers are now invalid
2085 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04002086 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2087 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2088 custom_border_color_sampler_count--;
2089 }
2090
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002091 sampler_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002092 }
2093 samplerMap.erase(sampler);
2094}
2095
2096void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2097 const VkAllocationCallbacks *pAllocator) {
2098 if (!descriptorSetLayout) return;
2099 auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout);
2100 if (layout_it != descriptorSetLayoutMap.end()) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002101 layout_it->second.get()->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002102 descriptorSetLayoutMap.erase(layout_it);
2103 }
2104}
2105
2106void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2107 const VkAllocationCallbacks *pAllocator) {
2108 if (!descriptorPool) return;
2109 DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002110 if (desc_pool_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002111 // Free sets that were in this pool
John Zulauf79f06582021-02-27 18:38:39 -07002112 for (auto *ds : desc_pool_state->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -06002113 FreeDescriptorSet(ds);
2114 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002115 desc_pool_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002116 descriptorPoolMap.erase(descriptorPool);
2117 }
2118}
2119
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002120// Free all command buffers in given list, removing all references/links to them using CMD_BUFFER_STATE::Reset
locke-lunargd556cc32019-09-17 01:21:23 -06002121void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count,
2122 const VkCommandBuffer *command_buffers) {
2123 for (uint32_t i = 0; i < command_buffer_count; i++) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002124 auto cb_state = Get<CMD_BUFFER_STATE>(command_buffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002125 // Remove references to command buffer's state and delete
2126 if (cb_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002127 cb_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002128 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002129 // Remove CBState from CB map
2130 pool_state->commandBuffers.erase(command_buffers[i]);
2131 commandBufferMap.erase(command_buffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002132 }
2133}
2134
2135void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
2136 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002137 auto pool = GetCommandPoolState(commandPool);
2138 FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06002139}
2140
2141void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
2142 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
2143 VkResult result) {
2144 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002145 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben159b3cc2021-06-03 09:09:03 -06002146 commandPoolMap[*pCommandPool] = std::make_shared<COMMAND_POOL_STATE>(*pCommandPool, pCreateInfo, queue_flags);
locke-lunargd556cc32019-09-17 01:21:23 -06002147}
2148
2149void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
2150 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
2151 VkResult result) {
2152 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002153
2154 uint32_t index_count = 0, n_perf_pass = 0;
2155 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002156 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002157 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002158 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002159
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06002160 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002161 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
2162 const auto &counter = counters.counters[perf->pCounterIndices[i]];
2163 switch (counter.scope) {
2164 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002165 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002166 break;
2167 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002168 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002169 break;
2170 default:
2171 break;
2172 }
2173 }
2174
Jeremy Gebben383b9a32021-09-08 16:31:33 -06002175 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002176 }
2177
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06002178 queryPoolMap[*pQueryPool] =
2179 std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb);
locke-lunargd556cc32019-09-17 01:21:23 -06002180
2181 QueryObject query_obj{*pQueryPool, 0u};
2182 for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) {
2183 query_obj.query = i;
2184 queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN;
2185 }
2186}
2187
2188void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
2189 const VkAllocationCallbacks *pAllocator) {
2190 if (!commandPool) return;
2191 COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool);
2192 // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers
2193 // "When a pool is destroyed, all command buffers allocated from the pool are freed."
2194 if (cp_state) {
2195 // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration.
2196 std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()};
2197 FreeCommandBufferStates(cp_state, static_cast<uint32_t>(cb_vec.size()), cb_vec.data());
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002198 cp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002199 commandPoolMap.erase(commandPool);
2200 }
2201}
2202
2203void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
2204 VkCommandPoolResetFlags flags, VkResult result) {
2205 if (VK_SUCCESS != result) return;
2206 // Reset all of the CBs allocated from this pool
2207 auto command_pool_state = GetCommandPoolState(commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002208 for (auto cmd_buffer : command_pool_state->commandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002209 auto cb_state = Get<CMD_BUFFER_STATE>(cmd_buffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002210 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002211 }
2212}
2213
2214void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2215 VkResult result) {
2216 for (uint32_t i = 0; i < fenceCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002217 auto fence_state = GetFenceState(pFences[i]);
2218 if (fence_state) {
2219 if (fence_state->scope == kSyncScopeInternal) {
2220 fence_state->state = FENCE_UNSIGNALED;
2221 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
2222 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06002223 }
2224 }
2225 }
2226}
2227
locke-lunargd556cc32019-09-17 01:21:23 -06002228void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
2229 const VkAllocationCallbacks *pAllocator) {
2230 if (!framebuffer) return;
2231 FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002232 framebuffer_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002233 frameBufferMap.erase(framebuffer);
2234}
2235
2236void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
2237 const VkAllocationCallbacks *pAllocator) {
2238 if (!renderPass) return;
2239 RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002240 rp_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06002241 renderPassMap.erase(renderPass);
2242}
2243
2244void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
2245 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
2246 if (VK_SUCCESS != result) return;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002247 fenceMap[*pFence] = std::make_shared<FENCE_STATE>(*pFence, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002248}
2249
2250bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2251 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2252 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002253 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002254 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
2255 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2256 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2257 cgpl_state->pipe_state.reserve(count);
2258 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002259 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
2260 GetRenderPassShared(pCreateInfos[i].renderPass),
2261 GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002262 }
2263 return false;
2264}
2265
2266void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2267 const VkGraphicsPipelineCreateInfo *pCreateInfos,
2268 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2269 VkResult result, void *cgpl_state_data) {
2270 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
2271 // This API may create pipelines regardless of the return value
2272 for (uint32_t i = 0; i < count; i++) {
2273 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002274 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002275 pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]);
2276 }
2277 }
2278 cgpl_state->pipe_state.clear();
2279}
2280
2281bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2282 const VkComputePipelineCreateInfo *pCreateInfos,
2283 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002284 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002285 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2286 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
2287 ccpl_state->pipe_state.reserve(count);
2288 for (uint32_t i = 0; i < count; i++) {
2289 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002290 ccpl_state->pipe_state.push_back(
2291 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002292 }
2293 return false;
2294}
2295
2296void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
2297 const VkComputePipelineCreateInfo *pCreateInfos,
2298 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
2299 VkResult result, void *ccpl_state_data) {
2300 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
2301
2302 // This API may create pipelines regardless of the return value
2303 for (uint32_t i = 0; i < count; i++) {
2304 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002305 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002306 pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]);
2307 }
2308 }
2309 ccpl_state->pipe_state.clear();
2310}
2311
2312bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
2313 uint32_t count,
2314 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2315 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002316 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002317 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2318 crtpl_state->pipe_state.reserve(count);
2319 for (uint32_t i = 0; i < count; i++) {
2320 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002321 crtpl_state->pipe_state.push_back(
2322 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06002323 }
2324 return false;
2325}
2326
2327void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
2328 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
2329 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
2330 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
2331 // This API may create pipelines regardless of the return value
2332 for (uint32_t i = 0; i < count; i++) {
2333 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002334 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002335 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2336 }
2337 }
2338 crtpl_state->pipe_state.clear();
2339}
2340
sourav parmarcd5fb182020-07-17 12:58:44 -07002341bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2342 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002343 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2344 const VkAllocationCallbacks *pAllocator,
2345 VkPipeline *pPipelines, void *crtpl_state_data) const {
2346 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2347 crtpl_state->pipe_state.reserve(count);
2348 for (uint32_t i = 0; i < count; i++) {
2349 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06002350 crtpl_state->pipe_state.push_back(
2351 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002352 }
2353 return false;
2354}
2355
sourav parmarcd5fb182020-07-17 12:58:44 -07002356void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
2357 VkPipelineCache pipelineCache, uint32_t count,
2358 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
2359 const VkAllocationCallbacks *pAllocator,
2360 VkPipeline *pPipelines, VkResult result,
2361 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002362 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
2363 // This API may create pipelines regardless of the return value
2364 for (uint32_t i = 0; i < count; i++) {
2365 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002366 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002367 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
2368 }
2369 }
2370 crtpl_state->pipe_state.clear();
2371}
2372
locke-lunargd556cc32019-09-17 01:21:23 -06002373void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
2374 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
2375 VkResult result) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002376 samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002377 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2378 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06002379 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002380 }
locke-lunargd556cc32019-09-17 01:21:23 -06002381}
2382
2383void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
2384 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
2385 const VkAllocationCallbacks *pAllocator,
2386 VkDescriptorSetLayout *pSetLayout, VkResult result) {
2387 if (VK_SUCCESS != result) return;
2388 descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout);
2389}
2390
locke-lunargd556cc32019-09-17 01:21:23 -06002391void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
2392 const VkAllocationCallbacks *pAllocator,
2393 VkPipelineLayout *pPipelineLayout, VkResult result) {
2394 if (VK_SUCCESS != result) return;
2395
Jeremy Gebbene6e45542021-08-05 16:39:49 -06002396 pipelineLayoutMap[*pPipelineLayout] = std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002397}
2398
2399void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2400 const VkAllocationCallbacks *pAllocator,
2401 VkDescriptorPool *pDescriptorPool, VkResult result) {
2402 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002403 descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002404}
2405
2406void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2407 VkDescriptorPoolResetFlags flags, VkResult result) {
2408 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002409 DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06002410 // TODO: validate flags
2411 // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet
John Zulauf79f06582021-02-27 18:38:39 -07002412 for (auto *ds : pool->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -06002413 FreeDescriptorSet(ds);
2414 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002415 pool->sets.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06002416 // Reset available count for each type and available sets for this pool
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002417 for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) {
2418 pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first];
locke-lunargd556cc32019-09-17 01:21:23 -06002419 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002420 pool->availableSets = pool->maxSets;
locke-lunargd556cc32019-09-17 01:21:23 -06002421}
2422
2423bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
2424 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002425 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06002426 // Always update common data
2427 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2428 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2429 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
2430
2431 return false;
2432}
2433
2434// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
2435void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
2436 VkDescriptorSet *pDescriptorSets, VkResult result,
2437 void *ads_state_data) {
2438 if (VK_SUCCESS != result) return;
2439 // All the updates are contained in a single cvdescriptorset function
2440 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2441 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
2442 PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state);
2443}
2444
2445void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2446 const VkDescriptorSet *pDescriptorSets) {
2447 DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool);
2448 // Update available descriptor sets in pool
2449 pool_state->availableSets += count;
2450
2451 // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap
2452 for (uint32_t i = 0; i < count; ++i) {
2453 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
2454 auto descriptor_set = setMap[pDescriptorSets[i]].get();
2455 uint32_t type_index = 0, descriptor_count = 0;
2456 for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) {
2457 type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j));
2458 descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j);
2459 pool_state->availableDescriptorTypeCount[type_index] += descriptor_count;
2460 }
2461 FreeDescriptorSet(descriptor_set);
2462 pool_state->sets.erase(descriptor_set);
2463 }
2464 }
2465}
2466
2467void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2468 const VkWriteDescriptorSet *pDescriptorWrites,
2469 uint32_t descriptorCopyCount,
2470 const VkCopyDescriptorSet *pDescriptorCopies) {
2471 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2472 pDescriptorCopies);
2473}
2474
2475void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
2476 VkCommandBuffer *pCommandBuffer, VkResult result) {
2477 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002478 auto pool = GetCommandPoolShared(pCreateInfo->commandPool);
2479 if (pool) {
locke-lunargd556cc32019-09-17 01:21:23 -06002480 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
2481 // Add command buffer to its commandPool map
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002482 pool->commandBuffers.insert(pCommandBuffer[i]);
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002483 commandBufferMap[pCommandBuffer[i]] = CreateCmdBufferState(pCommandBuffer[i], pCreateInfo, pool);
locke-lunargfc78e932020-11-19 17:06:24 -07002484 }
2485 }
2486}
2487
locke-lunargd556cc32019-09-17 01:21:23 -06002488void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2489 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002490 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002491 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002492
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002493 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002494}
2495
2496void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002497 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002498 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002499
2500 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002501}
2502
2503void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2504 VkResult result) {
2505 if (VK_SUCCESS == result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002506 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002507 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002508 }
2509}
2510
2511CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2512 // initially assume everything is static state
2513 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2514
2515 if (ds) {
2516 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002517 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002518 }
2519 }
locke-lunargd556cc32019-09-17 01:21:23 -06002520 return flags;
2521}
2522
2523// Validation cache:
2524// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002525
2526void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2527 VkPipeline pipeline) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002528 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002529 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002530 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002531
2532 auto pipe_state = GetPipelineState(pipeline);
2533 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002534 const auto &create_info = pipe_state->create_info.graphics;
2535 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2536 const auto *viewport_state = create_info.pViewportState;
2537 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002538 cb_state->status &= ~cb_state->static_status;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002539 cb_state->static_status = MakeStaticStateMask(dynamic_state->ptr());
locke-lunargd556cc32019-09-17 01:21:23 -06002540 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002541 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002542
2543 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002544 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2545 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002546 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002547 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002548 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002549 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002550 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002551 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002552
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002553 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002554 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2555 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2556 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002557 if (!has_dynamic_viewport_count) {
2558 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002559 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002560 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2561 // should become = ~uint32_t(0) if the other interpretation is correct.
2562 }
2563 }
2564 if (!has_dynamic_scissor_count) {
2565 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002566 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002567 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2568 // should become = ~uint32_t(0) if the other interpretation is correct.
2569 }
2570 }
locke-lunargd556cc32019-09-17 01:21:23 -06002571 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002572 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2573 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002574 if (!disabled[command_buffer_state]) {
2575 cb_state->AddChild(pipe_state);
2576 }
locke-lunargb8be8222020-10-20 00:34:37 -06002577 for (auto &slot : pipe_state->active_slots) {
2578 for (auto &req : slot.second) {
2579 for (auto &sampler : req.second.samplers_used_by_image) {
2580 for (auto &des : sampler) {
2581 des.second = nullptr;
2582 }
2583 }
2584 }
2585 }
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002586 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
locke-lunargd556cc32019-09-17 01:21:23 -06002587}
2588
2589void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2590 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002591 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002592 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002593 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2594 cb_state->viewportMask |= bits;
2595 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002596
2597 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2598 for (size_t i = 0; i < viewportCount; ++i) {
2599 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2600 }
locke-lunargd556cc32019-09-17 01:21:23 -06002601}
2602
2603void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2604 uint32_t exclusiveScissorCount,
2605 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002606 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002607 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002608 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2609 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002610}
2611
2612void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2613 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002614 if (disabled[command_buffer_state]) return;
2615
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002616 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002617 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002618
2619 if (imageView != VK_NULL_HANDLE) {
2620 auto view_state = GetImageViewState(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002621 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002622 }
2623}
2624
2625void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2626 uint32_t viewportCount,
2627 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002628 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002629 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002630 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2631 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002632}
2633
2634void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2635 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2636 const VkAllocationCallbacks *pAllocator,
2637 VkAccelerationStructureNV *pAccelerationStructure,
2638 VkResult result) {
2639 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002640 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002641
2642 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002643 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002644 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002645 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002646 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2647
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002648 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002649 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002650 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002651 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2652 &as_state->build_scratch_memory_requirements);
2653
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002654 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002655 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002656 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002657 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2658 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002659 as_state->allocator = pAllocator;
locke-lunargd556cc32019-09-17 01:21:23 -06002660 accelerationStructureMap[*pAccelerationStructure] = std::move(as_state);
2661}
2662
Jeff Bolz95176d02020-04-01 00:36:16 -05002663void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2664 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2665 const VkAllocationCallbacks *pAllocator,
2666 VkAccelerationStructureKHR *pAccelerationStructure,
2667 VkResult result) {
2668 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002669 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002670 as_state->allocator = pAllocator;
sourav parmarcd5fb182020-07-17 12:58:44 -07002671 accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state);
Jeff Bolz95176d02020-04-01 00:36:16 -05002672}
2673
sourav parmarcd5fb182020-07-17 12:58:44 -07002674void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2675 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2676 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002677 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002678 if (cb_state == nullptr) {
2679 return;
2680 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002681 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002682 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002683 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002684 if (dst_as_state != nullptr) {
2685 dst_as_state->built = true;
2686 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002687 if (!disabled[command_buffer_state]) {
2688 cb_state->AddChild(dst_as_state);
2689 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002690 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002691 if (!disabled[command_buffer_state]) {
2692 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2693 if (src_as_state != nullptr) {
2694 cb_state->AddChild(src_as_state);
2695 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002696 }
2697 }
2698 cb_state->hasBuildAccelerationStructureCmd = true;
2699}
2700
2701void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2702 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2703 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2704 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002705 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002706 if (cb_state == nullptr) {
2707 return;
2708 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002709 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002710 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002711 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002712 if (dst_as_state != nullptr) {
2713 dst_as_state->built = true;
2714 dst_as_state->build_info_khr.initialize(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002715 if (!disabled[command_buffer_state]) {
2716 cb_state->AddChild(dst_as_state);
2717 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002718 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002719 if (!disabled[command_buffer_state]) {
2720 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2721 if (src_as_state != nullptr) {
2722 cb_state->AddChild(src_as_state);
2723 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002724 }
2725 }
2726 cb_state->hasBuildAccelerationStructureCmd = true;
2727}
locke-lunargd556cc32019-09-17 01:21:23 -06002728void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002729 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002730 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002731 if (as_state != nullptr) {
2732 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2733 as_state->memory_requirements = *pMemoryRequirements;
2734 as_state->memory_requirements_checked = true;
2735 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2736 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2737 as_state->build_scratch_memory_requirements_checked = true;
2738 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2739 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2740 as_state->update_scratch_memory_requirements_checked = true;
2741 }
2742 }
2743}
2744
sourav parmarcd5fb182020-07-17 12:58:44 -07002745void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2746 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002747 if (VK_SUCCESS != result) return;
2748 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002749 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002750
sourav parmarcd5fb182020-07-17 12:58:44 -07002751 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002752 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002753 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002754 auto mem_state = GetDevMemShared(info.memory);
2755 if (mem_state) {
2756 as_state->SetMemBinding(mem_state, info.memoryOffset);
2757 }
locke-lunargd556cc32019-09-17 01:21:23 -06002758
2759 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002760 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002761 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002762 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2763 }
2764 }
2765 }
2766}
2767
2768void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2769 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2770 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002771 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002772 if (cb_state == nullptr) {
2773 return;
2774 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002775 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002776
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002777 auto *dst_as_state = GetAccelerationStructureStateNV(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002778 if (dst_as_state != nullptr) {
2779 dst_as_state->built = true;
2780 dst_as_state->build_info.initialize(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002781 if (!disabled[command_buffer_state]) {
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002782 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002783 }
locke-lunargd556cc32019-09-17 01:21:23 -06002784 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002785 if (!disabled[command_buffer_state]) {
2786 auto *src_as_state = GetAccelerationStructureStateNV(src);
2787 if (src_as_state != nullptr) {
2788 cb_state->AddChild(src_as_state);
2789 }
locke-lunargd556cc32019-09-17 01:21:23 -06002790 }
2791 cb_state->hasBuildAccelerationStructureCmd = true;
2792}
2793
2794void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2795 VkAccelerationStructureNV dst,
2796 VkAccelerationStructureNV src,
2797 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002798 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002799 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002800 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
2801 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002802 if (!disabled[command_buffer_state]) {
2803 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2804 }
locke-lunargd556cc32019-09-17 01:21:23 -06002805 if (dst_as_state != nullptr && src_as_state != nullptr) {
2806 dst_as_state->built = true;
2807 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002808 }
2809 }
2810}
2811
Jeff Bolz95176d02020-04-01 00:36:16 -05002812void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2813 VkAccelerationStructureKHR accelerationStructure,
2814 const VkAllocationCallbacks *pAllocator) {
locke-lunargd556cc32019-09-17 01:21:23 -06002815 if (!accelerationStructure) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002816 auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002817 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002818 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002819 accelerationStructureMap_khr.erase(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002820 }
2821}
2822
Jeff Bolz95176d02020-04-01 00:36:16 -05002823void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2824 VkAccelerationStructureNV accelerationStructure,
2825 const VkAllocationCallbacks *pAllocator) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002826 if (!accelerationStructure) return;
2827 auto *as_state = GetAccelerationStructureStateNV(accelerationStructure);
2828 if (as_state) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002829 as_state->Destroy();
sourav parmarcd5fb182020-07-17 12:58:44 -07002830 accelerationStructureMap.erase(accelerationStructure);
2831 }
Jeff Bolz95176d02020-04-01 00:36:16 -05002832}
2833
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002834void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2835 uint32_t viewportCount,
2836 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002837 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002838 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002839}
2840
locke-lunargd556cc32019-09-17 01:21:23 -06002841void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002842 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002843 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002844}
2845
2846void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2847 uint16_t lineStipplePattern) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002848 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002849 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
2852void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2853 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002854 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002855 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002856}
2857
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002858void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2859 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002860 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002861 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002862 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2863 cb_state->scissorMask |= bits;
2864 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002865}
2866
locke-lunargd556cc32019-09-17 01:21:23 -06002867void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002868 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002869 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002870}
2871
2872void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2873 float maxDepthBounds) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002874 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002875 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002876}
2877
2878void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2879 uint32_t compareMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002880 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002881 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002882}
2883
2884void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2885 uint32_t writeMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002886 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002887 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002888}
2889
2890void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2891 uint32_t reference) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002892 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002893 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002894}
2895
locke-lunargd556cc32019-09-17 01:21:23 -06002896
2897// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2898void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2899 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2900 uint32_t firstSet, uint32_t setCount,
2901 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2902 const uint32_t *pDynamicOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002903 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002904 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
locke-lunargd556cc32019-09-17 01:21:23 -06002905 auto pipeline_layout = GetPipelineLayout(layout);
2906
2907 // Resize binding arrays
2908 uint32_t last_set_index = firstSet + setCount - 1;
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002909 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2910 if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) {
2911 cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06002912 }
2913
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002914 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr,
2915 dynamicOffsetCount, pDynamicOffsets);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002916 cb_state->lastBound[lv_bind_point].pipeline_layout = layout;
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002917 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002918}
2919
locke-lunargd556cc32019-09-17 01:21:23 -06002920void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2921 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2922 uint32_t set, uint32_t descriptorWriteCount,
2923 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002924 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002925 auto pipeline_layout = GetPipelineLayout(layout);
2926 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout, set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002927}
2928
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002929void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2930 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2931 const void *pValues) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002932 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002933 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002934 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002935 cb_state->ResetPushConstantDataIfIncompatible(GetPipelineLayout(layout));
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002936
2937 auto &push_constant_data = cb_state->push_constant_data;
2938 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2939 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002940 cb_state->push_constant_pipeline_layout_set = layout;
2941
2942 auto flags = stageFlags;
2943 uint32_t bit_shift = 0;
2944 while (flags) {
2945 if (flags & 1) {
2946 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2947 const auto it = cb_state->push_constant_data_update.find(flag);
2948
2949 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002950 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002951 }
2952 }
2953 flags = flags >> 1;
2954 ++bit_shift;
2955 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002956 }
2957}
2958
locke-lunargd556cc32019-09-17 01:21:23 -06002959void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2960 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002961 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002962
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002963 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002964 cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer);
2965 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002966 cb_state->index_buffer_binding.offset = offset;
2967 cb_state->index_buffer_binding.index_type = indexType;
2968 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002969 if (!disabled[command_buffer_state]) {
2970 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state.get());
2971 }
locke-lunargd556cc32019-09-17 01:21:23 -06002972}
2973
2974void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2975 uint32_t bindingCount, const VkBuffer *pBuffers,
2976 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002977 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002978 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002979
2980 uint32_t end = firstBinding + bindingCount;
2981 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2982 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2983 }
2984
2985 for (uint32_t i = 0; i < bindingCount; ++i) {
2986 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07002987 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002988 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002989 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2990 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002991 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002992 if (pBuffers[i] && !disabled[command_buffer_state]) {
2993 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Jeff Bolz165818a2020-05-08 11:19:03 -05002994 }
locke-lunargd556cc32019-09-17 01:21:23 -06002995 }
2996}
2997
2998void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2999 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003000 if (disabled[command_buffer_state]) return;
3001
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003002 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003003 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06003004}
3005
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003006void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3007 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003008 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3009 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003010}
3011
3012void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3013 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003014 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003015 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
3016
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003017 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
3018 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003019}
3020
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003021void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
3022 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003023 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3024 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003025}
3026
3027void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
3028 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003029 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3030 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003031}
3032
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003033void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
3034 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
3035 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3036 uint32_t bufferMemoryBarrierCount,
3037 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3038 uint32_t imageMemoryBarrierCount,
3039 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003040 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3041 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
3042 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3043 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003044}
3045
3046void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
3047 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003048 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3049 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06003050 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003051 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06003052 }
3053}
3054
3055void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
3056 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
3057 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
3058 uint32_t bufferMemoryBarrierCount,
3059 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
3060 uint32_t imageMemoryBarrierCount,
3061 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003062 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3063 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
3064 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
3065 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06003066}
3067
3068void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
3069 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003070 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3071 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
3072 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06003073}
3074
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003075QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
3076 uint32_t perfPass) const {
3077 QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass);
locke-lunargd556cc32019-09-17 01:21:23 -06003078
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003079 auto iter = localQueryToStateMap->find(query);
3080 if (iter != localQueryToStateMap->end()) return iter->second;
Jeff Bolz310775c2019-10-09 00:46:33 -05003081
Jeff Bolz310775c2019-10-09 00:46:33 -05003082 return QUERYSTATE_UNKNOWN;
locke-lunargd556cc32019-09-17 01:21:23 -06003083}
3084
locke-lunargd556cc32019-09-17 01:21:23 -06003085void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
3086 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003087 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003088
locke-lunargd556cc32019-09-17 01:21:23 -06003089 QueryObject query = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003090 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003091 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003092 if (!disabled[query_validation]) {
3093 cb_state->BeginQuery(query);
3094 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003095 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003096 auto pool_state = GetQueryPoolState(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003097 cb_state->AddChild(pool_state);
3098 }
locke-lunargd556cc32019-09-17 01:21:23 -06003099}
3100
3101void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003102 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003103 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003104 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003105 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003106 if (!disabled[query_validation]) {
3107 cb_state->EndQuery(query_obj);
3108 }
3109 if (!disabled[command_buffer_state]) {
3110 auto pool_state = GetQueryPoolState(query_obj.pool);
3111 cb_state->AddChild(pool_state);
3112 }
locke-lunargd556cc32019-09-17 01:21:23 -06003113}
3114
3115void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3116 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003117 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003118 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003119
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003120 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003121 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02003122
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003123 if (!disabled[command_buffer_state]) {
3124 auto pool_state = GetQueryPoolState(queryPool);
3125 cb_state->AddChild(pool_state);
3126 }
locke-lunargd556cc32019-09-17 01:21:23 -06003127}
3128
3129void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3130 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
3131 VkDeviceSize dstOffset, VkDeviceSize stride,
3132 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003133 if (disabled[query_validation] || disabled[command_buffer_state]) return;
3134
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003135 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003136 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
locke-lunargd556cc32019-09-17 01:21:23 -06003137 auto dst_buff_state = GetBufferState(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003138 cb_state->AddChild(dst_buff_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05003139 auto pool_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003140 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003141}
3142
3143void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
3144 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003145 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3146 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07003147}
3148
3149void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
3150 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
3151 uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06003152 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3153 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06003154}
3155
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003156void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
3157 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
3158 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
3159 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003160 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003161 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003162 if (!disabled[command_buffer_state]) {
3163 auto pool_state = GetQueryPoolState(queryPool);
3164 cb_state->AddChild(pool_state);
3165 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003166 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01003167}
3168
locke-lunargd556cc32019-09-17 01:21:23 -06003169void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
3170 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
3171 VkResult result) {
3172 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003173
Jeremy Gebben88f58142021-06-01 10:07:52 -06003174 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08003175 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003176 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07003177
locke-lunargd556cc32019-09-17 01:21:23 -06003178 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003179 views[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003180 }
3181 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06003182
3183 frameBufferMap[*pFramebuffer] = std::make_shared<FRAMEBUFFER_STATE>(
3184 *pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass), std::move(views));
locke-lunargd556cc32019-09-17 01:21:23 -06003185}
3186
locke-lunargd556cc32019-09-17 01:21:23 -06003187void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
3188 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3189 VkResult result) {
3190 if (VK_SUCCESS != result) return;
Jeremy Gebben88f58142021-06-01 10:07:52 -06003191 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06003192}
3193
Mike Schuchardt2df08912020-12-15 16:28:09 -08003194void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003195 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3196 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003197 if (VK_SUCCESS != result) return;
3198
3199 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07003200}
3201
Mike Schuchardt2df08912020-12-15 16:28:09 -08003202void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07003203 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
3204 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06003205 if (VK_SUCCESS != result) return;
3206
3207 renderPassMap[*pRenderPass] = std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo);
Tony-LunarG977448c2019-12-02 14:52:02 -07003208}
3209
locke-lunargd556cc32019-09-17 01:21:23 -06003210void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
3211 const VkRenderPassBeginInfo *pRenderPassBegin,
3212 VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003213 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3214 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003215}
3216
3217void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
3218 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003219 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003220 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003221 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003222}
3223
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003224void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3225 uint32_t counterBufferCount,
3226 const VkBuffer *pCounterBuffers,
3227 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003228 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003229
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003230 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003231 cb_state->transform_feedback_active = true;
3232}
3233
3234void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
3235 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
3236 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003237 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003238
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003239 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06003240 cb_state->transform_feedback_active = false;
3241}
3242
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003243void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
3244 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06003245 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003246
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003247 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003248 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003249 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
3250 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003251}
3252
3253void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06003254 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003255
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003256 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003257 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02003258 cb_state->conditional_rendering_inside_render_pass = false;
3259 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02003260}
3261
Tony-LunarG977448c2019-12-02 14:52:02 -07003262void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
3263 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003264 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003265 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3266 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07003267}
3268
locke-lunargd556cc32019-09-17 01:21:23 -06003269
3270void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003271 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3272 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003273}
3274
3275void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003276 const VkSubpassBeginInfo *pSubpassBeginInfo,
3277 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003278 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003279 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003280}
3281
Tony-LunarG977448c2019-12-02 14:52:02 -07003282void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003283 const VkSubpassBeginInfo *pSubpassBeginInfo,
3284 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003285 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003286 cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06003287}
3288
3289void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003290 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3291 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06003292}
3293
3294void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003295 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003296 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003297 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003298}
3299
Tony-LunarG977448c2019-12-02 14:52:02 -07003300void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003301 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003302 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3303 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07003304}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003305
locke-lunargd556cc32019-09-17 01:21:23 -06003306void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
3307 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003308 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003309
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003310 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003311}
3312
3313void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
3314 VkFlags flags, void **ppData, VkResult result) {
3315 if (VK_SUCCESS != result) return;
3316 RecordMappedMemory(mem, offset, size, ppData);
3317}
3318
3319void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
3320 auto mem_info = GetDevMemState(mem);
3321 if (mem_info) {
3322 mem_info->mapped_range = MemRange();
3323 mem_info->p_driver_data = nullptr;
3324 }
3325}
3326
3327void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben8ee02af2021-07-16 10:15:55 -06003328 auto image_state = GetShared<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06003329 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06003330 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
3331 // See: VUID-vkGetImageSubresourceLayout-image-01895
3332 image_state->fragment_encoder =
3333 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003334 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003335 if (swapchain_info) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003336 auto swapchain = GetShared<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003337 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003338 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07003339
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003340 if (!swapchain_image.fake_base_address) {
3341 auto size = image_state->fragment_encoder->TotalSize();
3342 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06003343 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003344 // All images bound to this swapchain and index are aliases
3345 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003346 }
3347 } else {
3348 // Track bound memory range information
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003349 auto mem_info = GetDevMemShared(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06003350 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003351 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003352 }
locke-lunargd556cc32019-09-17 01:21:23 -06003353 }
locke-lunargd556cc32019-09-17 01:21:23 -06003354 }
3355}
3356
3357void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
3358 VkDeviceSize memoryOffset, VkResult result) {
3359 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06003360 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003361 bind_info.image = image;
3362 bind_info.memory = mem;
3363 bind_info.memoryOffset = memoryOffset;
3364 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003365}
3366
3367void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003368 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003369 if (VK_SUCCESS != result) return;
3370 for (uint32_t i = 0; i < bindInfoCount; i++) {
3371 UpdateBindImageMemoryState(pBindInfos[i]);
3372 }
3373}
3374
3375void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003376 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003377 if (VK_SUCCESS != result) return;
3378 for (uint32_t i = 0; i < bindInfoCount; i++) {
3379 UpdateBindImageMemoryState(pBindInfos[i]);
3380 }
3381}
3382
3383void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
3384 auto event_state = GetEventState(event);
3385 if (event_state) {
3386 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
3387 }
locke-lunargd556cc32019-09-17 01:21:23 -06003388}
3389
3390void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
3391 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
3392 VkResult result) {
3393 if (VK_SUCCESS != result) return;
3394 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
3395 pImportSemaphoreFdInfo->flags);
3396}
3397
3398void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003399 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003400 SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08003401 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003402 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
3403 semaphore_state->scope = kSyncScopeExternalPermanent;
3404 }
3405}
3406
3407#ifdef VK_USE_PLATFORM_WIN32_KHR
3408void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
3409 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
3410 if (VK_SUCCESS != result) return;
3411 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
3412 pImportSemaphoreWin32HandleInfo->flags);
3413}
3414
3415void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
3416 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3417 HANDLE *pHandle, VkResult result) {
3418 if (VK_SUCCESS != result) return;
3419 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
3420}
3421
3422void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
3423 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
3424 if (VK_SUCCESS != result) return;
3425 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
3426 pImportFenceWin32HandleInfo->flags);
3427}
3428
3429void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
3430 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
3431 HANDLE *pHandle, VkResult result) {
3432 if (VK_SUCCESS != result) return;
3433 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
3434}
3435#endif
3436
3437void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3438 VkResult result) {
3439 if (VK_SUCCESS != result) return;
3440 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3441}
3442
Mike Schuchardt2df08912020-12-15 16:28:09 -08003443void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3444 VkFenceImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06003445 FENCE_STATE *fence_node = GetFenceState(fence);
3446 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003447 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06003448 fence_node->scope == kSyncScopeInternal) {
3449 fence_node->scope = kSyncScopeExternalTemporary;
3450 } else {
3451 fence_node->scope = kSyncScopeExternalPermanent;
3452 }
3453 }
3454}
3455
3456void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3457 VkResult result) {
3458 if (VK_SUCCESS != result) return;
3459 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3460}
3461
Mike Schuchardt2df08912020-12-15 16:28:09 -08003462void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003463 FENCE_STATE *fence_state = GetFenceState(fence);
3464 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003465 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003466 // Export with reference transference becomes external
3467 fence_state->scope = kSyncScopeExternalPermanent;
3468 } else if (fence_state->scope == kSyncScopeInternal) {
3469 // Export with copy transference has a side effect of resetting the fence
3470 fence_state->state = FENCE_UNSIGNALED;
3471 }
3472 }
3473}
3474
3475void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3476 VkResult result) {
3477 if (VK_SUCCESS != result) return;
3478 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3479}
3480
3481void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3482 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3483 if (VK_SUCCESS != result) return;
John Zulaufd5115702021-01-18 12:34:33 -07003484 const auto event = *pEvent;
Jeremy Gebbencbf22862021-03-03 12:01:22 -07003485 eventMap.emplace(event, std::make_shared<EVENT_STATE>(event, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003486}
3487
3488void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003489 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003490 SWAPCHAIN_NODE *old_swapchain_state) {
3491 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003492 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003493 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003494 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003495 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3496 surface_state->AddParent(swapchain.get());
3497 surface_state->swapchain = swapchain.get();
3498 swapchain->surface = std::move(surface_state);
3499 swapchainMap[*pSwapchain] = std::move(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003500 } else {
3501 surface_state->swapchain = nullptr;
3502 }
3503 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003504 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003505 if (old_swapchain_state) {
3506 old_swapchain_state->retired = true;
3507 }
3508 return;
3509}
3510
3511void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3512 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3513 VkResult result) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003514 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfo->surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003515 auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003516 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003517}
3518
3519void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3520 const VkAllocationCallbacks *pAllocator) {
3521 if (!swapchain) return;
3522 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003523 if (!swapchain_data) return;
John Zulauffaa7a522021-03-05 12:22:45 -07003524
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003525 swapchain_data->Destroy();
3526 swapchainMap.erase(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003527}
3528
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003529void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3530 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3531 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3532 VkResult result) {
3533 if (VK_SUCCESS != result) return;
3534 if (!pMode) return;
Jeremy Gebben5573a8c2021-06-04 08:55:10 -06003535 display_mode_map[*pMode] = std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice);
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003536}
3537
locke-lunargd556cc32019-09-17 01:21:23 -06003538void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
3539 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3540 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003541 auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]);
3542 if (semaphore_state) {
3543 semaphore_state->signaler.first = VK_NULL_HANDLE;
3544 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06003545 }
3546 }
3547
Tony-LunarG6f887e52021-07-27 11:23:14 -06003548 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003549 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3550 // 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
3551 // confused itself just as much.
3552 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3553 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3554 // Mark the image as having been released to the WSI
3555 auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003556 if (swapchain_data) {
3557 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003558 if (present_id_info) {
3559 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3560 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3561 }
3562 }
locke-lunargd556cc32019-09-17 01:21:23 -06003563 }
3564 }
3565 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
3566 // its semaphore waits) /never/ participate in any completion proof.
3567}
3568
3569void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3570 const VkSwapchainCreateInfoKHR *pCreateInfos,
3571 const VkAllocationCallbacks *pAllocator,
3572 VkSwapchainKHR *pSwapchains, VkResult result) {
3573 if (pCreateInfos) {
3574 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003575 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfos[i].surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003576 auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003577 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003578 }
3579 }
3580}
3581
3582void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3583 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003584 auto fence_state = GetFenceState(fence);
3585 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003586 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3587 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003588 fence_state->state = FENCE_INFLIGHT;
3589 fence_state->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof.
locke-lunargd556cc32019-09-17 01:21:23 -06003590 }
3591
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003592 auto semaphore_state = GetSemaphoreState(semaphore);
3593 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003594 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3595 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003596 semaphore_state->signaled = true;
3597 semaphore_state->signaler.first = VK_NULL_HANDLE;
locke-lunargd556cc32019-09-17 01:21:23 -06003598 }
3599
3600 // Mark the image as acquired.
3601 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003602 if (swapchain_data) {
3603 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003604 }
3605}
3606
3607void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3608 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3609 VkResult result) {
3610 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3611 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3612}
3613
3614void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3615 uint32_t *pImageIndex, VkResult result) {
3616 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3617 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3618 pAcquireInfo->fence, pImageIndex);
3619}
3620
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003621std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3622 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3623}
3624
locke-lunargd556cc32019-09-17 01:21:23 -06003625void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
3626 VkPhysicalDevice *pPhysicalDevices, VkResult result) {
3627 if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) {
3628 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003629 physical_device_map.emplace(pPhysicalDevices[i], CreatePhysicalDeviceState(pPhysicalDevices[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06003630 }
3631 }
3632}
3633
3634// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003635static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003636 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003637}
3638
3639void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3640 uint32_t *pQueueFamilyPropertyCount,
3641 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003642 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3643 assert(pd_state);
3644 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003645}
3646
3647void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003648 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003649 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3650 assert(pd_state);
3651 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003652}
3653
3654void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003655 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003656 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3657 assert(pd_state);
3658 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003659}
3660void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3661 const VkAllocationCallbacks *pAllocator) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003662 if (!surface) return;
3663 auto surface_state = GetSurfaceState(surface);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003664 surface_state->Destroy();
locke-lunargd556cc32019-09-17 01:21:23 -06003665 surface_map.erase(surface);
3666}
3667
3668void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003669 surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface);
locke-lunargd556cc32019-09-17 01:21:23 -06003670}
3671
3672void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3673 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3674 const VkAllocationCallbacks *pAllocator,
3675 VkSurfaceKHR *pSurface, VkResult result) {
3676 if (VK_SUCCESS != result) return;
3677 RecordVulkanSurface(pSurface);
3678}
3679
3680#ifdef VK_USE_PLATFORM_ANDROID_KHR
3681void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3682 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3683 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3684 VkResult result) {
3685 if (VK_SUCCESS != result) return;
3686 RecordVulkanSurface(pSurface);
3687}
3688#endif // VK_USE_PLATFORM_ANDROID_KHR
3689
3690#ifdef VK_USE_PLATFORM_IOS_MVK
3691void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3692 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3693 VkResult result) {
3694 if (VK_SUCCESS != result) return;
3695 RecordVulkanSurface(pSurface);
3696}
3697#endif // VK_USE_PLATFORM_IOS_MVK
3698
3699#ifdef VK_USE_PLATFORM_MACOS_MVK
3700void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3701 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3702 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3703 VkResult result) {
3704 if (VK_SUCCESS != result) return;
3705 RecordVulkanSurface(pSurface);
3706}
3707#endif // VK_USE_PLATFORM_MACOS_MVK
3708
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003709#ifdef VK_USE_PLATFORM_METAL_EXT
3710void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3711 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3712 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3713 VkResult result) {
3714 if (VK_SUCCESS != result) return;
3715 RecordVulkanSurface(pSurface);
3716}
3717#endif // VK_USE_PLATFORM_METAL_EXT
3718
locke-lunargd556cc32019-09-17 01:21:23 -06003719#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3720void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3721 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3722 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3723 VkResult result) {
3724 if (VK_SUCCESS != result) return;
3725 RecordVulkanSurface(pSurface);
3726}
3727#endif // VK_USE_PLATFORM_WAYLAND_KHR
3728
3729#ifdef VK_USE_PLATFORM_WIN32_KHR
3730void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3731 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3732 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3733 VkResult result) {
3734 if (VK_SUCCESS != result) return;
3735 RecordVulkanSurface(pSurface);
3736}
3737#endif // VK_USE_PLATFORM_WIN32_KHR
3738
3739#ifdef VK_USE_PLATFORM_XCB_KHR
3740void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3741 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3742 VkResult result) {
3743 if (VK_SUCCESS != result) return;
3744 RecordVulkanSurface(pSurface);
3745}
3746#endif // VK_USE_PLATFORM_XCB_KHR
3747
3748#ifdef VK_USE_PLATFORM_XLIB_KHR
3749void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3750 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3751 VkResult result) {
3752 if (VK_SUCCESS != result) return;
3753 RecordVulkanSurface(pSurface);
3754}
3755#endif // VK_USE_PLATFORM_XLIB_KHR
3756
Niklas Haas8b84af12020-04-19 22:20:11 +02003757void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3758 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3759 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3760 VkResult result) {
3761 if (VK_SUCCESS != result) return;
3762 RecordVulkanSurface(pSurface);
3763}
3764
locke-lunargd556cc32019-09-17 01:21:23 -06003765void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3766 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3767 VkBool32 *pSupported, VkResult result) {
3768 if (VK_SUCCESS != result) return;
3769 auto surface_state = GetSurfaceState(surface);
3770 surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE);
3771}
3772
locke-lunargd556cc32019-09-17 01:21:23 -06003773void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3774 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003775 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3776 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003777 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3778}
3779
3780void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003781 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3782 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003783 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3784}
3785
3786void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3787 const VkDebugUtilsLabelEXT *pLabelInfo) {
3788 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3789
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003790 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003791 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3792 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003793 cb_state->debug_label = LoggingLabel(pLabelInfo);
3794}
3795
3796void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003797 uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06003798 if (NULL != pPhysicalDeviceGroupProperties) {
3799 for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) {
3800 for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) {
3801 VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j];
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003802
3803 physical_device_map.emplace(cur_phys_dev, CreatePhysicalDeviceState(cur_phys_dev));
locke-lunargd556cc32019-09-17 01:21:23 -06003804 }
3805 }
3806 }
3807}
3808
3809void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003810 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06003811 VkResult result) {
3812 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3813 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
3814}
3815
3816void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003817 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06003818 VkResult result) {
3819 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3820 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
3821}
3822
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003823void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3824 uint32_t queueFamilyIndex,
3825 uint32_t *pCounterCount,
3826 VkPerformanceCounterKHR *pCounters) {
3827 if (NULL == pCounters) return;
3828
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003829 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3830 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003831
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003832 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3833 queue_family_counters->counters.resize(*pCounterCount);
3834 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003835
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003836 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003837}
3838
3839void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3840 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3841 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3842 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3843 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3844}
3845
3846void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3847 VkResult result) {
3848 if (result == VK_SUCCESS) performance_lock_acquired = true;
3849}
3850
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003851void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3852 performance_lock_acquired = false;
3853 for (auto &cmd_buffer : commandBufferMap) {
3854 cmd_buffer.second->performance_lock_released = true;
3855 }
3856}
3857
locke-lunargd556cc32019-09-17 01:21:23 -06003858void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003859 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003860 const VkAllocationCallbacks *pAllocator) {
3861 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003862 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
3863 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003864 desc_template_map.erase(descriptorUpdateTemplate);
3865}
3866
3867void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003868 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003869 const VkAllocationCallbacks *pAllocator) {
3870 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003871 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
3872 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003873 desc_template_map.erase(descriptorUpdateTemplate);
3874}
3875
Mike Schuchardt2df08912020-12-15 16:28:09 -08003876void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3877 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
locke-lunargd556cc32019-09-17 01:21:23 -06003878 safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003879 auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003880 desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state);
3881}
3882
Mike Schuchardt2df08912020-12-15 16:28:09 -08003883void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3884 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3885 const VkAllocationCallbacks *pAllocator,
3886 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3887 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003888 if (VK_SUCCESS != result) return;
3889 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3890}
3891
3892void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003893 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3894 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003895 if (VK_SUCCESS != result) return;
3896 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3897}
3898
3899void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003900 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003901 const void *pData) {
3902 auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate);
3903 if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) {
3904 assert(0);
3905 } else {
3906 const TEMPLATE_STATE *template_state = template_map_entry->second.get();
3907 // TODO: Record template push descriptor updates
3908 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
3909 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData);
3910 }
3911 }
3912}
3913
3914void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3915 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3916 const void *pData) {
3917 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3918}
3919
3920void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003921 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003922 const void *pData) {
3923 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3924}
3925
Mike Schuchardt2df08912020-12-15 16:28:09 -08003926void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3927 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3928 VkPipelineLayout layout, uint32_t set,
3929 const void *pData) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003930 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003931
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003932 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003933 const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
3934 if (template_state) {
3935 auto layout_data = GetPipelineLayout(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003936 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003937 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003938 // Decode the template into a set of write updates
3939 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData,
3940 dsl->GetDescriptorSetLayout());
3941 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data, set,
3942 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3943 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003944 }
3945}
3946
3947void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3948 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003949 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003950 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003951 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003952 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003953 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003954 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003955 }
3956}
3957
3958void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3959 uint32_t *pPropertyCount,
3960 VkDisplayPlanePropertiesKHR *pProperties,
3961 VkResult result) {
3962 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3963 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3964}
3965
3966void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3967 uint32_t *pPropertyCount,
3968 VkDisplayPlaneProperties2KHR *pProperties,
3969 VkResult result) {
3970 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3971 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3972}
3973
3974void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3975 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3976 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003977 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003978 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003979 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003980}
3981
3982void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3983 uint32_t query, uint32_t index) {
3984 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003985 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003986 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003987 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003988}
3989
3990void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3991 VkSamplerYcbcrConversion ycbcr_conversion) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003992 VkFormatFeatureFlags format_features = 0;
3993
3994 if (create_info->format != VK_FORMAT_UNDEFINED) {
3995 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003996 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003997 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3998 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003999 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06004000
4001 samplerYcbcrConversionMap[ycbcr_conversion] =
4002 std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features);
locke-lunargd556cc32019-09-17 01:21:23 -06004003}
4004
4005void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
4006 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4007 const VkAllocationCallbacks *pAllocator,
4008 VkSamplerYcbcrConversion *pYcbcrConversion,
4009 VkResult result) {
4010 if (VK_SUCCESS != result) return;
4011 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4012}
4013
4014void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
4015 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
4016 const VkAllocationCallbacks *pAllocator,
4017 VkSamplerYcbcrConversion *pYcbcrConversion,
4018 VkResult result) {
4019 if (VK_SUCCESS != result) return;
4020 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
4021}
4022
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004023void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004024 auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004025 ycbcr_state->Destroy();
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004026 samplerYcbcrConversionMap.erase(ycbcr_conversion);
4027}
4028
locke-lunargd556cc32019-09-17 01:21:23 -06004029void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
4030 const VkAllocationCallbacks *pAllocator) {
4031 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004032 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004033}
4034
4035void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
4036 VkSamplerYcbcrConversion ycbcrConversion,
4037 const VkAllocationCallbacks *pAllocator) {
4038 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07004039 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06004040}
4041
Tony-LunarG977448c2019-12-02 14:52:02 -07004042void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4043 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06004044 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07004045 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004046
4047 // Do nothing if the query pool has been destroyed.
4048 auto query_pool_state = GetQueryPoolState(queryPool);
4049 if (!query_pool_state) return;
4050
4051 // Reset the state of existing entries.
4052 QueryObject query_obj{queryPool, 0};
4053 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
4054 for (uint32_t i = 0; i < max_query_count; ++i) {
4055 query_obj.query = firstQuery + i;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004056 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004057 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004058 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
4059 query_obj.perf_pass = pass_index;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004060 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004061 }
4062 }
locke-lunargd556cc32019-09-17 01:21:23 -06004063 }
4064}
4065
Tony-LunarG977448c2019-12-02 14:52:02 -07004066void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4067 uint32_t queryCount) {
4068 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4069}
4070
4071void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
4072 uint32_t queryCount) {
4073 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
4074}
4075
locke-lunargd556cc32019-09-17 01:21:23 -06004076void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
4077 const TEMPLATE_STATE *template_state, const void *pData) {
4078 // Translate the templated update into a normal update for validation...
4079 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
4080 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
4081 decoded_update.desc_writes.data(), 0, NULL);
4082}
4083
4084// Update the common AllocateDescriptorSetsData
4085void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05004086 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06004087 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05004088 auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004089 if (layout) {
4090 ds_data->layout_nodes[i] = layout;
4091 // Count total descriptors required per type
4092 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
4093 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004094 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
4095 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06004096 }
4097 }
4098 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
4099 }
4100}
4101
4102// Decrement allocated sets from the pool and insert new sets into set_map
4103void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
4104 const VkDescriptorSet *descriptor_sets,
4105 const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
4106 auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get();
4107 // Account for sets and individual descriptors allocated from pool
4108 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
4109 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
4110 pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
4111 }
4112
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07004113 const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06004114 bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount;
4115
4116 // Create tracking object for each descriptor set; insert into global map and the pool's set.
4117 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
4118 uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
4119
Jeff Bolz41a1ced2019-10-11 11:40:49 -05004120 auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], pool_state, ds_data->layout_nodes[i],
John Zulaufd2c3dae2019-12-12 11:02:17 -07004121 variable_count, this);
locke-lunargd556cc32019-09-17 01:21:23 -06004122 pool_state->sets.insert(new_ds.get());
locke-lunargd556cc32019-09-17 01:21:23 -06004123 setMap[descriptor_sets[i]] = std::move(new_ds);
4124 }
4125}
4126
locke-lunargd556cc32019-09-17 01:21:23 -06004127void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
4128 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004129 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004130 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004131}
4132
Tony-LunarG745150c2021-07-02 15:07:31 -06004133void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4134 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
4135 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004136 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004137 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004138}
4139
locke-lunargd556cc32019-09-17 01:21:23 -06004140void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
4141 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
4142 uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004143 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004144 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004145}
4146
Tony-LunarG745150c2021-07-02 15:07:31 -06004147void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
4148 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
4149 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
4150 const int32_t *pVertexOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004151 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004152 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06004153}
4154
locke-lunargd556cc32019-09-17 01:21:23 -06004155void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4156 uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004157 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004158 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004159 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004160 if (!disabled[command_buffer_state]) {
4161 cb_state->AddChild(buffer_state);
4162 }
locke-lunargd556cc32019-09-17 01:21:23 -06004163}
4164
4165void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4166 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004167 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06004168 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004169 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004170 if (!disabled[command_buffer_state]) {
4171 cb_state->AddChild(buffer_state);
4172 }
locke-lunargd556cc32019-09-17 01:21:23 -06004173}
4174
4175void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004176 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004177 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06004178}
4179
4180void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
4181 VkDeviceSize offset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004182 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004183 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004184 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004185 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004186 cb_state->AddChild(buffer_state);
4187 }
locke-lunargd556cc32019-09-17 01:21:23 -06004188}
4189
Tony-LunarG977448c2019-12-02 14:52:02 -07004190void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4191 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07004192 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004193 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004194 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004195 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004196 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4197 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004198 cb_state->AddChild(buffer_state);
4199 cb_state->AddChild(count_buffer_state);
4200 }
Tony-LunarG977448c2019-12-02 14:52:02 -07004201}
4202
locke-lunargd556cc32019-09-17 01:21:23 -06004203void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4204 VkDeviceSize offset, VkBuffer countBuffer,
4205 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4206 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004207 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004208 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004209}
4210
4211void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4212 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
4213 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004214 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004215 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07004216}
4217
4218void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4219 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07004220 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004221 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004222 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004223 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004224 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4225 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004226 cb_state->AddChild(buffer_state);
4227 cb_state->AddChild(count_buffer_state);
4228 }
locke-lunargd556cc32019-09-17 01:21:23 -06004229}
4230
4231void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
4232 VkDeviceSize offset, VkBuffer countBuffer,
4233 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4234 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004235 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004236 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07004237}
4238
4239void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
4240 VkDeviceSize offset, VkBuffer countBuffer,
4241 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4242 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06004243 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07004244 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06004245}
4246
4247void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
4248 uint32_t firstTask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004249 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004250 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004251}
4252
4253void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4254 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004255 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004256 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06004257 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004258 if (!disabled[command_buffer_state] && buffer_state) {
4259 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004260 }
4261}
4262
4263void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
4264 VkDeviceSize offset, VkBuffer countBuffer,
4265 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
4266 uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004267 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004268 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004269 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06004270 BUFFER_STATE *buffer_state = GetBufferState(buffer);
4271 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004272 if (buffer_state) {
4273 cb_state->AddChild(buffer_state);
4274 }
4275 if (count_buffer_state) {
4276 cb_state->AddChild(count_buffer_state);
4277 }
locke-lunargd556cc32019-09-17 01:21:23 -06004278 }
4279}
4280
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004281void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
4282 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
4283 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
4284 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
4285 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
4286 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
4287 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004288 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004289 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004290 cb_state->hasTraceRaysCmd = true;
4291}
4292
4293
4294void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
4295 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4296 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4297 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4298 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
4299 uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004300 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004301 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004302 cb_state->hasTraceRaysCmd = true;
4303}
4304
4305void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
4306 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
4307 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
4308 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
4309 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
4310 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004311 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07004312 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06004313 cb_state->hasTraceRaysCmd = true;
4314}
4315
locke-lunargd556cc32019-09-17 01:21:23 -06004316void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
4317 const VkAllocationCallbacks *pAllocator,
4318 VkShaderModule *pShaderModule, VkResult result,
4319 void *csm_state_data) {
4320 if (VK_SUCCESS != result) return;
4321 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
4322
sfricke-samsung45996a42021-09-16 13:45:27 -07004323 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06004324 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05004325 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
4326 csm_state->unique_shader_id)
4327 : std::make_shared<SHADER_MODULE_STATE>();
sfricke-samsung962cad92021-04-13 00:46:29 -07004328 new_shader_module->SetPushConstantUsedInShader();
locke-lunargd556cc32019-09-17 01:21:23 -06004329 shaderModuleMap[*pShaderModule] = std::move(new_shader_module);
4330}
4331
John Zulauf22b0fbe2019-10-15 06:26:16 -06004332void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
4333 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
4334 VkResult result) {
4335 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004336 auto swapchain_state = GetShared<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004337
4338 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
4339
4340 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004341 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07004342 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07004343 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06004344
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004345 auto format_features =
4346 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
4347 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004348
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06004349 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004350 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004351 if (!swapchain_image.fake_base_address) {
4352 auto size = image_state->fragment_encoder->TotalSize();
4353 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07004354 }
4355
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004356 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004357 swapchain_image.image_state = image_state.get();
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06004358 imageMap[pSwapchainImages[i]] = std::move(image_state);
John Zulauf22b0fbe2019-10-15 06:26:16 -06004359 }
4360 }
4361
4362 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06004363 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
4364 }
4365}
sourav parmar35e7a002020-06-09 17:58:44 -07004366
sourav parmar35e7a002020-06-09 17:58:44 -07004367void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
4368 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004369 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07004370 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004371 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07004372 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
4373 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07004374 if (dst_as_state != nullptr && src_as_state != nullptr) {
4375 dst_as_state->built = true;
4376 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004377 if (!disabled[command_buffer_state]) {
4378 cb_state->AddChild(dst_as_state);
4379 cb_state->AddChild(src_as_state);
4380 }
sourav parmar35e7a002020-06-09 17:58:44 -07004381 }
4382 }
4383}
Piers Daniell39842ee2020-07-10 16:42:33 -06004384
4385void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004386 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004387 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004388}
4389
4390void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004391 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004392 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004393}
4394
4395void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
4396 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004397 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004398 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004399 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06004400}
4401
4402void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
4403 const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004404 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004405 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004406 uint32_t bits = (1u << viewportCount) - 1u;
4407 cb_state->viewportWithCountMask |= bits;
4408 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004409 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004410 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004411
4412 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4413 for (size_t i = 0; i < viewportCount; ++i) {
4414 cb_state->dynamicViewports[i] = pViewports[i];
4415 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004416}
4417
4418void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4419 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004420 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004421 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004422 uint32_t bits = (1u << scissorCount) - 1u;
4423 cb_state->scissorWithCountMask |= bits;
4424 cb_state->trashedScissorMask &= ~bits;
4425 cb_state->scissorWithCountCount = scissorCount;
4426 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004427}
4428
4429void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4430 uint32_t bindingCount, const VkBuffer *pBuffers,
4431 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4432 const VkDeviceSize *pStrides) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004433 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004434 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004435
4436 uint32_t end = firstBinding + bindingCount;
4437 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4438 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4439 }
4440
4441 for (uint32_t i = 0; i < bindingCount; ++i) {
4442 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07004443 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004444 vertex_buffer_binding.offset = pOffsets[i];
4445 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4446 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4447 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004448 if (!disabled[command_buffer_state] && pBuffers[i]) {
4449 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Piers Daniell39842ee2020-07-10 16:42:33 -06004450 }
4451 }
4452}
4453
4454void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004455 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004456 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004457}
4458
4459void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004460 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004461 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004462}
4463
4464void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004465 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004466 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004467}
4468
4469void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4470 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004471 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004472 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004473}
4474void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004475 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004476 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004477}
4478
4479void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4480 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4481 VkCompareOp compareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004482 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004483 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004484}
locke-lunarg4189aa22020-10-21 00:23:48 -06004485
4486void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4487 uint32_t discardRectangleCount,
4488 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004489 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004490 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004491}
4492
4493void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4494 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004495 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004496 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004497}
4498
4499void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4500 VkCoarseSampleOrderTypeNV sampleOrderType,
4501 uint32_t customSampleOrderCount,
4502 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004503 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004504 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004505}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004506
4507void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004508 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004509 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004510}
4511
4512void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004513 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004514 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004515}
4516
4517void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4518 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004519 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004520 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004521}
4522
4523void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004524 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004525 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004526}
4527
4528void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4529 VkBool32 primitiveRestartEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004530 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004531 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004532}
Piers Daniell924cd832021-05-18 13:48:47 -06004533
4534void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4535 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4536 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4537 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004538 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004539 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4540
4541 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4542 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4543 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004544 if (pipeline_state->create_info.graphics.pDynamicState) {
4545 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4546 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004547 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4548 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4549 break;
4550 }
4551 }
4552 }
4553 }
4554 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004555}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004556
4557void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
4558 BUFFER_STATE *buffer_state = GetBufferState(pInfo->buffer);
4559 if (buffer_state) {
4560 // address is used for GPU-AV and ray tracing buffer validation
4561 buffer_state->deviceAddress = address;
4562 buffer_address_map_.emplace(address, buffer_state);
4563 }
4564}
4565
4566void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4567 VkDeviceAddress address) {
4568 RecordGetBufferDeviceAddress(pInfo, address);
4569}
4570
4571void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4572 VkDeviceAddress address) {
4573 RecordGetBufferDeviceAddress(pInfo, address);
4574}
4575
4576void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4577 VkDeviceAddress address) {
4578 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004579}
4580
4581std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4582 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004583 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004584}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004585
4586std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4587 const VkCommandBufferAllocateInfo *create_info,
4588 std::shared_ptr<COMMAND_POOL_STATE> &pool) {
4589 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4590}