blob: 8ea3c289d08739f3fa905990b9d677791791cc91 [file] [log] [blame]
Tony-LunarG73719992020-01-15 10:20:28 -07001/* Copyright (c) 2015-2020 The Khronos Group Inc.
2 * Copyright (c) 2015-2020 Valve Corporation
3 * Copyright (c) 2015-2020 LunarG, Inc.
4 * Copyright (C) 2015-2020 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
locke-lunargd556cc32019-09-17 01:21:23 -060025#include <cmath>
26#include <set>
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"
38
John Zulauf890b50b2020-06-17 15:18:19 -060039const char *CommandTypeString(CMD_TYPE type) {
40 // Autogenerated as part of the vk_validation_error_message.h codegen
Mark Lobodzinski677dc0b2020-11-12 15:28:09 -070041 return kGeneratedCommandNameList[type];
John Zulauf890b50b2020-06-17 15:18:19 -060042}
43
locke-lunarg4189aa22020-10-21 00:23:48 -060044VkDynamicState ConvertToDynamicState(CBStatusFlagBits flag) {
45 switch (flag) {
46 case CBSTATUS_LINE_WIDTH_SET:
47 return VK_DYNAMIC_STATE_LINE_WIDTH;
48 case CBSTATUS_DEPTH_BIAS_SET:
49 return VK_DYNAMIC_STATE_DEPTH_BIAS;
50 case CBSTATUS_BLEND_CONSTANTS_SET:
51 return VK_DYNAMIC_STATE_BLEND_CONSTANTS;
52 case CBSTATUS_DEPTH_BOUNDS_SET:
53 return VK_DYNAMIC_STATE_DEPTH_BOUNDS;
54 case CBSTATUS_STENCIL_READ_MASK_SET:
55 return VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK;
56 case CBSTATUS_STENCIL_WRITE_MASK_SET:
57 return VK_DYNAMIC_STATE_STENCIL_WRITE_MASK;
58 case CBSTATUS_STENCIL_REFERENCE_SET:
59 return VK_DYNAMIC_STATE_STENCIL_REFERENCE;
60 case CBSTATUS_VIEWPORT_SET:
61 return VK_DYNAMIC_STATE_VIEWPORT;
62 case CBSTATUS_SCISSOR_SET:
63 return VK_DYNAMIC_STATE_SCISSOR;
64 case CBSTATUS_EXCLUSIVE_SCISSOR_SET:
65 return VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV;
66 case CBSTATUS_SHADING_RATE_PALETTE_SET:
67 return VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV;
68 case CBSTATUS_LINE_STIPPLE_SET:
69 return VK_DYNAMIC_STATE_LINE_STIPPLE_EXT;
70 case CBSTATUS_VIEWPORT_W_SCALING_SET:
71 return VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV;
72 case CBSTATUS_CULL_MODE_SET:
73 return VK_DYNAMIC_STATE_CULL_MODE_EXT;
74 case CBSTATUS_FRONT_FACE_SET:
75 return VK_DYNAMIC_STATE_FRONT_FACE_EXT;
76 case CBSTATUS_PRIMITIVE_TOPOLOGY_SET:
77 return VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT;
78 case CBSTATUS_VIEWPORT_WITH_COUNT_SET:
79 return VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT;
80 case CBSTATUS_SCISSOR_WITH_COUNT_SET:
81 return VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT;
82 case CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET:
83 return VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT;
84 case CBSTATUS_DEPTH_TEST_ENABLE_SET:
85 return VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT;
86 case CBSTATUS_DEPTH_WRITE_ENABLE_SET:
87 return VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT;
88 case CBSTATUS_DEPTH_COMPARE_OP_SET:
89 return VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT;
90 case CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET:
91 return VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT;
92 case CBSTATUS_STENCIL_TEST_ENABLE_SET:
93 return VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT;
94 case CBSTATUS_STENCIL_OP_SET:
95 return VK_DYNAMIC_STATE_STENCIL_OP_EXT;
96 case CBSTATUS_DISCARD_RECTANGLE_SET:
97 return VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT;
98 case CBSTATUS_SAMPLE_LOCATIONS_SET:
99 return VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT;
100 case CBSTATUS_COARSE_SAMPLE_ORDER_SET:
101 return VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV;
102 default:
103 // CBSTATUS_INDEX_BUFFER_BOUND is not in VkDynamicState
104 return VK_DYNAMIC_STATE_MAX_ENUM;
105 }
106 return VK_DYNAMIC_STATE_MAX_ENUM;
107}
108
109CBStatusFlagBits ConvertToCBStatusFlagBits(VkDynamicState state) {
110 switch (state) {
111 case VK_DYNAMIC_STATE_VIEWPORT:
112 return CBSTATUS_VIEWPORT_SET;
113 case VK_DYNAMIC_STATE_SCISSOR:
114 return CBSTATUS_SCISSOR_SET;
115 case VK_DYNAMIC_STATE_LINE_WIDTH:
116 return CBSTATUS_LINE_WIDTH_SET;
117 case VK_DYNAMIC_STATE_DEPTH_BIAS:
118 return CBSTATUS_DEPTH_BIAS_SET;
119 case VK_DYNAMIC_STATE_BLEND_CONSTANTS:
120 return CBSTATUS_BLEND_CONSTANTS_SET;
121 case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
122 return CBSTATUS_DEPTH_BOUNDS_SET;
123 case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
124 return CBSTATUS_STENCIL_READ_MASK_SET;
125 case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
126 return CBSTATUS_STENCIL_WRITE_MASK_SET;
127 case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
128 return CBSTATUS_STENCIL_REFERENCE_SET;
129 case VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV:
130 return CBSTATUS_VIEWPORT_W_SCALING_SET;
131 case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT:
132 return CBSTATUS_DISCARD_RECTANGLE_SET;
133 case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT:
134 return CBSTATUS_SAMPLE_LOCATIONS_SET;
135 case VK_DYNAMIC_STATE_VIEWPORT_SHADING_RATE_PALETTE_NV:
136 return CBSTATUS_SHADING_RATE_PALETTE_SET;
137 case VK_DYNAMIC_STATE_VIEWPORT_COARSE_SAMPLE_ORDER_NV:
138 return CBSTATUS_COARSE_SAMPLE_ORDER_SET;
139 case VK_DYNAMIC_STATE_EXCLUSIVE_SCISSOR_NV:
140 return CBSTATUS_EXCLUSIVE_SCISSOR_SET;
141 case VK_DYNAMIC_STATE_LINE_STIPPLE_EXT:
142 return CBSTATUS_LINE_STIPPLE_SET;
143 case VK_DYNAMIC_STATE_CULL_MODE_EXT:
144 return CBSTATUS_CULL_MODE_SET;
145 case VK_DYNAMIC_STATE_FRONT_FACE_EXT:
146 return CBSTATUS_FRONT_FACE_SET;
147 case VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT:
148 return CBSTATUS_PRIMITIVE_TOPOLOGY_SET;
149 case VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT:
150 return CBSTATUS_VIEWPORT_WITH_COUNT_SET;
151 case VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT_EXT:
152 return CBSTATUS_SCISSOR_WITH_COUNT_SET;
153 case VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT:
154 return CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
155 case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT:
156 return CBSTATUS_DEPTH_TEST_ENABLE_SET;
157 case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT:
158 return CBSTATUS_DEPTH_WRITE_ENABLE_SET;
159 case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT:
160 return CBSTATUS_DEPTH_COMPARE_OP_SET;
161 case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT:
162 return CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET;
163 case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT:
164 return CBSTATUS_STENCIL_TEST_ENABLE_SET;
165 case VK_DYNAMIC_STATE_STENCIL_OP_EXT:
166 return CBSTATUS_STENCIL_OP_SET;
167 default:
168 return CBSTATUS_NONE;
169 }
170 return CBSTATUS_NONE;
171}
172
Mark Lobodzinskib4ab6ac2020-04-02 13:12:06 -0600173void ValidationStateTracker::InitDeviceValidationObject(bool add_obj, ValidationObject *inst_obj, ValidationObject *dev_obj) {
174 if (add_obj) {
175 instance_state = reinterpret_cast<ValidationStateTracker *>(GetValidationObject(inst_obj->object_dispatch, container_type));
176 // Call base class
177 ValidationObject::InitDeviceValidationObject(add_obj, inst_obj, dev_obj);
178 }
179}
180
John Zulauf5c5e88d2019-12-26 11:22:02 -0700181uint32_t ResolveRemainingLevels(const VkImageSubresourceRange *range, uint32_t mip_levels) {
182 // Return correct number of mip levels taking into account VK_REMAINING_MIP_LEVELS
183 uint32_t mip_level_count = range->levelCount;
184 if (range->levelCount == VK_REMAINING_MIP_LEVELS) {
185 mip_level_count = mip_levels - range->baseMipLevel;
186 }
187 return mip_level_count;
188}
189
190uint32_t ResolveRemainingLayers(const VkImageSubresourceRange *range, uint32_t layers) {
191 // Return correct number of layers taking into account VK_REMAINING_ARRAY_LAYERS
192 uint32_t array_layer_count = range->layerCount;
193 if (range->layerCount == VK_REMAINING_ARRAY_LAYERS) {
194 array_layer_count = layers - range->baseArrayLayer;
195 }
196 return array_layer_count;
197}
198
199VkImageSubresourceRange NormalizeSubresourceRange(const VkImageCreateInfo &image_create_info,
200 const VkImageSubresourceRange &range) {
201 VkImageSubresourceRange norm = range;
202 norm.levelCount = ResolveRemainingLevels(&range, image_create_info.mipLevels);
203
Mike Schuchardt2df08912020-12-15 16:28:09 -0800204 // Special case for 3D images with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT flag bit, where <extent.depth> and
John Zulauf5c5e88d2019-12-26 11:22:02 -0700205 // <arrayLayers> can potentially alias.
Mike Schuchardt2df08912020-12-15 16:28:09 -0800206 uint32_t layer_limit = (0 != (image_create_info.flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT))
John Zulauf5c5e88d2019-12-26 11:22:02 -0700207 ? image_create_info.extent.depth
208 : image_create_info.arrayLayers;
209 norm.layerCount = ResolveRemainingLayers(&range, layer_limit);
210
211 // For multiplanar formats, IMAGE_ASPECT_COLOR is equivalent to adding the aspect of the individual planes
212 VkImageAspectFlags &aspect_mask = norm.aspectMask;
213 if (FormatIsMultiplane(image_create_info.format)) {
214 if (aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) {
215 aspect_mask &= ~VK_IMAGE_ASPECT_COLOR_BIT;
216 aspect_mask |= (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT);
217 if (FormatPlaneCount(image_create_info.format) > 2) {
218 aspect_mask |= VK_IMAGE_ASPECT_PLANE_2_BIT;
219 }
220 }
221 }
222 return norm;
223}
224
225VkImageSubresourceRange NormalizeSubresourceRange(const IMAGE_STATE &image_state, const VkImageSubresourceRange &range) {
226 const VkImageCreateInfo &image_create_info = image_state.createInfo;
227 return NormalizeSubresourceRange(image_create_info, range);
228}
229
John Zulauf2bc1fde2020-04-24 15:09:51 -0600230// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
231// attachments won't persist past the API entry point exit.
232std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
233 const FRAMEBUFFER_STATE &fb_state) {
234 const VkImageView *attachments = fb_state.createInfo.pAttachments;
235 uint32_t count = fb_state.createInfo.attachmentCount;
236 if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
237 const auto *framebuffer_attachments = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
238 if (framebuffer_attachments) {
239 attachments = framebuffer_attachments->pAttachments;
240 count = framebuffer_attachments->attachmentCount;
241 }
242 }
243 return std::make_pair(count, attachments);
244}
245
246std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetAttachmentViews(const VkRenderPassBeginInfo &rp_begin,
247 const FRAMEBUFFER_STATE &fb_state) const {
248 std::vector<const IMAGE_VIEW_STATE *> views;
249
250 const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
251 const auto attachment_count = count_attachment.first;
252 const auto *attachments = count_attachment.second;
253 views.resize(attachment_count, nullptr);
254 for (uint32_t i = 0; i < attachment_count; i++) {
255 if (attachments[i] != VK_NULL_HANDLE) {
256 views[i] = Get<IMAGE_VIEW_STATE>(attachments[i]);
257 }
258 }
259 return views;
260}
261
262std::vector<const IMAGE_VIEW_STATE *> ValidationStateTracker::GetCurrentAttachmentViews(const CMD_BUFFER_STATE &cb_state) const {
263 // Only valid *after* RecordBeginRenderPass and *before* RecordEndRenderpass as it relies on cb_state for the renderpass info.
264 std::vector<const IMAGE_VIEW_STATE *> views;
265
locke-lunargaecf2152020-05-12 17:15:41 -0600266 const auto *rp_state = cb_state.activeRenderPass.get();
John Zulauf2bc1fde2020-04-24 15:09:51 -0600267 if (!rp_state) return views;
268 const auto &rp_begin = *cb_state.activeRenderPassBeginInfo.ptr();
269 const auto *fb_state = Get<FRAMEBUFFER_STATE>(rp_begin.framebuffer);
270 if (!fb_state) return views;
271
272 return GetAttachmentViews(rp_begin, *fb_state);
273}
274
locke-lunarg3e127c72020-06-09 17:45:28 -0600275PIPELINE_STATE *GetCurrentPipelineFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint) {
locke-lunargb8d7a7a2020-10-25 16:01:52 -0600276 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
277 return cmd.lastBound[lv_bind_point].pipeline_state;
locke-lunarg3e127c72020-06-09 17:45:28 -0600278}
279
280void GetCurrentPipelineAndDesriptorSetsFromCommandBuffer(const CMD_BUFFER_STATE &cmd, VkPipelineBindPoint pipelineBindPoint,
281 const PIPELINE_STATE **rtn_pipe,
282 const std::vector<LAST_BOUND_STATE::PER_SET> **rtn_sets) {
locke-lunargb8d7a7a2020-10-25 16:01:52 -0600283 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
284 const auto &last_bound_it = cmd.lastBound[lv_bind_point];
285 if (!last_bound_it.IsUsing()) {
locke-lunarg3e127c72020-06-09 17:45:28 -0600286 return;
287 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -0600288 *rtn_pipe = last_bound_it.pipeline_state;
289 *rtn_sets = &(last_bound_it.per_set);
locke-lunarg3e127c72020-06-09 17:45:28 -0600290}
291
locke-lunargd556cc32019-09-17 01:21:23 -0600292#ifdef VK_USE_PLATFORM_ANDROID_KHR
293// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
294// This could also move into a seperate core_validation_android.cpp file... ?
295
296void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {
297 const VkExternalMemoryImageCreateInfo *emici = lvl_find_in_chain<VkExternalMemoryImageCreateInfo>(create_info->pNext);
298 if (emici && (emici->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
Spencer Fricke224c9852020-04-06 07:47:29 -0700299 is_node->external_ahb = true;
locke-lunargd556cc32019-09-17 01:21:23 -0600300 }
301 const VkExternalFormatANDROID *ext_fmt_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext);
302 if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
303 is_node->has_ahb_format = true;
304 is_node->ahb_format = ext_fmt_android->externalFormat;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700305 // VUID 01894 will catch if not found in map
306 auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
307 if (it != ahb_ext_formats_map.end()) {
308 is_node->format_features = it->second;
309 }
locke-lunargd556cc32019-09-17 01:21:23 -0600310 }
311}
312
sfricke-samsung013f1ef2020-05-14 22:56:20 -0700313void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {
314 const VkExternalMemoryBufferCreateInfo *embci = lvl_find_in_chain<VkExternalMemoryBufferCreateInfo>(create_info->pNext);
315 if (embci && (embci->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) {
316 bs_node->external_ahb = true;
317 }
318}
319
locke-lunargd556cc32019-09-17 01:21:23 -0600320void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700321 VkSamplerYcbcrConversion ycbcr_conversion,
322 SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state) {
locke-lunargd556cc32019-09-17 01:21:23 -0600323 const VkExternalFormatANDROID *ext_format_android = lvl_find_in_chain<VkExternalFormatANDROID>(create_info->pNext);
324 if (ext_format_android && (0 != ext_format_android->externalFormat)) {
325 ycbcr_conversion_ahb_fmt_map.emplace(ycbcr_conversion, ext_format_android->externalFormat);
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700326 // VUID 01894 will catch if not found in map
327 auto it = ahb_ext_formats_map.find(ext_format_android->externalFormat);
328 if (it != ahb_ext_formats_map.end()) {
329 ycbcr_state->format_features = it->second;
330 }
locke-lunargd556cc32019-09-17 01:21:23 -0600331 }
332};
333
334void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion) {
335 ycbcr_conversion_ahb_fmt_map.erase(ycbcr_conversion);
336};
337
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700338void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
339 VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
340 if (VK_SUCCESS != result) return;
341 auto ahb_format_props = lvl_find_in_chain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
342 if (ahb_format_props) {
343 ahb_ext_formats_map.insert({ahb_format_props->externalFormat, ahb_format_props->formatFeatures});
344 }
345}
346
locke-lunargd556cc32019-09-17 01:21:23 -0600347#else
348
349void ValidationStateTracker::RecordCreateImageANDROID(const VkImageCreateInfo *create_info, IMAGE_STATE *is_node) {}
350
sfricke-samsung013f1ef2020-05-14 22:56:20 -0700351void ValidationStateTracker::RecordCreateBufferANDROID(const VkBufferCreateInfo *create_info, BUFFER_STATE *bs_node) {}
352
locke-lunargd556cc32019-09-17 01:21:23 -0600353void ValidationStateTracker::RecordCreateSamplerYcbcrConversionANDROID(const VkSamplerYcbcrConversionCreateInfo *create_info,
sfricke-samsungbe3584f2020-04-22 14:58:06 -0700354 VkSamplerYcbcrConversion ycbcr_conversion,
355 SAMPLER_YCBCR_CONVERSION_STATE *ycbcr_state){};
locke-lunargd556cc32019-09-17 01:21:23 -0600356
357void ValidationStateTracker::RecordDestroySamplerYcbcrConversionANDROID(VkSamplerYcbcrConversion ycbcr_conversion){};
358
359#endif // VK_USE_PLATFORM_ANDROID_KHR
360
Mark Lobodzinskid3ec86f2020-03-18 11:23:04 -0600361std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> GetDslFromPipelineLayout(PIPELINE_LAYOUT_STATE const *layout_data,
362 uint32_t set) {
363 std::shared_ptr<cvdescriptorset::DescriptorSetLayout const> dsl = nullptr;
364 if (layout_data && (set < layout_data->set_layouts.size())) {
365 dsl = layout_data->set_layouts[set];
366 }
367 return dsl;
368}
369
Petr Kraus44f1c482020-04-25 20:09:25 +0200370void AddImageStateProps(IMAGE_STATE &image_state, const VkDevice device, const VkPhysicalDevice physical_device) {
371 // Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
372 // if format is AHB external format then the features are already set
373 if (image_state.has_ahb_format == false) {
374 const VkImageTiling image_tiling = image_state.createInfo.tiling;
375 const VkFormat image_format = image_state.createInfo.format;
376 if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
377 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {
378 VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, nullptr};
379 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state.image, &drm_format_properties);
380
381 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
382 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
383 nullptr};
384 format_properties_2.pNext = (void *)&drm_properties_list;
385 DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2);
Lionel Landwerlin09351a72020-06-22 18:15:59 +0300386 std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
387 drm_properties.resize(drm_properties_list.drmFormatModifierCount);
388 drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
389 DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_format, &format_properties_2);
Petr Kraus44f1c482020-04-25 20:09:25 +0200390
391 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
Lionel Landwerlin94f1ce32020-07-02 17:39:31 +0300392 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier ==
393 drm_format_properties.drmFormatModifier) {
394 image_state.format_features =
Petr Kraus44f1c482020-04-25 20:09:25 +0200395 drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
Lionel Landwerlin94f1ce32020-07-02 17:39:31 +0300396 break;
Petr Kraus44f1c482020-04-25 20:09:25 +0200397 }
398 }
399 } else {
400 VkFormatProperties format_properties;
401 DispatchGetPhysicalDeviceFormatProperties(physical_device, image_format, &format_properties);
402 image_state.format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures
403 : format_properties.optimalTilingFeatures;
404 }
405 }
406}
407
locke-lunargd556cc32019-09-17 01:21:23 -0600408void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
409 const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
410 if (VK_SUCCESS != result) return;
locke-lunarg296a3c92020-03-25 01:04:29 -0600411 auto is_node = std::make_shared<IMAGE_STATE>(device, *pImage, pCreateInfo);
sfricke-samsung71bc6572020-04-29 15:49:43 -0700412 is_node->disjoint = ((pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) != 0);
locke-lunargd556cc32019-09-17 01:21:23 -0600413 if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
414 RecordCreateImageANDROID(pCreateInfo, is_node.get());
415 }
416 const auto swapchain_info = lvl_find_in_chain<VkImageSwapchainCreateInfoKHR>(pCreateInfo->pNext);
417 if (swapchain_info) {
418 is_node->create_from_swapchain = swapchain_info->swapchain;
419 }
420
locke-lunargd556cc32019-09-17 01:21:23 -0600421 // Record the memory requirements in case they won't be queried
sfricke-samsung013f1ef2020-05-14 22:56:20 -0700422 // External AHB memory can't be queried until after memory is bound
Spencer Fricke224c9852020-04-06 07:47:29 -0700423 if (is_node->external_ahb == false) {
sfricke-samsung71bc6572020-04-29 15:49:43 -0700424 if (is_node->disjoint == false) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -0700425 DispatchGetImageMemoryRequirements(device, *pImage, &is_node->requirements);
426 } else {
427 uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
428 VkImagePlaneMemoryRequirementsInfo image_plane_req = {VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO, nullptr};
429 VkMemoryRequirements2 mem_reqs2 = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, nullptr};
430 VkImageMemoryRequirementsInfo2 mem_req_info2 = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2};
431 mem_req_info2.pNext = &image_plane_req;
432 mem_req_info2.image = *pImage;
433
434 assert(plane_count != 0); // assumes each format has at least first plane
435 image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_0_BIT;
436 DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
437 is_node->plane0_requirements = mem_reqs2.memoryRequirements;
438
439 if (plane_count >= 2) {
440 image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_1_BIT;
441 DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
442 is_node->plane1_requirements = mem_reqs2.memoryRequirements;
443 }
444 if (plane_count >= 3) {
445 image_plane_req.planeAspect = VK_IMAGE_ASPECT_PLANE_2_BIT;
446 DispatchGetImageMemoryRequirements2(device, &mem_req_info2, &mem_reqs2);
447 is_node->plane2_requirements = mem_reqs2.memoryRequirements;
448 }
449 }
locke-lunargd556cc32019-09-17 01:21:23 -0600450 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700451
Petr Kraus44f1c482020-04-25 20:09:25 +0200452 AddImageStateProps(*is_node, device, physical_device);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700453
sfricke-samsungedce77a2020-07-03 22:35:13 -0700454 is_node->unprotected = ((pCreateInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0);
455
locke-lunargd556cc32019-09-17 01:21:23 -0600456 imageMap.insert(std::make_pair(*pImage, std::move(is_node)));
457}
458
459void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
460 if (!image) return;
461 IMAGE_STATE *image_state = GetImageState(image);
462 const VulkanTypedHandle obj_struct(image, kVulkanObjectTypeImage);
463 InvalidateCommandBuffers(image_state->cb_bindings, obj_struct);
464 // Clean up memory mapping, bindings and range references for image
465 for (auto mem_binding : image_state->GetBoundMemory()) {
locke-lunargcf04d582019-11-26 00:31:50 -0700466 RemoveImageMemoryRange(image, mem_binding);
locke-lunargd556cc32019-09-17 01:21:23 -0600467 }
468 if (image_state->bind_swapchain) {
469 auto swapchain = GetSwapchainState(image_state->bind_swapchain);
470 if (swapchain) {
locke-lunargb3584732019-10-28 20:18:36 -0600471 swapchain->images[image_state->bind_swapchain_imageIndex].bound_images.erase(image_state->image);
locke-lunargd556cc32019-09-17 01:21:23 -0600472 }
473 }
474 RemoveAliasingImage(image_state);
475 ClearMemoryObjectBindings(obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500476 image_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -0600477 // Remove image from imageMap
478 imageMap.erase(image);
479}
480
481void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
482 VkImageLayout imageLayout, const VkClearColorValue *pColor,
483 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
484 auto cb_node = GetCBState(commandBuffer);
485 auto image_state = GetImageState(image);
486 if (cb_node && image_state) {
487 AddCommandBufferBindingImage(cb_node, image_state);
488 }
489}
490
491void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
492 VkImageLayout imageLayout,
493 const VkClearDepthStencilValue *pDepthStencil,
494 uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
495 auto cb_node = GetCBState(commandBuffer);
496 auto image_state = GetImageState(image);
497 if (cb_node && image_state) {
498 AddCommandBufferBindingImage(cb_node, image_state);
499 }
500}
501
502void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
503 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
504 uint32_t regionCount, const VkImageCopy *pRegions) {
505 auto cb_node = GetCBState(commandBuffer);
506 auto src_image_state = GetImageState(srcImage);
507 auto dst_image_state = GetImageState(dstImage);
508
509 // Update bindings between images and cmd buffer
510 AddCommandBufferBindingImage(cb_node, src_image_state);
511 AddCommandBufferBindingImage(cb_node, dst_image_state);
512}
513
Jeff Leger178b1e52020-10-05 12:22:23 -0400514void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
515 const VkCopyImageInfo2KHR *pCopyImageInfo) {
516 auto cb_node = GetCBState(commandBuffer);
517 auto src_image_state = GetImageState(pCopyImageInfo->srcImage);
518 auto dst_image_state = GetImageState(pCopyImageInfo->dstImage);
519
520 // Update bindings between images and cmd buffer
521 AddCommandBufferBindingImage(cb_node, src_image_state);
522 AddCommandBufferBindingImage(cb_node, dst_image_state);
523}
524
locke-lunargd556cc32019-09-17 01:21:23 -0600525void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
526 VkImageLayout srcImageLayout, VkImage dstImage,
527 VkImageLayout dstImageLayout, uint32_t regionCount,
528 const VkImageResolve *pRegions) {
529 auto cb_node = GetCBState(commandBuffer);
530 auto src_image_state = GetImageState(srcImage);
531 auto dst_image_state = GetImageState(dstImage);
532
533 // Update bindings between images and cmd buffer
534 AddCommandBufferBindingImage(cb_node, src_image_state);
535 AddCommandBufferBindingImage(cb_node, dst_image_state);
536}
537
Jeff Leger178b1e52020-10-05 12:22:23 -0400538void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
539 const VkResolveImageInfo2KHR *pResolveImageInfo) {
540 auto cb_node = GetCBState(commandBuffer);
541 auto src_image_state = GetImageState(pResolveImageInfo->srcImage);
542 auto dst_image_state = GetImageState(pResolveImageInfo->dstImage);
543
544 // Update bindings between images and cmd buffer
545 AddCommandBufferBindingImage(cb_node, src_image_state);
546 AddCommandBufferBindingImage(cb_node, dst_image_state);
547}
548
locke-lunargd556cc32019-09-17 01:21:23 -0600549void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
550 VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
551 uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
552 auto cb_node = GetCBState(commandBuffer);
553 auto src_image_state = GetImageState(srcImage);
554 auto dst_image_state = GetImageState(dstImage);
555
556 // Update bindings between images and cmd buffer
557 AddCommandBufferBindingImage(cb_node, src_image_state);
558 AddCommandBufferBindingImage(cb_node, dst_image_state);
559}
560
Jeff Leger178b1e52020-10-05 12:22:23 -0400561void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
562 const VkBlitImageInfo2KHR *pBlitImageInfo) {
563 auto cb_node = GetCBState(commandBuffer);
564 auto src_image_state = GetImageState(pBlitImageInfo->srcImage);
565 auto dst_image_state = GetImageState(pBlitImageInfo->dstImage);
566
567 // Update bindings between images and cmd buffer
568 AddCommandBufferBindingImage(cb_node, src_image_state);
569 AddCommandBufferBindingImage(cb_node, dst_image_state);
570}
571
locke-lunargd556cc32019-09-17 01:21:23 -0600572void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
573 const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
574 VkResult result) {
575 if (result != VK_SUCCESS) return;
576 // TODO : This doesn't create deep copy of pQueueFamilyIndices so need to fix that if/when we want that data to be valid
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500577 auto buffer_state = std::make_shared<BUFFER_STATE>(*pBuffer, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -0600578
sfricke-samsung013f1ef2020-05-14 22:56:20 -0700579 if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
580 RecordCreateBufferANDROID(pCreateInfo, buffer_state.get());
581 }
locke-lunargd556cc32019-09-17 01:21:23 -0600582 // Get a set of requirements in the case the app does not
sfricke-samsungad90e722020-07-08 20:54:24 -0700583 DispatchGetBufferMemoryRequirements(device, *pBuffer, &buffer_state->requirements);
locke-lunargd556cc32019-09-17 01:21:23 -0600584
sfricke-samsungedce77a2020-07-03 22:35:13 -0700585 buffer_state->unprotected = ((pCreateInfo->flags & VK_BUFFER_CREATE_PROTECTED_BIT) == 0);
586
locke-lunargd556cc32019-09-17 01:21:23 -0600587 bufferMap.insert(std::make_pair(*pBuffer, std::move(buffer_state)));
588}
589
590void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
591 const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
592 VkResult result) {
593 if (result != VK_SUCCESS) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500594 auto buffer_state = GetBufferShared(pCreateInfo->buffer);
locke-lunarg25b6c352020-08-06 17:44:18 -0600595 auto buffer_view_state = std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo);
596
597 VkFormatProperties format_properties;
598 DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
599 buffer_view_state->format_features = format_properties.bufferFeatures;
600
601 bufferViewMap.insert(std::make_pair(*pView, std::move(buffer_view_state)));
locke-lunargd556cc32019-09-17 01:21:23 -0600602}
603
604void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
605 const VkAllocationCallbacks *pAllocator, VkImageView *pView,
606 VkResult result) {
607 if (result != VK_SUCCESS) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500608 auto image_state = GetImageShared(pCreateInfo->image);
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700609 auto image_view_state = std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo);
610
611 // Add feature support according to Image View Format Features (vkspec.html#resources-image-view-format-features)
612 const VkImageTiling image_tiling = image_state->createInfo.tiling;
613 const VkFormat image_view_format = pCreateInfo->format;
614 if (image_state->has_ahb_format == true) {
615 // The ImageView uses same Image's format feature since they share same AHB
616 image_view_state->format_features = image_state->format_features;
617 } else if (image_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
618 // Parameter validation should catch if this is used without VK_EXT_image_drm_format_modifier
619 assert(device_extensions.vk_ext_image_drm_format_modifier);
620 VkImageDrmFormatModifierPropertiesEXT drm_format_properties = {VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
621 nullptr};
622 DispatchGetImageDrmFormatModifierPropertiesEXT(device, image_state->image, &drm_format_properties);
623
624 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2, nullptr};
625 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
626 nullptr};
627 format_properties_2.pNext = (void *)&drm_properties_list;
628 DispatchGetPhysicalDeviceFormatProperties2(physical_device, image_view_format, &format_properties_2);
629
630 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
Lionel Landwerlin94f1ce32020-07-02 17:39:31 +0300631 if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700632 image_view_state->format_features |=
633 drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
Lionel Landwerlin94f1ce32020-07-02 17:39:31 +0300634 break;
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700635 }
636 }
637 } else {
638 VkFormatProperties format_properties;
639 DispatchGetPhysicalDeviceFormatProperties(physical_device, image_view_format, &format_properties);
640 image_view_state->format_features = (image_tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures
641 : format_properties.optimalTilingFeatures;
642 }
643
locke-lunarg9939d4b2020-10-26 20:11:08 -0600644 // filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
645 image_view_state->filter_cubic_props = lvl_init_struct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
646 if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
647 auto imageview_format_info = lvl_init_struct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
648 imageview_format_info.imageViewType = pCreateInfo->viewType;
649 auto image_format_info = lvl_init_struct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
650 image_format_info.type = image_state->createInfo.imageType;
651 image_format_info.format = image_state->createInfo.format;
652 image_format_info.tiling = image_state->createInfo.tiling;
653 image_format_info.usage = image_state->createInfo.usage;
654 image_format_info.flags = image_state->createInfo.flags;
655
656 auto image_format_properties = lvl_init_struct<VkImageFormatProperties2>(&image_view_state->filter_cubic_props);
657
658 DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
659 }
Spencer Fricke6bba8c72020-04-06 07:41:21 -0700660 imageViewMap.insert(std::make_pair(*pView, std::move(image_view_state)));
locke-lunargd556cc32019-09-17 01:21:23 -0600661}
662
663void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
664 uint32_t regionCount, const VkBufferCopy *pRegions) {
665 auto cb_node = GetCBState(commandBuffer);
666 auto src_buffer_state = GetBufferState(srcBuffer);
667 auto dst_buffer_state = GetBufferState(dstBuffer);
668
669 // Update bindings between buffers and cmd buffer
670 AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
671 AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
672}
673
Jeff Leger178b1e52020-10-05 12:22:23 -0400674void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
675 const VkCopyBufferInfo2KHR *pCopyBufferInfos) {
676 auto cb_node = GetCBState(commandBuffer);
677 auto src_buffer_state = GetBufferState(pCopyBufferInfos->srcBuffer);
678 auto dst_buffer_state = GetBufferState(pCopyBufferInfos->dstBuffer);
679
680 // Update bindings between buffers and cmd buffer
681 AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
682 AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
683}
684
locke-lunargd556cc32019-09-17 01:21:23 -0600685void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
686 const VkAllocationCallbacks *pAllocator) {
687 IMAGE_VIEW_STATE *image_view_state = GetImageViewState(imageView);
688 if (!image_view_state) return;
689 const VulkanTypedHandle obj_struct(imageView, kVulkanObjectTypeImageView);
690
691 // Any bound cmd buffers are now invalid
692 InvalidateCommandBuffers(image_view_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500693 image_view_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -0600694 imageViewMap.erase(imageView);
695}
696
697void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
698 if (!buffer) return;
699 auto buffer_state = GetBufferState(buffer);
700 const VulkanTypedHandle obj_struct(buffer, kVulkanObjectTypeBuffer);
701
702 InvalidateCommandBuffers(buffer_state->cb_bindings, obj_struct);
703 for (auto mem_binding : buffer_state->GetBoundMemory()) {
locke-lunargcf04d582019-11-26 00:31:50 -0700704 RemoveBufferMemoryRange(buffer, mem_binding);
locke-lunargd556cc32019-09-17 01:21:23 -0600705 }
706 ClearMemoryObjectBindings(obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500707 buffer_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -0600708 bufferMap.erase(buffer_state->buffer);
709}
710
711void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
712 const VkAllocationCallbacks *pAllocator) {
713 if (!bufferView) return;
714 auto buffer_view_state = GetBufferViewState(bufferView);
715 const VulkanTypedHandle obj_struct(bufferView, kVulkanObjectTypeBufferView);
716
717 // Any bound cmd buffers are now invalid
718 InvalidateCommandBuffers(buffer_view_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500719 buffer_view_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -0600720 bufferViewMap.erase(bufferView);
721}
722
723void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
724 VkDeviceSize size, uint32_t data) {
725 auto cb_node = GetCBState(commandBuffer);
726 auto buffer_state = GetBufferState(dstBuffer);
727 // Update bindings between buffer and cmd buffer
728 AddCommandBufferBindingBuffer(cb_node, buffer_state);
729}
730
731void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
732 VkImageLayout srcImageLayout, VkBuffer dstBuffer,
733 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
734 auto cb_node = GetCBState(commandBuffer);
735 auto src_image_state = GetImageState(srcImage);
736 auto dst_buffer_state = GetBufferState(dstBuffer);
737
738 // Update bindings between buffer/image and cmd buffer
739 AddCommandBufferBindingImage(cb_node, src_image_state);
740 AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
741}
742
Jeff Leger178b1e52020-10-05 12:22:23 -0400743void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
744 const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
745 auto cb_node = GetCBState(commandBuffer);
746 auto src_image_state = GetImageState(pCopyImageToBufferInfo->srcImage);
747 auto dst_buffer_state = GetBufferState(pCopyImageToBufferInfo->dstBuffer);
748
749 // Update bindings between buffer/image and cmd buffer
750 AddCommandBufferBindingImage(cb_node, src_image_state);
751 AddCommandBufferBindingBuffer(cb_node, dst_buffer_state);
752}
753
locke-lunargd556cc32019-09-17 01:21:23 -0600754void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
755 VkImageLayout dstImageLayout, uint32_t regionCount,
756 const VkBufferImageCopy *pRegions) {
757 auto cb_node = GetCBState(commandBuffer);
758 auto src_buffer_state = GetBufferState(srcBuffer);
759 auto dst_image_state = GetImageState(dstImage);
760
761 AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
762 AddCommandBufferBindingImage(cb_node, dst_image_state);
763}
764
Jeff Leger178b1e52020-10-05 12:22:23 -0400765void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
766 const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
767 auto cb_node = GetCBState(commandBuffer);
768 auto src_buffer_state = GetBufferState(pCopyBufferToImageInfo->srcBuffer);
769 auto dst_image_state = GetImageState(pCopyBufferToImageInfo->dstImage);
770
771 AddCommandBufferBindingBuffer(cb_node, src_buffer_state);
772 AddCommandBufferBindingImage(cb_node, dst_image_state);
773}
774
locke-lunargd556cc32019-09-17 01:21:23 -0600775// Get the image viewstate for a given framebuffer attachment
locke-lunargfc78e932020-11-19 17:06:24 -0700776IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index,
777 const CMD_BUFFER_STATE *primary_cb) {
778 if (primary_cb) {
779 assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size()));
780 return primary_cb->active_attachments->at(index);
Lionel Landwerlin484d10f2020-04-24 01:34:47 +0300781 }
locke-lunargfc78e932020-11-19 17:06:24 -0700782 assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size()));
783 return cb->active_attachments->at(index);
locke-lunargd556cc32019-09-17 01:21:23 -0600784}
785
786// Get the image viewstate for a given framebuffer attachment
locke-lunargfc78e932020-11-19 17:06:24 -0700787const IMAGE_VIEW_STATE *ValidationStateTracker::GetActiveAttachmentImageViewState(const CMD_BUFFER_STATE *cb, uint32_t index,
788 const CMD_BUFFER_STATE *primary_cb) const {
789 if (primary_cb) {
790 assert(primary_cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < primary_cb->active_attachments->size()));
791 return primary_cb->active_attachments->at(index);
Lionel Landwerlin484d10f2020-04-24 01:34:47 +0300792 }
locke-lunargfc78e932020-11-19 17:06:24 -0700793 assert(cb->active_attachments && index != VK_ATTACHMENT_UNUSED && (index < cb->active_attachments->size()));
794 return cb->active_attachments->at(index);
locke-lunargd556cc32019-09-17 01:21:23 -0600795}
796
797void ValidationStateTracker::AddAliasingImage(IMAGE_STATE *image_state) {
locke-lunargd556cc32019-09-17 01:21:23 -0600798 std::unordered_set<VkImage> *bound_images = nullptr;
799
locke-lunargb3584732019-10-28 20:18:36 -0600800 if (image_state->bind_swapchain) {
801 auto swapchain_state = GetSwapchainState(image_state->bind_swapchain);
locke-lunargd556cc32019-09-17 01:21:23 -0600802 if (swapchain_state) {
locke-lunargb3584732019-10-28 20:18:36 -0600803 bound_images = &swapchain_state->images[image_state->bind_swapchain_imageIndex].bound_images;
locke-lunargd556cc32019-09-17 01:21:23 -0600804 }
805 } else {
locke-lunargcf04d582019-11-26 00:31:50 -0700806 if (image_state->binding.mem_state) {
807 bound_images = &image_state->binding.mem_state->bound_images;
locke-lunargd556cc32019-09-17 01:21:23 -0600808 }
809 }
810
811 if (bound_images) {
812 for (const auto &handle : *bound_images) {
813 if (handle != image_state->image) {
814 auto is = GetImageState(handle);
815 if (is && is->IsCompatibleAliasing(image_state)) {
816 auto inserted = is->aliasing_images.emplace(image_state->image);
817 if (inserted.second) {
818 image_state->aliasing_images.emplace(handle);
819 }
820 }
821 }
822 }
823 }
824}
825
826void ValidationStateTracker::RemoveAliasingImage(IMAGE_STATE *image_state) {
827 for (const auto &image : image_state->aliasing_images) {
828 auto is = GetImageState(image);
829 if (is) {
830 is->aliasing_images.erase(image_state->image);
831 }
832 }
833 image_state->aliasing_images.clear();
834}
835
836void ValidationStateTracker::RemoveAliasingImages(const std::unordered_set<VkImage> &bound_images) {
837 // This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole
838 // reference. It doesn't need two ways clear.
839 for (const auto &handle : bound_images) {
840 auto is = GetImageState(handle);
841 if (is) {
842 is->aliasing_images.clear();
843 }
844 }
845}
846
Jeff Bolz310775c2019-10-09 00:46:33 -0500847const EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) const {
848 auto it = eventMap.find(event);
849 if (it == eventMap.end()) {
850 return nullptr;
851 }
852 return &it->second;
853}
854
locke-lunargd556cc32019-09-17 01:21:23 -0600855EVENT_STATE *ValidationStateTracker::GetEventState(VkEvent event) {
856 auto it = eventMap.find(event);
857 if (it == eventMap.end()) {
858 return nullptr;
859 }
860 return &it->second;
861}
862
863const QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) const {
864 auto it = queueMap.find(queue);
865 if (it == queueMap.cend()) {
866 return nullptr;
867 }
868 return &it->second;
869}
870
871QUEUE_STATE *ValidationStateTracker::GetQueueState(VkQueue queue) {
872 auto it = queueMap.find(queue);
873 if (it == queueMap.end()) {
874 return nullptr;
875 }
876 return &it->second;
877}
878
879const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) const {
880 auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map);
881 auto it = phys_dev_map->find(phys);
882 if (it == phys_dev_map->end()) {
883 return nullptr;
884 }
885 return &it->second;
886}
887
888PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState(VkPhysicalDevice phys) {
889 auto *phys_dev_map = ((physical_device_map.size() > 0) ? &physical_device_map : &instance_state->physical_device_map);
890 auto it = phys_dev_map->find(phys);
891 if (it == phys_dev_map->end()) {
892 return nullptr;
893 }
894 return &it->second;
895}
896
897PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() { return physical_device_state; }
898const PHYSICAL_DEVICE_STATE *ValidationStateTracker::GetPhysicalDeviceState() const { return physical_device_state; }
899
900// Return ptr to memory binding for given handle of specified type
901template <typename State, typename Result>
902static Result GetObjectMemBindingImpl(State state, const VulkanTypedHandle &typed_handle) {
903 switch (typed_handle.type) {
904 case kVulkanObjectTypeImage:
905 return state->GetImageState(typed_handle.Cast<VkImage>());
906 case kVulkanObjectTypeBuffer:
907 return state->GetBufferState(typed_handle.Cast<VkBuffer>());
908 case kVulkanObjectTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -0700909 return state->GetAccelerationStructureStateNV(typed_handle.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -0600910 default:
911 break;
912 }
913 return nullptr;
914}
915
916const BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) const {
917 return GetObjectMemBindingImpl<const ValidationStateTracker *, const BINDABLE *>(this, typed_handle);
918}
919
920BINDABLE *ValidationStateTracker::GetObjectMemBinding(const VulkanTypedHandle &typed_handle) {
921 return GetObjectMemBindingImpl<ValidationStateTracker *, BINDABLE *>(this, typed_handle);
922}
923
924void ValidationStateTracker::AddMemObjInfo(void *object, const VkDeviceMemory mem, const VkMemoryAllocateInfo *pAllocateInfo) {
925 assert(object != NULL);
926
John Zulauf79952712020-04-07 11:25:54 -0600927 auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
928 memObjMap[mem] = std::make_shared<DEVICE_MEMORY_STATE>(object, mem, pAllocateInfo, fake_address);
Jeff Bolze7fc67b2019-10-04 12:29:31 -0500929 auto mem_info = memObjMap[mem].get();
locke-lunargd556cc32019-09-17 01:21:23 -0600930
Mike Schuchardt2df08912020-12-15 16:28:09 -0800931 auto dedicated = lvl_find_in_chain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -0600932 if (dedicated) {
933 mem_info->is_dedicated = true;
934 mem_info->dedicated_buffer = dedicated->buffer;
935 mem_info->dedicated_image = dedicated->image;
936 }
937 auto export_info = lvl_find_in_chain<VkExportMemoryAllocateInfo>(pAllocateInfo->pNext);
938 if (export_info) {
939 mem_info->is_export = true;
940 mem_info->export_handle_type_flags = export_info->handleTypes;
941 }
sfricke-samsung23068272020-06-21 14:49:51 -0700942
Mark Lobodzinski7bda6ed2020-07-24 09:57:38 -0600943 auto alloc_flags = lvl_find_in_chain<VkMemoryAllocateFlagsInfo>(pAllocateInfo->pNext);
944 if (alloc_flags) {
945 auto dev_mask = alloc_flags->deviceMask;
946 if ((dev_mask != 0) && (dev_mask & (dev_mask - 1))) {
947 mem_info->multi_instance = true;
948 }
949 }
950 auto heap_index = phys_dev_mem_props.memoryTypes[mem_info->alloc_info.memoryTypeIndex].heapIndex;
Tony-LunarGb399fb02020-08-06 14:20:59 -0600951 mem_info->multi_instance |= (((phys_dev_mem_props.memoryHeaps[heap_index].flags & VK_MEMORY_HEAP_MULTI_INSTANCE_BIT) != 0) &&
952 physical_device_count > 1);
Mark Lobodzinski7bda6ed2020-07-24 09:57:38 -0600953
sfricke-samsung23068272020-06-21 14:49:51 -0700954 // Assumes validation already for only a single import operation in the pNext
955#ifdef VK_USE_PLATFORM_WIN32_KHR
956 auto win32_import = lvl_find_in_chain<VkImportMemoryWin32HandleInfoKHR>(pAllocateInfo->pNext);
957 if (win32_import) {
958 mem_info->is_import = true;
959 mem_info->import_handle_type_flags = win32_import->handleType;
960 }
961#endif
962 auto fd_import = lvl_find_in_chain<VkImportMemoryFdInfoKHR>(pAllocateInfo->pNext);
963 if (fd_import) {
964 mem_info->is_import = true;
965 mem_info->import_handle_type_flags = fd_import->handleType;
966 }
967 auto host_pointer_import = lvl_find_in_chain<VkImportMemoryHostPointerInfoEXT>(pAllocateInfo->pNext);
968 if (host_pointer_import) {
969 mem_info->is_import = true;
970 mem_info->import_handle_type_flags = host_pointer_import->handleType;
971 }
972#ifdef VK_USE_PLATFORM_ANDROID_KHR
973 // AHB Import doesn't have handle in the pNext struct
974 // It should be assumed that all imported AHB can only have the same, single handleType
975 auto ahb_import = lvl_find_in_chain<VkImportAndroidHardwareBufferInfoANDROID>(pAllocateInfo->pNext);
976 if ((ahb_import) && (ahb_import->buffer != nullptr)) {
977 mem_info->is_import_ahb = true;
978 mem_info->is_import = true;
979 mem_info->import_handle_type_flags = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
980 }
sfricke-samsung98acb882020-11-03 19:16:10 -0800981#endif // VK_USE_PLATFORM_ANDROID_KHR
sfricke-samsungedce77a2020-07-03 22:35:13 -0700982
983 const VkMemoryType memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
984 mem_info->unprotected = ((memory_type.propertyFlags & VK_MEMORY_PROPERTY_PROTECTED_BIT) == 0);
locke-lunargd556cc32019-09-17 01:21:23 -0600985}
986
987// Create binding link between given sampler and command buffer node
988void ValidationStateTracker::AddCommandBufferBindingSampler(CMD_BUFFER_STATE *cb_node, SAMPLER_STATE *sampler_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -0600989 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -0600990 return;
991 }
Jeff Bolzadbfa852019-10-04 13:53:30 -0500992 AddCommandBufferBinding(sampler_state->cb_bindings,
993 VulkanTypedHandle(sampler_state->sampler, kVulkanObjectTypeSampler, sampler_state), cb_node);
locke-lunargd556cc32019-09-17 01:21:23 -0600994}
995
996// Create binding link between given image node and command buffer node
997void ValidationStateTracker::AddCommandBufferBindingImage(CMD_BUFFER_STATE *cb_node, IMAGE_STATE *image_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -0600998 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -0600999 return;
1000 }
1001 // Skip validation if this image was created through WSI
1002 if (image_state->create_from_swapchain == VK_NULL_HANDLE) {
1003 // First update cb binding for image
Jeff Bolzadbfa852019-10-04 13:53:30 -05001004 if (AddCommandBufferBinding(image_state->cb_bindings,
1005 VulkanTypedHandle(image_state->image, kVulkanObjectTypeImage, image_state), cb_node)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001006 // Now update CB binding in MemObj mini CB list
1007 for (auto mem_binding : image_state->GetBoundMemory()) {
locke-lunargcf04d582019-11-26 00:31:50 -07001008 // Now update CBInfo's Mem reference list
1009 AddCommandBufferBinding(mem_binding->cb_bindings,
1010 VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node);
locke-lunargd556cc32019-09-17 01:21:23 -06001011 }
1012 }
1013 }
1014}
1015
1016// Create binding link between given image view node and its image with command buffer node
1017void ValidationStateTracker::AddCommandBufferBindingImageView(CMD_BUFFER_STATE *cb_node, IMAGE_VIEW_STATE *view_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06001018 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -06001019 return;
1020 }
1021 // First add bindings for imageView
Jeff Bolzadbfa852019-10-04 13:53:30 -05001022 if (AddCommandBufferBinding(view_state->cb_bindings,
1023 VulkanTypedHandle(view_state->image_view, kVulkanObjectTypeImageView, view_state), cb_node)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001024 // Only need to continue if this is a new item
Jeff Bolzadbfa852019-10-04 13:53:30 -05001025 auto image_state = view_state->image_state.get();
locke-lunargd556cc32019-09-17 01:21:23 -06001026 // Add bindings for image within imageView
1027 if (image_state) {
1028 AddCommandBufferBindingImage(cb_node, image_state);
1029 }
1030 }
1031}
1032
1033// Create binding link between given buffer node and command buffer node
1034void ValidationStateTracker::AddCommandBufferBindingBuffer(CMD_BUFFER_STATE *cb_node, BUFFER_STATE *buffer_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06001035 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -06001036 return;
1037 }
1038 // First update cb binding for buffer
Jeff Bolzadbfa852019-10-04 13:53:30 -05001039 if (AddCommandBufferBinding(buffer_state->cb_bindings,
1040 VulkanTypedHandle(buffer_state->buffer, kVulkanObjectTypeBuffer, buffer_state), cb_node)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001041 // Now update CB binding in MemObj mini CB list
1042 for (auto mem_binding : buffer_state->GetBoundMemory()) {
locke-lunargcf04d582019-11-26 00:31:50 -07001043 // Now update CBInfo's Mem reference list
1044 AddCommandBufferBinding(mem_binding->cb_bindings,
1045 VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node);
locke-lunargd556cc32019-09-17 01:21:23 -06001046 }
1047 }
1048}
1049
1050// Create binding link between given buffer view node and its buffer with command buffer node
1051void ValidationStateTracker::AddCommandBufferBindingBufferView(CMD_BUFFER_STATE *cb_node, BUFFER_VIEW_STATE *view_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06001052 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -06001053 return;
1054 }
1055 // First add bindings for bufferView
Jeff Bolzadbfa852019-10-04 13:53:30 -05001056 if (AddCommandBufferBinding(view_state->cb_bindings,
1057 VulkanTypedHandle(view_state->buffer_view, kVulkanObjectTypeBufferView, view_state), cb_node)) {
1058 auto buffer_state = view_state->buffer_state.get();
locke-lunargd556cc32019-09-17 01:21:23 -06001059 // Add bindings for buffer within bufferView
1060 if (buffer_state) {
1061 AddCommandBufferBindingBuffer(cb_node, buffer_state);
1062 }
1063 }
1064}
1065
1066// Create binding link between given acceleration structure and command buffer node
1067void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node,
1068 ACCELERATION_STRUCTURE_STATE *as_state) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06001069 if (disabled[command_buffer_state]) {
locke-lunargd556cc32019-09-17 01:21:23 -06001070 return;
1071 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05001072 if (AddCommandBufferBinding(
1073 as_state->cb_bindings,
1074 VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureNV, as_state), cb_node)) {
locke-lunargd556cc32019-09-17 01:21:23 -06001075 // Now update CB binding in MemObj mini CB list
1076 for (auto mem_binding : as_state->GetBoundMemory()) {
locke-lunargcf04d582019-11-26 00:31:50 -07001077 // Now update CBInfo's Mem reference list
1078 AddCommandBufferBinding(mem_binding->cb_bindings,
1079 VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node);
locke-lunargd556cc32019-09-17 01:21:23 -06001080 }
1081 }
1082}
1083
sourav parmarcd5fb182020-07-17 12:58:44 -07001084// Create binding link between given acceleration structure and command buffer node
1085void ValidationStateTracker::AddCommandBufferBindingAccelerationStructure(CMD_BUFFER_STATE *cb_node,
1086 ACCELERATION_STRUCTURE_STATE_KHR *as_state) {
1087 if (disabled[command_buffer_state]) {
1088 return;
1089 }
1090 if (AddCommandBufferBinding(
1091 as_state->cb_bindings,
1092 VulkanTypedHandle(as_state->acceleration_structure, kVulkanObjectTypeAccelerationStructureKHR, as_state), cb_node)) {
1093 // Now update CB binding in MemObj mini CB list
1094 for (auto mem_binding : as_state->GetBoundMemory()) {
1095 // Now update CBInfo's Mem reference list
1096 AddCommandBufferBinding(mem_binding->cb_bindings,
1097 VulkanTypedHandle(mem_binding->mem, kVulkanObjectTypeDeviceMemory, mem_binding), cb_node);
1098 }
1099 }
1100}
1101
locke-lunargd556cc32019-09-17 01:21:23 -06001102// Clear a single object binding from given memory object
locke-lunarg5f59e782019-12-19 10:32:23 -07001103void ValidationStateTracker::ClearMemoryObjectBinding(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) {
locke-lunargd556cc32019-09-17 01:21:23 -06001104 // This obj is bound to a memory object. Remove the reference to this object in that memory object's list
1105 if (mem_info) {
1106 mem_info->obj_bindings.erase(typed_handle);
1107 }
1108}
1109
1110// ClearMemoryObjectBindings clears the binding of objects to memory
1111// For the given object it pulls the memory bindings and makes sure that the bindings
1112// no longer refer to the object being cleared. This occurs when objects are destroyed.
1113void ValidationStateTracker::ClearMemoryObjectBindings(const VulkanTypedHandle &typed_handle) {
1114 BINDABLE *mem_binding = GetObjectMemBinding(typed_handle);
1115 if (mem_binding) {
1116 if (!mem_binding->sparse) {
locke-lunarg5f59e782019-12-19 10:32:23 -07001117 ClearMemoryObjectBinding(typed_handle, mem_binding->binding.mem_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06001118 } else { // Sparse, clear all bindings
1119 for (auto &sparse_mem_binding : mem_binding->sparse_bindings) {
locke-lunarg5f59e782019-12-19 10:32:23 -07001120 ClearMemoryObjectBinding(typed_handle, sparse_mem_binding.mem_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06001121 }
1122 }
1123 }
1124}
1125
1126// SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object.
1127// Corresponding valid usage checks are in ValidateSetMemBinding().
1128void ValidationStateTracker::SetMemBinding(VkDeviceMemory mem, BINDABLE *mem_binding, VkDeviceSize memory_offset,
1129 const VulkanTypedHandle &typed_handle) {
1130 assert(mem_binding);
locke-lunargd556cc32019-09-17 01:21:23 -06001131
1132 if (mem != VK_NULL_HANDLE) {
locke-lunargcf04d582019-11-26 00:31:50 -07001133 mem_binding->binding.mem_state = GetShared<DEVICE_MEMORY_STATE>(mem);
1134 if (mem_binding->binding.mem_state) {
locke-lunarg5f59e782019-12-19 10:32:23 -07001135 mem_binding->binding.offset = memory_offset;
1136 mem_binding->binding.size = mem_binding->requirements.size;
locke-lunargcf04d582019-11-26 00:31:50 -07001137 mem_binding->binding.mem_state->obj_bindings.insert(typed_handle);
locke-lunargd556cc32019-09-17 01:21:23 -06001138 // For image objects, make sure default memory state is correctly set
1139 // TODO : What's the best/correct way to handle this?
1140 if (kVulkanObjectTypeImage == typed_handle.type) {
1141 auto const image_state = reinterpret_cast<const IMAGE_STATE *>(mem_binding);
1142 if (image_state) {
1143 VkImageCreateInfo ici = image_state->createInfo;
1144 if (ici.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
1145 // TODO:: More memory state transition stuff.
1146 }
1147 }
1148 }
locke-lunargcf04d582019-11-26 00:31:50 -07001149 mem_binding->UpdateBoundMemorySet(); // force recreation of cached set
locke-lunargd556cc32019-09-17 01:21:23 -06001150 }
1151 }
1152}
1153
1154// For NULL mem case, clear any previous binding Else...
1155// Make sure given object is in its object map
1156// IF a previous binding existed, update binding
1157// Add reference from objectInfo to memoryInfo
1158// Add reference off of object's binding info
1159// Return VK_TRUE if addition is successful, VK_FALSE otherwise
locke-lunargcf04d582019-11-26 00:31:50 -07001160bool ValidationStateTracker::SetSparseMemBinding(const VkDeviceMemory mem, const VkDeviceSize mem_offset,
1161 const VkDeviceSize mem_size, const VulkanTypedHandle &typed_handle) {
locke-lunargd556cc32019-09-17 01:21:23 -06001162 bool skip = VK_FALSE;
1163 // Handle NULL case separately, just clear previous binding & decrement reference
locke-lunargcf04d582019-11-26 00:31:50 -07001164 if (mem == VK_NULL_HANDLE) {
locke-lunargd556cc32019-09-17 01:21:23 -06001165 // TODO : This should cause the range of the resource to be unbound according to spec
1166 } else {
1167 BINDABLE *mem_binding = GetObjectMemBinding(typed_handle);
1168 assert(mem_binding);
1169 if (mem_binding) { // Invalid handles are reported by object tracker, but Get returns NULL for them, so avoid SEGV here
1170 assert(mem_binding->sparse);
locke-lunargcf04d582019-11-26 00:31:50 -07001171 MEM_BINDING binding = {GetShared<DEVICE_MEMORY_STATE>(mem), mem_offset, mem_size};
1172 if (binding.mem_state) {
1173 binding.mem_state->obj_bindings.insert(typed_handle);
locke-lunargd556cc32019-09-17 01:21:23 -06001174 // Need to set mem binding for this object
1175 mem_binding->sparse_bindings.insert(binding);
1176 mem_binding->UpdateBoundMemorySet();
1177 }
1178 }
1179 }
1180 return skip;
1181}
1182
locke-lunarg540b2252020-08-03 13:23:36 -06001183void ValidationStateTracker::UpdateDrawState(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point,
1184 const char *function) {
locke-lunargb8d7a7a2020-10-25 16:01:52 -06001185 const auto lv_bind_point = ConvertToLvlBindPoint(bind_point);
1186 auto &state = cb_state->lastBound[lv_bind_point];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001187 PIPELINE_STATE *pipe = state.pipeline_state;
locke-lunargd556cc32019-09-17 01:21:23 -06001188 if (VK_NULL_HANDLE != state.pipeline_layout) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001189 for (const auto &set_binding_pair : pipe->active_slots) {
1190 uint32_t set_index = set_binding_pair.first;
locke-lunargd556cc32019-09-17 01:21:23 -06001191 // Pull the set node
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001192 cvdescriptorset::DescriptorSet *descriptor_set = state.per_set[set_index].bound_descriptor_set;
locke-lunargd556cc32019-09-17 01:21:23 -06001193
Tony-LunarG77822802020-05-28 16:35:46 -06001194 // For the "bindless" style resource usage with many descriptors, need to optimize command <-> descriptor binding
locke-lunargd556cc32019-09-17 01:21:23 -06001195
Tony-LunarG77822802020-05-28 16:35:46 -06001196 // TODO: If recreating the reduced_map here shows up in profilinging, need to find a way of sharing with the
1197 // Validate pass. Though in the case of "many" descriptors, typically the descriptor count >> binding count
1198 cvdescriptorset::PrefilterBindRequestMap reduced_map(*descriptor_set, set_binding_pair.second);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001199 const auto &binding_req_map = reduced_map.FilteredMap(*cb_state, *pipe);
Tony-LunarG77822802020-05-28 16:35:46 -06001200
1201 if (reduced_map.IsManyDescriptors()) {
1202 // Only update validate binding tags if we meet the "many" criteria in the Prefilter class
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001203 descriptor_set->UpdateValidationCache(*cb_state, *pipe, binding_req_map);
Tony-LunarG77822802020-05-28 16:35:46 -06001204 }
1205
1206 // We can skip updating the state if "nothing" has changed since the last validation.
1207 // See CoreChecks::ValidateCmdBufDrawState for more details.
1208 bool descriptor_set_changed =
1209 !reduced_map.IsManyDescriptors() ||
1210 // Update if descriptor set (or contents) has changed
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001211 state.per_set[set_index].validated_set != descriptor_set ||
1212 state.per_set[set_index].validated_set_change_count != descriptor_set->GetChangeCount() ||
Tony-LunarG77822802020-05-28 16:35:46 -06001213 (!disabled[image_layout_validation] &&
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001214 state.per_set[set_index].validated_set_image_layout_change_count != cb_state->image_layout_change_count);
Tony-LunarG77822802020-05-28 16:35:46 -06001215 bool need_update = descriptor_set_changed ||
1216 // Update if previous bindingReqMap doesn't include new bindingReqMap
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001217 !std::includes(state.per_set[set_index].validated_set_binding_req_map.begin(),
1218 state.per_set[set_index].validated_set_binding_req_map.end(), binding_req_map.begin(),
Tony-LunarG77822802020-05-28 16:35:46 -06001219 binding_req_map.end());
1220
1221 if (need_update) {
1222 // Bind this set and its active descriptor resources to the command buffer
1223 if (!descriptor_set_changed && reduced_map.IsManyDescriptors()) {
1224 // Only record the bindings that haven't already been recorded
1225 BindingReqMap delta_reqs;
1226 std::set_difference(binding_req_map.begin(), binding_req_map.end(),
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001227 state.per_set[set_index].validated_set_binding_req_map.begin(),
1228 state.per_set[set_index].validated_set_binding_req_map.end(),
Tony-LunarG77822802020-05-28 16:35:46 -06001229 std::inserter(delta_reqs, delta_reqs.begin()));
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001230 descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pipe, delta_reqs, function);
Tony-LunarG77822802020-05-28 16:35:46 -06001231 } else {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001232 descriptor_set->UpdateDrawState(this, cb_state, cmd_type, pipe, binding_req_map, function);
locke-lunargd556cc32019-09-17 01:21:23 -06001233 }
1234
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001235 state.per_set[set_index].validated_set = descriptor_set;
1236 state.per_set[set_index].validated_set_change_count = descriptor_set->GetChangeCount();
1237 state.per_set[set_index].validated_set_image_layout_change_count = cb_state->image_layout_change_count;
Tony-LunarG77822802020-05-28 16:35:46 -06001238 if (reduced_map.IsManyDescriptors()) {
1239 // Check whether old == new before assigning, the equality check is much cheaper than
1240 // freeing and reallocating the map.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001241 if (state.per_set[set_index].validated_set_binding_req_map != set_binding_pair.second) {
1242 state.per_set[set_index].validated_set_binding_req_map = set_binding_pair.second;
Jeff Bolz56308942019-10-06 22:05:23 -05001243 }
Tony-LunarG77822802020-05-28 16:35:46 -06001244 } else {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001245 state.per_set[set_index].validated_set_binding_req_map = BindingReqMap();
locke-lunargd556cc32019-09-17 01:21:23 -06001246 }
1247 }
1248 }
1249 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001250 if (!pipe->vertex_binding_descriptions_.empty()) {
locke-lunargd556cc32019-09-17 01:21:23 -06001251 cb_state->vertex_buffer_used = true;
1252 }
1253}
1254
1255// Remove set from setMap and delete the set
1256void ValidationStateTracker::FreeDescriptorSet(cvdescriptorset::DescriptorSet *descriptor_set) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05001257 descriptor_set->destroyed = true;
Jeff Bolzadbfa852019-10-04 13:53:30 -05001258 const VulkanTypedHandle obj_struct(descriptor_set->GetSet(), kVulkanObjectTypeDescriptorSet);
Jeff Bolz41a1ced2019-10-11 11:40:49 -05001259 // Any bound cmd buffers are now invalid
Jeff Bolzadbfa852019-10-04 13:53:30 -05001260 InvalidateCommandBuffers(descriptor_set->cb_bindings, obj_struct);
Jeff Bolz41a1ced2019-10-11 11:40:49 -05001261
locke-lunargd556cc32019-09-17 01:21:23 -06001262 setMap.erase(descriptor_set->GetSet());
1263}
1264
1265// Free all DS Pools including their Sets & related sub-structs
1266// NOTE : Calls to this function should be wrapped in mutex
1267void ValidationStateTracker::DeleteDescriptorSetPools() {
1268 for (auto ii = descriptorPoolMap.begin(); ii != descriptorPoolMap.end();) {
1269 // Remove this pools' sets from setMap and delete them
1270 for (auto ds : ii->second->sets) {
1271 FreeDescriptorSet(ds);
1272 }
1273 ii->second->sets.clear();
1274 ii = descriptorPoolMap.erase(ii);
1275 }
1276}
1277
1278// For given object struct return a ptr of BASE_NODE type for its wrapping struct
1279BASE_NODE *ValidationStateTracker::GetStateStructPtrFromObject(const VulkanTypedHandle &object_struct) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05001280 if (object_struct.node) {
1281#ifdef _DEBUG
1282 // assert that lookup would find the same object
1283 VulkanTypedHandle other = object_struct;
1284 other.node = nullptr;
1285 assert(object_struct.node == GetStateStructPtrFromObject(other));
1286#endif
1287 return object_struct.node;
1288 }
locke-lunargd556cc32019-09-17 01:21:23 -06001289 BASE_NODE *base_ptr = nullptr;
1290 switch (object_struct.type) {
1291 case kVulkanObjectTypeDescriptorSet: {
1292 base_ptr = GetSetNode(object_struct.Cast<VkDescriptorSet>());
1293 break;
1294 }
1295 case kVulkanObjectTypeSampler: {
1296 base_ptr = GetSamplerState(object_struct.Cast<VkSampler>());
1297 break;
1298 }
1299 case kVulkanObjectTypeQueryPool: {
1300 base_ptr = GetQueryPoolState(object_struct.Cast<VkQueryPool>());
1301 break;
1302 }
1303 case kVulkanObjectTypePipeline: {
1304 base_ptr = GetPipelineState(object_struct.Cast<VkPipeline>());
1305 break;
1306 }
1307 case kVulkanObjectTypeBuffer: {
1308 base_ptr = GetBufferState(object_struct.Cast<VkBuffer>());
1309 break;
1310 }
1311 case kVulkanObjectTypeBufferView: {
1312 base_ptr = GetBufferViewState(object_struct.Cast<VkBufferView>());
1313 break;
1314 }
1315 case kVulkanObjectTypeImage: {
1316 base_ptr = GetImageState(object_struct.Cast<VkImage>());
1317 break;
1318 }
1319 case kVulkanObjectTypeImageView: {
1320 base_ptr = GetImageViewState(object_struct.Cast<VkImageView>());
1321 break;
1322 }
1323 case kVulkanObjectTypeEvent: {
1324 base_ptr = GetEventState(object_struct.Cast<VkEvent>());
1325 break;
1326 }
1327 case kVulkanObjectTypeDescriptorPool: {
1328 base_ptr = GetDescriptorPoolState(object_struct.Cast<VkDescriptorPool>());
1329 break;
1330 }
1331 case kVulkanObjectTypeCommandPool: {
1332 base_ptr = GetCommandPoolState(object_struct.Cast<VkCommandPool>());
1333 break;
1334 }
1335 case kVulkanObjectTypeFramebuffer: {
1336 base_ptr = GetFramebufferState(object_struct.Cast<VkFramebuffer>());
1337 break;
1338 }
1339 case kVulkanObjectTypeRenderPass: {
1340 base_ptr = GetRenderPassState(object_struct.Cast<VkRenderPass>());
1341 break;
1342 }
1343 case kVulkanObjectTypeDeviceMemory: {
1344 base_ptr = GetDevMemState(object_struct.Cast<VkDeviceMemory>());
1345 break;
1346 }
1347 case kVulkanObjectTypeAccelerationStructureNV: {
sourav parmarcd5fb182020-07-17 12:58:44 -07001348 base_ptr = GetAccelerationStructureStateNV(object_struct.Cast<VkAccelerationStructureNV>());
1349 break;
1350 }
1351 case kVulkanObjectTypeAccelerationStructureKHR: {
1352 base_ptr = GetAccelerationStructureStateKHR(object_struct.Cast<VkAccelerationStructureKHR>());
locke-lunargd556cc32019-09-17 01:21:23 -06001353 break;
1354 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05001355 case kVulkanObjectTypeUnknown:
1356 // This can happen if an element of the object_bindings vector has been
1357 // zeroed out, after an object is destroyed.
1358 break;
locke-lunargd556cc32019-09-17 01:21:23 -06001359 default:
1360 // TODO : Any other objects to be handled here?
1361 assert(0);
1362 break;
1363 }
1364 return base_ptr;
1365}
1366
sfricke-samsungbf1a2ed2020-06-14 23:31:00 -07001367// Gets union of all features defined by Potential Format Features
1368// 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 -07001369VkFormatFeatureFlags ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
1370 VkFormatFeatureFlags format_features = 0;
1371
1372 if (format != VK_FORMAT_UNDEFINED) {
1373 VkFormatProperties format_properties;
1374 DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
1375 format_features |= format_properties.linearTilingFeatures;
1376 format_features |= format_properties.optimalTilingFeatures;
1377 if (device_extensions.vk_ext_image_drm_format_modifier) {
1378 // VK_KHR_get_physical_device_properties2 is required in this case
1379 VkFormatProperties2 format_properties_2 = {VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2};
1380 VkDrmFormatModifierPropertiesListEXT drm_properties_list = {VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT,
1381 nullptr};
1382 format_properties_2.pNext = (void *)&drm_properties_list;
1383 DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
1384 for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
1385 format_features |= drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
1386 }
1387 }
1388 }
1389
1390 return format_features;
1391}
1392
locke-lunargd556cc32019-09-17 01:21:23 -06001393// Tie the VulkanTypedHandle to the cmd buffer which includes:
1394// Add object_binding to cmd buffer
1395// Add cb_binding to object
Jeff Bolzadbfa852019-10-04 13:53:30 -05001396bool ValidationStateTracker::AddCommandBufferBinding(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_bindings,
locke-lunargd556cc32019-09-17 01:21:23 -06001397 const VulkanTypedHandle &obj, CMD_BUFFER_STATE *cb_node) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06001398 if (disabled[command_buffer_state]) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05001399 return false;
locke-lunargd556cc32019-09-17 01:21:23 -06001400 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05001401 // Insert the cb_binding with a default 'index' of -1. Then push the obj into the object_bindings
1402 // vector, and update cb_bindings[cb_node] with the index of that element of the vector.
1403 auto inserted = cb_bindings.insert({cb_node, -1});
1404 if (inserted.second) {
1405 cb_node->object_bindings.push_back(obj);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001406 inserted.first->second = static_cast<int>(cb_node->object_bindings.size()) - 1;
Jeff Bolzadbfa852019-10-04 13:53:30 -05001407 return true;
1408 }
1409 return false;
locke-lunargd556cc32019-09-17 01:21:23 -06001410}
1411
1412// For a given object, if cb_node is in that objects cb_bindings, remove cb_node
1413void ValidationStateTracker::RemoveCommandBufferBinding(VulkanTypedHandle const &object, CMD_BUFFER_STATE *cb_node) {
1414 BASE_NODE *base_obj = GetStateStructPtrFromObject(object);
1415 if (base_obj) base_obj->cb_bindings.erase(cb_node);
1416}
1417
1418// Reset the command buffer state
1419// Maintain the createInfo and set state to CB_NEW, but clear all other state
1420void ValidationStateTracker::ResetCommandBufferState(const VkCommandBuffer cb) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001421 CMD_BUFFER_STATE *cb_state = GetCBState(cb);
1422 if (cb_state) {
1423 cb_state->in_use.store(0);
locke-lunargd556cc32019-09-17 01:21:23 -06001424 // Reset CB state (note that createInfo is not cleared)
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001425 cb_state->commandBuffer = cb;
1426 memset(&cb_state->beginInfo, 0, sizeof(VkCommandBufferBeginInfo));
1427 memset(&cb_state->inheritanceInfo, 0, sizeof(VkCommandBufferInheritanceInfo));
1428 cb_state->hasDrawCmd = false;
1429 cb_state->hasTraceRaysCmd = false;
1430 cb_state->hasBuildAccelerationStructureCmd = false;
1431 cb_state->hasDispatchCmd = false;
1432 cb_state->state = CB_NEW;
1433 cb_state->commandCount = 0;
1434 cb_state->submitCount = 0;
1435 cb_state->image_layout_change_count = 1; // Start at 1. 0 is insert value for validation cache versions, s.t. new == dirty
1436 cb_state->status = 0;
1437 cb_state->static_status = 0;
1438 cb_state->viewportMask = 0;
1439 cb_state->viewportWithCountMask = 0;
1440 cb_state->viewportWithCountCount = 0;
1441 cb_state->scissorMask = 0;
1442 cb_state->scissorWithCountMask = 0;
1443 cb_state->primitiveTopology = VK_PRIMITIVE_TOPOLOGY_MAX_ENUM;
locke-lunargd556cc32019-09-17 01:21:23 -06001444
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001445 for (auto &item : cb_state->lastBound) {
locke-lunargb8d7a7a2020-10-25 16:01:52 -06001446 item.reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001447 }
1448
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001449 cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo();
1450 cb_state->activeRenderPass = nullptr;
1451 cb_state->active_attachments = nullptr;
1452 cb_state->active_subpasses = nullptr;
1453 cb_state->attachments_view_states.clear();
1454 cb_state->activeSubpassContents = VK_SUBPASS_CONTENTS_INLINE;
1455 cb_state->activeSubpass = 0;
1456 cb_state->broken_bindings.clear();
1457 cb_state->waitedEvents.clear();
1458 cb_state->events.clear();
1459 cb_state->writeEventsBeforeWait.clear();
1460 cb_state->activeQueries.clear();
1461 cb_state->startedQueries.clear();
1462 cb_state->image_layout_map.clear();
1463 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.clear();
1464 cb_state->vertex_buffer_used = false;
1465 cb_state->primaryCommandBuffer = VK_NULL_HANDLE;
locke-lunargd556cc32019-09-17 01:21:23 -06001466 // If secondary, invalidate any primary command buffer that may call us.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001467 if (cb_state->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
1468 InvalidateLinkedCommandBuffers(cb_state->linkedCommandBuffers, VulkanTypedHandle(cb, kVulkanObjectTypeCommandBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06001469 }
1470
1471 // Remove reverse command buffer links.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001472 for (auto sub_cb : cb_state->linkedCommandBuffers) {
1473 sub_cb->linkedCommandBuffers.erase(cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06001474 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001475 cb_state->linkedCommandBuffers.clear();
1476 cb_state->queue_submit_functions.clear();
1477 cb_state->cmd_execute_commands_functions.clear();
1478 cb_state->eventUpdates.clear();
1479 cb_state->queryUpdates.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001480
1481 // Remove object bindings
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001482 for (const auto &obj : cb_state->object_bindings) {
1483 RemoveCommandBufferBinding(obj, cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06001484 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001485 cb_state->object_bindings.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06001486 // Remove this cmdBuffer's reference from each FrameBuffer's CB ref list
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001487 for (auto framebuffer : cb_state->framebuffers) {
1488 framebuffer->cb_bindings.erase(cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06001489 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001490 cb_state->framebuffers.clear();
1491 cb_state->activeFramebuffer = VK_NULL_HANDLE;
1492 cb_state->index_buffer_binding.reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001493
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001494 cb_state->qfo_transfer_image_barriers.Reset();
1495 cb_state->qfo_transfer_buffer_barriers.Reset();
locke-lunargd556cc32019-09-17 01:21:23 -06001496
1497 // Clean up the label data
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001498 ResetCmdDebugUtilsLabel(report_data, cb_state->commandBuffer);
1499 cb_state->debug_label.Reset();
1500 cb_state->validate_descriptorsets_in_queuesubmit.clear();
Attilio Provenzano02859b22020-02-27 14:17:28 +00001501
1502 // Best practices info
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001503 cb_state->small_indexed_draw_call_count = 0;
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06001504
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001505 cb_state->transform_feedback_active = false;
locke-lunargd556cc32019-09-17 01:21:23 -06001506 }
1507 if (command_buffer_reset_callback) {
1508 (*command_buffer_reset_callback)(cb);
1509 }
1510}
1511
1512void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
1513 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
1514 VkResult result) {
1515 if (VK_SUCCESS != result) return;
1516
1517 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
1518 if (nullptr == enabled_features_found) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001519 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06001520 if (features2) {
1521 enabled_features_found = &(features2->features);
1522 }
1523 }
1524
1525 ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
1526 ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
1527 ValidationStateTracker *state_tracker = static_cast<ValidationStateTracker *>(validation_data);
1528
1529 if (nullptr == enabled_features_found) {
1530 state_tracker->enabled_features.core = {};
1531 } else {
1532 state_tracker->enabled_features.core = *enabled_features_found;
1533 }
1534
1535 // Make sure that queue_family_properties are obtained for this device's physical_device, even if the app has not
1536 // previously set them through an explicit API call.
1537 uint32_t count;
1538 auto pd_state = GetPhysicalDeviceState(gpu);
1539 DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, nullptr);
1540 pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count));
1541 DispatchGetPhysicalDeviceQueueFamilyProperties(gpu, &count, &pd_state->queue_family_properties[0]);
1542 // Save local link to this device's physical device state
1543 state_tracker->physical_device_state = pd_state;
1544
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001545 const auto *vulkan_12_features = lvl_find_in_chain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
1546 if (vulkan_12_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001547 state_tracker->enabled_features.core12 = *vulkan_12_features;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001548 } else {
sfricke-samsung27c70722020-05-02 08:42:39 -07001549 // Set Extension Feature Aliases to false as there is no struct to check
1550 state_tracker->enabled_features.core12.drawIndirectCount = VK_FALSE;
1551 state_tracker->enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
1552 state_tracker->enabled_features.core12.descriptorIndexing = VK_FALSE;
1553 state_tracker->enabled_features.core12.samplerFilterMinmax = VK_FALSE;
1554 state_tracker->enabled_features.core12.shaderOutputLayer = VK_FALSE;
1555 state_tracker->enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
1556
1557 // These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001558
1559 const auto *eight_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
1560 if (eight_bit_storage_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001561 state_tracker->enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
1562 state_tracker->enabled_features.core12.uniformAndStorageBuffer8BitAccess =
1563 eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
1564 state_tracker->enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001565 }
1566
1567 const auto *float16_int8_features = lvl_find_in_chain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
1568 if (float16_int8_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001569 state_tracker->enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
1570 state_tracker->enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001571 }
1572
1573 const auto *descriptor_indexing_features =
1574 lvl_find_in_chain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
1575 if (descriptor_indexing_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001576 state_tracker->enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
1577 descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
1578 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
1579 descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
1580 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
1581 descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
1582 state_tracker->enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
1583 descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
1584 state_tracker->enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
1585 descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
1586 state_tracker->enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
1587 descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
1588 state_tracker->enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
1589 descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
1590 state_tracker->enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
1591 descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
1592 state_tracker->enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
1593 descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
1594 state_tracker->enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
1595 descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
1596 state_tracker->enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
1597 descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
1598 state_tracker->enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
1599 descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
1600 state_tracker->enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
1601 descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
1602 state_tracker->enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
1603 descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
1604 state_tracker->enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
1605 descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
1606 state_tracker->enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
1607 descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
1608 state_tracker->enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
1609 descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
1610 state_tracker->enabled_features.core12.descriptorBindingPartiallyBound =
1611 descriptor_indexing_features->descriptorBindingPartiallyBound;
1612 state_tracker->enabled_features.core12.descriptorBindingVariableDescriptorCount =
1613 descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
1614 state_tracker->enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001615 }
1616
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001617 const auto *scalar_block_layout_features = lvl_find_in_chain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001618 if (scalar_block_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001619 state_tracker->enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001620 }
1621
1622 const auto *imageless_framebuffer_features =
1623 lvl_find_in_chain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
1624 if (imageless_framebuffer_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001625 state_tracker->enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001626 }
1627
1628 const auto *uniform_buffer_standard_layout_features =
1629 lvl_find_in_chain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
1630 if (uniform_buffer_standard_layout_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001631 state_tracker->enabled_features.core12.uniformBufferStandardLayout =
1632 uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001633 }
1634
1635 const auto *subgroup_extended_types_features =
1636 lvl_find_in_chain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
1637 if (subgroup_extended_types_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001638 state_tracker->enabled_features.core12.shaderSubgroupExtendedTypes =
1639 subgroup_extended_types_features->shaderSubgroupExtendedTypes;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001640 }
1641
1642 const auto *separate_depth_stencil_layouts_features =
1643 lvl_find_in_chain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
1644 if (separate_depth_stencil_layouts_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001645 state_tracker->enabled_features.core12.separateDepthStencilLayouts =
1646 separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001647 }
1648
1649 const auto *host_query_reset_features = lvl_find_in_chain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
1650 if (host_query_reset_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001651 state_tracker->enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001652 }
1653
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001654 const auto *timeline_semaphore_features = lvl_find_in_chain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001655 if (timeline_semaphore_features) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001656 state_tracker->enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001657 }
1658
1659 const auto *buffer_device_address = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
1660 if (buffer_device_address) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001661 state_tracker->enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
1662 state_tracker->enabled_features.core12.bufferDeviceAddressCaptureReplay =
1663 buffer_device_address->bufferDeviceAddressCaptureReplay;
1664 state_tracker->enabled_features.core12.bufferDeviceAddressMultiDevice =
1665 buffer_device_address->bufferDeviceAddressMultiDevice;
1666 }
1667 }
1668
1669 const auto *vulkan_11_features = lvl_find_in_chain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
1670 if (vulkan_11_features) {
1671 state_tracker->enabled_features.core11 = *vulkan_11_features;
1672 } else {
1673 // These structs are only allowed in pNext chain if there is no kPhysicalDeviceVulkan11Features
1674
1675 const auto *sixteen_bit_storage_features = lvl_find_in_chain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
1676 if (sixteen_bit_storage_features) {
1677 state_tracker->enabled_features.core11.storageBuffer16BitAccess =
1678 sixteen_bit_storage_features->storageBuffer16BitAccess;
1679 state_tracker->enabled_features.core11.uniformAndStorageBuffer16BitAccess =
1680 sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
1681 state_tracker->enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
1682 state_tracker->enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
1683 }
1684
1685 const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1686 if (multiview_features) {
1687 state_tracker->enabled_features.core11.multiview = multiview_features->multiview;
1688 state_tracker->enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
1689 state_tracker->enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
1690 }
1691
1692 const auto *variable_pointers_features = lvl_find_in_chain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
1693 if (variable_pointers_features) {
1694 state_tracker->enabled_features.core11.variablePointersStorageBuffer =
1695 variable_pointers_features->variablePointersStorageBuffer;
1696 state_tracker->enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
1697 }
1698
1699 const auto *protected_memory_features = lvl_find_in_chain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
1700 if (protected_memory_features) {
1701 state_tracker->enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
1702 }
1703
1704 const auto *ycbcr_conversion_features =
1705 lvl_find_in_chain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
1706 if (ycbcr_conversion_features) {
1707 state_tracker->enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
1708 }
1709
1710 const auto *shader_draw_parameters_features =
1711 lvl_find_in_chain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
1712 if (shader_draw_parameters_features) {
1713 state_tracker->enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
Tony-LunarGb036c2f2019-12-05 14:38:25 -07001714 }
1715 }
1716
locke-lunargd556cc32019-09-17 01:21:23 -06001717 const auto *device_group_ci = lvl_find_in_chain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
Tony-LunarGca4891a2020-08-10 15:46:46 -06001718 if (device_group_ci) {
1719 state_tracker->physical_device_count = device_group_ci->physicalDeviceCount;
1720 state_tracker->device_group_create_info = *device_group_ci;
1721 } else {
1722 state_tracker->physical_device_count = 1;
1723 }
locke-lunargd556cc32019-09-17 01:21:23 -06001724
locke-lunargd556cc32019-09-17 01:21:23 -06001725 const auto *exclusive_scissor_features = lvl_find_in_chain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
1726 if (exclusive_scissor_features) {
1727 state_tracker->enabled_features.exclusive_scissor = *exclusive_scissor_features;
1728 }
1729
1730 const auto *shading_rate_image_features = lvl_find_in_chain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
1731 if (shading_rate_image_features) {
1732 state_tracker->enabled_features.shading_rate_image = *shading_rate_image_features;
1733 }
1734
1735 const auto *mesh_shader_features = lvl_find_in_chain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
1736 if (mesh_shader_features) {
1737 state_tracker->enabled_features.mesh_shader = *mesh_shader_features;
1738 }
1739
1740 const auto *inline_uniform_block_features =
1741 lvl_find_in_chain<VkPhysicalDeviceInlineUniformBlockFeaturesEXT>(pCreateInfo->pNext);
1742 if (inline_uniform_block_features) {
1743 state_tracker->enabled_features.inline_uniform_block = *inline_uniform_block_features;
1744 }
1745
1746 const auto *transform_feedback_features = lvl_find_in_chain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
1747 if (transform_feedback_features) {
1748 state_tracker->enabled_features.transform_feedback_features = *transform_feedback_features;
1749 }
1750
locke-lunargd556cc32019-09-17 01:21:23 -06001751 const auto *vtx_attrib_div_features = lvl_find_in_chain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
1752 if (vtx_attrib_div_features) {
1753 state_tracker->enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
1754 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001755
Jeff Bolz4563f2a2019-12-10 13:30:30 -06001756 const auto *buffer_device_address_ext = lvl_find_in_chain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
1757 if (buffer_device_address_ext) {
Jeff Bolz33fc6722020-03-31 12:58:16 -05001758 state_tracker->enabled_features.buffer_device_address_ext = *buffer_device_address_ext;
locke-lunargd556cc32019-09-17 01:21:23 -06001759 }
1760
1761 const auto *cooperative_matrix_features = lvl_find_in_chain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
1762 if (cooperative_matrix_features) {
1763 state_tracker->enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
1764 }
1765
locke-lunargd556cc32019-09-17 01:21:23 -06001766 const auto *compute_shader_derivatives_features =
1767 lvl_find_in_chain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
1768 if (compute_shader_derivatives_features) {
1769 state_tracker->enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
1770 }
1771
1772 const auto *fragment_shader_barycentric_features =
1773 lvl_find_in_chain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
1774 if (fragment_shader_barycentric_features) {
1775 state_tracker->enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
1776 }
1777
1778 const auto *shader_image_footprint_features =
1779 lvl_find_in_chain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
1780 if (shader_image_footprint_features) {
1781 state_tracker->enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
1782 }
1783
1784 const auto *fragment_shader_interlock_features =
1785 lvl_find_in_chain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
1786 if (fragment_shader_interlock_features) {
1787 state_tracker->enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
1788 }
1789
1790 const auto *demote_to_helper_invocation_features =
1791 lvl_find_in_chain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT>(pCreateInfo->pNext);
1792 if (demote_to_helper_invocation_features) {
1793 state_tracker->enabled_features.demote_to_helper_invocation_features = *demote_to_helper_invocation_features;
1794 }
1795
1796 const auto *texel_buffer_alignment_features =
1797 lvl_find_in_chain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
1798 if (texel_buffer_alignment_features) {
1799 state_tracker->enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
1800 }
1801
locke-lunargd556cc32019-09-17 01:21:23 -06001802 const auto *pipeline_exe_props_features =
1803 lvl_find_in_chain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
1804 if (pipeline_exe_props_features) {
1805 state_tracker->enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
1806 }
1807
Jeff Bolz82f854d2019-09-17 14:56:47 -05001808 const auto *dedicated_allocation_image_aliasing_features =
1809 lvl_find_in_chain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
1810 if (dedicated_allocation_image_aliasing_features) {
1811 state_tracker->enabled_features.dedicated_allocation_image_aliasing_features =
1812 *dedicated_allocation_image_aliasing_features;
1813 }
1814
Lionel Landwerlinc7420912019-05-23 00:33:42 +01001815 const auto *performance_query_features = lvl_find_in_chain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
1816 if (performance_query_features) {
1817 state_tracker->enabled_features.performance_query_features = *performance_query_features;
1818 }
1819
Tobias Hector782bcde2019-11-28 16:19:42 +00001820 const auto *device_coherent_memory_features = lvl_find_in_chain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
1821 if (device_coherent_memory_features) {
1822 state_tracker->enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
1823 }
1824
sfricke-samsungcead0802020-01-30 22:20:10 -08001825 const auto *ycbcr_image_array_features = lvl_find_in_chain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
1826 if (ycbcr_image_array_features) {
1827 state_tracker->enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
1828 }
1829
sourav parmarcd5fb182020-07-17 12:58:44 -07001830 const auto *ray_query_features = lvl_find_in_chain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
1831 if (ray_query_features) {
1832 state_tracker->enabled_features.ray_query_features = *ray_query_features;
1833 }
1834
1835 const auto *ray_tracing_pipeline_features =
1836 lvl_find_in_chain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
1837 if (ray_tracing_pipeline_features) {
1838 state_tracker->enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
1839 }
1840
1841 const auto *ray_tracing_acceleration_structure_features =
1842 lvl_find_in_chain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
1843 if (ray_tracing_acceleration_structure_features) {
1844 state_tracker->enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
Jeff Bolz443c2ca2020-03-19 12:11:51 -05001845 }
1846
Jeff Bolz165818a2020-05-08 11:19:03 -05001847 const auto *robustness2_features = lvl_find_in_chain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
1848 if (robustness2_features) {
1849 state_tracker->enabled_features.robustness2_features = *robustness2_features;
1850 }
1851
janharaldfredriksen-arm3b793772020-05-12 18:55:53 +02001852 const auto *fragment_density_map_features =
1853 lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
1854 if (fragment_density_map_features) {
1855 state_tracker->enabled_features.fragment_density_map_features = *fragment_density_map_features;
1856 }
1857
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02001858 const auto *fragment_density_map_features2 =
1859 lvl_find_in_chain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
1860 if (fragment_density_map_features2) {
1861 state_tracker->enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
1862 }
1863
sfricke-samsung0c4a06f2020-06-27 01:24:32 -07001864 const auto *astc_decode_features = lvl_find_in_chain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
1865 if (astc_decode_features) {
1866 state_tracker->enabled_features.astc_decode_features = *astc_decode_features;
1867 }
1868
Tony-LunarG7337b312020-04-15 16:40:25 -06001869 const auto *custom_border_color_features = lvl_find_in_chain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
1870 if (custom_border_color_features) {
1871 state_tracker->enabled_features.custom_border_color_features = *custom_border_color_features;
1872 }
1873
sfricke-samsungfd661d62020-05-16 00:57:27 -07001874 const auto *pipeline_creation_cache_control_features =
1875 lvl_find_in_chain<VkPhysicalDevicePipelineCreationCacheControlFeaturesEXT>(pCreateInfo->pNext);
1876 if (pipeline_creation_cache_control_features) {
1877 state_tracker->enabled_features.pipeline_creation_cache_control_features = *pipeline_creation_cache_control_features;
1878 }
1879
Tobias Hector6663c9b2020-11-05 10:18:02 +00001880 const auto *fragment_shading_rate_features =
1881 lvl_find_in_chain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
1882 if (fragment_shading_rate_features) {
1883 state_tracker->enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
1884 }
1885
Piers Daniell39842ee2020-07-10 16:42:33 -06001886 const auto *extended_dynamic_state_features =
1887 lvl_find_in_chain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
1888 if (extended_dynamic_state_features) {
1889 state_tracker->enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
1890 }
1891
locke-lunarg3fa463a2020-10-23 16:39:04 -06001892 const auto *multiview_features = lvl_find_in_chain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
1893 if (multiview_features) {
1894 state_tracker->enabled_features.multiview_features = *multiview_features;
1895 }
1896
Nathaniel Cesariob3f2d702020-11-09 09:20:49 -07001897 const auto *portability_features = lvl_find_in_chain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
1898 if (portability_features) {
1899 state_tracker->enabled_features.portability_subset_features = *portability_features;
1900 }
1901
sfricke-samsung0065ce02020-12-03 22:46:37 -08001902 const auto *shader_integer_functions2_features =
1903 lvl_find_in_chain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
1904 if (shader_integer_functions2_features) {
1905 state_tracker->enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
1906 }
1907
1908 const auto *shader_sm_builtins_feature = lvl_find_in_chain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
1909 if (shader_sm_builtins_feature) {
1910 state_tracker->enabled_features.shader_sm_builtins_feature = *shader_sm_builtins_feature;
1911 }
1912
1913 const auto *shader_atomic_float_feature = lvl_find_in_chain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
1914 if (shader_atomic_float_feature) {
1915 state_tracker->enabled_features.shader_atomic_float_feature = *shader_atomic_float_feature;
1916 }
1917
1918 const auto *shader_image_atomic_int64_feature =
1919 lvl_find_in_chain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
1920 if (shader_image_atomic_int64_feature) {
1921 state_tracker->enabled_features.shader_image_atomic_int64_feature = *shader_image_atomic_int64_feature;
1922 }
1923
locke-lunargd556cc32019-09-17 01:21:23 -06001924 // Store physical device properties and physical device mem limits into CoreChecks structs
1925 DispatchGetPhysicalDeviceMemoryProperties(gpu, &state_tracker->phys_dev_mem_props);
1926 DispatchGetPhysicalDeviceProperties(gpu, &state_tracker->phys_dev_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001927 GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2,
1928 &state_tracker->phys_dev_props_core11);
1929 GetPhysicalDeviceExtProperties(gpu, state_tracker->device_extensions.vk_feature_version_1_2,
1930 &state_tracker->phys_dev_props_core12);
locke-lunargd556cc32019-09-17 01:21:23 -06001931
1932 const auto &dev_ext = state_tracker->device_extensions;
1933 auto *phys_dev_props = &state_tracker->phys_dev_ext_props;
1934
1935 if (dev_ext.vk_khr_push_descriptor) {
1936 // Get the needed push_descriptor limits
1937 VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor_prop;
1938 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_push_descriptor, &push_descriptor_prop);
1939 phys_dev_props->max_push_descriptors = push_descriptor_prop.maxPushDescriptors;
1940 }
1941
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001942 if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_ext_descriptor_indexing) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001943 VkPhysicalDeviceDescriptorIndexingProperties descriptor_indexing_prop;
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001944 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
1945 state_tracker->phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
1946 descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
1947 state_tracker->phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
1948 descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
1949 state_tracker->phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
1950 descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
1951 state_tracker->phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
1952 descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
1953 state_tracker->phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
1954 descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
1955 state_tracker->phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
1956 descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
1957 state_tracker->phys_dev_props_core12.robustBufferAccessUpdateAfterBind =
1958 descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
1959 state_tracker->phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
1960 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
1961 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
1962 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
1963 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
1964 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
1965 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
1966 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
1967 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
1968 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
1969 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
1970 state_tracker->phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
1971 descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
1972 state_tracker->phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
1973 descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
1974 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
1975 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
1976 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
1977 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
1978 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
1979 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
1980 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
1981 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
1982 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
1983 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
1984 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
1985 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
1986 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
1987 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
1988 state_tracker->phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
1989 descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
1990 }
1991
locke-lunargd556cc32019-09-17 01:21:23 -06001992 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
1993 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props);
1994 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_inline_uniform_block, &phys_dev_props->inline_uniform_block_props);
1995 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_vertex_attribute_divisor, &phys_dev_props->vtx_attrib_divisor_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001996
1997 if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_depth_stencil_resolve) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001998 VkPhysicalDeviceDepthStencilResolveProperties depth_stencil_resolve_props;
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001999 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
2000 state_tracker->phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
2001 state_tracker->phys_dev_props_core12.supportedStencilResolveModes =
2002 depth_stencil_resolve_props.supportedStencilResolveModes;
2003 state_tracker->phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
2004 state_tracker->phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
2005 }
2006
locke-lunargd556cc32019-09-17 01:21:23 -06002007 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002008 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_propsNV);
sourav parmarcd5fb182020-07-17 12:58:44 -07002009 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_propsKHR);
2010 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
locke-lunargd556cc32019-09-17 01:21:23 -06002011 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_texel_buffer_alignment, &phys_dev_props->texel_buffer_alignment_props);
2012 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map, &phys_dev_props->fragment_density_map_props);
janharaldfredriksen-arm36e17572020-07-07 13:59:28 +02002013 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_fragment_density_map_2, &phys_dev_props->fragment_density_map2_props);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002014 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
sfricke-samsung8f658d42020-05-03 20:12:24 -07002015 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
Tony-LunarG7337b312020-04-15 16:40:25 -06002016 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
locke-lunarg3fa463a2020-10-23 16:39:04 -06002017 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
Nathaniel Cesario3291c912020-11-17 16:54:41 -07002018 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
Piers Daniell41b8c5d2020-01-10 15:42:00 -07002019
2020 if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_timeline_semaphore) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08002021 VkPhysicalDeviceTimelineSemaphoreProperties timeline_semaphore_props;
Piers Daniell41b8c5d2020-01-10 15:42:00 -07002022 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
2023 state_tracker->phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
2024 timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
2025 }
2026
2027 if (!state_tracker->device_extensions.vk_feature_version_1_2 && dev_ext.vk_khr_shader_float_controls) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08002028 VkPhysicalDeviceFloatControlsProperties float_controls_props;
Piers Daniell41b8c5d2020-01-10 15:42:00 -07002029 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
2030 state_tracker->phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
2031 state_tracker->phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
2032 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
2033 float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
2034 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
2035 float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
2036 state_tracker->phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
2037 float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
2038 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
2039 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
2040 state_tracker->phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
2041 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
2042 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
2043 state_tracker->phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
2044 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
2045 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
2046 state_tracker->phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
2047 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
2048 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
2049 state_tracker->phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
2050 }
Mark Lobodzinskie4a2b7f2019-12-20 12:51:30 -07002051
locke-lunargd556cc32019-09-17 01:21:23 -06002052 if (state_tracker->device_extensions.vk_nv_cooperative_matrix) {
2053 // Get the needed cooperative_matrix properties
2054 auto cooperative_matrix_props = lvl_init_struct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
Mike Schuchardt2df08912020-12-15 16:28:09 -08002055 auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
locke-lunargd556cc32019-09-17 01:21:23 -06002056 instance_dispatch_table.GetPhysicalDeviceProperties2KHR(gpu, &prop2);
2057 state_tracker->phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
2058
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002059 uint32_t num_cooperative_matrix_properties = 0;
2060 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties, NULL);
2061 state_tracker->cooperative_matrix_properties.resize(num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06002062 lvl_init_struct<VkCooperativeMatrixPropertiesNV>());
2063
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002064 instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(gpu, &num_cooperative_matrix_properties,
locke-lunargd556cc32019-09-17 01:21:23 -06002065 state_tracker->cooperative_matrix_properties.data());
2066 }
Piers Daniell41b8c5d2020-01-10 15:42:00 -07002067 if (!state_tracker->device_extensions.vk_feature_version_1_2 && state_tracker->api_version >= VK_API_VERSION_1_1) {
locke-lunargd556cc32019-09-17 01:21:23 -06002068 // Get the needed subgroup limits
2069 auto subgroup_prop = lvl_init_struct<VkPhysicalDeviceSubgroupProperties>();
Mike Schuchardt2df08912020-12-15 16:28:09 -08002070 auto prop2 = lvl_init_struct<VkPhysicalDeviceProperties2>(&subgroup_prop);
locke-lunargd556cc32019-09-17 01:21:23 -06002071 instance_dispatch_table.GetPhysicalDeviceProperties2(gpu, &prop2);
2072
Piers Daniell41b8c5d2020-01-10 15:42:00 -07002073 state_tracker->phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
2074 state_tracker->phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
2075 state_tracker->phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
2076 state_tracker->phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
locke-lunargd556cc32019-09-17 01:21:23 -06002077 }
2078
Tobias Hector6663c9b2020-11-05 10:18:02 +00002079 GetPhysicalDeviceExtProperties(gpu, dev_ext.vk_khr_fragment_shading_rate, &phys_dev_props->fragment_shading_rate_props);
2080
locke-lunargd556cc32019-09-17 01:21:23 -06002081 // Store queue family data
2082 if (pCreateInfo->pQueueCreateInfos != nullptr) {
2083 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
sfricke-samsung590ae1e2020-04-25 01:18:05 -07002084 const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06002085 state_tracker->queue_family_index_map.insert(
sfricke-samsung590ae1e2020-04-25 01:18:05 -07002086 std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.queueCount));
2087 state_tracker->queue_family_create_flags_map.insert(
2088 std::make_pair(queue_create_info.queueFamilyIndex, queue_create_info.flags));
locke-lunargd556cc32019-09-17 01:21:23 -06002089 }
2090 }
2091}
2092
2093void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
2094 if (!device) return;
2095
locke-lunargd556cc32019-09-17 01:21:23 -06002096 // Reset all command buffers before destroying them, to unlink object_bindings.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002097 for (auto &command_buffer : commandBufferMap) {
2098 ResetCommandBufferState(command_buffer.first);
locke-lunargd556cc32019-09-17 01:21:23 -06002099 }
Jeff Bolzadbfa852019-10-04 13:53:30 -05002100 pipelineMap.clear();
2101 renderPassMap.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06002102 commandBufferMap.clear();
2103
2104 // This will also delete all sets in the pool & remove them from setMap
2105 DeleteDescriptorSetPools();
2106 // All sets should be removed
2107 assert(setMap.empty());
2108 descriptorSetLayoutMap.clear();
2109 imageViewMap.clear();
2110 imageMap.clear();
2111 bufferViewMap.clear();
2112 bufferMap.clear();
2113 // Queues persist until device is destroyed
2114 queueMap.clear();
2115}
2116
2117// Loop through bound objects and increment their in_use counts.
2118void ValidationStateTracker::IncrementBoundObjects(CMD_BUFFER_STATE const *cb_node) {
2119 for (auto obj : cb_node->object_bindings) {
2120 auto base_obj = GetStateStructPtrFromObject(obj);
2121 if (base_obj) {
2122 base_obj->in_use.fetch_add(1);
2123 }
2124 }
2125}
2126
2127// Track which resources are in-flight by atomically incrementing their "in_use" count
2128void ValidationStateTracker::IncrementResources(CMD_BUFFER_STATE *cb_node) {
2129 cb_node->submitCount++;
2130 cb_node->in_use.fetch_add(1);
2131
2132 // First Increment for all "generic" objects bound to cmd buffer, followed by special-case objects below
2133 IncrementBoundObjects(cb_node);
2134 // TODO : We should be able to remove the NULL look-up checks from the code below as long as
2135 // all the corresponding cases are verified to cause CB_INVALID state and the CB_INVALID state
2136 // should then be flagged prior to calling this function
2137 for (auto event : cb_node->writeEventsBeforeWait) {
2138 auto event_state = GetEventState(event);
2139 if (event_state) event_state->write_in_use++;
2140 }
2141}
2142
2143// Decrement in-use count for objects bound to command buffer
2144void ValidationStateTracker::DecrementBoundResources(CMD_BUFFER_STATE const *cb_node) {
2145 BASE_NODE *base_obj = nullptr;
2146 for (auto obj : cb_node->object_bindings) {
2147 base_obj = GetStateStructPtrFromObject(obj);
2148 if (base_obj) {
2149 base_obj->in_use.fetch_sub(1);
2150 }
2151 }
2152}
2153
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002154void ValidationStateTracker::RetireWorkOnQueue(QUEUE_STATE *pQueue, uint64_t seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002155 std::unordered_map<VkQueue, uint64_t> other_queue_seqs;
2156 std::unordered_map<VkSemaphore, uint64_t> timeline_semaphore_counters;
locke-lunargd556cc32019-09-17 01:21:23 -06002157
2158 // Roll this queue forward, one submission at a time.
2159 while (pQueue->seq < seq) {
2160 auto &submission = pQueue->submissions.front();
2161
2162 for (auto &wait : submission.waitSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002163 auto semaphore_state = GetSemaphoreState(wait.semaphore);
2164 if (semaphore_state) {
2165 semaphore_state->in_use.fetch_sub(1);
locke-lunargd556cc32019-09-17 01:21:23 -06002166 }
Mike Schuchardt2df08912020-12-15 16:28:09 -08002167 if (wait.type == VK_SEMAPHORE_TYPE_TIMELINE) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002168 auto &last_counter = timeline_semaphore_counters[wait.semaphore];
2169 last_counter = std::max(last_counter, wait.payload);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08002170 } else {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002171 auto &last_seq = other_queue_seqs[wait.queue];
2172 last_seq = std::max(last_seq, wait.seq);
Marshall Drew-Brook03847582020-11-06 15:10:45 -08002173 }
locke-lunargd556cc32019-09-17 01:21:23 -06002174 }
2175
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002176 for (auto &signal : submission.signalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002177 auto semaphore_state = GetSemaphoreState(signal.semaphore);
2178 if (semaphore_state) {
2179 semaphore_state->in_use.fetch_sub(1);
Mike Schuchardt2df08912020-12-15 16:28:09 -08002180 if (semaphore_state->type == VK_SEMAPHORE_TYPE_TIMELINE && semaphore_state->payload < signal.payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002181 semaphore_state->payload = signal.payload;
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002182 }
locke-lunargd556cc32019-09-17 01:21:23 -06002183 }
2184 }
2185
2186 for (auto &semaphore : submission.externalSemaphores) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002187 auto semaphore_state = GetSemaphoreState(semaphore);
2188 if (semaphore_state) {
2189 semaphore_state->in_use.fetch_sub(1);
locke-lunargd556cc32019-09-17 01:21:23 -06002190 }
2191 }
2192
2193 for (auto cb : submission.cbs) {
2194 auto cb_node = GetCBState(cb);
2195 if (!cb_node) {
2196 continue;
2197 }
2198 // First perform decrement on general case bound objects
2199 DecrementBoundResources(cb_node);
2200 for (auto event : cb_node->writeEventsBeforeWait) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002201 auto event_node = eventMap.find(event);
2202 if (event_node != eventMap.end()) {
2203 event_node->second.write_in_use--;
locke-lunargd556cc32019-09-17 01:21:23 -06002204 }
2205 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002206 QueryMap local_query_to_state_map;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002207 VkQueryPool first_pool = VK_NULL_HANDLE;
Jeff Bolz310775c2019-10-09 00:46:33 -05002208 for (auto &function : cb_node->queryUpdates) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002209 function(nullptr, /*do_validate*/ false, first_pool, submission.perf_submit_pass, &local_query_to_state_map);
Jeff Bolz310775c2019-10-09 00:46:33 -05002210 }
2211
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002212 for (auto query_state_pair : local_query_to_state_map) {
2213 if (query_state_pair.second == QUERYSTATE_ENDED) {
2214 queryToStateMap[query_state_pair.first] = QUERYSTATE_AVAILABLE;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002215 }
locke-lunargd556cc32019-09-17 01:21:23 -06002216 }
locke-lunargd556cc32019-09-17 01:21:23 -06002217 cb_node->in_use.fetch_sub(1);
2218 }
2219
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002220 auto fence_state = GetFenceState(submission.fence);
2221 if (fence_state && fence_state->scope == kSyncScopeInternal) {
2222 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06002223 }
2224
2225 pQueue->submissions.pop_front();
2226 pQueue->seq++;
2227 }
2228
2229 // Roll other queues forward to the highest seq we saw a wait for
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002230 for (auto qs : other_queue_seqs) {
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002231 RetireWorkOnQueue(GetQueueState(qs.first), qs.second);
locke-lunargd556cc32019-09-17 01:21:23 -06002232 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002233 for (auto sc : timeline_semaphore_counters) {
Marshall Drew-Brook03847582020-11-06 15:10:45 -08002234 RetireTimelineSemaphore(sc.first, sc.second);
2235 }
locke-lunargd556cc32019-09-17 01:21:23 -06002236}
2237
2238// Submit a fence to a queue, delimiting previous fences and previous untracked
2239// work by it.
2240static void SubmitFence(QUEUE_STATE *pQueue, FENCE_STATE *pFence, uint64_t submitCount) {
2241 pFence->state = FENCE_INFLIGHT;
2242 pFence->signaler.first = pQueue->queue;
2243 pFence->signaler.second = pQueue->seq + pQueue->submissions.size() + submitCount;
2244}
2245
2246void ValidationStateTracker::PostCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
2247 VkFence fence, VkResult result) {
Mark Lobodzinski09379db2020-05-07 08:22:01 -06002248 if (result != VK_SUCCESS) return;
locke-lunargd556cc32019-09-17 01:21:23 -06002249 uint64_t early_retire_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002250 auto queue_state = GetQueueState(queue);
2251 auto fence_state = GetFenceState(fence);
locke-lunargd556cc32019-09-17 01:21:23 -06002252
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002253 if (fence_state) {
2254 if (fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06002255 // Mark fence in use
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002256 SubmitFence(queue_state, fence_state, std::max(1u, submitCount));
locke-lunargd556cc32019-09-17 01:21:23 -06002257 if (!submitCount) {
2258 // If no submissions, but just dropping a fence on the end of the queue,
2259 // record an empty submission with just the fence, so we can determine
2260 // its completion.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002261 queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(),
2262 std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06002263 }
2264 } else {
2265 // Retire work up until this fence early, we will not see the wait that corresponds to this signal
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002266 early_retire_seq = queue_state->seq + queue_state->submissions.size();
locke-lunargd556cc32019-09-17 01:21:23 -06002267 }
2268 }
2269
2270 // Now process each individual submit
2271 for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
2272 std::vector<VkCommandBuffer> cbs;
2273 const VkSubmitInfo *submit = &pSubmits[submit_idx];
Jeremy Gebben404e6832020-09-29 14:58:07 -06002274 std::vector<SEMAPHORE_WAIT> semaphore_waits;
2275 std::vector<SEMAPHORE_SIGNAL> semaphore_signals;
2276 std::vector<VkSemaphore> semaphore_externals;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002277 const uint64_t next_seq = queue_state->seq + queue_state->submissions.size() + 1;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002278 auto *timeline_semaphore_submit = lvl_find_in_chain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002279 for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
2280 VkSemaphore semaphore = submit->pWaitSemaphores[i];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002281 auto semaphore_state = GetSemaphoreState(semaphore);
2282 if (semaphore_state) {
2283 if (semaphore_state->scope == kSyncScopeInternal) {
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002284 SEMAPHORE_WAIT wait;
2285 wait.semaphore = semaphore;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002286 wait.type = semaphore_state->type;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002287 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002288 if (semaphore_state->signaler.first != VK_NULL_HANDLE) {
2289 wait.queue = semaphore_state->signaler.first;
2290 wait.seq = semaphore_state->signaler.second;
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002291 semaphore_waits.push_back(wait);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002292 semaphore_state->in_use.fetch_add(1);
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002293 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002294 semaphore_state->signaler.first = VK_NULL_HANDLE;
2295 semaphore_state->signaled = false;
2296 } else if (semaphore_state->payload < timeline_semaphore_submit->pWaitSemaphoreValues[i]) {
Juan A. Suarez Romero9cef8852020-03-10 12:19:42 +01002297 wait.queue = queue;
2298 wait.seq = next_seq;
2299 wait.payload = timeline_semaphore_submit->pWaitSemaphoreValues[i];
2300 semaphore_waits.push_back(wait);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002301 semaphore_state->in_use.fetch_add(1);
locke-lunargd556cc32019-09-17 01:21:23 -06002302 }
locke-lunargd556cc32019-09-17 01:21:23 -06002303 } else {
2304 semaphore_externals.push_back(semaphore);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002305 semaphore_state->in_use.fetch_add(1);
2306 if (semaphore_state->scope == kSyncScopeExternalTemporary) {
2307 semaphore_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06002308 }
2309 }
2310 }
2311 }
2312 for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
2313 VkSemaphore semaphore = submit->pSignalSemaphores[i];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002314 auto semaphore_state = GetSemaphoreState(semaphore);
2315 if (semaphore_state) {
2316 if (semaphore_state->scope == kSyncScopeInternal) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002317 SEMAPHORE_SIGNAL signal;
2318 signal.semaphore = semaphore;
2319 signal.seq = next_seq;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002320 if (semaphore_state->type == VK_SEMAPHORE_TYPE_BINARY) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002321 semaphore_state->signaler.first = queue;
2322 semaphore_state->signaler.second = next_seq;
2323 semaphore_state->signaled = true;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002324 } else {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002325 signal.payload = timeline_semaphore_submit->pSignalSemaphoreValues[i];
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002326 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002327 semaphore_state->in_use.fetch_add(1);
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002328 semaphore_signals.push_back(signal);
locke-lunargd556cc32019-09-17 01:21:23 -06002329 } else {
2330 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002331 early_retire_seq = std::max(early_retire_seq, next_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06002332 }
2333 }
2334 }
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002335 const auto perf_submit = lvl_find_in_chain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
2336 uint32_t perf_pass = perf_submit ? perf_submit->counterPassIndex : 0;
2337
locke-lunargd556cc32019-09-17 01:21:23 -06002338 for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
2339 auto cb_node = GetCBState(submit->pCommandBuffers[i]);
2340 if (cb_node) {
2341 cbs.push_back(submit->pCommandBuffers[i]);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002342 for (auto secondary_cmd_buffer : cb_node->linkedCommandBuffers) {
2343 cbs.push_back(secondary_cmd_buffer->commandBuffer);
2344 IncrementResources(secondary_cmd_buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002345 }
2346 IncrementResources(cb_node);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002347
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02002348 VkQueryPool first_pool = VK_NULL_HANDLE;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002349 EventToStageMap local_event_to_stage_map;
2350 QueryMap local_query_to_state_map;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002351 for (auto &function : cb_node->queryUpdates) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002352 function(nullptr, /*do_validate*/ false, first_pool, perf_pass, &local_query_to_state_map);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002353 }
2354
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002355 for (auto query_state_pair : local_query_to_state_map) {
2356 queryToStateMap[query_state_pair.first] = query_state_pair.second;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002357 }
2358
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002359 for (auto &function : cb_node->eventUpdates) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002360 function(nullptr, /*do_validate*/ false, &local_event_to_stage_map);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002361 }
2362
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002363 for (auto event_stage_pair : local_event_to_stage_map) {
2364 eventMap[event_stage_pair.first].stageMask = event_stage_pair.second;
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002365 }
locke-lunargd556cc32019-09-17 01:21:23 -06002366 }
2367 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01002368
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002369 queue_state->submissions.emplace_back(cbs, semaphore_waits, semaphore_signals, semaphore_externals,
2370 submit_idx == submitCount - 1 ? fence : (VkFence)VK_NULL_HANDLE, perf_pass);
locke-lunargd556cc32019-09-17 01:21:23 -06002371 }
2372
2373 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002374 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06002375 }
2376}
2377
2378void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
2379 const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
2380 VkResult result) {
2381 if (VK_SUCCESS == result) {
2382 AddMemObjInfo(device, *pMemory, pAllocateInfo);
2383 }
2384 return;
2385}
2386
2387void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
2388 if (!mem) return;
2389 DEVICE_MEMORY_STATE *mem_info = GetDevMemState(mem);
2390 const VulkanTypedHandle obj_struct(mem, kVulkanObjectTypeDeviceMemory);
2391
2392 // Clear mem binding for any bound objects
2393 for (const auto &obj : mem_info->obj_bindings) {
2394 BINDABLE *bindable_state = nullptr;
2395 switch (obj.type) {
2396 case kVulkanObjectTypeImage:
2397 bindable_state = GetImageState(obj.Cast<VkImage>());
2398 break;
2399 case kVulkanObjectTypeBuffer:
2400 bindable_state = GetBufferState(obj.Cast<VkBuffer>());
2401 break;
2402 case kVulkanObjectTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -07002403 bindable_state = GetAccelerationStructureStateNV(obj.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06002404 break;
2405
2406 default:
2407 // Should only have acceleration structure, buffer, or image objects bound to memory
2408 assert(0);
2409 }
2410
2411 if (bindable_state) {
Jeff Bolz41e29052020-03-29 22:33:55 -05002412 // Remove any sparse bindings bound to the resource that use this memory.
2413 for (auto it = bindable_state->sparse_bindings.begin(); it != bindable_state->sparse_bindings.end();) {
2414 auto nextit = it;
2415 nextit++;
2416
2417 auto &sparse_mem_binding = *it;
2418 if (sparse_mem_binding.mem_state.get() == mem_info) {
2419 bindable_state->sparse_bindings.erase(it);
2420 }
2421
2422 it = nextit;
2423 }
locke-lunargd556cc32019-09-17 01:21:23 -06002424 bindable_state->UpdateBoundMemorySet();
2425 }
2426 }
2427 // Any bound cmd buffers are now invalid
2428 InvalidateCommandBuffers(mem_info->cb_bindings, obj_struct);
2429 RemoveAliasingImages(mem_info->bound_images);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002430 mem_info->destroyed = true;
John Zulauf79952712020-04-07 11:25:54 -06002431 fake_memory.Free(mem_info->fake_base_address);
locke-lunargd556cc32019-09-17 01:21:23 -06002432 memObjMap.erase(mem);
2433}
2434
2435void ValidationStateTracker::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
2436 VkFence fence, VkResult result) {
2437 if (result != VK_SUCCESS) return;
2438 uint64_t early_retire_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002439 auto fence_state = GetFenceState(fence);
2440 auto queue_state = GetQueueState(queue);
locke-lunargd556cc32019-09-17 01:21:23 -06002441
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002442 if (fence_state) {
2443 if (fence_state->scope == kSyncScopeInternal) {
2444 SubmitFence(queue_state, fence_state, std::max(1u, bindInfoCount));
locke-lunargd556cc32019-09-17 01:21:23 -06002445 if (!bindInfoCount) {
2446 // No work to do, just dropping a fence in the queue by itself.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002447 queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), std::vector<SEMAPHORE_WAIT>(),
2448 std::vector<SEMAPHORE_SIGNAL>(), std::vector<VkSemaphore>(), fence, 0);
locke-lunargd556cc32019-09-17 01:21:23 -06002449 }
2450 } else {
2451 // Retire work up until this fence early, we will not see the wait that corresponds to this signal
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002452 early_retire_seq = queue_state->seq + queue_state->submissions.size();
locke-lunargd556cc32019-09-17 01:21:23 -06002453 }
2454 }
2455
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002456 for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
2457 const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
locke-lunargd556cc32019-09-17 01:21:23 -06002458 // Track objects tied to memory
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002459 for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
2460 for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
2461 auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
locke-lunargcf04d582019-11-26 00:31:50 -07002462 SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002463 VulkanTypedHandle(bind_info.pBufferBinds[j].buffer, kVulkanObjectTypeBuffer));
locke-lunargd556cc32019-09-17 01:21:23 -06002464 }
2465 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002466 for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
2467 for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
2468 auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
locke-lunargcf04d582019-11-26 00:31:50 -07002469 SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, sparse_binding.size,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002470 VulkanTypedHandle(bind_info.pImageOpaqueBinds[j].image, kVulkanObjectTypeImage));
locke-lunargd556cc32019-09-17 01:21:23 -06002471 }
2472 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002473 for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
2474 for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
2475 auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
locke-lunargd556cc32019-09-17 01:21:23 -06002476 // TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
2477 VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
locke-lunargcf04d582019-11-26 00:31:50 -07002478 SetSparseMemBinding(sparse_binding.memory, sparse_binding.memoryOffset, size,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002479 VulkanTypedHandle(bind_info.pImageBinds[j].image, kVulkanObjectTypeImage));
locke-lunargd556cc32019-09-17 01:21:23 -06002480 }
2481 }
2482
2483 std::vector<SEMAPHORE_WAIT> semaphore_waits;
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002484 std::vector<SEMAPHORE_SIGNAL> semaphore_signals;
locke-lunargd556cc32019-09-17 01:21:23 -06002485 std::vector<VkSemaphore> semaphore_externals;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002486 for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
2487 VkSemaphore semaphore = bind_info.pWaitSemaphores[i];
2488 auto semaphore_state = GetSemaphoreState(semaphore);
2489 if (semaphore_state) {
2490 if (semaphore_state->scope == kSyncScopeInternal) {
2491 if (semaphore_state->signaler.first != VK_NULL_HANDLE) {
Marshall Drew-Brook03847582020-11-06 15:10:45 -08002492 semaphore_waits.push_back(
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002493 {semaphore, semaphore_state->type, semaphore_state->signaler.first, semaphore_state->signaler.second});
2494 semaphore_state->in_use.fetch_add(1);
locke-lunargd556cc32019-09-17 01:21:23 -06002495 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002496 semaphore_state->signaler.first = VK_NULL_HANDLE;
2497 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06002498 } else {
2499 semaphore_externals.push_back(semaphore);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002500 semaphore_state->in_use.fetch_add(1);
2501 if (semaphore_state->scope == kSyncScopeExternalTemporary) {
2502 semaphore_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06002503 }
2504 }
2505 }
2506 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002507 for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
2508 VkSemaphore semaphore = bind_info.pSignalSemaphores[i];
2509 auto semaphore_state = GetSemaphoreState(semaphore);
2510 if (semaphore_state) {
2511 if (semaphore_state->scope == kSyncScopeInternal) {
2512 semaphore_state->signaler.first = queue;
2513 semaphore_state->signaler.second = queue_state->seq + queue_state->submissions.size() + 1;
2514 semaphore_state->signaled = true;
2515 semaphore_state->in_use.fetch_add(1);
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002516
2517 SEMAPHORE_SIGNAL signal;
2518 signal.semaphore = semaphore;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002519 signal.seq = semaphore_state->signaler.second;
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002520 semaphore_signals.push_back(signal);
locke-lunargd556cc32019-09-17 01:21:23 -06002521 } else {
2522 // Retire work up until this submit early, we will not see the wait that corresponds to this signal
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002523 early_retire_seq = std::max(early_retire_seq, queue_state->seq + queue_state->submissions.size() + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06002524 }
2525 }
2526 }
2527
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002528 queue_state->submissions.emplace_back(std::vector<VkCommandBuffer>(), semaphore_waits, semaphore_signals,
2529 semaphore_externals, bind_idx == bindInfoCount - 1 ? fence : (VkFence)VK_NULL_HANDLE,
2530 0);
locke-lunargd556cc32019-09-17 01:21:23 -06002531 }
2532
2533 if (early_retire_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002534 RetireWorkOnQueue(queue_state, early_retire_seq);
locke-lunargd556cc32019-09-17 01:21:23 -06002535 }
2536}
2537
2538void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
2539 const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
2540 VkResult result) {
2541 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002542 auto semaphore_state = std::make_shared<SEMAPHORE_STATE>();
locke-lunargd556cc32019-09-17 01:21:23 -06002543 semaphore_state->signaler.first = VK_NULL_HANDLE;
2544 semaphore_state->signaler.second = 0;
2545 semaphore_state->signaled = false;
2546 semaphore_state->scope = kSyncScopeInternal;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002547 semaphore_state->type = VK_SEMAPHORE_TYPE_BINARY;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002548 semaphore_state->payload = 0;
Mike Schuchardt2df08912020-12-15 16:28:09 -08002549 auto semaphore_type_create_info = lvl_find_in_chain<VkSemaphoreTypeCreateInfo>(pCreateInfo->pNext);
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002550 if (semaphore_type_create_info) {
2551 semaphore_state->type = semaphore_type_create_info->semaphoreType;
2552 semaphore_state->payload = semaphore_type_create_info->initialValue;
2553 }
locke-lunargd556cc32019-09-17 01:21:23 -06002554 semaphoreMap[*pSemaphore] = std::move(semaphore_state);
2555}
2556
Mike Schuchardt2df08912020-12-15 16:28:09 -08002557void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
2558 VkSemaphoreImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06002559 SEMAPHORE_STATE *sema_node = GetSemaphoreState(semaphore);
2560 if (sema_node && sema_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08002561 if ((handle_type == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_SEMAPHORE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06002562 sema_node->scope == kSyncScopeInternal) {
2563 sema_node->scope = kSyncScopeExternalTemporary;
2564 } else {
2565 sema_node->scope = kSyncScopeExternalPermanent;
2566 }
2567 }
2568}
2569
Mike Schuchardt2df08912020-12-15 16:28:09 -08002570void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002571 VkResult result) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002572 auto *semaphore_state = GetSemaphoreState(pSignalInfo->semaphore);
2573 semaphore_state->payload = pSignalInfo->value;
Juan A. Suarez Romerof3024162019-10-31 17:57:50 +00002574}
2575
locke-lunargd556cc32019-09-17 01:21:23 -06002576void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
2577 auto mem_info = GetDevMemState(mem);
2578 if (mem_info) {
2579 mem_info->mapped_range.offset = offset;
2580 mem_info->mapped_range.size = size;
2581 mem_info->p_driver_data = *ppData;
2582 }
2583}
2584
2585void ValidationStateTracker::RetireFence(VkFence fence) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002586 auto fence_state = GetFenceState(fence);
2587 if (fence_state && fence_state->scope == kSyncScopeInternal) {
2588 if (fence_state->signaler.first != VK_NULL_HANDLE) {
locke-lunargd556cc32019-09-17 01:21:23 -06002589 // Fence signaller is a queue -- use this as proof that prior operations on that queue have completed.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002590 RetireWorkOnQueue(GetQueueState(fence_state->signaler.first), fence_state->signaler.second);
locke-lunargd556cc32019-09-17 01:21:23 -06002591 } else {
2592 // Fence signaller is the WSI. We're not tracking what the WSI op actually /was/ in CV yet, but we need to mark
2593 // the fence as retired.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002594 fence_state->state = FENCE_RETIRED;
locke-lunargd556cc32019-09-17 01:21:23 -06002595 }
2596 }
2597}
2598
2599void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
2600 VkBool32 waitAll, uint64_t timeout, VkResult result) {
2601 if (VK_SUCCESS != result) return;
2602
2603 // When we know that all fences are complete we can clean/remove their CBs
2604 if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
2605 for (uint32_t i = 0; i < fenceCount; i++) {
2606 RetireFence(pFences[i]);
2607 }
2608 }
2609 // NOTE : Alternate case not handled here is when some fences have completed. In
2610 // this case for app to guarantee which fences completed it will have to call
2611 // vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
2612}
2613
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002614void ValidationStateTracker::RetireTimelineSemaphore(VkSemaphore semaphore, uint64_t until_payload) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002615 auto semaphore_state = GetSemaphoreState(semaphore);
2616 if (semaphore_state) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002617 for (auto &pair : queueMap) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002618 QUEUE_STATE &queue_state = pair.second;
Tony-LunarG47d5e272020-04-07 15:35:55 -06002619 uint64_t max_seq = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002620 for (const auto &submission : queue_state.submissions) {
2621 for (const auto &signal_semaphore : submission.signalSemaphores) {
2622 if (signal_semaphore.semaphore == semaphore && signal_semaphore.payload <= until_payload) {
2623 if (signal_semaphore.seq > max_seq) {
2624 max_seq = signal_semaphore.seq;
Tony-LunarG47d5e272020-04-07 15:35:55 -06002625 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002626 }
2627 }
2628 }
Tony-LunarG47d5e272020-04-07 15:35:55 -06002629 if (max_seq) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002630 RetireWorkOnQueue(&queue_state, max_seq);
Tony-LunarG47d5e272020-04-07 15:35:55 -06002631 }
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002632 }
2633 }
2634}
2635
John Zulauff89de662020-04-13 18:57:34 -06002636void ValidationStateTracker::RecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
2637 VkResult result) {
Jakub Okoński04feb3b2020-02-01 18:31:01 +01002638 if (VK_SUCCESS != result) return;
2639
2640 for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
2641 RetireTimelineSemaphore(pWaitInfo->pSemaphores[i], pWaitInfo->pValues[i]);
2642 }
2643}
2644
John Zulauff89de662020-04-13 18:57:34 -06002645void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
2646 VkResult result) {
2647 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
2648}
2649
2650void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
2651 uint64_t timeout, VkResult result) {
2652 RecordWaitSemaphores(device, pWaitInfo, timeout, result);
2653}
2654
Adrian Coca Lorentec7d76102020-09-28 13:58:16 +02002655void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
2656 VkResult result) {
2657 if (VK_SUCCESS != result) return;
2658
2659 RetireTimelineSemaphore(semaphore, *pValue);
2660}
2661
2662void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
2663 VkResult result) {
2664 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
2665}
2666void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
2667 VkResult result) {
2668 RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
2669}
2670
locke-lunargd556cc32019-09-17 01:21:23 -06002671void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
2672 if (VK_SUCCESS != result) return;
2673 RetireFence(fence);
2674}
2675
2676void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkQueue queue) {
2677 // Add queue to tracking set only if it is new
2678 auto queue_is_new = queues.emplace(queue);
2679 if (queue_is_new.second == true) {
2680 QUEUE_STATE *queue_state = &queueMap[queue];
2681 queue_state->queue = queue;
2682 queue_state->queueFamilyIndex = queue_family_index;
2683 queue_state->seq = 0;
2684 }
2685}
2686
2687void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
2688 VkQueue *pQueue) {
2689 RecordGetDeviceQueueState(queueFamilyIndex, *pQueue);
2690}
2691
2692void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
2693 RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, *pQueue);
2694}
2695
2696void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
2697 if (VK_SUCCESS != result) return;
2698 QUEUE_STATE *queue_state = GetQueueState(queue);
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002699 RetireWorkOnQueue(queue_state, queue_state->seq + queue_state->submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06002700}
2701
2702void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
2703 if (VK_SUCCESS != result) return;
2704 for (auto &queue : queueMap) {
Jeff Bolz8041c5b2019-10-20 22:14:20 -05002705 RetireWorkOnQueue(&queue.second, queue.second.seq + queue.second.submissions.size());
locke-lunargd556cc32019-09-17 01:21:23 -06002706 }
2707}
2708
2709void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
2710 if (!fence) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002711 auto fence_state = GetFenceState(fence);
2712 fence_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002713 fenceMap.erase(fence);
2714}
2715
2716void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
2717 const VkAllocationCallbacks *pAllocator) {
2718 if (!semaphore) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002719 auto semaphore_state = GetSemaphoreState(semaphore);
2720 semaphore_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002721 semaphoreMap.erase(semaphore);
2722}
2723
2724void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
2725 if (!event) return;
2726 EVENT_STATE *event_state = GetEventState(event);
2727 const VulkanTypedHandle obj_struct(event, kVulkanObjectTypeEvent);
2728 InvalidateCommandBuffers(event_state->cb_bindings, obj_struct);
2729 eventMap.erase(event);
2730}
2731
2732void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
2733 const VkAllocationCallbacks *pAllocator) {
2734 if (!queryPool) return;
2735 QUERY_POOL_STATE *qp_state = GetQueryPoolState(queryPool);
2736 const VulkanTypedHandle obj_struct(queryPool, kVulkanObjectTypeQueryPool);
2737 InvalidateCommandBuffers(qp_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002738 qp_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002739 queryPoolMap.erase(queryPool);
2740}
2741
2742// Object with given handle is being bound to memory w/ given mem_info struct.
2743// Track the newly bound memory range with given memoryOffset
2744// Also scan any previous ranges, track aliased ranges with new range, and flag an error if a linear
2745// and non-linear range incorrectly overlap.
locke-lunargd556cc32019-09-17 01:21:23 -06002746void ValidationStateTracker::InsertMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info,
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002747 VkDeviceSize memoryOffset) {
locke-lunargd556cc32019-09-17 01:21:23 -06002748 if (typed_handle.type == kVulkanObjectTypeImage) {
2749 mem_info->bound_images.insert(typed_handle.Cast<VkImage>());
2750 } else if (typed_handle.type == kVulkanObjectTypeBuffer) {
locke-lunarg37c410a2020-02-17 17:34:13 -07002751 mem_info->bound_buffers.insert(typed_handle.Cast<VkBuffer>());
locke-lunargd556cc32019-09-17 01:21:23 -06002752 } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) {
locke-lunarg37c410a2020-02-17 17:34:13 -07002753 mem_info->bound_acceleration_structures.insert(typed_handle.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06002754 } else {
2755 // Unsupported object type
2756 assert(false);
2757 }
2758}
2759
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002760void ValidationStateTracker::InsertImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) {
2761 InsertMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info, mem_offset);
locke-lunargd556cc32019-09-17 01:21:23 -06002762}
2763
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002764void ValidationStateTracker::InsertBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info, VkDeviceSize mem_offset) {
2765 InsertMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info, mem_offset);
locke-lunargd556cc32019-09-17 01:21:23 -06002766}
2767
2768void ValidationStateTracker::InsertAccelerationStructureMemoryRange(VkAccelerationStructureNV as, DEVICE_MEMORY_STATE *mem_info,
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002769 VkDeviceSize mem_offset) {
2770 InsertMemoryRange(VulkanTypedHandle(as, kVulkanObjectTypeAccelerationStructureNV), mem_info, mem_offset);
locke-lunargd556cc32019-09-17 01:21:23 -06002771}
2772
2773// This function will remove the handle-to-index mapping from the appropriate map.
2774static void RemoveMemoryRange(const VulkanTypedHandle &typed_handle, DEVICE_MEMORY_STATE *mem_info) {
2775 if (typed_handle.type == kVulkanObjectTypeImage) {
2776 mem_info->bound_images.erase(typed_handle.Cast<VkImage>());
2777 } else if (typed_handle.type == kVulkanObjectTypeBuffer) {
locke-lunarg37c410a2020-02-17 17:34:13 -07002778 mem_info->bound_buffers.erase(typed_handle.Cast<VkBuffer>());
locke-lunargd556cc32019-09-17 01:21:23 -06002779 } else if (typed_handle.type == kVulkanObjectTypeAccelerationStructureNV) {
locke-lunarg37c410a2020-02-17 17:34:13 -07002780 mem_info->bound_acceleration_structures.erase(typed_handle.Cast<VkAccelerationStructureNV>());
locke-lunargd556cc32019-09-17 01:21:23 -06002781 } else {
2782 // Unsupported object type
2783 assert(false);
2784 }
2785}
2786
2787void ValidationStateTracker::RemoveBufferMemoryRange(VkBuffer buffer, DEVICE_MEMORY_STATE *mem_info) {
2788 RemoveMemoryRange(VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer), mem_info);
2789}
2790
2791void ValidationStateTracker::RemoveImageMemoryRange(VkImage image, DEVICE_MEMORY_STATE *mem_info) {
2792 RemoveMemoryRange(VulkanTypedHandle(image, kVulkanObjectTypeImage), mem_info);
2793}
2794
locke-lunargd556cc32019-09-17 01:21:23 -06002795void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
2796 BUFFER_STATE *buffer_state = GetBufferState(buffer);
2797 if (buffer_state) {
2798 // Track bound memory range information
2799 auto mem_info = GetDevMemState(mem);
2800 if (mem_info) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002801 InsertBufferMemoryRange(buffer, mem_info, memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06002802 }
2803 // Track objects tied to memory
2804 SetMemBinding(mem, buffer_state, memoryOffset, VulkanTypedHandle(buffer, kVulkanObjectTypeBuffer));
2805 }
2806}
2807
2808void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
2809 VkDeviceSize memoryOffset, VkResult result) {
2810 if (VK_SUCCESS != result) return;
2811 UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
2812}
2813
2814void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002815 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002816 for (uint32_t i = 0; i < bindInfoCount; i++) {
2817 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
2818 }
2819}
2820
2821void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002822 const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06002823 for (uint32_t i = 0; i < bindInfoCount; i++) {
2824 UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
2825 }
2826}
2827
Spencer Fricke6c127102020-04-16 06:25:20 -07002828void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
locke-lunargd556cc32019-09-17 01:21:23 -06002829 BUFFER_STATE *buffer_state = GetBufferState(buffer);
2830 if (buffer_state) {
locke-lunargd556cc32019-09-17 01:21:23 -06002831 buffer_state->memory_requirements_checked = true;
2832 }
2833}
2834
2835void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
2836 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002837 RecordGetBufferMemoryRequirementsState(buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002838}
2839
2840void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002841 const VkBufferMemoryRequirementsInfo2 *pInfo,
2842 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002843 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002844}
2845
2846void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08002847 const VkBufferMemoryRequirementsInfo2 *pInfo,
2848 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002849 RecordGetBufferMemoryRequirementsState(pInfo->buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06002850}
2851
Spencer Fricke6c127102020-04-16 06:25:20 -07002852void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002853 const VkImagePlaneMemoryRequirementsInfo *plane_info =
2854 (pInfo == nullptr) ? nullptr : lvl_find_in_chain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06002855 IMAGE_STATE *image_state = GetImageState(image);
2856 if (image_state) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002857 if (plane_info != nullptr) {
2858 // Multi-plane image
2859 image_state->memory_requirements_checked = false; // Each image plane needs to be checked itself
2860 if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
2861 image_state->plane0_memory_requirements_checked = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002862 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
2863 image_state->plane1_memory_requirements_checked = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002864 } else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
2865 image_state->plane2_memory_requirements_checked = true;
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002866 }
2867 } else {
2868 // Single Plane image
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07002869 image_state->memory_requirements_checked = true;
2870 }
locke-lunargd556cc32019-09-17 01:21:23 -06002871 }
2872}
2873
2874void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
2875 VkMemoryRequirements *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002876 RecordGetImageMemoryRequirementsState(image, nullptr);
locke-lunargd556cc32019-09-17 01:21:23 -06002877}
2878
2879void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
2880 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002881 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002882}
2883
2884void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
2885 const VkImageMemoryRequirementsInfo2 *pInfo,
2886 VkMemoryRequirements2 *pMemoryRequirements) {
Spencer Fricke6c127102020-04-16 06:25:20 -07002887 RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06002888}
2889
2890static void RecordGetImageSparseMemoryRequirementsState(IMAGE_STATE *image_state,
2891 VkSparseImageMemoryRequirements *sparse_image_memory_requirements) {
2892 image_state->sparse_requirements.emplace_back(*sparse_image_memory_requirements);
2893 if (sparse_image_memory_requirements->formatProperties.aspectMask & VK_IMAGE_ASPECT_METADATA_BIT) {
2894 image_state->sparse_metadata_required = true;
2895 }
2896}
2897
2898void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
2899 VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
2900 VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
2901 auto image_state = GetImageState(image);
2902 image_state->get_sparse_reqs_called = true;
2903 if (!pSparseMemoryRequirements) return;
2904 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2905 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i]);
2906 }
2907}
2908
2909void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002910 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2911 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002912 auto image_state = GetImageState(pInfo->image);
2913 image_state->get_sparse_reqs_called = true;
2914 if (!pSparseMemoryRequirements) return;
2915 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2916 assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it
2917 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements);
2918 }
2919}
2920
2921void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08002922 VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
2923 VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
locke-lunargd556cc32019-09-17 01:21:23 -06002924 auto image_state = GetImageState(pInfo->image);
2925 image_state->get_sparse_reqs_called = true;
2926 if (!pSparseMemoryRequirements) return;
2927 for (uint32_t i = 0; i < *pSparseMemoryRequirementCount; i++) {
2928 assert(!pSparseMemoryRequirements[i].pNext); // TODO: If an extension is ever added here we need to handle it
2929 RecordGetImageSparseMemoryRequirementsState(image_state, &pSparseMemoryRequirements[i].memoryRequirements);
2930 }
2931}
2932
2933void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
2934 const VkAllocationCallbacks *pAllocator) {
2935 if (!shaderModule) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002936 auto shader_module_state = GetShaderModuleState(shaderModule);
2937 shader_module_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002938 shaderModuleMap.erase(shaderModule);
2939}
2940
2941void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
2942 const VkAllocationCallbacks *pAllocator) {
2943 if (!pipeline) return;
2944 PIPELINE_STATE *pipeline_state = GetPipelineState(pipeline);
2945 const VulkanTypedHandle obj_struct(pipeline, kVulkanObjectTypePipeline);
2946 // Any bound cmd buffers are now invalid
2947 InvalidateCommandBuffers(pipeline_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002948 pipeline_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002949 pipelineMap.erase(pipeline);
2950}
2951
2952void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
2953 const VkAllocationCallbacks *pAllocator) {
2954 if (!pipelineLayout) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002955 auto pipeline_layout_state = GetPipelineLayout(pipelineLayout);
2956 pipeline_layout_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002957 pipelineLayoutMap.erase(pipelineLayout);
2958}
2959
2960void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
2961 const VkAllocationCallbacks *pAllocator) {
2962 if (!sampler) return;
2963 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
2964 const VulkanTypedHandle obj_struct(sampler, kVulkanObjectTypeSampler);
2965 // Any bound cmd buffers are now invalid
2966 if (sampler_state) {
2967 InvalidateCommandBuffers(sampler_state->cb_bindings, obj_struct);
Yuly Novikov424cdd52020-05-26 16:45:12 -04002968
2969 if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
2970 sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
2971 custom_border_color_sampler_count--;
2972 }
2973
2974 sampler_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002975 }
2976 samplerMap.erase(sampler);
2977}
2978
2979void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
2980 const VkAllocationCallbacks *pAllocator) {
2981 if (!descriptorSetLayout) return;
2982 auto layout_it = descriptorSetLayoutMap.find(descriptorSetLayout);
2983 if (layout_it != descriptorSetLayoutMap.end()) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05002984 layout_it->second.get()->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06002985 descriptorSetLayoutMap.erase(layout_it);
2986 }
2987}
2988
2989void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
2990 const VkAllocationCallbacks *pAllocator) {
2991 if (!descriptorPool) return;
2992 DESCRIPTOR_POOL_STATE *desc_pool_state = GetDescriptorPoolState(descriptorPool);
2993 const VulkanTypedHandle obj_struct(descriptorPool, kVulkanObjectTypeDescriptorPool);
2994 if (desc_pool_state) {
2995 // Any bound cmd buffers are now invalid
2996 InvalidateCommandBuffers(desc_pool_state->cb_bindings, obj_struct);
2997 // Free sets that were in this pool
2998 for (auto ds : desc_pool_state->sets) {
2999 FreeDescriptorSet(ds);
3000 }
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003001 desc_pool_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003002 descriptorPoolMap.erase(descriptorPool);
3003 }
3004}
3005
3006// Free all command buffers in given list, removing all references/links to them using ResetCommandBufferState
3007void ValidationStateTracker::FreeCommandBufferStates(COMMAND_POOL_STATE *pool_state, const uint32_t command_buffer_count,
3008 const VkCommandBuffer *command_buffers) {
3009 for (uint32_t i = 0; i < command_buffer_count; i++) {
John Zulaufd1f85d42020-04-15 12:23:15 -06003010 // Allow any derived class to clean up command buffer state
3011 if (command_buffer_free_callback) {
3012 (*command_buffer_free_callback)(command_buffers[i]);
3013 }
3014
locke-lunargd556cc32019-09-17 01:21:23 -06003015 auto cb_state = GetCBState(command_buffers[i]);
3016 // Remove references to command buffer's state and delete
3017 if (cb_state) {
3018 // reset prior to delete, removing various references to it.
3019 // TODO: fix this, it's insane.
3020 ResetCommandBufferState(cb_state->commandBuffer);
3021 // Remove the cb_state's references from COMMAND_POOL_STATEs
3022 pool_state->commandBuffers.erase(command_buffers[i]);
3023 // Remove the cb debug labels
3024 EraseCmdDebugUtilsLabel(report_data, cb_state->commandBuffer);
3025 // Remove CBState from CB map
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003026 cb_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003027 commandBufferMap.erase(cb_state->commandBuffer);
3028 }
3029 }
3030}
3031
3032void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
3033 uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003034 auto pool = GetCommandPoolState(commandPool);
3035 FreeCommandBufferStates(pool, commandBufferCount, pCommandBuffers);
locke-lunargd556cc32019-09-17 01:21:23 -06003036}
3037
3038void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
3039 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
3040 VkResult result) {
3041 if (VK_SUCCESS != result) return;
sfricke-samsungc1543372020-08-18 22:37:27 -07003042 VkCommandPool command_pool = *pCommandPool;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003043 auto cmd_pool_state = std::make_shared<COMMAND_POOL_STATE>();
sfricke-samsungc1543372020-08-18 22:37:27 -07003044 cmd_pool_state->commandPool = command_pool;
locke-lunargd556cc32019-09-17 01:21:23 -06003045 cmd_pool_state->createFlags = pCreateInfo->flags;
3046 cmd_pool_state->queueFamilyIndex = pCreateInfo->queueFamilyIndex;
sfricke-samsung0c45edc2020-07-01 22:19:53 -07003047 cmd_pool_state->unprotected = ((pCreateInfo->flags & VK_COMMAND_POOL_CREATE_PROTECTED_BIT) == 0);
sfricke-samsungc1543372020-08-18 22:37:27 -07003048 commandPoolMap[command_pool] = std::move(cmd_pool_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003049}
3050
3051void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
3052 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
3053 VkResult result) {
3054 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003055 auto query_pool_state = std::make_shared<QUERY_POOL_STATE>();
locke-lunargd556cc32019-09-17 01:21:23 -06003056 query_pool_state->createInfo = *pCreateInfo;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003057 query_pool_state->pool = *pQueryPool;
3058 if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
3059 const auto *perf = lvl_find_in_chain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06003060 query_pool_state->perf_counter_index_count = perf->counterIndexCount;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003061
Mark Lobodzinski7e948e42020-09-09 10:23:36 -06003062 const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003063 for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
3064 const auto &counter = counters.counters[perf->pCounterIndices[i]];
3065 switch (counter.scope) {
3066 case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
3067 query_pool_state->has_perf_scope_command_buffer = true;
3068 break;
3069 case VK_QUERY_SCOPE_RENDER_PASS_KHR:
3070 query_pool_state->has_perf_scope_render_pass = true;
3071 break;
3072 default:
3073 break;
3074 }
3075 }
3076
3077 DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->phys_device, perf,
3078 &query_pool_state->n_performance_passes);
3079 }
3080
locke-lunargd556cc32019-09-17 01:21:23 -06003081 queryPoolMap[*pQueryPool] = std::move(query_pool_state);
3082
3083 QueryObject query_obj{*pQueryPool, 0u};
3084 for (uint32_t i = 0; i < pCreateInfo->queryCount; ++i) {
3085 query_obj.query = i;
3086 queryToStateMap[query_obj] = QUERYSTATE_UNKNOWN;
3087 }
3088}
3089
3090void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
3091 const VkAllocationCallbacks *pAllocator) {
3092 if (!commandPool) return;
3093 COMMAND_POOL_STATE *cp_state = GetCommandPoolState(commandPool);
3094 // Remove cmdpool from cmdpoolmap, after freeing layer data for the command buffers
3095 // "When a pool is destroyed, all command buffers allocated from the pool are freed."
3096 if (cp_state) {
3097 // Create a vector, as FreeCommandBufferStates deletes from cp_state->commandBuffers during iteration.
3098 std::vector<VkCommandBuffer> cb_vec{cp_state->commandBuffers.begin(), cp_state->commandBuffers.end()};
3099 FreeCommandBufferStates(cp_state, static_cast<uint32_t>(cb_vec.size()), cb_vec.data());
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003100 cp_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003101 commandPoolMap.erase(commandPool);
3102 }
3103}
3104
3105void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
3106 VkCommandPoolResetFlags flags, VkResult result) {
3107 if (VK_SUCCESS != result) return;
3108 // Reset all of the CBs allocated from this pool
3109 auto command_pool_state = GetCommandPoolState(commandPool);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003110 for (auto cmd_buffer : command_pool_state->commandBuffers) {
3111 ResetCommandBufferState(cmd_buffer);
locke-lunargd556cc32019-09-17 01:21:23 -06003112 }
3113}
3114
3115void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
3116 VkResult result) {
3117 for (uint32_t i = 0; i < fenceCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003118 auto fence_state = GetFenceState(pFences[i]);
3119 if (fence_state) {
3120 if (fence_state->scope == kSyncScopeInternal) {
3121 fence_state->state = FENCE_UNSIGNALED;
3122 } else if (fence_state->scope == kSyncScopeExternalTemporary) {
3123 fence_state->scope = kSyncScopeInternal;
locke-lunargd556cc32019-09-17 01:21:23 -06003124 }
3125 }
3126 }
3127}
3128
Jeff Bolzadbfa852019-10-04 13:53:30 -05003129// For given cb_nodes, invalidate them and track object causing invalidation.
3130// InvalidateCommandBuffers and InvalidateLinkedCommandBuffers are essentially
3131// the same, except one takes a map and one takes a set, and InvalidateCommandBuffers
3132// can also unlink objects from command buffers.
3133void ValidationStateTracker::InvalidateCommandBuffers(small_unordered_map<CMD_BUFFER_STATE *, int, 8> &cb_nodes,
3134 const VulkanTypedHandle &obj, bool unlink) {
3135 for (const auto &cb_node_pair : cb_nodes) {
3136 auto &cb_node = cb_node_pair.first;
3137 if (cb_node->state == CB_RECORDING) {
3138 cb_node->state = CB_INVALID_INCOMPLETE;
3139 } else if (cb_node->state == CB_RECORDED) {
3140 cb_node->state = CB_INVALID_COMPLETE;
3141 }
3142 cb_node->broken_bindings.push_back(obj);
3143
3144 // if secondary, then propagate the invalidation to the primaries that will call us.
3145 if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
3146 InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj);
3147 }
3148 if (unlink) {
3149 int index = cb_node_pair.second;
3150 assert(cb_node->object_bindings[index] == obj);
3151 cb_node->object_bindings[index] = VulkanTypedHandle();
3152 }
3153 }
3154 if (unlink) {
3155 cb_nodes.clear();
3156 }
3157}
3158
3159void ValidationStateTracker::InvalidateLinkedCommandBuffers(std::unordered_set<CMD_BUFFER_STATE *> &cb_nodes,
3160 const VulkanTypedHandle &obj) {
locke-lunargd556cc32019-09-17 01:21:23 -06003161 for (auto cb_node : cb_nodes) {
3162 if (cb_node->state == CB_RECORDING) {
3163 cb_node->state = CB_INVALID_INCOMPLETE;
3164 } else if (cb_node->state == CB_RECORDED) {
3165 cb_node->state = CB_INVALID_COMPLETE;
3166 }
3167 cb_node->broken_bindings.push_back(obj);
3168
3169 // if secondary, then propagate the invalidation to the primaries that will call us.
3170 if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05003171 InvalidateLinkedCommandBuffers(cb_node->linkedCommandBuffers, obj);
locke-lunargd556cc32019-09-17 01:21:23 -06003172 }
3173 }
3174}
3175
3176void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
3177 const VkAllocationCallbacks *pAllocator) {
3178 if (!framebuffer) return;
3179 FRAMEBUFFER_STATE *framebuffer_state = GetFramebufferState(framebuffer);
3180 const VulkanTypedHandle obj_struct(framebuffer, kVulkanObjectTypeFramebuffer);
3181 InvalidateCommandBuffers(framebuffer_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003182 framebuffer_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003183 frameBufferMap.erase(framebuffer);
3184}
3185
3186void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
3187 const VkAllocationCallbacks *pAllocator) {
3188 if (!renderPass) return;
3189 RENDER_PASS_STATE *rp_state = GetRenderPassState(renderPass);
3190 const VulkanTypedHandle obj_struct(renderPass, kVulkanObjectTypeRenderPass);
3191 InvalidateCommandBuffers(rp_state->cb_bindings, obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003192 rp_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06003193 renderPassMap.erase(renderPass);
3194}
3195
3196void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
3197 const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
3198 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003199 auto fence_state = std::make_shared<FENCE_STATE>();
locke-lunargd556cc32019-09-17 01:21:23 -06003200 fence_state->fence = *pFence;
3201 fence_state->createInfo = *pCreateInfo;
3202 fence_state->state = (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) ? FENCE_RETIRED : FENCE_UNSIGNALED;
3203 fenceMap[*pFence] = std::move(fence_state);
3204}
3205
3206bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
3207 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3208 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05003209 void *cgpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003210 // Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
3211 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
3212 cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
3213 cgpl_state->pipe_state.reserve(count);
3214 for (uint32_t i = 0; i < count; i++) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003215 cgpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>());
Jeff Bolz6ae39612019-10-11 20:57:36 -05003216 (cgpl_state->pipe_state)[i]->initGraphicsPipeline(this, &pCreateInfos[i], GetRenderPassShared(pCreateInfos[i].renderPass));
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003217 (cgpl_state->pipe_state)[i]->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout);
locke-lunargd556cc32019-09-17 01:21:23 -06003218 }
3219 return false;
3220}
3221
3222void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
3223 const VkGraphicsPipelineCreateInfo *pCreateInfos,
3224 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
3225 VkResult result, void *cgpl_state_data) {
3226 create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
3227 // This API may create pipelines regardless of the return value
3228 for (uint32_t i = 0; i < count; i++) {
3229 if (pPipelines[i] != VK_NULL_HANDLE) {
3230 (cgpl_state->pipe_state)[i]->pipeline = pPipelines[i];
3231 pipelineMap[pPipelines[i]] = std::move((cgpl_state->pipe_state)[i]);
3232 }
3233 }
3234 cgpl_state->pipe_state.clear();
3235}
3236
3237bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
3238 const VkComputePipelineCreateInfo *pCreateInfos,
3239 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
Jeff Bolz5c801d12019-10-09 10:38:45 -05003240 void *ccpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003241 auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
3242 ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
3243 ccpl_state->pipe_state.reserve(count);
3244 for (uint32_t i = 0; i < count; i++) {
3245 // Create and initialize internal tracking data structure
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003246 ccpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>());
locke-lunargd556cc32019-09-17 01:21:23 -06003247 ccpl_state->pipe_state.back()->initComputePipeline(this, &pCreateInfos[i]);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003248 ccpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout);
locke-lunargd556cc32019-09-17 01:21:23 -06003249 }
3250 return false;
3251}
3252
3253void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
3254 const VkComputePipelineCreateInfo *pCreateInfos,
3255 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
3256 VkResult result, void *ccpl_state_data) {
3257 create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
3258
3259 // This API may create pipelines regardless of the return value
3260 for (uint32_t i = 0; i < count; i++) {
3261 if (pPipelines[i] != VK_NULL_HANDLE) {
3262 (ccpl_state->pipe_state)[i]->pipeline = pPipelines[i];
3263 pipelineMap[pPipelines[i]] = std::move((ccpl_state->pipe_state)[i]);
3264 }
3265 }
3266 ccpl_state->pipe_state.clear();
3267}
3268
3269bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
3270 uint32_t count,
3271 const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
3272 const VkAllocationCallbacks *pAllocator,
Jeff Bolz5c801d12019-10-09 10:38:45 -05003273 VkPipeline *pPipelines, void *crtpl_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003274 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
3275 crtpl_state->pipe_state.reserve(count);
3276 for (uint32_t i = 0; i < count; i++) {
3277 // Create and initialize internal tracking data structure
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003278 crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>());
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003279 crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003280 crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout);
locke-lunargd556cc32019-09-17 01:21:23 -06003281 }
3282 return false;
3283}
3284
3285void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
3286 VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
3287 const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
3288 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
3289 // This API may create pipelines regardless of the return value
3290 for (uint32_t i = 0; i < count; i++) {
3291 if (pPipelines[i] != VK_NULL_HANDLE) {
3292 (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i];
3293 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
3294 }
3295 }
3296 crtpl_state->pipe_state.clear();
3297}
3298
sourav parmarcd5fb182020-07-17 12:58:44 -07003299bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
3300 VkPipelineCache pipelineCache, uint32_t count,
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003301 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
3302 const VkAllocationCallbacks *pAllocator,
3303 VkPipeline *pPipelines, void *crtpl_state_data) const {
3304 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
3305 crtpl_state->pipe_state.reserve(count);
3306 for (uint32_t i = 0; i < count; i++) {
3307 // Create and initialize internal tracking data structure
3308 crtpl_state->pipe_state.push_back(std::make_shared<PIPELINE_STATE>());
3309 crtpl_state->pipe_state.back()->initRayTracingPipeline(this, &pCreateInfos[i]);
3310 crtpl_state->pipe_state.back()->pipeline_layout = GetPipelineLayoutShared(pCreateInfos[i].layout);
3311 }
3312 return false;
3313}
3314
sourav parmarcd5fb182020-07-17 12:58:44 -07003315void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
3316 VkPipelineCache pipelineCache, uint32_t count,
3317 const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
3318 const VkAllocationCallbacks *pAllocator,
3319 VkPipeline *pPipelines, VkResult result,
3320 void *crtpl_state_data) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003321 auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
3322 // This API may create pipelines regardless of the return value
3323 for (uint32_t i = 0; i < count; i++) {
3324 if (pPipelines[i] != VK_NULL_HANDLE) {
3325 (crtpl_state->pipe_state)[i]->pipeline = pPipelines[i];
3326 pipelineMap[pPipelines[i]] = std::move((crtpl_state->pipe_state)[i]);
3327 }
3328 }
3329 crtpl_state->pipe_state.clear();
3330}
3331
locke-lunargd556cc32019-09-17 01:21:23 -06003332void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
3333 const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
3334 VkResult result) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003335 samplerMap[*pSampler] = std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003336 if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
3337 pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
Tony-LunarG7337b312020-04-15 16:40:25 -06003338 custom_border_color_sampler_count++;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003339 }
locke-lunargd556cc32019-09-17 01:21:23 -06003340}
3341
3342void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
3343 const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
3344 const VkAllocationCallbacks *pAllocator,
3345 VkDescriptorSetLayout *pSetLayout, VkResult result) {
3346 if (VK_SUCCESS != result) return;
3347 descriptorSetLayoutMap[*pSetLayout] = std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout);
3348}
3349
3350// For repeatable sorting, not very useful for "memory in range" search
3351struct PushConstantRangeCompare {
3352 bool operator()(const VkPushConstantRange *lhs, const VkPushConstantRange *rhs) const {
3353 if (lhs->offset == rhs->offset) {
3354 if (lhs->size == rhs->size) {
3355 // The comparison is arbitrary, but avoids false aliasing by comparing all fields.
3356 return lhs->stageFlags < rhs->stageFlags;
3357 }
3358 // If the offsets are the same then sorting by the end of range is useful for validation
3359 return lhs->size < rhs->size;
3360 }
3361 return lhs->offset < rhs->offset;
3362 }
3363};
3364
3365static PushConstantRangesDict push_constant_ranges_dict;
3366
3367PushConstantRangesId GetCanonicalId(const VkPipelineLayoutCreateInfo *info) {
3368 if (!info->pPushConstantRanges) {
3369 // Hand back the empty entry (creating as needed)...
3370 return push_constant_ranges_dict.look_up(PushConstantRanges());
3371 }
3372
3373 // Sort the input ranges to ensure equivalent ranges map to the same id
3374 std::set<const VkPushConstantRange *, PushConstantRangeCompare> sorted;
3375 for (uint32_t i = 0; i < info->pushConstantRangeCount; i++) {
3376 sorted.insert(info->pPushConstantRanges + i);
3377 }
3378
Jeremy Hayesf34b9fb2019-12-06 09:37:03 -07003379 PushConstantRanges ranges;
3380 ranges.reserve(sorted.size());
locke-lunargd556cc32019-09-17 01:21:23 -06003381 for (const auto range : sorted) {
3382 ranges.emplace_back(*range);
3383 }
3384 return push_constant_ranges_dict.look_up(std::move(ranges));
3385}
3386
3387// Dictionary of canoncial form of the pipeline set layout of descriptor set layouts
3388static PipelineLayoutSetLayoutsDict pipeline_layout_set_layouts_dict;
3389
3390// Dictionary of canonical form of the "compatible for set" records
3391static PipelineLayoutCompatDict pipeline_layout_compat_dict;
3392
3393static PipelineLayoutCompatId GetCanonicalId(const uint32_t set_index, const PushConstantRangesId pcr_id,
3394 const PipelineLayoutSetLayoutsId set_layouts_id) {
3395 return pipeline_layout_compat_dict.look_up(PipelineLayoutCompatDef(set_index, pcr_id, set_layouts_id));
3396}
3397
3398void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
3399 const VkAllocationCallbacks *pAllocator,
3400 VkPipelineLayout *pPipelineLayout, VkResult result) {
3401 if (VK_SUCCESS != result) return;
3402
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003403 auto pipeline_layout_state = std::make_shared<PIPELINE_LAYOUT_STATE>();
locke-lunargd556cc32019-09-17 01:21:23 -06003404 pipeline_layout_state->layout = *pPipelineLayout;
3405 pipeline_layout_state->set_layouts.resize(pCreateInfo->setLayoutCount);
3406 PipelineLayoutSetLayoutsDef set_layouts(pCreateInfo->setLayoutCount);
3407 for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05003408 pipeline_layout_state->set_layouts[i] = GetDescriptorSetLayoutShared(pCreateInfo->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003409 set_layouts[i] = pipeline_layout_state->set_layouts[i]->GetLayoutId();
3410 }
3411
3412 // Get canonical form IDs for the "compatible for set" contents
3413 pipeline_layout_state->push_constant_ranges = GetCanonicalId(pCreateInfo);
3414 auto set_layouts_id = pipeline_layout_set_layouts_dict.look_up(set_layouts);
3415 pipeline_layout_state->compat_for_set.reserve(pCreateInfo->setLayoutCount);
3416
3417 // Create table of "compatible for set N" cannonical forms for trivial accept validation
3418 for (uint32_t i = 0; i < pCreateInfo->setLayoutCount; ++i) {
3419 pipeline_layout_state->compat_for_set.emplace_back(
3420 GetCanonicalId(i, pipeline_layout_state->push_constant_ranges, set_layouts_id));
3421 }
3422 pipelineLayoutMap[*pPipelineLayout] = std::move(pipeline_layout_state);
3423}
3424
3425void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
3426 const VkAllocationCallbacks *pAllocator,
3427 VkDescriptorPool *pDescriptorPool, VkResult result) {
3428 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003429 descriptorPoolMap[*pDescriptorPool] = std::make_shared<DESCRIPTOR_POOL_STATE>(*pDescriptorPool, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06003430}
3431
3432void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
3433 VkDescriptorPoolResetFlags flags, VkResult result) {
3434 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003435 DESCRIPTOR_POOL_STATE *pool = GetDescriptorPoolState(descriptorPool);
locke-lunargd556cc32019-09-17 01:21:23 -06003436 // TODO: validate flags
3437 // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003438 for (auto ds : pool->sets) {
locke-lunargd556cc32019-09-17 01:21:23 -06003439 FreeDescriptorSet(ds);
3440 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003441 pool->sets.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06003442 // Reset available count for each type and available sets for this pool
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003443 for (auto it = pool->availableDescriptorTypeCount.begin(); it != pool->availableDescriptorTypeCount.end(); ++it) {
3444 pool->availableDescriptorTypeCount[it->first] = pool->maxDescriptorTypeCount[it->first];
locke-lunargd556cc32019-09-17 01:21:23 -06003445 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003446 pool->availableSets = pool->maxSets;
locke-lunargd556cc32019-09-17 01:21:23 -06003447}
3448
3449bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
3450 const VkDescriptorSetAllocateInfo *pAllocateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05003451 VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06003452 // Always update common data
3453 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
3454 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
3455 UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
3456
3457 return false;
3458}
3459
3460// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
3461void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
3462 VkDescriptorSet *pDescriptorSets, VkResult result,
3463 void *ads_state_data) {
3464 if (VK_SUCCESS != result) return;
3465 // All the updates are contained in a single cvdescriptorset function
3466 cvdescriptorset::AllocateDescriptorSetsData *ads_state =
3467 reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
3468 PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, ads_state);
3469}
3470
3471void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
3472 const VkDescriptorSet *pDescriptorSets) {
3473 DESCRIPTOR_POOL_STATE *pool_state = GetDescriptorPoolState(descriptorPool);
3474 // Update available descriptor sets in pool
3475 pool_state->availableSets += count;
3476
3477 // For each freed descriptor add its resources back into the pool as available and remove from pool and setMap
3478 for (uint32_t i = 0; i < count; ++i) {
3479 if (pDescriptorSets[i] != VK_NULL_HANDLE) {
3480 auto descriptor_set = setMap[pDescriptorSets[i]].get();
3481 uint32_t type_index = 0, descriptor_count = 0;
3482 for (uint32_t j = 0; j < descriptor_set->GetBindingCount(); ++j) {
3483 type_index = static_cast<uint32_t>(descriptor_set->GetTypeFromIndex(j));
3484 descriptor_count = descriptor_set->GetDescriptorCountFromIndex(j);
3485 pool_state->availableDescriptorTypeCount[type_index] += descriptor_count;
3486 }
3487 FreeDescriptorSet(descriptor_set);
3488 pool_state->sets.erase(descriptor_set);
3489 }
3490 }
3491}
3492
3493void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
3494 const VkWriteDescriptorSet *pDescriptorWrites,
3495 uint32_t descriptorCopyCount,
3496 const VkCopyDescriptorSet *pDescriptorCopies) {
3497 cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
3498 pDescriptorCopies);
3499}
3500
3501void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
3502 VkCommandBuffer *pCommandBuffer, VkResult result) {
3503 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003504 auto pool = GetCommandPoolShared(pCreateInfo->commandPool);
3505 if (pool) {
locke-lunargd556cc32019-09-17 01:21:23 -06003506 for (uint32_t i = 0; i < pCreateInfo->commandBufferCount; i++) {
3507 // Add command buffer to its commandPool map
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003508 pool->commandBuffers.insert(pCommandBuffer[i]);
3509 auto cb_state = std::make_shared<CMD_BUFFER_STATE>();
3510 cb_state->createInfo = *pCreateInfo;
3511 cb_state->command_pool = pool;
3512 cb_state->unprotected = pool->unprotected;
locke-lunargd556cc32019-09-17 01:21:23 -06003513 // Add command buffer to map
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003514 commandBufferMap[pCommandBuffer[i]] = std::move(cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06003515 ResetCommandBufferState(pCommandBuffer[i]);
3516 }
3517 }
3518}
3519
3520// Add bindings between the given cmd buffer & framebuffer and the framebuffer's children
3521void ValidationStateTracker::AddFramebufferBinding(CMD_BUFFER_STATE *cb_state, FRAMEBUFFER_STATE *fb_state) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05003522 AddCommandBufferBinding(fb_state->cb_bindings, VulkanTypedHandle(fb_state->framebuffer, kVulkanObjectTypeFramebuffer, fb_state),
locke-lunargd556cc32019-09-17 01:21:23 -06003523 cb_state);
Mark Lobodzinski544b3dd2019-12-03 14:44:54 -07003524 // If imageless fb, skip fb binding
Mike Schuchardt2df08912020-12-15 16:28:09 -08003525 if (!fb_state || fb_state->createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003526 const uint32_t attachment_count = fb_state->createInfo.attachmentCount;
3527 for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) {
locke-lunargfc78e932020-11-19 17:06:24 -07003528 auto view_state = GetActiveAttachmentImageViewState(cb_state, attachment);
locke-lunargd556cc32019-09-17 01:21:23 -06003529 if (view_state) {
3530 AddCommandBufferBindingImageView(cb_state, view_state);
3531 }
3532 }
3533}
3534
locke-lunargfc78e932020-11-19 17:06:24 -07003535void UpdateSubpassAttachments(const safe_VkSubpassDescription2 &subpass, std::vector<SUBPASS_INFO> &subpasses) {
3536 for (uint32_t index = 0; index < subpass.inputAttachmentCount; ++index) {
3537 const uint32_t attachment_index = subpass.pInputAttachments[index].attachment;
3538 if (attachment_index != VK_ATTACHMENT_UNUSED) {
3539 subpasses[attachment_index].used = true;
3540 subpasses[attachment_index].usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
3541 subpasses[attachment_index].layout = subpass.pInputAttachments[index].layout;
3542 }
3543 }
3544
3545 for (uint32_t index = 0; index < subpass.colorAttachmentCount; ++index) {
3546 const uint32_t attachment_index = subpass.pColorAttachments[index].attachment;
3547 if (attachment_index != VK_ATTACHMENT_UNUSED) {
3548 subpasses[attachment_index].used = true;
3549 subpasses[attachment_index].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
3550 subpasses[attachment_index].layout = subpass.pColorAttachments[index].layout;
3551 }
3552 if (subpass.pResolveAttachments) {
3553 const uint32_t attachment_index2 = subpass.pResolveAttachments[index].attachment;
3554 if (attachment_index2 != VK_ATTACHMENT_UNUSED) {
3555 subpasses[attachment_index2].used = true;
3556 subpasses[attachment_index2].usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
3557 subpasses[attachment_index2].layout = subpass.pResolveAttachments[index].layout;
3558 }
3559 }
3560 }
3561
3562 if (subpass.pDepthStencilAttachment) {
3563 const uint32_t attachment_index = subpass.pDepthStencilAttachment->attachment;
3564 if (attachment_index != VK_ATTACHMENT_UNUSED) {
3565 subpasses[attachment_index].used = true;
3566 subpasses[attachment_index].usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
3567 subpasses[attachment_index].layout = subpass.pDepthStencilAttachment->layout;
3568 }
3569 }
3570}
3571
3572void UpdateAttachmentsView(ValidationStateTracker &tracker, CMD_BUFFER_STATE &cb_state, const FRAMEBUFFER_STATE &framebuffer,
3573 const VkRenderPassBeginInfo *pRenderPassBegin) {
3574 auto &attachments = *(cb_state.active_attachments.get());
3575 const bool imageless = (framebuffer.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) ? true : false;
3576 const VkRenderPassAttachmentBeginInfo *attachment_info_struct = nullptr;
3577 if (pRenderPassBegin) attachment_info_struct = lvl_find_in_chain<VkRenderPassAttachmentBeginInfo>(pRenderPassBegin->pNext);
3578
3579 for (uint32_t i = 0; i < attachments.size(); ++i) {
3580 if (imageless) {
3581 if (attachment_info_struct && i < attachment_info_struct->attachmentCount) {
3582 auto res = cb_state.attachments_view_states.insert(
3583 tracker.GetShared<IMAGE_VIEW_STATE>(attachment_info_struct->pAttachments[i]));
3584 attachments[i] = res.first->get();
3585 }
3586 } else {
3587 auto res = cb_state.attachments_view_states.insert(framebuffer.attachments_view_state[i]);
3588 attachments[i] = res.first->get();
3589 }
3590 }
3591}
3592
locke-lunargd556cc32019-09-17 01:21:23 -06003593void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
3594 const VkCommandBufferBeginInfo *pBeginInfo) {
3595 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3596 if (!cb_state) return;
locke-lunargfc78e932020-11-19 17:06:24 -07003597
locke-lunargd556cc32019-09-17 01:21:23 -06003598 if (CB_RECORDED == cb_state->state || CB_INVALID_COMPLETE == cb_state->state) {
3599 ResetCommandBufferState(commandBuffer);
3600 }
3601 // Set updated state here in case implicit reset occurs above
3602 cb_state->state = CB_RECORDING;
3603 cb_state->beginInfo = *pBeginInfo;
3604 if (cb_state->beginInfo.pInheritanceInfo) {
3605 cb_state->inheritanceInfo = *(cb_state->beginInfo.pInheritanceInfo);
3606 cb_state->beginInfo.pInheritanceInfo = &cb_state->inheritanceInfo;
3607 // If we are a secondary command-buffer and inheriting. Update the items we should inherit.
3608 if ((cb_state->createInfo.level != VK_COMMAND_BUFFER_LEVEL_PRIMARY) &&
3609 (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT)) {
locke-lunargaecf2152020-05-12 17:15:41 -06003610 cb_state->activeRenderPass = GetShared<RENDER_PASS_STATE>(cb_state->beginInfo.pInheritanceInfo->renderPass);
locke-lunargd556cc32019-09-17 01:21:23 -06003611 cb_state->activeSubpass = cb_state->beginInfo.pInheritanceInfo->subpass;
locke-lunargfc78e932020-11-19 17:06:24 -07003612
locke-lunargaecf2152020-05-12 17:15:41 -06003613 if (cb_state->beginInfo.pInheritanceInfo->framebuffer) {
3614 cb_state->activeFramebuffer = GetShared<FRAMEBUFFER_STATE>(cb_state->beginInfo.pInheritanceInfo->framebuffer);
locke-lunargfc78e932020-11-19 17:06:24 -07003615 cb_state->active_subpasses = nullptr;
3616 cb_state->active_attachments = nullptr;
3617
3618 if (cb_state->activeFramebuffer) {
3619 cb_state->framebuffers.insert(cb_state->activeFramebuffer);
3620
3621 // Set cb_state->active_subpasses
3622 cb_state->active_subpasses =
3623 std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount);
3624 const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass];
3625 UpdateSubpassAttachments(subpass, *cb_state->active_subpasses);
3626
3627 // Set cb_state->active_attachments & cb_state->attachments_view_states
3628 cb_state->active_attachments =
3629 std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(cb_state->activeFramebuffer->createInfo.attachmentCount);
3630 UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, nullptr);
3631
3632 // Connect this framebuffer and its children to this cmdBuffer
3633 AddFramebufferBinding(cb_state, cb_state->activeFramebuffer.get());
3634 }
locke-lunargaecf2152020-05-12 17:15:41 -06003635 }
locke-lunargd556cc32019-09-17 01:21:23 -06003636 }
3637 }
3638
3639 auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupCommandBufferBeginInfo>(pBeginInfo->pNext);
3640 if (chained_device_group_struct) {
3641 cb_state->initial_device_mask = chained_device_group_struct->deviceMask;
3642 } else {
3643 cb_state->initial_device_mask = (1 << physical_device_count) - 1;
3644 }
Lionel Landwerlinc7420912019-05-23 00:33:42 +01003645
3646 cb_state->performance_lock_acquired = performance_lock_acquired;
locke-lunargd556cc32019-09-17 01:21:23 -06003647}
3648
3649void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
3650 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3651 if (!cb_state) return;
3652 // Cached validation is specific to a specific recording of a specific command buffer.
3653 for (auto descriptor_set : cb_state->validated_descriptor_sets) {
3654 descriptor_set->ClearCachedValidation(cb_state);
3655 }
3656 cb_state->validated_descriptor_sets.clear();
3657 if (VK_SUCCESS == result) {
3658 cb_state->state = CB_RECORDED;
3659 }
3660}
3661
3662void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
3663 VkResult result) {
3664 if (VK_SUCCESS == result) {
3665 ResetCommandBufferState(commandBuffer);
3666 }
3667}
3668
3669CBStatusFlags MakeStaticStateMask(VkPipelineDynamicStateCreateInfo const *ds) {
3670 // initially assume everything is static state
3671 CBStatusFlags flags = CBSTATUS_ALL_STATE_SET;
3672
3673 if (ds) {
3674 for (uint32_t i = 0; i < ds->dynamicStateCount; i++) {
locke-lunarg4189aa22020-10-21 00:23:48 -06003675 flags &= ~ConvertToCBStatusFlagBits(ds->pDynamicStates[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06003676 }
3677 }
locke-lunargd556cc32019-09-17 01:21:23 -06003678 return flags;
3679}
3680
3681// Validation cache:
3682// CV is the bottommost implementor of this extension. Don't pass calls down.
3683// utility function to set collective state for pipeline
3684void SetPipelineState(PIPELINE_STATE *pPipe) {
3685 // If any attachment used by this pipeline has blendEnable, set top-level blendEnable
3686 if (pPipe->graphicsPipelineCI.pColorBlendState) {
3687 for (size_t i = 0; i < pPipe->attachments.size(); ++i) {
3688 if (VK_TRUE == pPipe->attachments[i].blendEnable) {
3689 if (((pPipe->attachments[i].dstAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) &&
3690 (pPipe->attachments[i].dstAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) ||
3691 ((pPipe->attachments[i].dstColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) &&
3692 (pPipe->attachments[i].dstColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) ||
3693 ((pPipe->attachments[i].srcAlphaBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) &&
3694 (pPipe->attachments[i].srcAlphaBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA)) ||
3695 ((pPipe->attachments[i].srcColorBlendFactor >= VK_BLEND_FACTOR_CONSTANT_COLOR) &&
3696 (pPipe->attachments[i].srcColorBlendFactor <= VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA))) {
3697 pPipe->blendConstantsEnabled = true;
3698 }
3699 }
3700 }
3701 }
sfricke-samsung8f658d42020-05-03 20:12:24 -07003702 // Check if sample location is enabled
3703 if (pPipe->graphicsPipelineCI.pMultisampleState) {
3704 const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_state =
3705 lvl_find_in_chain<VkPipelineSampleLocationsStateCreateInfoEXT>(pPipe->graphicsPipelineCI.pMultisampleState->pNext);
3706 if (sample_location_state != nullptr) {
3707 pPipe->sample_location_enabled = sample_location_state->sampleLocationsEnable;
3708 }
3709 }
locke-lunargd556cc32019-09-17 01:21:23 -06003710}
3711
locke-lunargb8be8222020-10-20 00:34:37 -06003712void UpdateSamplerDescriptorsUsedByImage(LAST_BOUND_STATE &last_bound_state) {
3713 if (!last_bound_state.pipeline_state) return;
3714 if (last_bound_state.per_set.empty()) return;
3715
3716 for (auto &slot : last_bound_state.pipeline_state->active_slots) {
3717 for (auto &req : slot.second) {
3718 for (auto &samplers : req.second.samplers_used_by_image) {
3719 for (auto &sampler : samplers) {
3720 if (sampler.first.sampler_slot.first < last_bound_state.per_set.size() &&
3721 last_bound_state.per_set[sampler.first.sampler_slot.first].bound_descriptor_set) {
3722 sampler.second = last_bound_state.per_set[sampler.first.sampler_slot.first]
locke-lunargb8d7a7a2020-10-25 16:01:52 -06003723 .bound_descriptor_set->GetDescriptorFromBinding(sampler.first.sampler_slot.second,
3724 sampler.first.sampler_index);
locke-lunargb8be8222020-10-20 00:34:37 -06003725 }
3726 }
3727 }
3728 }
3729 }
3730}
3731
locke-lunargd556cc32019-09-17 01:21:23 -06003732void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
3733 VkPipeline pipeline) {
3734 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3735 assert(cb_state);
3736
3737 auto pipe_state = GetPipelineState(pipeline);
3738 if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
3739 cb_state->status &= ~cb_state->static_status;
3740 cb_state->static_status = MakeStaticStateMask(pipe_state->graphicsPipelineCI.ptr()->pDynamicState);
3741 cb_state->status |= cb_state->static_status;
locke-lunarg4189aa22020-10-21 00:23:48 -06003742 cb_state->dynamic_status = CBSTATUS_ALL_STATE_SET & (~cb_state->static_status);
locke-lunargd556cc32019-09-17 01:21:23 -06003743 }
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003744 ResetCommandBufferPushConstantDataIfIncompatible(cb_state, pipe_state->pipeline_layout->layout);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06003745 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
3746 cb_state->lastBound[lv_bind_point].pipeline_state = pipe_state;
locke-lunargd556cc32019-09-17 01:21:23 -06003747 SetPipelineState(pipe_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05003748 AddCommandBufferBinding(pipe_state->cb_bindings, VulkanTypedHandle(pipeline, kVulkanObjectTypePipeline), cb_state);
locke-lunargb8be8222020-10-20 00:34:37 -06003749
3750 for (auto &slot : pipe_state->active_slots) {
3751 for (auto &req : slot.second) {
3752 for (auto &sampler : req.second.samplers_used_by_image) {
3753 for (auto &des : sampler) {
3754 des.second = nullptr;
3755 }
3756 }
3757 }
3758 }
locke-lunargb8d7a7a2020-10-25 16:01:52 -06003759 UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]);
locke-lunargd556cc32019-09-17 01:21:23 -06003760}
3761
3762void ValidationStateTracker::PreCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
3763 uint32_t viewportCount, const VkViewport *pViewports) {
3764 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3765 cb_state->viewportMask |= ((1u << viewportCount) - 1u) << firstViewport;
3766 cb_state->status |= CBSTATUS_VIEWPORT_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06003767 cb_state->static_status &= ~CBSTATUS_VIEWPORT_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06003768}
3769
3770void ValidationStateTracker::PreCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
3771 uint32_t exclusiveScissorCount,
3772 const VkRect2D *pExclusiveScissors) {
3773 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3774 // TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
3775 // cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
3776 cb_state->status |= CBSTATUS_EXCLUSIVE_SCISSOR_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06003777 cb_state->static_status &= ~CBSTATUS_EXCLUSIVE_SCISSOR_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06003778}
3779
3780void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
3781 VkImageLayout imageLayout) {
3782 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3783
3784 if (imageView != VK_NULL_HANDLE) {
3785 auto view_state = GetImageViewState(imageView);
3786 AddCommandBufferBindingImageView(cb_state, view_state);
3787 }
3788}
3789
3790void ValidationStateTracker::PreCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
3791 uint32_t viewportCount,
3792 const VkShadingRatePaletteNV *pShadingRatePalettes) {
3793 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3794 // TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
3795 // cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
3796 cb_state->status |= CBSTATUS_SHADING_RATE_PALETTE_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06003797 cb_state->static_status &= ~CBSTATUS_SHADING_RATE_PALETTE_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06003798}
3799
3800void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
3801 const VkAccelerationStructureCreateInfoNV *pCreateInfo,
3802 const VkAllocationCallbacks *pAllocator,
3803 VkAccelerationStructureNV *pAccelerationStructure,
3804 VkResult result) {
3805 if (VK_SUCCESS != result) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003806 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE>(*pAccelerationStructure, pCreateInfo);
locke-lunargd556cc32019-09-17 01:21:23 -06003807
3808 // Query the requirements in case the application doesn't (to avoid bind/validation time query)
3809 VkAccelerationStructureMemoryRequirementsInfoNV as_memory_requirements_info = {};
3810 as_memory_requirements_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV;
3811 as_memory_requirements_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV;
3812 as_memory_requirements_info.accelerationStructure = as_state->acceleration_structure;
3813 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &as_memory_requirements_info, &as_state->memory_requirements);
3814
3815 VkAccelerationStructureMemoryRequirementsInfoNV scratch_memory_req_info = {};
3816 scratch_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV;
3817 scratch_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV;
3818 scratch_memory_req_info.accelerationStructure = as_state->acceleration_structure;
3819 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &scratch_memory_req_info,
3820 &as_state->build_scratch_memory_requirements);
3821
3822 VkAccelerationStructureMemoryRequirementsInfoNV update_memory_req_info = {};
3823 update_memory_req_info.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_INFO_NV;
3824 update_memory_req_info.type = VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV;
3825 update_memory_req_info.accelerationStructure = as_state->acceleration_structure;
3826 DispatchGetAccelerationStructureMemoryRequirementsNV(device, &update_memory_req_info,
3827 &as_state->update_scratch_memory_requirements);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06003828 as_state->allocator = pAllocator;
locke-lunargd556cc32019-09-17 01:21:23 -06003829 accelerationStructureMap[*pAccelerationStructure] = std::move(as_state);
3830}
3831
Jeff Bolz95176d02020-04-01 00:36:16 -05003832void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
3833 const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
3834 const VkAllocationCallbacks *pAllocator,
3835 VkAccelerationStructureKHR *pAccelerationStructure,
3836 VkResult result) {
3837 if (VK_SUCCESS != result) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07003838 auto as_state = std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo);
Mark Lobodzinski17dc4602020-05-29 07:48:40 -06003839 as_state->allocator = pAllocator;
sourav parmarcd5fb182020-07-17 12:58:44 -07003840 accelerationStructureMap_khr[*pAccelerationStructure] = std::move(as_state);
Jeff Bolz95176d02020-04-01 00:36:16 -05003841}
3842
sourav parmarcd5fb182020-07-17 12:58:44 -07003843void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
3844 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
3845 const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
3846 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3847 if (cb_state == nullptr) {
3848 return;
3849 }
3850 for (uint32_t i = 0; i < infoCount; ++i) {
3851 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
3852 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
3853 if (dst_as_state != nullptr) {
3854 dst_as_state->built = true;
3855 dst_as_state->build_info_khr.initialize(&pInfos[i]);
3856 AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state);
3857 }
3858 if (src_as_state != nullptr) {
3859 AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state);
3860 }
3861 }
3862 cb_state->hasBuildAccelerationStructureCmd = true;
3863}
3864
3865void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
3866 VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
3867 const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
3868 const uint32_t *const *ppMaxPrimitiveCounts) {
3869 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3870 if (cb_state == nullptr) {
3871 return;
3872 }
3873 for (uint32_t i = 0; i < infoCount; ++i) {
3874 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfos[i].dstAccelerationStructure);
3875 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfos[i].srcAccelerationStructure);
3876 if (dst_as_state != nullptr) {
3877 dst_as_state->built = true;
3878 dst_as_state->build_info_khr.initialize(&pInfos[i]);
3879 AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state);
3880 }
3881 if (src_as_state != nullptr) {
3882 AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state);
3883 }
3884 }
3885 cb_state->hasBuildAccelerationStructureCmd = true;
3886}
locke-lunargd556cc32019-09-17 01:21:23 -06003887void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
Mike Schuchardt2df08912020-12-15 16:28:09 -08003888 VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003889 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(pInfo->accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06003890 if (as_state != nullptr) {
3891 if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
3892 as_state->memory_requirements = *pMemoryRequirements;
3893 as_state->memory_requirements_checked = true;
3894 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
3895 as_state->build_scratch_memory_requirements = *pMemoryRequirements;
3896 as_state->build_scratch_memory_requirements_checked = true;
3897 } else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
3898 as_state->update_scratch_memory_requirements = *pMemoryRequirements;
3899 as_state->update_scratch_memory_requirements_checked = true;
3900 }
3901 }
3902}
3903
sourav parmarcd5fb182020-07-17 12:58:44 -07003904void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
3905 VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06003906 if (VK_SUCCESS != result) return;
3907 for (uint32_t i = 0; i < bindInfoCount; i++) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003908 const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
locke-lunargd556cc32019-09-17 01:21:23 -06003909
sourav parmarcd5fb182020-07-17 12:58:44 -07003910 ACCELERATION_STRUCTURE_STATE *as_state = GetAccelerationStructureStateNV(info.accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06003911 if (as_state) {
3912 // Track bound memory range information
3913 auto mem_info = GetDevMemState(info.memory);
3914 if (mem_info) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07003915 InsertAccelerationStructureMemoryRange(info.accelerationStructure, mem_info, info.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06003916 }
3917 // Track objects tied to memory
3918 SetMemBinding(info.memory, as_state, info.memoryOffset,
sourav parmarcd5fb182020-07-17 12:58:44 -07003919 VulkanTypedHandle(info.accelerationStructure, kVulkanObjectTypeAccelerationStructureNV));
locke-lunargd556cc32019-09-17 01:21:23 -06003920
3921 // GPU validation of top level acceleration structure building needs acceleration structure handles.
Jeff Bolz95176d02020-04-01 00:36:16 -05003922 // XXX TODO: Query device address for KHR extension
sourav parmarcd5fb182020-07-17 12:58:44 -07003923 if (enabled[gpu_validation]) {
locke-lunargd556cc32019-09-17 01:21:23 -06003924 DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
3925 }
3926 }
3927 }
3928}
3929
3930void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
3931 VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
3932 VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
3933 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3934 if (cb_state == nullptr) {
3935 return;
3936 }
3937
sourav parmarcd5fb182020-07-17 12:58:44 -07003938 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
3939 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
locke-lunargd556cc32019-09-17 01:21:23 -06003940 if (dst_as_state != nullptr) {
3941 dst_as_state->built = true;
3942 dst_as_state->build_info.initialize(pInfo);
3943 AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state);
3944 }
3945 if (src_as_state != nullptr) {
3946 AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state);
3947 }
3948 cb_state->hasBuildAccelerationStructureCmd = true;
3949}
3950
3951void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
3952 VkAccelerationStructureNV dst,
3953 VkAccelerationStructureNV src,
3954 VkCopyAccelerationStructureModeNV mode) {
3955 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
3956 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003957 ACCELERATION_STRUCTURE_STATE *src_as_state = GetAccelerationStructureStateNV(src);
3958 ACCELERATION_STRUCTURE_STATE *dst_as_state = GetAccelerationStructureStateNV(dst);
locke-lunargd556cc32019-09-17 01:21:23 -06003959 if (dst_as_state != nullptr && src_as_state != nullptr) {
3960 dst_as_state->built = true;
3961 dst_as_state->build_info = src_as_state->build_info;
3962 AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state);
3963 AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state);
3964 }
3965 }
3966}
3967
Jeff Bolz95176d02020-04-01 00:36:16 -05003968void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
3969 VkAccelerationStructureKHR accelerationStructure,
3970 const VkAllocationCallbacks *pAllocator) {
locke-lunargd556cc32019-09-17 01:21:23 -06003971 if (!accelerationStructure) return;
sourav parmarcd5fb182020-07-17 12:58:44 -07003972 auto *as_state = GetAccelerationStructureStateKHR(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06003973 if (as_state) {
Jeff Bolz95176d02020-04-01 00:36:16 -05003974 const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureKHR);
locke-lunargd556cc32019-09-17 01:21:23 -06003975 InvalidateCommandBuffers(as_state->cb_bindings, obj_struct);
3976 for (auto mem_binding : as_state->GetBoundMemory()) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003977 RemoveMemoryRange(obj_struct, mem_binding);
locke-lunargd556cc32019-09-17 01:21:23 -06003978 }
3979 ClearMemoryObjectBindings(obj_struct);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05003980 as_state->destroyed = true;
sourav parmarcd5fb182020-07-17 12:58:44 -07003981 accelerationStructureMap_khr.erase(accelerationStructure);
locke-lunargd556cc32019-09-17 01:21:23 -06003982 }
3983}
3984
Jeff Bolz95176d02020-04-01 00:36:16 -05003985void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
3986 VkAccelerationStructureNV accelerationStructure,
3987 const VkAllocationCallbacks *pAllocator) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003988 if (!accelerationStructure) return;
3989 auto *as_state = GetAccelerationStructureStateNV(accelerationStructure);
3990 if (as_state) {
3991 const VulkanTypedHandle obj_struct(accelerationStructure, kVulkanObjectTypeAccelerationStructureNV);
3992 InvalidateCommandBuffers(as_state->cb_bindings, obj_struct);
3993 for (auto mem_binding : as_state->GetBoundMemory()) {
3994 RemoveMemoryRange(obj_struct, mem_binding);
3995 }
3996 ClearMemoryObjectBindings(obj_struct);
3997 as_state->destroyed = true;
3998 accelerationStructureMap.erase(accelerationStructure);
3999 }
Jeff Bolz95176d02020-04-01 00:36:16 -05004000}
4001
Chris Mayer9ded5eb2019-09-19 16:33:26 +02004002void ValidationStateTracker::PreCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
4003 uint32_t viewportCount,
4004 const VkViewportWScalingNV *pViewportWScalings) {
4005 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4006 cb_state->status |= CBSTATUS_VIEWPORT_W_SCALING_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004007 cb_state->static_status &= ~CBSTATUS_VIEWPORT_W_SCALING_SET;
Chris Mayer9ded5eb2019-09-19 16:33:26 +02004008}
4009
locke-lunargd556cc32019-09-17 01:21:23 -06004010void ValidationStateTracker::PreCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
4011 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4012 cb_state->status |= CBSTATUS_LINE_WIDTH_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004013 cb_state->static_status &= ~CBSTATUS_LINE_WIDTH_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004014}
4015
4016void ValidationStateTracker::PreCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
4017 uint16_t lineStipplePattern) {
4018 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4019 cb_state->status |= CBSTATUS_LINE_STIPPLE_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004020 cb_state->static_status &= ~CBSTATUS_LINE_STIPPLE_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004021}
4022
4023void ValidationStateTracker::PreCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
4024 float depthBiasClamp, float depthBiasSlopeFactor) {
4025 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4026 cb_state->status |= CBSTATUS_DEPTH_BIAS_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004027 cb_state->static_status &= ~CBSTATUS_DEPTH_BIAS_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004028}
4029
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004030void ValidationStateTracker::PreCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount,
4031 const VkRect2D *pScissors) {
4032 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4033 cb_state->scissorMask |= ((1u << scissorCount) - 1u) << firstScissor;
4034 cb_state->status |= CBSTATUS_SCISSOR_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004035 cb_state->static_status &= ~CBSTATUS_SCISSOR_SET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01004036}
4037
locke-lunargd556cc32019-09-17 01:21:23 -06004038void ValidationStateTracker::PreCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
4039 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4040 cb_state->status |= CBSTATUS_BLEND_CONSTANTS_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004041 cb_state->static_status &= ~CBSTATUS_BLEND_CONSTANTS_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004042}
4043
4044void ValidationStateTracker::PreCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
4045 float maxDepthBounds) {
4046 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4047 cb_state->status |= CBSTATUS_DEPTH_BOUNDS_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004048 cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004049}
4050
4051void ValidationStateTracker::PreCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4052 uint32_t compareMask) {
4053 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4054 cb_state->status |= CBSTATUS_STENCIL_READ_MASK_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004055 cb_state->static_status &= ~CBSTATUS_STENCIL_READ_MASK_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004056}
4057
4058void ValidationStateTracker::PreCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4059 uint32_t writeMask) {
4060 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4061 cb_state->status |= CBSTATUS_STENCIL_WRITE_MASK_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004062 cb_state->static_status &= ~CBSTATUS_STENCIL_WRITE_MASK_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004063}
4064
4065void ValidationStateTracker::PreCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
4066 uint32_t reference) {
4067 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4068 cb_state->status |= CBSTATUS_STENCIL_REFERENCE_SET;
Piers Daniell39842ee2020-07-10 16:42:33 -06004069 cb_state->static_status &= ~CBSTATUS_STENCIL_REFERENCE_SET;
locke-lunargd556cc32019-09-17 01:21:23 -06004070}
4071
4072// Update pipeline_layout bind points applying the "Pipeline Layout Compatibility" rules.
4073// One of pDescriptorSets or push_descriptor_set should be nullptr, indicating whether this
4074// is called for CmdBindDescriptorSets or CmdPushDescriptorSet.
4075void ValidationStateTracker::UpdateLastBoundDescriptorSets(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipeline_bind_point,
4076 const PIPELINE_LAYOUT_STATE *pipeline_layout, uint32_t first_set,
4077 uint32_t set_count, const VkDescriptorSet *pDescriptorSets,
4078 cvdescriptorset::DescriptorSet *push_descriptor_set,
4079 uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets) {
4080 assert((pDescriptorSets == nullptr) ^ (push_descriptor_set == nullptr));
4081 // Defensive
4082 assert(pipeline_layout);
4083 if (!pipeline_layout) return;
4084
4085 uint32_t required_size = first_set + set_count;
4086 const uint32_t last_binding_index = required_size - 1;
4087 assert(last_binding_index < pipeline_layout->compat_for_set.size());
4088
4089 // Some useful shorthand
locke-lunargb8d7a7a2020-10-25 16:01:52 -06004090 const auto lv_bind_point = ConvertToLvlBindPoint(pipeline_bind_point);
4091 auto &last_bound = cb_state->lastBound[lv_bind_point];
locke-lunargd556cc32019-09-17 01:21:23 -06004092 auto &pipe_compat_ids = pipeline_layout->compat_for_set;
4093 const uint32_t current_size = static_cast<uint32_t>(last_bound.per_set.size());
4094
4095 // We need this three times in this function, but nowhere else
4096 auto push_descriptor_cleanup = [&last_bound](const cvdescriptorset::DescriptorSet *ds) -> bool {
4097 if (ds && ds->IsPushDescriptor()) {
4098 assert(ds == last_bound.push_descriptor_set.get());
4099 last_bound.push_descriptor_set = nullptr;
4100 return true;
4101 }
4102 return false;
4103 };
4104
4105 // Clean up the "disturbed" before and after the range to be set
4106 if (required_size < current_size) {
4107 if (last_bound.per_set[last_binding_index].compat_id_for_set != pipe_compat_ids[last_binding_index]) {
4108 // We're disturbing those after last, we'll shrink below, but first need to check for and cleanup the push_descriptor
4109 for (auto set_idx = required_size; set_idx < current_size; ++set_idx) {
4110 if (push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set)) break;
4111 }
4112 } else {
4113 // We're not disturbing past last, so leave the upper binding data alone.
4114 required_size = current_size;
4115 }
4116 }
4117
4118 // We resize if we need more set entries or if those past "last" are disturbed
4119 if (required_size != current_size) {
4120 last_bound.per_set.resize(required_size);
4121 }
4122
4123 // For any previously bound sets, need to set them to "invalid" if they were disturbed by this update
4124 for (uint32_t set_idx = 0; set_idx < first_set; ++set_idx) {
4125 if (last_bound.per_set[set_idx].compat_id_for_set != pipe_compat_ids[set_idx]) {
4126 push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set);
4127 last_bound.per_set[set_idx].bound_descriptor_set = nullptr;
4128 last_bound.per_set[set_idx].dynamicOffsets.clear();
4129 last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx];
4130 }
4131 }
4132
4133 // Now update the bound sets with the input sets
4134 const uint32_t *input_dynamic_offsets = p_dynamic_offsets; // "read" pointer for dynamic offset data
4135 for (uint32_t input_idx = 0; input_idx < set_count; input_idx++) {
4136 auto set_idx = input_idx + first_set; // set_idx is index within layout, input_idx is index within input descriptor sets
4137 cvdescriptorset::DescriptorSet *descriptor_set =
4138 push_descriptor_set ? push_descriptor_set : GetSetNode(pDescriptorSets[input_idx]);
4139
4140 // Record binding (or push)
4141 if (descriptor_set != last_bound.push_descriptor_set.get()) {
4142 // Only cleanup the push descriptors if they aren't the currently used set.
4143 push_descriptor_cleanup(last_bound.per_set[set_idx].bound_descriptor_set);
4144 }
4145 last_bound.per_set[set_idx].bound_descriptor_set = descriptor_set;
4146 last_bound.per_set[set_idx].compat_id_for_set = pipe_compat_ids[set_idx]; // compat ids are canonical *per* set index
4147
4148 if (descriptor_set) {
4149 auto set_dynamic_descriptor_count = descriptor_set->GetDynamicDescriptorCount();
4150 // TODO: Add logic for tracking push_descriptor offsets (here or in caller)
4151 if (set_dynamic_descriptor_count && input_dynamic_offsets) {
4152 const uint32_t *end_offset = input_dynamic_offsets + set_dynamic_descriptor_count;
4153 last_bound.per_set[set_idx].dynamicOffsets = std::vector<uint32_t>(input_dynamic_offsets, end_offset);
4154 input_dynamic_offsets = end_offset;
4155 assert(input_dynamic_offsets <= (p_dynamic_offsets + dynamic_offset_count));
4156 } else {
4157 last_bound.per_set[set_idx].dynamicOffsets.clear();
4158 }
4159 if (!descriptor_set->IsPushDescriptor()) {
4160 // Can't cache validation of push_descriptors
4161 cb_state->validated_descriptor_sets.insert(descriptor_set);
4162 }
4163 }
4164 }
4165}
4166
4167// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
4168void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
4169 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
4170 uint32_t firstSet, uint32_t setCount,
4171 const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
4172 const uint32_t *pDynamicOffsets) {
4173 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4174 auto pipeline_layout = GetPipelineLayout(layout);
4175
4176 // Resize binding arrays
4177 uint32_t last_set_index = firstSet + setCount - 1;
locke-lunargb8d7a7a2020-10-25 16:01:52 -06004178 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
4179 if (last_set_index >= cb_state->lastBound[lv_bind_point].per_set.size()) {
4180 cb_state->lastBound[lv_bind_point].per_set.resize(last_set_index + 1);
locke-lunargd556cc32019-09-17 01:21:23 -06004181 }
4182
4183 UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, firstSet, setCount, pDescriptorSets, nullptr,
4184 dynamicOffsetCount, pDynamicOffsets);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06004185 cb_state->lastBound[lv_bind_point].pipeline_layout = layout;
locke-lunargd556cc32019-09-17 01:21:23 -06004186 ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout);
locke-lunargb8d7a7a2020-10-25 16:01:52 -06004187 UpdateSamplerDescriptorsUsedByImage(cb_state->lastBound[lv_bind_point]);
locke-lunargd556cc32019-09-17 01:21:23 -06004188}
4189
4190void ValidationStateTracker::RecordCmdPushDescriptorSetState(CMD_BUFFER_STATE *cb_state, VkPipelineBindPoint pipelineBindPoint,
4191 VkPipelineLayout layout, uint32_t set, uint32_t descriptorWriteCount,
4192 const VkWriteDescriptorSet *pDescriptorWrites) {
4193 const auto &pipeline_layout = GetPipelineLayout(layout);
4194 // Short circuit invalid updates
4195 if (!pipeline_layout || (set >= pipeline_layout->set_layouts.size()) || !pipeline_layout->set_layouts[set] ||
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004196 !pipeline_layout->set_layouts[set]->IsPushDescriptor()) {
locke-lunargd556cc32019-09-17 01:21:23 -06004197 return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004198 }
locke-lunargd556cc32019-09-17 01:21:23 -06004199
4200 // We need a descriptor set to update the bindings with, compatible with the passed layout
4201 const auto dsl = pipeline_layout->set_layouts[set];
locke-lunargb8d7a7a2020-10-25 16:01:52 -06004202 const auto lv_bind_point = ConvertToLvlBindPoint(pipelineBindPoint);
4203 auto &last_bound = cb_state->lastBound[lv_bind_point];
locke-lunargd556cc32019-09-17 01:21:23 -06004204 auto &push_descriptor_set = last_bound.push_descriptor_set;
4205 // If we are disturbing the current push_desriptor_set clear it
4206 if (!push_descriptor_set || !CompatForSet(set, last_bound, pipeline_layout->compat_for_set)) {
John Zulaufd2c3dae2019-12-12 11:02:17 -07004207 last_bound.UnbindAndResetPushDescriptorSet(new cvdescriptorset::DescriptorSet(0, nullptr, dsl, 0, this));
locke-lunargd556cc32019-09-17 01:21:23 -06004208 }
4209
4210 UpdateLastBoundDescriptorSets(cb_state, pipelineBindPoint, pipeline_layout, set, 1, nullptr, push_descriptor_set.get(), 0,
4211 nullptr);
4212 last_bound.pipeline_layout = layout;
4213
4214 // Now that we have either the new or extant push_descriptor set ... do the write updates against it
Jeff Bolz41a1ced2019-10-11 11:40:49 -05004215 push_descriptor_set->PerformPushDescriptorsUpdate(this, descriptorWriteCount, pDescriptorWrites);
locke-lunargd556cc32019-09-17 01:21:23 -06004216}
4217
4218void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
4219 VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
4220 uint32_t set, uint32_t descriptorWriteCount,
4221 const VkWriteDescriptorSet *pDescriptorWrites) {
4222 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4223 RecordCmdPushDescriptorSetState(cb_state, pipelineBindPoint, layout, set, descriptorWriteCount, pDescriptorWrites);
4224}
4225
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06004226void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
4227 VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
4228 const void *pValues) {
4229 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4230 if (cb_state != nullptr) {
4231 ResetCommandBufferPushConstantDataIfIncompatible(cb_state, layout);
4232
4233 auto &push_constant_data = cb_state->push_constant_data;
4234 assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
4235 std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06004236 cb_state->push_constant_pipeline_layout_set = layout;
4237
4238 auto flags = stageFlags;
4239 uint32_t bit_shift = 0;
4240 while (flags) {
4241 if (flags & 1) {
4242 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
4243 const auto it = cb_state->push_constant_data_update.find(flag);
4244
4245 if (it != cb_state->push_constant_data_update.end()) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06004246 std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
locke-lunargde3f0fa2020-09-10 11:55:31 -06004247 }
4248 }
4249 flags = flags >> 1;
4250 ++bit_shift;
4251 }
Tony-LunarG6bb1d0c2019-09-23 10:39:25 -06004252 }
4253}
4254
locke-lunargd556cc32019-09-17 01:21:23 -06004255void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
4256 VkIndexType indexType) {
locke-lunargd556cc32019-09-17 01:21:23 -06004257 auto cb_state = GetCBState(commandBuffer);
4258
4259 cb_state->status |= CBSTATUS_INDEX_BUFFER_BOUND;
Piers Daniell39842ee2020-07-10 16:42:33 -06004260 cb_state->static_status &= ~CBSTATUS_INDEX_BUFFER_BOUND;
locke-lunarg1ae57d62020-11-18 10:49:19 -07004261 cb_state->index_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(buffer);
4262 cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
locke-lunargd556cc32019-09-17 01:21:23 -06004263 cb_state->index_buffer_binding.offset = offset;
4264 cb_state->index_buffer_binding.index_type = indexType;
4265 // Add binding for this index buffer to this commandbuffer
locke-lunarg1ae57d62020-11-18 10:49:19 -07004266 AddCommandBufferBindingBuffer(cb_state, cb_state->index_buffer_binding.buffer_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06004267}
4268
4269void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
4270 uint32_t bindingCount, const VkBuffer *pBuffers,
4271 const VkDeviceSize *pOffsets) {
4272 auto cb_state = GetCBState(commandBuffer);
4273
4274 uint32_t end = firstBinding + bindingCount;
4275 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
4276 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
4277 }
4278
4279 for (uint32_t i = 0; i < bindingCount; ++i) {
4280 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07004281 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004282 vertex_buffer_binding.offset = pOffsets[i];
Piers Daniell39842ee2020-07-10 16:42:33 -06004283 vertex_buffer_binding.size = VK_WHOLE_SIZE;
4284 vertex_buffer_binding.stride = 0;
locke-lunargd556cc32019-09-17 01:21:23 -06004285 // Add binding for this vertex buffer to this commandbuffer
Jeff Bolz165818a2020-05-08 11:19:03 -05004286 if (pBuffers[i]) {
locke-lunarg1ae57d62020-11-18 10:49:19 -07004287 AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get());
Jeff Bolz165818a2020-05-08 11:19:03 -05004288 }
locke-lunargd556cc32019-09-17 01:21:23 -06004289 }
4290}
4291
4292void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
4293 VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
4294 auto cb_state = GetCBState(commandBuffer);
4295 auto dst_buffer_state = GetBufferState(dstBuffer);
4296
4297 // Update bindings between buffer and cmd buffer
4298 AddCommandBufferBindingBuffer(cb_state, dst_buffer_state);
4299}
4300
Jeff Bolz310775c2019-10-09 00:46:33 -05004301bool ValidationStateTracker::SetEventStageMask(VkEvent event, VkPipelineStageFlags stageMask,
4302 EventToStageMap *localEventToStageMap) {
4303 (*localEventToStageMap)[event] = stageMask;
locke-lunargd556cc32019-09-17 01:21:23 -06004304 return false;
4305}
4306
4307void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
4308 VkPipelineStageFlags stageMask) {
4309 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4310 auto event_state = GetEventState(event);
4311 if (event_state) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05004312 AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004313 }
4314 cb_state->events.push_back(event);
4315 if (!cb_state->waitedEvents.count(event)) {
4316 cb_state->writeEventsBeforeWait.push_back(event);
4317 }
Jeff Bolz310775c2019-10-09 00:46:33 -05004318 cb_state->eventUpdates.emplace_back(
4319 [event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) {
4320 return SetEventStageMask(event, stageMask, localEventToStageMap);
4321 });
locke-lunargd556cc32019-09-17 01:21:23 -06004322}
4323
4324void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
4325 VkPipelineStageFlags stageMask) {
4326 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4327 auto event_state = GetEventState(event);
4328 if (event_state) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05004329 AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(event, kVulkanObjectTypeEvent, event_state), cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004330 }
4331 cb_state->events.push_back(event);
4332 if (!cb_state->waitedEvents.count(event)) {
4333 cb_state->writeEventsBeforeWait.push_back(event);
4334 }
4335
4336 cb_state->eventUpdates.emplace_back(
Jeff Bolz310775c2019-10-09 00:46:33 -05004337 [event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) {
4338 return SetEventStageMask(event, VkPipelineStageFlags(0), localEventToStageMap);
4339 });
locke-lunargd556cc32019-09-17 01:21:23 -06004340}
4341
4342void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
4343 VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
4344 uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
4345 uint32_t bufferMemoryBarrierCount,
4346 const VkBufferMemoryBarrier *pBufferMemoryBarriers,
4347 uint32_t imageMemoryBarrierCount,
4348 const VkImageMemoryBarrier *pImageMemoryBarriers) {
4349 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4350 for (uint32_t i = 0; i < eventCount; ++i) {
4351 auto event_state = GetEventState(pEvents[i]);
4352 if (event_state) {
Jeff Bolzadbfa852019-10-04 13:53:30 -05004353 AddCommandBufferBinding(event_state->cb_bindings, VulkanTypedHandle(pEvents[i], kVulkanObjectTypeEvent, event_state),
4354 cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004355 }
4356 cb_state->waitedEvents.insert(pEvents[i]);
4357 cb_state->events.push_back(pEvents[i]);
4358 }
4359}
4360
Jeff Bolz310775c2019-10-09 00:46:33 -05004361bool ValidationStateTracker::SetQueryState(QueryObject object, QueryState value, QueryMap *localQueryToStateMap) {
4362 (*localQueryToStateMap)[object] = value;
4363 return false;
4364}
4365
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004366bool ValidationStateTracker::SetQueryStateMulti(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount, uint32_t perfPass,
4367 QueryState value, QueryMap *localQueryToStateMap) {
Jeff Bolz310775c2019-10-09 00:46:33 -05004368 for (uint32_t i = 0; i < queryCount; i++) {
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004369 QueryObject object = QueryObject(QueryObject(queryPool, firstQuery + i), perfPass);
Jeff Bolz310775c2019-10-09 00:46:33 -05004370 (*localQueryToStateMap)[object] = value;
locke-lunargd556cc32019-09-17 01:21:23 -06004371 }
4372 return false;
4373}
4374
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004375QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
4376 uint32_t perfPass) const {
4377 QueryObject query = QueryObject(QueryObject(queryPool, queryIndex), perfPass);
locke-lunargd556cc32019-09-17 01:21:23 -06004378
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004379 auto iter = localQueryToStateMap->find(query);
4380 if (iter != localQueryToStateMap->end()) return iter->second;
Jeff Bolz310775c2019-10-09 00:46:33 -05004381
Jeff Bolz310775c2019-10-09 00:46:33 -05004382 return QUERYSTATE_UNKNOWN;
locke-lunargd556cc32019-09-17 01:21:23 -06004383}
4384
4385void ValidationStateTracker::RecordCmdBeginQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004386 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004387 cb_state->activeQueries.insert(query_obj);
4388 cb_state->startedQueries.insert(query_obj);
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004389 cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate,
4390 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
4391 QueryMap *localQueryToStateMap) {
4392 SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_RUNNING, localQueryToStateMap);
4393 return false;
4394 });
Jeff Bolzadbfa852019-10-04 13:53:30 -05004395 auto pool_state = GetQueryPoolState(query_obj.pool);
4396 AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state),
4397 cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004398}
4399
4400void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
4401 VkFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004402 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004403 QueryObject query = {queryPool, slot};
4404 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4405 RecordCmdBeginQuery(cb_state, query);
4406}
4407
4408void ValidationStateTracker::RecordCmdEndQuery(CMD_BUFFER_STATE *cb_state, const QueryObject &query_obj) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004409 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004410 cb_state->activeQueries.erase(query_obj);
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004411 cb_state->queryUpdates.emplace_back([query_obj](const ValidationStateTracker *device_data, bool do_validate,
4412 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
4413 QueryMap *localQueryToStateMap) {
4414 return SetQueryState(QueryObject(query_obj, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap);
4415 });
Jeff Bolzadbfa852019-10-04 13:53:30 -05004416 auto pool_state = GetQueryPoolState(query_obj.pool);
4417 AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(query_obj.pool, kVulkanObjectTypeQueryPool, pool_state),
4418 cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004419}
4420
4421void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004422 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004423 QueryObject query_obj = {queryPool, slot};
4424 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4425 RecordCmdEndQuery(cb_state, query_obj);
4426}
4427
4428void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4429 uint32_t firstQuery, uint32_t queryCount) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004430 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004431 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4432
Lionel Landwerlinb1e5a422020-02-18 16:49:09 +02004433 for (uint32_t slot = firstQuery; slot < (firstQuery + queryCount); slot++) {
4434 QueryObject query = {queryPool, slot};
4435 cb_state->resetQueries.insert(query);
4436 }
4437
Jeff Bolz310775c2019-10-09 00:46:33 -05004438 cb_state->queryUpdates.emplace_back([queryPool, firstQuery, queryCount](const ValidationStateTracker *device_data,
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004439 bool do_validate, VkQueryPool &firstPerfQueryPool,
4440 uint32_t perfQueryPass,
4441 QueryMap *localQueryToStateMap) {
4442 return SetQueryStateMulti(queryPool, firstQuery, queryCount, perfQueryPass, QUERYSTATE_RESET, localQueryToStateMap);
locke-lunargd556cc32019-09-17 01:21:23 -06004443 });
Jeff Bolzadbfa852019-10-04 13:53:30 -05004444 auto pool_state = GetQueryPoolState(queryPool);
4445 AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state),
locke-lunargd556cc32019-09-17 01:21:23 -06004446 cb_state);
4447}
4448
4449void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
4450 uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
4451 VkDeviceSize dstOffset, VkDeviceSize stride,
4452 VkQueryResultFlags flags) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004453 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004454 auto cb_state = GetCBState(commandBuffer);
4455 auto dst_buff_state = GetBufferState(dstBuffer);
4456 AddCommandBufferBindingBuffer(cb_state, dst_buff_state);
Jeff Bolzadbfa852019-10-04 13:53:30 -05004457 auto pool_state = GetQueryPoolState(queryPool);
4458 AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state),
locke-lunargd556cc32019-09-17 01:21:23 -06004459 cb_state);
4460}
4461
4462void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
4463 VkQueryPool queryPool, uint32_t slot) {
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06004464 if (disabled[query_validation]) return;
locke-lunargd556cc32019-09-17 01:21:23 -06004465 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
Jeff Bolzadbfa852019-10-04 13:53:30 -05004466 auto pool_state = GetQueryPoolState(queryPool);
4467 AddCommandBufferBinding(pool_state->cb_bindings, VulkanTypedHandle(queryPool, kVulkanObjectTypeQueryPool, pool_state),
locke-lunargd556cc32019-09-17 01:21:23 -06004468 cb_state);
4469 QueryObject query = {queryPool, slot};
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02004470 cb_state->queryUpdates.emplace_back([query](const ValidationStateTracker *device_data, bool do_validate,
4471 VkQueryPool &firstPerfQueryPool, uint32_t perfQueryPass,
4472 QueryMap *localQueryToStateMap) {
4473 return SetQueryState(QueryObject(query, perfQueryPass), QUERYSTATE_ENDED, localQueryToStateMap);
4474 });
locke-lunargd556cc32019-09-17 01:21:23 -06004475}
4476
4477void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
4478 const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
4479 VkResult result) {
4480 if (VK_SUCCESS != result) return;
4481 // Shadow create info and store in map
Jeff Bolz6ae39612019-10-11 20:57:36 -05004482 auto fb_state = std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, GetRenderPassShared(pCreateInfo->renderPass));
locke-lunargd556cc32019-09-17 01:21:23 -06004483
Mike Schuchardt2df08912020-12-15 16:28:09 -08004484 if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
locke-lunarg1ae57d62020-11-18 10:49:19 -07004485 fb_state->attachments_view_state.resize(pCreateInfo->attachmentCount);
4486
locke-lunargd556cc32019-09-17 01:21:23 -06004487 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
locke-lunarg1ae57d62020-11-18 10:49:19 -07004488 fb_state->attachments_view_state[i] = GetShared<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06004489 }
4490 }
4491 frameBufferMap[*pFramebuffer] = std::move(fb_state);
4492}
4493
Mike Schuchardt2df08912020-12-15 16:28:09 -08004494void ValidationStateTracker::RecordRenderPassDAG(RenderPassCreateVersion rp_version, const VkRenderPassCreateInfo2 *pCreateInfo,
locke-lunargd556cc32019-09-17 01:21:23 -06004495 RENDER_PASS_STATE *render_pass) {
4496 auto &subpass_to_node = render_pass->subpassToNode;
4497 subpass_to_node.resize(pCreateInfo->subpassCount);
4498 auto &self_dependencies = render_pass->self_dependencies;
4499 self_dependencies.resize(pCreateInfo->subpassCount);
John Zulauf4aff5d92020-02-21 08:29:35 -07004500 auto &subpass_dependencies = render_pass->subpass_dependencies;
4501 subpass_dependencies.resize(pCreateInfo->subpassCount);
locke-lunargd556cc32019-09-17 01:21:23 -06004502
4503 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
4504 subpass_to_node[i].pass = i;
4505 self_dependencies[i].clear();
John Zulauf4aff5d92020-02-21 08:29:35 -07004506 subpass_dependencies[i].pass = i;
locke-lunargd556cc32019-09-17 01:21:23 -06004507 }
4508 for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
John Zulaufbaea94f2020-09-15 17:55:16 -06004509 const auto &dependency = pCreateInfo->pDependencies[i];
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004510 const auto src_subpass = dependency.srcSubpass;
4511 const auto dst_subpass = dependency.dstSubpass;
locke-lunargd556cc32019-09-17 01:21:23 -06004512 if ((dependency.srcSubpass != VK_SUBPASS_EXTERNAL) && (dependency.dstSubpass != VK_SUBPASS_EXTERNAL)) {
4513 if (dependency.srcSubpass == dependency.dstSubpass) {
4514 self_dependencies[dependency.srcSubpass].push_back(i);
4515 } else {
4516 subpass_to_node[dependency.dstSubpass].prev.push_back(dependency.srcSubpass);
4517 subpass_to_node[dependency.srcSubpass].next.push_back(dependency.dstSubpass);
4518 }
4519 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004520 if (src_subpass == VK_SUBPASS_EXTERNAL) {
4521 assert(dst_subpass != VK_SUBPASS_EXTERNAL); // this is invalid per VUID-VkSubpassDependency-srcSubpass-00865
4522 subpass_dependencies[dst_subpass].barrier_from_external.emplace_back(&dependency);
4523 } else if (dst_subpass == VK_SUBPASS_EXTERNAL) {
4524 subpass_dependencies[src_subpass].barrier_to_external.emplace_back(&dependency);
John Zulauf4aff5d92020-02-21 08:29:35 -07004525 } else if (dependency.srcSubpass != dependency.dstSubpass) {
4526 // ignore self dependencies in prev and next
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004527 subpass_dependencies[src_subpass].next[&subpass_dependencies[dst_subpass]].emplace_back(&dependency);
4528 subpass_dependencies[dst_subpass].prev[&subpass_dependencies[src_subpass]].emplace_back(&dependency);
John Zulauf4aff5d92020-02-21 08:29:35 -07004529 }
4530 }
4531
4532 //
4533 // Determine "asynchrononous" subpassess
4534 // syncronization is only interested in asyncronous stages *earlier* that the current one... so we'll only look towards those.
4535 // NOTE: This is O(N^3), which we could shrink to O(N^2logN) using sets instead of arrays, but given that N is likely to be
4536 // small and the K for |= from the prev is must less than for set, we'll accept the brute force.
4537 std::vector<std::vector<bool>> pass_depends(pCreateInfo->subpassCount);
4538 for (uint32_t i = 1; i < pCreateInfo->subpassCount; ++i) {
4539 auto &depends = pass_depends[i];
4540 depends.resize(i);
4541 auto &subpass_dep = subpass_dependencies[i];
4542 for (const auto &prev : subpass_dep.prev) {
John Zulaufbaea94f2020-09-15 17:55:16 -06004543 const auto prev_pass = prev.first->pass;
John Zulauf4aff5d92020-02-21 08:29:35 -07004544 const auto &prev_depends = pass_depends[prev_pass];
4545 for (uint32_t j = 0; j < prev_pass; j++) {
4546 depends[j] = depends[j] | prev_depends[j];
4547 }
4548 depends[prev_pass] = true;
4549 }
4550 for (uint32_t pass = 0; pass < subpass_dep.pass; pass++) {
4551 if (!depends[pass]) {
4552 subpass_dep.async.push_back(pass);
4553 }
4554 }
locke-lunargd556cc32019-09-17 01:21:23 -06004555 }
4556}
4557
John Zulauf4aff5d92020-02-21 08:29:35 -07004558static VkSubpassDependency2 ImplicitDependencyFromExternal(uint32_t subpass) {
4559 VkSubpassDependency2 from_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
4560 nullptr,
4561 VK_SUBPASS_EXTERNAL,
4562 subpass,
4563 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
4564 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4565 0,
4566 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
4567 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
4568 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4569 0,
4570 0};
4571 return from_external;
4572}
4573
4574static VkSubpassDependency2 ImplicitDependencyToExternal(uint32_t subpass) {
4575 VkSubpassDependency2 to_external = {VK_STRUCTURE_TYPE_SUBPASS_DEPENDENCY_2,
4576 nullptr,
4577 subpass,
4578 VK_SUBPASS_EXTERNAL,
4579 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
4580 VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
4581 VK_ACCESS_INPUT_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
4582 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
4583 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
4584 0,
4585 0,
4586 0};
4587 return to_external;
4588}
4589
locke-lunargd556cc32019-09-17 01:21:23 -06004590void ValidationStateTracker::RecordCreateRenderPassState(RenderPassCreateVersion rp_version,
4591 std::shared_ptr<RENDER_PASS_STATE> &render_pass,
4592 VkRenderPass *pRenderPass) {
4593 render_pass->renderPass = *pRenderPass;
4594 auto create_info = render_pass->createInfo.ptr();
4595
4596 RecordRenderPassDAG(RENDER_PASS_VERSION_1, create_info, render_pass.get());
4597
John Zulauf8863c332020-03-20 10:34:33 -06004598 struct AttachmentTracker { // This is really only of local interest, but a bit big for a lambda
4599 RENDER_PASS_STATE *const rp;
John Zulaufbb9f07f2020-03-19 16:53:06 -06004600 std::vector<uint32_t> &first;
John Zulauf1507ee42020-05-18 11:33:09 -06004601 std::vector<bool> &first_is_transition;
John Zulaufbb9f07f2020-03-19 16:53:06 -06004602 std::vector<uint32_t> &last;
John Zulauf8863c332020-03-20 10:34:33 -06004603 std::vector<std::vector<RENDER_PASS_STATE::AttachmentTransition>> &subpass_transitions;
John Zulaufbb9f07f2020-03-19 16:53:06 -06004604 std::unordered_map<uint32_t, bool> &first_read;
4605 const uint32_t attachment_count;
John Zulauf8863c332020-03-20 10:34:33 -06004606 std::vector<VkImageLayout> attachment_layout;
John Zulauf2bc1fde2020-04-24 15:09:51 -06004607 std::vector<std::vector<VkImageLayout>> subpass_attachment_layout;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004608 explicit AttachmentTracker(std::shared_ptr<RENDER_PASS_STATE> &render_pass)
John Zulauf8863c332020-03-20 10:34:33 -06004609 : rp(render_pass.get()),
4610 first(rp->attachment_first_subpass),
John Zulauf1507ee42020-05-18 11:33:09 -06004611 first_is_transition(rp->attachment_first_is_transition),
John Zulauf8863c332020-03-20 10:34:33 -06004612 last(rp->attachment_last_subpass),
4613 subpass_transitions(rp->subpass_transitions),
4614 first_read(rp->attachment_first_read),
4615 attachment_count(rp->createInfo.attachmentCount),
John Zulauf2bc1fde2020-04-24 15:09:51 -06004616 attachment_layout(),
4617 subpass_attachment_layout() {
John Zulaufbb9f07f2020-03-19 16:53:06 -06004618 first.resize(attachment_count, VK_SUBPASS_EXTERNAL);
John Zulauf1507ee42020-05-18 11:33:09 -06004619 first_is_transition.resize(attachment_count, false);
John Zulaufbb9f07f2020-03-19 16:53:06 -06004620 last.resize(attachment_count, VK_SUBPASS_EXTERNAL);
John Zulauf8863c332020-03-20 10:34:33 -06004621 subpass_transitions.resize(rp->createInfo.subpassCount + 1); // Add an extra for EndRenderPass
4622 attachment_layout.reserve(attachment_count);
John Zulauf2bc1fde2020-04-24 15:09:51 -06004623 subpass_attachment_layout.resize(rp->createInfo.subpassCount);
4624 for (auto &subpass_layouts : subpass_attachment_layout) {
4625 subpass_layouts.resize(attachment_count, kInvalidLayout);
4626 }
4627
John Zulauf8863c332020-03-20 10:34:33 -06004628 for (uint32_t j = 0; j < attachment_count; j++) {
4629 attachment_layout.push_back(rp->createInfo.pAttachments[j].initialLayout);
4630 }
John Zulauf4aff5d92020-02-21 08:29:35 -07004631 }
John Zulauf4aff5d92020-02-21 08:29:35 -07004632
John Zulaufbb9f07f2020-03-19 16:53:06 -06004633 void Update(uint32_t subpass, const VkAttachmentReference2 *attach_ref, uint32_t count, bool is_read) {
4634 if (nullptr == attach_ref) return;
4635 for (uint32_t j = 0; j < count; ++j) {
4636 const auto attachment = attach_ref[j].attachment;
4637 if (attachment != VK_ATTACHMENT_UNUSED) {
John Zulauf8863c332020-03-20 10:34:33 -06004638 const auto layout = attach_ref[j].layout;
John Zulaufbb9f07f2020-03-19 16:53:06 -06004639 // Take advantage of the fact that insert won't overwrite, so we'll only write the first time.
4640 first_read.insert(std::make_pair(attachment, is_read));
John Zulauf2bc1fde2020-04-24 15:09:51 -06004641 if (first[attachment] == VK_SUBPASS_EXTERNAL) {
4642 first[attachment] = subpass;
4643 const auto initial_layout = rp->createInfo.pAttachments[attachment].initialLayout;
John Zulauf1507ee42020-05-18 11:33:09 -06004644 if (initial_layout != layout) {
4645 subpass_transitions[subpass].emplace_back(VK_SUBPASS_EXTERNAL, attachment, initial_layout, layout);
4646 first_is_transition[attachment] = true;
4647 }
John Zulauf2bc1fde2020-04-24 15:09:51 -06004648 }
John Zulaufbb9f07f2020-03-19 16:53:06 -06004649 last[attachment] = subpass;
John Zulauf8863c332020-03-20 10:34:33 -06004650
John Zulauf2bc1fde2020-04-24 15:09:51 -06004651 for (const auto &prev : rp->subpass_dependencies[subpass].prev) {
John Zulaufbaea94f2020-09-15 17:55:16 -06004652 const auto prev_pass = prev.first->pass;
John Zulauf2bc1fde2020-04-24 15:09:51 -06004653 const auto prev_layout = subpass_attachment_layout[prev_pass][attachment];
4654 if ((prev_layout != kInvalidLayout) && (prev_layout != layout)) {
4655 subpass_transitions[subpass].emplace_back(prev_pass, attachment, prev_layout, layout);
4656 }
John Zulauf8863c332020-03-20 10:34:33 -06004657 }
John Zulauf2bc1fde2020-04-24 15:09:51 -06004658 attachment_layout[attachment] = layout;
John Zulauf8863c332020-03-20 10:34:33 -06004659 }
4660 }
4661 }
4662 void FinalTransitions() {
4663 auto &final_transitions = subpass_transitions[rp->createInfo.subpassCount];
4664
4665 for (uint32_t attachment = 0; attachment < attachment_count; ++attachment) {
4666 const auto final_layout = rp->createInfo.pAttachments[attachment].finalLayout;
John Zulauf2bc1fde2020-04-24 15:09:51 -06004667 // Add final transitions for attachments that were used and change layout.
4668 if ((last[attachment] != VK_SUBPASS_EXTERNAL) && final_layout != attachment_layout[attachment]) {
4669 final_transitions.emplace_back(last[attachment], attachment, attachment_layout[attachment], final_layout);
John Zulaufbb9f07f2020-03-19 16:53:06 -06004670 }
locke-lunargd556cc32019-09-17 01:21:23 -06004671 }
4672 }
John Zulaufbb9f07f2020-03-19 16:53:06 -06004673 };
John Zulauf8863c332020-03-20 10:34:33 -06004674 AttachmentTracker attachment_tracker(render_pass);
John Zulaufbb9f07f2020-03-19 16:53:06 -06004675
4676 for (uint32_t subpass_index = 0; subpass_index < create_info->subpassCount; ++subpass_index) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08004677 const VkSubpassDescription2 &subpass = create_info->pSubpasses[subpass_index];
John Zulauf8863c332020-03-20 10:34:33 -06004678 attachment_tracker.Update(subpass_index, subpass.pColorAttachments, subpass.colorAttachmentCount, false);
4679 attachment_tracker.Update(subpass_index, subpass.pResolveAttachments, subpass.colorAttachmentCount, false);
4680 attachment_tracker.Update(subpass_index, subpass.pDepthStencilAttachment, 1, false);
4681 attachment_tracker.Update(subpass_index, subpass.pInputAttachments, subpass.inputAttachmentCount, true);
John Zulauf4aff5d92020-02-21 08:29:35 -07004682 }
John Zulauf8863c332020-03-20 10:34:33 -06004683 attachment_tracker.FinalTransitions();
John Zulauf4aff5d92020-02-21 08:29:35 -07004684
John Zulaufbb9f07f2020-03-19 16:53:06 -06004685 // Add implicit dependencies
John Zulauf8863c332020-03-20 10:34:33 -06004686 for (uint32_t attachment = 0; attachment < attachment_tracker.attachment_count; attachment++) {
4687 const auto first_use = attachment_tracker.first[attachment];
John Zulauf4aff5d92020-02-21 08:29:35 -07004688 if (first_use != VK_SUBPASS_EXTERNAL) {
4689 auto &subpass_dep = render_pass->subpass_dependencies[first_use];
John Zulaufbaea94f2020-09-15 17:55:16 -06004690 if (subpass_dep.barrier_from_external.size() == 0) {
4691 // Add implicit from barrier if they're aren't any
John Zulauf4aff5d92020-02-21 08:29:35 -07004692 subpass_dep.implicit_barrier_from_external.reset(
4693 new VkSubpassDependency2(ImplicitDependencyFromExternal(first_use)));
John Zulaufbaea94f2020-09-15 17:55:16 -06004694 subpass_dep.barrier_from_external.emplace_back(subpass_dep.implicit_barrier_from_external.get());
John Zulauf4aff5d92020-02-21 08:29:35 -07004695 }
4696 }
4697
John Zulauf8863c332020-03-20 10:34:33 -06004698 const auto last_use = attachment_tracker.last[attachment];
John Zulauf4aff5d92020-02-21 08:29:35 -07004699 if (last_use != VK_SUBPASS_EXTERNAL) {
4700 auto &subpass_dep = render_pass->subpass_dependencies[last_use];
John Zulaufbaea94f2020-09-15 17:55:16 -06004701 if (render_pass->subpass_dependencies[last_use].barrier_to_external.size() == 0) {
4702 // Add implicit to barrier if they're aren't any
John Zulauf4aff5d92020-02-21 08:29:35 -07004703 subpass_dep.implicit_barrier_to_external.reset(new VkSubpassDependency2(ImplicitDependencyToExternal(last_use)));
John Zulaufbaea94f2020-09-15 17:55:16 -06004704 subpass_dep.barrier_to_external.emplace_back(subpass_dep.implicit_barrier_to_external.get());
John Zulauf4aff5d92020-02-21 08:29:35 -07004705 }
locke-lunargd556cc32019-09-17 01:21:23 -06004706 }
4707 }
4708
4709 // Even though render_pass is an rvalue-ref parameter, still must move s.t. move assignment is invoked.
4710 renderPassMap[*pRenderPass] = std::move(render_pass);
4711}
4712
4713// Style note:
4714// Use of rvalue reference exceeds reccommended usage of rvalue refs in google style guide, but intentionally forces caller to move
4715// or copy. This is clearer than passing a pointer to shared_ptr and avoids the atomic increment/decrement of shared_ptr copy
4716// construction or assignment.
4717void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
4718 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4719 VkResult result) {
4720 if (VK_SUCCESS != result) return;
4721 auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo);
4722 RecordCreateRenderPassState(RENDER_PASS_VERSION_1, render_pass_state, pRenderPass);
4723}
4724
Mike Schuchardt2df08912020-12-15 16:28:09 -08004725void ValidationStateTracker::RecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07004726 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4727 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004728 if (VK_SUCCESS != result) return;
4729 auto render_pass_state = std::make_shared<RENDER_PASS_STATE>(pCreateInfo);
4730 RecordCreateRenderPassState(RENDER_PASS_VERSION_2, render_pass_state, pRenderPass);
4731}
4732
Mike Schuchardt2df08912020-12-15 16:28:09 -08004733void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07004734 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4735 VkResult result) {
4736 RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result);
4737}
4738
Mike Schuchardt2df08912020-12-15 16:28:09 -08004739void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
Tony-LunarG977448c2019-12-02 14:52:02 -07004740 const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
4741 VkResult result) {
4742 RecordCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, result);
4743}
4744
locke-lunargd556cc32019-09-17 01:21:23 -06004745void ValidationStateTracker::RecordCmdBeginRenderPassState(VkCommandBuffer commandBuffer,
4746 const VkRenderPassBeginInfo *pRenderPassBegin,
4747 const VkSubpassContents contents) {
4748 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunargaecf2152020-05-12 17:15:41 -06004749 auto render_pass_state = pRenderPassBegin ? GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass) : nullptr;
4750 auto framebuffer = pRenderPassBegin ? GetShared<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer) : nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004751
4752 if (render_pass_state) {
locke-lunargaecf2152020-05-12 17:15:41 -06004753 cb_state->activeFramebuffer = framebuffer;
locke-lunargd556cc32019-09-17 01:21:23 -06004754 cb_state->activeRenderPass = render_pass_state;
Tony-LunarG61e7c0c2020-03-03 16:09:11 -07004755 cb_state->activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin);
locke-lunargd556cc32019-09-17 01:21:23 -06004756 cb_state->activeSubpass = 0;
4757 cb_state->activeSubpassContents = contents;
locke-lunargfc78e932020-11-19 17:06:24 -07004758
locke-lunargd556cc32019-09-17 01:21:23 -06004759 // Connect this RP to cmdBuffer
locke-lunargaecf2152020-05-12 17:15:41 -06004760 AddCommandBufferBinding(
4761 render_pass_state->cb_bindings,
4762 VulkanTypedHandle(render_pass_state->renderPass, kVulkanObjectTypeRenderPass, render_pass_state.get()), cb_state);
locke-lunargd556cc32019-09-17 01:21:23 -06004763
4764 auto chained_device_group_struct = lvl_find_in_chain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext);
4765 if (chained_device_group_struct) {
4766 cb_state->active_render_pass_device_mask = chained_device_group_struct->deviceMask;
4767 } else {
4768 cb_state->active_render_pass_device_mask = cb_state->initial_device_mask;
4769 }
Lionel Landwerlin484d10f2020-04-24 01:34:47 +03004770
locke-lunargfc78e932020-11-19 17:06:24 -07004771 cb_state->active_subpasses = nullptr;
4772 cb_state->active_attachments = nullptr;
4773
4774 if (framebuffer) {
4775 cb_state->framebuffers.insert(framebuffer);
4776
4777 // Set cb_state->active_subpasses
4778 cb_state->active_subpasses =
4779 std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount);
4780 const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass];
4781 UpdateSubpassAttachments(subpass, *cb_state->active_subpasses);
4782
4783 // Set cb_state->active_attachments & cb_state->attachments_view_states
4784 cb_state->active_attachments =
4785 std::make_shared<std::vector<IMAGE_VIEW_STATE *>>(framebuffer->createInfo.attachmentCount);
4786 UpdateAttachmentsView(*this, *cb_state, *cb_state->activeFramebuffer, pRenderPassBegin);
4787
4788 // Connect this framebuffer and its children to this cmdBuffer
4789 AddFramebufferBinding(cb_state, framebuffer.get());
Lionel Landwerlin484d10f2020-04-24 01:34:47 +03004790 }
locke-lunargd556cc32019-09-17 01:21:23 -06004791 }
4792}
4793
4794void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
4795 const VkRenderPassBeginInfo *pRenderPassBegin,
4796 VkSubpassContents contents) {
4797 RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, contents);
4798}
4799
4800void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
4801 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004802 const VkSubpassBeginInfo *pSubpassBeginInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -06004803 RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents);
4804}
4805
Jeremy Hayes9bda85a2020-05-21 16:36:17 -06004806void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
4807 uint32_t counterBufferCount,
4808 const VkBuffer *pCounterBuffers,
4809 const VkDeviceSize *pCounterBufferOffsets) {
4810 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4811
4812 cb_state->transform_feedback_active = true;
4813}
4814
4815void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
4816 uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
4817 const VkDeviceSize *pCounterBufferOffsets) {
4818 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4819
4820 cb_state->transform_feedback_active = false;
4821}
4822
Tony-LunarG977448c2019-12-02 14:52:02 -07004823void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
4824 const VkRenderPassBeginInfo *pRenderPassBegin,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004825 const VkSubpassBeginInfo *pSubpassBeginInfo) {
Tony-LunarG977448c2019-12-02 14:52:02 -07004826 RecordCmdBeginRenderPassState(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents);
4827}
4828
locke-lunargd556cc32019-09-17 01:21:23 -06004829void ValidationStateTracker::RecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
4830 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4831 cb_state->activeSubpass++;
4832 cb_state->activeSubpassContents = contents;
locke-lunargfc78e932020-11-19 17:06:24 -07004833
4834 // Update cb_state->active_subpasses
4835 if (cb_state->activeRenderPass && cb_state->activeFramebuffer) {
4836 cb_state->active_subpasses = nullptr;
4837 cb_state->active_subpasses =
4838 std::make_shared<std::vector<SUBPASS_INFO>>(cb_state->activeFramebuffer->createInfo.attachmentCount);
4839
4840 const auto &subpass = cb_state->activeRenderPass->createInfo.pSubpasses[cb_state->activeSubpass];
4841 UpdateSubpassAttachments(subpass, *cb_state->active_subpasses);
4842 }
locke-lunargd556cc32019-09-17 01:21:23 -06004843}
4844
4845void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
4846 RecordCmdNextSubpass(commandBuffer, contents);
4847}
4848
4849void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004850 const VkSubpassBeginInfo *pSubpassBeginInfo,
4851 const VkSubpassEndInfo *pSubpassEndInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -06004852 RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents);
4853}
4854
Tony-LunarG977448c2019-12-02 14:52:02 -07004855void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004856 const VkSubpassBeginInfo *pSubpassBeginInfo,
4857 const VkSubpassEndInfo *pSubpassEndInfo) {
Tony-LunarG977448c2019-12-02 14:52:02 -07004858 RecordCmdNextSubpass(commandBuffer, pSubpassBeginInfo->contents);
4859}
4860
locke-lunargd556cc32019-09-17 01:21:23 -06004861void ValidationStateTracker::RecordCmdEndRenderPassState(VkCommandBuffer commandBuffer) {
4862 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4863 cb_state->activeRenderPass = nullptr;
locke-lunargfc78e932020-11-19 17:06:24 -07004864 cb_state->active_attachments = nullptr;
4865 cb_state->active_subpasses = nullptr;
locke-lunargd556cc32019-09-17 01:21:23 -06004866 cb_state->activeSubpass = 0;
4867 cb_state->activeFramebuffer = VK_NULL_HANDLE;
4868}
4869
4870void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
4871 RecordCmdEndRenderPassState(commandBuffer);
4872}
4873
4874void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004875 const VkSubpassEndInfo *pSubpassEndInfo) {
locke-lunargd556cc32019-09-17 01:21:23 -06004876 RecordCmdEndRenderPassState(commandBuffer);
4877}
4878
Tony-LunarG977448c2019-12-02 14:52:02 -07004879void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004880 const VkSubpassEndInfo *pSubpassEndInfo) {
Tony-LunarG977448c2019-12-02 14:52:02 -07004881 RecordCmdEndRenderPassState(commandBuffer);
4882}
locke-lunargd556cc32019-09-17 01:21:23 -06004883void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
4884 const VkCommandBuffer *pCommandBuffers) {
4885 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
4886
4887 CMD_BUFFER_STATE *sub_cb_state = NULL;
4888 for (uint32_t i = 0; i < commandBuffersCount; i++) {
4889 sub_cb_state = GetCBState(pCommandBuffers[i]);
4890 assert(sub_cb_state);
4891 if (!(sub_cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
4892 if (cb_state->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT) {
4893 // TODO: Because this is a state change, clearing the VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT needs to be moved
4894 // from the validation step to the recording step
4895 cb_state->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
4896 }
4897 }
4898
4899 // Propagate inital layout and current layout state to the primary cmd buffer
4900 // NOTE: The update/population of the image_layout_map is done in CoreChecks, but for other classes derived from
4901 // ValidationStateTracker these maps will be empty, so leaving the propagation in the the state tracker should be a no-op
4902 // for those other classes.
4903 for (const auto &sub_layout_map_entry : sub_cb_state->image_layout_map) {
4904 const auto image = sub_layout_map_entry.first;
4905 const auto *image_state = GetImageState(image);
4906 if (!image_state) continue; // Can't set layouts of a dead image
4907
4908 auto *cb_subres_map = GetImageSubresourceLayoutMap(cb_state, *image_state);
4909 const auto *sub_cb_subres_map = sub_layout_map_entry.second.get();
4910 assert(cb_subres_map && sub_cb_subres_map); // Non const get and map traversal should never be null
4911 cb_subres_map->UpdateFrom(*sub_cb_subres_map);
4912 }
4913
4914 sub_cb_state->primaryCommandBuffer = cb_state->commandBuffer;
4915 cb_state->linkedCommandBuffers.insert(sub_cb_state);
4916 sub_cb_state->linkedCommandBuffers.insert(cb_state);
4917 for (auto &function : sub_cb_state->queryUpdates) {
4918 cb_state->queryUpdates.push_back(function);
4919 }
4920 for (auto &function : sub_cb_state->queue_submit_functions) {
4921 cb_state->queue_submit_functions.push_back(function);
4922 }
4923 }
4924}
4925
4926void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
4927 VkFlags flags, void **ppData, VkResult result) {
4928 if (VK_SUCCESS != result) return;
4929 RecordMappedMemory(mem, offset, size, ppData);
4930}
4931
4932void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
4933 auto mem_info = GetDevMemState(mem);
4934 if (mem_info) {
4935 mem_info->mapped_range = MemRange();
4936 mem_info->p_driver_data = nullptr;
4937 }
4938}
4939
4940void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
4941 IMAGE_STATE *image_state = GetImageState(bindInfo.image);
4942 if (image_state) {
locke-lunargae26eac2020-04-16 15:29:05 -06004943 // An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
4944 // See: VUID-vkGetImageSubresourceLayout-image-01895
4945 image_state->fragment_encoder =
4946 std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
locke-lunargd556cc32019-09-17 01:21:23 -06004947 const auto swapchain_info = lvl_find_in_chain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
4948 if (swapchain_info) {
4949 auto swapchain = GetSwapchainState(swapchain_info->swapchain);
4950 if (swapchain) {
locke-lunargb3584732019-10-28 20:18:36 -06004951 swapchain->images[swapchain_info->imageIndex].bound_images.emplace(image_state->image);
locke-lunargd556cc32019-09-17 01:21:23 -06004952 image_state->bind_swapchain = swapchain_info->swapchain;
4953 image_state->bind_swapchain_imageIndex = swapchain_info->imageIndex;
4954 }
4955 } else {
4956 // Track bound memory range information
4957 auto mem_info = GetDevMemState(bindInfo.memory);
4958 if (mem_info) {
sfricke-samsungd7ea5de2020-04-08 09:19:18 -07004959 InsertImageMemoryRange(bindInfo.image, mem_info, bindInfo.memoryOffset);
locke-lunargd556cc32019-09-17 01:21:23 -06004960 }
4961
4962 // Track objects tied to memory
4963 SetMemBinding(bindInfo.memory, image_state, bindInfo.memoryOffset,
4964 VulkanTypedHandle(bindInfo.image, kVulkanObjectTypeImage));
4965 }
Tony-LunarG330cf4c2020-03-04 16:29:03 -07004966 if ((image_state->createInfo.flags & VK_IMAGE_CREATE_ALIAS_BIT) || swapchain_info) {
locke-lunargd556cc32019-09-17 01:21:23 -06004967 AddAliasingImage(image_state);
4968 }
4969 }
4970}
4971
4972void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
4973 VkDeviceSize memoryOffset, VkResult result) {
4974 if (VK_SUCCESS != result) return;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07004975 VkBindImageMemoryInfo bind_info = {};
4976 bind_info.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
4977 bind_info.image = image;
4978 bind_info.memory = mem;
4979 bind_info.memoryOffset = memoryOffset;
4980 UpdateBindImageMemoryState(bind_info);
locke-lunargd556cc32019-09-17 01:21:23 -06004981}
4982
4983void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004984 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004985 if (VK_SUCCESS != result) return;
4986 for (uint32_t i = 0; i < bindInfoCount; i++) {
4987 UpdateBindImageMemoryState(pBindInfos[i]);
4988 }
4989}
4990
4991void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
Mike Schuchardt2df08912020-12-15 16:28:09 -08004992 const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06004993 if (VK_SUCCESS != result) return;
4994 for (uint32_t i = 0; i < bindInfoCount; i++) {
4995 UpdateBindImageMemoryState(pBindInfos[i]);
4996 }
4997}
4998
4999void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
5000 auto event_state = GetEventState(event);
5001 if (event_state) {
5002 event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
5003 }
locke-lunargd556cc32019-09-17 01:21:23 -06005004}
5005
5006void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
5007 const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
5008 VkResult result) {
5009 if (VK_SUCCESS != result) return;
5010 RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
5011 pImportSemaphoreFdInfo->flags);
5012}
5013
5014void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005015 VkExternalSemaphoreHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06005016 SEMAPHORE_STATE *semaphore_state = GetSemaphoreState(semaphore);
Mike Schuchardt2df08912020-12-15 16:28:09 -08005017 if (semaphore_state && handle_type != VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06005018 // Cannot track semaphore state once it is exported, except for Sync FD handle types which have copy transference
5019 semaphore_state->scope = kSyncScopeExternalPermanent;
5020 }
5021}
5022
5023#ifdef VK_USE_PLATFORM_WIN32_KHR
5024void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
5025 VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
5026 if (VK_SUCCESS != result) return;
5027 RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
5028 pImportSemaphoreWin32HandleInfo->flags);
5029}
5030
5031void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
5032 const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
5033 HANDLE *pHandle, VkResult result) {
5034 if (VK_SUCCESS != result) return;
5035 RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
5036}
5037
5038void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
5039 VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
5040 if (VK_SUCCESS != result) return;
5041 RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
5042 pImportFenceWin32HandleInfo->flags);
5043}
5044
5045void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
5046 const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
5047 HANDLE *pHandle, VkResult result) {
5048 if (VK_SUCCESS != result) return;
5049 RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
5050}
5051#endif
5052
5053void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
5054 VkResult result) {
5055 if (VK_SUCCESS != result) return;
5056 RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
5057}
5058
Mike Schuchardt2df08912020-12-15 16:28:09 -08005059void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
5060 VkFenceImportFlags flags) {
locke-lunargd556cc32019-09-17 01:21:23 -06005061 FENCE_STATE *fence_node = GetFenceState(fence);
5062 if (fence_node && fence_node->scope != kSyncScopeExternalPermanent) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08005063 if ((handle_type == VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT || flags & VK_FENCE_IMPORT_TEMPORARY_BIT) &&
locke-lunargd556cc32019-09-17 01:21:23 -06005064 fence_node->scope == kSyncScopeInternal) {
5065 fence_node->scope = kSyncScopeExternalTemporary;
5066 } else {
5067 fence_node->scope = kSyncScopeExternalPermanent;
5068 }
5069 }
5070}
5071
5072void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
5073 VkResult result) {
5074 if (VK_SUCCESS != result) return;
5075 RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
5076}
5077
Mike Schuchardt2df08912020-12-15 16:28:09 -08005078void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
locke-lunargd556cc32019-09-17 01:21:23 -06005079 FENCE_STATE *fence_state = GetFenceState(fence);
5080 if (fence_state) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08005081 if (handle_type != VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT) {
locke-lunargd556cc32019-09-17 01:21:23 -06005082 // Export with reference transference becomes external
5083 fence_state->scope = kSyncScopeExternalPermanent;
5084 } else if (fence_state->scope == kSyncScopeInternal) {
5085 // Export with copy transference has a side effect of resetting the fence
5086 fence_state->state = FENCE_UNSIGNALED;
5087 }
5088 }
5089}
5090
5091void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
5092 VkResult result) {
5093 if (VK_SUCCESS != result) return;
5094 RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
5095}
5096
5097void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
5098 const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
5099 if (VK_SUCCESS != result) return;
5100 eventMap[*pEvent].write_in_use = 0;
5101 eventMap[*pEvent].stageMask = VkPipelineStageFlags(0);
5102}
5103
5104void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
5105 VkSwapchainKHR *pSwapchain, SURFACE_STATE *surface_state,
5106 SWAPCHAIN_NODE *old_swapchain_state) {
5107 if (VK_SUCCESS == result) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005108 auto swapchain_state = std::make_shared<SWAPCHAIN_NODE>(pCreateInfo, *pSwapchain);
locke-lunargd556cc32019-09-17 01:21:23 -06005109 if (VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR == pCreateInfo->presentMode ||
5110 VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR == pCreateInfo->presentMode) {
5111 swapchain_state->shared_presentable = true;
5112 }
5113 surface_state->swapchain = swapchain_state.get();
5114 swapchainMap[*pSwapchain] = std::move(swapchain_state);
5115 } else {
5116 surface_state->swapchain = nullptr;
5117 }
5118 // Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
5119 if (old_swapchain_state) {
5120 old_swapchain_state->retired = true;
5121 }
5122 return;
5123}
5124
5125void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
5126 const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
5127 VkResult result) {
5128 auto surface_state = GetSurfaceState(pCreateInfo->surface);
5129 auto old_swapchain_state = GetSwapchainState(pCreateInfo->oldSwapchain);
5130 RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, surface_state, old_swapchain_state);
5131}
5132
5133void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
5134 const VkAllocationCallbacks *pAllocator) {
5135 if (!swapchain) return;
5136 auto swapchain_data = GetSwapchainState(swapchain);
5137 if (swapchain_data) {
5138 for (const auto &swapchain_image : swapchain_data->images) {
locke-lunargb3584732019-10-28 20:18:36 -06005139 ClearMemoryObjectBindings(VulkanTypedHandle(swapchain_image.image, kVulkanObjectTypeImage));
5140 imageMap.erase(swapchain_image.image);
5141 RemoveAliasingImages(swapchain_image.bound_images);
locke-lunargd556cc32019-09-17 01:21:23 -06005142 }
5143
5144 auto surface_state = GetSurfaceState(swapchain_data->createInfo.surface);
5145 if (surface_state) {
5146 if (surface_state->swapchain == swapchain_data) surface_state->swapchain = nullptr;
5147 }
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005148 swapchain_data->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005149 swapchainMap.erase(swapchain);
5150 }
5151}
5152
sfricke-samsung5c1b7392020-12-13 22:17:15 -08005153void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
5154 const VkDisplayModeCreateInfoKHR *pCreateInfo,
5155 const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
5156 VkResult result) {
5157 if (VK_SUCCESS != result) return;
5158 if (!pMode) return;
5159 auto display_mode_state = std::make_shared<DISPLAY_MODE_STATE>(*pMode);
5160 display_mode_state->physical_device = physicalDevice;
5161 display_mode_map[*pMode] = std::move(display_mode_state);
5162}
5163
locke-lunargd556cc32019-09-17 01:21:23 -06005164void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
5165 // Semaphore waits occur before error generation, if the call reached the ICD. (Confirm?)
5166 for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005167 auto semaphore_state = GetSemaphoreState(pPresentInfo->pWaitSemaphores[i]);
5168 if (semaphore_state) {
5169 semaphore_state->signaler.first = VK_NULL_HANDLE;
5170 semaphore_state->signaled = false;
locke-lunargd556cc32019-09-17 01:21:23 -06005171 }
5172 }
5173
5174 for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
5175 // 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
5176 // confused itself just as much.
5177 auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
5178 if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
5179 // Mark the image as having been released to the WSI
5180 auto swapchain_data = GetSwapchainState(pPresentInfo->pSwapchains[i]);
5181 if (swapchain_data && (swapchain_data->images.size() > pPresentInfo->pImageIndices[i])) {
locke-lunargb3584732019-10-28 20:18:36 -06005182 auto image = swapchain_data->images[pPresentInfo->pImageIndices[i]].image;
locke-lunargd556cc32019-09-17 01:21:23 -06005183 auto image_state = GetImageState(image);
5184 if (image_state) {
5185 image_state->acquired = false;
Jeff Bolz46c0ea02019-10-09 13:06:29 -05005186 if (image_state->shared_presentable) {
5187 image_state->layout_locked = true;
5188 }
locke-lunargd556cc32019-09-17 01:21:23 -06005189 }
5190 }
5191 }
5192 // Note: even though presentation is directed to a queue, there is no direct ordering between QP and subsequent work, so QP (and
5193 // its semaphore waits) /never/ participate in any completion proof.
5194}
5195
5196void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
5197 const VkSwapchainCreateInfoKHR *pCreateInfos,
5198 const VkAllocationCallbacks *pAllocator,
5199 VkSwapchainKHR *pSwapchains, VkResult result) {
5200 if (pCreateInfos) {
5201 for (uint32_t i = 0; i < swapchainCount; i++) {
5202 auto surface_state = GetSurfaceState(pCreateInfos[i].surface);
5203 auto old_swapchain_state = GetSwapchainState(pCreateInfos[i].oldSwapchain);
5204 RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], surface_state, old_swapchain_state);
5205 }
5206 }
5207}
5208
5209void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
5210 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005211 auto fence_state = GetFenceState(fence);
5212 if (fence_state && fence_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06005213 // Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
5214 // import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005215 fence_state->state = FENCE_INFLIGHT;
5216 fence_state->signaler.first = VK_NULL_HANDLE; // ANI isn't on a queue, so this can't participate in a completion proof.
locke-lunargd556cc32019-09-17 01:21:23 -06005217 }
5218
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005219 auto semaphore_state = GetSemaphoreState(semaphore);
5220 if (semaphore_state && semaphore_state->scope == kSyncScopeInternal) {
locke-lunargd556cc32019-09-17 01:21:23 -06005221 // Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
5222 // temporary import
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005223 semaphore_state->signaled = true;
5224 semaphore_state->signaler.first = VK_NULL_HANDLE;
locke-lunargd556cc32019-09-17 01:21:23 -06005225 }
5226
5227 // Mark the image as acquired.
5228 auto swapchain_data = GetSwapchainState(swapchain);
5229 if (swapchain_data && (swapchain_data->images.size() > *pImageIndex)) {
locke-lunargb3584732019-10-28 20:18:36 -06005230 auto image = swapchain_data->images[*pImageIndex].image;
locke-lunargd556cc32019-09-17 01:21:23 -06005231 auto image_state = GetImageState(image);
5232 if (image_state) {
5233 image_state->acquired = true;
5234 image_state->shared_presentable = swapchain_data->shared_presentable;
5235 }
5236 }
5237}
5238
5239void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
5240 VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
5241 VkResult result) {
5242 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
5243 RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
5244}
5245
5246void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
5247 uint32_t *pImageIndex, VkResult result) {
5248 if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
5249 RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
5250 pAcquireInfo->fence, pImageIndex);
5251}
5252
5253void ValidationStateTracker::PostCallRecordEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount,
5254 VkPhysicalDevice *pPhysicalDevices, VkResult result) {
5255 if ((NULL != pPhysicalDevices) && ((result == VK_SUCCESS || result == VK_INCOMPLETE))) {
5256 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
5257 auto &phys_device_state = physical_device_map[pPhysicalDevices[i]];
5258 phys_device_state.phys_device = pPhysicalDevices[i];
5259 // Init actual features for each physical device
5260 DispatchGetPhysicalDeviceFeatures(pPhysicalDevices[i], &phys_device_state.features2.features);
5261 }
5262 }
5263}
5264
5265// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
5266static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005267 VkQueueFamilyProperties2 *pQueueFamilyProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06005268 pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
5269
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06005270 if (pQueueFamilyProperties) { // Save queue family properties
locke-lunargd556cc32019-09-17 01:21:23 -06005271 pd_state->queue_family_properties.resize(std::max(static_cast<uint32_t>(pd_state->queue_family_properties.size()), count));
5272 for (uint32_t i = 0; i < count; ++i) {
5273 pd_state->queue_family_properties[i] = pQueueFamilyProperties[i].queueFamilyProperties;
5274 }
5275 }
5276}
5277
5278void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
5279 uint32_t *pQueueFamilyPropertyCount,
5280 VkQueueFamilyProperties *pQueueFamilyProperties) {
5281 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
5282 assert(physical_device_state);
Mike Schuchardt2df08912020-12-15 16:28:09 -08005283 VkQueueFamilyProperties2 *pqfp = nullptr;
5284 std::vector<VkQueueFamilyProperties2> qfp;
locke-lunargd556cc32019-09-17 01:21:23 -06005285 qfp.resize(*pQueueFamilyPropertyCount);
5286 if (pQueueFamilyProperties) {
5287 for (uint32_t i = 0; i < *pQueueFamilyPropertyCount; ++i) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08005288 qfp[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2;
locke-lunargd556cc32019-09-17 01:21:23 -06005289 qfp[i].pNext = nullptr;
5290 qfp[i].queueFamilyProperties = pQueueFamilyProperties[i];
5291 }
5292 pqfp = qfp.data();
5293 }
5294 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount, pqfp);
5295}
5296
5297void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005298 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06005299 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
5300 assert(physical_device_state);
5301 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount,
5302 pQueueFamilyProperties);
5303}
5304
5305void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005306 VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06005307 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
5308 assert(physical_device_state);
5309 StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(physical_device_state, *pQueueFamilyPropertyCount,
5310 pQueueFamilyProperties);
5311}
5312void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
5313 const VkAllocationCallbacks *pAllocator) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005314 if (!surface) return;
5315 auto surface_state = GetSurfaceState(surface);
5316 surface_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005317 surface_map.erase(surface);
5318}
5319
5320void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) {
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005321 surface_map[*pSurface] = std::make_shared<SURFACE_STATE>(*pSurface);
locke-lunargd556cc32019-09-17 01:21:23 -06005322}
5323
5324void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
5325 const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
5326 const VkAllocationCallbacks *pAllocator,
5327 VkSurfaceKHR *pSurface, VkResult result) {
5328 if (VK_SUCCESS != result) return;
5329 RecordVulkanSurface(pSurface);
5330}
5331
5332#ifdef VK_USE_PLATFORM_ANDROID_KHR
5333void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
5334 const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
5335 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5336 VkResult result) {
5337 if (VK_SUCCESS != result) return;
5338 RecordVulkanSurface(pSurface);
5339}
5340#endif // VK_USE_PLATFORM_ANDROID_KHR
5341
5342#ifdef VK_USE_PLATFORM_IOS_MVK
5343void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
5344 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5345 VkResult result) {
5346 if (VK_SUCCESS != result) return;
5347 RecordVulkanSurface(pSurface);
5348}
5349#endif // VK_USE_PLATFORM_IOS_MVK
5350
5351#ifdef VK_USE_PLATFORM_MACOS_MVK
5352void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
5353 const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
5354 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5355 VkResult result) {
5356 if (VK_SUCCESS != result) return;
5357 RecordVulkanSurface(pSurface);
5358}
5359#endif // VK_USE_PLATFORM_MACOS_MVK
5360
Jeremy Kniagerf33a67c2019-12-09 09:44:39 -07005361#ifdef VK_USE_PLATFORM_METAL_EXT
5362void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
5363 const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
5364 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5365 VkResult result) {
5366 if (VK_SUCCESS != result) return;
5367 RecordVulkanSurface(pSurface);
5368}
5369#endif // VK_USE_PLATFORM_METAL_EXT
5370
locke-lunargd556cc32019-09-17 01:21:23 -06005371#ifdef VK_USE_PLATFORM_WAYLAND_KHR
5372void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
5373 const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
5374 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5375 VkResult result) {
5376 if (VK_SUCCESS != result) return;
5377 RecordVulkanSurface(pSurface);
5378}
5379#endif // VK_USE_PLATFORM_WAYLAND_KHR
5380
5381#ifdef VK_USE_PLATFORM_WIN32_KHR
5382void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
5383 const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
5384 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5385 VkResult result) {
5386 if (VK_SUCCESS != result) return;
5387 RecordVulkanSurface(pSurface);
5388}
5389#endif // VK_USE_PLATFORM_WIN32_KHR
5390
5391#ifdef VK_USE_PLATFORM_XCB_KHR
5392void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
5393 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5394 VkResult result) {
5395 if (VK_SUCCESS != result) return;
5396 RecordVulkanSurface(pSurface);
5397}
5398#endif // VK_USE_PLATFORM_XCB_KHR
5399
5400#ifdef VK_USE_PLATFORM_XLIB_KHR
5401void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
5402 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5403 VkResult result) {
5404 if (VK_SUCCESS != result) return;
5405 RecordVulkanSurface(pSurface);
5406}
5407#endif // VK_USE_PLATFORM_XLIB_KHR
5408
Niklas Haas8b84af12020-04-19 22:20:11 +02005409void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
5410 const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
5411 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
5412 VkResult result) {
5413 if (VK_SUCCESS != result) return;
5414 RecordVulkanSurface(pSurface);
5415}
5416
Cort23cf2282019-09-20 18:58:18 +02005417void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
Cortffba2642019-09-20 22:09:41 +02005418 VkPhysicalDeviceFeatures *pFeatures) {
5419 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
Yilong Li358152a2020-07-08 02:16:45 -07005420 // Reset the features2 safe struct before setting up the features field.
5421 physical_device_state->features2 = safe_VkPhysicalDeviceFeatures2();
Cortffba2642019-09-20 22:09:41 +02005422 physical_device_state->features2.features = *pFeatures;
Cort23cf2282019-09-20 18:58:18 +02005423}
5424
5425void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
Cortffba2642019-09-20 22:09:41 +02005426 VkPhysicalDeviceFeatures2 *pFeatures) {
5427 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
Cortffba2642019-09-20 22:09:41 +02005428 physical_device_state->features2.initialize(pFeatures);
Cort23cf2282019-09-20 18:58:18 +02005429}
5430
5431void ValidationStateTracker::PostCallRecordGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice,
Cortffba2642019-09-20 22:09:41 +02005432 VkPhysicalDeviceFeatures2 *pFeatures) {
5433 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
Cortffba2642019-09-20 22:09:41 +02005434 physical_device_state->features2.initialize(pFeatures);
Cort23cf2282019-09-20 18:58:18 +02005435}
5436
locke-lunargd556cc32019-09-17 01:21:23 -06005437void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
5438 VkSurfaceKHR surface,
5439 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
5440 VkResult result) {
5441 if (VK_SUCCESS != result) return;
5442 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005443 physical_device_state->surfaceCapabilities = *pSurfaceCapabilities;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06005444
5445 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
5446 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005447}
5448
5449void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
5450 VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
5451 VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
5452 if (VK_SUCCESS != result) return;
5453 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005454 physical_device_state->surfaceCapabilities = pSurfaceCapabilities->surfaceCapabilities;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06005455
5456 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
5457 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005458}
5459
5460void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
5461 VkSurfaceKHR surface,
5462 VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
5463 VkResult result) {
5464 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005465 physical_device_state->surfaceCapabilities.minImageCount = pSurfaceCapabilities->minImageCount;
5466 physical_device_state->surfaceCapabilities.maxImageCount = pSurfaceCapabilities->maxImageCount;
5467 physical_device_state->surfaceCapabilities.currentExtent = pSurfaceCapabilities->currentExtent;
5468 physical_device_state->surfaceCapabilities.minImageExtent = pSurfaceCapabilities->minImageExtent;
5469 physical_device_state->surfaceCapabilities.maxImageExtent = pSurfaceCapabilities->maxImageExtent;
5470 physical_device_state->surfaceCapabilities.maxImageArrayLayers = pSurfaceCapabilities->maxImageArrayLayers;
5471 physical_device_state->surfaceCapabilities.supportedTransforms = pSurfaceCapabilities->supportedTransforms;
5472 physical_device_state->surfaceCapabilities.currentTransform = pSurfaceCapabilities->currentTransform;
5473 physical_device_state->surfaceCapabilities.supportedCompositeAlpha = pSurfaceCapabilities->supportedCompositeAlpha;
5474 physical_device_state->surfaceCapabilities.supportedUsageFlags = pSurfaceCapabilities->supportedUsageFlags;
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06005475
5476 // TODO May make sense to move this to BestPractices, but needs further refactoring in CoreChecks first
5477 physical_device_state->vkGetPhysicalDeviceSurfaceCapabilitiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005478}
5479
5480void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
5481 uint32_t queueFamilyIndex, VkSurfaceKHR surface,
5482 VkBool32 *pSupported, VkResult result) {
5483 if (VK_SUCCESS != result) return;
5484 auto surface_state = GetSurfaceState(surface);
5485 surface_state->gpu_queue_support[{physicalDevice, queueFamilyIndex}] = (*pSupported == VK_TRUE);
5486}
5487
5488void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
5489 VkSurfaceKHR surface,
5490 uint32_t *pPresentModeCount,
5491 VkPresentModeKHR *pPresentModes,
5492 VkResult result) {
5493 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5494
5495 // TODO: This isn't quite right -- available modes may differ by surface AND physical device.
5496 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005497
5498 if (*pPresentModeCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005499 if (*pPresentModeCount > physical_device_state->present_modes.size()) {
locke-lunargd556cc32019-09-17 01:21:23 -06005500 physical_device_state->present_modes.resize(*pPresentModeCount);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005501 }
locke-lunargd556cc32019-09-17 01:21:23 -06005502 }
5503 if (pPresentModes) {
locke-lunargd556cc32019-09-17 01:21:23 -06005504 for (uint32_t i = 0; i < *pPresentModeCount; i++) {
5505 physical_device_state->present_modes[i] = pPresentModes[i];
5506 }
5507 }
5508}
5509
5510void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
5511 uint32_t *pSurfaceFormatCount,
5512 VkSurfaceFormatKHR *pSurfaceFormats,
5513 VkResult result) {
5514 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5515
5516 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005517
5518 if (*pSurfaceFormatCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005519 if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) {
locke-lunargd556cc32019-09-17 01:21:23 -06005520 physical_device_state->surface_formats.resize(*pSurfaceFormatCount);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005521 }
locke-lunargd556cc32019-09-17 01:21:23 -06005522 }
5523 if (pSurfaceFormats) {
locke-lunargd556cc32019-09-17 01:21:23 -06005524 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
5525 physical_device_state->surface_formats[i] = pSurfaceFormats[i];
5526 }
5527 }
5528}
5529
5530void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
5531 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
5532 uint32_t *pSurfaceFormatCount,
5533 VkSurfaceFormat2KHR *pSurfaceFormats,
5534 VkResult result) {
5535 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5536
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005537 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
locke-lunargd556cc32019-09-17 01:21:23 -06005538 if (*pSurfaceFormatCount) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005539 if (*pSurfaceFormatCount > physical_device_state->surface_formats.size()) {
5540 physical_device_state->surface_formats.resize(*pSurfaceFormatCount);
5541 }
locke-lunargd556cc32019-09-17 01:21:23 -06005542 }
5543 if (pSurfaceFormats) {
locke-lunargd556cc32019-09-17 01:21:23 -06005544 for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005545 physical_device_state->surface_formats[i] = pSurfaceFormats[i].surfaceFormat;
locke-lunargd556cc32019-09-17 01:21:23 -06005546 }
5547 }
5548}
5549
5550void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
5551 const VkDebugUtilsLabelEXT *pLabelInfo) {
5552 BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
5553}
5554
5555void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
5556 EndCmdDebugUtilsLabel(report_data, commandBuffer);
5557}
5558
5559void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
5560 const VkDebugUtilsLabelEXT *pLabelInfo) {
5561 InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
5562
5563 // Squirrel away an easily accessible copy.
5564 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5565 cb_state->debug_label = LoggingLabel(pLabelInfo);
5566}
5567
5568void ValidationStateTracker::RecordEnumeratePhysicalDeviceGroupsState(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005569 uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) {
locke-lunargd556cc32019-09-17 01:21:23 -06005570 if (NULL != pPhysicalDeviceGroupProperties) {
5571 for (uint32_t i = 0; i < *pPhysicalDeviceGroupCount; i++) {
5572 for (uint32_t j = 0; j < pPhysicalDeviceGroupProperties[i].physicalDeviceCount; j++) {
5573 VkPhysicalDevice cur_phys_dev = pPhysicalDeviceGroupProperties[i].physicalDevices[j];
5574 auto &phys_device_state = physical_device_map[cur_phys_dev];
5575 phys_device_state.phys_device = cur_phys_dev;
5576 // Init actual features for each physical device
5577 DispatchGetPhysicalDeviceFeatures(cur_phys_dev, &phys_device_state.features2.features);
5578 }
5579 }
5580 }
5581}
5582
5583void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroups(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005584 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06005585 VkResult result) {
5586 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5587 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
5588}
5589
5590void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceGroupsKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005591 VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties,
locke-lunargd556cc32019-09-17 01:21:23 -06005592 VkResult result) {
5593 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5594 RecordEnumeratePhysicalDeviceGroupsState(pPhysicalDeviceGroupCount, pPhysicalDeviceGroupProperties);
5595}
5596
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005597void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
5598 uint32_t queueFamilyIndex,
5599 uint32_t *pCounterCount,
5600 VkPerformanceCounterKHR *pCounters) {
5601 if (NULL == pCounters) return;
5602
5603 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
5604 assert(physical_device_state);
5605
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005606 std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
5607 queue_family_counters->counters.resize(*pCounterCount);
5608 for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005609
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005610 physical_device_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005611}
5612
5613void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
5614 VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
5615 VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
5616 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5617 RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
5618}
5619
5620void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
5621 VkResult result) {
5622 if (result == VK_SUCCESS) performance_lock_acquired = true;
5623}
5624
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005625void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
5626 performance_lock_acquired = false;
5627 for (auto &cmd_buffer : commandBufferMap) {
5628 cmd_buffer.second->performance_lock_released = true;
5629 }
5630}
5631
locke-lunargd556cc32019-09-17 01:21:23 -06005632void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005633 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06005634 const VkAllocationCallbacks *pAllocator) {
5635 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005636 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
5637 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005638 desc_template_map.erase(descriptorUpdateTemplate);
5639}
5640
5641void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005642 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06005643 const VkAllocationCallbacks *pAllocator) {
5644 if (!descriptorUpdateTemplate) return;
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005645 auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
5646 template_state->destroyed = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005647 desc_template_map.erase(descriptorUpdateTemplate);
5648}
5649
Mike Schuchardt2df08912020-12-15 16:28:09 -08005650void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
5651 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
locke-lunargd556cc32019-09-17 01:21:23 -06005652 safe_VkDescriptorUpdateTemplateCreateInfo local_create_info(pCreateInfo);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05005653 auto template_state = std::make_shared<TEMPLATE_STATE>(*pDescriptorUpdateTemplate, &local_create_info);
locke-lunargd556cc32019-09-17 01:21:23 -06005654 desc_template_map[*pDescriptorUpdateTemplate] = std::move(template_state);
5655}
5656
Mike Schuchardt2df08912020-12-15 16:28:09 -08005657void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
5658 const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
5659 const VkAllocationCallbacks *pAllocator,
5660 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
5661 VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06005662 if (VK_SUCCESS != result) return;
5663 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
5664}
5665
5666void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
Mike Schuchardt2df08912020-12-15 16:28:09 -08005667 VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
5668 VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
locke-lunargd556cc32019-09-17 01:21:23 -06005669 if (VK_SUCCESS != result) return;
5670 RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
5671}
5672
5673void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005674 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06005675 const void *pData) {
5676 auto const template_map_entry = desc_template_map.find(descriptorUpdateTemplate);
5677 if ((template_map_entry == desc_template_map.end()) || (template_map_entry->second.get() == nullptr)) {
5678 assert(0);
5679 } else {
5680 const TEMPLATE_STATE *template_state = template_map_entry->second.get();
5681 // TODO: Record template push descriptor updates
5682 if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
5683 PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state, pData);
5684 }
5685 }
5686}
5687
5688void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
5689 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
5690 const void *pData) {
5691 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
5692}
5693
5694void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
Mike Schuchardt2df08912020-12-15 16:28:09 -08005695 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
locke-lunargd556cc32019-09-17 01:21:23 -06005696 const void *pData) {
5697 RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
5698}
5699
Mike Schuchardt2df08912020-12-15 16:28:09 -08005700void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
5701 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
5702 VkPipelineLayout layout, uint32_t set,
5703 const void *pData) {
locke-lunargd556cc32019-09-17 01:21:23 -06005704 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5705
5706 const auto template_state = GetDescriptorTemplateState(descriptorUpdateTemplate);
5707 if (template_state) {
5708 auto layout_data = GetPipelineLayout(layout);
5709 auto dsl = GetDslFromPipelineLayout(layout_data, set);
5710 const auto &template_ci = template_state->create_info;
Jeff Bolz6ae39612019-10-11 20:57:36 -05005711 if (dsl && !dsl->destroyed) {
locke-lunargd556cc32019-09-17 01:21:23 -06005712 // Decode the template into a set of write updates
5713 cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state, pData,
5714 dsl->GetDescriptorSetLayout());
5715 RecordCmdPushDescriptorSetState(cb_state, template_ci.pipelineBindPoint, layout, set,
5716 static_cast<uint32_t>(decoded_template.desc_writes.size()),
5717 decoded_template.desc_writes.data());
5718 }
5719 }
5720}
5721
5722void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
5723 uint32_t *pPropertyCount, void *pProperties) {
5724 auto physical_device_state = GetPhysicalDeviceState(physicalDevice);
5725 if (*pPropertyCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06005726 physical_device_state->display_plane_property_count = *pPropertyCount;
5727 }
Nathaniel Cesario24184fe2020-10-06 12:46:12 -06005728 if (*pPropertyCount || pProperties) {
5729 physical_device_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
locke-lunargd556cc32019-09-17 01:21:23 -06005730 }
5731}
5732
5733void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
5734 uint32_t *pPropertyCount,
5735 VkDisplayPlanePropertiesKHR *pProperties,
5736 VkResult result) {
5737 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5738 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
5739}
5740
5741void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
5742 uint32_t *pPropertyCount,
5743 VkDisplayPlaneProperties2KHR *pProperties,
5744 VkResult result) {
5745 if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
5746 RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
5747}
5748
5749void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
5750 uint32_t query, VkQueryControlFlags flags, uint32_t index) {
5751 QueryObject query_obj = {queryPool, query, index};
5752 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5753 RecordCmdBeginQuery(cb_state, query_obj);
5754}
5755
5756void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
5757 uint32_t query, uint32_t index) {
5758 QueryObject query_obj = {queryPool, query, index};
5759 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5760 RecordCmdEndQuery(cb_state, query_obj);
5761}
5762
5763void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
5764 VkSamplerYcbcrConversion ycbcr_conversion) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005765 auto ycbcr_state = std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>();
5766
locke-lunargd556cc32019-09-17 01:21:23 -06005767 if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005768 RecordCreateSamplerYcbcrConversionANDROID(create_info, ycbcr_conversion, ycbcr_state.get());
locke-lunargd556cc32019-09-17 01:21:23 -06005769 }
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005770
5771 const VkFormat conversion_format = create_info->format;
5772
5773 if (conversion_format != VK_FORMAT_UNDEFINED) {
5774 // If format is VK_FORMAT_UNDEFINED, will be set by external AHB features
5775 ycbcr_state->format_features = GetPotentialFormatFeatures(conversion_format);
5776 }
5777
5778 ycbcr_state->chromaFilter = create_info->chromaFilter;
5779 ycbcr_state->format = conversion_format;
5780 samplerYcbcrConversionMap[ycbcr_conversion] = std::move(ycbcr_state);
locke-lunargd556cc32019-09-17 01:21:23 -06005781}
5782
5783void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
5784 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
5785 const VkAllocationCallbacks *pAllocator,
5786 VkSamplerYcbcrConversion *pYcbcrConversion,
5787 VkResult result) {
5788 if (VK_SUCCESS != result) return;
5789 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
5790}
5791
5792void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
5793 const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
5794 const VkAllocationCallbacks *pAllocator,
5795 VkSamplerYcbcrConversion *pYcbcrConversion,
5796 VkResult result) {
5797 if (VK_SUCCESS != result) return;
5798 RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
5799}
5800
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005801void ValidationStateTracker::RecordDestroySamplerYcbcrConversionState(VkSamplerYcbcrConversion ycbcr_conversion) {
5802 if (device_extensions.vk_android_external_memory_android_hardware_buffer) {
5803 RecordDestroySamplerYcbcrConversionANDROID(ycbcr_conversion);
5804 }
5805
5806 auto ycbcr_state = GetSamplerYcbcrConversionState(ycbcr_conversion);
5807 ycbcr_state->destroyed = true;
5808 samplerYcbcrConversionMap.erase(ycbcr_conversion);
5809}
5810
locke-lunargd556cc32019-09-17 01:21:23 -06005811void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
5812 const VkAllocationCallbacks *pAllocator) {
5813 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005814 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06005815}
5816
5817void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
5818 VkSamplerYcbcrConversion ycbcrConversion,
5819 const VkAllocationCallbacks *pAllocator) {
5820 if (!ycbcrConversion) return;
sfricke-samsungbe3584f2020-04-22 14:58:06 -07005821 RecordDestroySamplerYcbcrConversionState(ycbcrConversion);
locke-lunargd556cc32019-09-17 01:21:23 -06005822}
5823
Tony-LunarG977448c2019-12-02 14:52:02 -07005824void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
5825 uint32_t queryCount) {
locke-lunargd556cc32019-09-17 01:21:23 -06005826 // Do nothing if the feature is not enabled.
Piers Daniell41b8c5d2020-01-10 15:42:00 -07005827 if (!enabled_features.core12.hostQueryReset) return;
locke-lunargd556cc32019-09-17 01:21:23 -06005828
5829 // Do nothing if the query pool has been destroyed.
5830 auto query_pool_state = GetQueryPoolState(queryPool);
5831 if (!query_pool_state) return;
5832
5833 // Reset the state of existing entries.
5834 QueryObject query_obj{queryPool, 0};
5835 const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
5836 for (uint32_t i = 0; i < max_query_count; ++i) {
5837 query_obj.query = firstQuery + i;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02005838 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005839 if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005840 for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
5841 query_obj.perf_pass = pass_index;
Lionel Landwerlin7dc796b2020-02-18 18:17:10 +02005842 queryToStateMap[query_obj] = QUERYSTATE_RESET;
Lionel Landwerlinc7420912019-05-23 00:33:42 +01005843 }
5844 }
locke-lunargd556cc32019-09-17 01:21:23 -06005845 }
5846}
5847
Tony-LunarG977448c2019-12-02 14:52:02 -07005848void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
5849 uint32_t queryCount) {
5850 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
5851}
5852
5853void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
5854 uint32_t queryCount) {
5855 RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
5856}
5857
locke-lunargd556cc32019-09-17 01:21:23 -06005858void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
5859 const TEMPLATE_STATE *template_state, const void *pData) {
5860 // Translate the templated update into a normal update for validation...
5861 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
5862 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
5863 decoded_update.desc_writes.data(), 0, NULL);
5864}
5865
5866// Update the common AllocateDescriptorSetsData
5867void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05005868 cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
locke-lunargd556cc32019-09-17 01:21:23 -06005869 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolz6ae39612019-10-11 20:57:36 -05005870 auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]);
locke-lunargd556cc32019-09-17 01:21:23 -06005871 if (layout) {
5872 ds_data->layout_nodes[i] = layout;
5873 // Count total descriptors required per type
5874 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
5875 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07005876 uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
5877 ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
locke-lunargd556cc32019-09-17 01:21:23 -06005878 }
5879 }
5880 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
5881 }
5882}
5883
5884// Decrement allocated sets from the pool and insert new sets into set_map
5885void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
5886 const VkDescriptorSet *descriptor_sets,
5887 const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
5888 auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get();
5889 // Account for sets and individual descriptors allocated from pool
5890 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
5891 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
5892 pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
5893 }
5894
Mike Schuchardt2df08912020-12-15 16:28:09 -08005895 const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext);
locke-lunargd556cc32019-09-17 01:21:23 -06005896 bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount;
5897
5898 // Create tracking object for each descriptor set; insert into global map and the pool's set.
5899 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
5900 uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
5901
Jeff Bolz41a1ced2019-10-11 11:40:49 -05005902 auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], pool_state, ds_data->layout_nodes[i],
John Zulaufd2c3dae2019-12-12 11:02:17 -07005903 variable_count, this);
locke-lunargd556cc32019-09-17 01:21:23 -06005904 pool_state->sets.insert(new_ds.get());
5905 new_ds->in_use.store(0);
5906 setMap[descriptor_sets[i]] = std::move(new_ds);
5907 }
5908}
5909
5910// Generic function to handle state update for all CmdDraw* and CmdDispatch* type functions
Jeremy Kniager05631e72020-06-08 14:21:35 -06005911void ValidationStateTracker::UpdateStateCmdDrawDispatchType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type,
locke-lunarg540b2252020-08-03 13:23:36 -06005912 VkPipelineBindPoint bind_point, const char *function) {
5913 UpdateDrawState(cb_state, cmd_type, bind_point, function);
locke-lunargd556cc32019-09-17 01:21:23 -06005914 cb_state->hasDispatchCmd = true;
5915}
5916
locke-lunargd556cc32019-09-17 01:21:23 -06005917// Generic function to handle state update for all CmdDraw* type functions
locke-lunarg540b2252020-08-03 13:23:36 -06005918void ValidationStateTracker::UpdateStateCmdDrawType(CMD_BUFFER_STATE *cb_state, CMD_TYPE cmd_type, VkPipelineBindPoint bind_point,
5919 const char *function) {
5920 UpdateStateCmdDrawDispatchType(cb_state, cmd_type, bind_point, function);
locke-lunargd556cc32019-09-17 01:21:23 -06005921 cb_state->hasDrawCmd = true;
5922}
5923
5924void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
5925 uint32_t firstVertex, uint32_t firstInstance) {
5926 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005927 UpdateStateCmdDrawType(cb_state, CMD_DRAW, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDraw()");
locke-lunargd556cc32019-09-17 01:21:23 -06005928}
5929
5930void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
5931 uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
5932 uint32_t firstInstance) {
5933 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005934 UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXED, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexed()");
locke-lunargd556cc32019-09-17 01:21:23 -06005935}
5936
5937void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
5938 uint32_t count, uint32_t stride) {
5939 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5940 BUFFER_STATE *buffer_state = GetBufferState(buffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005941 UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndirect()");
locke-lunargd556cc32019-09-17 01:21:23 -06005942 AddCommandBufferBindingBuffer(cb_state, buffer_state);
5943}
5944
5945void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
5946 VkDeviceSize offset, uint32_t count, uint32_t stride) {
5947 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5948 BUFFER_STATE *buffer_state = GetBufferState(buffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005949 UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECT, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawIndexedIndirect()");
locke-lunargd556cc32019-09-17 01:21:23 -06005950 AddCommandBufferBindingBuffer(cb_state, buffer_state);
5951}
5952
5953void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
5954 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005955 UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCH, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatch()");
locke-lunargd556cc32019-09-17 01:21:23 -06005956}
5957
5958void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
5959 VkDeviceSize offset) {
5960 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005961 UpdateStateCmdDrawDispatchType(cb_state, CMD_DISPATCHINDIRECT, VK_PIPELINE_BIND_POINT_COMPUTE, "vkCmdDispatchIndirect()");
locke-lunargd556cc32019-09-17 01:21:23 -06005962 BUFFER_STATE *buffer_state = GetBufferState(buffer);
5963 AddCommandBufferBindingBuffer(cb_state, buffer_state);
5964}
5965
Tony-LunarG977448c2019-12-02 14:52:02 -07005966void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
5967 VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
locke-lunarg540b2252020-08-03 13:23:36 -06005968 uint32_t stride, const char *function) {
Tony-LunarG977448c2019-12-02 14:52:02 -07005969 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5970 BUFFER_STATE *buffer_state = GetBufferState(buffer);
5971 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005972 UpdateStateCmdDrawType(cb_state, CMD_DRAWINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function);
Tony-LunarG977448c2019-12-02 14:52:02 -07005973 AddCommandBufferBindingBuffer(cb_state, buffer_state);
5974 AddCommandBufferBindingBuffer(cb_state, count_buffer_state);
5975}
5976
locke-lunargd556cc32019-09-17 01:21:23 -06005977void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
5978 VkDeviceSize offset, VkBuffer countBuffer,
5979 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
5980 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06005981 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
5982 "vkCmdDrawIndirectCountKHR()");
Tony-LunarG977448c2019-12-02 14:52:02 -07005983}
5984
5985void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
5986 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
5987 uint32_t maxDrawCount, uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06005988 RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
5989 "vkCmdDrawIndirectCount()");
Tony-LunarG977448c2019-12-02 14:52:02 -07005990}
5991
5992void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
5993 VkBuffer countBuffer, VkDeviceSize countBufferOffset,
locke-lunarg540b2252020-08-03 13:23:36 -06005994 uint32_t maxDrawCount, uint32_t stride, const char *function) {
locke-lunargd556cc32019-09-17 01:21:23 -06005995 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
5996 BUFFER_STATE *buffer_state = GetBufferState(buffer);
5997 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06005998 UpdateStateCmdDrawType(cb_state, CMD_DRAWINDEXEDINDIRECTCOUNT, VK_PIPELINE_BIND_POINT_GRAPHICS, function);
locke-lunargd556cc32019-09-17 01:21:23 -06005999 AddCommandBufferBindingBuffer(cb_state, buffer_state);
6000 AddCommandBufferBindingBuffer(cb_state, count_buffer_state);
6001}
6002
6003void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
6004 VkDeviceSize offset, VkBuffer countBuffer,
6005 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
6006 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06006007 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
6008 "vkCmdDrawIndexedIndirectCountKHR()");
Tony-LunarG977448c2019-12-02 14:52:02 -07006009}
6010
6011void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
6012 VkDeviceSize offset, VkBuffer countBuffer,
6013 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
6014 uint32_t stride) {
locke-lunarg540b2252020-08-03 13:23:36 -06006015 RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
6016 "vkCmdDrawIndexedIndirectCount()");
locke-lunargd556cc32019-09-17 01:21:23 -06006017}
6018
6019void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
6020 uint32_t firstTask) {
6021 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06006022 UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSNV, VK_PIPELINE_BIND_POINT_GRAPHICS, "vkCmdDrawMeshTasksNV()");
locke-lunargd556cc32019-09-17 01:21:23 -06006023}
6024
6025void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
6026 VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
6027 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06006028 UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTNV, VK_PIPELINE_BIND_POINT_GRAPHICS,
6029 "vkCmdDrawMeshTasksIndirectNV()");
locke-lunargd556cc32019-09-17 01:21:23 -06006030 BUFFER_STATE *buffer_state = GetBufferState(buffer);
6031 if (buffer_state) {
6032 AddCommandBufferBindingBuffer(cb_state, buffer_state);
6033 }
6034}
6035
6036void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
6037 VkDeviceSize offset, VkBuffer countBuffer,
6038 VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
6039 uint32_t stride) {
6040 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6041 BUFFER_STATE *buffer_state = GetBufferState(buffer);
6042 BUFFER_STATE *count_buffer_state = GetBufferState(countBuffer);
locke-lunarg540b2252020-08-03 13:23:36 -06006043 UpdateStateCmdDrawType(cb_state, CMD_DRAWMESHTASKSINDIRECTCOUNTNV, VK_PIPELINE_BIND_POINT_GRAPHICS,
6044 "vkCmdDrawMeshTasksIndirectCountNV()");
locke-lunargd556cc32019-09-17 01:21:23 -06006045 if (buffer_state) {
6046 AddCommandBufferBindingBuffer(cb_state, buffer_state);
6047 }
6048 if (count_buffer_state) {
6049 AddCommandBufferBindingBuffer(cb_state, count_buffer_state);
6050 }
6051}
6052
6053void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
6054 const VkAllocationCallbacks *pAllocator,
6055 VkShaderModule *pShaderModule, VkResult result,
6056 void *csm_state_data) {
6057 if (VK_SUCCESS != result) return;
6058 create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
6059
Tony-LunarG8a51b7d2020-07-01 15:57:23 -06006060 spv_target_env spirv_environment = PickSpirvEnv(api_version, (device_extensions.vk_khr_spirv_1_4 != kNotEnabled));
locke-lunargd556cc32019-09-17 01:21:23 -06006061 bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber);
Jeff Bolze7fc67b2019-10-04 12:29:31 -05006062 auto new_shader_module = is_spirv ? std::make_shared<SHADER_MODULE_STATE>(pCreateInfo, *pShaderModule, spirv_environment,
6063 csm_state->unique_shader_id)
6064 : std::make_shared<SHADER_MODULE_STATE>();
locke-lunargde3f0fa2020-09-10 11:55:31 -06006065 SetPushConstantUsedInShader(*new_shader_module);
locke-lunargd556cc32019-09-17 01:21:23 -06006066 shaderModuleMap[*pShaderModule] = std::move(new_shader_module);
6067}
6068
6069void ValidationStateTracker::RecordPipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline,
Jeff Bolz46c0ea02019-10-09 13:06:29 -05006070 PIPELINE_STATE::StageState *stage_state) const {
locke-lunargd556cc32019-09-17 01:21:23 -06006071 // Validation shouldn't rely on anything in stage state being valid if the spirv isn't
locke-lunargde3f0fa2020-09-10 11:55:31 -06006072 stage_state->entry_point_name = pStage->pName;
6073 stage_state->shader_state = GetShared<SHADER_MODULE_STATE>(pStage->module);
6074 auto module = stage_state->shader_state.get();
locke-lunargd556cc32019-09-17 01:21:23 -06006075 if (!module->has_valid_spirv) return;
6076
6077 // Validation shouldn't rely on anything in stage state being valid if the entrypoint isn't present
6078 auto entrypoint = FindEntrypoint(module, pStage->pName, pStage->stage);
6079 if (entrypoint == module->end()) return;
6080
locke-lunarg654e3692020-06-04 17:19:15 -06006081 stage_state->stage_flag = pStage->stage;
6082
locke-lunargd556cc32019-09-17 01:21:23 -06006083 // Mark accessible ids
6084 stage_state->accessible_ids = MarkAccessibleIds(module, entrypoint);
6085 ProcessExecutionModes(module, entrypoint, pipeline);
6086
locke-lunarg63e4daf2020-08-17 17:53:25 -06006087 stage_state->descriptor_uses = CollectInterfaceByDescriptorSlot(
6088 module, stage_state->accessible_ids, &stage_state->has_writable_descriptor, &stage_state->has_atomic_descriptor);
locke-lunargd556cc32019-09-17 01:21:23 -06006089 // Capture descriptor uses for the pipeline
locke-lunarg36045992020-08-20 16:54:37 -06006090 for (const auto &use : stage_state->descriptor_uses) {
locke-lunargd556cc32019-09-17 01:21:23 -06006091 // While validating shaders capture which slots are used by the pipeline
John Zulauf649edd52019-10-02 14:39:41 -06006092 const uint32_t slot = use.first.first;
locke-lunarg351c9d82020-10-23 14:43:21 -06006093 pipeline->active_slots[slot][use.first.second].is_writable |= use.second.is_writable;
locke-lunarg36045992020-08-20 16:54:37 -06006094 auto &reqs = pipeline->active_slots[slot][use.first.second].reqs;
locke-lunargd556cc32019-09-17 01:21:23 -06006095 reqs = descriptor_req(reqs | DescriptorTypeToReqs(module, use.second.type_id));
locke-lunarg25b6c352020-08-06 17:44:18 -06006096 if (use.second.is_atomic_operation) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_VIEW_ATOMIC_OPERATION);
locke-lunarg12d20992020-09-21 12:46:49 -06006097 if (use.second.is_sampler_implicitLod_dref_proj) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_SAMPLER_IMPLICITLOD_DREF_PROJ);
locke-lunargae2a43c2020-09-22 17:21:57 -06006098 if (use.second.is_sampler_bias_offset) reqs = descriptor_req(reqs | DESCRIPTOR_REQ_SAMPLER_BIAS_OFFSET);
locke-lunarg12d20992020-09-21 12:46:49 -06006099
John Zulauf649edd52019-10-02 14:39:41 -06006100 pipeline->max_active_slot = std::max(pipeline->max_active_slot, slot);
locke-lunarg36045992020-08-20 16:54:37 -06006101 if (use.second.samplers_used_by_image.size()) {
locke-lunarg654a9052020-10-13 16:28:42 -06006102 auto &samplers_used_by_image = pipeline->active_slots[slot][use.first.second].samplers_used_by_image;
6103 if (use.second.samplers_used_by_image.size() > samplers_used_by_image.size()) {
6104 samplers_used_by_image.resize(use.second.samplers_used_by_image.size());
6105 }
locke-lunarg654a9052020-10-13 16:28:42 -06006106 uint32_t image_index = 0;
6107 for (const auto &samplers : use.second.samplers_used_by_image) {
6108 for (const auto &sampler : samplers) {
locke-lunargb8be8222020-10-20 00:34:37 -06006109 samplers_used_by_image[image_index].emplace(sampler, nullptr);
locke-lunarg654a9052020-10-13 16:28:42 -06006110 }
6111 ++image_index;
6112 }
locke-lunarg36045992020-08-20 16:54:37 -06006113 }
locke-lunargd556cc32019-09-17 01:21:23 -06006114 }
locke-lunarg78486832020-09-09 19:39:42 -06006115
locke-lunarg96dc9632020-06-10 17:22:18 -06006116 if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
6117 pipeline->fragmentShader_writable_output_location_list = CollectWritableOutputLocationinFS(*module, *pStage);
6118 }
locke-lunargd556cc32019-09-17 01:21:23 -06006119}
6120
6121void ValidationStateTracker::ResetCommandBufferPushConstantDataIfIncompatible(CMD_BUFFER_STATE *cb_state, VkPipelineLayout layout) {
6122 if (cb_state == nullptr) {
6123 return;
6124 }
6125
6126 const PIPELINE_LAYOUT_STATE *pipeline_layout_state = GetPipelineLayout(layout);
6127 if (pipeline_layout_state == nullptr) {
6128 return;
6129 }
6130
6131 if (cb_state->push_constant_data_ranges != pipeline_layout_state->push_constant_ranges) {
6132 cb_state->push_constant_data_ranges = pipeline_layout_state->push_constant_ranges;
6133 cb_state->push_constant_data.clear();
locke-lunargde3f0fa2020-09-10 11:55:31 -06006134 cb_state->push_constant_data_update.clear();
locke-lunargd556cc32019-09-17 01:21:23 -06006135 uint32_t size_needed = 0;
6136 for (auto push_constant_range : *cb_state->push_constant_data_ranges) {
locke-lunargde3f0fa2020-09-10 11:55:31 -06006137 auto size = push_constant_range.offset + push_constant_range.size;
6138 size_needed = std::max(size_needed, size);
6139
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006140 auto stage_flags = push_constant_range.stageFlags;
locke-lunargde3f0fa2020-09-10 11:55:31 -06006141 uint32_t bit_shift = 0;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006142 while (stage_flags) {
6143 if (stage_flags & 1) {
locke-lunargde3f0fa2020-09-10 11:55:31 -06006144 VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
6145 const auto it = cb_state->push_constant_data_update.find(flag);
6146
6147 if (it != cb_state->push_constant_data_update.end()) {
6148 if (it->second.size() < push_constant_range.offset) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06006149 it->second.resize(push_constant_range.offset, PC_Byte_Not_Set);
locke-lunargde3f0fa2020-09-10 11:55:31 -06006150 }
6151 if (it->second.size() < size) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06006152 it->second.resize(size, PC_Byte_Not_Updated);
locke-lunargde3f0fa2020-09-10 11:55:31 -06006153 }
6154 } else {
locke-lunarg3d8b8f32020-10-26 17:04:16 -06006155 std::vector<uint8_t> bytes;
6156 bytes.resize(push_constant_range.offset, PC_Byte_Not_Set);
6157 bytes.resize(size, PC_Byte_Not_Updated);
locke-lunargde3f0fa2020-09-10 11:55:31 -06006158 cb_state->push_constant_data_update[flag] = bytes;
6159 }
6160 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006161 stage_flags = stage_flags >> 1;
locke-lunargde3f0fa2020-09-10 11:55:31 -06006162 ++bit_shift;
6163 }
locke-lunargd556cc32019-09-17 01:21:23 -06006164 }
6165 cb_state->push_constant_data.resize(size_needed, 0);
6166 }
6167}
John Zulauf22b0fbe2019-10-15 06:26:16 -06006168
6169void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
6170 uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
6171 VkResult result) {
6172 if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
6173 auto swapchain_state = GetSwapchainState(swapchain);
6174
6175 if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
6176
6177 if (pSwapchainImages) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06006178 for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
locke-lunargb3584732019-10-28 20:18:36 -06006179 if (swapchain_state->images[i].image != VK_NULL_HANDLE) continue; // Already retrieved this.
John Zulauf22b0fbe2019-10-15 06:26:16 -06006180
6181 // Add imageMap entries for each swapchain image
6182 VkImageCreateInfo image_ci;
6183 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskid3ec86f2020-03-18 11:23:04 -06006184 image_ci.pNext = nullptr; // to be set later
6185 image_ci.flags = 0; // to be updated below
John Zulauf22b0fbe2019-10-15 06:26:16 -06006186 image_ci.imageType = VK_IMAGE_TYPE_2D;
6187 image_ci.format = swapchain_state->createInfo.imageFormat;
6188 image_ci.extent.width = swapchain_state->createInfo.imageExtent.width;
6189 image_ci.extent.height = swapchain_state->createInfo.imageExtent.height;
6190 image_ci.extent.depth = 1;
6191 image_ci.mipLevels = 1;
6192 image_ci.arrayLayers = swapchain_state->createInfo.imageArrayLayers;
6193 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
6194 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
6195 image_ci.usage = swapchain_state->createInfo.imageUsage;
6196 image_ci.sharingMode = swapchain_state->createInfo.imageSharingMode;
6197 image_ci.queueFamilyIndexCount = swapchain_state->createInfo.queueFamilyIndexCount;
6198 image_ci.pQueueFamilyIndices = swapchain_state->createInfo.pQueueFamilyIndices;
6199 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
6200
Mike Schuchardt2df08912020-12-15 16:28:09 -08006201 image_ci.pNext = lvl_find_in_chain<VkImageFormatListCreateInfo>(swapchain_state->createInfo.pNext);
John Zulauf22b0fbe2019-10-15 06:26:16 -06006202
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006203 if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT_KHR) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06006204 image_ci.flags |= VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006205 }
6206 if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06006207 image_ci.flags |= VK_IMAGE_CREATE_PROTECTED_BIT;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006208 }
6209 if (swapchain_state->createInfo.flags & VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08006210 image_ci.flags |= (VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07006211 }
John Zulauf22b0fbe2019-10-15 06:26:16 -06006212
locke-lunarg296a3c92020-03-25 01:04:29 -06006213 imageMap[pSwapchainImages[i]] = std::make_shared<IMAGE_STATE>(device, pSwapchainImages[i], &image_ci);
John Zulauf22b0fbe2019-10-15 06:26:16 -06006214 auto &image_state = imageMap[pSwapchainImages[i]];
6215 image_state->valid = false;
6216 image_state->create_from_swapchain = swapchain;
6217 image_state->bind_swapchain = swapchain;
6218 image_state->bind_swapchain_imageIndex = i;
Tony-LunarGe64e4fe2020-02-17 16:21:55 -07006219 image_state->is_swapchain_image = true;
locke-lunargb3584732019-10-28 20:18:36 -06006220 swapchain_state->images[i].image = pSwapchainImages[i];
6221 swapchain_state->images[i].bound_images.emplace(pSwapchainImages[i]);
Petr Kraus44f1c482020-04-25 20:09:25 +02006222
6223 AddImageStateProps(*image_state, device, physical_device);
John Zulauf22b0fbe2019-10-15 06:26:16 -06006224 }
6225 }
6226
6227 if (*pSwapchainImageCount) {
John Zulauf22b0fbe2019-10-15 06:26:16 -06006228 swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
6229 }
6230}
sourav parmar35e7a002020-06-09 17:58:44 -07006231
sourav parmar35e7a002020-06-09 17:58:44 -07006232void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
6233 const VkCopyAccelerationStructureInfoKHR *pInfo) {
6234 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6235 if (cb_state) {
sourav parmarcd5fb182020-07-17 12:58:44 -07006236 ACCELERATION_STRUCTURE_STATE_KHR *src_as_state = GetAccelerationStructureStateKHR(pInfo->src);
6237 ACCELERATION_STRUCTURE_STATE_KHR *dst_as_state = GetAccelerationStructureStateKHR(pInfo->dst);
sourav parmar35e7a002020-06-09 17:58:44 -07006238 if (dst_as_state != nullptr && src_as_state != nullptr) {
6239 dst_as_state->built = true;
6240 dst_as_state->build_info_khr = src_as_state->build_info_khr;
6241 AddCommandBufferBindingAccelerationStructure(cb_state, dst_as_state);
6242 AddCommandBufferBindingAccelerationStructure(cb_state, src_as_state);
6243 }
6244 }
6245}
Piers Daniell39842ee2020-07-10 16:42:33 -06006246
6247void ValidationStateTracker::PreCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
6248 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6249 cb_state->status |= CBSTATUS_CULL_MODE_SET;
6250 cb_state->static_status &= ~CBSTATUS_CULL_MODE_SET;
6251}
6252
6253void ValidationStateTracker::PreCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
6254 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6255 cb_state->status |= CBSTATUS_FRONT_FACE_SET;
6256 cb_state->static_status &= ~CBSTATUS_FRONT_FACE_SET;
6257}
6258
6259void ValidationStateTracker::PreCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
6260 VkPrimitiveTopology primitiveTopology) {
6261 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6262 cb_state->primitiveTopology = primitiveTopology;
6263 cb_state->status |= CBSTATUS_PRIMITIVE_TOPOLOGY_SET;
6264 cb_state->static_status &= ~CBSTATUS_PRIMITIVE_TOPOLOGY_SET;
6265}
6266
6267void ValidationStateTracker::PreCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
6268 const VkViewport *pViewports) {
6269 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6270 cb_state->viewportWithCountMask |= (1u << viewportCount) - 1u;
Tobias Hector6663c9b2020-11-05 10:18:02 +00006271 cb_state->viewportWithCountCount = viewportCount;
Piers Daniell39842ee2020-07-10 16:42:33 -06006272 cb_state->status |= CBSTATUS_VIEWPORT_WITH_COUNT_SET;
6273 cb_state->static_status &= ~CBSTATUS_VIEWPORT_WITH_COUNT_SET;
6274}
6275
6276void ValidationStateTracker::PreCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
6277 const VkRect2D *pScissors) {
6278 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6279 cb_state->scissorWithCountMask |= (1u << scissorCount) - 1u;
6280 cb_state->status |= CBSTATUS_SCISSOR_WITH_COUNT_SET;
6281 cb_state->static_status &= ~CBSTATUS_SCISSOR_WITH_COUNT_SET;
6282}
6283
6284void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
6285 uint32_t bindingCount, const VkBuffer *pBuffers,
6286 const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
6287 const VkDeviceSize *pStrides) {
6288 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6289 if (pStrides) {
6290 cb_state->status |= CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
6291 cb_state->static_status &= ~CBSTATUS_VERTEX_INPUT_BINDING_STRIDE_SET;
6292 }
6293
6294 uint32_t end = firstBinding + bindingCount;
6295 if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
6296 cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
6297 }
6298
6299 for (uint32_t i = 0; i < bindingCount; ++i) {
6300 auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
locke-lunarg1ae57d62020-11-18 10:49:19 -07006301 vertex_buffer_binding.buffer_state = GetShared<BUFFER_STATE>(pBuffers[i]);
Piers Daniell39842ee2020-07-10 16:42:33 -06006302 vertex_buffer_binding.offset = pOffsets[i];
6303 vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
6304 vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
6305 // Add binding for this vertex buffer to this commandbuffer
6306 if (pBuffers[i]) {
locke-lunarg1ae57d62020-11-18 10:49:19 -07006307 AddCommandBufferBindingBuffer(cb_state, vertex_buffer_binding.buffer_state.get());
Piers Daniell39842ee2020-07-10 16:42:33 -06006308 }
6309 }
6310}
6311
6312void ValidationStateTracker::PreCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
6313 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6314 cb_state->status |= CBSTATUS_DEPTH_TEST_ENABLE_SET;
6315 cb_state->static_status &= ~CBSTATUS_DEPTH_TEST_ENABLE_SET;
6316}
6317
6318void ValidationStateTracker::PreCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
6319 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6320 cb_state->status |= CBSTATUS_DEPTH_WRITE_ENABLE_SET;
6321 cb_state->static_status &= ~CBSTATUS_DEPTH_WRITE_ENABLE_SET;
6322}
6323
6324void ValidationStateTracker::PreCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
6325 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6326 cb_state->status |= CBSTATUS_DEPTH_COMPARE_OP_SET;
6327 cb_state->static_status &= ~CBSTATUS_DEPTH_COMPARE_OP_SET;
6328}
6329
6330void ValidationStateTracker::PreCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
6331 VkBool32 depthBoundsTestEnable) {
6332 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6333 cb_state->status |= CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET;
6334 cb_state->static_status &= ~CBSTATUS_DEPTH_BOUNDS_TEST_ENABLE_SET;
6335}
6336void ValidationStateTracker::PreCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
6337 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6338 cb_state->status |= CBSTATUS_STENCIL_TEST_ENABLE_SET;
6339 cb_state->static_status &= ~CBSTATUS_STENCIL_TEST_ENABLE_SET;
6340}
6341
6342void ValidationStateTracker::PreCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
6343 VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
6344 VkCompareOp compareOp) {
6345 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6346 cb_state->status |= CBSTATUS_STENCIL_OP_SET;
6347 cb_state->static_status &= ~CBSTATUS_STENCIL_OP_SET;
6348}
locke-lunarg4189aa22020-10-21 00:23:48 -06006349
6350void ValidationStateTracker::PreCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
6351 uint32_t discardRectangleCount,
6352 const VkRect2D *pDiscardRectangles) {
6353 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6354 cb_state->status |= CBSTATUS_DISCARD_RECTANGLE_SET;
6355 cb_state->static_status &= ~CBSTATUS_DISCARD_RECTANGLE_SET;
6356}
6357
6358void ValidationStateTracker::PreCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
6359 const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
6360 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6361 cb_state->status |= CBSTATUS_SAMPLE_LOCATIONS_SET;
6362 cb_state->static_status &= ~CBSTATUS_SAMPLE_LOCATIONS_SET;
6363}
6364
6365void ValidationStateTracker::PreCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
6366 VkCoarseSampleOrderTypeNV sampleOrderType,
6367 uint32_t customSampleOrderCount,
6368 const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
6369 CMD_BUFFER_STATE *cb_state = GetCBState(commandBuffer);
6370 cb_state->status |= CBSTATUS_COARSE_SAMPLE_ORDER_SET;
6371 cb_state->static_status &= ~CBSTATUS_COARSE_SAMPLE_ORDER_SET;
6372}