blob: 8a0784c21ef9c97950ab9ace4711211d07c78ae0 [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 Gebben082a9832021-10-28 13:40:11 -0600175 Add(std::make_shared<IMAGE_STATE>(this, *pImage, pCreateInfo, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -0600176}
177
178void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600179 Destroy<IMAGE_STATE>(image);
locke-lunargd556cc32019-09-17 01:21:23 -0600180}
181
182void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
183 VkImageLayout imageLayout, const VkClearColorValue *pColor,
184 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600185 if (disabled[command_buffer_state]) return;
186
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600187 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600188 if (cb_node) {
189 cb_node->RecordTransferCmd(CMD_CLEARCOLORIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600190 }
191}
192
193void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
194 VkImageLayout imageLayout,
195 const VkClearDepthStencilValue *pDepthStencil,
196 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600197 if (disabled[command_buffer_state]) return;
198
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600199 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600200 if (cb_node) {
201 cb_node->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, GetImageState(image));
locke-lunargd556cc32019-09-17 01:21:23 -0600202 }
203}
204
205void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
206 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
207 uint32_t regionCount, const VkImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600208 if (disabled[command_buffer_state]) return;
209
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600210 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600211 cb_node->RecordTransferCmd(CMD_COPYIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600212}
213
Jeff Leger178b1e52020-10-05 12:22:23 -0400214void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
215 const VkCopyImageInfo2KHR *pCopyImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600216 if (disabled[command_buffer_state]) return;
217
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600218 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600219 cb_node->RecordTransferCmd(CMD_COPYIMAGE2KHR, GetImageState(pCopyImageInfo->srcImage), GetImageState(pCopyImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400220}
221
locke-lunargd556cc32019-09-17 01:21:23 -0600222void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
223 VkImageLayout srcImageLayout, VkImage dstImage,
224 VkImageLayout dstImageLayout, uint32_t regionCount,
225 const VkImageResolve *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600226 if (disabled[command_buffer_state]) return;
227
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600228 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600229 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600230}
231
Jeff Leger178b1e52020-10-05 12:22:23 -0400232void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
233 const VkResolveImageInfo2KHR *pResolveImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600234 if (disabled[command_buffer_state]) return;
235
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600236 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600237 cb_node->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, GetImageState(pResolveImageInfo->srcImage),
238 GetImageState(pResolveImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400239}
240
locke-lunargd556cc32019-09-17 01:21:23 -0600241void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
242 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
243 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600244 if (disabled[command_buffer_state]) return;
245
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600246 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600247 cb_node->RecordTransferCmd(CMD_BLITIMAGE, GetImageState(srcImage), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600248}
249
Jeff Leger178b1e52020-10-05 12:22:23 -0400250void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
251 const VkBlitImageInfo2KHR *pBlitImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600252 if (disabled[command_buffer_state]) return;
253
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600254 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600255 cb_node->RecordTransferCmd(CMD_BLITIMAGE2KHR, GetImageState(pBlitImageInfo->srcImage), GetImageState(pBlitImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400256}
257
locke-lunargd556cc32019-09-17 01:21:23 -0600258void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
259 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
260 VkResult result) {
261 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600262
Jeremy Gebbenc8937b62021-09-24 15:50:56 -0600263 auto buffer_state = std::make_shared<BUFFER_STATE>(this, *pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600264
James Rumble2f6e7bb2021-07-13 15:21:20 +0100265 if (pCreateInfo) {
266 const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
267 if (opaque_capture_address) {
268 // address is used for GPU-AV and ray tracing buffer validation
269 buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
270 buffer_address_map_.emplace(opaque_capture_address->opaqueCaptureAddress, buffer_state.get());
271 }
272 }
Jeremy Gebben082a9832021-10-28 13:40:11 -0600273 Add(std::move(buffer_state));
locke-lunargd556cc32019-09-17 01:21:23 -0600274}
275
276void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
277 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
278 VkResult result) {
279 if (result != VK_SUCCESS) return;
Jeremy Gebbenf2912cd2021-07-07 07:57:39 -0600280
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500281 auto buffer_state = GetBufferShared(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600282
283 VkFormatProperties format_properties;
284 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
locke-lunarg25b6c352020-08-06 17:44:18 -0600285
Jeremy Gebben082a9832021-10-28 13:40:11 -0600286 Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, format_properties.bufferFeatures));
locke-lunargd556cc32019-09-17 01:21:23 -0600287}
288
289void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
290 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
291 VkResult result) {
292 if (result != VK_SUCCESS) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500293 auto image_state = GetImageShared(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700294
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600295 VkFormatFeatureFlags format_features = 0;
296 if (image_state->HasAHBFormat() == true) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700297 // The ImageView uses same Image's format feature since they share same AHB
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600298 format_features = image_state->format_features;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700299 } else {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600300 format_features = GetImageFormatFeatures(physical_device, device, image_state->image(), pCreateInfo->format,
301 image_state->createInfo.tiling);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700302 }
303
locke-lunarg9939d4b2020-10-26 20:11:08 -0600304 // 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 -0600305 auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600306 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700307 auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
locke-lunarg9939d4b2020-10-26 20:11:08 -0600308 imageview_format_info.imageViewType = pCreateInfo->viewType;
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -0700309 auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600310 image_format_info.type = image_state->createInfo.imageType;
311 image_format_info.format = image_state->createInfo.format;
312 image_format_info.tiling = image_state->createInfo.tiling;
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600313 auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
314 image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
locke-lunarg9939d4b2020-10-26 20:11:08 -0600315 image_format_info.flags = image_state->createInfo.flags;
316
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600317 auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
locke-lunarg9939d4b2020-10-26 20:11:08 -0600318
319 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
320 }
Jeremy Gebbenb4d17012021-07-08 13:18:15 -0600321
Jeremy Gebben082a9832021-10-28 13:40:11 -0600322 Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
locke-lunargd556cc32019-09-17 01:21:23 -0600323}
324
325void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
326 uint32_t regionCount, const VkBufferCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600327 if (disabled[command_buffer_state]) return;
328
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600329 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600330 cb_node->RecordTransferCmd(CMD_COPYBUFFER, GetBufferState(srcBuffer), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600331}
332
Jeff Leger178b1e52020-10-05 12:22:23 -0400333void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600334 const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
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_COPYBUFFER2KHR, GetBufferState(pCopyBufferInfo->srcBuffer),
339 GetBufferState(pCopyBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400340}
341
locke-lunargd556cc32019-09-17 01:21:23 -0600342void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
343 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600344 Destroy<IMAGE_VIEW_STATE>(imageView);
locke-lunargd556cc32019-09-17 01:21:23 -0600345}
346
347void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600348 Destroy<BUFFER_STATE>(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600349}
350
351void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
352 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -0600353 Destroy<BUFFER_VIEW_STATE>(bufferView);
locke-lunargd556cc32019-09-17 01:21:23 -0600354}
355
356void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
357 VkDeviceSize size, uint32_t data) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600358 if (disabled[command_buffer_state]) return;
359
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600360 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600361 cb_node->RecordTransferCmd(CMD_FILLBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600362}
363
364void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
365 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
366 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600367 if (disabled[command_buffer_state]) return;
368
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600369 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -0600370
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600371 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, GetImageState(srcImage), GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -0600372}
373
Jeff Leger178b1e52020-10-05 12:22:23 -0400374void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
375 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600376 if (disabled[command_buffer_state]) return;
377
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600378 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600379 cb_node->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, GetImageState(pCopyImageToBufferInfo->srcImage),
380 GetBufferState(pCopyImageToBufferInfo->dstBuffer));
Jeff Leger178b1e52020-10-05 12:22:23 -0400381}
382
locke-lunargd556cc32019-09-17 01:21:23 -0600383void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
384 VkImageLayout dstImageLayout, uint32_t regionCount,
385 const VkBufferImageCopy *pRegions) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600386 if (disabled[command_buffer_state]) return;
387
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600388 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600389 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, GetBufferState(srcBuffer), GetImageState(dstImage));
locke-lunargd556cc32019-09-17 01:21:23 -0600390}
391
Jeff Leger178b1e52020-10-05 12:22:23 -0400392void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
393 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -0600394 if (disabled[command_buffer_state]) return;
395
Jeremy Gebben3d22d582021-08-11 15:37:58 -0600396 auto cb_node = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -0600397 cb_node->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, GetBufferState(pCopyBufferToImageInfo->srcBuffer),
398 GetImageState(pCopyBufferToImageInfo->dstImage));
Jeff Leger178b1e52020-10-05 12:22:23 -0400399}
400
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -0700401// Gets union of all features defined by Potential Format Features
402// 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 -0700403VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
404 VkFormatFeatureFlags format_features = 0;
405
406 if (format != VK_FORMAT_UNDEFINED) {
407 VkFormatProperties format_properties;
408 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
409 format_features |= format_properties.linearTilingFeatures;
410 format_features |= format_properties.optimalTilingFeatures;
sfricke-samsung45996a42021-09-16 13:45:27 -0700411 if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700412 // VK_KHR_get_physical_device_properties2 is required in this case
413 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
414 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
415 nullptr};
416 format_properties_2.pNext = (void *)&drm_properties_list;
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100417
418 // First call is to get the number of modifiers compatible with the queried format
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700419 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
Marc Alcala Prieto773871c2021-02-04 19:24:43 +0100420
421 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
422 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
423 drm_properties_list.pDrmFormatModifierProperties = drm_properties.data();
424
425 // Second call, now with an allocated array in pDrmFormatModifierProperties, is to get the modifiers
426 // compatible with the queried format
427 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
428
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700429 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
430 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
431 }
432 }
433 }
434
435 return format_features;
436}
437
locke-lunargd556cc32019-09-17 01:21:23 -0600438void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
439 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
440 VkResult result) {
441 if (VK_SUCCESS != result) return;
442
Locke Linf3873542021-04-26 11:25:10 -0600443 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
444 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
445 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
446
locke-lunargd556cc32019-09-17 01:21:23 -0600447 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
448 if (nullptr == enabled_features_found) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700449 const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600450 if (features2) {
451 enabled_features_found = &(features2->features);
452 }
453 }
454
locke-lunargd556cc32019-09-17 01:21:23 -0600455 if (nullptr == enabled_features_found) {
456 state_tracker->enabled_features.core = {};
457 } else {
458 state_tracker->enabled_features.core = *enabled_features_found;
459 }
460
locke-lunargd556cc32019-09-17 01:21:23 -0600461 // Save local link to this device's physical device state
Jeremy Gebben383b9a32021-09-08 16:31:33 -0600462 state_tracker->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu);
locke-lunargd556cc32019-09-17 01:21:23 -0600463
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700464 const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700465 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700466 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700467 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -0700468 // Set Extension Feature Aliases to false as there is no struct to check
469 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
470 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
471 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
472 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
473 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
474 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800475 state_tracker->enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
sfricke-samsung27c70722020-05-02 08:42:39 -0700476
477 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700478
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700479 const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700480 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700481 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
482 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
483 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
484 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700485 }
486
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700487 const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700488 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700489 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
490 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700491 }
492
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700493 const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700494 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700495 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
496 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
497 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
498 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
499 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
500 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
501 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
502 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
503 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
504 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
505 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
506 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
507 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
508 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
509 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
510 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
511 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
512 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
513 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
514 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
515 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
516 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
517 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
518 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
519 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
520 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
521 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
522 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
523 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
524 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
525 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
526 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
527 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
528 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
529 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
530 descriptor_indexing_features->descriptorBindingPartiallyBound;
531 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
532 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
533 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700534 }
535
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700536 const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700537 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700538 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700539 }
540
541 const auto *imageless_framebuffer_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700542 LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700543 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700544 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700545 }
546
547 const auto *uniform_buffer_standard_layout_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700548 LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700549 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700550 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
551 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700552 }
553
554 const auto *subgroup_extended_types_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700555 LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700556 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700557 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
558 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700559 }
560
561 const auto *separate_depth_stencil_layouts_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700562 LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700563 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700564 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
565 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700566 }
567
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700568 const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700569 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700570 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700571 }
572
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700573 const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700574 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700575 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700576 }
577
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700578 const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700579 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700580 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
581 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
582 buffer_device_address->bufferDeviceAddressCaptureReplay;
583 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
584 buffer_device_address->bufferDeviceAddressMultiDevice;
585 }
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800586
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700587 const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800588 if (atomic_int64_features) {
589 state_tracker->enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
590 state_tracker->enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
591 }
592
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700593 const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
sfricke-samsunga4143ac2020-12-18 00:00:53 -0800594 if (memory_model_features) {
595 state_tracker->enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
596 state_tracker->enabled_features.core12.vulkanMemoryModelDeviceScope =
597 memory_model_features->vulkanMemoryModelDeviceScope;
598 state_tracker->enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
599 memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
600 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700601 }
602
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700603 const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700604 if (vulkan_11_features) {
605 state_tracker->enabled_features.core11 = *vulkan_11_features;
606 } else {
sfricke-samsung828e59d2021-08-22 23:20:49 -0700607 // These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700608
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700609 const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700610 if (sixteen_bit_storage_features) {
611 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
612 sixteen_bit_storage_features->storageBuffer16BitAccess;
613 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
614 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
615 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
616 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
617 }
618
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700619 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700620 if (multiview_features) {
621 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
622 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
623 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
624 }
625
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700626 const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700627 if (variable_pointers_features) {
628 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
629 variable_pointers_features->variablePointersStorageBuffer;
630 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
631 }
632
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700633 const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700634 if (protected_memory_features) {
635 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
636 }
637
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700638 const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700639 if (ycbcr_conversion_features) {
640 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
641 }
642
643 const auto *shader_draw_parameters_features =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700644 LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700645 if (shader_draw_parameters_features) {
646 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -0700647 }
648 }
649
Mark Lobodzinski1f887d32020-12-30 15:31:33 -0700650 const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -0600651 if (device_group_ci) {
652 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
653 state_tracker->device_group_create_info = *device_group_ci;
654 } else {
655 state_tracker->physical_device_count = 1;
656 }
locke-lunargd556cc32019-09-17 01:21:23 -0600657
sfricke-samsung828e59d2021-08-22 23:20:49 -0700658 // Features from other extensions passesd in create info
659 {
660 const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
661 if (exclusive_scissor_features) {
662 state_tracker->enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
663 }
locke-lunargd556cc32019-09-17 01:21:23 -0600664
sfricke-samsung828e59d2021-08-22 23:20:49 -0700665 const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
666 if (shading_rate_image_features) {
667 state_tracker->enabled_features.shading_rate_image_features = *shading_rate_image_features;
668 }
locke-lunargd556cc32019-09-17 01:21:23 -0600669
sfricke-samsung828e59d2021-08-22 23:20:49 -0700670 const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
671 if (mesh_shader_features) {
672 state_tracker->enabled_features.mesh_shader_features = *mesh_shader_features;
673 }
locke-lunargd556cc32019-09-17 01:21:23 -0600674
sfricke-samsung828e59d2021-08-22 23:20:49 -0700675 const auto *inline_uniform_block_features =
676 LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
677 if (inline_uniform_block_features) {
678 state_tracker->enabled_features.inline_uniform_block_features = *inline_uniform_block_features;
679 }
locke-lunargd556cc32019-09-17 01:21:23 -0600680
sfricke-samsung828e59d2021-08-22 23:20:49 -0700681 const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
682 if (transform_feedback_features) {
683 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
684 }
locke-lunargd556cc32019-09-17 01:21:23 -0600685
sfricke-samsung828e59d2021-08-22 23:20:49 -0700686 const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
687 if (vtx_attrib_div_features) {
688 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
689 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -0700690
sfricke-samsung828e59d2021-08-22 23:20:49 -0700691 const auto *buffer_device_address_ext_features =
692 LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
693 if (buffer_device_address_ext_features) {
694 state_tracker->enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
695 }
locke-lunargd556cc32019-09-17 01:21:23 -0600696
sfricke-samsung828e59d2021-08-22 23:20:49 -0700697 const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
698 if (cooperative_matrix_features) {
699 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
700 }
locke-lunargd556cc32019-09-17 01:21:23 -0600701
sfricke-samsung828e59d2021-08-22 23:20:49 -0700702 const auto *compute_shader_derivatives_features =
703 LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
704 if (compute_shader_derivatives_features) {
705 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
706 }
locke-lunargd556cc32019-09-17 01:21:23 -0600707
sfricke-samsung828e59d2021-08-22 23:20:49 -0700708 const auto *fragment_shader_barycentric_features =
709 LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
710 if (fragment_shader_barycentric_features) {
711 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
712 }
locke-lunargd556cc32019-09-17 01:21:23 -0600713
sfricke-samsung828e59d2021-08-22 23:20:49 -0700714 const auto *shader_image_footprint_features =
715 LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
716 if (shader_image_footprint_features) {
717 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
718 }
locke-lunargd556cc32019-09-17 01:21:23 -0600719
sfricke-samsung828e59d2021-08-22 23:20:49 -0700720 const auto *fragment_shader_interlock_features =
721 LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
722 if (fragment_shader_interlock_features) {
723 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
724 }
locke-lunargd556cc32019-09-17 01:21:23 -0600725
sfricke-samsung828e59d2021-08-22 23:20:49 -0700726 const auto *demote_to_helper_invocation_features =
727 LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
728 if (demote_to_helper_invocation_features) {
729 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
730 }
locke-lunargd556cc32019-09-17 01:21:23 -0600731
sfricke-samsung828e59d2021-08-22 23:20:49 -0700732 const auto *texel_buffer_alignment_features =
733 LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
734 if (texel_buffer_alignment_features) {
735 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
736 }
locke-lunargd556cc32019-09-17 01:21:23 -0600737
sfricke-samsung828e59d2021-08-22 23:20:49 -0700738 const auto *pipeline_exe_props_features =
739 LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
740 if (pipeline_exe_props_features) {
741 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
742 }
locke-lunargd556cc32019-09-17 01:21:23 -0600743
sfricke-samsung828e59d2021-08-22 23:20:49 -0700744 const auto *dedicated_allocation_image_aliasing_features =
745 LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
746 if (dedicated_allocation_image_aliasing_features) {
747 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
748 *dedicated_allocation_image_aliasing_features;
749 }
Jeff Bolz82f854d2019-09-17 14:56:47 -0500750
sfricke-samsung828e59d2021-08-22 23:20:49 -0700751 const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
752 if (performance_query_features) {
753 state_tracker->enabled_features.performance_query_features = *performance_query_features;
754 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +0100755
sfricke-samsung828e59d2021-08-22 23:20:49 -0700756 const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
757 if (device_coherent_memory_features) {
758 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
759 }
Tobias Hector782bcde2019-11-28 16:19:42 +0000760
sfricke-samsung828e59d2021-08-22 23:20:49 -0700761 const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
762 if (ycbcr_image_array_features) {
763 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
764 }
sfricke-samsungcead0802020-01-30 22:20:10 -0800765
sfricke-samsung828e59d2021-08-22 23:20:49 -0700766 const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
767 if (ray_query_features) {
768 state_tracker->enabled_features.ray_query_features = *ray_query_features;
769 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700770
sfricke-samsung828e59d2021-08-22 23:20:49 -0700771 const auto *ray_tracing_pipeline_features =
772 LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
773 if (ray_tracing_pipeline_features) {
774 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
775 }
sourav parmarcd5fb182020-07-17 12:58:44 -0700776
sfricke-samsung828e59d2021-08-22 23:20:49 -0700777 const auto *ray_tracing_acceleration_structure_features =
778 LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
779 if (ray_tracing_acceleration_structure_features) {
780 state_tracker->enabled_features.ray_tracing_acceleration_structure_features =
781 *ray_tracing_acceleration_structure_features;
782 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -0500783
sfricke-samsung828e59d2021-08-22 23:20:49 -0700784 const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
785 if (robustness2_features) {
786 state_tracker->enabled_features.robustness2_features = *robustness2_features;
787 }
Jeff Bolz165818a2020-05-08 11:19:03 -0500788
sfricke-samsung828e59d2021-08-22 23:20:49 -0700789 const auto *fragment_density_map_features =
790 LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
791 if (fragment_density_map_features) {
792 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
793 }
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +0200794
sfricke-samsung828e59d2021-08-22 23:20:49 -0700795 const auto *fragment_density_map_features2 =
796 LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
797 if (fragment_density_map_features2) {
798 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
799 }
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +0200800
sfricke-samsung828e59d2021-08-22 23:20:49 -0700801 const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
802 if (astc_decode_features) {
803 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
804 }
sfricke-samsung0c4a06f2020-06-27 01:24:32 -0700805
sfricke-samsung828e59d2021-08-22 23:20:49 -0700806 const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
807 if (custom_border_color_features) {
808 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
809 }
Tony-LunarG7337b312020-04-15 16:40:25 -0600810
sfricke-samsung828e59d2021-08-22 23:20:49 -0700811 const auto *pipeline_creation_cache_control_features =
812 LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
813 if (pipeline_creation_cache_control_features) {
814 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
815 }
sfricke-samsungfd661d62020-05-16 00:57:27 -0700816
sfricke-samsung828e59d2021-08-22 23:20:49 -0700817 const auto *fragment_shading_rate_features =
818 LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
819 if (fragment_shading_rate_features) {
820 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
821 }
Tobias Hector6663c9b2020-11-05 10:18:02 +0000822
sfricke-samsung828e59d2021-08-22 23:20:49 -0700823 const auto *extended_dynamic_state_features =
824 LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
825 if (extended_dynamic_state_features) {
826 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
827 }
Piers Daniell39842ee2020-07-10 16:42:33 -0600828
sfricke-samsung828e59d2021-08-22 23:20:49 -0700829 const auto *extended_dynamic_state2_features =
830 LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
831 if (extended_dynamic_state2_features) {
832 state_tracker->enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
833 }
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -0700834
sfricke-samsung828e59d2021-08-22 23:20:49 -0700835 const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
836 if (multiview_features) {
837 state_tracker->enabled_features.multiview_features = *multiview_features;
838 }
locke-lunarg3fa463a2020-10-23 16:39:04 -0600839
sfricke-samsung828e59d2021-08-22 23:20:49 -0700840 const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
841 if (portability_features) {
842 state_tracker->enabled_features.portability_subset_features = *portability_features;
843 }
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -0700844
sfricke-samsung828e59d2021-08-22 23:20:49 -0700845 const auto *shader_integer_functions2_features =
846 LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
847 if (shader_integer_functions2_features) {
848 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
849 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800850
sfricke-samsung828e59d2021-08-22 23:20:49 -0700851 const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
852 if (shader_sm_builtins_features) {
853 state_tracker->enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
854 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800855
sfricke-samsung828e59d2021-08-22 23:20:49 -0700856 const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
857 if (shader_atomic_float_features) {
858 state_tracker->enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
859 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800860
sfricke-samsung828e59d2021-08-22 23:20:49 -0700861 const auto *shader_image_atomic_int64_features =
862 LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
863 if (shader_image_atomic_int64_features) {
864 state_tracker->enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
865 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800866
sfricke-samsung828e59d2021-08-22 23:20:49 -0700867 const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
868 if (shader_clock_features) {
869 state_tracker->enabled_features.shader_clock_features = *shader_clock_features;
870 }
sfricke-samsung486a51e2021-01-02 00:10:15 -0800871
sfricke-samsung828e59d2021-08-22 23:20:49 -0700872 const auto *conditional_rendering_features =
873 LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
874 if (conditional_rendering_features) {
875 state_tracker->enabled_features.conditional_rendering_features = *conditional_rendering_features;
876 }
Jeremy Gebben5f585ae2021-02-02 09:03:06 -0700877
sfricke-samsung828e59d2021-08-22 23:20:49 -0700878 const auto *workgroup_memory_explicit_layout_features =
879 LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
880 if (workgroup_memory_explicit_layout_features) {
881 state_tracker->enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
882 }
Shannon McPhersondb287d42021-02-02 15:27:32 -0700883
sfricke-samsung828e59d2021-08-22 23:20:49 -0700884 const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2FeaturesKHR>(pCreateInfo->pNext);
885 if (synchronization2_features) {
886 state_tracker->enabled_features.synchronization2_features = *synchronization2_features;
887 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -0700888
sfricke-samsung828e59d2021-08-22 23:20:49 -0700889 const auto *provoking_vertex_features = lvl_find_in_chain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
890 if (provoking_vertex_features) {
891 state_tracker->enabled_features.provoking_vertex_features = *provoking_vertex_features;
892 }
Locke Linf3873542021-04-26 11:25:10 -0600893
sfricke-samsung828e59d2021-08-22 23:20:49 -0700894 const auto *vertex_input_dynamic_state_features =
895 LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
896 if (vertex_input_dynamic_state_features) {
897 state_tracker->enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
898 }
Piers Daniellcb6d8032021-04-19 18:51:26 -0600899
sfricke-samsung828e59d2021-08-22 23:20:49 -0700900 const auto *inherited_viewport_scissor_features =
901 LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
902 if (inherited_viewport_scissor_features) {
903 state_tracker->enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
904 }
David Zhao Akeley44139b12021-04-26 16:16:13 -0700905
sfricke-samsung828e59d2021-08-22 23:20:49 -0700906 const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
907 if (multi_draw_features) {
908 state_tracker->enabled_features.multi_draw_features = *multi_draw_features;
909 }
Tony-LunarG4490de42021-06-21 15:49:19 -0600910
sfricke-samsung828e59d2021-08-22 23:20:49 -0700911 const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
912 if (color_write_features) {
913 state_tracker->enabled_features.color_write_features = *color_write_features;
914 }
ziga-lunarg29ba2b92021-07-20 21:51:45 +0200915
sfricke-samsung828e59d2021-08-22 23:20:49 -0700916 const auto *shader_atomic_float2_features =
917 LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
918 if (shader_atomic_float2_features) {
919 state_tracker->enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
920 }
Mike Schuchardtb3870ea2021-07-20 18:56:51 -0700921
sfricke-samsung828e59d2021-08-22 23:20:49 -0700922 const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
923 if (present_id_features) {
924 state_tracker->enabled_features.present_id_features = *present_id_features;
925 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600926
sfricke-samsung828e59d2021-08-22 23:20:49 -0700927 const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
928 if (present_wait_features) {
929 state_tracker->enabled_features.present_wait_features = *present_wait_features;
930 }
Mike Schuchardt9f65d3f2021-08-25 15:11:39 -0700931
932 const auto *ray_tracing_motion_blur_features =
933 LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
934 if (ray_tracing_motion_blur_features) {
935 state_tracker->enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
936 }
Mike Schuchardtb4d90452021-08-30 09:24:51 -0700937
938 const auto *shader_integer_dot_product_features =
939 LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
940 if (shader_integer_dot_product_features) {
941 state_tracker->enabled_features.shader_integer_dot_product_features = *shader_integer_dot_product_features;
942 }
Tony-LunarG0b0d8be2021-08-30 13:50:38 -0600943
944 const auto *primitive_topology_list_restart_features =
945 LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
946 if (primitive_topology_list_restart_features) {
947 state_tracker->enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
948 }
sfricke-samsung10b35ce2021-09-29 08:50:20 -0700949
950 const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
951 if (rgba10x6_formats_features) {
952 state_tracker->enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
953 }
sfricke-samsungd3c917b2021-10-19 08:24:57 -0700954
955 const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
956 if (maintenance4_features) {
957 state_tracker->enabled_features.maintenance4_features = *maintenance4_features;
958 }
Jeremy Gebbence23dac2021-11-10 10:19:42 -0700959
960 const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeaturesKHR>(pCreateInfo->pNext);
961 if (dynamic_rendering_features) {
962 state_tracker->enabled_features.dynamic_rendering_features = *dynamic_rendering_features;
963 }
Tony-LunarG6f887e52021-07-27 11:23:14 -0600964 }
965
ziga-lunarg73163742021-08-25 13:15:29 +0200966 const auto *subgroup_size_control_features = LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeaturesEXT>(pCreateInfo->pNext);
967 if (subgroup_size_control_features) {
968 state_tracker->enabled_features.subgroup_size_control_features = *subgroup_size_control_features;
969 }
970
locke-lunargd556cc32019-09-17 01:21:23 -0600971 // Store physical device properties and physical device mem limits into CoreChecks structs
972 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
973 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
974
975 const auto &dev_ext = state_tracker->device_extensions;
976 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
977
sfricke-samsung828e59d2021-08-22 23:20:49 -0700978 // Vulkan 1.2 can get properties from single struct, otherwise need to add to it per extension
sfricke-samsung45996a42021-09-16 13:45:27 -0700979 if (dev_ext.vk_feature_version_1_2) {
980 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core11);
981 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_feature_version_1_2, &state_tracker->phys_dev_props_core12);
sfricke-samsung828e59d2021-08-22 23:20:49 -0700982 } else {
983 // VkPhysicalDeviceVulkan11Properties
984 //
985 // Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
986
987 if (dev_ext.vk_khr_multiview) {
988 auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
989 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &multiview_props);
990 state_tracker->phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
991 state_tracker->phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
992 }
993
994 if (dev_ext.vk_khr_maintenance3) {
995 auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
996 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_maintenance3, &maintenance3_props);
997 state_tracker->phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
998 state_tracker->phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
999 }
1000
1001 // Some 1.1 properties were added to core without previous extensions
1002 if (state_tracker->api_version >= VK_API_VERSION_1_1) {
1003 auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
1004 auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
1005 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
1006 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
1007
1008 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
1009 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
1010 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
1011 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
1012
1013 state_tracker->phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
1014 }
1015
1016 // VkPhysicalDeviceVulkan12Properties
1017 //
1018 // Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
1019
1020 if (dev_ext.vk_ext_descriptor_indexing) {
1021 auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
1022 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1023 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1024 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1025 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1026 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1027 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1028 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1029 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1030 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1031 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1032 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1033 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1034 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1035 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1036 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1037 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1038 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1039 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1040 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1041 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1042 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1043 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1044 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1045 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1046 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1047 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1048 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1049 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1050 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1051 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1052 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1053 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1054 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1055 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1056 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1057 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1058 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1059 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1060 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1061 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1062 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1063 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1064 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1065 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1066 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1067 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1068 }
1069
1070 if (dev_ext.vk_khr_depth_stencil_resolve) {
1071 auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
1072 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
1073 state_tracker->phys_dev_props_core12.supportedDepthResolveModes =
1074 depth_stencil_resolve_props.supportedDepthResolveModes;
1075 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
1076 depth_stencil_resolve_props.supportedStencilResolveModes;
1077 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
1078 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
1079 }
1080
1081 if (dev_ext.vk_khr_timeline_semaphore) {
1082 auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
1083 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
1084 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
1085 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
1086 }
1087
1088 if (dev_ext.vk_ext_sampler_filter_minmax) {
1089 auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
1090 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
1091 state_tracker->phys_dev_props_core12.filterMinmaxSingleComponentFormats =
1092 sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
1093 state_tracker->phys_dev_props_core12.filterMinmaxImageComponentMapping =
1094 sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
1095 }
1096
1097 if (dev_ext.vk_khr_shader_float_controls) {
1098 auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
1099 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
1100 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
1101 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
1102 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
1103 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
1104 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
1105 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
1106 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
1107 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
1108 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
1109 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
1110 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
1111 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 =
1112 float_controls_props.shaderDenormFlushToZeroFloat16;
1113 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 =
1114 float_controls_props.shaderDenormFlushToZeroFloat32;
1115 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 =
1116 float_controls_props.shaderDenormFlushToZeroFloat64;
1117 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
1118 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
1119 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
1120 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
1121 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
1122 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
1123 }
locke-lunargd556cc32019-09-17 01:21:23 -06001124 }
1125
sfricke-samsung828e59d2021-08-22 23:20:49 -07001126 // Extensions with properties to extract to DeviceExtensionProperties
1127 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001128 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1129 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1130 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1131 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001132 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001133 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07001134 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
1135 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001136 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
1137 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
Mike Schuchardtc57de4a2021-07-20 17:26:32 -07001138 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001139 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07001140 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06001141 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06001142 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07001143 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
sfricke-samsung828e59d2021-08-22 23:20:49 -07001144 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
Locke Lin016d8482021-05-27 12:11:31 -06001145 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
Tony-LunarG4490de42021-06-21 15:49:19 -06001146 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
ziga-lunarg128904a2021-07-30 13:49:01 +02001147 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
ziga-lunarg86492812021-08-05 23:58:16 +02001148 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_blend_operation_advanced, &phys_dev_props->blend_operation_advanced_props);
ziga-lunargbd8ded62021-09-20 18:24:39 +02001149 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_conservative_rasterization, &phys_dev_props->conservative_rasterization_props);
ziga-lunarg11fecb92021-09-20 16:48:06 +02001150 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_subgroup_size_control, &phys_dev_props->subgroup_size_control_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001151
sfricke-samsung45996a42021-09-16 13:45:27 -07001152 if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001153 // Get the needed cooperative_matrix properties
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001154 auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
1155 auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06001156 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
1157 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
1158
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001159 uint32_t num_cooperative_matrix_properties = 0;
1160 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
1161 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
Mark Lobodzinski6fe9e702020-12-30 15:36:39 -07001162 LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06001163
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001164 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06001165 state_tracker->cooperative_matrix_properties.data());
1166 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00001167
locke-lunargd556cc32019-09-17 01:21:23 -06001168 // Store queue family data
1169 if (pCreateInfo->pQueueCreateInfos != nullptr) {
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001170 uint32_t total_count = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001171 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07001172 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
sfricke-samsungb585ec12021-05-06 03:10:13 -07001173 state_tracker->queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
1174 state_tracker->device_queue_info_list.push_back(
1175 {i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001176 total_count += queue_create_info.queueCount;
1177 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001178 queue_map_.reserve(total_count);
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001179 for (const auto &queue_info : state_tracker->device_queue_info_list) {
1180 for (uint32_t i = 0; i < queue_info.queue_count; i++) {
1181 VkQueue queue = VK_NULL_HANDLE;
1182 // vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
1183 if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
1184 auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
1185 get_info.flags = queue_info.flags;
1186 get_info.queueFamilyIndex = queue_info.queue_family_index;
1187 get_info.queueIndex = i;
1188 DispatchGetDeviceQueue2(*pDevice, &get_info, &queue);
1189 } else {
1190 DispatchGetDeviceQueue(*pDevice, queue_info.queue_family_index, i, &queue);
1191 }
1192 assert(queue != VK_NULL_HANDLE);
Mike Schuchardta9101d32021-11-12 12:24:08 -08001193 state_tracker->Add(std::make_shared<QUEUE_STATE>(queue, queue_info.queue_family_index, queue_info.flags));
Jeremy Gebbena15e2382021-09-30 11:49:32 -06001194 }
locke-lunargd556cc32019-09-17 01:21:23 -06001195 }
1196 }
1197}
1198
1199void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
1200 if (!device) return;
1201
Jeremy Gebbend177d922021-10-28 13:42:10 -06001202 command_pool_map_.clear();
1203 assert(command_buffer_map_.empty());
1204 pipeline_map_.clear();
1205 render_pass_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001206
1207 // This will also delete all sets in the pool & remove them from setMap
Jeremy Gebbend177d922021-10-28 13:42:10 -06001208 descriptor_pool_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001209 // All sets should be removed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001210 assert(descriptor_set_map_.empty());
1211 desc_template_map_.clear();
1212 descriptor_set_layout_map_.clear();
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001213 // Because swapchains are associated with Surfaces, which are at instance level,
1214 // they need to be explicitly destroyed here to avoid continued references to
1215 // the device we're destroying.
Jeremy Gebbend177d922021-10-28 13:42:10 -06001216 for (auto &entry : swapchain_map_) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06001217 entry.second->Destroy();
1218 }
Jeremy Gebbend177d922021-10-28 13:42:10 -06001219 swapchain_map_.clear();
1220 image_view_map_.clear();
1221 image_map_.clear();
1222 buffer_view_map_.clear();
1223 buffer_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001224 // Queues persist until device is destroyed
Jeremy Gebbend177d922021-10-28 13:42:10 -06001225 queue_map_.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001226}
1227
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001228void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
1229 VkFence fence, VkResult result) {
1230 if (result != VK_SUCCESS) return;
1231 auto queue_state = GetQueueState(queue);
1232
Jeremy Gebben57642982021-09-14 14:14:55 -06001233 uint64_t early_retire_seq = 0;
1234
1235 if (submitCount == 0) {
1236 CB_SUBMISSION submission;
1237 submission.AddFence(GetShared<FENCE_STATE>(fence));
1238 early_retire_seq = queue_state->Submit(std::move(submission));
1239 }
locke-lunargd556cc32019-09-17 01:21:23 -06001240
1241 // Now process each individual submit
1242 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001243 CB_SUBMISSION submission;
locke-lunargd556cc32019-09-17 01:21:23 -06001244 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001245 auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001246 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001247 uint64_t value = 0;
1248 if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
1249 (i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
1250 value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
1251 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001252 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
locke-lunargd556cc32019-09-17 01:21:23 -06001253 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001254
locke-lunargd556cc32019-09-17 01:21:23 -06001255 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
Jeremy Gebben4ae5cc72021-03-10 15:34:44 -07001256 uint64_t value = 0;
1257 if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
1258 (i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
1259 value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
1260 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001261 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001262 }
1263
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001264 const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001265 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02001266
locke-lunargd556cc32019-09-17 01:21:23 -06001267 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001268 submission.AddCommandBuffer(GetShared<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001269 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001270 if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
1271 submission.AddFence(GetShared<FENCE_STATE>(fence));
1272 }
1273 auto submit_seq = queue_state->Submit(std::move(submission));
1274 early_retire_seq = std::max(early_retire_seq, submit_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001275 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001276
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001277 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001278 queue_state->Retire(early_retire_seq);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001279 }
1280}
1281
1282void ValidationStateTracker::PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
1283 VkFence fence, VkResult result) {
1284 if (result != VK_SUCCESS) return;
1285 auto queue_state = GetQueueState(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001286 uint64_t early_retire_seq = 0;
1287 if (submitCount == 0) {
1288 CB_SUBMISSION submission;
1289 submission.AddFence(GetShared<FENCE_STATE>(fence));
1290 early_retire_seq = queue_state->Submit(std::move(submission));
1291 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001292
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001293 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
1294 CB_SUBMISSION submission;
1295 const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001296 for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
1297 const auto &sem_info = submit->pWaitSemaphoreInfos[i];
Jeremy Gebben57642982021-09-14 14:14:55 -06001298 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001299 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001300 for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
1301 const auto &sem_info = submit->pSignalSemaphoreInfos[i];
Jeremy Gebben57642982021-09-14 14:14:55 -06001302 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001303 }
1304 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
1305 submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
1306
1307 for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001308 submission.AddCommandBuffer(GetShared<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001309 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001310 if (submit_idx == (submitCount - 1)) {
1311 submission.AddFence(GetShared<FENCE_STATE>(fence));
1312 }
1313 auto submit_seq = queue_state->Submit(std::move(submission));
1314 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001315 }
locke-lunargd556cc32019-09-17 01:21:23 -06001316 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001317 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001318 }
1319}
1320
1321void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
1322 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
1323 VkResult result) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001324 if (VK_SUCCESS != result) {
1325 return;
locke-lunargd556cc32019-09-17 01:21:23 -06001326 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001327 const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
1328 const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
1329 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
1330
1331 layer_data::optional<DedicatedBinding> dedicated_binding;
1332
1333 auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
1334 if (dedicated) {
1335 if (dedicated->buffer) {
1336 const auto *buffer_state = GetBufferState(dedicated->buffer);
1337 assert(buffer_state);
1338 if (!buffer_state) {
1339 return;
1340 }
1341 dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
1342 } else if (dedicated->image) {
1343 const auto *image_state = GetImageState(dedicated->image);
1344 assert(image_state);
1345 if (!image_state) {
1346 return;
1347 }
1348 dedicated_binding.emplace(dedicated->image, image_state->createInfo);
1349 }
1350 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001351 Add(std::make_shared<DEVICE_MEMORY_STATE>(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap,
1352 std::move(dedicated_binding), physical_device_count));
locke-lunargd556cc32019-09-17 01:21:23 -06001353 return;
1354}
1355
1356void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
locke-lunargd556cc32019-09-17 01:21:23 -06001357 DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001358 if (mem_info) {
1359 fake_memory.Free(mem_info->fake_base_address);
1360 }
1361 Destroy<DEVICE_MEMORY_STATE>(mem);
locke-lunargd556cc32019-09-17 01:21:23 -06001362}
1363
1364void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
1365 VkFence fence, VkResult result) {
1366 if (result != VK_SUCCESS) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001367 auto queue_state = GetQueueState(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06001368
Jeremy Gebben57642982021-09-14 14:14:55 -06001369 uint64_t early_retire_seq = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06001370
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001371 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
1372 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06001373 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001374 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
1375 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
1376 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001377 auto buffer_state = GetBufferState(bind_info.pBufferBinds[j].buffer);
1378 auto mem_state = GetDevMemShared(sparse_binding.memory);
1379 if (buffer_state && mem_state) {
1380 buffer_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1381 }
locke-lunargd556cc32019-09-17 01:21:23 -06001382 }
1383 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001384 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
1385 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
1386 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001387 auto image_state = GetImageState(bind_info.pImageOpaqueBinds[j].image);
1388 auto mem_state = GetDevMemShared(sparse_binding.memory);
1389 if (image_state && mem_state) {
1390 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, sparse_binding.size);
1391 }
locke-lunargd556cc32019-09-17 01:21:23 -06001392 }
1393 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001394 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
1395 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
1396 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06001397 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
1398 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001399 auto image_state = GetImageState(bind_info.pImageBinds[j].image);
1400 auto mem_state = GetDevMemShared(sparse_binding.memory);
1401 if (image_state && mem_state) {
1402 image_state->SetSparseMemBinding(mem_state, sparse_binding.memoryOffset, size);
1403 }
locke-lunargd556cc32019-09-17 01:21:23 -06001404 }
1405 }
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001406 CB_SUBMISSION submission;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001407 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001408 submission.AddWaitSemaphore(GetShared<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), 0);
locke-lunargd556cc32019-09-17 01:21:23 -06001409 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001410 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001411 submission.AddSignalSemaphore(GetShared<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), 0);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07001412 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001413 if (bind_idx == (bindInfoCount - 1)) {
1414 submission.AddFence(GetShared<FENCE_STATE>(fence));
locke-lunargd556cc32019-09-17 01:21:23 -06001415 }
Jeremy Gebben57642982021-09-14 14:14:55 -06001416 auto submit_seq = queue_state->Submit(std::move(submission));
1417 early_retire_seq = std::max(early_retire_seq, submit_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001418 }
1419
1420 if (early_retire_seq) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001421 queue_state->Retire(early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06001422 }
1423}
1424
1425void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
1426 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
1427 VkResult result) {
1428 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001429 Add(std::make_shared<SEMAPHORE_STATE>(*pSemaphore, LvlFindInChain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext)));
locke-lunargd556cc32019-09-17 01:21:23 -06001430}
1431
Mike Schuchardt2df08912020-12-15 16:28:09 -08001432void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
1433 VkSemaphoreImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06001434 SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore);
1435 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001436 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06001437 sema_node->scope == kSyncScopeInternal) {
1438 sema_node->scope = kSyncScopeExternalTemporary;
1439 } else {
1440 sema_node->scope = kSyncScopeExternalPermanent;
1441 }
1442 }
1443}
1444
Mike Schuchardt2df08912020-12-15 16:28:09 -08001445void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001446 VkResult result) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001447 auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore);
1448 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00001449}
1450
locke-lunargd556cc32019-09-17 01:21:23 -06001451void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
1452 auto mem_info = GetDevMemState(mem);
1453 if (mem_info) {
1454 mem_info->mapped_range.offset = offset;
1455 mem_info->mapped_range.size = size;
1456 mem_info->p_driver_data = *ppData;
1457 }
1458}
1459
locke-lunargd556cc32019-09-17 01:21:23 -06001460void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1461 VkBool32 waitAll, uint64_t timeout, VkResult result) {
1462 if (VK_SUCCESS != result) return;
1463
1464 // When we know that all fences are complete we can clean/remove their CBs
1465 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
1466 for (uint32_t i = 0; i < fenceCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001467 auto fence_state = GetFenceState(pFences[i]);
1468 if (fence_state) {
1469 fence_state->Retire();
1470 }
locke-lunargd556cc32019-09-17 01:21:23 -06001471 }
1472 }
1473 // NOTE : Alternate case not handled here is when some fences have completed. In
1474 // this case for app to guarantee which fences completed it will have to call
1475 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
1476}
1477
John Zulauff89de662020-04-13 18:57:34 -06001478void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1479 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001480 if (VK_SUCCESS != result) return;
1481
1482 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001483 auto semaphore_state = GetSemaphoreState(pWaitInfo->pSemaphores[i]);
1484 if (semaphore_state) {
1485 semaphore_state->Retire(pWaitInfo->pValues[i]);
1486 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01001487 }
1488}
1489
John Zulauff89de662020-04-13 18:57:34 -06001490void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
1491 VkResult result) {
1492 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1493}
1494
1495void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
1496 uint64_t timeout, VkResult result) {
1497 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
1498}
1499
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001500void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1501 VkResult result) {
1502 if (VK_SUCCESS != result) return;
1503
Jeremy Gebben57642982021-09-14 14:14:55 -06001504 auto semaphore_state = GetSemaphoreState(semaphore);
1505 if (semaphore_state) {
1506 semaphore_state->Retire(*pValue);
1507 }
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02001508}
1509
1510void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1511 VkResult result) {
1512 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1513}
1514void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
1515 VkResult result) {
1516 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
1517}
1518
locke-lunargd556cc32019-09-17 01:21:23 -06001519void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
1520 if (VK_SUCCESS != result) return;
Jeremy Gebben57642982021-09-14 14:14:55 -06001521 auto fence_state = GetFenceState(fence);
1522 if (fence_state) {
1523 fence_state->Retire();
1524 }
locke-lunargd556cc32019-09-17 01:21:23 -06001525}
1526
locke-lunargd556cc32019-09-17 01:21:23 -06001527void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
1528 if (VK_SUCCESS != result) return;
1529 QUEUE_STATE *queue_state = GetQueueState(queue);
Jeremy Gebben57642982021-09-14 14:14:55 -06001530 if (queue_state) {
1531 queue_state->Retire();
1532 }
locke-lunargd556cc32019-09-17 01:21:23 -06001533}
1534
1535void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
1536 if (VK_SUCCESS != result) return;
Jeremy Gebbend177d922021-10-28 13:42:10 -06001537 for (auto &queue : queue_map_) {
Jeremy Gebben57642982021-09-14 14:14:55 -06001538 queue.second->Retire();
locke-lunargd556cc32019-09-17 01:21:23 -06001539 }
1540}
1541
1542void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001543 Destroy<FENCE_STATE>(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06001544}
1545
1546void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
1547 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001548 Destroy<SEMAPHORE_STATE>(semaphore);
locke-lunargd556cc32019-09-17 01:21:23 -06001549}
1550
1551void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001552 Destroy<EVENT_STATE>(event);
locke-lunargd556cc32019-09-17 01:21:23 -06001553}
1554
1555void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
1556 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001557 Destroy<QUERY_POOL_STATE>(queryPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001558}
1559
locke-lunargd556cc32019-09-17 01:21:23 -06001560void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
1561 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1562 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001563 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001564 auto mem_state = GetDevMemShared(mem);
1565 if (mem_state) {
1566 buffer_state->SetMemBinding(mem_state, memoryOffset);
1567 }
locke-lunargd556cc32019-09-17 01:21:23 -06001568 }
1569}
1570
1571void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
1572 VkDeviceSize memoryOffset, VkResult result) {
1573 if (VK_SUCCESS != result) return;
1574 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
1575}
1576
1577void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001578 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001579 for (uint32_t i = 0; i < bindInfoCount; i++) {
1580 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1581 }
1582}
1583
1584void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001585 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06001586 for (uint32_t i = 0; i < bindInfoCount; i++) {
1587 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
1588 }
1589}
1590
Spencer Fricke6c127102020-04-16 06:25:20 -07001591void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
locke-lunargd556cc32019-09-17 01:21:23 -06001592 BUFFER_STATE *buffer_state = GetBufferState(buffer);
1593 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06001594 buffer_state->memory_requirements_checked = true;
1595 }
1596}
1597
1598void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
1599 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001600 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001601}
1602
1603void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001604 const VkBufferMemoryRequirementsInfo2 *pInfo,
1605 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001606 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001607}
1608
1609void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08001610 const VkBufferMemoryRequirementsInfo2 *pInfo,
1611 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001612 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001613}
1614
Spencer Fricke6c127102020-04-16 06:25:20 -07001615void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001616 const VkImagePlaneMemoryRequirementsInfo *plane_info =
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001617 (pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001618 IMAGE_STATE *image_state = GetImageState(image);
1619 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001620 if (plane_info != nullptr) {
1621 // Multi-plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001622 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001623 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001624 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001625 image_state->memory_requirements_checked[1] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001626 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001627 image_state->memory_requirements_checked[2] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001628 }
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001629 } else if (!image_state->disjoint) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001630 // Single Plane image
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06001631 image_state->memory_requirements_checked[0] = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07001632 }
locke-lunargd556cc32019-09-17 01:21:23 -06001633 }
1634}
1635
1636void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
1637 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001638 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06001639}
1640
1641void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
1642 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001643 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001644}
1645
1646void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
1647 const VkImageMemoryRequirementsInfo2 *pInfo,
1648 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07001649 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06001650}
1651
locke-lunargd556cc32019-09-17 01:21:23 -06001652void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
1653 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
1654 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
1655 auto image_state = GetImageState(image);
1656 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001657}
1658
1659void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001660 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1661 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06001662 auto image_state = GetImageState(pInfo->image);
1663 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001664}
1665
1666void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08001667 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
1668 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06001669 auto image_state = GetImageState(pInfo->image);
1670 image_state->get_sparse_reqs_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06001671}
1672
1673void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
1674 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001675 Destroy<SHADER_MODULE_STATE>(shaderModule);
locke-lunargd556cc32019-09-17 01:21:23 -06001676}
1677
1678void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
1679 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001680 Destroy<PIPELINE_STATE>(pipeline);
locke-lunargd556cc32019-09-17 01:21:23 -06001681}
1682
1683void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
1684 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001685 Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001686}
1687
1688void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
1689 const VkAllocationCallbacks *pAllocator) {
1690 if (!sampler) return;
1691 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001692 // Any bound cmd buffers are now invalid
1693 if (sampler_state) {
Yuly Novikov424cdd52020-05-26 16:45:12 -04001694 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1695 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
1696 custom_border_color_sampler_count--;
1697 }
locke-lunargd556cc32019-09-17 01:21:23 -06001698 }
Jeremy Gebben082a9832021-10-28 13:40:11 -06001699 Destroy<SAMPLER_STATE>(sampler);
locke-lunargd556cc32019-09-17 01:21:23 -06001700}
1701
1702void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
1703 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001704 Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
locke-lunargd556cc32019-09-17 01:21:23 -06001705}
1706
1707void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1708 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001709 Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001710}
1711
locke-lunargd556cc32019-09-17 01:21:23 -06001712void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
1713 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001714 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1715 if (pool) {
1716 pool->Free(commandBufferCount, pCommandBuffers);
1717 }
locke-lunargd556cc32019-09-17 01:21:23 -06001718}
1719
1720void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
1721 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
1722 VkResult result) {
1723 if (VK_SUCCESS != result) return;
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001724 auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001725 Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
locke-lunargd556cc32019-09-17 01:21:23 -06001726}
1727
1728void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
1729 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
1730 VkResult result) {
1731 if (VK_SUCCESS != result) return;
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001732
1733 uint32_t index_count = 0, n_perf_pass = 0;
1734 bool has_cb = false, has_rb = false;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001735 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07001736 const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001737 index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001738
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06001739 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001740 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
1741 const auto &counter = counters.counters[perf->pCounterIndices[i]];
1742 switch (counter.scope) {
1743 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001744 has_cb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001745 break;
1746 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
Jeremy Gebbene9206ee2021-06-02 12:44:41 -06001747 has_rb = true;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001748 break;
1749 default:
1750 break;
1751 }
1752 }
1753
Jeremy Gebben383b9a32021-09-08 16:31:33 -06001754 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001755 }
1756
Jeremy Gebben082a9832021-10-28 13:40:11 -06001757 Add(std::make_shared<QUERY_POOL_STATE>(*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb));
locke-lunargd556cc32019-09-17 01:21:23 -06001758
1759 QueryObject query_obj{*pQueryPool, 0u};
1760 for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) {
1761 query_obj.query = i;
1762 queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN;
1763 }
1764}
1765
1766void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
1767 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001768 Destroy<COMMAND_POOL_STATE>(commandPool);
locke-lunargd556cc32019-09-17 01:21:23 -06001769}
1770
1771void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
1772 VkCommandPoolResetFlags flags, VkResult result) {
1773 if (VK_SUCCESS != result) return;
1774 // Reset all of the CBs allocated from this pool
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06001775 auto pool = Get<COMMAND_POOL_STATE>(commandPool);
1776 if (pool) {
1777 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001778 }
1779}
1780
1781void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
1782 VkResult result) {
1783 for (uint32_t i = 0; i < fenceCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001784 auto fence_state = GetFenceState(pFences[i]);
1785 if (fence_state) {
1786 if (fence_state->scope == kSyncScopeInternal) {
1787 fence_state->state = FENCE_UNSIGNALED;
1788 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
1789 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06001790 }
1791 }
1792 }
1793}
1794
locke-lunargd556cc32019-09-17 01:21:23 -06001795void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
1796 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001797 Destroy<FRAMEBUFFER_STATE>(framebuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06001798}
1799
1800void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
1801 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001802 Destroy<RENDER_PASS_STATE>(renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06001803}
1804
1805void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
1806 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
1807 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001808 Add(std::make_shared<FENCE_STATE>(*pFence, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001809}
1810
1811bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1812 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1813 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001814 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001815 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
1816 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1817 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1818 cgpl_state->pipe_state.reserve(count);
1819 for (uint32_t i = 0; i < count; i++) {
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001820 if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
1821 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
1822 GetRenderPassShared(pCreateInfos[i].renderPass),
1823 GetPipelineLayoutShared(pCreateInfos[i].layout)));
amhagana448ea52021-11-02 14:09:14 -04001824 } else if (enabled_features.dynamic_rendering_features.dynamicRendering) {
1825 auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfoKHR>(pCreateInfos[i].pNext);
1826 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i],
1827 std::make_shared<RENDER_PASS_STATE>(dynamic_rendering),
1828 GetPipelineLayoutShared(pCreateInfos[i].layout)));
Jeremy Gebbence23dac2021-11-10 10:19:42 -07001829 }
locke-lunargd556cc32019-09-17 01:21:23 -06001830 }
1831 return false;
1832}
1833
1834void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1835 const VkGraphicsPipelineCreateInfo *pCreateInfos,
1836 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1837 VkResult result, void *cgpl_state_data) {
1838 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
1839 // This API may create pipelines regardless of the return value
1840 for (uint32_t i = 0; i < count; i++) {
1841 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001842 (cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001843 Add(std::move((cgpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001844 }
1845 }
1846 cgpl_state->pipe_state.clear();
1847}
1848
1849bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1850 const VkComputePipelineCreateInfo *pCreateInfos,
1851 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001852 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001853 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1854 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
1855 ccpl_state->pipe_state.reserve(count);
1856 for (uint32_t i = 0; i < count; i++) {
1857 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001858 ccpl_state->pipe_state.push_back(
1859 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001860 }
1861 return false;
1862}
1863
1864void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
1865 const VkComputePipelineCreateInfo *pCreateInfos,
1866 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
1867 VkResult result, void *ccpl_state_data) {
1868 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
1869
1870 // This API may create pipelines regardless of the return value
1871 for (uint32_t i = 0; i < count; i++) {
1872 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001873 (ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001874 Add(std::move((ccpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001875 }
1876 }
1877 ccpl_state->pipe_state.clear();
1878}
1879
1880bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
1881 uint32_t count,
1882 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1883 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001884 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001885 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1886 crtpl_state->pipe_state.reserve(count);
1887 for (uint32_t i = 0; i < count; i++) {
1888 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001889 crtpl_state->pipe_state.push_back(
1890 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
locke-lunargd556cc32019-09-17 01:21:23 -06001891 }
1892 return false;
1893}
1894
1895void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
1896 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
1897 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
1898 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
1899 // This API may create pipelines regardless of the return value
1900 for (uint32_t i = 0; i < count; i++) {
1901 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001902 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001903 Add(std::move((crtpl_state->pipe_state)[i]));
locke-lunargd556cc32019-09-17 01:21:23 -06001904 }
1905 }
1906 crtpl_state->pipe_state.clear();
1907}
1908
sourav parmarcd5fb182020-07-17 12:58:44 -07001909bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1910 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001911 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1912 const VkAllocationCallbacks *pAllocator,
1913 VkPipeline *pPipelines, void *crtpl_state_data) const {
1914 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
1915 crtpl_state->pipe_state.reserve(count);
1916 for (uint32_t i = 0; i < count; i++) {
1917 // Create and initialize internal tracking data structure
Jeremy Gebben11af9792021-08-20 10:20:09 -06001918 crtpl_state->pipe_state.push_back(
1919 std::make_shared<PIPELINE_STATE>(this, &pCreateInfos[i], GetPipelineLayoutShared(pCreateInfos[i].layout)));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001920 }
1921 return false;
1922}
1923
sourav parmarcd5fb182020-07-17 12:58:44 -07001924void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
1925 VkPipelineCache pipelineCache, uint32_t count,
1926 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
1927 const VkAllocationCallbacks *pAllocator,
1928 VkPipeline *pPipelines, VkResult result,
1929 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001930 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
1931 // This API may create pipelines regardless of the return value
1932 for (uint32_t i = 0; i < count; i++) {
1933 if (pPipelines[i] != VK_NULL_HANDLE) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06001934 (crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Jeremy Gebben082a9832021-10-28 13:40:11 -06001935 Add(std::move((crtpl_state->pipe_state)[i]));
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001936 }
1937 }
1938 crtpl_state->pipe_state.clear();
1939}
1940
locke-lunargd556cc32019-09-17 01:21:23 -06001941void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
1942 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
1943 VkResult result) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06001944 Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001945 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
1946 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06001947 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001948 }
locke-lunargd556cc32019-09-17 01:21:23 -06001949}
1950
1951void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
1952 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1953 const VkAllocationCallbacks *pAllocator,
1954 VkDescriptorSetLayout *pSetLayout, VkResult result) {
1955 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001956 Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
locke-lunargd556cc32019-09-17 01:21:23 -06001957}
1958
locke-lunargd556cc32019-09-17 01:21:23 -06001959void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
1960 const VkAllocationCallbacks *pAllocator,
1961 VkPipelineLayout *pPipelineLayout, VkResult result) {
1962 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001963 Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001964}
1965
1966void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
1967 const VkAllocationCallbacks *pAllocator,
1968 VkDescriptorPool *pDescriptorPool, VkResult result) {
1969 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06001970 Add(std::make_shared<DESCRIPTOR_POOL_STATE>(this, *pDescriptorPool, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06001971}
1972
1973void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
1974 VkDescriptorPoolResetFlags flags, VkResult result) {
1975 if (VK_SUCCESS != result) return;
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06001976 auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
1977 if (pool) {
1978 pool->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001979 }
locke-lunargd556cc32019-09-17 01:21:23 -06001980}
1981
1982bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
1983 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05001984 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06001985 // Always update common data
1986 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
1987 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
1988 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
1989
1990 return false;
1991}
1992
1993// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
1994void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
1995 VkDescriptorSet *pDescriptorSets, VkResult result,
1996 void *ads_state_data) {
1997 if (VK_SUCCESS != result) return;
1998 // All the updates are contained in a single cvdescriptorset function
1999 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
2000 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002001 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
2002 if (pool_state) {
2003 pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
2004 }
locke-lunargd556cc32019-09-17 01:21:23 -06002005}
2006
2007void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
2008 const VkDescriptorSet *pDescriptorSets) {
Jeremy Gebben1fbebb82021-10-27 10:27:27 -06002009 auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
2010 if (pool_state) {
2011 pool_state->Free(count, pDescriptorSets);
locke-lunargd556cc32019-09-17 01:21:23 -06002012 }
2013}
2014
2015void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
2016 const VkWriteDescriptorSet *pDescriptorWrites,
2017 uint32_t descriptorCopyCount,
2018 const VkCopyDescriptorSet *pDescriptorCopies) {
2019 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
2020 pDescriptorCopies);
2021}
2022
2023void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002024 VkCommandBuffer *pCommandBuffers, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002025 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002026 auto pool = GetCommandPoolShared(pCreateInfo->commandPool);
2027 if (pool) {
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06002028 pool->Allocate(pCreateInfo, pCommandBuffers);
locke-lunargfc78e932020-11-19 17:06:24 -07002029 }
2030}
2031
locke-lunargd556cc32019-09-17 01:21:23 -06002032void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
2033 const VkCommandBufferBeginInfo *pBeginInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002034 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002035 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07002036
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002037 cb_state->Begin(pBeginInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002038}
2039
2040void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002041 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002042 if (!cb_state) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002043
2044 cb_state->End(result);
locke-lunargd556cc32019-09-17 01:21:23 -06002045}
2046
2047void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
2048 VkResult result) {
2049 if (VK_SUCCESS == result) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002050 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002051 cb_state->Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06002052 }
2053}
2054
2055CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
2056 // initially assume everything is static state
2057 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
2058
2059 if (ds) {
2060 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06002061 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002062 }
2063 }
locke-lunargd556cc32019-09-17 01:21:23 -06002064 return flags;
2065}
2066
2067// Validation cache:
2068// CV is the bottommost implementor of this extension. Don't pass calls down.
locke-lunargd556cc32019-09-17 01:21:23 -06002069
2070void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
2071 VkPipeline pipeline) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002072 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002073 assert(cb_state);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002074 cb_state->RecordCmd(CMD_BINDPIPELINE);
locke-lunargd556cc32019-09-17 01:21:23 -06002075
2076 auto pipe_state = GetPipelineState(pipeline);
2077 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002078 const auto &create_info = pipe_state->create_info.graphics;
2079 bool rasterization_enabled = VK_FALSE == create_info.pRasterizationState->rasterizerDiscardEnable;
2080 const auto *viewport_state = create_info.pViewportState;
2081 const auto *dynamic_state = create_info.pDynamicState;
locke-lunargd556cc32019-09-17 01:21:23 -06002082 cb_state->status &= ~cb_state->static_status;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002083 cb_state->static_status = MakeStaticStateMask(dynamic_state->ptr());
locke-lunargd556cc32019-09-17 01:21:23 -06002084 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06002085 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002086
2087 // Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002088 // If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
2089 // this time), then these are set to 0 to disable this checking.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002090 auto has_dynamic_viewport_count = cb_state->dynamic_status & CBSTATUS_VIEWPORT_WITH_COUNT_SET;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002091 auto has_dynamic_scissor_count = cb_state->dynamic_status & CBSTATUS_SCISSOR_WITH_COUNT_SET;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002092 cb_state->pipelineStaticViewportCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002093 has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002094 cb_state->pipelineStaticScissorCount =
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002095 has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002096
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002097 // Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002098 // akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
2099 // the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
2100 // I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
David Zhao Akeley44139b12021-04-26 16:16:13 -07002101 if (!has_dynamic_viewport_count) {
2102 cb_state->trashedViewportCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002103 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_VIEWPORT_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002104 cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
2105 // should become = ~uint32_t(0) if the other interpretation is correct.
2106 }
2107 }
2108 if (!has_dynamic_scissor_count) {
2109 cb_state->trashedScissorCount = true;
David Zhao Akeley5f40eb72021-05-04 21:56:14 -07002110 if (rasterization_enabled && (cb_state->static_status & CBSTATUS_SCISSOR_SET)) {
David Zhao Akeley44139b12021-04-26 16:16:13 -07002111 cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
2112 // should become = ~uint32_t(0) if the other interpretation is correct.
2113 }
2114 }
locke-lunargd556cc32019-09-17 01:21:23 -06002115 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002116 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2117 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002118 if (!disabled[command_buffer_state]) {
2119 cb_state->AddChild(pipe_state);
2120 }
locke-lunargb8be8222020-10-20 00:34:37 -06002121 for (auto &slot : pipe_state->active_slots) {
2122 for (auto &req : slot.second) {
2123 for (auto &sampler : req.second.samplers_used_by_image) {
2124 for (auto &des : sampler) {
2125 des.second = nullptr;
2126 }
2127 }
2128 }
2129 }
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002130 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
locke-lunargd556cc32019-09-17 01:21:23 -06002131}
2132
2133void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2134 uint32_t viewportCount, const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002135 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002136 cb_state->RecordStateCmd(CMD_SETVIEWPORT, CBSTATUS_VIEWPORT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002137 uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
2138 cb_state->viewportMask |= bits;
2139 cb_state->trashedViewportMask &= ~bits;
David Zhao Akeley44139b12021-04-26 16:16:13 -07002140
2141 cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
2142 for (size_t i = 0; i < viewportCount; ++i) {
2143 cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
2144 }
locke-lunargd556cc32019-09-17 01:21:23 -06002145}
2146
2147void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
2148 uint32_t exclusiveScissorCount,
2149 const VkRect2D *pExclusiveScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002150 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002151 cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CBSTATUS_EXCLUSIVE_SCISSOR_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002152 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
2153 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
locke-lunargd556cc32019-09-17 01:21:23 -06002154}
2155
2156void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
2157 VkImageLayout imageLayout) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002158 if (disabled[command_buffer_state]) return;
2159
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002160 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002161 cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002162
2163 if (imageView != VK_NULL_HANDLE) {
2164 auto view_state = GetImageViewState(imageView);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002165 cb_state->AddChild(view_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002166 }
2167}
2168
2169void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2170 uint32_t viewportCount,
2171 const VkShadingRatePaletteNV *pShadingRatePalettes) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002172 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002173 cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CBSTATUS_SHADING_RATE_PALETTE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002174 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
2175 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
locke-lunargd556cc32019-09-17 01:21:23 -06002176}
2177
2178void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
2179 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
2180 const VkAllocationCallbacks *pAllocator,
2181 VkAccelerationStructureNV *pAccelerationStructure,
2182 VkResult result) {
2183 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002184 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002185
2186 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002187 auto as_memory_requirements_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002188 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002189 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002190 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
2191
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002192 auto scratch_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002193 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002194 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002195 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
2196 &as_state->build_scratch_memory_requirements);
2197
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002198 auto update_memory_req_info = LvlInitStruct<VkAccelerationStructureMemoryRequirementsInfoNV>();
locke-lunargd556cc32019-09-17 01:21:23 -06002199 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002200 update_memory_req_info.accelerationStructure = as_state->acceleration_structure();
locke-lunargd556cc32019-09-17 01:21:23 -06002201 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
2202 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002203 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002204 Add(std::move(as_state));
locke-lunargd556cc32019-09-17 01:21:23 -06002205}
2206
Jeff Bolz95176d02020-04-01 00:36:16 -05002207void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
2208 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
2209 const VkAllocationCallbacks *pAllocator,
2210 VkAccelerationStructureKHR *pAccelerationStructure,
2211 VkResult result) {
2212 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07002213 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06002214 as_state->allocator = pAllocator;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002215 Add(std::move(as_state));
Jeff Bolz95176d02020-04-01 00:36:16 -05002216}
2217
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002218void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
2219 VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
2220 const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2221 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
2222 for (uint32_t i = 0; i < infoCount; ++i) {
2223 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
2224 if (dst_as_state != nullptr) {
2225 dst_as_state->Build(&pInfos[i]);
2226 }
2227 }
2228}
2229
sourav parmarcd5fb182020-07-17 12:58:44 -07002230void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
2231 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2232 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002233 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002234 if (cb_state == nullptr) {
2235 return;
2236 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002237 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002238 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002239 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002240 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002241 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002242 if (!disabled[command_buffer_state]) {
2243 cb_state->AddChild(dst_as_state);
2244 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002245 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002246 if (!disabled[command_buffer_state]) {
2247 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2248 if (src_as_state != nullptr) {
2249 cb_state->AddChild(src_as_state);
2250 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002251 }
2252 }
2253 cb_state->hasBuildAccelerationStructureCmd = true;
2254}
2255
2256void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
2257 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
2258 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
2259 const uint32_t *const *ppMaxPrimitiveCounts) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002260 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmarcd5fb182020-07-17 12:58:44 -07002261 if (cb_state == nullptr) {
2262 return;
2263 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002264 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07002265 for (uint32_t i = 0; i < infoCount; ++i) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002266 auto *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
sourav parmarcd5fb182020-07-17 12:58:44 -07002267 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002268 dst_as_state->Build(&pInfos[i]);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002269 if (!disabled[command_buffer_state]) {
2270 cb_state->AddChild(dst_as_state);
2271 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002272 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002273 if (!disabled[command_buffer_state]) {
2274 auto *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
2275 if (src_as_state != nullptr) {
2276 cb_state->AddChild(src_as_state);
2277 }
sourav parmarcd5fb182020-07-17 12:58:44 -07002278 }
2279 }
2280 cb_state->hasBuildAccelerationStructureCmd = true;
2281}
locke-lunargd556cc32019-09-17 01:21:23 -06002282void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002283 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002284 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002285 if (as_state != nullptr) {
2286 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
2287 as_state->memory_requirements = *pMemoryRequirements;
2288 as_state->memory_requirements_checked = true;
2289 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
2290 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
2291 as_state->build_scratch_memory_requirements_checked = true;
2292 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
2293 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
2294 as_state->update_scratch_memory_requirements_checked = true;
2295 }
2296 }
2297}
2298
sourav parmarcd5fb182020-07-17 12:58:44 -07002299void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
2300 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002301 if (VK_SUCCESS != result) return;
2302 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002303 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002304
sourav parmarcd5fb182020-07-17 12:58:44 -07002305 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002306 if (as_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002307 // Track objects tied to memory
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002308 auto mem_state = GetDevMemShared(info.memory);
2309 if (mem_state) {
2310 as_state->SetMemBinding(mem_state, info.memoryOffset);
2311 }
locke-lunargd556cc32019-09-17 01:21:23 -06002312
2313 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05002314 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07002315 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06002316 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
2317 }
2318 }
2319 }
2320}
2321
2322void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
2323 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
2324 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002325 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002326 if (cb_state == nullptr) {
2327 return;
2328 }
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002329 cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
locke-lunargd556cc32019-09-17 01:21:23 -06002330
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002331 auto *dst_as_state = GetAccelerationStructureStateNV(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06002332 if (dst_as_state != nullptr) {
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02002333 dst_as_state->Build(pInfo);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002334 if (!disabled[command_buffer_state]) {
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002335 cb_state->AddChild(dst_as_state);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002336 }
locke-lunargd556cc32019-09-17 01:21:23 -06002337 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002338 if (!disabled[command_buffer_state]) {
2339 auto *src_as_state = GetAccelerationStructureStateNV(src);
2340 if (src_as_state != nullptr) {
2341 cb_state->AddChild(src_as_state);
2342 }
locke-lunargd556cc32019-09-17 01:21:23 -06002343 }
2344 cb_state->hasBuildAccelerationStructureCmd = true;
2345}
2346
2347void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
2348 VkAccelerationStructureNV dst,
2349 VkAccelerationStructureNV src,
2350 VkCopyAccelerationStructureModeNV mode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002351 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002352 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002353 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
2354 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002355 if (!disabled[command_buffer_state]) {
2356 cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
2357 }
locke-lunargd556cc32019-09-17 01:21:23 -06002358 if (dst_as_state != nullptr && src_as_state != nullptr) {
2359 dst_as_state->built = true;
2360 dst_as_state->build_info = src_as_state->build_info;
locke-lunargd556cc32019-09-17 01:21:23 -06002361 }
2362 }
2363}
2364
Jeff Bolz95176d02020-04-01 00:36:16 -05002365void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
2366 VkAccelerationStructureKHR accelerationStructure,
2367 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002368 Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06002369}
2370
Jeff Bolz95176d02020-04-01 00:36:16 -05002371void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
2372 VkAccelerationStructureNV accelerationStructure,
2373 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06002374 Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
Jeff Bolz95176d02020-04-01 00:36:16 -05002375}
2376
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002377void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
2378 uint32_t viewportCount,
2379 const VkViewportWScalingNV *pViewportWScalings) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002380 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002381 cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CBSTATUS_VIEWPORT_W_SCALING_SET);
Chris Mayer9ded5eb2019-09-19 16:33:26 +02002382}
2383
locke-lunargd556cc32019-09-17 01:21:23 -06002384void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002385 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002386 cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CBSTATUS_LINE_WIDTH_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002387}
2388
2389void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
2390 uint16_t lineStipplePattern) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002391 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002392 cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CBSTATUS_LINE_STIPPLE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002393}
2394
2395void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
2396 float depthBiasClamp, float depthBiasSlopeFactor) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002397 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002398 cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CBSTATUS_DEPTH_BIAS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002399}
2400
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002401void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
2402 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002403 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002404 cb_state->RecordStateCmd(CMD_SETSCISSOR, CBSTATUS_SCISSOR_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07002405 uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
2406 cb_state->scissorMask |= bits;
2407 cb_state->trashedScissorMask &= ~bits;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002408}
2409
locke-lunargd556cc32019-09-17 01:21:23 -06002410void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002411 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002412 cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CBSTATUS_BLEND_CONSTANTS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002413}
2414
2415void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
2416 float maxDepthBounds) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002417 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002418 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CBSTATUS_DEPTH_BOUNDS_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002419}
2420
2421void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2422 uint32_t compareMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002423 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002424 cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CBSTATUS_STENCIL_READ_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002425}
2426
2427void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2428 uint32_t writeMask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002429 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002430 cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CBSTATUS_STENCIL_WRITE_MASK_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002431}
2432
2433void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
2434 uint32_t reference) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002435 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002436 cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CBSTATUS_STENCIL_REFERENCE_SET);
locke-lunargd556cc32019-09-17 01:21:23 -06002437}
2438
locke-lunargd556cc32019-09-17 01:21:23 -06002439// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
2440void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
2441 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2442 uint32_t firstSet, uint32_t setCount,
2443 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
2444 const uint32_t *pDynamicOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002445 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002446 cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
locke-lunargd556cc32019-09-17 01:21:23 -06002447 auto pipeline_layout = GetPipelineLayout(layout);
2448
2449 // Resize binding arrays
2450 uint32_t last_set_index = firstSet + setCount - 1;
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002451 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
2452 if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) {
2453 cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06002454 }
2455
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002456 cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr,
2457 dynamicOffsetCount, pDynamicOffsets);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06002458 cb_state->lastBound[lv_bind_point].pipeline_layout = layout;
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06002459 cb_state->lastBound[lv_bind_point].UpdateSamplerDescriptorsUsedByImage();
Jeremy Gebben5570abe2021-05-16 18:35:13 -06002460}
2461
locke-lunargd556cc32019-09-17 01:21:23 -06002462void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
2463 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
2464 uint32_t set, uint32_t descriptorWriteCount,
2465 const VkWriteDescriptorSet *pDescriptorWrites) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002466 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002467 auto pipeline_layout = GetPipelineLayout(layout);
2468 cb_state->PushDescriptorSetState(pipelineBindPoint, pipeline_layout, set, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06002469}
2470
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002471void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
2472 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
2473 const void *pValues) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002474 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002475 if (cb_state != nullptr) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002476 cb_state->RecordCmd(CMD_PUSHCONSTANTS);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002477 cb_state->ResetPushConstantDataIfIncompatible(GetPipelineLayout(layout));
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002478
2479 auto &push_constant_data = cb_state->push_constant_data;
2480 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
2481 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002482 cb_state->push_constant_pipeline_layout_set = layout;
2483
2484 auto flags = stageFlags;
2485 uint32_t bit_shift = 0;
2486 while (flags) {
2487 if (flags & 1) {
2488 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
2489 const auto it = cb_state->push_constant_data_update.find(flag);
2490
2491 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06002492 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06002493 }
2494 }
2495 flags = flags >> 1;
2496 ++bit_shift;
2497 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06002498 }
2499}
2500
locke-lunargd556cc32019-09-17 01:21:23 -06002501void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
2502 VkIndexType indexType) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002503 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002504
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002505 cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002506 cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer);
2507 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06002508 cb_state->index_buffer_binding.offset = offset;
2509 cb_state->index_buffer_binding.index_type = indexType;
2510 // Add binding for this index buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002511 if (!disabled[command_buffer_state]) {
2512 cb_state->AddChild(cb_state->index_buffer_binding.buffer_state.get());
2513 }
locke-lunargd556cc32019-09-17 01:21:23 -06002514}
2515
2516void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
2517 uint32_t bindingCount, const VkBuffer *pBuffers,
2518 const VkDeviceSize *pOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002519 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002520 cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
locke-lunargd556cc32019-09-17 01:21:23 -06002521
2522 uint32_t end = firstBinding + bindingCount;
2523 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
2524 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
2525 }
2526
2527 for (uint32_t i = 0; i < bindingCount; ++i) {
2528 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07002529 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002530 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06002531 vertex_buffer_binding.size = VK_WHOLE_SIZE;
2532 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06002533 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002534 if (pBuffers[i] && !disabled[command_buffer_state]) {
2535 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Jeff Bolz165818a2020-05-08 11:19:03 -05002536 }
locke-lunargd556cc32019-09-17 01:21:23 -06002537 }
2538}
2539
2540void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
2541 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002542 if (disabled[command_buffer_state]) return;
2543
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002544 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002545 cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, GetBufferState(dstBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002546}
2547
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002548void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2549 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002550 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2551 cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002552}
2553
2554void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2555 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002556 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002557 auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
2558
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002559 cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
2560 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002561}
2562
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002563void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
2564 VkPipelineStageFlags stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002565 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2566 cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002567}
2568
2569void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
2570 VkPipelineStageFlags2KHR stageMask) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002571 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2572 cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002573}
2574
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002575void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
2576 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
2577 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2578 uint32_t bufferMemoryBarrierCount,
2579 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2580 uint32_t imageMemoryBarrierCount,
2581 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002582 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2583 cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
2584 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2585 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002586}
2587
2588void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
2589 const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002590 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2591 cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
Jeremy Gebben79649152021-06-22 14:46:24 -06002592 for (uint32_t i = 0; i < eventCount; i++) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002593 cb_state->RecordBarriers(pDependencyInfos[i]);
Jeremy Gebben79649152021-06-22 14:46:24 -06002594 }
2595}
2596
2597void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
2598 VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
2599 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
2600 uint32_t bufferMemoryBarrierCount,
2601 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
2602 uint32_t imageMemoryBarrierCount,
2603 const VkImageMemoryBarrier *pImageMemoryBarriers) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002604 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2605 cb_state->RecordCmd(CMD_PIPELINEBARRIER);
2606 cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
2607 imageMemoryBarrierCount, pImageMemoryBarriers);
Jeremy Gebben79649152021-06-22 14:46:24 -06002608}
2609
2610void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
2611 const VkDependencyInfoKHR *pDependencyInfo) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002612 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2613 cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
2614 cb_state->RecordBarriers(*pDependencyInfo);
Jeremy Gebben79649152021-06-22 14:46:24 -06002615}
2616
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002617QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
2618 uint32_t perfPass) const {
2619 QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass);
locke-lunargd556cc32019-09-17 01:21:23 -06002620
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002621 auto iter = localQueryToStateMap->find(query);
2622 if (iter != localQueryToStateMap->end()) return iter->second;
Jeff Bolz310775c2019-10-09 00:46:33 -05002623
Jeff Bolz310775c2019-10-09 00:46:33 -05002624 return QUERYSTATE_UNKNOWN;
locke-lunargd556cc32019-09-17 01:21:23 -06002625}
2626
locke-lunargd556cc32019-09-17 01:21:23 -06002627void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
2628 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002629 if (disabled[query_validation]) return;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002630
locke-lunargd556cc32019-09-17 01:21:23 -06002631 QueryObject query = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002632 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002633 cb_state->RecordCmd(CMD_BEGINQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002634 if (!disabled[query_validation]) {
2635 cb_state->BeginQuery(query);
2636 }
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002637 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002638 auto pool_state = GetQueryPoolState(query.pool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002639 cb_state->AddChild(pool_state);
2640 }
locke-lunargd556cc32019-09-17 01:21:23 -06002641}
2642
2643void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002644 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002645 QueryObject query_obj = {queryPool, slot};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002646 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002647 cb_state->RecordCmd(CMD_ENDQUERY);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002648 if (!disabled[query_validation]) {
2649 cb_state->EndQuery(query_obj);
2650 }
2651 if (!disabled[command_buffer_state]) {
2652 auto pool_state = GetQueryPoolState(query_obj.pool);
2653 cb_state->AddChild(pool_state);
2654 }
locke-lunargd556cc32019-09-17 01:21:23 -06002655}
2656
2657void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2658 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002659 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002660 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002661
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002662 cb_state->RecordCmd(CMD_RESETQUERYPOOL);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002663 cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02002664
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002665 if (!disabled[command_buffer_state]) {
2666 auto pool_state = GetQueryPoolState(queryPool);
2667 cb_state->AddChild(pool_state);
2668 }
locke-lunargd556cc32019-09-17 01:21:23 -06002669}
2670
2671void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
2672 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
2673 VkDeviceSize dstOffset, VkDeviceSize stride,
2674 VkQueryResultFlags flags) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002675 if (disabled[query_validation] || disabled[command_buffer_state]) return;
2676
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002677 auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002678 cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
locke-lunargd556cc32019-09-17 01:21:23 -06002679 auto dst_buff_state = GetBufferState(dstBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002680 cb_state->AddChild(dst_buff_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05002681 auto pool_state = GetQueryPoolState(queryPool);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002682 cb_state->AddChild(pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06002683}
2684
2685void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
2686 VkQueryPool queryPool, uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002687 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2688 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
Jeremy Gebben74aa7622020-12-15 11:18:00 -07002689}
2690
2691void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
2692 VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
2693 uint32_t slot) {
Jeremy Gebbencefa7fd2021-08-17 13:44:47 -06002694 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2695 cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
locke-lunargd556cc32019-09-17 01:21:23 -06002696}
2697
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002698void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
2699 VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
2700 VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
2701 if (disabled[query_validation]) return;
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002702 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002703 cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002704 if (!disabled[command_buffer_state]) {
2705 auto pool_state = GetQueryPoolState(queryPool);
2706 cb_state->AddChild(pool_state);
2707 }
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002708 cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
Marijn Suijten6750fdc2020-12-30 22:06:42 +01002709}
2710
locke-lunargd556cc32019-09-17 01:21:23 -06002711void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
2712 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
2713 VkResult result) {
2714 if (VK_SUCCESS != result) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002715
Jeremy Gebben88f58142021-06-01 10:07:52 -06002716 std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002717 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002718 views.resize(pCreateInfo->attachmentCount);
locke-lunarg1ae57d62020-11-18 10:49:19 -07002719
locke-lunargd556cc32019-09-17 01:21:23 -06002720 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002721 views[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06002722 }
2723 }
Jeremy Gebben88f58142021-06-01 10:07:52 -06002724
Jeremy Gebben082a9832021-10-28 13:40:11 -06002725 Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass),
2726 std::move(views)));
locke-lunargd556cc32019-09-17 01:21:23 -06002727}
2728
locke-lunargd556cc32019-09-17 01:21:23 -06002729void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
2730 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2731 VkResult result) {
2732 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06002733 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06002734}
2735
Mike Schuchardt2df08912020-12-15 16:28:09 -08002736void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002737 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2738 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002739 if (VK_SUCCESS != result) return;
2740
Jeremy Gebben082a9832021-10-28 13:40:11 -06002741 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002742}
2743
Mike Schuchardt2df08912020-12-15 16:28:09 -08002744void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07002745 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
2746 VkResult result) {
Jeremy Gebben88f58142021-06-01 10:07:52 -06002747 if (VK_SUCCESS != result) return;
2748
Jeremy Gebben082a9832021-10-28 13:40:11 -06002749 Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
Tony-LunarG977448c2019-12-02 14:52:02 -07002750}
2751
locke-lunargd556cc32019-09-17 01:21:23 -06002752void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
2753 const VkRenderPassBeginInfo *pRenderPassBegin,
2754 VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002755 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2756 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002757}
2758
2759void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
2760 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002761 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002762 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002763 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002764}
2765
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002766void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2767 uint32_t counterBufferCount,
2768 const VkBuffer *pCounterBuffers,
2769 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002770 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002771
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002772 cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002773 cb_state->transform_feedback_active = true;
2774}
2775
2776void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
2777 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
2778 const VkDeviceSize *pCounterBufferOffsets) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002779 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002780
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002781 cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06002782 cb_state->transform_feedback_active = false;
2783}
2784
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002785void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
2786 VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06002787 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002788
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002789 cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002790 cb_state->conditional_rendering_active = true;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002791 cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
2792 cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002793}
2794
2795void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebbenc8b51a92021-08-16 15:19:00 -06002796 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002797
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002798 cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002799 cb_state->conditional_rendering_active = false;
ziga-lunarg39eeaf22021-09-03 19:12:44 +02002800 cb_state->conditional_rendering_inside_render_pass = false;
2801 cb_state->conditional_rendering_subpass = 0;
ziga-lunarg40f5fbc2021-08-14 23:06:41 +02002802}
2803
amhagana448ea52021-11-02 14:09:14 -04002804void ValidationStateTracker::RecordCmdBeginRenderingRenderPassState(VkCommandBuffer commandBuffer,
2805 const VkRenderingInfoKHR *pRenderingInfo) {
2806 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2807 cb_state->activeRenderPass = std::make_shared<RENDER_PASS_STATE>(pRenderingInfo);
2808}
2809
2810void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
2811 auto *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2812 cb_state->activeRenderPass = nullptr;
2813}
2814
2815void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
2816 const VkRenderingInfoKHR *pRenderingInfo) {
2817 RecordCmdBeginRenderingRenderPassState(commandBuffer, pRenderingInfo);
2818 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2819 cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
2820}
2821
2822void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
2823 RecordCmdEndRenderingRenderPassState(commandBuffer);
2824}
2825
Tony-LunarG977448c2019-12-02 14:52:02 -07002826void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
2827 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002828 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002829 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2830 cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
Tony-LunarG977448c2019-12-02 14:52:02 -07002831}
2832
locke-lunargd556cc32019-09-17 01:21:23 -06002833void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002834 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2835 cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002836}
2837
2838void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002839 const VkSubpassBeginInfo *pSubpassBeginInfo,
2840 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002841 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002842 cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002843}
2844
Tony-LunarG977448c2019-12-02 14:52:02 -07002845void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002846 const VkSubpassBeginInfo *pSubpassBeginInfo,
2847 const VkSubpassEndInfo *pSubpassEndInfo) {
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->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
2852void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002853 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2854 cb_state->EndRenderPass(CMD_ENDRENDERPASS);
locke-lunargd556cc32019-09-17 01:21:23 -06002855}
2856
2857void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002858 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002859 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07002860 cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
locke-lunargd556cc32019-09-17 01:21:23 -06002861}
2862
Tony-LunarG977448c2019-12-02 14:52:02 -07002863void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002864 const VkSubpassEndInfo *pSubpassEndInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06002865 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
2866 cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
Tony-LunarG977448c2019-12-02 14:52:02 -07002867}
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002868
locke-lunargd556cc32019-09-17 01:21:23 -06002869void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
2870 const VkCommandBuffer *pCommandBuffers) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06002871 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002872
Jeremy Gebben1ec89332021-08-05 13:51:49 -06002873 cb_state->ExecuteCommands(commandBuffersCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06002874}
2875
2876void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
2877 VkFlags flags, void **ppData, VkResult result) {
2878 if (VK_SUCCESS != result) return;
2879 RecordMappedMemory(mem, offset, size, ppData);
2880}
2881
2882void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
2883 auto mem_info = GetDevMemState(mem);
2884 if (mem_info) {
2885 mem_info->mapped_range = MemRange();
2886 mem_info->p_driver_data = nullptr;
2887 }
2888}
2889
2890void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
Jeremy Gebben8ee02af2021-07-16 10:15:55 -06002891 auto image_state = GetShared<IMAGE_STATE>(bindInfo.image);
locke-lunargd556cc32019-09-17 01:21:23 -06002892 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06002893 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
2894 // See: VUID-vkGetImageSubresourceLayout-image-01895
2895 image_state->fragment_encoder =
2896 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002897 const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002898 if (swapchain_info) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002899 auto swapchain = GetShared<SWAPCHAIN_NODE>(swapchain_info->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06002900 if (swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002901 SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
John Zulaufd13b38e2021-03-05 08:17:38 -07002902
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002903 if (!swapchain_image.fake_base_address) {
2904 auto size = image_state->fragment_encoder->TotalSize();
2905 swapchain_image.fake_base_address = fake_memory.Alloc(size);
Jeremy Gebben6fbf8242021-06-21 09:14:46 -06002906 }
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06002907 // All images bound to this swapchain and index are aliases
2908 image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06002909 }
2910 } else {
2911 // Track bound memory range information
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002912 auto mem_info = GetDevMemShared(bindInfo.memory);
locke-lunargd556cc32019-09-17 01:21:23 -06002913 if (mem_info) {
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06002914 image_state->SetMemBinding(mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06002915 }
locke-lunargd556cc32019-09-17 01:21:23 -06002916 }
locke-lunargd556cc32019-09-17 01:21:23 -06002917 }
2918}
2919
2920void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
2921 VkDeviceSize memoryOffset, VkResult result) {
2922 if (VK_SUCCESS != result) return;
Nathaniel Cesariofc6291e2021-04-06 00:22:15 -06002923 auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002924 bind_info.image = image;
2925 bind_info.memory = mem;
2926 bind_info.memoryOffset = memoryOffset;
2927 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06002928}
2929
2930void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002931 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002932 if (VK_SUCCESS != result) return;
2933 for (uint32_t i = 0; i < bindInfoCount; i++) {
2934 UpdateBindImageMemoryState(pBindInfos[i]);
2935 }
2936}
2937
2938void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002939 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002940 if (VK_SUCCESS != result) return;
2941 for (uint32_t i = 0; i < bindInfoCount; i++) {
2942 UpdateBindImageMemoryState(pBindInfos[i]);
2943 }
2944}
2945
2946void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
2947 auto event_state = GetEventState(event);
2948 if (event_state) {
2949 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
2950 }
locke-lunargd556cc32019-09-17 01:21:23 -06002951}
2952
2953void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
2954 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
2955 VkResult result) {
2956 if (VK_SUCCESS != result) return;
2957 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
2958 pImportSemaphoreFdInfo->flags);
2959}
2960
2961void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002962 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06002963 SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08002964 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06002965 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
2966 semaphore_state->scope = kSyncScopeExternalPermanent;
2967 }
2968}
2969
2970#ifdef VK_USE_PLATFORM_WIN32_KHR
2971void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
2972 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
2973 if (VK_SUCCESS != result) return;
2974 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
2975 pImportSemaphoreWin32HandleInfo->flags);
2976}
2977
2978void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
2979 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
2980 HANDLE *pHandle, VkResult result) {
2981 if (VK_SUCCESS != result) return;
2982 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
2983}
2984
2985void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
2986 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
2987 if (VK_SUCCESS != result) return;
2988 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
2989 pImportFenceWin32HandleInfo->flags);
2990}
2991
2992void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
2993 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
2994 HANDLE *pHandle, VkResult result) {
2995 if (VK_SUCCESS != result) return;
2996 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
2997}
2998#endif
2999
3000void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
3001 VkResult result) {
3002 if (VK_SUCCESS != result) return;
3003 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
3004}
3005
Mike Schuchardt2df08912020-12-15 16:28:09 -08003006void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
3007 VkFenceImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06003008 FENCE_STATE *fence_node = GetFenceState(fence);
3009 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003010 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06003011 fence_node->scope == kSyncScopeInternal) {
3012 fence_node->scope = kSyncScopeExternalTemporary;
3013 } else {
3014 fence_node->scope = kSyncScopeExternalPermanent;
3015 }
3016 }
3017}
3018
3019void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
3020 VkResult result) {
3021 if (VK_SUCCESS != result) return;
3022 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
3023}
3024
Mike Schuchardt2df08912020-12-15 16:28:09 -08003025void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06003026 FENCE_STATE *fence_state = GetFenceState(fence);
3027 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08003028 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06003029 // Export with reference transference becomes external
3030 fence_state->scope = kSyncScopeExternalPermanent;
3031 } else if (fence_state->scope == kSyncScopeInternal) {
3032 // Export with copy transference has a side effect of resetting the fence
3033 fence_state->state = FENCE_UNSIGNALED;
3034 }
3035 }
3036}
3037
3038void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
3039 VkResult result) {
3040 if (VK_SUCCESS != result) return;
3041 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
3042}
3043
3044void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
3045 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
3046 if (VK_SUCCESS != result) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003047 Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo->flags));
locke-lunargd556cc32019-09-17 01:21:23 -06003048}
3049
3050void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003051 VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
locke-lunargd556cc32019-09-17 01:21:23 -06003052 SWAPCHAIN_NODE *old_swapchain_state) {
3053 if (VK_SUCCESS == result) {
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003054 if (surface_state->swapchain) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003055 surface_state->RemoveParent(surface_state->swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003056 }
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003057 auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
3058 surface_state->AddParent(swapchain.get());
3059 surface_state->swapchain = swapchain.get();
3060 swapchain->surface = std::move(surface_state);
Jeremy Gebben082a9832021-10-28 13:40:11 -06003061 Add(std::move(swapchain));
locke-lunargd556cc32019-09-17 01:21:23 -06003062 } else {
3063 surface_state->swapchain = nullptr;
3064 }
3065 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003066 // Retired swapchains remain associated with the surface until they are destroyed.
locke-lunargd556cc32019-09-17 01:21:23 -06003067 if (old_swapchain_state) {
3068 old_swapchain_state->retired = true;
3069 }
3070 return;
3071}
3072
3073void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
3074 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
3075 VkResult result) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003076 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfo->surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003077 auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003078 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003079}
3080
3081void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
3082 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003083 Destroy<SWAPCHAIN_NODE>(swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06003084}
3085
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003086void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
3087 const VkDisplayModeCreateInfoKHR *pCreateInfo,
3088 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
3089 VkResult result) {
3090 if (VK_SUCCESS != result) return;
3091 if (!pMode) return;
Jeremy Gebben082a9832021-10-28 13:40:11 -06003092 Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
sfricke-samsung5c1b7392020-12-13 22:17:15 -08003093}
3094
locke-lunargd556cc32019-09-17 01:21:23 -06003095void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
3096 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
3097 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003098 auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]);
3099 if (semaphore_state) {
Jeremy Gebben57642982021-09-14 14:14:55 -06003100 semaphore_state->signaler.queue = nullptr;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003101 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06003102 }
3103 }
3104
Tony-LunarG6f887e52021-07-27 11:23:14 -06003105 const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06003106 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
3107 // 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
3108 // confused itself just as much.
3109 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
3110 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
3111 // Mark the image as having been released to the WSI
3112 auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003113 if (swapchain_data) {
3114 swapchain_data->PresentImage(pPresentInfo->pImageIndices[i]);
Tony-LunarG6f887e52021-07-27 11:23:14 -06003115 if (present_id_info) {
3116 if (i < present_id_info->swapchainCount && present_id_info->pPresentIds[i] > swapchain_data->max_present_id) {
3117 swapchain_data->max_present_id = present_id_info->pPresentIds[i];
3118 }
3119 }
locke-lunargd556cc32019-09-17 01:21:23 -06003120 }
3121 }
3122 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
3123 // its semaphore waits) /never/ participate in any completion proof.
3124}
3125
3126void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
3127 const VkSwapchainCreateInfoKHR *pCreateInfos,
3128 const VkAllocationCallbacks *pAllocator,
3129 VkSwapchainKHR *pSwapchains, VkResult result) {
3130 if (pCreateInfos) {
3131 for (uint32_t i = 0; i < swapchainCount; i++) {
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003132 auto surface_state = GetShared<SURFACE_STATE>(pCreateInfos[i].surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003133 auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain);
Jeremy Gebben5a542f52021-07-21 15:25:52 -06003134 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state), old_swapchain_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003135 }
3136 }
3137}
3138
3139void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3140 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003141 auto fence_state = GetFenceState(fence);
3142 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003143 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
3144 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003145 fence_state->state = FENCE_INFLIGHT;
Jeremy Gebben57642982021-09-14 14:14:55 -06003146 fence_state->signaler.queue = nullptr; // ANI isn't on a queue, so this can't participate in a completion proof.
locke-lunargd556cc32019-09-17 01:21:23 -06003147 }
3148
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003149 auto semaphore_state = GetSemaphoreState(semaphore);
3150 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06003151 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
3152 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003153 semaphore_state->signaled = true;
Jeremy Gebben57642982021-09-14 14:14:55 -06003154 semaphore_state->signaler.queue = nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003155 }
3156
3157 // Mark the image as acquired.
3158 auto swapchain_data = GetSwapchainState(swapchain);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003159 if (swapchain_data) {
3160 swapchain_data->AcquireImage(*pImageIndex);
locke-lunargd556cc32019-09-17 01:21:23 -06003161 }
3162}
3163
3164void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
3165 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
3166 VkResult result) {
3167 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3168 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
3169}
3170
3171void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
3172 uint32_t *pImageIndex, VkResult result) {
3173 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
3174 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
3175 pAcquireInfo->fence, pImageIndex);
3176}
3177
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003178std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
3179 return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
3180}
3181
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003182void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
3183 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
3184 VkResult result) {
3185 if (result != VK_SUCCESS) {
3186 return;
3187 }
Jeremy Gebben404f6ac2021-10-28 12:33:28 -06003188 instance_state = this;
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003189 uint32_t count = 0;
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003190 // this can fail if the allocator fails
3191 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
3192 if (result != VK_SUCCESS) {
3193 return;
3194 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003195 std::vector<VkPhysicalDevice> physdev_handles(count);
Jeremy Gebbenc4916802021-10-22 16:15:16 -06003196 result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
3197 if (result != VK_SUCCESS) {
3198 return;
3199 }
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003200
Jeremy Gebbend177d922021-10-28 13:42:10 -06003201 physical_device_map_.reserve(count);
Jeremy Gebbenee3a3a22021-09-30 12:27:11 -06003202 for (auto physdev : physdev_handles) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003203 Add(CreatePhysicalDeviceState(physdev));
locke-lunargd556cc32019-09-17 01:21:23 -06003204 }
3205}
3206
3207// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003208static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
locke-lunargd556cc32019-09-17 01:21:23 -06003209 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
locke-lunargd556cc32019-09-17 01:21:23 -06003210}
3211
3212void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
3213 uint32_t *pQueueFamilyPropertyCount,
3214 VkQueueFamilyProperties *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003215 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3216 assert(pd_state);
3217 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003218}
3219
3220void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003221 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003222 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3223 assert(pd_state);
3224 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003225}
3226
3227void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003228 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003229 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3230 assert(pd_state);
3231 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state, *pQueueFamilyPropertyCount);
locke-lunargd556cc32019-09-17 01:21:23 -06003232}
3233void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
3234 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003235 Destroy<SURFACE_STATE>(surface);
locke-lunargd556cc32019-09-17 01:21:23 -06003236}
3237
Jeremy Gebben082a9832021-10-28 13:40:11 -06003238void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
locke-lunargd556cc32019-09-17 01:21:23 -06003239
3240void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
3241 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
3242 const VkAllocationCallbacks *pAllocator,
3243 VkSurfaceKHR *pSurface, VkResult result) {
3244 if (VK_SUCCESS != result) return;
3245 RecordVulkanSurface(pSurface);
3246}
3247
3248#ifdef VK_USE_PLATFORM_ANDROID_KHR
3249void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
3250 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
3251 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3252 VkResult result) {
3253 if (VK_SUCCESS != result) return;
3254 RecordVulkanSurface(pSurface);
3255}
3256#endif // VK_USE_PLATFORM_ANDROID_KHR
3257
3258#ifdef VK_USE_PLATFORM_IOS_MVK
3259void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
3260 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3261 VkResult result) {
3262 if (VK_SUCCESS != result) return;
3263 RecordVulkanSurface(pSurface);
3264}
3265#endif // VK_USE_PLATFORM_IOS_MVK
3266
3267#ifdef VK_USE_PLATFORM_MACOS_MVK
3268void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
3269 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
3270 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3271 VkResult result) {
3272 if (VK_SUCCESS != result) return;
3273 RecordVulkanSurface(pSurface);
3274}
3275#endif // VK_USE_PLATFORM_MACOS_MVK
3276
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07003277#ifdef VK_USE_PLATFORM_METAL_EXT
3278void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
3279 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
3280 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3281 VkResult result) {
3282 if (VK_SUCCESS != result) return;
3283 RecordVulkanSurface(pSurface);
3284}
3285#endif // VK_USE_PLATFORM_METAL_EXT
3286
locke-lunargd556cc32019-09-17 01:21:23 -06003287#ifdef VK_USE_PLATFORM_WAYLAND_KHR
3288void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
3289 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
3290 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3291 VkResult result) {
3292 if (VK_SUCCESS != result) return;
3293 RecordVulkanSurface(pSurface);
3294}
3295#endif // VK_USE_PLATFORM_WAYLAND_KHR
3296
3297#ifdef VK_USE_PLATFORM_WIN32_KHR
3298void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
3299 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
3300 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3301 VkResult result) {
3302 if (VK_SUCCESS != result) return;
3303 RecordVulkanSurface(pSurface);
3304}
3305#endif // VK_USE_PLATFORM_WIN32_KHR
3306
3307#ifdef VK_USE_PLATFORM_XCB_KHR
3308void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
3309 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3310 VkResult result) {
3311 if (VK_SUCCESS != result) return;
3312 RecordVulkanSurface(pSurface);
3313}
3314#endif // VK_USE_PLATFORM_XCB_KHR
3315
3316#ifdef VK_USE_PLATFORM_XLIB_KHR
3317void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
3318 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3319 VkResult result) {
3320 if (VK_SUCCESS != result) return;
3321 RecordVulkanSurface(pSurface);
3322}
3323#endif // VK_USE_PLATFORM_XLIB_KHR
3324
Niklas Haas8b84af12020-04-19 22:20:11 +02003325void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
3326 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
3327 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
3328 VkResult result) {
3329 if (VK_SUCCESS != result) return;
3330 RecordVulkanSurface(pSurface);
3331}
3332
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003333void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
3334 VkSurfaceKHR surface,
3335 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
3336 VkResult result) {
3337 if (VK_SUCCESS != result) return;
3338 auto surface_state = Get<SURFACE_STATE>(surface);
3339 surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
3340}
3341
3342void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
3343 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3344 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
3345 if (VK_SUCCESS != result) return;
3346 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3347 surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
3348}
3349
3350void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
3351 VkSurfaceKHR surface,
3352 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
3353 VkResult result) {
3354 auto surface_state = Get<SURFACE_STATE>(surface);
3355 VkSurfaceCapabilitiesKHR caps{
3356 pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
3357 pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
3358 pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
3359 pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
3360 pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
3361 };
3362 surface_state->SetCapabilities(physicalDevice, caps);
3363}
3364
locke-lunargd556cc32019-09-17 01:21:23 -06003365void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
3366 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
3367 VkBool32 *pSupported, VkResult result) {
3368 if (VK_SUCCESS != result) return;
Jeremy Gebben87b2e6b2021-10-20 11:21:40 -06003369 auto surface_state = Get<SURFACE_STATE>(surface);
3370 surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
3371}
3372
3373void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
3374 VkSurfaceKHR surface,
3375 uint32_t *pPresentModeCount,
3376 VkPresentModeKHR *pPresentModes,
3377 VkResult result) {
3378 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3379
3380 if (pPresentModes) {
3381 auto surface_state = Get<SURFACE_STATE>(surface);
3382 surface_state->SetPresentModes(physicalDevice,
3383 std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount));
3384 }
3385}
3386
3387void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
3388 uint32_t *pSurfaceFormatCount,
3389 VkSurfaceFormatKHR *pSurfaceFormats,
3390 VkResult result) {
3391 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3392
3393 if (pSurfaceFormats) {
3394 auto surface_state = Get<SURFACE_STATE>(surface);
3395 surface_state->SetFormats(physicalDevice,
3396 std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
3397 }
3398}
3399
3400void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
3401 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
3402 uint32_t *pSurfaceFormatCount,
3403 VkSurfaceFormat2KHR *pSurfaceFormats,
3404 VkResult result) {
3405 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3406
3407 if (pSurfaceFormats) {
3408 std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
3409 auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
3410 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
3411 fmts[i] = pSurfaceFormats[i].surfaceFormat;
3412 }
3413 surface_state->SetFormats(physicalDevice, std::move(fmts));
3414 }
locke-lunargd556cc32019-09-17 01:21:23 -06003415}
3416
locke-lunargd556cc32019-09-17 01:21:23 -06003417void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3418 const VkDebugUtilsLabelEXT *pLabelInfo) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003419 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3420 cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003421 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3422}
3423
3424void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003425 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3426 cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
locke-lunargd556cc32019-09-17 01:21:23 -06003427 EndCmdDebugUtilsLabel(report_data, commandBuffer);
3428}
3429
3430void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
3431 const VkDebugUtilsLabelEXT *pLabelInfo) {
3432 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
3433
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003434 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003435 cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
3436 // Squirrel away an easily accessible copy.
locke-lunargd556cc32019-09-17 01:21:23 -06003437 cb_state->debug_label = LoggingLabel(pLabelInfo);
3438}
3439
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003440void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
3441 uint32_t queueFamilyIndex,
3442 uint32_t *pCounterCount,
3443 VkPerformanceCounterKHR *pCounters) {
3444 if (NULL == pCounters) return;
3445
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003446 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
3447 assert(pd_state);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003448
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003449 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
3450 queue_family_counters->counters.resize(*pCounterCount);
3451 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003452
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003453 pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003454}
3455
3456void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
3457 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
3458 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
3459 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3460 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
3461}
3462
3463void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
3464 VkResult result) {
3465 if (result == VK_SUCCESS) performance_lock_acquired = true;
3466}
3467
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003468void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
3469 performance_lock_acquired = false;
Jeremy Gebbend177d922021-10-28 13:42:10 -06003470 for (auto &cmd_buffer : command_buffer_map_) {
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003471 cmd_buffer.second->performance_lock_released = true;
3472 }
3473}
3474
locke-lunargd556cc32019-09-17 01:21:23 -06003475void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003476 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003477 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003478 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003479}
3480
3481void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003482 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003483 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003484 Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003485}
3486
Mike Schuchardt2df08912020-12-15 16:28:09 -08003487void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3488 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003489 Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
locke-lunargd556cc32019-09-17 01:21:23 -06003490}
3491
Mike Schuchardt2df08912020-12-15 16:28:09 -08003492void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
3493 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
3494 const VkAllocationCallbacks *pAllocator,
3495 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
3496 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003497 if (VK_SUCCESS != result) return;
3498 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3499}
3500
3501void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003502 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
3503 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003504 if (VK_SUCCESS != result) return;
3505 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
3506}
3507
3508void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003509 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003510 const void *pData) {
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003511 auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
3512 assert(template_state);
3513 if (template_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06003514 // TODO: Record template push descriptor updates
3515 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
3516 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData);
3517 }
3518 }
3519}
3520
3521void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
3522 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3523 const void *pData) {
3524 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3525}
3526
3527void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08003528 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06003529 const void *pData) {
3530 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
3531}
3532
Mike Schuchardt2df08912020-12-15 16:28:09 -08003533void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
3534 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
3535 VkPipelineLayout layout, uint32_t set,
3536 const void *pData) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003537 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003538
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003539 cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003540 const auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
locke-lunargd556cc32019-09-17 01:21:23 -06003541 if (template_state) {
3542 auto layout_data = GetPipelineLayout(layout);
Jeremy Gebbenadb3eb02021-06-15 12:55:19 -06003543 auto dsl = layout_data ? layout_data->GetDsl(set) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06003544 const auto &template_ci = template_state->create_info;
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003545 // Decode the template into a set of write updates
3546 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData,
3547 dsl->GetDescriptorSetLayout());
3548 cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, layout_data, set,
3549 static_cast<uint32_t>(decoded_template.desc_writes.size()),
3550 decoded_template.desc_writes.data());
locke-lunargd556cc32019-09-17 01:21:23 -06003551 }
3552}
3553
3554void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
3555 uint32_t *pPropertyCount, void *pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003556 auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06003557 if (*pPropertyCount) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003558 pd_state->display_plane_property_count = *pPropertyCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003559 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06003560 if (*pPropertyCount || pProperties) {
Jeremy Gebben383b9a32021-09-08 16:31:33 -06003561 pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003562 }
3563}
3564
3565void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
3566 uint32_t *pPropertyCount,
3567 VkDisplayPlanePropertiesKHR *pProperties,
3568 VkResult result) {
3569 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3570 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3571}
3572
3573void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
3574 uint32_t *pPropertyCount,
3575 VkDisplayPlaneProperties2KHR *pProperties,
3576 VkResult result) {
3577 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
3578 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
3579}
3580
3581void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3582 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
3583 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003584 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003585 cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003586 cb_state->BeginQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003587}
3588
3589void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
3590 uint32_t query, uint32_t index) {
3591 QueryObject query_obj = {queryPool, query, index};
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003592 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003593 cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003594 cb_state->EndQuery(query_obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003595}
3596
3597void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
3598 VkSamplerYcbcrConversion ycbcr_conversion) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003599 VkFormatFeatureFlags format_features = 0;
3600
3601 if (create_info->format != VK_FORMAT_UNDEFINED) {
3602 format_features = GetPotentialFormatFeatures(create_info->format);
sfricke-samsung45996a42021-09-16 13:45:27 -07003603 } else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003604 // If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
3605 format_features = GetExternalFormatFeaturesANDROID(create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06003606 }
Jeremy Gebbenf4fb2a02021-07-08 09:57:46 -06003607
Jeremy Gebben082a9832021-10-28 13:40:11 -06003608 Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
locke-lunargd556cc32019-09-17 01:21:23 -06003609}
3610
3611void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
3612 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3613 const VkAllocationCallbacks *pAllocator,
3614 VkSamplerYcbcrConversion *pYcbcrConversion,
3615 VkResult result) {
3616 if (VK_SUCCESS != result) return;
3617 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3618}
3619
3620void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
3621 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
3622 const VkAllocationCallbacks *pAllocator,
3623 VkSamplerYcbcrConversion *pYcbcrConversion,
3624 VkResult result) {
3625 if (VK_SUCCESS != result) return;
3626 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
3627}
3628
3629void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
3630 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003631 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003632}
3633
3634void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
3635 VkSamplerYcbcrConversion ycbcrConversion,
3636 const VkAllocationCallbacks *pAllocator) {
Jeremy Gebben082a9832021-10-28 13:40:11 -06003637 Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06003638}
3639
Tony-LunarG977448c2019-12-02 14:52:02 -07003640void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3641 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06003642 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07003643 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06003644
3645 // Do nothing if the query pool has been destroyed.
3646 auto query_pool_state = GetQueryPoolState(queryPool);
3647 if (!query_pool_state) return;
3648
3649 // Reset the state of existing entries.
3650 QueryObject query_obj{queryPool, 0};
3651 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
3652 for (uint32_t i = 0; i < max_query_count; ++i) {
3653 query_obj.query = firstQuery + i;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003654 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003655 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003656 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
3657 query_obj.perf_pass = pass_index;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02003658 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003659 }
3660 }
locke-lunargd556cc32019-09-17 01:21:23 -06003661 }
3662}
3663
Tony-LunarG977448c2019-12-02 14:52:02 -07003664void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3665 uint32_t queryCount) {
3666 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3667}
3668
3669void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
3670 uint32_t queryCount) {
3671 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
3672}
3673
locke-lunargd556cc32019-09-17 01:21:23 -06003674void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
Jeremy Gebbenfc890452021-10-27 10:56:49 -06003675 const UPDATE_TEMPLATE_STATE *template_state,
3676 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06003677 // Translate the templated update into a normal update for validation...
3678 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
3679 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
3680 decoded_update.desc_writes.data(), 0, NULL);
3681}
3682
3683// Update the common AllocateDescriptorSetsData
3684void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05003685 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003686 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05003687 auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003688 if (layout) {
3689 ds_data->layout_nodes[i] = layout;
3690 // Count total descriptors required per type
3691 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
3692 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003693 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
3694 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06003695 }
3696 }
3697 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
3698 }
3699}
3700
locke-lunargd556cc32019-09-17 01:21:23 -06003701void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
3702 uint32_t firstVertex, uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003703 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003704 cb_state->UpdateStateCmdDrawType(CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003705}
3706
Tony-LunarG745150c2021-07-02 15:07:31 -06003707void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3708 const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
3709 uint32_t firstInstance, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003710 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003711 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003712}
3713
locke-lunargd556cc32019-09-17 01:21:23 -06003714void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
3715 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
3716 uint32_t firstInstance) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003717 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003718 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003719}
3720
Tony-LunarG745150c2021-07-02 15:07:31 -06003721void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
3722 const VkMultiDrawIndexedInfoEXT *pIndexInfo,
3723 uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
3724 const int32_t *pVertexOffset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003725 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003726 cb_state->UpdateStateCmdDrawType(CMD_DRAWMULTIINDEXEDEXT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Tony-LunarG745150c2021-07-02 15:07:31 -06003727}
3728
locke-lunargd556cc32019-09-17 01:21:23 -06003729void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3730 uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003731 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003732 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003733 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003734 if (!disabled[command_buffer_state]) {
3735 cb_state->AddChild(buffer_state);
3736 }
locke-lunargd556cc32019-09-17 01:21:23 -06003737}
3738
3739void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3740 VkDeviceSize offset, uint32_t count, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003741 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003742 BUFFER_STATE *buffer_state = GetBufferState(buffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003743 cb_state->UpdateStateCmdDrawType(CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003744 if (!disabled[command_buffer_state]) {
3745 cb_state->AddChild(buffer_state);
3746 }
locke-lunargd556cc32019-09-17 01:21:23 -06003747}
3748
3749void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003750 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003751 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
locke-lunargd556cc32019-09-17 01:21:23 -06003752}
3753
3754void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
3755 VkDeviceSize offset) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003756 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003757 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003758 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003759 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003760 cb_state->AddChild(buffer_state);
3761 }
locke-lunargd556cc32019-09-17 01:21:23 -06003762}
3763
Nathaniel Cesarioa1325f42021-10-26 13:18:11 -06003764void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3765 uint32_t, uint32_t) {
3766 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3767 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3768}
3769
3770void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
3771 uint32_t, uint32_t) {
3772 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
3773 cb_state->UpdateStateCmdDrawDispatchType(CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE);
3774}
3775
Tony-LunarG977448c2019-12-02 14:52:02 -07003776void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3777 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
sfricke-samsung85584a72021-09-30 21:43:38 -07003778 uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003779 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003780 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003781 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003782 BUFFER_STATE *buffer_state = GetBufferState(buffer);
3783 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003784 cb_state->AddChild(buffer_state);
3785 cb_state->AddChild(count_buffer_state);
3786 }
Tony-LunarG977448c2019-12-02 14:52:02 -07003787}
3788
locke-lunargd556cc32019-09-17 01:21:23 -06003789void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3790 VkDeviceSize offset, VkBuffer countBuffer,
3791 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3792 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003793 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003794 CMD_DRAWINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003795}
3796
3797void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3798 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
3799 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003800 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003801 CMD_DRAWINDIRECTCOUNT);
Tony-LunarG977448c2019-12-02 14:52:02 -07003802}
3803
3804void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
3805 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
sfricke-samsung85584a72021-09-30 21:43:38 -07003806 uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003807 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003808 cb_state->UpdateStateCmdDrawType(cmd_type, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003809 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003810 BUFFER_STATE *buffer_state = GetBufferState(buffer);
3811 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003812 cb_state->AddChild(buffer_state);
3813 cb_state->AddChild(count_buffer_state);
3814 }
locke-lunargd556cc32019-09-17 01:21:23 -06003815}
3816
3817void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
3818 VkDeviceSize offset, VkBuffer countBuffer,
3819 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3820 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003821 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003822 CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
Tony-LunarG977448c2019-12-02 14:52:02 -07003823}
3824
3825void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
3826 VkDeviceSize offset, VkBuffer countBuffer,
3827 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3828 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06003829 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
sfricke-samsung85584a72021-09-30 21:43:38 -07003830 CMD_DRAWINDEXEDINDIRECTCOUNT);
locke-lunargd556cc32019-09-17 01:21:23 -06003831}
3832
3833void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
3834 uint32_t firstTask) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003835 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003836 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003837}
3838
3839void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3840 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003841 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003842 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
locke-lunargd556cc32019-09-17 01:21:23 -06003843 BUFFER_STATE *buffer_state = GetBufferState(buffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003844 if (!disabled[command_buffer_state] && buffer_state) {
3845 cb_state->AddChild(buffer_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003846 }
3847}
3848
3849void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
3850 VkDeviceSize offset, VkBuffer countBuffer,
3851 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
3852 uint32_t stride) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003853 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003854 cb_state->UpdateStateCmdDrawType(CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003855 if (!disabled[command_buffer_state]) {
Jeremy Gebben1ec89332021-08-05 13:51:49 -06003856 BUFFER_STATE *buffer_state = GetBufferState(buffer);
3857 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003858 if (buffer_state) {
3859 cb_state->AddChild(buffer_state);
3860 }
3861 if (count_buffer_state) {
3862 cb_state->AddChild(count_buffer_state);
3863 }
locke-lunargd556cc32019-09-17 01:21:23 -06003864 }
3865}
3866
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003867void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
3868 VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
3869 VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
3870 VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
3871 VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
3872 VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
3873 uint32_t width, uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003874 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003875 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSNV, VK_PIPELINE_BIND_POINT_RAY_TRACING_NV);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003876 cb_state->hasTraceRaysCmd = true;
3877}
3878
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003879void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
3880 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3881 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3882 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3883 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
3884 uint32_t height, uint32_t depth) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003885 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003886 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003887 cb_state->hasTraceRaysCmd = true;
3888}
3889
3890void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
3891 const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
3892 const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
3893 const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
3894 const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
3895 VkDeviceAddress indirectDeviceAddress) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003896 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sfricke-samsung85584a72021-09-30 21:43:38 -07003897 cb_state->UpdateStateCmdDrawDispatchType(CMD_TRACERAYSINDIRECTKHR, VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
Jeremy Gebben252f60c2021-07-15 14:54:30 -06003898 cb_state->hasTraceRaysCmd = true;
3899}
3900
locke-lunargd556cc32019-09-17 01:21:23 -06003901void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
3902 const VkAllocationCallbacks *pAllocator,
3903 VkShaderModule *pShaderModule, VkResult result,
3904 void *csm_state_data) {
3905 if (VK_SUCCESS != result) return;
3906 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
3907
sfricke-samsung45996a42021-09-16 13:45:27 -07003908 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
locke-lunargd556cc32019-09-17 01:21:23 -06003909 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003910 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
3911 csm_state->unique_shader_id)
3912 : std::make_shared<SHADER_MODULE_STATE>();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003913 Add(std::move(new_shader_module));
locke-lunargd556cc32019-09-17 01:21:23 -06003914}
3915
John Zulauf22b0fbe2019-10-15 06:26:16 -06003916void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
3917 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
3918 VkResult result) {
3919 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003920 auto swapchain_state = GetShared<SWAPCHAIN_NODE>(swapchain);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003921
3922 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
3923
3924 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003925 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
John Zulauf29d00532021-03-04 13:28:54 -07003926 SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
John Zulauffaa7a522021-03-05 12:22:45 -07003927 if (swapchain_image.image_state) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06003928
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003929 auto format_features =
3930 GetImageFormatFeatures(physical_device, device, pSwapchainImages[i], swapchain_state->image_create_info.format,
3931 swapchain_state->image_create_info.tiling);
John Zulauf22b0fbe2019-10-15 06:26:16 -06003932
Jeremy Gebbenbc9aacf2021-09-23 11:57:37 -06003933 auto image_state = std::make_shared<IMAGE_STATE>(this, pSwapchainImages[i], swapchain_state->image_create_info.ptr(),
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003934 swapchain, i, format_features);
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003935 if (!swapchain_image.fake_base_address) {
3936 auto size = image_state->fragment_encoder->TotalSize();
3937 swapchain_image.fake_base_address = fake_memory.Alloc(size);
John Zulauf29d00532021-03-04 13:28:54 -07003938 }
3939
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06003940 image_state->SetSwapchain(swapchain_state, i);
Jeremy Gebbenb4d17012021-07-08 13:18:15 -06003941 swapchain_image.image_state = image_state.get();
Jeremy Gebben082a9832021-10-28 13:40:11 -06003942 Add(std::move(image_state));
John Zulauf22b0fbe2019-10-15 06:26:16 -06003943 }
3944 }
3945
3946 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06003947 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
3948 }
3949}
sourav parmar35e7a002020-06-09 17:58:44 -07003950
Lars-Ivar Hesselberg Simonsen0dd3a812021-10-28 14:09:01 +02003951void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
3952 const VkCopyAccelerationStructureInfoKHR *pInfo,
3953 VkResult result) {
3954 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
3955 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
3956 if (dst_as_state != nullptr && src_as_state != nullptr) {
3957 dst_as_state->built = true;
3958 dst_as_state->build_info_khr = src_as_state->build_info_khr;
3959 }
3960}
3961
sourav parmar35e7a002020-06-09 17:58:44 -07003962void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
3963 const VkCopyAccelerationStructureInfoKHR *pInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003964 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
sourav parmar35e7a002020-06-09 17:58:44 -07003965 if (cb_state) {
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003966 cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
sourav parmarcd5fb182020-07-17 12:58:44 -07003967 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
3968 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07003969 if (dst_as_state != nullptr && src_as_state != nullptr) {
3970 dst_as_state->built = true;
3971 dst_as_state->build_info_khr = src_as_state->build_info_khr;
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06003972 if (!disabled[command_buffer_state]) {
3973 cb_state->AddChild(dst_as_state);
3974 cb_state->AddChild(src_as_state);
3975 }
sourav parmar35e7a002020-06-09 17:58:44 -07003976 }
3977 }
3978}
Piers Daniell39842ee2020-07-10 16:42:33 -06003979
3980void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003981 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003982 cb_state->RecordStateCmd(CMD_SETCULLMODEEXT, CBSTATUS_CULL_MODE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003983}
3984
3985void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003986 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003987 cb_state->RecordStateCmd(CMD_SETFRONTFACEEXT, CBSTATUS_FRONT_FACE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003988}
3989
3990void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
3991 VkPrimitiveTopology primitiveTopology) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003992 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06003993 cb_state->RecordStateCmd(CMD_SETPRIMITIVETOPOLOGYEXT, CBSTATUS_PRIMITIVE_TOPOLOGY_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06003994 cb_state->primitiveTopology = primitiveTopology;
Piers Daniell39842ee2020-07-10 16:42:33 -06003995}
3996
3997void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
3998 const VkViewport *pViewports) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06003999 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004000 cb_state->RecordStateCmd(CMD_SETVIEWPORTWITHCOUNTEXT, CBSTATUS_VIEWPORT_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004001 uint32_t bits = (1u << viewportCount) - 1u;
4002 cb_state->viewportWithCountMask |= bits;
4003 cb_state->trashedViewportMask &= ~bits;
Tobias Hector6663c9b2020-11-05 10:18:02 +00004004 cb_state->viewportWithCountCount = viewportCount;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004005 cb_state->trashedViewportCount = false;
David Zhao Akeley44139b12021-04-26 16:16:13 -07004006
4007 cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
4008 for (size_t i = 0; i < viewportCount; ++i) {
4009 cb_state->dynamicViewports[i] = pViewports[i];
4010 }
Piers Daniell39842ee2020-07-10 16:42:33 -06004011}
4012
4013void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
4014 const VkRect2D *pScissors) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004015 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004016 cb_state->RecordStateCmd(CMD_SETSCISSORWITHCOUNTEXT, CBSTATUS_SCISSOR_WITH_COUNT_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004017 uint32_t bits = (1u << scissorCount) - 1u;
4018 cb_state->scissorWithCountMask |= bits;
4019 cb_state->trashedScissorMask &= ~bits;
4020 cb_state->scissorWithCountCount = scissorCount;
4021 cb_state->trashedScissorCount = false;
Piers Daniell39842ee2020-07-10 16:42:33 -06004022}
4023
4024void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4025 uint32_t bindingCount, const VkBuffer *pBuffers,
4026 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
4027 const VkDeviceSize *pStrides) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004028 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004029 cb_state->RecordStateCmd(CMD_BINDVERTEXBUFFERS2EXT, pStrides ? CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET : CBSTATUS_NONE);
Piers Daniell39842ee2020-07-10 16:42:33 -06004030
4031 uint32_t end = firstBinding + bindingCount;
4032 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4033 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4034 }
4035
4036 for (uint32_t i = 0; i < bindingCount; ++i) {
4037 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07004038 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06004039 vertex_buffer_binding.offset = pOffsets[i];
4040 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
4041 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
4042 // Add binding for this vertex buffer to this commandbuffer
Jeremy Gebben9efe1cf2021-05-15 20:05:09 -06004043 if (!disabled[command_buffer_state] && pBuffers[i]) {
4044 cb_state->AddChild(vertex_buffer_binding.buffer_state.get());
Piers Daniell39842ee2020-07-10 16:42:33 -06004045 }
4046 }
4047}
4048
4049void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004050 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004051 cb_state->RecordStateCmd(CMD_SETDEPTHTESTENABLEEXT, CBSTATUS_DEPTH_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004052}
4053
4054void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004055 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004056 cb_state->RecordStateCmd(CMD_SETDEPTHWRITEENABLEEXT, CBSTATUS_DEPTH_WRITE_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004057}
4058
4059void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004060 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004061 cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOPEXT, CBSTATUS_DEPTH_COMPARE_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004062}
4063
4064void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
4065 VkBool32 depthBoundsTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004066 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004067 cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDSTESTENABLEEXT, CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004068}
4069void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004070 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004071 cb_state->RecordStateCmd(CMD_SETSTENCILTESTENABLEEXT, CBSTATUS_STENCIL_TEST_ENABLE_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004072}
4073
4074void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4075 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
4076 VkCompareOp compareOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004077 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004078 cb_state->RecordStateCmd(CMD_SETSTENCILOPEXT, CBSTATUS_STENCIL_OP_SET);
Piers Daniell39842ee2020-07-10 16:42:33 -06004079}
locke-lunarg4189aa22020-10-21 00:23:48 -06004080
4081void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
4082 uint32_t discardRectangleCount,
4083 const VkRect2D *pDiscardRectangles) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004084 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004085 cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CBSTATUS_DISCARD_RECTANGLE_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004086}
4087
4088void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
4089 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004090 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004091 cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CBSTATUS_SAMPLE_LOCATIONS_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004092}
4093
4094void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
4095 VkCoarseSampleOrderTypeNV sampleOrderType,
4096 uint32_t customSampleOrderCount,
4097 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004098 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004099 cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CBSTATUS_COARSE_SAMPLE_ORDER_SET);
locke-lunarg4189aa22020-10-21 00:23:48 -06004100}
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004101
4102void ValidationStateTracker::PreCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004103 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004104 cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CBSTATUS_PATCH_CONTROL_POINTS_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004105}
4106
4107void ValidationStateTracker::PreCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004108 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004109 cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CBSTATUS_LOGIC_OP_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004110}
4111
4112void ValidationStateTracker::PreCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
4113 VkBool32 rasterizerDiscardEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004114 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004115 cb_state->RecordStateCmd(CMD_SETRASTERIZERDISCARDENABLEEXT, CBSTATUS_RASTERIZER_DISCARD_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004116}
4117
4118void ValidationStateTracker::PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004119 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004120 cb_state->RecordStateCmd(CMD_SETDEPTHBIASENABLEEXT, CBSTATUS_DEPTH_BIAS_ENABLE_SET);
Vikram Kushwahaa57b0c32021-04-19 12:21:46 -07004121}
4122
4123void ValidationStateTracker::PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
4124 VkBool32 primitiveRestartEnable) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004125 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
Jeremy Gebben10a0ed12021-08-17 09:54:29 -06004126 cb_state->RecordStateCmd(CMD_SETPRIMITIVERESTARTENABLEEXT, CBSTATUS_PRIMITIVE_RESTART_ENABLE_SET);
David Zhao Akeley44139b12021-04-26 16:16:13 -07004127}
Piers Daniell924cd832021-05-18 13:48:47 -06004128
4129void ValidationStateTracker::PreCallRecordCmdSetVertexInputEXT(
4130 VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
4131 const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
4132 const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004133 CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004134 CBStatusFlags status_flags = CBSTATUS_VERTEX_INPUT_SET;
4135
4136 const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
4137 const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
4138 if (pipeline_state) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06004139 if (pipeline_state->create_info.graphics.pDynamicState) {
4140 for (uint32_t i = 0; i < pipeline_state->create_info.graphics.pDynamicState->dynamicStateCount; ++i) {
4141 if (pipeline_state->create_info.graphics.pDynamicState->pDynamicStates[i] ==
ziga-lunarg4af0a8c2021-08-27 15:53:20 +02004142 VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
4143 status_flags |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
4144 break;
4145 }
4146 }
4147 }
4148 }
4149 cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
Piers Daniell924cd832021-05-18 13:48:47 -06004150}
Nathaniel Cesario42ac6ca2021-06-15 17:23:05 -06004151
4152void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
4153 BUFFER_STATE *buffer_state = GetBufferState(pInfo->buffer);
4154 if (buffer_state) {
4155 // address is used for GPU-AV and ray tracing buffer validation
4156 buffer_state->deviceAddress = address;
4157 buffer_address_map_.emplace(address, buffer_state);
4158 }
4159}
4160
4161void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4162 VkDeviceAddress address) {
4163 RecordGetBufferDeviceAddress(pInfo, address);
4164}
4165
4166void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4167 VkDeviceAddress address) {
4168 RecordGetBufferDeviceAddress(pInfo, address);
4169}
4170
4171void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
4172 VkDeviceAddress address) {
4173 RecordGetBufferDeviceAddress(pInfo, address);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004174}
4175
4176std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
4177 VkSwapchainKHR swapchain) {
Jeremy Gebben62c3bf42021-07-21 15:38:24 -06004178 return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
Nathaniel Cesario39152e62021-07-02 13:04:16 -06004179}
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004180
4181std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
4182 const VkCommandBufferAllocateInfo *create_info,
Jeremy Gebbencd7fa282021-10-27 10:25:32 -06004183 const COMMAND_POOL_STATE *pool) {
Jeremy Gebben3d22d582021-08-11 15:37:58 -06004184 return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
4185}