blob: 301cf014d29ab629c94897b1f5760623b8fede6b [file] [log] [blame]
John Zulauff4c07882019-01-24 14:03:36 -07001/* Copyright (c) 2015-2019 The Khronos Group Inc.
2 * Copyright (c) 2015-2019 Valve Corporation
3 * Copyright (c) 2015-2019 LunarG, Inc.
4 * Copyright (C) 2015-2019 Google Inc.
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Tobin Ehlis <tobine@google.com>
John Zulaufc483f442017-12-15 14:02:06 -070019 * John Zulauf <jzulauf@lunarg.com>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060020 */
21
Tobin Ehlisf922ef82016-11-30 10:19:14 -070022// Allow use of STL min and max functions in Windows
23#define NOMINMAX
24
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -070025#include "chassis.h"
Mark Lobodzinski76d76662019-02-14 14:38:21 -070026#include "core_validation_error_enums.h"
27#include "core_validation.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060028#include "descriptor_sets.h"
John Zulaufd47d0612018-02-16 13:00:34 -070029#include "hash_vk_types.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060030#include "vk_enum_string_helper.h"
31#include "vk_safe_struct.h"
Jeff Bolzfdf96072018-04-10 14:32:18 -050032#include "vk_typemap_helper.h"
Tobin Ehlisc8266452017-04-07 12:20:30 -060033#include "buffer_validation.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060034#include <sstream>
Mark Lobodzinski2eee5d82016-12-02 15:33:18 -070035#include <algorithm>
John Zulauff4c07882019-01-24 14:03:36 -070036#include <array>
John Zulauf1f8174b2018-02-16 12:58:37 -070037#include <memory>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060038
Jeff Bolzfdf96072018-04-10 14:32:18 -050039// ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended
40// state that comes from a different array/structure so they can stay together
41// while being sorted by binding number.
42struct ExtendedBinding {
43 ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlagsEXT f) : layout_binding(l), binding_flags(f) {}
44
45 const VkDescriptorSetLayoutBinding *layout_binding;
46 VkDescriptorBindingFlagsEXT binding_flags;
47};
48
John Zulauf508d13a2018-01-05 15:10:34 -070049struct BindingNumCmp {
Jeff Bolzfdf96072018-04-10 14:32:18 -050050 bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const {
51 return a.layout_binding->binding < b.layout_binding->binding;
John Zulauf508d13a2018-01-05 15:10:34 -070052 }
53};
54
John Zulauf613fd982019-06-04 15:14:41 -060055using DescriptorSet = cvdescriptorset::DescriptorSet;
John Zulauf4a015c92019-06-04 09:50:05 -060056using DescriptorSetLayout = cvdescriptorset::DescriptorSetLayout;
John Zulaufd47d0612018-02-16 13:00:34 -070057using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef;
58using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId;
59
John Zulauf34ebf272018-02-16 13:08:47 -070060// Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information)
61cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict;
John Zulaufd47d0612018-02-16 13:00:34 -070062
Shannon McPhersonc06c33d2018-06-28 17:21:12 -060063DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) {
John Zulauf34ebf272018-02-16 13:08:47 -070064 return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info));
John Zulaufd47d0612018-02-16 13:00:34 -070065}
John Zulauf34ebf272018-02-16 13:08:47 -070066
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060067// Construct DescriptorSetLayout instance from given create info
John Zulauf48a6a702017-12-22 17:14:54 -070068// Proactively reserve and resize as possible, as the reallocation was visible in profiling
John Zulauf1f8174b2018-02-16 12:58:37 -070069cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info)
70 : flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) {
Jeff Bolzfdf96072018-04-10 14:32:18 -050071 const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(p_create_info->pNext);
72
John Zulauf48a6a702017-12-22 17:14:54 -070073 binding_type_stats_ = {0, 0, 0};
Jeff Bolzfdf96072018-04-10 14:32:18 -050074 std::set<ExtendedBinding, BindingNumCmp> sorted_bindings;
John Zulauf508d13a2018-01-05 15:10:34 -070075 const uint32_t input_bindings_count = p_create_info->bindingCount;
76 // Sort the input bindings in binding number order, eliminating duplicates
77 for (uint32_t i = 0; i < input_bindings_count; i++) {
Jeff Bolzfdf96072018-04-10 14:32:18 -050078 VkDescriptorBindingFlagsEXT flags = 0;
79 if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) {
80 flags = flags_create_info->pBindingFlags[i];
81 }
82 sorted_bindings.insert(ExtendedBinding(p_create_info->pBindings + i, flags));
John Zulaufb6d71202017-12-22 16:47:09 -070083 }
84
85 // Store the create info in the sorted order from above
Tobin Ehlisa3525e02016-11-17 10:50:52 -070086 std::map<uint32_t, uint32_t> binding_to_dyn_count;
John Zulauf508d13a2018-01-05 15:10:34 -070087 uint32_t index = 0;
88 binding_count_ = static_cast<uint32_t>(sorted_bindings.size());
89 bindings_.reserve(binding_count_);
Jeff Bolzfdf96072018-04-10 14:32:18 -050090 binding_flags_.reserve(binding_count_);
John Zulauf508d13a2018-01-05 15:10:34 -070091 binding_to_index_map_.reserve(binding_count_);
92 for (auto input_binding : sorted_bindings) {
93 // Add to binding and map, s.t. it is robust to invalid duplication of binding_num
Jeff Bolzfdf96072018-04-10 14:32:18 -050094 const auto binding_num = input_binding.layout_binding->binding;
John Zulauf508d13a2018-01-05 15:10:34 -070095 binding_to_index_map_[binding_num] = index++;
Jeff Bolzfdf96072018-04-10 14:32:18 -050096 bindings_.emplace_back(input_binding.layout_binding);
John Zulauf508d13a2018-01-05 15:10:34 -070097 auto &binding_info = bindings_.back();
Jeff Bolzfdf96072018-04-10 14:32:18 -050098 binding_flags_.emplace_back(input_binding.binding_flags);
John Zulauf508d13a2018-01-05 15:10:34 -070099
John Zulaufb6d71202017-12-22 16:47:09 -0700100 descriptor_count_ += binding_info.descriptorCount;
101 if (binding_info.descriptorCount > 0) {
102 non_empty_bindings_.insert(binding_num);
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700103 }
John Zulaufb6d71202017-12-22 16:47:09 -0700104
105 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
106 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
107 binding_to_dyn_count[binding_num] = binding_info.descriptorCount;
108 dynamic_descriptor_count_ += binding_info.descriptorCount;
John Zulauf48a6a702017-12-22 17:14:54 -0700109 binding_type_stats_.dynamic_buffer_count++;
110 } else if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
111 (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) {
112 binding_type_stats_.non_dynamic_buffer_count++;
113 } else {
114 binding_type_stats_.image_sampler_count++;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600115 }
116 }
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700117 assert(bindings_.size() == binding_count_);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500118 assert(binding_flags_.size() == binding_count_);
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700119 uint32_t global_index = 0;
John Zulauf7705bfc2019-06-10 09:52:04 -0600120 global_index_range_.reserve(binding_count_);
121 // Vector order is finalized so build vectors of descriptors and dynamic offsets by binding index
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700122 for (uint32_t i = 0; i < binding_count_; ++i) {
John Zulaufc483f442017-12-15 14:02:06 -0700123 auto final_index = global_index + bindings_[i].descriptorCount;
John Zulauf7705bfc2019-06-10 09:52:04 -0600124 global_index_range_.emplace_back(global_index, final_index);
John Zulaufc483f442017-12-15 14:02:06 -0700125 global_index = final_index;
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700126 }
John Zulaufb6d71202017-12-22 16:47:09 -0700127
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700128 // Now create dyn offset array mapping for any dynamic descriptors
129 uint32_t dyn_array_idx = 0;
John Zulaufb6d71202017-12-22 16:47:09 -0700130 binding_to_dynamic_array_idx_map_.reserve(binding_to_dyn_count.size());
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700131 for (const auto &bc_pair : binding_to_dyn_count) {
132 binding_to_dynamic_array_idx_map_[bc_pair.first] = dyn_array_idx;
133 dyn_array_idx += bc_pair.second;
134 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600135}
Tobin Ehlis154c2692016-10-25 09:36:53 -0600136
John Zulaufd47d0612018-02-16 13:00:34 -0700137size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const {
138 hash_util::HashCombiner hc;
139 hc << flags_;
140 hc.Combine(bindings_);
John Zulauf223b69d2018-11-09 16:00:59 -0700141 hc.Combine(binding_flags_);
John Zulaufd47d0612018-02-16 13:00:34 -0700142 return hc.Value();
143}
144//
145
John Zulauf1f8174b2018-02-16 12:58:37 -0700146// Return valid index or "end" i.e. binding_count_;
147// The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given
148// Common code for all binding lookups.
149uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const {
150 const auto &bi_itr = binding_to_index_map_.find(binding);
151 if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second;
152 return GetBindingCount();
153}
154VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex(
155 const uint32_t index) const {
156 if (index >= bindings_.size()) return nullptr;
157 return bindings_[index].ptr();
158}
159// Return descriptorCount for given index, 0 if index is unavailable
160uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const {
161 if (index >= bindings_.size()) return 0;
162 return bindings_[index].descriptorCount;
163}
164// For the given index, return descriptorType
165VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const {
166 assert(index < bindings_.size());
167 if (index < bindings_.size()) return bindings_[index].descriptorType;
168 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
169}
170// For the given index, return stageFlags
171VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const {
172 assert(index < bindings_.size());
173 if (index < bindings_.size()) return bindings_[index].stageFlags;
174 return VkShaderStageFlags(0);
175}
Jeff Bolzfdf96072018-04-10 14:32:18 -0500176// Return binding flags for given index, 0 if index is unavailable
177VkDescriptorBindingFlagsEXT cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex(
178 const uint32_t index) const {
179 if (index >= binding_flags_.size()) return 0;
180 return binding_flags_[index];
181}
John Zulauf1f8174b2018-02-16 12:58:37 -0700182
John Zulauf7705bfc2019-06-10 09:52:04 -0600183const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromIndex(uint32_t index) const {
184 const static IndexRange kInvalidRange = {0xFFFFFFFF, 0xFFFFFFFF};
185 if (index >= binding_flags_.size()) return kInvalidRange;
186 return global_index_range_[index];
John Zulauf1f8174b2018-02-16 12:58:37 -0700187}
188
John Zulauf7705bfc2019-06-10 09:52:04 -0600189// For the given binding, return the global index range (half open)
190// As start and end are often needed in pairs, get both with a single lookup.
John Zulauf1f8174b2018-02-16 12:58:37 -0700191const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding(
192 const uint32_t binding) const {
John Zulauf7705bfc2019-06-10 09:52:04 -0600193 uint32_t index = GetIndexFromBinding(binding);
194 return GetGlobalIndexRangeFromIndex(index);
John Zulauf1f8174b2018-02-16 12:58:37 -0700195}
196
197// For given binding, return ptr to ImmutableSampler array
198VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
199 const auto &bi_itr = binding_to_index_map_.find(binding);
200 if (bi_itr != binding_to_index_map_.end()) {
201 return bindings_[bi_itr->second].pImmutableSamplers;
202 }
203 return nullptr;
204}
205// Move to next valid binding having a non-zero binding count
206uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const {
207 auto it = non_empty_bindings_.upper_bound(binding);
208 assert(it != non_empty_bindings_.cend());
209 if (it != non_empty_bindings_.cend()) return *it;
210 return GetMaxBinding() + 1;
211}
212// For given index, return ptr to ImmutableSampler array
213VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
214 if (index < bindings_.size()) {
215 return bindings_[index].pImmutableSamplers;
216 }
217 return nullptr;
218}
John Zulauf9ce3b252019-06-06 15:20:22 -0600219
220// If our layout is compatible with rh_ds_layout, return true.
221bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *rh_ds_layout) const {
222 bool compatible = (this == rh_ds_layout) || (GetLayoutDef() == rh_ds_layout->GetLayoutDef());
223 return compatible;
224}
John Zulauf1f8174b2018-02-16 12:58:37 -0700225// If our layout is compatible with rh_ds_layout, return true,
226// else return false and fill in error_msg will description of what causes incompatibility
John Zulauf9ce3b252019-06-06 15:20:22 -0600227bool cvdescriptorset::VerifySetLayoutCompatibility(DescriptorSetLayout const *lh_ds_layout, DescriptorSetLayout const *rh_ds_layout,
228 std::string *error_msg) {
229 // Short circuit the detailed check.
230 if (lh_ds_layout->IsCompatible(rh_ds_layout)) return true;
John Zulauf1f8174b2018-02-16 12:58:37 -0700231
John Zulauf9ce3b252019-06-06 15:20:22 -0600232 // Do a detailed compatibility check of this lhs def (referenced by lh_ds_layout), vs. the rhs (layout and def)
233 // Should only be run if trivial accept has failed, and in that context should return false.
234 VkDescriptorSetLayout lh_dsl_handle = lh_ds_layout->GetDescriptorSetLayout();
235 VkDescriptorSetLayout rh_dsl_handle = rh_ds_layout->GetDescriptorSetLayout();
236 DescriptorSetLayoutDef const *lh_ds_layout_def = lh_ds_layout->GetLayoutDef();
237 DescriptorSetLayoutDef const *rh_ds_layout_def = rh_ds_layout->GetLayoutDef();
238
239 // Check descriptor counts
240 if (lh_ds_layout_def->GetTotalDescriptorCount() != rh_ds_layout_def->GetTotalDescriptorCount()) {
John Zulauf1f8174b2018-02-16 12:58:37 -0700241 std::stringstream error_str;
John Zulauf9ce3b252019-06-06 15:20:22 -0600242 error_str << "DescriptorSetLayout " << lh_dsl_handle << " has " << lh_ds_layout_def->GetTotalDescriptorCount()
243 << " descriptors, but DescriptorSetLayout " << rh_dsl_handle << ", which comes from pipelineLayout, has "
244 << rh_ds_layout_def->GetTotalDescriptorCount() << " descriptors.";
John Zulauf1f8174b2018-02-16 12:58:37 -0700245 *error_msg = error_str.str();
246 return false; // trivial fail case
247 }
John Zulaufd47d0612018-02-16 13:00:34 -0700248
John Zulauf1f8174b2018-02-16 12:58:37 -0700249 // Descriptor counts match so need to go through bindings one-by-one
250 // and verify that type and stageFlags match
John Zulauf9ce3b252019-06-06 15:20:22 -0600251 for (const auto &binding : lh_ds_layout_def->GetBindings()) {
John Zulauf1f8174b2018-02-16 12:58:37 -0700252 // TODO : Do we also need to check immutable samplers?
253 // VkDescriptorSetLayoutBinding *rh_binding;
254 if (binding.descriptorCount != rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding)) {
255 std::stringstream error_str;
John Zulauf9ce3b252019-06-06 15:20:22 -0600256 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << lh_dsl_handle
257 << " has a descriptorCount of " << binding.descriptorCount << " but binding " << binding.binding
258 << " for DescriptorSetLayout " << rh_dsl_handle
259 << ", which comes from pipelineLayout, has a descriptorCount of "
John Zulauf1f8174b2018-02-16 12:58:37 -0700260 << rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding);
261 *error_msg = error_str.str();
262 return false;
263 } else if (binding.descriptorType != rh_ds_layout_def->GetTypeFromBinding(binding.binding)) {
264 std::stringstream error_str;
John Zulauf9ce3b252019-06-06 15:20:22 -0600265 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << lh_dsl_handle << " is type '"
John Zulauf1f8174b2018-02-16 12:58:37 -0700266 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
John Zulauf9ce3b252019-06-06 15:20:22 -0600267 << " for DescriptorSetLayout " << rh_dsl_handle << ", which comes from pipelineLayout, is type '"
John Zulauf1f8174b2018-02-16 12:58:37 -0700268 << string_VkDescriptorType(rh_ds_layout_def->GetTypeFromBinding(binding.binding)) << "'";
269 *error_msg = error_str.str();
270 return false;
271 } else if (binding.stageFlags != rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding)) {
272 std::stringstream error_str;
John Zulauf9ce3b252019-06-06 15:20:22 -0600273 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << lh_dsl_handle << " has stageFlags "
274 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " << rh_dsl_handle
John Zulauf1f8174b2018-02-16 12:58:37 -0700275 << ", which comes from pipelineLayout, has stageFlags "
276 << rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding);
277 *error_msg = error_str.str();
278 return false;
279 }
280 }
John Zulauf9ce3b252019-06-06 15:20:22 -0600281 // No detailed check should succeed if the trivial check failed -- or the dictionary has failed somehow.
282 bool compatible = true;
283 assert(!compatible);
284 return compatible;
John Zulauf1f8174b2018-02-16 12:58:37 -0700285}
286
287bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const {
288 if (!binding_to_index_map_.count(binding + 1)) return false;
289 auto const &bi_itr = binding_to_index_map_.find(binding);
290 if (bi_itr != binding_to_index_map_.end()) {
291 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
292 if (next_bi_itr != binding_to_index_map_.end()) {
293 auto type = bindings_[bi_itr->second].descriptorType;
294 auto stage_flags = bindings_[bi_itr->second].stageFlags;
295 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
Jeff Bolzfdf96072018-04-10 14:32:18 -0500296 auto flags = binding_flags_[bi_itr->second];
John Zulauf1f8174b2018-02-16 12:58:37 -0700297 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
298 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
Jeff Bolzfdf96072018-04-10 14:32:18 -0500299 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) ||
300 (flags != binding_flags_[next_bi_itr->second])) {
John Zulauf1f8174b2018-02-16 12:58:37 -0700301 return false;
302 }
303 return true;
304 }
305 }
306 return false;
307}
John Zulauf1f8174b2018-02-16 12:58:37 -0700308
309// The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the
310// handle invariant portion
311cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info,
312 const VkDescriptorSetLayout layout)
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600313 : layout_(layout), layout_destroyed_(false), layout_id_(GetCanonicalId(p_create_info)) {}
John Zulauf1f8174b2018-02-16 12:58:37 -0700314
Tobin Ehlis154c2692016-10-25 09:36:53 -0600315// Validate descriptor set layout create info
John Zulaufd9435c32019-06-05 15:55:36 -0600316bool cvdescriptorset::ValidateDescriptorSetLayoutCreateInfo(
Jeff Bolzfdf96072018-04-10 14:32:18 -0500317 const debug_report_data *report_data, const VkDescriptorSetLayoutCreateInfo *create_info, const bool push_descriptor_ext,
318 const uint32_t max_push_descriptors, const bool descriptor_indexing_ext,
Jeff Bolze54ae892018-09-08 12:16:29 -0500319 const VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features,
320 const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features,
321 const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props) {
Tobin Ehlis154c2692016-10-25 09:36:53 -0600322 bool skip = false;
323 std::unordered_set<uint32_t> bindings;
John Zulauf0fdeab32018-01-23 11:27:35 -0700324 uint64_t total_descriptors = 0;
325
Jeff Bolzfdf96072018-04-10 14:32:18 -0500326 const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(create_info->pNext);
327
328 const bool push_descriptor_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
John Zulauf0fdeab32018-01-23 11:27:35 -0700329 if (push_descriptor_set && !push_descriptor_ext) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600330 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houlton51653902018-06-22 17:32:13 -0600331 kVUID_Core_DrawState_ExtensionNotEnabled,
Mark Lobodzinskifb5a3e62018-04-13 10:46:48 -0600332 "Attempted to use %s in %s but its required extension %s has not been enabled.\n",
John Zulauf0fdeab32018-01-23 11:27:35 -0700333 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR", "VkDescriptorSetLayoutCreateInfo::flags",
334 VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
335 }
336
Jeff Bolzfdf96072018-04-10 14:32:18 -0500337 const bool update_after_bind_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT);
338 if (update_after_bind_set && !descriptor_indexing_ext) {
339 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houlton51653902018-06-22 17:32:13 -0600340 kVUID_Core_DrawState_ExtensionNotEnabled,
Jeff Bolzfdf96072018-04-10 14:32:18 -0500341 "Attemped to use %s in %s but its required extension %s has not been enabled.\n",
342 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT", "VkDescriptorSetLayoutCreateInfo::flags",
343 VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
344 }
345
John Zulauf0fdeab32018-01-23 11:27:35 -0700346 auto valid_type = [push_descriptor_set](const VkDescriptorType type) {
347 return !push_descriptor_set ||
Dave Houlton142c4cb2018-10-17 15:04:41 -0600348 ((type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) && (type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) &&
Jeff Bolze54ae892018-09-08 12:16:29 -0500349 (type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT));
John Zulauf0fdeab32018-01-23 11:27:35 -0700350 };
351
Jeff Bolzfdf96072018-04-10 14:32:18 -0500352 uint32_t max_binding = 0;
353
Tobin Ehlis154c2692016-10-25 09:36:53 -0600354 for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
John Zulauf0fdeab32018-01-23 11:27:35 -0700355 const auto &binding_info = create_info->pBindings[i];
Jeff Bolzfdf96072018-04-10 14:32:18 -0500356 max_binding = std::max(max_binding, binding_info.binding);
357
John Zulauf0fdeab32018-01-23 11:27:35 -0700358 if (!bindings.insert(binding_info.binding).second) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600359 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houltond8ed0212018-05-16 17:18:24 -0600360 "VUID-VkDescriptorSetLayoutCreateInfo-binding-00279",
361 "duplicated binding number in VkDescriptorSetLayoutBinding.");
Tobin Ehlis154c2692016-10-25 09:36:53 -0600362 }
John Zulauf0fdeab32018-01-23 11:27:35 -0700363 if (!valid_type(binding_info.descriptorType)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600364 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houlton142c4cb2018-10-17 15:04:41 -0600365 (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
366 ? "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208"
367 : "VUID-VkDescriptorSetLayoutCreateInfo-flags-00280",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600368 "invalid type %s ,for push descriptors in VkDescriptorSetLayoutBinding entry %" PRIu32 ".",
369 string_VkDescriptorType(binding_info.descriptorType), i);
John Zulauf0fdeab32018-01-23 11:27:35 -0700370 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500371
372 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
373 if ((binding_info.descriptorCount % 4) != 0) {
374 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
375 "VUID-VkDescriptorSetLayoutBinding-descriptorType-02209",
Dave Houlton142c4cb2018-10-17 15:04:41 -0600376 "descriptorCount =(%" PRIu32 ") must be a multiple of 4", binding_info.descriptorCount);
Jeff Bolze54ae892018-09-08 12:16:29 -0500377 }
378 if (binding_info.descriptorCount > inline_uniform_block_props->maxInlineUniformBlockSize) {
379 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
380 "VUID-VkDescriptorSetLayoutBinding-descriptorType-02210",
381 "descriptorCount =(%" PRIu32 ") must be less than or equal to maxInlineUniformBlockSize",
382 binding_info.descriptorCount);
383 }
384 }
385
John Zulauf0fdeab32018-01-23 11:27:35 -0700386 total_descriptors += binding_info.descriptorCount;
Tobin Ehlis154c2692016-10-25 09:36:53 -0600387 }
John Zulauf0fdeab32018-01-23 11:27:35 -0700388
Jeff Bolzfdf96072018-04-10 14:32:18 -0500389 if (flags_create_info) {
390 if (flags_create_info->bindingCount != 0 && flags_create_info->bindingCount != create_info->bindingCount) {
391 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houltond8ed0212018-05-16 17:18:24 -0600392 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-bindingCount-03002",
Jeff Bolzfdf96072018-04-10 14:32:18 -0500393 "VkDescriptorSetLayoutCreateInfo::bindingCount (%d) != "
394 "VkDescriptorSetLayoutBindingFlagsCreateInfoEXT::bindingCount (%d)",
395 create_info->bindingCount, flags_create_info->bindingCount);
396 }
397
398 if (flags_create_info->bindingCount == create_info->bindingCount) {
399 for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
400 const auto &binding_info = create_info->pBindings[i];
401
402 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT) {
403 if (!update_after_bind_set) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600404 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
405 "VUID-VkDescriptorSetLayoutCreateInfo-flags-03000",
406 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500407 }
408
409 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER &&
410 !descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600411 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
412 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
413 "descriptorBindingUniformBufferUpdateAfterBind-03005",
414 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500415 }
416 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
417 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
418 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) &&
419 !descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600420 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
421 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
422 "descriptorBindingSampledImageUpdateAfterBind-03006",
423 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500424 }
425 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
426 !descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600427 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
428 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
429 "descriptorBindingStorageImageUpdateAfterBind-03007",
430 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500431 }
432 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER &&
433 !descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600434 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
435 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
436 "descriptorBindingStorageBufferUpdateAfterBind-03008",
437 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500438 }
439 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER &&
440 !descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600441 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
442 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
443 "descriptorBindingUniformTexelBufferUpdateAfterBind-03009",
444 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500445 }
446 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER &&
447 !descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600448 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
449 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
450 "descriptorBindingStorageTexelBufferUpdateAfterBind-03010",
451 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500452 }
453 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT ||
454 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
455 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600456 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
457 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-None-03011",
458 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500459 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500460
461 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT &&
462 !inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind) {
463 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houlton142c4cb2018-10-17 15:04:41 -0600464 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
465 "descriptorBindingInlineUniformBlockUpdateAfterBind-02211",
466 "Invalid flags (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT) for "
467 "VkDescriptorSetLayoutBinding entry %" PRIu32
468 " with descriptorBindingInlineUniformBlockUpdateAfterBind not enabled",
469 i);
Jeff Bolze54ae892018-09-08 12:16:29 -0500470 }
Jeff Bolzfdf96072018-04-10 14:32:18 -0500471 }
472
473 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT) {
474 if (!descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600475 skip |= log_msg(
476 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
477 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingUpdateUnusedWhilePending-03012",
478 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500479 }
480 }
481
482 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT) {
483 if (!descriptor_indexing_features->descriptorBindingPartiallyBound) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600484 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
485 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingPartiallyBound-03013",
486 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500487 }
488 }
489
490 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT) {
491 if (binding_info.binding != max_binding) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600492 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
493 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03004",
494 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500495 }
496
497 if (!descriptor_indexing_features->descriptorBindingVariableDescriptorCount) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600498 skip |= log_msg(
499 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
500 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingVariableDescriptorCount-03014",
501 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500502 }
503 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
504 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600505 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
506 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03015",
507 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500508 }
509 }
510
511 if (push_descriptor_set &&
512 (flags_create_info->pBindingFlags[i] &
513 (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
514 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT))) {
515 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dave Houltond8ed0212018-05-16 17:18:24 -0600516 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-flags-03003",
517 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500518 }
519 }
520 }
521 }
522
John Zulauf0fdeab32018-01-23 11:27:35 -0700523 if ((push_descriptor_set) && (total_descriptors > max_push_descriptors)) {
524 const char *undefined = push_descriptor_ext ? "" : " -- undefined";
Dave Houltond8ed0212018-05-16 17:18:24 -0600525 skip |=
526 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
527 "VUID-VkDescriptorSetLayoutCreateInfo-flags-00281",
528 "for push descriptor, total descriptor count in layout (%" PRIu64
529 ") must not be greater than VkPhysicalDevicePushDescriptorPropertiesKHR::maxPushDescriptors (%" PRIu32 "%s).",
530 total_descriptors, max_push_descriptors, undefined);
John Zulauf0fdeab32018-01-23 11:27:35 -0700531 }
532
Tobin Ehlis154c2692016-10-25 09:36:53 -0600533 return skip;
534}
535
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600536cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
537 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
538
Tobin Ehlis93f22372016-10-12 14:34:12 -0600539cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
Jeff Bolzfdf96072018-04-10 14:32:18 -0500540 const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count,
John Zulaufc93c4252019-06-25 09:19:49 -0600541 cvdescriptorset::DescriptorSet::StateTracker *state_data)
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -0700542 : some_update_(false),
543 set_(set),
544 pool_state_(nullptr),
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600545 p_layout_(layout),
John Zulaufc93c4252019-06-25 09:19:49 -0600546 state_data_(state_data),
Jeff Bolzfdf96072018-04-10 14:32:18 -0500547 variable_count_(variable_count) {
John Zulaufc93c4252019-06-25 09:19:49 -0600548 pool_state_ = state_data->GetDescriptorPoolState(pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600549 // Foreach binding, create default descriptors of given type
John Zulaufb6d71202017-12-22 16:47:09 -0700550 descriptors_.reserve(p_layout_->GetTotalDescriptorCount());
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600551 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
552 auto type = p_layout_->GetTypeFromIndex(i);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600553 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700554 case VK_DESCRIPTOR_TYPE_SAMPLER: {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600555 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
556 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
Tobin Ehlis082c7512017-05-08 11:24:57 -0600557 if (immut_sampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700558 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis082c7512017-05-08 11:24:57 -0600559 some_update_ = true; // Immutable samplers are updated at creation
560 } else
Chris Forbes9f340852017-05-09 08:51:38 -0700561 descriptors_.emplace_back(new SamplerDescriptor(nullptr));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700562 }
563 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600564 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700565 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600566 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
567 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
Tobin Ehlis082c7512017-05-08 11:24:57 -0600568 if (immut) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700569 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis082c7512017-05-08 11:24:57 -0600570 some_update_ = true; // Immutable samplers are updated at creation
571 } else
Chris Forbes9f340852017-05-09 08:51:38 -0700572 descriptors_.emplace_back(new ImageSamplerDescriptor(nullptr));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700573 }
574 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600575 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700576 // ImageDescriptors
577 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
578 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
579 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600580 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700581 descriptors_.emplace_back(new ImageDescriptor(type));
582 break;
583 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
584 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600585 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 descriptors_.emplace_back(new TexelDescriptor(type));
587 break;
588 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
589 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
590 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
591 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600592 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700593 descriptors_.emplace_back(new BufferDescriptor(type));
594 break;
Jeff Bolze54ae892018-09-08 12:16:29 -0500595 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
596 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
597 descriptors_.emplace_back(new InlineUniformDescriptor(type));
598 break;
Eric Werness30127fd2018-10-31 21:01:03 -0700599 case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
Jeff Bolzfbe51582018-09-13 10:01:35 -0500600 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
601 descriptors_.emplace_back(new AccelerationStructureDescriptor(type));
602 break;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700603 default:
604 assert(0); // Bad descriptor type specified
605 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600606 }
607 }
608}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600609
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700610cvdescriptorset::DescriptorSet::~DescriptorSet() { InvalidateBoundCmdBuffers(); }
Chris Forbes57989132016-07-26 17:06:10 +1200611
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600612static std::string StringDescriptorReqViewType(descriptor_req req) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700613 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200614 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
615 if (req & (1 << i)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700616 if (result.size()) result += ", ";
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700617 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200618 }
619 }
620
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700621 if (!result.size()) result = "(none)";
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700622
623 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200624}
625
Chris Forbesda01e8d2018-08-27 15:36:57 -0700626static char const *StringDescriptorReqComponentType(descriptor_req req) {
627 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT";
628 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT";
629 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT";
630 return "(none)";
631}
632
Chris Forbesda01e8d2018-08-27 15:36:57 -0700633static unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) {
634 if (FormatIsSInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
635 if (FormatIsUInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
636 if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
637 if (fmt == VK_FORMAT_UNDEFINED) return 0;
638 // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
639 return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
640}
641
Tobin Ehlis3066db62016-08-22 08:12:23 -0600642// Validate that the state of this set is appropriate for the given bindings and dynamic_offsets at Draw time
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600643// This includes validating that all descriptors in the given bindings are updated,
644// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
645// Return true if state is acceptable, or false and write an error message into error string
John Zulaufc93c4252019-06-25 09:19:49 -0600646bool CoreChecks::ValidateDrawState(const DescriptorSet *descriptor_set, const std::map<uint32_t, descriptor_req> &bindings,
647 const std::vector<uint32_t> &dynamic_offsets, CMD_BUFFER_STATE *cb_node, const char *caller,
648 std::string *error) {
649 using DescriptorClass = cvdescriptorset::DescriptorClass;
650 using BufferDescriptor = cvdescriptorset::BufferDescriptor;
651 using ImageDescriptor = cvdescriptorset::ImageDescriptor;
652 using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor;
653 using SamplerDescriptor = cvdescriptorset::SamplerDescriptor;
654 using TexelDescriptor = cvdescriptorset::TexelDescriptor;
Chris Forbesc7090a82016-07-25 18:10:41 +1200655 for (auto binding_pair : bindings) {
656 auto binding = binding_pair.first;
John Zulauf382e1912019-06-10 15:27:44 -0600657 DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), binding);
658 if (binding_it.AtEnd()) { // End at construction is the condition for an invalid binding.
Tobin Ehlis58c59582016-06-21 12:34:33 -0600659 std::stringstream error_str;
660 error_str << "Attempting to validate DrawState for binding #" << binding
661 << " which is an invalid binding for this descriptor set.";
662 *error = error_str.str();
663 return false;
664 }
John Zulauf382e1912019-06-10 15:27:44 -0600665 // Copy the range, the end range is subject to update based on variable length descriptor arrays.
666 cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange();
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700667 auto array_idx = 0; // Track array idx if we're dealing with array descriptors
Jeff Bolzfdf96072018-04-10 14:32:18 -0500668
John Zulauf382e1912019-06-10 15:27:44 -0600669 if (binding_it.IsVariableDescriptorCount()) {
Jeff Bolzfdf96072018-04-10 14:32:18 -0500670 // Only validate the first N descriptors if it uses variable_count
John Zulauf382e1912019-06-10 15:27:44 -0600671 index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount();
Jeff Bolzfdf96072018-04-10 14:32:18 -0500672 }
673
John Zulaufc483f442017-12-15 14:02:06 -0700674 for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) {
Lockeb994adf2019-03-29 23:52:31 -0600675 uint32_t index = i - index_range.start;
John Zulauf382e1912019-06-10 15:27:44 -0600676 const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i);
Lockeb994adf2019-03-29 23:52:31 -0600677
John Zulauf382e1912019-06-10 15:27:44 -0600678 if ((binding_it.GetDescriptorBindingFlags() &
Tobin Ehlisda77de72018-12-13 08:53:28 -0700679 (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT)) ||
John Zulaufc93c4252019-06-25 09:19:49 -0600680 descriptor->GetClass() == DescriptorClass::InlineUniform) {
Jeff Bolzfdf96072018-04-10 14:32:18 -0500681 // Can't validate the descriptor because it may not have been updated,
682 // or the view could have been destroyed
683 continue;
John Zulauf382e1912019-06-10 15:27:44 -0600684 } else if (!descriptor->updated) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700685 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600686 error_str << "Descriptor in binding #" << binding << " index " << index
Tobin Ehlisc604bd72019-06-19 11:54:51 -0600687 << " is being used in draw but has never been updated via vkUpdateDescriptorSets() or a similar call.";
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700688 *error = error_str.str();
689 return false;
690 } else {
John Zulauf382e1912019-06-10 15:27:44 -0600691 auto descriptor_class = descriptor->GetClass();
John Zulaufc93c4252019-06-25 09:19:49 -0600692 if (descriptor_class == DescriptorClass::GeneralBuffer) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700693 // Verify that buffers are valid
John Zulauf382e1912019-06-10 15:27:44 -0600694 auto buffer = static_cast<const BufferDescriptor *>(descriptor)->GetBuffer();
John Zulaufc93c4252019-06-25 09:19:49 -0600695 auto buffer_node = GetBufferState(buffer);
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700696 if (!buffer_node) {
697 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600698 error_str << "Descriptor in binding #" << binding << " index " << index << " references invalid buffer "
699 << buffer << ".";
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700700 *error = error_str.str();
701 return false;
John Zulauf48a6a702017-12-22 17:14:54 -0700702 } else if (!buffer_node->sparse) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700703 for (auto mem_binding : buffer_node->GetBoundMemory()) {
John Zulaufc93c4252019-06-25 09:19:49 -0600704 if (!GetDevMemState(mem_binding)) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700705 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600706 error_str << "Descriptor in binding #" << binding << " index " << index << " uses buffer " << buffer
707 << " that references invalid memory " << mem_binding << ".";
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700708 *error = error_str.str();
Tobin Ehlisc8266452017-04-07 12:20:30 -0600709 return false;
710 }
711 }
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700712 }
John Zulauf382e1912019-06-10 15:27:44 -0600713 if (descriptor->IsDynamic()) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700714 // Validate that dynamic offsets are within the buffer
715 auto buffer_size = buffer_node->createInfo.size;
John Zulauf382e1912019-06-10 15:27:44 -0600716 auto range = static_cast<const BufferDescriptor *>(descriptor)->GetRange();
717 auto desc_offset = static_cast<const BufferDescriptor *>(descriptor)->GetOffset();
718 auto dyn_offset = dynamic_offsets[binding_it.GetDynamicOffsetIndex() + array_idx];
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700719 if (VK_WHOLE_SIZE == range) {
720 if ((dyn_offset + desc_offset) > buffer_size) {
721 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600722 error_str << "Dynamic descriptor in binding #" << binding << " index " << index << " uses buffer "
723 << buffer << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
724 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
725 << buffer_size << ".";
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700726 *error = error_str.str();
727 return false;
728 }
729 } else {
730 if ((dyn_offset + desc_offset + range) > buffer_size) {
731 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600732 error_str << "Dynamic descriptor in binding #" << binding << " index " << index << " uses buffer "
733 << buffer << " with dynamic offset " << dyn_offset << " combined with offset "
734 << desc_offset << " and range " << range << " that oversteps the buffer size of "
735 << buffer_size << ".";
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700736 *error = error_str.str();
737 return false;
738 }
739 }
740 }
John Zulaufc93c4252019-06-25 09:19:49 -0600741 } else if (descriptor_class == DescriptorClass::ImageSampler || descriptor_class == DescriptorClass::Image) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700742 VkImageView image_view;
743 VkImageLayout image_layout;
John Zulaufc93c4252019-06-25 09:19:49 -0600744 if (descriptor_class == DescriptorClass::ImageSampler) {
John Zulauf382e1912019-06-10 15:27:44 -0600745 image_view = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageView();
746 image_layout = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetImageLayout();
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700747 } else {
John Zulauf382e1912019-06-10 15:27:44 -0600748 image_view = static_cast<const ImageDescriptor *>(descriptor)->GetImageView();
749 image_layout = static_cast<const ImageDescriptor *>(descriptor)->GetImageLayout();
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700750 }
751 auto reqs = binding_pair.second;
752
John Zulaufc93c4252019-06-25 09:19:49 -0600753 auto image_view_state = GetImageViewState(image_view);
Tobin Ehlis836a1372017-07-14 11:25:21 -0600754 if (nullptr == image_view_state) {
755 // Image view must have been destroyed since initial update. Could potentially flag the descriptor
756 // as "invalid" (updated = false) at DestroyImageView() time and detect this error at bind time
757 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600758 error_str << "Descriptor in binding #" << binding << " index " << index << " is using imageView "
John Zulaufc93c4252019-06-25 09:19:49 -0600759 << report_data->FormatHandle(image_view).c_str() << " that has been destroyed.";
Tobin Ehlis836a1372017-07-14 11:25:21 -0600760 *error = error_str.str();
761 return false;
762 }
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700763 auto image_view_ci = image_view_state->create_info;
764
765 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
766 // bad view type
767 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600768 error_str << "Descriptor in binding #" << binding << " index " << index
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600769 << " requires an image view of type " << StringDescriptorReqViewType(reqs) << " but got "
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700770 << string_VkImageViewType(image_view_ci.viewType) << ".";
771 *error = error_str.str();
772 return false;
773 }
774
Chris Forbesda01e8d2018-08-27 15:36:57 -0700775 auto format_bits = DescriptorRequirementsBitsFromFormat(image_view_ci.format);
776 if (!(reqs & format_bits)) {
777 // bad component type
778 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600779 error_str << "Descriptor in binding #" << binding << " index " << index << " requires "
Chris Forbesda01e8d2018-08-27 15:36:57 -0700780 << StringDescriptorReqComponentType(reqs) << " component type, but bound descriptor format is "
781 << string_VkFormat(image_view_ci.format) << ".";
782 *error = error_str.str();
783 return false;
784 }
785
John Zulaufc93c4252019-06-25 09:19:49 -0600786 auto image_node = GetImageState(image_view_ci.image);
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700787 assert(image_node);
788 // Verify Image Layout
John Zulauff660ad62019-03-23 07:16:05 -0600789 // No "invalid layout" VUID required for this call, since the optimal_layout parameter is UNDEFINED.
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700790 bool hit_error = false;
John Zulaufc93c4252019-06-25 09:19:49 -0600791 VerifyImageLayout(cb_node, image_node, image_view_state->normalized_subresource_range,
792 image_view_ci.subresourceRange.aspectMask, image_layout, VK_IMAGE_LAYOUT_UNDEFINED, caller,
793 kVUIDUndefined, "VUID-VkDescriptorImageInfo-imageLayout-00344", &hit_error);
John Zulauff660ad62019-03-23 07:16:05 -0600794 if (hit_error) {
795 *error =
796 "Image layout specified at vkUpdateDescriptorSet* or vkCmdPushDescriptorSet* time "
797 "doesn't match actual image layout at time descriptor is used. See previous error callback for "
798 "specific details.";
799 return false;
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700800 }
John Zulauff660ad62019-03-23 07:16:05 -0600801
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700802 // Verify Sample counts
803 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
804 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600805 error_str << "Descriptor in binding #" << binding << " index " << index
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700806 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
807 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
808 *error = error_str.str();
809 return false;
810 }
811 if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
812 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600813 error_str << "Descriptor in binding #" << binding << " index " << index
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700814 << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
815 *error = error_str.str();
816 return false;
Chris Forbes57989132016-07-26 17:06:10 +1200817 }
John Zulaufc93c4252019-06-25 09:19:49 -0600818 } else if (descriptor_class == DescriptorClass::TexelBuffer) {
John Zulauf382e1912019-06-10 15:27:44 -0600819 auto texel_buffer = static_cast<const TexelDescriptor *>(descriptor);
John Zulaufc93c4252019-06-25 09:19:49 -0600820 auto buffer_view = GetBufferViewState(texel_buffer->GetBufferView());
Chris Forbese92dd1d2019-01-21 15:58:57 -0800821
Locke2d9c3dd2019-04-08 16:29:09 -0600822 if (nullptr == buffer_view) {
823 std::stringstream error_str;
824 error_str << "Descriptor in binding #" << binding << " index " << index << " is using bufferView "
825 << buffer_view << " that has been destroyed.";
826 *error = error_str.str();
827 return false;
828 }
829 auto buffer = buffer_view->create_info.buffer;
John Zulaufc93c4252019-06-25 09:19:49 -0600830 auto buffer_state = GetBufferState(buffer);
Locke2d9c3dd2019-04-08 16:29:09 -0600831 if (!buffer_state) {
832 std::stringstream error_str;
833 error_str << "Descriptor in binding #" << binding << " index " << index << " is using buffer "
834 << buffer_state << " that has been destroyed.";
835 *error = error_str.str();
836 return false;
837 }
Chris Forbese92dd1d2019-01-21 15:58:57 -0800838 auto reqs = binding_pair.second;
839 auto format_bits = DescriptorRequirementsBitsFromFormat(buffer_view->create_info.format);
840
841 if (!(reqs & format_bits)) {
842 // bad component type
843 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600844 error_str << "Descriptor in binding #" << binding << " index " << index << " requires "
Chris Forbese92dd1d2019-01-21 15:58:57 -0800845 << StringDescriptorReqComponentType(reqs) << " component type, but bound descriptor format is "
846 << string_VkFormat(buffer_view->create_info.format) << ".";
847 *error = error_str.str();
848 return false;
849 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600850 }
John Zulaufc93c4252019-06-25 09:19:49 -0600851 if (descriptor_class == DescriptorClass::ImageSampler || descriptor_class == DescriptorClass::PlainSampler) {
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600852 // Verify Sampler still valid
853 VkSampler sampler;
John Zulaufc93c4252019-06-25 09:19:49 -0600854 if (descriptor_class == DescriptorClass::ImageSampler) {
John Zulauf382e1912019-06-10 15:27:44 -0600855 sampler = static_cast<const ImageSamplerDescriptor *>(descriptor)->GetSampler();
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600856 } else {
John Zulauf382e1912019-06-10 15:27:44 -0600857 sampler = static_cast<const SamplerDescriptor *>(descriptor)->GetSampler();
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600858 }
John Zulaufc93c4252019-06-25 09:19:49 -0600859 if (!ValidateSampler(sampler)) {
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600860 std::stringstream error_str;
Lockeb994adf2019-03-29 23:52:31 -0600861 error_str << "Descriptor in binding #" << binding << " index " << index << " is using sampler " << sampler
862 << " that has been destroyed.";
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600863 *error = error_str.str();
864 return false;
Lockea223c102019-04-05 00:38:24 -0600865 } else {
John Zulaufc93c4252019-06-25 09:19:49 -0600866 SAMPLER_STATE *sampler_state = GetSamplerState(sampler);
John Zulauf382e1912019-06-10 15:27:44 -0600867 if (sampler_state->samplerConversion && !descriptor->IsImmutableSampler()) {
Lockea223c102019-04-05 00:38:24 -0600868 std::stringstream error_str;
John Zulauf382e1912019-06-10 15:27:44 -0600869 error_str << "sampler (" << sampler << ") in the descriptor set (" << descriptor_set->GetSet()
Lockea223c102019-04-05 00:38:24 -0600870 << ") contains a YCBCR conversion (" << sampler_state->samplerConversion
871 << ") , then the sampler MUST also exists as an immutable sampler.";
872 *error = error_str.str();
873 }
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600874 }
875 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600876 }
877 }
878 }
879 return true;
880}
Chris Forbes57989132016-07-26 17:06:10 +1200881
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600882// For given bindings, place any update buffers or images into the passed-in unordered_sets
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600883uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600884 std::unordered_set<VkBuffer> *buffer_set,
885 std::unordered_set<VkImageView> *image_set) const {
886 auto num_updates = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200887 for (auto binding_pair : bindings) {
888 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600889 // If a binding doesn't exist, skip it
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600890 if (!p_layout_->HasBinding(binding)) {
Tobin Ehlis58c59582016-06-21 12:34:33 -0600891 continue;
892 }
John Zulaufc483f442017-12-15 14:02:06 -0700893 uint32_t start_idx = p_layout_->GetGlobalIndexRangeFromBinding(binding).start;
Tobin Ehlis81f17852016-05-05 09:04:33 -0600894 if (descriptors_[start_idx]->IsStorage()) {
895 if (Image == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600896 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600897 if (descriptors_[start_idx + i]->updated) {
898 image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600899 num_updates++;
900 }
901 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600902 } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600903 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600904 if (descriptors_[start_idx + i]->updated) {
905 auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
John Zulaufc93c4252019-06-25 09:19:49 -0600906 auto bv_state = state_data_->GetBufferViewState(bufferview);
Tobin Ehlis8b872462016-09-14 08:12:08 -0600907 if (bv_state) {
908 buffer_set->insert(bv_state->create_info.buffer);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600909 num_updates++;
910 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600911 }
912 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600913 } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600914 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600915 if (descriptors_[start_idx + i]->updated) {
916 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600917 num_updates++;
918 }
919 }
920 }
921 }
922 }
923 return num_updates;
924}
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600925// Set is being deleted or updates so invalidate all bound cmd buffers
926void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() {
John Zulaufc93c4252019-06-25 09:19:49 -0600927 state_data_->InvalidateCommandBuffers(cb_bindings, VulkanTypedHandle(set_, kVulkanObjectTypeDescriptorSet));
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600928}
John Zulauf1d27e0a2018-11-05 10:12:48 -0700929
930// Loop through the write updates to do for a push descriptor set, ignoring dstSet
931void cvdescriptorset::DescriptorSet::PerformPushDescriptorsUpdate(uint32_t write_count, const VkWriteDescriptorSet *p_wds) {
932 assert(IsPushDescriptor());
933 for (uint32_t i = 0; i < write_count; i++) {
934 PerformWriteUpdate(&p_wds[i]);
935 }
936}
937
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600938// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600939void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700940 // Perform update on a per-binding basis as consecutive updates roll over to next binding
941 auto descriptors_remaining = update->descriptorCount;
942 auto binding_being_updated = update->dstBinding;
943 auto offset = update->dstArrayElement;
Tobin Ehlise16805c2017-08-09 09:10:37 -0600944 uint32_t update_index = 0;
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700945 while (descriptors_remaining) {
946 uint32_t update_count = std::min(descriptors_remaining, GetDescriptorCountFromBinding(binding_being_updated));
John Zulaufc483f442017-12-15 14:02:06 -0700947 auto global_idx = p_layout_->GetGlobalIndexRangeFromBinding(binding_being_updated).start + offset;
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700948 // Loop over the updates for a single binding at a time
Tobin Ehlise16805c2017-08-09 09:10:37 -0600949 for (uint32_t di = 0; di < update_count; ++di, ++update_index) {
950 descriptors_[global_idx + di]->WriteUpdate(update, update_index);
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700951 }
952 // Roll over to next binding in case of consecutive update
953 descriptors_remaining -= update_count;
954 offset = 0;
955 binding_being_updated++;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600956 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700957 if (update->descriptorCount) some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600958
Jeff Bolzfdf96072018-04-10 14:32:18 -0500959 if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
960 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
961 InvalidateBoundCmdBuffers();
962 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600963}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600964// Validate Copy update
John Zulaufc93c4252019-06-25 09:19:49 -0600965bool CoreChecks::ValidateCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *dst_set, const DescriptorSet *src_set,
966 const char *func_name, std::string *error_code, std::string *error_msg) {
John Zulaufd9435c32019-06-05 15:55:36 -0600967 auto dst_layout = dst_set->GetLayout();
968 auto src_layout = src_set->GetLayout();
969
John Zulauf5dfd45c2018-01-17 11:06:34 -0700970 // Verify dst layout still valid
John Zulaufd9435c32019-06-05 15:55:36 -0600971 if (dst_layout->IsDestroyed()) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600972 *error_code = "VUID-VkCopyDescriptorSet-dstSet-parameter";
John Zulauf5dfd45c2018-01-17 11:06:34 -0700973 string_sprintf(error_msg,
locke-lunarg9edc2812019-06-17 23:18:52 -0600974 "Cannot call %s to perform copy update on dstSet %s"
975 " created with destroyed %s.",
John Zulaufd9435c32019-06-05 15:55:36 -0600976 func_name, report_data->FormatHandle(dst_set->GetSet()).c_str(),
977 report_data->FormatHandle(dst_layout->GetDescriptorSetLayout()).c_str());
John Zulauf5dfd45c2018-01-17 11:06:34 -0700978 return false;
979 }
980
981 // Verify src layout still valid
John Zulaufd9435c32019-06-05 15:55:36 -0600982 if (src_layout->IsDestroyed()) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600983 *error_code = "VUID-VkCopyDescriptorSet-srcSet-parameter";
John Zulaufb45fdc32018-10-12 15:14:17 -0600984 string_sprintf(error_msg,
Lockeca0d9792019-03-03 23:48:13 -0700985 "Cannot call %s to perform copy update of dstSet %s"
locke-lunarg9edc2812019-06-17 23:18:52 -0600986 " from srcSet %s"
987 " created with destroyed %s.",
John Zulaufd9435c32019-06-05 15:55:36 -0600988 func_name, report_data->FormatHandle(dst_set->GetSet()).c_str(),
989 report_data->FormatHandle(src_set->GetSet()).c_str(),
990 report_data->FormatHandle(src_layout->GetDescriptorSetLayout()).c_str());
John Zulauf5dfd45c2018-01-17 11:06:34 -0700991 return false;
992 }
993
John Zulaufd9435c32019-06-05 15:55:36 -0600994 if (!dst_layout->HasBinding(update->dstBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600995 *error_code = "VUID-VkCopyDescriptorSet-dstBinding-00347";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600996 std::stringstream error_str;
John Zulaufd9435c32019-06-05 15:55:36 -0600997 error_str << "DescriptorSet " << dst_set->GetSet() << " does not have copy update dest binding of " << update->dstBinding;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600998 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600999 return false;
1000 }
1001 if (!src_set->HasBinding(update->srcBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001002 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-00345";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001003 std::stringstream error_str;
John Zulaufd9435c32019-06-05 15:55:36 -06001004 error_str << "DescriptorSet " << dst_set->GetSet() << " does not have copy update src binding of " << update->srcBinding;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001005 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001006 return false;
1007 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05001008 // Verify idle ds
John Zulaufd9435c32019-06-05 15:55:36 -06001009 if (dst_set->in_use.load() &&
1010 !(dst_layout->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
Jeff Bolzfdf96072018-04-10 14:32:18 -05001011 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
1012 // TODO : Re-using Free Idle error code, need copy update idle error code
Dave Houlton00c154e2018-05-24 13:20:50 -06001013 *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001014 std::stringstream error_str;
John Zulaufd9435c32019-06-05 15:55:36 -06001015 error_str << "Cannot call " << func_name << " to perform copy update on descriptor set " << dst_set->GetSet()
Jeff Bolzfdf96072018-04-10 14:32:18 -05001016 << " that is in use by a command buffer";
1017 *error_msg = error_str.str();
1018 return false;
1019 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001020 // src & dst set bindings are valid
1021 // Check bounds of src & dst
John Zulaufc483f442017-12-15 14:02:06 -07001022 auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001023 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
1024 // SRC update out of bounds
Dave Houlton00c154e2018-05-24 13:20:50 -06001025 *error_code = "VUID-VkCopyDescriptorSet-srcArrayElement-00346";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001026 std::stringstream error_str;
1027 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
John Zulaufc483f442017-12-15 14:02:06 -07001028 << " with offset index of " << src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001029 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
Tobin Ehlis1d81edd2016-11-21 09:50:49 -07001030 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001031 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001032 return false;
1033 }
John Zulaufd9435c32019-06-05 15:55:36 -06001034 auto dst_start_idx = dst_layout->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement;
1035 if ((dst_start_idx + update->descriptorCount) > dst_layout->GetTotalDescriptorCount()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001036 // DST update out of bounds
Dave Houlton00c154e2018-05-24 13:20:50 -06001037 *error_code = "VUID-VkCopyDescriptorSet-dstArrayElement-00348";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001038 std::stringstream error_str;
John Zulaufd9435c32019-06-05 15:55:36 -06001039 error_str << "Attempting copy update to descriptorSet " << dst_set->GetSet() << " binding#" << update->dstBinding
1040 << " with offset index of " << dst_layout->GetGlobalIndexRangeFromBinding(update->dstBinding).start
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001041 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
John Zulaufd9435c32019-06-05 15:55:36 -06001042 << " descriptors oversteps total number of descriptors in set: " << dst_layout->GetTotalDescriptorCount();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001043 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001044 return false;
1045 }
1046 // Check that types match
Dave Houltond8ed0212018-05-16 17:18:24 -06001047 // TODO : Base default error case going from here is "VUID-VkAcquireNextImageInfoKHR-semaphore-parameter"2ba which covers all
1048 // consistency issues, need more fine-grained error codes
Dave Houlton00c154e2018-05-24 13:20:50 -06001049 *error_code = "VUID-VkCopyDescriptorSet-srcSet-00349";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001050 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
John Zulaufd9435c32019-06-05 15:55:36 -06001051 auto dst_type = dst_layout->GetTypeFromBinding(update->dstBinding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001052 if (src_type != dst_type) {
1053 std::stringstream error_str;
John Zulaufd9435c32019-06-05 15:55:36 -06001054 error_str << "Attempting copy update to descriptorSet " << dst_set->GetSet() << " binding #" << update->dstBinding
1055 << " with type " << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet()
1056 << " binding #" << update->srcBinding << " with type " << string_VkDescriptorType(src_type)
1057 << ". Types do not match";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001058 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001059 return false;
1060 }
1061 // Verify consistency of src & dst bindings if update crosses binding boundaries
John Zulaufd9435c32019-06-05 15:55:36 -06001062 if ((!VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator(src_layout.get(), update->srcBinding),
John Zulauf4a015c92019-06-04 09:50:05 -06001063 update->srcArrayElement, update->descriptorCount, "copy update from", src_set->GetSet(),
1064 error_msg)) ||
John Zulaufd9435c32019-06-05 15:55:36 -06001065 (!VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator(dst_layout.get(), update->dstBinding),
1066 update->dstArrayElement, update->descriptorCount, "copy update to", dst_set->GetSet(),
1067 error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001068 return false;
1069 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05001070
John Zulaufd9435c32019-06-05 15:55:36 -06001071 if ((src_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) &&
1072 !(dst_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001073 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01918";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001074 std::stringstream error_str;
1075 error_str << "If pname:srcSet's (" << update->srcSet
1076 << ") layout was created with the "
1077 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag "
1078 "set, then pname:dstSet's ("
1079 << update->dstSet
1080 << ") layout must: also have been created with the "
1081 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set";
1082 *error_msg = error_str.str();
1083 return false;
1084 }
1085
John Zulaufd9435c32019-06-05 15:55:36 -06001086 if (!(src_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) &&
1087 (dst_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001088 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01919";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001089 std::stringstream error_str;
1090 error_str << "If pname:srcSet's (" << update->srcSet
1091 << ") layout was created without the "
1092 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag "
1093 "set, then pname:dstSet's ("
1094 << update->dstSet
1095 << ") layout must: also have been created without the "
1096 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set";
1097 *error_msg = error_str.str();
1098 return false;
1099 }
1100
1101 if ((src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) &&
John Zulaufd9435c32019-06-05 15:55:36 -06001102 !(dst_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001103 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01920";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001104 std::stringstream error_str;
1105 error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet
1106 << ") was allocated was created "
1107 "with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag "
1108 "set, then the descriptor pool from which pname:dstSet ("
1109 << update->dstSet
1110 << ") was allocated must: "
1111 "also have been created with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set";
1112 *error_msg = error_str.str();
1113 return false;
1114 }
1115
1116 if (!(src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) &&
John Zulaufd9435c32019-06-05 15:55:36 -06001117 (dst_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001118 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01921";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001119 std::stringstream error_str;
1120 error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet
1121 << ") was allocated was created "
1122 "without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag "
1123 "set, then the descriptor pool from which pname:dstSet ("
1124 << update->dstSet
1125 << ") was allocated must: "
1126 "also have been created without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set";
1127 *error_msg = error_str.str();
1128 return false;
1129 }
1130
Jeff Bolze54ae892018-09-08 12:16:29 -05001131 if (src_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
1132 if ((update->srcArrayElement % 4) != 0) {
1133 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02223";
1134 std::stringstream error_str;
1135 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1136 << "srcArrayElement " << update->srcArrayElement << " not a multiple of 4";
1137 *error_msg = error_str.str();
1138 return false;
1139 }
1140 if ((update->dstArrayElement % 4) != 0) {
1141 *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02224";
1142 std::stringstream error_str;
1143 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1144 << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
1145 *error_msg = error_str.str();
1146 return false;
1147 }
1148 if ((update->descriptorCount % 4) != 0) {
1149 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02225";
1150 std::stringstream error_str;
1151 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1152 << "descriptorCount " << update->descriptorCount << " not a multiple of 4";
1153 *error_msg = error_str.str();
1154 return false;
1155 }
1156 }
1157
Tobin Ehlisd41e7b62016-05-19 07:56:18 -06001158 // Update parameters all look good and descriptor updated so verify update contents
John Zulaufc93c4252019-06-25 09:19:49 -06001159 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, func_name, error_code, error_msg)) return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001160
1161 // All checks passed so update is good
1162 return true;
1163}
1164// Perform Copy update
1165void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
John Zulaufc483f442017-12-15 14:02:06 -07001166 auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement;
1167 auto dst_start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001168 // Update parameters all look good so perform update
1169 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02001170 auto src = src_set->descriptors_[src_start_idx + di].get();
1171 auto dst = descriptors_[dst_start_idx + di].get();
1172 if (src->updated) {
1173 dst->CopyUpdate(src);
1174 some_update_ = true;
1175 } else {
1176 dst->updated = false;
1177 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001178 }
Tobin Ehlis56a30942016-05-19 08:00:00 -06001179
Jeff Bolzfdf96072018-04-10 14:32:18 -05001180 if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
1181 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
1182 InvalidateBoundCmdBuffers();
1183 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001184}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001185
John Zulauf6f3d2bd2018-10-29 17:08:42 -06001186// Update the drawing state for the affected descriptors.
1187// Set cb_node to this set and this set to cb_node.
1188// Add the bindings of the descriptor
1189// Set the layout based on the current descriptor layout (will mask subsequent layer mismatch errors)
1190// TODO: Modify the UpdateDrawState virtural functions to *only* set initial layout and not change layouts
Tobin Ehlisf9519102016-08-17 09:49:13 -06001191// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
1192// to be used in a draw by the given cb_node
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001193void cvdescriptorset::DescriptorSet::UpdateDrawState(CoreChecks *device_data, CMD_BUFFER_STATE *cb_node,
John Zulauf6f3d2bd2018-10-29 17:08:42 -06001194 const std::map<uint32_t, descriptor_req> &binding_req_map) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -06001195 // bind cb to this descriptor set
1196 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -06001197 // Add bindings for descriptor set, the set's pool, and individual objects in the set
John Zulauf4fea6622019-04-01 11:38:18 -06001198 cb_node->object_bindings.emplace(set_, kVulkanObjectTypeDescriptorSet);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -06001199 pool_state_->cb_bindings.insert(cb_node);
John Zulauf4fea6622019-04-01 11:38:18 -06001200 cb_node->object_bindings.emplace(pool_state_->pool, kVulkanObjectTypeDescriptorPool);
Tobin Ehlisf9519102016-08-17 09:49:13 -06001201 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
1202 // resources
Tobin Ehlis022528b2016-12-29 12:22:32 -07001203 for (auto binding_req_pair : binding_req_map) {
1204 auto binding = binding_req_pair.first;
Tony-LunarG62c5dba2018-12-20 14:27:23 -07001205 // We aren't validating descriptors created with PARTIALLY_BOUND or UPDATE_AFTER_BIND, so don't record state
1206 if (p_layout_->GetDescriptorBindingFlagsFromBinding(binding) &
1207 (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT)) {
1208 continue;
1209 }
John Zulaufc483f442017-12-15 14:02:06 -07001210 auto range = p_layout_->GetGlobalIndexRangeFromBinding(binding);
1211 for (uint32_t i = range.start; i < range.end; ++i) {
Mark Lobodzinskifae179e2019-03-08 16:47:08 -07001212 descriptors_[i]->UpdateDrawState(device_data, cb_node);
Mark Lobodzinski2872f4a2018-09-03 17:00:53 -06001213 }
1214 }
1215}
1216
John Zulauf48a6a702017-12-22 17:14:54 -07001217void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair,
1218 const BindingReqMap &in_req, BindingReqMap *out_req,
1219 TrackedBindings *bindings) {
1220 assert(out_req);
1221 assert(bindings);
1222 const auto binding = binding_req_pair.first;
1223 // Use insert and look at the boolean ("was inserted") in the returned pair to see if this is a new set member.
1224 // Saves one hash lookup vs. find ... compare w/ end ... insert.
1225 const auto it_bool_pair = bindings->insert(binding);
1226 if (it_bool_pair.second) {
1227 out_req->emplace(binding_req_pair);
1228 }
1229}
Mark Lobodzinski2872f4a2018-09-03 17:00:53 -06001230
John Zulauf48a6a702017-12-22 17:14:54 -07001231void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair,
1232 const BindingReqMap &in_req, BindingReqMap *out_req,
1233 TrackedBindings *bindings, uint32_t limit) {
1234 if (bindings->size() < limit) FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, bindings);
1235}
1236
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001237void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(CMD_BUFFER_STATE *cb_state, const BindingReqMap &in_req,
John Zulauf48a6a702017-12-22 17:14:54 -07001238 BindingReqMap *out_req) {
1239 TrackedBindings &bound = cached_validation_[cb_state].command_binding_and_usage;
1240 if (bound.size() == GetBindingCount()) {
1241 return; // All bindings are bound, out req is empty
1242 }
1243 for (const auto &binding_req_pair : in_req) {
1244 const auto binding = binding_req_pair.first;
1245 // If a binding doesn't exist, or has already been bound, skip it
1246 if (p_layout_->HasBinding(binding)) {
1247 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, &bound);
1248 }
1249 }
1250}
1251
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001252void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(CMD_BUFFER_STATE *cb_state, PIPELINE_STATE *pipeline,
John Zulauf48a6a702017-12-22 17:14:54 -07001253 const BindingReqMap &in_req, BindingReqMap *out_req) {
1254 auto &validated = cached_validation_[cb_state];
1255 auto &image_sample_val = validated.image_samplers[pipeline];
1256 auto *const dynamic_buffers = &validated.dynamic_buffers;
1257 auto *const non_dynamic_buffers = &validated.non_dynamic_buffers;
1258 const auto &stats = p_layout_->GetBindingTypeStats();
1259 for (const auto &binding_req_pair : in_req) {
1260 auto binding = binding_req_pair.first;
1261 VkDescriptorSetLayoutBinding const *layout_binding = p_layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding);
1262 if (!layout_binding) {
1263 continue;
1264 }
1265 // Caching criteria differs per type.
1266 // If image_layout have changed , the image descriptors need to be validated against them.
1267 if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1268 (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1269 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, dynamic_buffers, stats.dynamic_buffer_count);
1270 } else if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1271 (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) {
1272 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, non_dynamic_buffers, stats.non_dynamic_buffer_count);
1273 } else {
1274 // This is rather crude, as the changed layouts may not impact the bound descriptors,
1275 // but the simple "versioning" is a simple "dirt" test.
1276 auto &version = image_sample_val[binding]; // Take advantage of default construtor zero initialzing new entries
1277 if (version != cb_state->image_layout_change_count) {
1278 version = cb_state->image_layout_change_count;
1279 out_req->emplace(binding_req_pair);
1280 }
1281 }
1282 }
1283}
Tobin Ehlis9252c2b2016-07-21 14:40:22 -06001284
Tobin Ehlis300888c2016-05-18 13:43:26 -06001285cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001286 updated = false;
1287 descriptor_class = PlainSampler;
1288 if (immut) {
1289 sampler_ = *immut;
1290 immutable_ = true;
1291 updated = true;
1292 }
1293}
Tobin Ehlise2f80292016-06-02 10:08:53 -06001294// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
John Zulaufc93c4252019-06-25 09:19:49 -06001295bool CoreChecks::ValidateSampler(const VkSampler sampler) const { return (GetSamplerState(sampler) != nullptr); }
Tobin Ehlis56a30942016-05-19 08:00:00 -06001296
John Zulaufc93c4252019-06-25 09:19:49 -06001297bool CoreChecks::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
1298 const char *func_name, std::string *error_code, std::string *error_msg) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001299 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00326";
John Zulaufc93c4252019-06-25 09:19:49 -06001300 auto iv_state = GetImageViewState(image_view);
Mark Lobodzinski3fc3d752019-06-24 14:22:46 -06001301 assert(iv_state);
1302
Tobin Ehlis81280962016-07-20 14:04:20 -06001303 // Note that when an imageview is created, we validated that memory is bound so no need to re-check here
Tobin Ehlis1809f912016-05-25 09:24:36 -06001304 // Validate that imageLayout is compatible with aspect_mask and image format
1305 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001306 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
1307 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001308 VkFormat format = VK_FORMAT_MAX_ENUM;
1309 VkImageUsageFlags usage = 0;
John Zulaufc93c4252019-06-25 09:19:49 -06001310 auto image_node = GetImageState(image);
Mark Lobodzinski3fc3d752019-06-24 14:22:46 -06001311 assert(image_node);
Chris Forbes67757ff2017-07-21 13:59:01 -07001312
Mark Lobodzinski3fc3d752019-06-24 14:22:46 -06001313 format = image_node->createInfo.format;
1314 usage = image_node->createInfo.usage;
1315 // Validate that memory is bound to image
1316 // TODO: This should have its own valid usage id apart from 2524 which is from CreateImageView case. The only
1317 // the error here occurs is if memory bound to a created imageView has been freed.
1318 if (ValidateMemoryIsBoundToImage(image_node, func_name, "VUID-VkImageViewCreateInfo-image-01020")) {
1319 *error_code = "VUID-VkImageViewCreateInfo-image-01020";
1320 *error_msg = "No memory bound to image.";
Tobin Ehlis1809f912016-05-25 09:24:36 -06001321 return false;
1322 }
Mark Lobodzinski3fc3d752019-06-24 14:22:46 -06001323
1324 // KHR_maintenance1 allows rendering into 2D or 2DArray views which slice a 3D image,
1325 // but not binding them to descriptor sets.
1326 if (image_node->createInfo.imageType == VK_IMAGE_TYPE_3D && (iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D ||
1327 iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
1328 *error_code = "VUID-VkDescriptorImageInfo-imageView-00343";
1329 *error_msg = "ImageView must not be a 2D or 2DArray view of a 3D image";
1330 return false;
1331 }
1332
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001333 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
1334 // vkCreateImageView(). What's the best way to create unique id for these cases?
Mark Lobodzinski3fc3d752019-06-24 14:22:46 -06001335 *error_code = "UNASSIGNED-CoreValidation-DrawState-InvalidImageView";
Dave Houlton1d2022c2017-03-29 11:43:58 -06001336 bool ds = FormatIsDepthOrStencil(format);
Tobin Ehlis1809f912016-05-25 09:24:36 -06001337 switch (image_layout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001338 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1339 // Only Color bit must be set
1340 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis1809f912016-05-25 09:24:36 -06001341 std::stringstream error_str;
Dave Houltona9df0ce2018-02-07 10:51:23 -07001342 error_str
John Zulaufc93c4252019-06-25 09:19:49 -06001343 << "ImageView (" << report_data->FormatHandle(image_view).c_str()
Dave Houltona9df0ce2018-02-07 10:51:23 -07001344 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does not have VK_IMAGE_ASPECT_COLOR_BIT set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001345 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -06001346 return false;
1347 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001348 // format must NOT be DS
1349 if (ds) {
1350 std::stringstream error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001351 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str()
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001352 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
1353 << string_VkFormat(format) << " which is not a color format.";
1354 *error_msg = error_str.str();
1355 return false;
1356 }
1357 break;
1358 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1359 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1360 // Depth or stencil bit must be set, but both must NOT be set
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001361 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1362 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1363 // both must NOT be set
1364 std::stringstream error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001365 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str()
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001366 << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001367 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001368 return false;
1369 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001370 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1371 // Neither were set
1372 std::stringstream error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001373 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str() << ") has layout "
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001374 << string_VkImageLayout(image_layout) << " but does not have STENCIL or DEPTH aspects set";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001375 *error_msg = error_str.str();
1376 return false;
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001377 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001378 // format must be DS
1379 if (!ds) {
1380 std::stringstream error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001381 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str() << ") has layout "
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001382 << string_VkImageLayout(image_layout) << " but the image format is " << string_VkFormat(format)
1383 << " which is not a depth/stencil format.";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001384 *error_msg = error_str.str();
1385 return false;
1386 }
1387 break;
1388 default:
1389 // For other layouts if the source is depth/stencil image, both aspect bits must not be set
1390 if (ds) {
1391 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1392 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1393 // both must NOT be set
1394 std::stringstream error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001395 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str() << ") has layout "
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001396 << string_VkImageLayout(image_layout) << " and is using depth/stencil image of format "
1397 << string_VkFormat(format)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001398 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
1399 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
1400 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
1401 "reads respectively.";
Mark Lobodzinski4d05d7a2019-06-25 09:12:06 -06001402 *error_code = "VUID-VkDescriptorImageInfo-imageView-01976";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001403 *error_msg = error_str.str();
1404 return false;
1405 }
1406 }
1407 }
1408 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001409 }
1410 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -06001411 // As we're switching per-type, if any type has specific layout requirements, check those here as well
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001412 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
1413 // under vkCreateImage()
Dave Houltond8ed0212018-05-16 17:18:24 -06001414 // TODO : Need to also validate case "VUID-VkWriteDescriptorSet-descriptorType-00336" where STORAGE_IMAGE & INPUT_ATTACH types
1415 // must have been created with identify swizzle
Jeff Bolz6d3beaa2019-02-09 21:00:05 -06001416 const char *error_usage_bit = nullptr;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001417 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001418 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1419 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1420 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
1421 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
1422 }
1423 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001424 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001425 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1426 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
1427 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
1428 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
1429 std::stringstream error_str;
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001430 // TODO : Need to create custom enum error codes for these cases
1431 if (image_node->shared_presentable) {
1432 if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != image_layout) {
John Zulaufc93c4252019-06-25 09:19:49 -06001433 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str()
Dave Houltona9df0ce2018-02-07 10:51:23 -07001434 << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type with a front-buffered image is being updated with "
1435 "layout "
1436 << string_VkImageLayout(image_layout)
1437 << " but according to spec section 13.1 Descriptor Types, 'Front-buffered images that report "
1438 "support for VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT must be in the "
1439 "VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR layout.'";
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001440 *error_msg = error_str.str();
1441 return false;
1442 }
1443 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
John Zulaufc93c4252019-06-25 09:19:49 -06001444 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str()
Dave Houltona9df0ce2018-02-07 10:51:23 -07001445 << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
1446 << string_VkImageLayout(image_layout)
1447 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage "
1448 "images can only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001449 *error_msg = error_str.str();
1450 return false;
1451 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001452 }
1453 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001454 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001455 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
1456 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
1457 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
1458 }
1459 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001460 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001461 default:
1462 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001463 }
Jeff Bolz6d3beaa2019-02-09 21:00:05 -06001464 if (error_usage_bit) {
Tobin Ehlis1809f912016-05-25 09:24:36 -06001465 std::stringstream error_str;
Mark Lobodzinski54a67c42019-06-24 14:35:21 -06001466 error_str << "ImageView (" << report_data->FormatHandle(image_view).c_str() << ") with usage mask " << std::hex
1467 << std::showbase << usage << " being used for a descriptor update of type " << string_VkDescriptorType(type)
1468 << " does not have " << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001469 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -06001470 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001471 }
John Zulauff4c07882019-01-24 14:03:36 -07001472
1473 if ((type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) {
1474 // Test that the layout is compatible with the descriptorType for the two sampled image types
1475 const static std::array<VkImageLayout, 3> valid_layouts = {
Jeremy Hayesd0549f62019-06-05 10:15:36 -06001476 {VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL}};
John Zulauff4c07882019-01-24 14:03:36 -07001477
1478 struct ExtensionLayout {
1479 VkImageLayout layout;
1480 bool DeviceExtensions::*extension;
1481 };
1482
1483 const static std::array<ExtensionLayout, 3> extended_layouts{
1484 {// Note double brace req'd for aggregate initialization
1485 {VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, &DeviceExtensions::vk_khr_shared_presentable_image},
1486 {VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, &DeviceExtensions::vk_khr_maintenance2},
1487 {VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, &DeviceExtensions::vk_khr_maintenance2}}};
John Zulaufc93c4252019-06-25 09:19:49 -06001488 auto is_layout = [image_layout, this](const ExtensionLayout &ext_layout) {
1489 return device_extensions.*(ext_layout.extension) && (ext_layout.layout == image_layout);
John Zulauff4c07882019-01-24 14:03:36 -07001490 };
1491
1492 bool valid_layout = (std::find(valid_layouts.cbegin(), valid_layouts.cend(), image_layout) != valid_layouts.cend()) ||
1493 std::any_of(extended_layouts.cbegin(), extended_layouts.cend(), is_layout);
1494
1495 if (!valid_layout) {
1496 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-01403";
1497 std::stringstream error_str;
1498 error_str << "Descriptor update with descriptorType " << string_VkDescriptorType(type)
Mark Lobodzinski74eddba2019-06-21 14:16:33 -06001499 << " is being updated with invalid imageLayout " << string_VkImageLayout(image_layout) << " for image "
John Zulaufc93c4252019-06-25 09:19:49 -06001500 << report_data->FormatHandle(image).c_str() << " in imageView "
1501 << report_data->FormatHandle(image_view).c_str()
John Zulauff4c07882019-01-24 14:03:36 -07001502 << ". Allowed layouts are: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, "
1503 << "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL";
1504 for (auto &ext_layout : extended_layouts) {
John Zulaufc93c4252019-06-25 09:19:49 -06001505 if (device_extensions.*(ext_layout.extension)) {
John Zulauff4c07882019-01-24 14:03:36 -07001506 error_str << ", " << string_VkImageLayout(ext_layout.layout);
1507 }
1508 }
1509 *error_msg = error_str.str();
1510 return false;
1511 }
1512 }
1513
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001514 return true;
1515}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001516
Tobin Ehlis300888c2016-05-18 13:43:26 -06001517void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Chris Forbesfea2c542018-04-13 09:34:15 -07001518 if (!immutable_) {
1519 sampler_ = update->pImageInfo[index].sampler;
1520 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001521 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001522}
1523
Tobin Ehlis300888c2016-05-18 13:43:26 -06001524void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001525 if (!immutable_) {
1526 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001527 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001528 }
1529 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001530}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001531
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001532void cvdescriptorset::SamplerDescriptor::UpdateDrawState(CoreChecks *dev_data, CMD_BUFFER_STATE *cb_node) {
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001533 if (!immutable_) {
Mark Lobodzinskif8d1ef92019-03-06 11:53:27 -07001534 auto sampler_state = dev_data->GetSamplerState(sampler_);
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07001535 if (sampler_state) dev_data->AddCommandBufferBindingSampler(cb_node, sampler_state);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001536 }
1537}
1538
Tobin Ehlis300888c2016-05-18 13:43:26 -06001539cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
Chris Forbes9f340852017-05-09 08:51:38 -07001540 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001541 updated = false;
1542 descriptor_class = ImageSampler;
1543 if (immut) {
1544 sampler_ = *immut;
1545 immutable_ = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001546 }
1547}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001548
Tobin Ehlis300888c2016-05-18 13:43:26 -06001549void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001550 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001551 const auto &image_info = update->pImageInfo[index];
Chris Forbesfea2c542018-04-13 09:34:15 -07001552 if (!immutable_) {
1553 sampler_ = image_info.sampler;
1554 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001555 image_view_ = image_info.imageView;
1556 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001557}
1558
Tobin Ehlis300888c2016-05-18 13:43:26 -06001559void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001560 if (!immutable_) {
1561 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001562 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001563 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001564 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
1565 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001566 updated = true;
1567 image_view_ = image_view;
1568 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001569}
1570
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001571void cvdescriptorset::ImageSamplerDescriptor::UpdateDrawState(CoreChecks *dev_data, CMD_BUFFER_STATE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -06001572 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001573 if (!immutable_) {
Mark Lobodzinskif8d1ef92019-03-06 11:53:27 -07001574 auto sampler_state = dev_data->GetSamplerState(sampler_);
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07001575 if (sampler_state) dev_data->AddCommandBufferBindingSampler(cb_node, sampler_state);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001576 }
Tobin Ehlis81e46372016-08-17 13:33:44 -06001577 // Add binding for image
Mark Lobodzinskia3a230b2019-03-06 15:35:13 -07001578 auto iv_state = dev_data->GetImageViewState(image_view_);
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001579 if (iv_state) {
Mark Lobodzinskifae179e2019-03-08 16:47:08 -07001580 dev_data->AddCommandBufferBindingImageView(cb_node, iv_state);
John Zulauff660ad62019-03-23 07:16:05 -06001581 dev_data->SetImageViewInitialLayout(cb_node, *iv_state, image_layout_);
Jeff Bolz148d94e2018-12-13 21:25:56 -06001582 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001583}
1584
Tobin Ehlis300888c2016-05-18 13:43:26 -06001585cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
1586 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001587 updated = false;
1588 descriptor_class = Image;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001589 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) storage_ = true;
Petr Kraus13c98a62017-12-09 00:22:39 +01001590}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001591
Tobin Ehlis300888c2016-05-18 13:43:26 -06001592void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001593 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001594 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -06001595 image_view_ = image_info.imageView;
1596 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001597}
1598
Tobin Ehlis300888c2016-05-18 13:43:26 -06001599void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001600 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
1601 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001602 updated = true;
1603 image_view_ = image_view;
1604 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001605}
1606
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001607void cvdescriptorset::ImageDescriptor::UpdateDrawState(CoreChecks *dev_data, CMD_BUFFER_STATE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -06001608 // Add binding for image
Mark Lobodzinskia3a230b2019-03-06 15:35:13 -07001609 auto iv_state = dev_data->GetImageViewState(image_view_);
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001610 if (iv_state) {
Mark Lobodzinskifae179e2019-03-08 16:47:08 -07001611 dev_data->AddCommandBufferBindingImageView(cb_node, iv_state);
John Zulauff660ad62019-03-23 07:16:05 -06001612 dev_data->SetImageViewInitialLayout(cb_node, *iv_state, image_layout_);
Jeff Bolz148d94e2018-12-13 21:25:56 -06001613 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001614}
1615
Tobin Ehlis300888c2016-05-18 13:43:26 -06001616cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
1617 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001618 updated = false;
1619 descriptor_class = GeneralBuffer;
1620 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
1621 dynamic_ = true;
1622 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
1623 storage_ = true;
1624 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
1625 dynamic_ = true;
1626 storage_ = true;
1627 }
1628}
Tobin Ehlis300888c2016-05-18 13:43:26 -06001629void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001630 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001631 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -06001632 buffer_ = buffer_info.buffer;
1633 offset_ = buffer_info.offset;
1634 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001635}
1636
Tobin Ehlis300888c2016-05-18 13:43:26 -06001637void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
1638 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001639 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001640 buffer_ = buff_desc->buffer_;
1641 offset_ = buff_desc->offset_;
1642 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001643}
1644
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001645void cvdescriptorset::BufferDescriptor::UpdateDrawState(CoreChecks *dev_data, CMD_BUFFER_STATE *cb_node) {
Mark Lobodzinski6ed74142019-03-06 11:35:39 -07001646 auto buffer_node = dev_data->GetBufferState(buffer_);
Mark Lobodzinskifae179e2019-03-08 16:47:08 -07001647 if (buffer_node) dev_data->AddCommandBufferBindingBuffer(cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001648}
1649
Tobin Ehlis300888c2016-05-18 13:43:26 -06001650cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001651 updated = false;
1652 descriptor_class = TexelBuffer;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001653 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) storage_ = true;
Petr Kraus13c98a62017-12-09 00:22:39 +01001654}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001655
Tobin Ehlis300888c2016-05-18 13:43:26 -06001656void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001657 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001658 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001659}
1660
Tobin Ehlis300888c2016-05-18 13:43:26 -06001661void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1662 updated = true;
1663 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1664}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001665
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06001666void cvdescriptorset::TexelDescriptor::UpdateDrawState(CoreChecks *dev_data, CMD_BUFFER_STATE *cb_node) {
Mark Lobodzinski31aa9b02019-03-06 11:51:37 -07001667 auto bv_state = dev_data->GetBufferViewState(buffer_view_);
Tobin Ehlis8b872462016-09-14 08:12:08 -06001668 if (bv_state) {
Mark Lobodzinskifae179e2019-03-08 16:47:08 -07001669 dev_data->AddCommandBufferBindingBufferView(cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001670 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001671}
1672
Tobin Ehlis300888c2016-05-18 13:43:26 -06001673// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1674// sets, and then calls their respective Validate[Write|Copy]Update functions.
1675// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1676// be skipped, then true is returned.
1677// If there is no issue with the update, then false is returned.
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07001678bool CoreChecks::ValidateUpdateDescriptorSets(uint32_t write_count, const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07001679 const VkCopyDescriptorSet *p_cds, const char *func_name) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001680 bool skip = false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001681 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001682 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001683 auto dest_set = p_wds[i].dstSet;
Mark Lobodzinskifc2f0d32019-03-06 11:25:39 -07001684 auto set_node = GetSetNode(dest_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001685 if (!set_node) {
John Zulaufb45fdc32018-10-12 15:14:17 -06001686 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1687 HandleToUint64(dest_set), kVUID_Core_DrawState_InvalidDescriptorSet,
locke-lunarg9edc2812019-06-17 23:18:52 -06001688 "Cannot call %s on %s that has not been allocated.", func_name,
Lockeca0d9792019-03-03 23:48:13 -07001689 report_data->FormatHandle(dest_set).c_str());
Tobin Ehlis300888c2016-05-18 13:43:26 -06001690 } else {
Dave Houltond8ed0212018-05-16 17:18:24 -06001691 std::string error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001692 std::string error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001693 if (!ValidateWriteUpdate(set_node, &p_wds[i], func_name, &error_code, &error_str)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001694 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
locke-lunarg9edc2812019-06-17 23:18:52 -06001695 HandleToUint64(dest_set), error_code, "%s failed write update validation for %s with error: %s.",
1696 func_name, report_data->FormatHandle(dest_set).c_str(), error_str.c_str());
Tobin Ehlis300888c2016-05-18 13:43:26 -06001697 }
1698 }
1699 }
1700 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001701 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001702 auto dst_set = p_cds[i].dstSet;
1703 auto src_set = p_cds[i].srcSet;
Mark Lobodzinskifc2f0d32019-03-06 11:25:39 -07001704 auto src_node = GetSetNode(src_set);
1705 auto dst_node = GetSetNode(dst_set);
Tobin Ehlisa1712752017-01-04 09:41:47 -07001706 // Object_tracker verifies that src & dest descriptor set are valid
1707 assert(src_node);
1708 assert(dst_node);
Dave Houltond8ed0212018-05-16 17:18:24 -06001709 std::string error_code;
Tobin Ehlisa1712752017-01-04 09:41:47 -07001710 std::string error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001711 if (!ValidateCopyUpdate(&p_cds[i], dst_node, src_node, func_name, &error_code, &error_str)) {
locke-lunarg9edc2812019-06-17 23:18:52 -06001712 skip |=
1713 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1714 HandleToUint64(dst_set), error_code, "%s failed copy update from %s to %s with error: %s.", func_name,
1715 report_data->FormatHandle(src_set).c_str(), report_data->FormatHandle(dst_set).c_str(), error_str.c_str());
Tobin Ehlis300888c2016-05-18 13:43:26 -06001716 }
1717 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001718 return skip;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001719}
1720// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1721// sets, and then calls their respective Perform[Write|Copy]Update functions.
1722// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1723// with the same set of updates.
1724// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1725// calling down the chain.
John Zulaufe3b35f32019-06-25 14:21:21 -06001726void cvdescriptorset::PerformUpdateDescriptorSets(ValidationStateTracker *dev_data, uint32_t write_count,
1727 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1728 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001729 // Write updates first
1730 uint32_t i = 0;
1731 for (i = 0; i < write_count; ++i) {
1732 auto dest_set = p_wds[i].dstSet;
Mark Lobodzinskifc2f0d32019-03-06 11:25:39 -07001733 auto set_node = dev_data->GetSetNode(dest_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001734 if (set_node) {
1735 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001736 }
1737 }
1738 // Now copy updates
1739 for (i = 0; i < copy_count; ++i) {
1740 auto dst_set = p_cds[i].dstSet;
1741 auto src_set = p_cds[i].srcSet;
Mark Lobodzinskifc2f0d32019-03-06 11:25:39 -07001742 auto src_node = dev_data->GetSetNode(src_set);
1743 auto dst_node = dev_data->GetSetNode(dst_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001744 if (src_node && dst_node) {
1745 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001746 }
1747 }
1748}
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001749
John Zulaufe3b35f32019-06-25 14:21:21 -06001750cvdescriptorset::DecodedTemplateUpdate::DecodedTemplateUpdate(const ValidationStateTracker *device_data,
1751 VkDescriptorSet descriptorSet, const TEMPLATE_STATE *template_state,
1752 const void *pData, VkDescriptorSetLayout push_layout) {
John Zulaufb845eb22018-10-12 11:41:06 -06001753 auto const &create_info = template_state->create_info;
1754 inline_infos.resize(create_info.descriptorUpdateEntryCount); // Make sure we have one if we need it
1755 desc_writes.reserve(create_info.descriptorUpdateEntryCount); // emplaced, so reserved without initialization
John Zulauf1d27e0a2018-11-05 10:12:48 -07001756 VkDescriptorSetLayout effective_dsl = create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET
1757 ? create_info.descriptorSetLayout
1758 : push_layout;
1759 auto layout_obj = GetDescriptorSetLayout(device_data, effective_dsl);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001760
1761 // Create a WriteDescriptorSet struct for each template update entry
1762 for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) {
1763 auto binding_count = layout_obj->GetDescriptorCountFromBinding(create_info.pDescriptorUpdateEntries[i].dstBinding);
1764 auto binding_being_updated = create_info.pDescriptorUpdateEntries[i].dstBinding;
1765 auto dst_array_element = create_info.pDescriptorUpdateEntries[i].dstArrayElement;
1766
John Zulaufb6d71202017-12-22 16:47:09 -07001767 desc_writes.reserve(desc_writes.size() + create_info.pDescriptorUpdateEntries[i].descriptorCount);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001768 for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) {
1769 desc_writes.emplace_back();
1770 auto &write_entry = desc_writes.back();
1771
1772 size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride;
1773 char *update_entry = (char *)(pData) + offset;
1774
1775 if (dst_array_element >= binding_count) {
1776 dst_array_element = 0;
Mark Lobodzinski4aa479d2017-03-10 09:14:00 -07001777 binding_being_updated = layout_obj->GetNextValidBinding(binding_being_updated);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001778 }
1779
1780 write_entry.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1781 write_entry.pNext = NULL;
1782 write_entry.dstSet = descriptorSet;
1783 write_entry.dstBinding = binding_being_updated;
1784 write_entry.dstArrayElement = dst_array_element;
1785 write_entry.descriptorCount = 1;
1786 write_entry.descriptorType = create_info.pDescriptorUpdateEntries[i].descriptorType;
1787
1788 switch (create_info.pDescriptorUpdateEntries[i].descriptorType) {
1789 case VK_DESCRIPTOR_TYPE_SAMPLER:
1790 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1791 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1792 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1793 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1794 write_entry.pImageInfo = reinterpret_cast<VkDescriptorImageInfo *>(update_entry);
1795 break;
1796
1797 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1798 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1799 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1800 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1801 write_entry.pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry);
1802 break;
1803
1804 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1805 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1806 write_entry.pTexelBufferView = reinterpret_cast<VkBufferView *>(update_entry);
1807 break;
Dave Houlton142c4cb2018-10-17 15:04:41 -06001808 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: {
1809 VkWriteDescriptorSetInlineUniformBlockEXT *inline_info = &inline_infos[i];
1810 inline_info->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT;
1811 inline_info->pNext = nullptr;
1812 inline_info->dataSize = create_info.pDescriptorUpdateEntries[i].descriptorCount;
1813 inline_info->pData = update_entry;
1814 write_entry.pNext = inline_info;
Ricardo Garciafee15732019-05-28 11:13:31 +02001815 // descriptorCount must match the dataSize member of the VkWriteDescriptorSetInlineUniformBlockEXT structure
1816 write_entry.descriptorCount = inline_info->dataSize;
Dave Houlton142c4cb2018-10-17 15:04:41 -06001817 // skip the rest of the array, they just represent bytes in the update
1818 j = create_info.pDescriptorUpdateEntries[i].descriptorCount;
1819 break;
1820 }
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001821 default:
1822 assert(0);
1823 break;
1824 }
1825 dst_array_element++;
1826 }
1827 }
John Zulaufb845eb22018-10-12 11:41:06 -06001828}
John Zulaufb45fdc32018-10-12 15:14:17 -06001829// These helper functions carry out the validate and record descriptor updates peformed via update templates. They decode
1830// the templatized data and leverage the non-template UpdateDescriptor helper functions.
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07001831bool CoreChecks::ValidateUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, const TEMPLATE_STATE *template_state,
1832 const void *pData) {
John Zulaufb45fdc32018-10-12 15:14:17 -06001833 // Translate the templated update into a normal update for validation...
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07001834 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
1835 return ValidateUpdateDescriptorSets(static_cast<uint32_t>(decoded_update.desc_writes.size()), decoded_update.desc_writes.data(),
1836 0, NULL, "vkUpdateDescriptorSetWithTemplate()");
John Zulaufb45fdc32018-10-12 15:14:17 -06001837}
John Zulaufb845eb22018-10-12 11:41:06 -06001838
John Zulaufe3b35f32019-06-25 14:21:21 -06001839void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
1840 const TEMPLATE_STATE *template_state, const void *pData) {
John Zulaufb45fdc32018-10-12 15:14:17 -06001841 // Translate the templated update into a normal update for validation...
Mark Lobodzinski254c8512019-03-09 12:21:15 -07001842 cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
1843 cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07001844 decoded_update.desc_writes.data(), 0, NULL);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001845}
John Zulauf4e7bcb52018-11-02 10:46:30 -06001846
1847std::string cvdescriptorset::DescriptorSet::StringifySetAndLayout() const {
1848 std::string out;
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001849 auto layout_handle = p_layout_->GetDescriptorSetLayout();
John Zulauf4e7bcb52018-11-02 10:46:30 -06001850 if (IsPushDescriptor()) {
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001851 string_sprintf(&out, "Push Descriptors defined with VkDescriptorSetLayout %s",
John Zulaufc93c4252019-06-25 09:19:49 -06001852 state_data_->report_data->FormatHandle(layout_handle).c_str());
John Zulauf4e7bcb52018-11-02 10:46:30 -06001853 } else {
Mark Lobodzinski6b042922019-06-21 14:46:42 -06001854 string_sprintf(&out, "VkDescriptorSet %s allocated with VkDescriptorSetLayout %s",
John Zulaufc93c4252019-06-25 09:19:49 -06001855 state_data_->report_data->FormatHandle(set_).c_str(),
1856 state_data_->report_data->FormatHandle(layout_handle).c_str());
John Zulauf4e7bcb52018-11-02 10:46:30 -06001857 }
1858 return out;
1859};
1860
John Zulauf1d27e0a2018-11-05 10:12:48 -07001861// Loop through the write updates to validate for a push descriptor set, ignoring dstSet
John Zulaufc93c4252019-06-25 09:19:49 -06001862bool CoreChecks::ValidatePushDescriptorsUpdate(const DescriptorSet *push_set, uint32_t write_count,
1863 const VkWriteDescriptorSet *p_wds, const char *func_name) {
John Zulaufd9435c32019-06-05 15:55:36 -06001864 assert(push_set->IsPushDescriptor());
John Zulauf1d27e0a2018-11-05 10:12:48 -07001865 bool skip = false;
1866 for (uint32_t i = 0; i < write_count; i++) {
1867 std::string error_code;
1868 std::string error_str;
John Zulaufc93c4252019-06-25 09:19:49 -06001869 if (!ValidateWriteUpdate(push_set, &p_wds[i], func_name, &error_code, &error_str)) {
John Zulauf1d27e0a2018-11-05 10:12:48 -07001870 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
John Zulaufd9435c32019-06-05 15:55:36 -06001871 HandleToUint64(push_set->GetDescriptorSetLayout()), error_code, "%s failed update validation: %s.",
John Zulauf1d27e0a2018-11-05 10:12:48 -07001872 func_name, error_str.c_str());
1873 }
1874 }
1875 return skip;
1876}
1877
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001878// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001879// If there's an error, update the error_msg string with details and return false, else return true
John Zulaufd9435c32019-06-05 15:55:36 -06001880bool cvdescriptorset::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type, std::string *error_code,
1881 std::string *error_msg) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001882 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001883 auto usage = buffer_node->createInfo.usage;
Jeff Bolz6d3beaa2019-02-09 21:00:05 -06001884 const char *error_usage_bit = nullptr;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001885 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001886 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1887 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001888 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00334";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001889 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1890 }
1891 break;
1892 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1893 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001894 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00335";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001895 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1896 }
1897 break;
1898 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1899 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1900 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001901 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00330";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001902 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1903 }
1904 break;
1905 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1906 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1907 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001908 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00331";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001909 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1910 }
1911 break;
1912 default:
1913 break;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001914 }
Jeff Bolz6d3beaa2019-02-09 21:00:05 -06001915 if (error_usage_bit) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001916 std::stringstream error_str;
Mark Lobodzinski54a67c42019-06-24 14:35:21 -06001917 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask " << std::hex << std::showbase << usage
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001918 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1919 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001920 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001921 return false;
1922 }
1923 return true;
1924}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001925// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1926// 1. buffer is valid
1927// 2. buffer was created with correct usage flags
1928// 3. offset is less than buffer size
1929// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001930// 5. range and offset are within the device's limits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001931// If there's an error, update the error_msg string with details and return false, else return true
John Zulaufc93c4252019-06-25 09:19:49 -06001932bool CoreChecks::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, const char *func_name,
1933 std::string *error_code, std::string *error_msg) {
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001934 // First make sure that buffer is valid
John Zulaufc93c4252019-06-25 09:19:49 -06001935 auto buffer_node = GetBufferState(buffer_info->buffer);
Tobin Ehlisfa8b6182016-12-22 13:40:45 -07001936 // Any invalid buffer should already be caught by object_tracker
1937 assert(buffer_node);
John Zulaufc93c4252019-06-25 09:19:49 -06001938 if (ValidateMemoryIsBoundToBuffer(buffer_node, func_name, "VUID-VkWriteDescriptorSet-descriptorType-00329")) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001939 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00329";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001940 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001941 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001942 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001943 // Verify usage bits
John Zulaufc93c4252019-06-25 09:19:49 -06001944 if (!cvdescriptorset::ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001945 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001946 return false;
1947 }
1948 // offset must be less than buffer size
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07001949 if (buffer_info->offset >= buffer_node->createInfo.size) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001950 *error_code = "VUID-VkDescriptorBufferInfo-offset-00340";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001951 std::stringstream error_str;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07001952 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than or equal to buffer "
1953 << buffer_node->buffer << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001954 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001955 return false;
1956 }
1957 if (buffer_info->range != VK_WHOLE_SIZE) {
1958 // Range must be VK_WHOLE_SIZE or > 0
1959 if (!buffer_info->range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001960 *error_code = "VUID-VkDescriptorBufferInfo-range-00341";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001961 std::stringstream error_str;
1962 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001963 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001964 return false;
1965 }
1966 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
1967 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001968 *error_code = "VUID-VkDescriptorBufferInfo-range-00342";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001969 std::stringstream error_str;
1970 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
1971 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001972 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001973 return false;
1974 }
1975 }
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001976 // Check buffer update sizes against device limits
John Zulaufc93c4252019-06-25 09:19:49 -06001977 const auto &limits = phys_dev_props.limits;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001978 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type || VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
John Zulaufd9435c32019-06-05 15:55:36 -06001979 auto max_ub_range = limits.maxUniformBufferRange;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001980 if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_ub_range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001981 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332";
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001982 std::stringstream error_str;
1983 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range
1984 << " which is greater than this device's maxUniformBufferRange (" << max_ub_range << ")";
1985 *error_msg = error_str.str();
1986 return false;
Peter Kohaut2794a292018-07-13 11:13:47 +02001987 } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_ub_range) {
1988 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332";
1989 std::stringstream error_str;
Peter Kohaut18f413d2018-07-16 13:15:42 +02001990 error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range "
1991 << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's "
Peter Kohaut2794a292018-07-13 11:13:47 +02001992 << "maxUniformBufferRange (" << max_ub_range << ")";
1993 *error_msg = error_str.str();
1994 return false;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001995 }
1996 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type || VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
John Zulaufd9435c32019-06-05 15:55:36 -06001997 auto max_sb_range = limits.maxStorageBufferRange;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001998 if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_sb_range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001999 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333";
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002000 std::stringstream error_str;
2001 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range
2002 << " which is greater than this device's maxStorageBufferRange (" << max_sb_range << ")";
2003 *error_msg = error_str.str();
2004 return false;
Peter Kohaut2794a292018-07-13 11:13:47 +02002005 } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_sb_range) {
2006 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333";
2007 std::stringstream error_str;
Peter Kohaut18f413d2018-07-16 13:15:42 +02002008 error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range "
2009 << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's "
Peter Kohaut2794a292018-07-13 11:13:47 +02002010 << "maxStorageBufferRange (" << max_sb_range << ")";
2011 *error_msg = error_str.str();
2012 return false;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002013 }
2014 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002015 return true;
2016}
Tobin Ehlis300888c2016-05-18 13:43:26 -06002017// Verify that the contents of the update are ok, but don't perform actual update
John Zulaufc93c4252019-06-25 09:19:49 -06002018bool CoreChecks::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, VkDescriptorType type,
2019 uint32_t index, const char *func_name, std::string *error_code, std::string *error_msg) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002020 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
2021 // for write updates
John Zulaufc93c4252019-06-25 09:19:49 -06002022 using DescriptorClass = cvdescriptorset::DescriptorClass;
2023 using BufferDescriptor = cvdescriptorset::BufferDescriptor;
2024 using ImageDescriptor = cvdescriptorset::ImageDescriptor;
2025 using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor;
2026 using SamplerDescriptor = cvdescriptorset::SamplerDescriptor;
2027 using TexelDescriptor = cvdescriptorset::TexelDescriptor;
2028
2029 auto device_data = this;
John Zulaufd9435c32019-06-05 15:55:36 -06002030 switch (src_set->GetDescriptorFromGlobalIndex(index)->descriptor_class) {
John Zulaufc93c4252019-06-25 09:19:49 -06002031 case DescriptorClass::PlainSampler: {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002032 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufd9435c32019-06-05 15:55:36 -06002033 const auto src_desc = src_set->GetDescriptorFromGlobalIndex(index + di);
Józef Kucia5297e372017-10-13 22:31:34 +02002034 if (!src_desc->updated) continue;
2035 if (!src_desc->IsImmutableSampler()) {
John Zulaufd9435c32019-06-05 15:55:36 -06002036 auto update_sampler = static_cast<const SamplerDescriptor *>(src_desc)->GetSampler();
John Zulaufc93c4252019-06-25 09:19:49 -06002037 if (!ValidateSampler(update_sampler)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002038 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002039 std::stringstream error_str;
2040 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
2041 *error_msg = error_str.str();
2042 return false;
2043 }
2044 } else {
2045 // TODO : Warn here
2046 }
2047 }
2048 break;
2049 }
John Zulaufc93c4252019-06-25 09:19:49 -06002050 case DescriptorClass::ImageSampler: {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002051 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufd9435c32019-06-05 15:55:36 -06002052 const auto src_desc = src_set->GetDescriptorFromGlobalIndex(index + di);
Józef Kucia5297e372017-10-13 22:31:34 +02002053 if (!src_desc->updated) continue;
2054 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_desc);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002055 // First validate sampler
2056 if (!img_samp_desc->IsImmutableSampler()) {
2057 auto update_sampler = img_samp_desc->GetSampler();
John Zulaufc93c4252019-06-25 09:19:49 -06002058 if (!ValidateSampler(update_sampler)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002059 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002060 std::stringstream error_str;
2061 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
2062 *error_msg = error_str.str();
2063 return false;
2064 }
2065 } else {
2066 // TODO : Warn here
2067 }
2068 // Validate image
2069 auto image_view = img_samp_desc->GetImageView();
2070 auto image_layout = img_samp_desc->GetImageLayout();
John Zulaufc93c4252019-06-25 09:19:49 -06002071 if (!ValidateImageUpdate(image_view, image_layout, type, func_name, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002072 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002073 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002074 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06002075 return false;
2076 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002077 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002078 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002079 }
John Zulaufc93c4252019-06-25 09:19:49 -06002080 case DescriptorClass::Image: {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002081 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufd9435c32019-06-05 15:55:36 -06002082 const auto src_desc = src_set->GetDescriptorFromGlobalIndex(index + di);
Józef Kucia5297e372017-10-13 22:31:34 +02002083 if (!src_desc->updated) continue;
2084 auto img_desc = static_cast<const ImageDescriptor *>(src_desc);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002085 auto image_view = img_desc->GetImageView();
2086 auto image_layout = img_desc->GetImageLayout();
John Zulaufc93c4252019-06-25 09:19:49 -06002087 if (!ValidateImageUpdate(image_view, image_layout, type, func_name, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002088 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002089 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002090 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06002091 return false;
2092 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002093 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002094 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002095 }
John Zulaufc93c4252019-06-25 09:19:49 -06002096 case DescriptorClass::TexelBuffer: {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002097 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufd9435c32019-06-05 15:55:36 -06002098 const auto src_desc = src_set->GetDescriptorFromGlobalIndex(index + di);
Józef Kucia5297e372017-10-13 22:31:34 +02002099 if (!src_desc->updated) continue;
John Zulaufd9435c32019-06-05 15:55:36 -06002100 auto buffer_view = static_cast<const TexelDescriptor *>(src_desc)->GetBufferView();
2101 auto bv_state = device_data->GetBufferViewState(buffer_view);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002102 if (!bv_state) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002103 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002104 std::stringstream error_str;
2105 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
2106 *error_msg = error_str.str();
2107 return false;
2108 }
2109 auto buffer = bv_state->create_info.buffer;
John Zulaufc93c4252019-06-25 09:19:49 -06002110 if (!cvdescriptorset::ValidateBufferUsage(GetBufferState(buffer), type, error_code, error_msg)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002111 std::stringstream error_str;
2112 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
2113 *error_msg = error_str.str();
2114 return false;
2115 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002116 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002117 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002118 }
John Zulaufc93c4252019-06-25 09:19:49 -06002119 case DescriptorClass::GeneralBuffer: {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002120 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufd9435c32019-06-05 15:55:36 -06002121 const auto src_desc = src_set->GetDescriptorFromGlobalIndex(index + di);
Józef Kucia5297e372017-10-13 22:31:34 +02002122 if (!src_desc->updated) continue;
John Zulaufd9435c32019-06-05 15:55:36 -06002123 auto buffer = static_cast<const BufferDescriptor *>(src_desc)->GetBuffer();
John Zulaufc93c4252019-06-25 09:19:49 -06002124 if (!cvdescriptorset::ValidateBufferUsage(GetBufferState(buffer), type, error_code, error_msg)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002125 std::stringstream error_str;
2126 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
2127 *error_msg = error_str.str();
2128 return false;
2129 }
Tobin Ehliscbcf2342016-05-24 13:07:12 -06002130 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002131 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002132 }
John Zulaufc93c4252019-06-25 09:19:49 -06002133 case DescriptorClass::InlineUniform:
2134 case DescriptorClass::AccelerationStructure:
Jeff Bolze54ae892018-09-08 12:16:29 -05002135 break;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002136 default:
2137 assert(0); // We've already verified update type so should never get here
2138 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002139 }
2140 // All checks passed so update contents are good
2141 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12002142}
Tobin Ehlisf320b192017-03-14 11:22:50 -06002143// Update the common AllocateDescriptorSetsData
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07002144void CoreChecks::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07002145 cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
Tobin Ehlisf320b192017-03-14 11:22:50 -06002146 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07002147 auto layout = GetDescriptorSetLayout(this, p_alloc_info->pSetLayouts[i]);
Tobin Ehlisf320b192017-03-14 11:22:50 -06002148 if (layout) {
2149 ds_data->layout_nodes[i] = layout;
2150 // Count total descriptors required per type
2151 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
2152 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
2153 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
2154 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
2155 }
2156 }
2157 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
2158 }
Petr Kraus13c98a62017-12-09 00:22:39 +01002159}
Tobin Ehlisee471462016-05-26 11:21:59 -06002160// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07002161bool CoreChecks::ValidateAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07002162 const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002163 bool skip = false;
Mark Lobodzinski7804bd42019-03-06 11:28:48 -07002164 auto pool_state = GetDescriptorPoolState(p_alloc_info->descriptorPool);
Tobin Ehlisee471462016-05-26 11:21:59 -06002165
2166 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07002167 auto layout = GetDescriptorSetLayout(this, p_alloc_info->pSetLayouts[i]);
John Zulauf5562d062018-01-24 11:54:05 -07002168 if (layout) { // nullptr layout indicates no valid layout handle for this device, validated/logged in object_tracker
John Zulauf1d27e0a2018-11-05 10:12:48 -07002169 if (layout->IsPushDescriptor()) {
John Zulauf5562d062018-01-24 11:54:05 -07002170 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
Dave Houltond8ed0212018-05-16 17:18:24 -06002171 HandleToUint64(p_alloc_info->pSetLayouts[i]), "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-00308",
locke-lunarg9edc2812019-06-17 23:18:52 -06002172 "%s specified at pSetLayouts[%" PRIu32
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002173 "] in vkAllocateDescriptorSets() was created with invalid flag %s set.",
Lockeca0d9792019-03-03 23:48:13 -07002174 report_data->FormatHandle(p_alloc_info->pSetLayouts[i]).c_str(), i,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002175 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR");
John Zulauf5562d062018-01-24 11:54:05 -07002176 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05002177 if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT &&
2178 !(pool_state->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
2179 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
Dave Houltond8ed0212018-05-16 17:18:24 -06002180 0, "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-03044",
Jeff Bolzfdf96072018-04-10 14:32:18 -05002181 "Descriptor set layout create flags and pool create flags mismatch for index (%d)", i);
2182 }
Tobin Ehlisee471462016-05-26 11:21:59 -06002183 }
2184 }
Mark Lobodzinskif45e45f2019-04-19 14:15:39 -06002185 if (!device_extensions.vk_khr_maintenance1) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002186 // Track number of descriptorSets allowable in this pool
2187 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002188 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Dave Houltond8ed0212018-05-16 17:18:24 -06002189 HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorSetCount-00306",
locke-lunarg9edc2812019-06-17 23:18:52 -06002190 "Unable to allocate %u descriptorSets from %s"
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002191 ". This pool only has %d descriptorSets remaining.",
Lockeca0d9792019-03-03 23:48:13 -07002192 p_alloc_info->descriptorSetCount, report_data->FormatHandle(pool_state->pool).c_str(),
2193 pool_state->availableSets);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002194 }
2195 // Determine whether descriptor counts are satisfiable
Jeff Bolze54ae892018-09-08 12:16:29 -05002196 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
2197 if (ds_data->required_descriptors_by_type.at(it->first) > pool_state->availableDescriptorTypeCount[it->first]) {
Lockeca0d9792019-03-03 23:48:13 -07002198 skip |= log_msg(
2199 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2200 HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorPool-00307",
locke-lunarg9edc2812019-06-17 23:18:52 -06002201 "Unable to allocate %u descriptors of type %s from %s"
Lockeca0d9792019-03-03 23:48:13 -07002202 ". This pool only has %d descriptors of this type remaining.",
2203 ds_data->required_descriptors_by_type.at(it->first), string_VkDescriptorType(VkDescriptorType(it->first)),
2204 report_data->FormatHandle(pool_state->pool).c_str(), pool_state->availableDescriptorTypeCount[it->first]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002205 }
Tobin Ehlisee471462016-05-26 11:21:59 -06002206 }
2207 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06002208
Jeff Bolzfdf96072018-04-10 14:32:18 -05002209 const auto *count_allocate_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext);
2210
2211 if (count_allocate_info) {
2212 if (count_allocate_info->descriptorSetCount != 0 &&
2213 count_allocate_info->descriptorSetCount != p_alloc_info->descriptorSetCount) {
2214 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, 0,
Dave Houltond8ed0212018-05-16 17:18:24 -06002215 "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-descriptorSetCount-03045",
Jeff Bolzfdf96072018-04-10 14:32:18 -05002216 "VkDescriptorSetAllocateInfo::descriptorSetCount (%d) != "
2217 "VkDescriptorSetVariableDescriptorCountAllocateInfoEXT::descriptorSetCount (%d)",
2218 p_alloc_info->descriptorSetCount, count_allocate_info->descriptorSetCount);
2219 }
2220 if (count_allocate_info->descriptorSetCount == p_alloc_info->descriptorSetCount) {
2221 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Mark Lobodzinski3840ca02019-03-08 18:36:11 -07002222 auto layout = GetDescriptorSetLayout(this, p_alloc_info->pSetLayouts[i]);
Jeff Bolzfdf96072018-04-10 14:32:18 -05002223 if (count_allocate_info->pDescriptorCounts[i] > layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())) {
2224 skip |= log_msg(
2225 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, 0,
Dave Houltond8ed0212018-05-16 17:18:24 -06002226 "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-pSetLayouts-03046",
2227 "pDescriptorCounts[%d] = (%d), binding's descriptorCount = (%d)", i,
Jeff Bolzfdf96072018-04-10 14:32:18 -05002228 count_allocate_info->pDescriptorCounts[i], layout->GetDescriptorCountFromBinding(layout->GetMaxBinding()));
2229 }
2230 }
2231 }
2232 }
2233
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002234 return skip;
Tobin Ehlisee471462016-05-26 11:21:59 -06002235}
2236// Decrement allocated sets from the pool and insert new sets into set_map
John Zulaufe3b35f32019-06-25 14:21:21 -06002237void ValidationStateTracker::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
2238 const VkDescriptorSet *descriptor_sets,
2239 const cvdescriptorset::AllocateDescriptorSetsData *ds_data) {
Mark Lobodzinskia33af952019-04-25 14:59:05 -06002240 auto pool_state = descriptorPoolMap[p_alloc_info->descriptorPool].get();
Mark Lobodzinskic9430182017-06-13 13:00:05 -06002241 // Account for sets and individual descriptors allocated from pool
Tobin Ehlisee471462016-05-26 11:21:59 -06002242 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Jeff Bolze54ae892018-09-08 12:16:29 -05002243 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
2244 pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06002245 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05002246
2247 const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext);
2248 bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount;
2249
Mark Lobodzinskic9430182017-06-13 13:00:05 -06002250 // Create tracking object for each descriptor set; insert into global map and the pool's set.
Tobin Ehlisee471462016-05-26 11:21:59 -06002251 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolzfdf96072018-04-10 14:32:18 -05002252 uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
2253
Mark Lobodzinski14112ab2019-04-25 15:29:34 -06002254 std::unique_ptr<cvdescriptorset::DescriptorSet> new_ds(new cvdescriptorset::DescriptorSet(
2255 descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i], variable_count, this));
2256 pool_state->sets.insert(new_ds.get());
Tobin Ehlisee471462016-05-26 11:21:59 -06002257 new_ds->in_use.store(0);
Mark Lobodzinski14112ab2019-04-25 15:29:34 -06002258 setMap[descriptor_sets[i]] = std::move(new_ds);
Tobin Ehlisee471462016-05-26 11:21:59 -06002259 }
2260}
John Zulauf48a6a702017-12-22 17:14:54 -07002261
2262cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map,
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06002263 CMD_BUFFER_STATE *cb_state)
John Zulauf48a6a702017-12-22 17:14:54 -07002264 : filtered_map_(), orig_map_(in_map) {
2265 if (ds.GetTotalDescriptorCount() > kManyDescriptors_) {
2266 filtered_map_.reset(new std::map<uint32_t, descriptor_req>());
2267 ds.FilterAndTrackBindingReqs(cb_state, orig_map_, filtered_map_.get());
2268 }
2269}
2270cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map,
Mark Lobodzinski33a34b82019-04-25 11:38:36 -06002271 CMD_BUFFER_STATE *cb_state, PIPELINE_STATE *pipeline)
John Zulauf48a6a702017-12-22 17:14:54 -07002272 : filtered_map_(), orig_map_(in_map) {
2273 if (ds.GetTotalDescriptorCount() > kManyDescriptors_) {
2274 filtered_map_.reset(new std::map<uint32_t, descriptor_req>());
2275 ds.FilterAndTrackBindingReqs(cb_state, pipeline, orig_map_, filtered_map_.get());
2276 }
Artem Kharytoniuk2456f992018-01-12 14:17:41 +01002277}
John Zulauf4a015c92019-06-04 09:50:05 -06002278
2279// Starting at offset descriptor of given binding, parse over update_count
2280// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
2281// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
2282// If so, return true. If not, fill in error_msg and return false
2283bool cvdescriptorset::VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator current_binding, uint32_t offset,
2284 uint32_t update_count, const char *type, const VkDescriptorSet set,
2285 std::string *error_msg) {
2286 // Verify consecutive bindings match (if needed)
2287 auto orig_binding = current_binding;
2288 // Track count of descriptors in the current_bindings that are remaining to be updated
2289 auto binding_remaining = current_binding.GetDescriptorCount();
2290 // First, it's legal to offset beyond your own binding so handle that case
2291 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
2292 while (offset >= binding_remaining && !current_binding.AtEnd()) {
2293 // Advance to next binding, decrement offset by binding size
2294 offset -= binding_remaining;
2295 ++current_binding;
2296 binding_remaining = current_binding.GetDescriptorCount(); // Accessors are safe if AtEnd
2297 }
2298 assert(!current_binding.AtEnd()); // As written assumes range check has been made before calling
2299 binding_remaining -= offset;
2300 while (update_count > binding_remaining) { // While our updates overstep current binding
2301 // Verify next consecutive binding matches type, stage flags & immutable sampler use
2302 auto next_binding = current_binding.Next();
2303 if (!current_binding.IsConsistent(next_binding)) {
2304 std::stringstream error_str;
2305 error_str << "Attempting " << type;
2306 if (current_binding.Layout()->IsPushDescriptor()) {
2307 error_str << " push descriptors";
2308 } else {
2309 error_str << " descriptor set " << set;
2310 }
2311 error_str << " binding #" << orig_binding.Binding() << " with #" << update_count
2312 << " descriptors being updated but this update oversteps the bounds of this binding and the next binding is "
2313 "not consistent with current binding so this update is invalid.";
2314 *error_msg = error_str.str();
2315 return false;
2316 }
2317 current_binding = next_binding;
2318 // For sake of this check consider the bindings updated and grab count for next binding
2319 update_count -= binding_remaining;
2320 binding_remaining = current_binding.GetDescriptorCount();
2321 }
2322 return true;
2323}
John Zulauf4956fff2019-06-04 16:54:38 -06002324
2325// Validate the state for a given write update but don't actually perform the update
2326// If an error would occur for this update, return false and fill in details in error_msg string
John Zulaufc93c4252019-06-25 09:19:49 -06002327bool CoreChecks::ValidateWriteUpdate(const DescriptorSet *dest_set, const VkWriteDescriptorSet *update, const char *func_name,
2328 std::string *error_code, std::string *error_msg) {
John Zulauf4956fff2019-06-04 16:54:38 -06002329 const auto dest_layout = dest_set->GetLayout();
2330
2331 // Verify dst layout still valid
2332 if (dest_layout->IsDestroyed()) {
2333 *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320";
2334 string_sprintf(error_msg, "Cannot call %s to perform write update on %s which has been destroyed", func_name,
2335 dest_set->StringifySetAndLayout().c_str());
2336 return false;
2337 }
2338 // Verify dst binding exists
2339 if (!dest_layout->HasBinding(update->dstBinding)) {
2340 *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315";
2341 std::stringstream error_str;
2342 error_str << dest_set->StringifySetAndLayout() << " does not have binding " << update->dstBinding;
2343 *error_msg = error_str.str();
2344 return false;
2345 }
2346
2347 DescriptorSetLayout::ConstBindingIterator dest(dest_layout.get(), update->dstBinding);
2348 // Make sure binding isn't empty
2349 if (0 == dest.GetDescriptorCount()) {
2350 *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316";
2351 std::stringstream error_str;
2352 error_str << dest_set->StringifySetAndLayout() << " cannot updated binding " << update->dstBinding
2353 << " that has 0 descriptors";
2354 *error_msg = error_str.str();
2355 return false;
2356 }
2357
2358 // Verify idle ds
2359 if (dest_set->in_use.load() && !(dest.GetDescriptorBindingFlags() & (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
2360 VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
2361 // TODO : Re-using Free Idle error code, need write update idle error code
2362 *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
2363 std::stringstream error_str;
2364 error_str << "Cannot call " << func_name << " to perform write update on " << dest_set->StringifySetAndLayout()
2365 << " that is in use by a command buffer";
2366 *error_msg = error_str.str();
2367 return false;
2368 }
2369 // We know that binding is valid, verify update and do update on each descriptor
2370 auto start_idx = dest.GetGlobalIndexRange().start + update->dstArrayElement;
2371 auto type = dest.GetType();
2372 if (type != update->descriptorType) {
2373 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319";
2374 std::stringstream error_str;
2375 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2376 << " with type " << string_VkDescriptorType(type) << " but update type is "
2377 << string_VkDescriptorType(update->descriptorType);
2378 *error_msg = error_str.str();
2379 return false;
2380 }
2381 auto total_descriptors = dest_layout->GetTotalDescriptorCount();
2382 if (update->descriptorCount > (total_descriptors - start_idx)) {
2383 *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
2384 std::stringstream error_str;
2385 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2386 << " with " << total_descriptors - start_idx
2387 << " descriptors in that binding and all successive bindings of the set, but update of "
2388 << update->descriptorCount << " descriptors combined with update array element offset of "
2389 << update->dstArrayElement << " oversteps the available number of consecutive descriptors";
2390 *error_msg = error_str.str();
2391 return false;
2392 }
2393 if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
2394 if ((update->dstArrayElement % 4) != 0) {
2395 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219";
2396 std::stringstream error_str;
2397 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2398 << " with "
2399 << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
2400 *error_msg = error_str.str();
2401 return false;
2402 }
2403 if ((update->descriptorCount % 4) != 0) {
2404 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220";
2405 std::stringstream error_str;
2406 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2407 << " with "
2408 << "descriptorCount " << update->descriptorCount << " not a multiple of 4";
2409 *error_msg = error_str.str();
2410 return false;
2411 }
2412 const auto *write_inline_info = lvl_find_in_chain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext);
2413 if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) {
2414 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221";
2415 std::stringstream error_str;
2416 if (!write_inline_info) {
2417 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
2418 << update->dstBinding << " with "
2419 << "VkWriteDescriptorSetInlineUniformBlockEXT missing";
2420 } else {
2421 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
2422 << update->dstBinding << " with "
2423 << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
2424 << " not equal to "
2425 << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount;
2426 }
2427 *error_msg = error_str.str();
2428 return false;
2429 }
2430 // This error is probably unreachable due to the previous two errors
2431 if (write_inline_info && (write_inline_info->dataSize % 4) != 0) {
2432 *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222";
2433 std::stringstream error_str;
2434 error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2435 << " with "
2436 << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
2437 << " not a multiple of 4";
2438 *error_msg = error_str.str();
2439 return false;
2440 }
2441 }
2442 // Verify consecutive bindings match (if needed)
2443 if (!VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator(dest_layout.get(), update->dstBinding),
2444 update->dstArrayElement, update->descriptorCount, "write update to", dest_set->GetSet(),
2445 error_msg)) {
2446 // TODO : Should break out "consecutive binding updates" language into valid usage statements
2447 *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
2448 return false;
2449 }
2450 // Update is within bounds and consistent so last step is to validate update contents
John Zulauf459939f2019-06-04 16:49:35 -06002451 if (!VerifyWriteUpdateContents(dest_set, update, start_idx, func_name, error_code, error_msg)) {
John Zulauf4956fff2019-06-04 16:54:38 -06002452 std::stringstream error_str;
2453 error_str << "Write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
2454 << " failed with error message: " << error_msg->c_str();
2455 *error_msg = error_str.str();
2456 return false;
2457 }
2458 // All checks passed, update is clean
2459 return true;
2460}
John Zulaufadb3f542019-06-04 17:01:00 -06002461
2462// Verify that the contents of the update are ok, but don't perform actual update
John Zulaufc93c4252019-06-25 09:19:49 -06002463bool CoreChecks::VerifyWriteUpdateContents(const DescriptorSet *dest_set, const VkWriteDescriptorSet *update, const uint32_t index,
2464 const char *func_name, std::string *error_code, std::string *error_msg) {
2465 using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor;
2466 using SamplerDescriptor = cvdescriptorset::SamplerDescriptor;
2467
John Zulaufadb3f542019-06-04 17:01:00 -06002468 switch (update->descriptorType) {
2469 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
2470 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2471 // Validate image
2472 auto image_view = update->pImageInfo[di].imageView;
2473 auto image_layout = update->pImageInfo[di].imageLayout;
John Zulaufc93c4252019-06-25 09:19:49 -06002474 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, func_name, error_code, error_msg)) {
John Zulaufadb3f542019-06-04 17:01:00 -06002475 std::stringstream error_str;
2476 error_str << "Attempted write update to combined image sampler descriptor failed due to: "
2477 << error_msg->c_str();
2478 *error_msg = error_str.str();
2479 return false;
2480 }
John Zulaufc93c4252019-06-25 09:19:49 -06002481 if (device_extensions.vk_khr_sampler_ycbcr_conversion) {
John Zulaufadb3f542019-06-04 17:01:00 -06002482 ImageSamplerDescriptor *desc = (ImageSamplerDescriptor *)dest_set->GetDescriptorFromGlobalIndex(index + di);
2483 if (desc->IsImmutableSampler()) {
John Zulaufc93c4252019-06-25 09:19:49 -06002484 auto sampler_state = GetSamplerState(desc->GetSampler());
2485 auto iv_state = GetImageViewState(image_view);
John Zulaufadb3f542019-06-04 17:01:00 -06002486 if (iv_state && sampler_state) {
2487 if (iv_state->samplerConversion != sampler_state->samplerConversion) {
2488 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-01948";
2489 std::stringstream error_str;
2490 error_str << "Attempted write update to combined image sampler and image view and sampler ycbcr "
2491 "conversions are not identical, sampler: "
2492 << desc->GetSampler() << " image view: " << iv_state->image_view << ".";
2493 *error_msg = error_str.str();
2494 return false;
2495 }
2496 }
2497 } else {
John Zulaufc93c4252019-06-25 09:19:49 -06002498 auto iv_state = GetImageViewState(image_view);
John Zulaufadb3f542019-06-04 17:01:00 -06002499 if (iv_state && (iv_state->samplerConversion != VK_NULL_HANDLE)) {
Shannon McPhersonf7d9cf62019-06-26 09:23:57 -06002500 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02738";
John Zulaufadb3f542019-06-04 17:01:00 -06002501 std::stringstream error_str;
2502 error_str << "Because dstSet (" << update->dstSet << ") is bound to image view ("
2503 << iv_state->image_view
2504 << ") that includes a YCBCR conversion, it must have been allocated with a layout that "
2505 "includes an immutable sampler.";
2506 *error_msg = error_str.str();
2507 return false;
2508 }
2509 }
2510 }
2511 }
2512 }
2513 // fall through
2514 case VK_DESCRIPTOR_TYPE_SAMPLER: {
2515 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2516 SamplerDescriptor *desc = (SamplerDescriptor *)dest_set->GetDescriptorFromGlobalIndex(index + di);
2517 if (!desc->IsImmutableSampler()) {
John Zulaufc93c4252019-06-25 09:19:49 -06002518 if (!ValidateSampler(update->pImageInfo[di].sampler)) {
John Zulaufadb3f542019-06-04 17:01:00 -06002519 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
2520 std::stringstream error_str;
2521 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
2522 << update->pImageInfo[di].sampler << ".";
2523 *error_msg = error_str.str();
2524 return false;
2525 }
2526 } else {
2527 // TODO : Warn here
2528 }
2529 }
2530 break;
2531 }
2532 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2533 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2534 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
2535 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2536 auto image_view = update->pImageInfo[di].imageView;
2537 auto image_layout = update->pImageInfo[di].imageLayout;
John Zulaufc93c4252019-06-25 09:19:49 -06002538 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, func_name, error_code, error_msg)) {
John Zulaufadb3f542019-06-04 17:01:00 -06002539 std::stringstream error_str;
2540 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
2541 *error_msg = error_str.str();
2542 return false;
2543 }
2544 }
2545 break;
2546 }
2547 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2548 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
2549 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2550 auto buffer_view = update->pTexelBufferView[di];
John Zulaufc93c4252019-06-25 09:19:49 -06002551 auto bv_state = GetBufferViewState(buffer_view);
John Zulaufadb3f542019-06-04 17:01:00 -06002552 if (!bv_state) {
2553 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
2554 std::stringstream error_str;
2555 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
2556 *error_msg = error_str.str();
2557 return false;
2558 }
2559 auto buffer = bv_state->create_info.buffer;
John Zulaufc93c4252019-06-25 09:19:49 -06002560 auto buffer_state = GetBufferState(buffer);
John Zulaufadb3f542019-06-04 17:01:00 -06002561 // Verify that buffer underlying the view hasn't been destroyed prematurely
2562 if (!buffer_state) {
2563 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
2564 std::stringstream error_str;
2565 error_str << "Attempted write update to texel buffer descriptor failed because underlying buffer (" << buffer
2566 << ") has been destroyed: " << error_msg->c_str();
2567 *error_msg = error_str.str();
2568 return false;
John Zulaufc93c4252019-06-25 09:19:49 -06002569 } else if (!cvdescriptorset::ValidateBufferUsage(buffer_state, update->descriptorType, error_code, error_msg)) {
John Zulaufadb3f542019-06-04 17:01:00 -06002570 std::stringstream error_str;
2571 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
2572 *error_msg = error_str.str();
2573 return false;
2574 }
2575 }
2576 break;
2577 }
2578 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2579 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2580 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2581 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
2582 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
John Zulaufc93c4252019-06-25 09:19:49 -06002583 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, func_name, error_code, error_msg)) {
John Zulaufadb3f542019-06-04 17:01:00 -06002584 std::stringstream error_str;
2585 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
2586 *error_msg = error_str.str();
2587 return false;
2588 }
2589 }
2590 break;
2591 }
2592 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
2593 break;
2594 case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
2595 // XXX TODO
2596 break;
2597 default:
2598 assert(0); // We've already verified update type so should never get here
2599 break;
2600 }
2601 // All checks passed so update contents are good
2602 return true;
2603}