blob: c8b2552a19fb1c24dd4a96b870c07710b3c5d1d0 [file] [log] [blame]
Dave Houlton51653902018-06-22 17:32:13 -06001/* Copyright (c) 2015-2018 The Khronos Group Inc.
2 * Copyright (c) 2015-2018 Valve Corporation
3 * Copyright (c) 2015-2018 LunarG, Inc.
4 * Copyright (C) 2015-2018 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
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060025#include "descriptor_sets.h"
John Zulaufd47d0612018-02-16 13:00:34 -070026#include "hash_vk_types.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060027#include "vk_enum_string_helper.h"
28#include "vk_safe_struct.h"
Jeff Bolzfdf96072018-04-10 14:32:18 -050029#include "vk_typemap_helper.h"
Tobin Ehlisc8266452017-04-07 12:20:30 -060030#include "buffer_validation.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060031#include <sstream>
Mark Lobodzinski2eee5d82016-12-02 15:33:18 -070032#include <algorithm>
John Zulauf1f8174b2018-02-16 12:58:37 -070033#include <memory>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060034
Jeff Bolzfdf96072018-04-10 14:32:18 -050035// ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended
36// state that comes from a different array/structure so they can stay together
37// while being sorted by binding number.
38struct ExtendedBinding {
39 ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlagsEXT f) : layout_binding(l), binding_flags(f) {}
40
41 const VkDescriptorSetLayoutBinding *layout_binding;
42 VkDescriptorBindingFlagsEXT binding_flags;
43};
44
John Zulauf508d13a2018-01-05 15:10:34 -070045struct BindingNumCmp {
Jeff Bolzfdf96072018-04-10 14:32:18 -050046 bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const {
47 return a.layout_binding->binding < b.layout_binding->binding;
John Zulauf508d13a2018-01-05 15:10:34 -070048 }
49};
50
John Zulaufd47d0612018-02-16 13:00:34 -070051using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef;
52using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId;
53
John Zulauf34ebf272018-02-16 13:08:47 -070054// Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information)
55cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict;
John Zulaufd47d0612018-02-16 13:00:34 -070056
Shannon McPhersonc06c33d2018-06-28 17:21:12 -060057DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) {
John Zulauf34ebf272018-02-16 13:08:47 -070058 return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info));
John Zulaufd47d0612018-02-16 13:00:34 -070059}
John Zulauf34ebf272018-02-16 13:08:47 -070060
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060061// Construct DescriptorSetLayout instance from given create info
John Zulauf48a6a702017-12-22 17:14:54 -070062// Proactively reserve and resize as possible, as the reallocation was visible in profiling
John Zulauf1f8174b2018-02-16 12:58:37 -070063cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info)
64 : flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) {
Jeff Bolzfdf96072018-04-10 14:32:18 -050065 const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(p_create_info->pNext);
66
John Zulauf48a6a702017-12-22 17:14:54 -070067 binding_type_stats_ = {0, 0, 0};
Jeff Bolzfdf96072018-04-10 14:32:18 -050068 std::set<ExtendedBinding, BindingNumCmp> sorted_bindings;
John Zulauf508d13a2018-01-05 15:10:34 -070069 const uint32_t input_bindings_count = p_create_info->bindingCount;
70 // Sort the input bindings in binding number order, eliminating duplicates
71 for (uint32_t i = 0; i < input_bindings_count; i++) {
Jeff Bolzfdf96072018-04-10 14:32:18 -050072 VkDescriptorBindingFlagsEXT flags = 0;
73 if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) {
74 flags = flags_create_info->pBindingFlags[i];
75 }
76 sorted_bindings.insert(ExtendedBinding(p_create_info->pBindings + i, flags));
John Zulaufb6d71202017-12-22 16:47:09 -070077 }
78
79 // Store the create info in the sorted order from above
Tobin Ehlisa3525e02016-11-17 10:50:52 -070080 std::map<uint32_t, uint32_t> binding_to_dyn_count;
John Zulauf508d13a2018-01-05 15:10:34 -070081 uint32_t index = 0;
82 binding_count_ = static_cast<uint32_t>(sorted_bindings.size());
83 bindings_.reserve(binding_count_);
Jeff Bolzfdf96072018-04-10 14:32:18 -050084 binding_flags_.reserve(binding_count_);
John Zulauf508d13a2018-01-05 15:10:34 -070085 binding_to_index_map_.reserve(binding_count_);
86 for (auto input_binding : sorted_bindings) {
87 // Add to binding and map, s.t. it is robust to invalid duplication of binding_num
Jeff Bolzfdf96072018-04-10 14:32:18 -050088 const auto binding_num = input_binding.layout_binding->binding;
John Zulauf508d13a2018-01-05 15:10:34 -070089 binding_to_index_map_[binding_num] = index++;
Jeff Bolzfdf96072018-04-10 14:32:18 -050090 bindings_.emplace_back(input_binding.layout_binding);
John Zulauf508d13a2018-01-05 15:10:34 -070091 auto &binding_info = bindings_.back();
Jeff Bolzfdf96072018-04-10 14:32:18 -050092 binding_flags_.emplace_back(input_binding.binding_flags);
John Zulauf508d13a2018-01-05 15:10:34 -070093
John Zulaufb6d71202017-12-22 16:47:09 -070094 descriptor_count_ += binding_info.descriptorCount;
95 if (binding_info.descriptorCount > 0) {
96 non_empty_bindings_.insert(binding_num);
Tobin Ehlis9637fb22016-12-12 15:59:34 -070097 }
John Zulaufb6d71202017-12-22 16:47:09 -070098
99 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
100 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
101 binding_to_dyn_count[binding_num] = binding_info.descriptorCount;
102 dynamic_descriptor_count_ += binding_info.descriptorCount;
John Zulauf48a6a702017-12-22 17:14:54 -0700103 binding_type_stats_.dynamic_buffer_count++;
104 } else if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
105 (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) {
106 binding_type_stats_.non_dynamic_buffer_count++;
107 } else {
108 binding_type_stats_.image_sampler_count++;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600109 }
110 }
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700111 assert(bindings_.size() == binding_count_);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500112 assert(binding_flags_.size() == binding_count_);
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700113 uint32_t global_index = 0;
John Zulaufb6d71202017-12-22 16:47:09 -0700114 binding_to_global_index_range_map_.reserve(binding_count_);
115 // Vector order is finalized so create maps of bindings to descriptors and descriptors to indices
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700116 for (uint32_t i = 0; i < binding_count_; ++i) {
117 auto binding_num = bindings_[i].binding;
John Zulaufc483f442017-12-15 14:02:06 -0700118 auto final_index = global_index + bindings_[i].descriptorCount;
119 binding_to_global_index_range_map_[binding_num] = IndexRange(global_index, final_index);
John Zulaufb6d71202017-12-22 16:47:09 -0700120 if (final_index != global_index) {
121 global_start_to_index_map_[global_index] = i;
122 }
John Zulaufc483f442017-12-15 14:02:06 -0700123 global_index = final_index;
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700124 }
John Zulaufb6d71202017-12-22 16:47:09 -0700125
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700126 // Now create dyn offset array mapping for any dynamic descriptors
127 uint32_t dyn_array_idx = 0;
John Zulaufb6d71202017-12-22 16:47:09 -0700128 binding_to_dynamic_array_idx_map_.reserve(binding_to_dyn_count.size());
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700129 for (const auto &bc_pair : binding_to_dyn_count) {
130 binding_to_dynamic_array_idx_map_[bc_pair.first] = dyn_array_idx;
131 dyn_array_idx += bc_pair.second;
132 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600133}
Tobin Ehlis154c2692016-10-25 09:36:53 -0600134
John Zulaufd47d0612018-02-16 13:00:34 -0700135size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const {
136 hash_util::HashCombiner hc;
137 hc << flags_;
138 hc.Combine(bindings_);
139 return hc.Value();
140}
141//
142
John Zulauf1f8174b2018-02-16 12:58:37 -0700143// Return valid index or "end" i.e. binding_count_;
144// The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given
145// Common code for all binding lookups.
146uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const {
147 const auto &bi_itr = binding_to_index_map_.find(binding);
148 if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second;
149 return GetBindingCount();
150}
151VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex(
152 const uint32_t index) const {
153 if (index >= bindings_.size()) return nullptr;
154 return bindings_[index].ptr();
155}
156// Return descriptorCount for given index, 0 if index is unavailable
157uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const {
158 if (index >= bindings_.size()) return 0;
159 return bindings_[index].descriptorCount;
160}
161// For the given index, return descriptorType
162VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const {
163 assert(index < bindings_.size());
164 if (index < bindings_.size()) return bindings_[index].descriptorType;
165 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
166}
167// For the given index, return stageFlags
168VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const {
169 assert(index < bindings_.size());
170 if (index < bindings_.size()) return bindings_[index].stageFlags;
171 return VkShaderStageFlags(0);
172}
Jeff Bolzfdf96072018-04-10 14:32:18 -0500173// Return binding flags for given index, 0 if index is unavailable
174VkDescriptorBindingFlagsEXT cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex(
175 const uint32_t index) const {
176 if (index >= binding_flags_.size()) return 0;
177 return binding_flags_[index];
178}
John Zulauf1f8174b2018-02-16 12:58:37 -0700179
180// For the given global index, return index
181uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromGlobalIndex(const uint32_t global_index) const {
182 auto start_it = global_start_to_index_map_.upper_bound(global_index);
183 uint32_t index = binding_count_;
184 assert(start_it != global_start_to_index_map_.cbegin());
185 if (start_it != global_start_to_index_map_.cbegin()) {
186 --start_it;
187 index = start_it->second;
188#ifndef NDEBUG
189 const auto &range = GetGlobalIndexRangeFromBinding(bindings_[index].binding);
190 assert(range.start <= global_index && global_index < range.end);
191#endif
192 }
193 return index;
194}
195
196// For the given binding, return the global index range
197// As start and end are often needed in pairs, get both with a single hash lookup.
198const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding(
199 const uint32_t binding) const {
200 assert(binding_to_global_index_range_map_.count(binding));
201 // In error case max uint32_t so index is out of bounds to break ASAP
202 const static IndexRange kInvalidRange = {0xFFFFFFFF, 0xFFFFFFFF};
203 const auto &range_it = binding_to_global_index_range_map_.find(binding);
204 if (range_it != binding_to_global_index_range_map_.end()) {
205 return range_it->second;
206 }
207 return kInvalidRange;
208}
209
210// For given binding, return ptr to ImmutableSampler array
211VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
212 const auto &bi_itr = binding_to_index_map_.find(binding);
213 if (bi_itr != binding_to_index_map_.end()) {
214 return bindings_[bi_itr->second].pImmutableSamplers;
215 }
216 return nullptr;
217}
218// Move to next valid binding having a non-zero binding count
219uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const {
220 auto it = non_empty_bindings_.upper_bound(binding);
221 assert(it != non_empty_bindings_.cend());
222 if (it != non_empty_bindings_.cend()) return *it;
223 return GetMaxBinding() + 1;
224}
225// For given index, return ptr to ImmutableSampler array
226VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
227 if (index < bindings_.size()) {
228 return bindings_[index].pImmutableSamplers;
229 }
230 return nullptr;
231}
232// If our layout is compatible with rh_ds_layout, return true,
233// else return false and fill in error_msg will description of what causes incompatibility
234bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *const rh_ds_layout,
235 std::string *error_msg) const {
236 // Trivial case
237 if (layout_ == rh_ds_layout->GetDescriptorSetLayout()) return true;
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600238 if (GetLayoutDef() == rh_ds_layout->GetLayoutDef()) return true;
John Zulaufd47d0612018-02-16 13:00:34 -0700239 bool detailed_compat_check =
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600240 GetLayoutDef()->IsCompatible(layout_, rh_ds_layout->GetDescriptorSetLayout(), rh_ds_layout->GetLayoutDef(), error_msg);
John Zulaufd47d0612018-02-16 13:00:34 -0700241 // The detailed check should never tell us mismatching DSL are compatible
242 assert(!detailed_compat_check);
243 return detailed_compat_check;
John Zulauf1f8174b2018-02-16 12:58:37 -0700244}
245
John Zulaufdf3c5c12018-03-06 16:44:43 -0700246// Do a detailed compatibility check of this def (referenced by ds_layout), vs. the rhs (layout and def)
247// Should only be called if trivial accept has failed, and in that context should return false.
John Zulauf1f8174b2018-02-16 12:58:37 -0700248bool cvdescriptorset::DescriptorSetLayoutDef::IsCompatible(VkDescriptorSetLayout ds_layout, VkDescriptorSetLayout rh_ds_layout,
249 DescriptorSetLayoutDef const *const rh_ds_layout_def,
250 std::string *error_msg) const {
251 if (descriptor_count_ != rh_ds_layout_def->descriptor_count_) {
252 std::stringstream error_str;
253 error_str << "DescriptorSetLayout " << ds_layout << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
254 << rh_ds_layout << ", which comes from pipelineLayout, has " << rh_ds_layout_def->descriptor_count_
255 << " descriptors.";
256 *error_msg = error_str.str();
257 return false; // trivial fail case
258 }
John Zulaufd47d0612018-02-16 13:00:34 -0700259
John Zulauf1f8174b2018-02-16 12:58:37 -0700260 // Descriptor counts match so need to go through bindings one-by-one
261 // and verify that type and stageFlags match
262 for (auto binding : bindings_) {
263 // TODO : Do we also need to check immutable samplers?
264 // VkDescriptorSetLayoutBinding *rh_binding;
265 if (binding.descriptorCount != rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding)) {
266 std::stringstream error_str;
267 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " has a descriptorCount of "
268 << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout "
269 << rh_ds_layout << ", which comes from pipelineLayout, has a descriptorCount of "
270 << rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding);
271 *error_msg = error_str.str();
272 return false;
273 } else if (binding.descriptorType != rh_ds_layout_def->GetTypeFromBinding(binding.binding)) {
274 std::stringstream error_str;
275 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " is type '"
276 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
277 << " for DescriptorSetLayout " << rh_ds_layout << ", which comes from pipelineLayout, is type '"
278 << string_VkDescriptorType(rh_ds_layout_def->GetTypeFromBinding(binding.binding)) << "'";
279 *error_msg = error_str.str();
280 return false;
281 } else if (binding.stageFlags != rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding)) {
282 std::stringstream error_str;
283 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " has stageFlags "
284 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " << rh_ds_layout
285 << ", which comes from pipelineLayout, has stageFlags "
286 << rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding);
287 *error_msg = error_str.str();
288 return false;
289 }
290 }
291 return true;
292}
293
294bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const {
295 if (!binding_to_index_map_.count(binding + 1)) return false;
296 auto const &bi_itr = binding_to_index_map_.find(binding);
297 if (bi_itr != binding_to_index_map_.end()) {
298 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
299 if (next_bi_itr != binding_to_index_map_.end()) {
300 auto type = bindings_[bi_itr->second].descriptorType;
301 auto stage_flags = bindings_[bi_itr->second].stageFlags;
302 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
Jeff Bolzfdf96072018-04-10 14:32:18 -0500303 auto flags = binding_flags_[bi_itr->second];
John Zulauf1f8174b2018-02-16 12:58:37 -0700304 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
305 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
Jeff Bolzfdf96072018-04-10 14:32:18 -0500306 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) ||
307 (flags != binding_flags_[next_bi_itr->second])) {
John Zulauf1f8174b2018-02-16 12:58:37 -0700308 return false;
309 }
310 return true;
311 }
312 }
313 return false;
314}
315// Starting at offset descriptor of given binding, parse over update_count
316// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
317// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
318// If so, return true. If not, fill in error_msg and return false
319bool cvdescriptorset::DescriptorSetLayoutDef::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset,
320 uint32_t update_count, const char *type,
321 const VkDescriptorSet set, std::string *error_msg) const {
322 // Verify consecutive bindings match (if needed)
323 auto orig_binding = current_binding;
324 // Track count of descriptors in the current_bindings that are remaining to be updated
325 auto binding_remaining = GetDescriptorCountFromBinding(current_binding);
326 // First, it's legal to offset beyond your own binding so handle that case
327 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
328 while (offset >= binding_remaining) {
329 // Advance to next binding, decrement offset by binding size
330 offset -= binding_remaining;
331 binding_remaining = GetDescriptorCountFromBinding(++current_binding);
332 }
333 binding_remaining -= offset;
334 while (update_count > binding_remaining) { // While our updates overstep current binding
335 // Verify next consecutive binding matches type, stage flags & immutable sampler use
336 if (!IsNextBindingConsistent(current_binding++)) {
337 std::stringstream error_str;
338 error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #"
339 << update_count
340 << " descriptors being updated but this update oversteps the bounds of this binding and the next binding is "
341 "not consistent with current binding so this update is invalid.";
342 *error_msg = error_str.str();
343 return false;
344 }
345 // For sake of this check consider the bindings updated and grab count for next binding
346 update_count -= binding_remaining;
347 binding_remaining = GetDescriptorCountFromBinding(current_binding);
348 }
349 return true;
350}
351
352// The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the
353// handle invariant portion
354cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info,
355 const VkDescriptorSetLayout layout)
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600356 : layout_(layout), layout_destroyed_(false), layout_id_(GetCanonicalId(p_create_info)) {}
John Zulauf1f8174b2018-02-16 12:58:37 -0700357
Tobin Ehlis154c2692016-10-25 09:36:53 -0600358// Validate descriptor set layout create info
Jeff Bolzfdf96072018-04-10 14:32:18 -0500359bool cvdescriptorset::DescriptorSetLayout::ValidateCreateInfo(
360 const debug_report_data *report_data, const VkDescriptorSetLayoutCreateInfo *create_info, const bool push_descriptor_ext,
361 const uint32_t max_push_descriptors, const bool descriptor_indexing_ext,
Jeff Bolze54ae892018-09-08 12:16:29 -0500362 const VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features,
363 const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features,
364 const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props) {
Tobin Ehlis154c2692016-10-25 09:36:53 -0600365 bool skip = false;
366 std::unordered_set<uint32_t> bindings;
John Zulauf0fdeab32018-01-23 11:27:35 -0700367 uint64_t total_descriptors = 0;
368
Jeff Bolzfdf96072018-04-10 14:32:18 -0500369 const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(create_info->pNext);
370
371 const bool push_descriptor_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
John Zulauf0fdeab32018-01-23 11:27:35 -0700372 if (push_descriptor_set && !push_descriptor_ext) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600373 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 -0600374 kVUID_Core_DrawState_ExtensionNotEnabled,
Mark Lobodzinskifb5a3e62018-04-13 10:46:48 -0600375 "Attempted to use %s in %s but its required extension %s has not been enabled.\n",
John Zulauf0fdeab32018-01-23 11:27:35 -0700376 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR", "VkDescriptorSetLayoutCreateInfo::flags",
377 VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
378 }
379
Jeff Bolzfdf96072018-04-10 14:32:18 -0500380 const bool update_after_bind_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT);
381 if (update_after_bind_set && !descriptor_indexing_ext) {
382 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 -0600383 kVUID_Core_DrawState_ExtensionNotEnabled,
Jeff Bolzfdf96072018-04-10 14:32:18 -0500384 "Attemped to use %s in %s but its required extension %s has not been enabled.\n",
385 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT", "VkDescriptorSetLayoutCreateInfo::flags",
386 VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME);
387 }
388
John Zulauf0fdeab32018-01-23 11:27:35 -0700389 auto valid_type = [push_descriptor_set](const VkDescriptorType type) {
390 return !push_descriptor_set ||
Jeff Bolze54ae892018-09-08 12:16:29 -0500391 ((type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) &&
392 (type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) &&
393 (type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT));
John Zulauf0fdeab32018-01-23 11:27:35 -0700394 };
395
Jeff Bolzfdf96072018-04-10 14:32:18 -0500396 uint32_t max_binding = 0;
397
Tobin Ehlis154c2692016-10-25 09:36:53 -0600398 for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
John Zulauf0fdeab32018-01-23 11:27:35 -0700399 const auto &binding_info = create_info->pBindings[i];
Jeff Bolzfdf96072018-04-10 14:32:18 -0500400 max_binding = std::max(max_binding, binding_info.binding);
401
John Zulauf0fdeab32018-01-23 11:27:35 -0700402 if (!bindings.insert(binding_info.binding).second) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600403 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 -0600404 "VUID-VkDescriptorSetLayoutCreateInfo-binding-00279",
405 "duplicated binding number in VkDescriptorSetLayoutBinding.");
Tobin Ehlis154c2692016-10-25 09:36:53 -0600406 }
John Zulauf0fdeab32018-01-23 11:27:35 -0700407 if (!valid_type(binding_info.descriptorType)) {
Mark Lobodzinskib1fd9d12018-03-30 14:26:00 -0600408 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Jeff Bolze54ae892018-09-08 12:16:29 -0500409 (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) ?
410 "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208" :
411 "VUID-VkDescriptorSetLayoutCreateInfo-flags-00280",
Mark Lobodzinski487a0d12018-03-30 10:09:03 -0600412 "invalid type %s ,for push descriptors in VkDescriptorSetLayoutBinding entry %" PRIu32 ".",
413 string_VkDescriptorType(binding_info.descriptorType), i);
John Zulauf0fdeab32018-01-23 11:27:35 -0700414 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500415
416 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
417 if ((binding_info.descriptorCount % 4) != 0) {
418 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
419 "VUID-VkDescriptorSetLayoutBinding-descriptorType-02209",
420 "descriptorCount =(%" PRIu32 ") must be a multiple of 4",
421 binding_info.descriptorCount);
422 }
423 if (binding_info.descriptorCount > inline_uniform_block_props->maxInlineUniformBlockSize) {
424 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
425 "VUID-VkDescriptorSetLayoutBinding-descriptorType-02210",
426 "descriptorCount =(%" PRIu32 ") must be less than or equal to maxInlineUniformBlockSize",
427 binding_info.descriptorCount);
428 }
429 }
430
John Zulauf0fdeab32018-01-23 11:27:35 -0700431 total_descriptors += binding_info.descriptorCount;
Tobin Ehlis154c2692016-10-25 09:36:53 -0600432 }
John Zulauf0fdeab32018-01-23 11:27:35 -0700433
Jeff Bolzfdf96072018-04-10 14:32:18 -0500434 if (flags_create_info) {
435 if (flags_create_info->bindingCount != 0 && flags_create_info->bindingCount != create_info->bindingCount) {
436 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 -0600437 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-bindingCount-03002",
Jeff Bolzfdf96072018-04-10 14:32:18 -0500438 "VkDescriptorSetLayoutCreateInfo::bindingCount (%d) != "
439 "VkDescriptorSetLayoutBindingFlagsCreateInfoEXT::bindingCount (%d)",
440 create_info->bindingCount, flags_create_info->bindingCount);
441 }
442
443 if (flags_create_info->bindingCount == create_info->bindingCount) {
444 for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
445 const auto &binding_info = create_info->pBindings[i];
446
447 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT) {
448 if (!update_after_bind_set) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600449 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
450 "VUID-VkDescriptorSetLayoutCreateInfo-flags-03000",
451 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500452 }
453
454 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER &&
455 !descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind) {
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-"
458 "descriptorBindingUniformBufferUpdateAfterBind-03005",
459 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500460 }
461 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER ||
462 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ||
463 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) &&
464 !descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600465 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
466 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
467 "descriptorBindingSampledImageUpdateAfterBind-03006",
468 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500469 }
470 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
471 !descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600472 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
473 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
474 "descriptorBindingStorageImageUpdateAfterBind-03007",
475 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500476 }
477 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER &&
478 !descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600479 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
480 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
481 "descriptorBindingStorageBufferUpdateAfterBind-03008",
482 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500483 }
484 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER &&
485 !descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600486 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
487 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
488 "descriptorBindingUniformTexelBufferUpdateAfterBind-03009",
489 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500490 }
491 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER &&
492 !descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600493 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
494 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-"
495 "descriptorBindingStorageTexelBufferUpdateAfterBind-03010",
496 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500497 }
498 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT ||
499 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
500 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600501 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
502 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-None-03011",
503 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500504 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500505
506 if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT &&
507 !inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind) {
508 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
509 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingInlineUniformBlockUpdateAfterBind-02211",
510 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
511 }
Jeff Bolzfdf96072018-04-10 14:32:18 -0500512 }
513
514 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT) {
515 if (!descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600516 skip |= log_msg(
517 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
518 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingUpdateUnusedWhilePending-03012",
519 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500520 }
521 }
522
523 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT) {
524 if (!descriptor_indexing_features->descriptorBindingPartiallyBound) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600525 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
526 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingPartiallyBound-03013",
527 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500528 }
529 }
530
531 if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT) {
532 if (binding_info.binding != max_binding) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600533 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
534 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03004",
535 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500536 }
537
538 if (!descriptor_indexing_features->descriptorBindingVariableDescriptorCount) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600539 skip |= log_msg(
540 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
541 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingVariableDescriptorCount-03014",
542 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500543 }
544 if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
545 binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dave Houltond8ed0212018-05-16 17:18:24 -0600546 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
547 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03015",
548 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500549 }
550 }
551
552 if (push_descriptor_set &&
553 (flags_create_info->pBindingFlags[i] &
554 (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
555 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT))) {
556 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 -0600557 "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-flags-03003",
558 "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i);
Jeff Bolzfdf96072018-04-10 14:32:18 -0500559 }
560 }
561 }
562 }
563
John Zulauf0fdeab32018-01-23 11:27:35 -0700564 if ((push_descriptor_set) && (total_descriptors > max_push_descriptors)) {
565 const char *undefined = push_descriptor_ext ? "" : " -- undefined";
Dave Houltond8ed0212018-05-16 17:18:24 -0600566 skip |=
567 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
568 "VUID-VkDescriptorSetLayoutCreateInfo-flags-00281",
569 "for push descriptor, total descriptor count in layout (%" PRIu64
570 ") must not be greater than VkPhysicalDevicePushDescriptorPropertiesKHR::maxPushDescriptors (%" PRIu32 "%s).",
571 total_descriptors, max_push_descriptors, undefined);
John Zulauf0fdeab32018-01-23 11:27:35 -0700572 }
573
Tobin Ehlis154c2692016-10-25 09:36:53 -0600574 return skip;
575}
576
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600577cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
578 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
579
Tobin Ehlis93f22372016-10-12 14:34:12 -0600580cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
Jeff Bolzfdf96072018-04-10 14:32:18 -0500581 const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count,
582 layer_data *dev_data)
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -0700583 : some_update_(false),
584 set_(set),
585 pool_state_(nullptr),
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600586 p_layout_(layout),
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -0700587 device_data_(dev_data),
Jeff Bolzfdf96072018-04-10 14:32:18 -0500588 limits_(GetPhysDevProperties(dev_data)->properties.limits),
589 variable_count_(variable_count) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700590 pool_state_ = GetDescriptorPoolState(dev_data, pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600591 // Foreach binding, create default descriptors of given type
John Zulaufb6d71202017-12-22 16:47:09 -0700592 descriptors_.reserve(p_layout_->GetTotalDescriptorCount());
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600593 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
594 auto type = p_layout_->GetTypeFromIndex(i);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600595 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700596 case VK_DESCRIPTOR_TYPE_SAMPLER: {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600597 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
598 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
Tobin Ehlis082c7512017-05-08 11:24:57 -0600599 if (immut_sampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700600 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis082c7512017-05-08 11:24:57 -0600601 some_update_ = true; // Immutable samplers are updated at creation
602 } else
Chris Forbes9f340852017-05-09 08:51:38 -0700603 descriptors_.emplace_back(new SamplerDescriptor(nullptr));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700604 }
605 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600606 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700607 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600608 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
609 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
Tobin Ehlis082c7512017-05-08 11:24:57 -0600610 if (immut) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700611 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis082c7512017-05-08 11:24:57 -0600612 some_update_ = true; // Immutable samplers are updated at creation
613 } else
Chris Forbes9f340852017-05-09 08:51:38 -0700614 descriptors_.emplace_back(new ImageSamplerDescriptor(nullptr));
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700615 }
616 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600617 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700618 // ImageDescriptors
619 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
620 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
621 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600622 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700623 descriptors_.emplace_back(new ImageDescriptor(type));
624 break;
625 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
626 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600627 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700628 descriptors_.emplace_back(new TexelDescriptor(type));
629 break;
630 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
631 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
632 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
633 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600634 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700635 descriptors_.emplace_back(new BufferDescriptor(type));
636 break;
Jeff Bolze54ae892018-09-08 12:16:29 -0500637 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
638 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
639 descriptors_.emplace_back(new InlineUniformDescriptor(type));
640 break;
Jeff Bolzfbe51582018-09-13 10:01:35 -0500641 case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NVX:
642 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
643 descriptors_.emplace_back(new AccelerationStructureDescriptor(type));
644 break;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700645 default:
646 assert(0); // Bad descriptor type specified
647 break;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600648 }
649 }
650}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600651
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700652cvdescriptorset::DescriptorSet::~DescriptorSet() { InvalidateBoundCmdBuffers(); }
Chris Forbes57989132016-07-26 17:06:10 +1200653
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600654static std::string StringDescriptorReqViewType(descriptor_req req) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700655 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200656 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
657 if (req & (1 << i)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700658 if (result.size()) result += ", ";
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700659 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200660 }
661 }
662
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700663 if (!result.size()) result = "(none)";
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700664
665 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200666}
667
Chris Forbesda01e8d2018-08-27 15:36:57 -0700668static char const *StringDescriptorReqComponentType(descriptor_req req) {
669 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT";
670 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT";
671 if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT";
672 return "(none)";
673}
674
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600675// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
Tobin Ehlis6dc57dd2017-06-21 10:08:52 -0600676bool cvdescriptorset::DescriptorSet::IsCompatible(DescriptorSetLayout const *const layout, std::string *error) const {
677 return layout->IsCompatible(p_layout_.get(), error);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600678}
Chris Forbes57989132016-07-26 17:06:10 +1200679
Chris Forbesda01e8d2018-08-27 15:36:57 -0700680static unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) {
681 if (FormatIsSInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
682 if (FormatIsUInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
683 if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
684 if (fmt == VK_FORMAT_UNDEFINED) return 0;
685 // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
686 return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
687}
688
Tobin Ehlis3066db62016-08-22 08:12:23 -0600689// 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 -0600690// This includes validating that all descriptors in the given bindings are updated,
691// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
692// Return true if state is acceptable, or false and write an error message into error string
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600693bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings,
John Zulauf48a6a702017-12-22 17:14:54 -0700694 const std::vector<uint32_t> &dynamic_offsets, GLOBAL_CB_NODE *cb_node,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600695 const char *caller, std::string *error) const {
Chris Forbesc7090a82016-07-25 18:10:41 +1200696 for (auto binding_pair : bindings) {
697 auto binding = binding_pair.first;
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600698 if (!p_layout_->HasBinding(binding)) {
Tobin Ehlis58c59582016-06-21 12:34:33 -0600699 std::stringstream error_str;
700 error_str << "Attempting to validate DrawState for binding #" << binding
701 << " which is an invalid binding for this descriptor set.";
702 *error = error_str.str();
703 return false;
704 }
John Zulaufc483f442017-12-15 14:02:06 -0700705 IndexRange index_range = p_layout_->GetGlobalIndexRangeFromBinding(binding);
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700706 auto array_idx = 0; // Track array idx if we're dealing with array descriptors
Jeff Bolzfdf96072018-04-10 14:32:18 -0500707
708 if (IsVariableDescriptorCount(binding)) {
709 // Only validate the first N descriptors if it uses variable_count
710 index_range.end = index_range.start + GetVariableDescriptorCount();
711 }
712
John Zulaufc483f442017-12-15 14:02:06 -0700713 for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500714 if ((p_layout_->GetDescriptorBindingFlagsFromBinding(binding) & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT) ||
715 descriptors_[i]->GetClass() == InlineUniform) {
Jeff Bolzfdf96072018-04-10 14:32:18 -0500716 // Can't validate the descriptor because it may not have been updated,
717 // or the view could have been destroyed
718 continue;
719 } else if (!descriptors_[i]->updated) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700720 std::stringstream error_str;
721 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
722 << " is being used in draw but has not been updated.";
723 *error = error_str.str();
724 return false;
725 } else {
726 auto descriptor_class = descriptors_[i]->GetClass();
727 if (descriptor_class == GeneralBuffer) {
728 // Verify that buffers are valid
729 auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer();
730 auto buffer_node = GetBufferState(device_data_, buffer);
731 if (!buffer_node) {
732 std::stringstream error_str;
733 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
734 << " references invalid buffer " << buffer << ".";
735 *error = error_str.str();
736 return false;
John Zulauf48a6a702017-12-22 17:14:54 -0700737 } else if (!buffer_node->sparse) {
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700738 for (auto mem_binding : buffer_node->GetBoundMemory()) {
739 if (!GetMemObjInfo(device_data_, mem_binding)) {
740 std::stringstream error_str;
741 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
742 << " uses buffer " << buffer << " that references invalid memory " << mem_binding << ".";
743 *error = error_str.str();
Tobin Ehlisc8266452017-04-07 12:20:30 -0600744 return false;
745 }
746 }
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700747 }
748 if (descriptors_[i]->IsDynamic()) {
749 // Validate that dynamic offsets are within the buffer
750 auto buffer_size = buffer_node->createInfo.size;
751 auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange();
752 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset();
753 auto dyn_offset = dynamic_offsets[GetDynamicOffsetIndexFromBinding(binding) + array_idx];
754 if (VK_WHOLE_SIZE == range) {
755 if ((dyn_offset + desc_offset) > buffer_size) {
756 std::stringstream error_str;
757 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
758 << " uses buffer " << buffer << " with update range of VK_WHOLE_SIZE has dynamic offset "
759 << dyn_offset << " combined with offset " << desc_offset
760 << " that oversteps the buffer size of " << buffer_size << ".";
761 *error = error_str.str();
762 return false;
763 }
764 } else {
765 if ((dyn_offset + desc_offset + range) > buffer_size) {
766 std::stringstream error_str;
767 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
768 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
769 << " combined with offset " << desc_offset << " and range " << range
770 << " that oversteps the buffer size of " << buffer_size << ".";
771 *error = error_str.str();
772 return false;
773 }
774 }
775 }
776 } else if (descriptor_class == ImageSampler || descriptor_class == Image) {
777 VkImageView image_view;
778 VkImageLayout image_layout;
779 if (descriptor_class == ImageSampler) {
780 image_view = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView();
781 image_layout = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageLayout();
782 } else {
783 image_view = static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView();
784 image_layout = static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageLayout();
785 }
786 auto reqs = binding_pair.second;
787
788 auto image_view_state = GetImageViewState(device_data_, image_view);
Tobin Ehlis836a1372017-07-14 11:25:21 -0600789 if (nullptr == image_view_state) {
790 // Image view must have been destroyed since initial update. Could potentially flag the descriptor
791 // as "invalid" (updated = false) at DestroyImageView() time and detect this error at bind time
792 std::stringstream error_str;
793 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
794 << " is using imageView " << image_view << " that has been destroyed.";
795 *error = error_str.str();
796 return false;
797 }
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700798 auto image_view_ci = image_view_state->create_info;
799
800 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
801 // bad view type
802 std::stringstream error_str;
803 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600804 << " requires an image view of type " << StringDescriptorReqViewType(reqs) << " but got "
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700805 << string_VkImageViewType(image_view_ci.viewType) << ".";
806 *error = error_str.str();
807 return false;
808 }
809
Chris Forbesda01e8d2018-08-27 15:36:57 -0700810 auto format_bits = DescriptorRequirementsBitsFromFormat(image_view_ci.format);
811 if (!(reqs & format_bits)) {
812 // bad component type
813 std::stringstream error_str;
814 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i << " requires "
815 << StringDescriptorReqComponentType(reqs) << " component type, but bound descriptor format is "
816 << string_VkFormat(image_view_ci.format) << ".";
817 *error = error_str.str();
818 return false;
819 }
820
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700821 auto image_node = GetImageState(device_data_, image_view_ci.image);
822 assert(image_node);
823 // Verify Image Layout
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700824 // Copy first mip level into sub_layers and loop over each mip level to verify layout
825 VkImageSubresourceLayers sub_layers;
826 sub_layers.aspectMask = image_view_ci.subresourceRange.aspectMask;
827 sub_layers.baseArrayLayer = image_view_ci.subresourceRange.baseArrayLayer;
828 sub_layers.layerCount = image_view_ci.subresourceRange.layerCount;
829 bool hit_error = false;
830 for (auto cur_level = image_view_ci.subresourceRange.baseMipLevel;
831 cur_level < image_view_ci.subresourceRange.levelCount; ++cur_level) {
832 sub_layers.mipLevel = cur_level;
Cort Stratton7df30962018-05-17 19:45:57 -0700833 // No "invalid layout" VUID required for this call, since the optimal_layout parameter is UNDEFINED.
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700834 VerifyImageLayout(device_data_, cb_node, image_node, sub_layers, image_layout, VK_IMAGE_LAYOUT_UNDEFINED,
Cort Stratton7df30962018-05-17 19:45:57 -0700835 caller, kVUIDUndefined, "VUID-VkDescriptorImageInfo-imageLayout-00344", &hit_error);
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700836 if (hit_error) {
837 *error =
Dave Houltona9df0ce2018-02-07 10:51:23 -0700838 "Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time "
839 "descriptor is used. See previous error callback for specific details.";
Chris Forbes57989132016-07-26 17:06:10 +1200840 return false;
841 }
Chris Forbes1f7f3ca2017-05-08 13:54:50 -0700842 }
843 // Verify Sample counts
844 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
845 std::stringstream error_str;
846 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
847 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
848 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
849 *error = error_str.str();
850 return false;
851 }
852 if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
853 std::stringstream error_str;
854 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
855 << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
856 *error = error_str.str();
857 return false;
Chris Forbes57989132016-07-26 17:06:10 +1200858 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600859 }
Tobin Ehlisb1a2e4b2018-03-16 07:54:24 -0600860 if (descriptor_class == ImageSampler || descriptor_class == PlainSampler) {
861 // Verify Sampler still valid
862 VkSampler sampler;
863 if (descriptor_class == ImageSampler) {
864 sampler = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetSampler();
865 } else {
866 sampler = static_cast<SamplerDescriptor *>(descriptors_[i].get())->GetSampler();
867 }
868 if (!ValidateSampler(sampler, device_data_)) {
869 std::stringstream error_str;
870 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
871 << " is using sampler " << sampler << " that has been destroyed.";
872 *error = error_str.str();
873 return false;
874 }
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();
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -0700906 auto bv_state = GetBufferViewState(device_data_, 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() {
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600927 core_validation::InvalidateCommandBuffers(device_data_, cb_bindings, {HandleToUint64(set_), kVulkanObjectTypeDescriptorSet});
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600928}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600929// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600930void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700931 // Perform update on a per-binding basis as consecutive updates roll over to next binding
932 auto descriptors_remaining = update->descriptorCount;
933 auto binding_being_updated = update->dstBinding;
934 auto offset = update->dstArrayElement;
Tobin Ehlise16805c2017-08-09 09:10:37 -0600935 uint32_t update_index = 0;
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700936 while (descriptors_remaining) {
937 uint32_t update_count = std::min(descriptors_remaining, GetDescriptorCountFromBinding(binding_being_updated));
John Zulaufc483f442017-12-15 14:02:06 -0700938 auto global_idx = p_layout_->GetGlobalIndexRangeFromBinding(binding_being_updated).start + offset;
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700939 // Loop over the updates for a single binding at a time
Tobin Ehlise16805c2017-08-09 09:10:37 -0600940 for (uint32_t di = 0; di < update_count; ++di, ++update_index) {
941 descriptors_[global_idx + di]->WriteUpdate(update, update_index);
Tobin Ehlisf922ef82016-11-30 10:19:14 -0700942 }
943 // Roll over to next binding in case of consecutive update
944 descriptors_remaining -= update_count;
945 offset = 0;
946 binding_being_updated++;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600947 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700948 if (update->descriptorCount) some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600949
Jeff Bolzfdf96072018-04-10 14:32:18 -0500950 if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
951 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
952 InvalidateBoundCmdBuffers();
953 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600954}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600955// Validate Copy update
956bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update,
Dave Houlton00c154e2018-05-24 13:20:50 -0600957 const DescriptorSet *src_set, std::string *error_code,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600958 std::string *error_msg) {
John Zulauf5dfd45c2018-01-17 11:06:34 -0700959 // Verify dst layout still valid
960 if (p_layout_->IsDestroyed()) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600961 *error_code = "VUID-VkCopyDescriptorSet-dstSet-parameter";
John Zulauf5dfd45c2018-01-17 11:06:34 -0700962 string_sprintf(error_msg,
963 "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set dstSet 0x%" PRIxLEAST64
964 " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64,
965 HandleToUint64(set_), HandleToUint64(p_layout_->GetDescriptorSetLayout()));
966 return false;
967 }
968
969 // Verify src layout still valid
970 if (src_set->p_layout_->IsDestroyed()) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600971 *error_code = "VUID-VkCopyDescriptorSet-srcSet-parameter";
John Zulauf5dfd45c2018-01-17 11:06:34 -0700972 string_sprintf(
973 error_msg,
974 "Cannot call vkUpdateDescriptorSets() to perform copy update of dstSet 0x%" PRIxLEAST64
975 " from descriptor set srcSet 0x%" PRIxLEAST64 " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64,
976 HandleToUint64(set_), HandleToUint64(src_set->set_), HandleToUint64(src_set->p_layout_->GetDescriptorSetLayout()));
977 return false;
978 }
979
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600980 if (!p_layout_->HasBinding(update->dstBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600981 *error_code = "VUID-VkCopyDescriptorSet-dstBinding-00347";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600982 std::stringstream error_str;
Tobin Ehlis1d81edd2016-11-21 09:50:49 -0700983 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600984 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600985 return false;
986 }
987 if (!src_set->HasBinding(update->srcBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -0600988 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-00345";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600989 std::stringstream error_str;
Tobin Ehlis1d81edd2016-11-21 09:50:49 -0700990 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600991 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600992 return false;
993 }
Jeff Bolzfdf96072018-04-10 14:32:18 -0500994 // Verify idle ds
995 if (in_use.load() &&
996 !(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
997 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
998 // TODO : Re-using Free Idle error code, need copy update idle error code
Dave Houlton00c154e2018-05-24 13:20:50 -0600999 *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001000 std::stringstream error_str;
1001 error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
1002 << " that is in use by a command buffer";
1003 *error_msg = error_str.str();
1004 return false;
1005 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001006 // src & dst set bindings are valid
1007 // Check bounds of src & dst
John Zulaufc483f442017-12-15 14:02:06 -07001008 auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001009 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
1010 // SRC update out of bounds
Dave Houlton00c154e2018-05-24 13:20:50 -06001011 *error_code = "VUID-VkCopyDescriptorSet-srcArrayElement-00346";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001012 std::stringstream error_str;
1013 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
John Zulaufc483f442017-12-15 14:02:06 -07001014 << " with offset index of " << src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001015 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
Tobin Ehlis1d81edd2016-11-21 09:50:49 -07001016 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001017 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001018 return false;
1019 }
John Zulaufc483f442017-12-15 14:02:06 -07001020 auto dst_start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement;
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001021 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001022 // DST update out of bounds
Dave Houlton00c154e2018-05-24 13:20:50 -06001023 *error_code = "VUID-VkCopyDescriptorSet-dstArrayElement-00348";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001024 std::stringstream error_str;
1025 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
John Zulaufc483f442017-12-15 14:02:06 -07001026 << " with offset index of " << p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001027 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001028 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001029 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001030 return false;
1031 }
1032 // Check that types match
Dave Houltond8ed0212018-05-16 17:18:24 -06001033 // TODO : Base default error case going from here is "VUID-VkAcquireNextImageInfoKHR-semaphore-parameter"2ba which covers all
1034 // consistency issues, need more fine-grained error codes
Dave Houlton00c154e2018-05-24 13:20:50 -06001035 *error_code = "VUID-VkCopyDescriptorSet-srcSet-00349";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001036 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001037 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001038 if (src_type != dst_type) {
1039 std::stringstream error_str;
1040 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
1041 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
Tobin Ehlis1d81edd2016-11-21 09:50:49 -07001042 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match";
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 // Verify consistency of src & dst bindings if update crosses binding boundaries
Tobin Ehlis1f946f82016-05-05 12:03:44 -06001047 if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001048 "copy update from", src_set->GetSet(), error_msg)) ||
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001049 (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001050 set_, error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001051 return false;
1052 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05001053
1054 if ((src_set->GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) &&
1055 !(GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001056 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01918";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001057 std::stringstream error_str;
1058 error_str << "If pname:srcSet's (" << update->srcSet
1059 << ") layout was created with the "
1060 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag "
1061 "set, then pname:dstSet's ("
1062 << update->dstSet
1063 << ") layout must: also have been created with the "
1064 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set";
1065 *error_msg = error_str.str();
1066 return false;
1067 }
1068
1069 if (!(src_set->GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) &&
1070 (GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001071 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01919";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001072 std::stringstream error_str;
1073 error_str << "If pname:srcSet's (" << update->srcSet
1074 << ") layout was created without the "
1075 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag "
1076 "set, then pname:dstSet's ("
1077 << update->dstSet
1078 << ") layout must: also have been created without the "
1079 "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set";
1080 *error_msg = error_str.str();
1081 return false;
1082 }
1083
1084 if ((src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) &&
1085 !(GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001086 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01920";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001087 std::stringstream error_str;
1088 error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet
1089 << ") was allocated was created "
1090 "with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag "
1091 "set, then the descriptor pool from which pname:dstSet ("
1092 << update->dstSet
1093 << ") was allocated must: "
1094 "also have been created with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set";
1095 *error_msg = error_str.str();
1096 return false;
1097 }
1098
1099 if (!(src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) &&
1100 (GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001101 *error_code = "VUID-VkCopyDescriptorSet-srcSet-01921";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001102 std::stringstream error_str;
1103 error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet
1104 << ") was allocated was created "
1105 "without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag "
1106 "set, then the descriptor pool from which pname:dstSet ("
1107 << update->dstSet
1108 << ") was allocated must: "
1109 "also have been created without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set";
1110 *error_msg = error_str.str();
1111 return false;
1112 }
1113
Jeff Bolze54ae892018-09-08 12:16:29 -05001114 if (src_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
1115 if ((update->srcArrayElement % 4) != 0) {
1116 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02223";
1117 std::stringstream error_str;
1118 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1119 << "srcArrayElement " << update->srcArrayElement << " not a multiple of 4";
1120 *error_msg = error_str.str();
1121 return false;
1122 }
1123 if ((update->dstArrayElement % 4) != 0) {
1124 *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02224";
1125 std::stringstream error_str;
1126 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1127 << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
1128 *error_msg = error_str.str();
1129 return false;
1130 }
1131 if ((update->descriptorCount % 4) != 0) {
1132 *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02225";
1133 std::stringstream error_str;
1134 error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with "
1135 << "descriptorCount " << update->descriptorCount << " not a multiple of 4";
1136 *error_msg = error_str.str();
1137 return false;
1138 }
1139 }
1140
Tobin Ehlisd41e7b62016-05-19 07:56:18 -06001141 // Update parameters all look good and descriptor updated so verify update contents
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001142 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg)) return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001143
1144 // All checks passed so update is good
1145 return true;
1146}
1147// Perform Copy update
1148void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
John Zulaufc483f442017-12-15 14:02:06 -07001149 auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement;
1150 auto dst_start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001151 // Update parameters all look good so perform update
1152 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02001153 auto src = src_set->descriptors_[src_start_idx + di].get();
1154 auto dst = descriptors_[dst_start_idx + di].get();
1155 if (src->updated) {
1156 dst->CopyUpdate(src);
1157 some_update_ = true;
1158 } else {
1159 dst->updated = false;
1160 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001161 }
Tobin Ehlis56a30942016-05-19 08:00:00 -06001162
Jeff Bolzfdf96072018-04-10 14:32:18 -05001163 if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
1164 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
1165 InvalidateBoundCmdBuffers();
1166 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001167}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001168
Tobin Ehlisf9519102016-08-17 09:49:13 -06001169// Bind cb_node to this set and this set to cb_node.
1170// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
1171// to be used in a draw by the given cb_node
Tobin Ehlis276d3d32016-12-21 09:21:06 -07001172void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node,
Tobin Ehlis022528b2016-12-29 12:22:32 -07001173 const std::map<uint32_t, descriptor_req> &binding_req_map) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -06001174 // bind cb to this descriptor set
1175 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -06001176 // Add bindings for descriptor set, the set's pool, and individual objects in the set
Petr Krausbc7f5442017-05-14 23:43:38 +02001177 cb_node->object_bindings.insert({HandleToUint64(set_), kVulkanObjectTypeDescriptorSet});
Tobin Ehlis7ca20be2016-10-12 15:09:16 -06001178 pool_state_->cb_bindings.insert(cb_node);
Petr Krausbc7f5442017-05-14 23:43:38 +02001179 cb_node->object_bindings.insert({HandleToUint64(pool_state_->pool), kVulkanObjectTypeDescriptorPool});
Tobin Ehlisf9519102016-08-17 09:49:13 -06001180 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
1181 // resources
Tobin Ehlis022528b2016-12-29 12:22:32 -07001182 for (auto binding_req_pair : binding_req_map) {
1183 auto binding = binding_req_pair.first;
John Zulaufc483f442017-12-15 14:02:06 -07001184 auto range = p_layout_->GetGlobalIndexRangeFromBinding(binding);
1185 for (uint32_t i = range.start; i < range.end; ++i) {
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001186 descriptors_[i]->BindCommandBuffer(device_data_, cb_node);
1187 }
1188 }
Tobin Ehlis9252c2b2016-07-21 14:40:22 -06001189}
Mark Lobodzinski2872f4a2018-09-03 17:00:53 -06001190
1191// Update CB layout map with any image/imagesampler descriptor image layouts
1192void cvdescriptorset::DescriptorSet::UpdateDSImageLayoutState(GLOBAL_CB_NODE *cb_state) {
1193 for (auto const &desc : descriptors_) {
Mark Lobodzinskieae49f02018-09-10 11:58:08 -06001194 if (desc->updated && (desc->descriptor_class == ImageSampler || desc->descriptor_class == Image)) {
Mark Lobodzinski2872f4a2018-09-03 17:00:53 -06001195 VkImageView image_view;
1196 VkImageLayout image_layout;
1197 if (desc->descriptor_class == ImageSampler) {
1198 image_view = static_cast<ImageSamplerDescriptor *>(desc.get())->GetImageView();
1199 image_layout = static_cast<ImageSamplerDescriptor *>(desc.get())->GetImageLayout();
1200 } else {
1201 image_view = static_cast<ImageDescriptor *>(desc.get())->GetImageView();
1202 image_layout = static_cast<ImageDescriptor *>(desc.get())->GetImageLayout();
1203 }
1204 SetImageViewLayout(device_data_, cb_state, image_view, image_layout);
1205 }
1206 }
1207}
1208
John Zulauf48a6a702017-12-22 17:14:54 -07001209void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair,
1210 const BindingReqMap &in_req, BindingReqMap *out_req,
1211 TrackedBindings *bindings) {
1212 assert(out_req);
1213 assert(bindings);
1214 const auto binding = binding_req_pair.first;
1215 // Use insert and look at the boolean ("was inserted") in the returned pair to see if this is a new set member.
1216 // Saves one hash lookup vs. find ... compare w/ end ... insert.
1217 const auto it_bool_pair = bindings->insert(binding);
1218 if (it_bool_pair.second) {
1219 out_req->emplace(binding_req_pair);
1220 }
1221}
Mark Lobodzinski2872f4a2018-09-03 17:00:53 -06001222
John Zulauf48a6a702017-12-22 17:14:54 -07001223void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair,
1224 const BindingReqMap &in_req, BindingReqMap *out_req,
1225 TrackedBindings *bindings, uint32_t limit) {
1226 if (bindings->size() < limit) FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, bindings);
1227}
1228
1229void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(GLOBAL_CB_NODE *cb_state, const BindingReqMap &in_req,
1230 BindingReqMap *out_req) {
1231 TrackedBindings &bound = cached_validation_[cb_state].command_binding_and_usage;
1232 if (bound.size() == GetBindingCount()) {
1233 return; // All bindings are bound, out req is empty
1234 }
1235 for (const auto &binding_req_pair : in_req) {
1236 const auto binding = binding_req_pair.first;
1237 // If a binding doesn't exist, or has already been bound, skip it
1238 if (p_layout_->HasBinding(binding)) {
1239 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, &bound);
1240 }
1241 }
1242}
1243
1244void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *pipeline,
1245 const BindingReqMap &in_req, BindingReqMap *out_req) {
1246 auto &validated = cached_validation_[cb_state];
1247 auto &image_sample_val = validated.image_samplers[pipeline];
1248 auto *const dynamic_buffers = &validated.dynamic_buffers;
1249 auto *const non_dynamic_buffers = &validated.non_dynamic_buffers;
1250 const auto &stats = p_layout_->GetBindingTypeStats();
1251 for (const auto &binding_req_pair : in_req) {
1252 auto binding = binding_req_pair.first;
1253 VkDescriptorSetLayoutBinding const *layout_binding = p_layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding);
1254 if (!layout_binding) {
1255 continue;
1256 }
1257 // Caching criteria differs per type.
1258 // If image_layout have changed , the image descriptors need to be validated against them.
1259 if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1260 (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1261 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, dynamic_buffers, stats.dynamic_buffer_count);
1262 } else if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1263 (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) {
1264 FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, non_dynamic_buffers, stats.non_dynamic_buffer_count);
1265 } else {
1266 // This is rather crude, as the changed layouts may not impact the bound descriptors,
1267 // but the simple "versioning" is a simple "dirt" test.
1268 auto &version = image_sample_val[binding]; // Take advantage of default construtor zero initialzing new entries
1269 if (version != cb_state->image_layout_change_count) {
1270 version = cb_state->image_layout_change_count;
1271 out_req->emplace(binding_req_pair);
1272 }
1273 }
1274 }
1275}
Tobin Ehlis9252c2b2016-07-21 14:40:22 -06001276
Tobin Ehlis300888c2016-05-18 13:43:26 -06001277cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001278 updated = false;
1279 descriptor_class = PlainSampler;
1280 if (immut) {
1281 sampler_ = *immut;
1282 immutable_ = true;
1283 updated = true;
1284 }
1285}
Tobin Ehlise2f80292016-06-02 10:08:53 -06001286// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001287bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const layer_data *dev_data) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001288 return (GetSamplerState(dev_data, sampler) != nullptr);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001289}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001290
Tobin Ehlis554bf382016-05-24 11:14:43 -06001291bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
Dave Houlton00c154e2018-05-24 13:20:50 -06001292 const layer_data *dev_data, std::string *error_code, std::string *error_msg) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001293 // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases.
Dave Houlton00c154e2018-05-24 13:20:50 -06001294 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00326";
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001295 auto iv_state = GetImageViewState(dev_data, image_view);
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001296 if (!iv_state) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001297 std::stringstream error_str;
1298 error_str << "Invalid VkImageView: " << image_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001299 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001300 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001301 }
Tobin Ehlis81280962016-07-20 14:04:20 -06001302 // 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 -06001303 // Validate that imageLayout is compatible with aspect_mask and image format
1304 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001305 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
1306 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001307 VkFormat format = VK_FORMAT_MAX_ENUM;
1308 VkImageUsageFlags usage = 0;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001309 auto image_node = GetImageState(dev_data, image);
Tobin Ehlis1c9c55f2016-06-02 11:49:22 -06001310 if (image_node) {
1311 format = image_node->createInfo.format;
1312 usage = image_node->createInfo.usage;
Tobin Ehlis029d2fe2016-09-21 09:19:15 -06001313 // Validate that memory is bound to image
Tobin Ehlis2cb8eb22017-01-03 14:09:57 -07001314 // TODO: This should have its own valid usage id apart from 2524 which is from CreateImageView case. The only
1315 // the error here occurs is if memory bound to a created imageView has been freed.
Dave Houltond8ed0212018-05-16 17:18:24 -06001316 if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()",
1317 "VUID-VkImageViewCreateInfo-image-01020")) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001318 *error_code = "VUID-VkImageViewCreateInfo-image-01020";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001319 *error_msg = "No memory bound to image.";
Tobin Ehlis029d2fe2016-09-21 09:19:15 -06001320 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001321 }
Chris Forbes67757ff2017-07-21 13:59:01 -07001322
1323 // KHR_maintenance1 allows rendering into 2D or 2DArray views which slice a 3D image,
1324 // but not binding them to descriptor sets.
1325 if (image_node->createInfo.imageType == VK_IMAGE_TYPE_3D &&
1326 (iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D ||
1327 iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001328 *error_code = "VUID-VkDescriptorImageInfo-imageView-00343";
Chris Forbes67757ff2017-07-21 13:59:01 -07001329 *error_msg = "ImageView must not be a 2D or 2DArray view of a 3D image";
1330 return false;
1331 }
Tobin Ehlis1809f912016-05-25 09:24:36 -06001332 }
1333 // First validate that format and layout are compatible
1334 if (format == VK_FORMAT_MAX_ENUM) {
1335 std::stringstream error_str;
1336 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001337 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -06001338 return false;
1339 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001340 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
1341 // vkCreateImageView(). What's the best way to create unique id for these cases?
Dave Houlton1d2022c2017-03-29 11:43:58 -06001342 bool ds = FormatIsDepthOrStencil(format);
Tobin Ehlis1809f912016-05-25 09:24:36 -06001343 switch (image_layout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001344 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
1345 // Only Color bit must be set
1346 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis1809f912016-05-25 09:24:36 -06001347 std::stringstream error_str;
Dave Houltona9df0ce2018-02-07 10:51:23 -07001348 error_str
1349 << "ImageView (" << image_view
1350 << ") 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 -06001351 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -06001352 return false;
1353 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001354 // format must NOT be DS
1355 if (ds) {
1356 std::stringstream error_str;
1357 error_str << "ImageView (" << image_view
1358 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
1359 << string_VkFormat(format) << " which is not a color format.";
1360 *error_msg = error_str.str();
1361 return false;
1362 }
1363 break;
1364 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
1365 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
1366 // Depth or stencil bit must be set, but both must NOT be set
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001367 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1368 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1369 // both must NOT be set
1370 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001371 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001372 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001373 return false;
1374 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001375 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
1376 // Neither were set
1377 std::stringstream error_str;
1378 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
1379 << " but does not have STENCIL or DEPTH aspects set";
1380 *error_msg = error_str.str();
1381 return false;
Tobin Ehlisbbf3f912016-06-15 13:03:58 -06001382 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001383 // format must be DS
1384 if (!ds) {
1385 std::stringstream error_str;
1386 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
1387 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
1388 *error_msg = error_str.str();
1389 return false;
1390 }
1391 break;
1392 default:
1393 // For other layouts if the source is depth/stencil image, both aspect bits must not be set
1394 if (ds) {
1395 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
1396 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
1397 // both must NOT be set
1398 std::stringstream error_str;
1399 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
1400 << " and is using depth/stencil image of format " << string_VkFormat(format)
1401 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
1402 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
1403 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
1404 "reads respectively.";
1405 *error_msg = error_str.str();
1406 return false;
1407 }
1408 }
1409 }
1410 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001411 }
1412 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -06001413 // 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 -06001414 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
1415 // under vkCreateImage()
Dave Houltond8ed0212018-05-16 17:18:24 -06001416 // TODO : Need to also validate case "VUID-VkWriteDescriptorSet-descriptorType-00336" where STORAGE_IMAGE & INPUT_ATTACH types
1417 // must have been created with identify swizzle
Tobin Ehlis1809f912016-05-25 09:24:36 -06001418 std::string error_usage_bit;
1419 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001420 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1421 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1422 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
1423 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
1424 }
1425 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001426 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001427 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1428 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
1429 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
1430 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
1431 std::stringstream error_str;
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001432 // TODO : Need to create custom enum error codes for these cases
1433 if (image_node->shared_presentable) {
1434 if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != image_layout) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001435 error_str << "ImageView (" << image_view
1436 << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type with a front-buffered image is being updated with "
1437 "layout "
1438 << string_VkImageLayout(image_layout)
1439 << " but according to spec section 13.1 Descriptor Types, 'Front-buffered images that report "
1440 "support for VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT must be in the "
1441 "VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR layout.'";
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001442 *error_msg = error_str.str();
1443 return false;
1444 }
1445 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
Dave Houltona9df0ce2018-02-07 10:51:23 -07001446 error_str << "ImageView (" << image_view
1447 << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
1448 << string_VkImageLayout(image_layout)
1449 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage "
1450 "images can only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
Tobin Ehlisbb03e5f2017-05-11 08:52:51 -06001451 *error_msg = error_str.str();
1452 return false;
1453 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001454 }
1455 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001456 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001457 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
1458 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
1459 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
1460 }
1461 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001462 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001463 default:
1464 break;
Tobin Ehlis1809f912016-05-25 09:24:36 -06001465 }
1466 if (!error_usage_bit.empty()) {
1467 std::stringstream error_str;
1468 error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage
1469 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1470 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001471 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -06001472 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001473 }
1474 return true;
1475}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001476
Tobin Ehlis300888c2016-05-18 13:43:26 -06001477void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Chris Forbesfea2c542018-04-13 09:34:15 -07001478 if (!immutable_) {
1479 sampler_ = update->pImageInfo[index].sampler;
1480 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001481 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001482}
1483
Tobin Ehlis300888c2016-05-18 13:43:26 -06001484void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001485 if (!immutable_) {
1486 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001487 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001488 }
1489 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001490}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001491
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001492void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001493 if (!immutable_) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001494 auto sampler_state = GetSamplerState(dev_data, sampler_);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001495 if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001496 }
1497}
1498
Tobin Ehlis300888c2016-05-18 13:43:26 -06001499cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
Chris Forbes9f340852017-05-09 08:51:38 -07001500 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001501 updated = false;
1502 descriptor_class = ImageSampler;
1503 if (immut) {
1504 sampler_ = *immut;
1505 immutable_ = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001506 }
1507}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001508
Tobin Ehlis300888c2016-05-18 13:43:26 -06001509void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001510 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001511 const auto &image_info = update->pImageInfo[index];
Chris Forbesfea2c542018-04-13 09:34:15 -07001512 if (!immutable_) {
1513 sampler_ = image_info.sampler;
1514 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001515 image_view_ = image_info.imageView;
1516 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001517}
1518
Tobin Ehlis300888c2016-05-18 13:43:26 -06001519void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001520 if (!immutable_) {
1521 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001522 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001523 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001524 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
1525 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001526 updated = true;
1527 image_view_ = image_view;
1528 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001529}
1530
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001531void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -06001532 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001533 if (!immutable_) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001534 auto sampler_state = GetSamplerState(dev_data, sampler_);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001535 if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001536 }
Tobin Ehlis81e46372016-08-17 13:33:44 -06001537 // Add binding for image
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001538 auto iv_state = GetImageViewState(dev_data, image_view_);
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001539 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -06001540 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001541 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001542}
1543
Tobin Ehlis300888c2016-05-18 13:43:26 -06001544cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
1545 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001546 updated = false;
1547 descriptor_class = Image;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001548 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) storage_ = true;
Petr Kraus13c98a62017-12-09 00:22:39 +01001549}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001550
Tobin Ehlis300888c2016-05-18 13:43:26 -06001551void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001552 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001553 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -06001554 image_view_ = image_info.imageView;
1555 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001556}
1557
Tobin Ehlis300888c2016-05-18 13:43:26 -06001558void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001559 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
1560 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001561 updated = true;
1562 image_view_ = image_view;
1563 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001564}
1565
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001566void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -06001567 // Add binding for image
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001568 auto iv_state = GetImageViewState(dev_data, image_view_);
Tobin Ehlis8b26a382016-09-14 08:02:49 -06001569 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -06001570 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001571 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001572}
1573
Tobin Ehlis300888c2016-05-18 13:43:26 -06001574cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
1575 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001576 updated = false;
1577 descriptor_class = GeneralBuffer;
1578 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
1579 dynamic_ = true;
1580 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
1581 storage_ = true;
1582 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
1583 dynamic_ = true;
1584 storage_ = true;
1585 }
1586}
Tobin Ehlis300888c2016-05-18 13:43:26 -06001587void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001588 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -06001589 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -06001590 buffer_ = buffer_info.buffer;
1591 offset_ = buffer_info.offset;
1592 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001593}
1594
Tobin Ehlis300888c2016-05-18 13:43:26 -06001595void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
1596 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001597 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001598 buffer_ = buff_desc->buffer_;
1599 offset_ = buff_desc->offset_;
1600 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001601}
1602
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001603void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001604 auto buffer_node = GetBufferState(dev_data, buffer_);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001605 if (buffer_node) core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001606}
1607
Tobin Ehlis300888c2016-05-18 13:43:26 -06001608cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001609 updated = false;
1610 descriptor_class = TexelBuffer;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001611 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) storage_ = true;
Petr Kraus13c98a62017-12-09 00:22:39 +01001612}
Tobin Ehlis56a30942016-05-19 08:00:00 -06001613
Tobin Ehlis300888c2016-05-18 13:43:26 -06001614void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001615 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001616 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001617}
1618
Tobin Ehlis300888c2016-05-18 13:43:26 -06001619void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1620 updated = true;
1621 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1622}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001623
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001624void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001625 auto bv_state = GetBufferViewState(dev_data, buffer_view_);
Tobin Ehlis8b872462016-09-14 08:12:08 -06001626 if (bv_state) {
Tobin Ehlis2515c0e2016-09-28 07:12:28 -06001627 core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001628 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001629}
1630
Tobin Ehlis300888c2016-05-18 13:43:26 -06001631// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1632// sets, and then calls their respective Validate[Write|Copy]Update functions.
1633// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1634// be skipped, then true is returned.
1635// If there is no issue with the update, then false is returned.
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001636bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data, const layer_data *dev_data,
1637 uint32_t write_count, const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001638 const VkCopyDescriptorSet *p_cds) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001639 bool skip = false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001640 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001641 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001642 auto dest_set = p_wds[i].dstSet;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001643 auto set_node = core_validation::GetSetNode(dev_data, dest_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001644 if (!set_node) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001645 skip |=
Tobin Ehlis300888c2016-05-18 13:43:26 -06001646 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Dave Houlton51653902018-06-22 17:32:13 -06001647 HandleToUint64(dest_set), kVUID_Core_DrawState_InvalidDescriptorSet,
Tobin Ehlis300888c2016-05-18 13:43:26 -06001648 "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.",
Petr Krausbc7f5442017-05-14 23:43:38 +02001649 HandleToUint64(dest_set));
Tobin Ehlis300888c2016-05-18 13:43:26 -06001650 } else {
Dave Houltond8ed0212018-05-16 17:18:24 -06001651 std::string error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001652 std::string error_str;
Dave Houlton00c154e2018-05-24 13:20:50 -06001653 if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001654 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001655 HandleToUint64(dest_set), error_code,
Artem Kharytoniuk2456f992018-01-12 14:17:41 +01001656 "vkUpdateDescriptorSets() failed write update validation for Descriptor Set 0x%" PRIx64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001657 " with error: %s.",
1658 HandleToUint64(dest_set), error_str.c_str());
Tobin Ehlis300888c2016-05-18 13:43:26 -06001659 }
1660 }
1661 }
1662 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001663 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001664 auto dst_set = p_cds[i].dstSet;
1665 auto src_set = p_cds[i].srcSet;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001666 auto src_node = core_validation::GetSetNode(dev_data, src_set);
1667 auto dst_node = core_validation::GetSetNode(dev_data, dst_set);
Tobin Ehlisa1712752017-01-04 09:41:47 -07001668 // Object_tracker verifies that src & dest descriptor set are valid
1669 assert(src_node);
1670 assert(dst_node);
Dave Houltond8ed0212018-05-16 17:18:24 -06001671 std::string error_code;
Tobin Ehlisa1712752017-01-04 09:41:47 -07001672 std::string error_str;
Dave Houlton00c154e2018-05-24 13:20:50 -06001673 if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001674 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Mark Lobodzinski88529492018-04-01 10:38:15 -06001675 HandleToUint64(dst_set), error_code,
Artem Kharytoniuk2456f992018-01-12 14:17:41 +01001676 "vkUpdateDescriptorSets() failed copy update from Descriptor Set 0x%" PRIx64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06001677 " to Descriptor Set 0x%" PRIx64 " with error: %s.",
1678 HandleToUint64(src_set), HandleToUint64(dst_set), error_str.c_str());
Tobin Ehlis300888c2016-05-18 13:43:26 -06001679 }
1680 }
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06001681 return skip;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001682}
1683// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1684// sets, and then calls their respective Perform[Write|Copy]Update functions.
1685// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1686// with the same set of updates.
1687// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1688// calling down the chain.
Tobin Ehlis58c884f2017-02-08 12:15:27 -07001689void cvdescriptorset::PerformUpdateDescriptorSets(const layer_data *dev_data, uint32_t write_count,
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001690 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1691 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001692 // Write updates first
1693 uint32_t i = 0;
1694 for (i = 0; i < write_count; ++i) {
1695 auto dest_set = p_wds[i].dstSet;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001696 auto set_node = core_validation::GetSetNode(dev_data, dest_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001697 if (set_node) {
1698 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001699 }
1700 }
1701 // Now copy updates
1702 for (i = 0; i < copy_count; ++i) {
1703 auto dst_set = p_cds[i].dstSet;
1704 auto src_set = p_cds[i].srcSet;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001705 auto src_node = core_validation::GetSetNode(dev_data, src_set);
1706 auto dst_node = core_validation::GetSetNode(dev_data, dst_set);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001707 if (src_node && dst_node) {
1708 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001709 }
1710 }
1711}
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001712// This helper function carries out the state updates for descriptor updates peformed via update templates. It basically collects
1713// data and leverages the PerformUpdateDescriptor helper functions to do this.
1714void cvdescriptorset::PerformUpdateDescriptorSetsWithTemplateKHR(layer_data *device_data, VkDescriptorSet descriptorSet,
1715 std::unique_ptr<TEMPLATE_STATE> const &template_state,
1716 const void *pData) {
1717 auto const &create_info = template_state->create_info;
1718
1719 // Create a vector of write structs
1720 std::vector<VkWriteDescriptorSet> desc_writes;
Jeff Bolze54ae892018-09-08 12:16:29 -05001721 std::vector<VkWriteDescriptorSetInlineUniformBlockEXT> inline_infos(create_info.descriptorUpdateEntryCount);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001722 auto layout_obj = GetDescriptorSetLayout(device_data, create_info.descriptorSetLayout);
1723
1724 // Create a WriteDescriptorSet struct for each template update entry
1725 for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) {
1726 auto binding_count = layout_obj->GetDescriptorCountFromBinding(create_info.pDescriptorUpdateEntries[i].dstBinding);
1727 auto binding_being_updated = create_info.pDescriptorUpdateEntries[i].dstBinding;
1728 auto dst_array_element = create_info.pDescriptorUpdateEntries[i].dstArrayElement;
1729
John Zulaufb6d71202017-12-22 16:47:09 -07001730 desc_writes.reserve(desc_writes.size() + create_info.pDescriptorUpdateEntries[i].descriptorCount);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001731 for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) {
1732 desc_writes.emplace_back();
1733 auto &write_entry = desc_writes.back();
1734
1735 size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride;
1736 char *update_entry = (char *)(pData) + offset;
1737
1738 if (dst_array_element >= binding_count) {
1739 dst_array_element = 0;
Mark Lobodzinski4aa479d2017-03-10 09:14:00 -07001740 binding_being_updated = layout_obj->GetNextValidBinding(binding_being_updated);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001741 }
1742
1743 write_entry.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
1744 write_entry.pNext = NULL;
1745 write_entry.dstSet = descriptorSet;
1746 write_entry.dstBinding = binding_being_updated;
1747 write_entry.dstArrayElement = dst_array_element;
1748 write_entry.descriptorCount = 1;
1749 write_entry.descriptorType = create_info.pDescriptorUpdateEntries[i].descriptorType;
1750
1751 switch (create_info.pDescriptorUpdateEntries[i].descriptorType) {
1752 case VK_DESCRIPTOR_TYPE_SAMPLER:
1753 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1754 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1755 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1756 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1757 write_entry.pImageInfo = reinterpret_cast<VkDescriptorImageInfo *>(update_entry);
1758 break;
1759
1760 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1761 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1762 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1763 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1764 write_entry.pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry);
1765 break;
1766
1767 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1768 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1769 write_entry.pTexelBufferView = reinterpret_cast<VkBufferView *>(update_entry);
1770 break;
Jeff Bolze54ae892018-09-08 12:16:29 -05001771 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
1772 {
1773 VkWriteDescriptorSetInlineUniformBlockEXT *inline_info = &inline_infos[i];
1774 inline_info->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT;
1775 inline_info->pNext = nullptr;
1776 inline_info->dataSize = create_info.pDescriptorUpdateEntries[i].descriptorCount;
1777 inline_info->pData = update_entry;
1778 write_entry.pNext = inline_info;
1779 // skip the rest of the array, they just represent bytes in the update
1780 j = create_info.pDescriptorUpdateEntries[i].descriptorCount;
1781 break;
1782 }
Mark Lobodzinski3d63a042017-03-09 16:24:13 -07001783 default:
1784 assert(0);
1785 break;
1786 }
1787 dst_array_element++;
1788 }
1789 }
1790 PerformUpdateDescriptorSets(device_data, static_cast<uint32_t>(desc_writes.size()), desc_writes.data(), 0, NULL);
1791}
Tobin Ehlis300888c2016-05-18 13:43:26 -06001792// Validate the state for a given write update but don't actually perform the update
1793// If an error would occur for this update, return false and fill in details in error_msg string
1794bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update,
Dave Houlton00c154e2018-05-24 13:20:50 -06001795 std::string *error_code, std::string *error_msg) {
John Zulauf5dfd45c2018-01-17 11:06:34 -07001796 // Verify dst layout still valid
1797 if (p_layout_->IsDestroyed()) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001798 *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320";
John Zulauf5dfd45c2018-01-17 11:06:34 -07001799 string_sprintf(error_msg,
1800 "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set 0x%" PRIxLEAST64
1801 " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64,
1802 HandleToUint64(set_), HandleToUint64(p_layout_->GetDescriptorSetLayout()));
1803 return false;
1804 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001805 // Verify dst binding exists
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001806 if (!p_layout_->HasBinding(update->dstBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001807 *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315";
Tobin Ehlis300888c2016-05-18 13:43:26 -06001808 std::stringstream error_str;
Tobin Ehlis1d81edd2016-11-21 09:50:49 -07001809 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001810 *error_msg = error_str.str();
1811 return false;
Tobin Ehlis59a5efc2016-11-21 09:41:57 -07001812 } else {
1813 // Make sure binding isn't empty
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001814 if (0 == p_layout_->GetDescriptorCountFromBinding(update->dstBinding)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001815 *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316";
Tobin Ehlis59a5efc2016-11-21 09:41:57 -07001816 std::stringstream error_str;
1817 error_str << "DescriptorSet " << set_ << " cannot updated binding " << update->dstBinding << " that has 0 descriptors";
1818 *error_msg = error_str.str();
1819 return false;
1820 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001821 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05001822 // Verify idle ds
1823 if (in_use.load() &&
1824 !(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) &
1825 (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
1826 // TODO : Re-using Free Idle error code, need write update idle error code
Dave Houlton00c154e2018-05-24 13:20:50 -06001827 *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
Jeff Bolzfdf96072018-04-10 14:32:18 -05001828 std::stringstream error_str;
1829 error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
1830 << " that is in use by a command buffer";
1831 *error_msg = error_str.str();
1832 return false;
1833 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001834 // We know that binding is valid, verify update and do update on each descriptor
John Zulaufc483f442017-12-15 14:02:06 -07001835 auto start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement;
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001836 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001837 if (type != update->descriptorType) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001838 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319";
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001839 std::stringstream error_str;
1840 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
1841 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
1842 *error_msg = error_str.str();
1843 return false;
1844 }
Tobin Ehlis7b402352016-12-15 07:51:20 -07001845 if (update->descriptorCount > (descriptors_.size() - start_idx)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001846 *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001847 std::stringstream error_str;
1848 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
Tobin Ehlis7b402352016-12-15 07:51:20 -07001849 << descriptors_.size() - start_idx
Tobin Ehlisf922ef82016-11-30 10:19:14 -07001850 << " descriptors in that binding and all successive bindings of the set, but update of "
1851 << update->descriptorCount << " descriptors combined with update array element offset of "
1852 << update->dstArrayElement << " oversteps the available number of consecutive descriptors";
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001853 *error_msg = error_str.str();
1854 return false;
1855 }
Jeff Bolze54ae892018-09-08 12:16:29 -05001856 if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
1857 if ((update->dstArrayElement % 4) != 0) {
1858 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219";
1859 std::stringstream error_str;
1860 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1861 << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
1862 *error_msg = error_str.str();
1863 return false;
1864 }
1865 if ((update->descriptorCount % 4) != 0) {
1866 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220";
1867 std::stringstream error_str;
1868 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1869 << "descriptorCount " << update->descriptorCount << " not a multiple of 4";
1870 *error_msg = error_str.str();
1871 return false;
1872 }
1873 const auto *write_inline_info = lvl_find_in_chain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext);
1874 if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) {
1875 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221";
1876 std::stringstream error_str;
1877 if (!write_inline_info) {
1878 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1879 << "VkWriteDescriptorSetInlineUniformBlockEXT missing";
1880 } else {
1881 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1882 << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize << " not equal to "
1883 << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount;
1884 }
1885 *error_msg = error_str.str();
1886 return false;
1887 }
1888 // This error is probably unreachable due to the previous two errors
1889 if (write_inline_info && (write_inline_info->dataSize % 4) != 0) {
1890 *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222";
1891 std::stringstream error_str;
1892 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1893 << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize << " not a multiple of 4";
1894 *error_msg = error_str.str();
1895 return false;
1896 }
1897 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001898 // Verify consecutive bindings match (if needed)
Tobin Ehlis7cd8c792017-06-20 08:30:39 -06001899 if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001900 set_, error_msg)) {
Tobin Ehlis48fbd692017-01-04 09:17:01 -07001901 // TODO : Should break out "consecutive binding updates" language into valid usage statements
Dave Houlton00c154e2018-05-24 13:20:50 -06001902 *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001903 return false;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001904 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001905 // Update is within bounds and consistent so last step is to validate update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001906 if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) {
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001907 std::stringstream error_str;
1908 error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding
1909 << " failed with error message: " << error_msg->c_str();
1910 *error_msg = error_str.str();
1911 return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001912 }
1913 // All checks passed, update is clean
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001914 return true;
Tobin Ehlis03d61de2016-05-17 08:31:46 -06001915}
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001916// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001917// If there's an error, update the error_msg string with details and return false, else return true
Tobin Ehlis4668dce2016-11-16 09:30:23 -07001918bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type,
Dave Houlton00c154e2018-05-24 13:20:50 -06001919 std::string *error_code, std::string *error_msg) const {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001920 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001921 auto usage = buffer_node->createInfo.usage;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001922 std::string error_usage_bit;
1923 switch (type) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001924 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1925 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001926 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00334";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1928 }
1929 break;
1930 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1931 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001932 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00335";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001933 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1934 }
1935 break;
1936 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1937 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1938 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001939 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00330";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001940 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1941 }
1942 break;
1943 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1944 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1945 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001946 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00331";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001947 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1948 }
1949 break;
1950 default:
1951 break;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001952 }
1953 if (!error_usage_bit.empty()) {
1954 std::stringstream error_str;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001955 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage
1956 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1957 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001958 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001959 return false;
1960 }
1961 return true;
1962}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001963// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1964// 1. buffer is valid
1965// 2. buffer was created with correct usage flags
1966// 3. offset is less than buffer size
1967// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07001968// 5. range and offset are within the device's limits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001969// If there's an error, update the error_msg string with details and return false, else return true
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001970bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type,
Dave Houlton00c154e2018-05-24 13:20:50 -06001971 std::string *error_code, std::string *error_msg) const {
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001972 // First make sure that buffer is valid
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07001973 auto buffer_node = GetBufferState(device_data_, buffer_info->buffer);
Tobin Ehlisfa8b6182016-12-22 13:40:45 -07001974 // Any invalid buffer should already be caught by object_tracker
1975 assert(buffer_node);
Dave Houltond8ed0212018-05-16 17:18:24 -06001976 if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()",
1977 "VUID-VkWriteDescriptorSet-descriptorType-00329")) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001978 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00329";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001979 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001980 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001981 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001982 // Verify usage bits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001983 if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
1984 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001985 return false;
1986 }
1987 // offset must be less than buffer size
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07001988 if (buffer_info->offset >= buffer_node->createInfo.size) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001989 *error_code = "VUID-VkDescriptorBufferInfo-offset-00340";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001990 std::stringstream error_str;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07001991 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than or equal to buffer "
1992 << buffer_node->buffer << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001993 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001994 return false;
1995 }
1996 if (buffer_info->range != VK_WHOLE_SIZE) {
1997 // Range must be VK_WHOLE_SIZE or > 0
1998 if (!buffer_info->range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06001999 *error_code = "VUID-VkDescriptorBufferInfo-range-00341";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002000 std::stringstream error_str;
2001 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002002 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002003 return false;
2004 }
2005 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
2006 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002007 *error_code = "VUID-VkDescriptorBufferInfo-range-00342";
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002008 std::stringstream error_str;
2009 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
2010 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002011 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002012 return false;
2013 }
2014 }
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002015 // Check buffer update sizes against device limits
2016 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type || VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
2017 auto max_ub_range = limits_.maxUniformBufferRange;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002018 if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_ub_range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002019 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332";
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002020 std::stringstream error_str;
2021 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range
2022 << " which is greater than this device's maxUniformBufferRange (" << max_ub_range << ")";
2023 *error_msg = error_str.str();
2024 return false;
Peter Kohaut2794a292018-07-13 11:13:47 +02002025 } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_ub_range) {
2026 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332";
2027 std::stringstream error_str;
Peter Kohaut18f413d2018-07-16 13:15:42 +02002028 error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range "
2029 << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's "
Peter Kohaut2794a292018-07-13 11:13:47 +02002030 << "maxUniformBufferRange (" << max_ub_range << ")";
2031 *error_msg = error_str.str();
2032 return false;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002033 }
2034 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type || VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
2035 auto max_sb_range = limits_.maxStorageBufferRange;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002036 if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_sb_range) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002037 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333";
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002038 std::stringstream error_str;
2039 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range
2040 << " which is greater than this device's maxStorageBufferRange (" << max_sb_range << ")";
2041 *error_msg = error_str.str();
2042 return false;
Peter Kohaut2794a292018-07-13 11:13:47 +02002043 } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_sb_range) {
2044 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333";
2045 std::stringstream error_str;
Peter Kohaut18f413d2018-07-16 13:15:42 +02002046 error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range "
2047 << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's "
Peter Kohaut2794a292018-07-13 11:13:47 +02002048 << "maxStorageBufferRange (" << max_sb_range << ")";
2049 *error_msg = error_str.str();
2050 return false;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -07002051 }
2052 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06002053 return true;
2054}
2055
Tobin Ehlis300888c2016-05-18 13:43:26 -06002056// Verify that the contents of the update are ok, but don't perform actual update
2057bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index,
Dave Houlton00c154e2018-05-24 13:20:50 -06002058 std::string *error_code, std::string *error_msg) const {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002059 switch (update->descriptorType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002060 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
2061 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2062 // Validate image
2063 auto image_view = update->pImageInfo[di].imageView;
2064 auto image_layout = update->pImageInfo[di].imageLayout;
2065 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002066 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002067 error_str << "Attempted write update to combined image sampler descriptor failed due to: "
2068 << error_msg->c_str();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002069 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06002070 return false;
2071 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002072 }
2073 }
Tobin Ehlis648b1cf2018-04-13 15:24:13 -06002074 // fall through
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002075 case VK_DESCRIPTOR_TYPE_SAMPLER: {
2076 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2077 if (!descriptors_[index + di].get()->IsImmutableSampler()) {
2078 if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002079 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002080 std::stringstream error_str;
2081 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
2082 << update->pImageInfo[di].sampler << ".";
2083 *error_msg = error_str.str();
2084 return false;
2085 }
2086 } else {
2087 // TODO : Warn here
2088 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002089 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002090 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002091 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002092 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
2093 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
2094 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
2095 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2096 auto image_view = update->pImageInfo[di].imageView;
2097 auto image_layout = update->pImageInfo[di].imageLayout;
2098 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
2099 std::stringstream error_str;
2100 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
2101 *error_msg = error_str.str();
2102 return false;
2103 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002104 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002105 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002106 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002107 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
2108 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
2109 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2110 auto buffer_view = update->pTexelBufferView[di];
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002111 auto bv_state = GetBufferViewState(device_data_, buffer_view);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002112 if (!bv_state) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002113 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002114 std::stringstream error_str;
2115 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
2116 *error_msg = error_str.str();
2117 return false;
2118 }
2119 auto buffer = bv_state->create_info.buffer;
Tobin Ehlisdf0d62a2017-10-11 08:48:00 -06002120 auto buffer_state = GetBufferState(device_data_, buffer);
2121 // Verify that buffer underlying the view hasn't been destroyed prematurely
2122 if (!buffer_state) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002123 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
Tobin Ehlisdf0d62a2017-10-11 08:48:00 -06002124 std::stringstream error_str;
2125 error_str << "Attempted write update to texel buffer descriptor failed because underlying buffer (" << buffer
2126 << ") has been destroyed: " << error_msg->c_str();
2127 *error_msg = error_str.str();
2128 return false;
2129 } else if (!ValidateBufferUsage(buffer_state, update->descriptorType, error_code, error_msg)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002130 std::stringstream error_str;
2131 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
2132 *error_msg = error_str.str();
2133 return false;
2134 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002135 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002136 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002137 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002138 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
2139 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
2140 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
2141 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
2142 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
2143 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) {
2144 std::stringstream error_str;
2145 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
2146 *error_msg = error_str.str();
2147 return false;
2148 }
2149 }
2150 break;
2151 }
Jeff Bolze54ae892018-09-08 12:16:29 -05002152 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
2153 break;
Jeff Bolzfbe51582018-09-13 10:01:35 -05002154 case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NVX:
2155 // XXX TODO
2156 break;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002157 default:
2158 assert(0); // We've already verified update type so should never get here
2159 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002160 }
2161 // All checks passed so update contents are good
2162 return true;
2163}
2164// Verify that the contents of the update are ok, but don't perform actual update
2165bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set,
Dave Houlton00c154e2018-05-24 13:20:50 -06002166 VkDescriptorType type, uint32_t index, std::string *error_code,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002167 std::string *error_msg) const {
2168 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
2169 // for write updates
Tobin Ehlis300888c2016-05-18 13:43:26 -06002170 switch (src_set->descriptors_[index]->descriptor_class) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002171 case PlainSampler: {
2172 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02002173 const auto src_desc = src_set->descriptors_[index + di].get();
2174 if (!src_desc->updated) continue;
2175 if (!src_desc->IsImmutableSampler()) {
2176 auto update_sampler = static_cast<SamplerDescriptor *>(src_desc)->GetSampler();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002177 if (!ValidateSampler(update_sampler, device_data_)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002178 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002179 std::stringstream error_str;
2180 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
2181 *error_msg = error_str.str();
2182 return false;
2183 }
2184 } else {
2185 // TODO : Warn here
2186 }
2187 }
2188 break;
2189 }
2190 case ImageSampler: {
2191 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02002192 const auto src_desc = src_set->descriptors_[index + di].get();
2193 if (!src_desc->updated) continue;
2194 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_desc);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002195 // First validate sampler
2196 if (!img_samp_desc->IsImmutableSampler()) {
2197 auto update_sampler = img_samp_desc->GetSampler();
2198 if (!ValidateSampler(update_sampler, device_data_)) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002199 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002200 std::stringstream error_str;
2201 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
2202 *error_msg = error_str.str();
2203 return false;
2204 }
2205 } else {
2206 // TODO : Warn here
2207 }
2208 // Validate image
2209 auto image_view = img_samp_desc->GetImageView();
2210 auto image_layout = img_samp_desc->GetImageLayout();
2211 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002212 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002213 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002214 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06002215 return false;
2216 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002217 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002218 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002219 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002220 case Image: {
2221 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02002222 const auto src_desc = src_set->descriptors_[index + di].get();
2223 if (!src_desc->updated) continue;
2224 auto img_desc = static_cast<const ImageDescriptor *>(src_desc);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002225 auto image_view = img_desc->GetImageView();
2226 auto image_layout = img_desc->GetImageLayout();
2227 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06002228 std::stringstream error_str;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002229 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06002230 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06002231 return false;
2232 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002233 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002234 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002235 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002236 case TexelBuffer: {
2237 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02002238 const auto src_desc = src_set->descriptors_[index + di].get();
2239 if (!src_desc->updated) continue;
2240 auto buffer_view = static_cast<TexelDescriptor *>(src_desc)->GetBufferView();
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002241 auto bv_state = GetBufferViewState(device_data_, buffer_view);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002242 if (!bv_state) {
Dave Houlton00c154e2018-05-24 13:20:50 -06002243 *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002244 std::stringstream error_str;
2245 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
2246 *error_msg = error_str.str();
2247 return false;
2248 }
2249 auto buffer = bv_state->create_info.buffer;
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002250 if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002251 std::stringstream error_str;
2252 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
2253 *error_msg = error_str.str();
2254 return false;
2255 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06002256 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002257 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002258 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002259 case GeneralBuffer: {
2260 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Józef Kucia5297e372017-10-13 22:31:34 +02002261 const auto src_desc = src_set->descriptors_[index + di].get();
2262 if (!src_desc->updated) continue;
2263 auto buffer = static_cast<BufferDescriptor *>(src_desc)->GetBuffer();
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002264 if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002265 std::stringstream error_str;
2266 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
2267 *error_msg = error_str.str();
2268 return false;
2269 }
Tobin Ehliscbcf2342016-05-24 13:07:12 -06002270 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002271 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002272 }
Jeff Bolze54ae892018-09-08 12:16:29 -05002273 case InlineUniform:
Jeff Bolzfbe51582018-09-13 10:01:35 -05002274 case AccelerationStructure:
Jeff Bolze54ae892018-09-08 12:16:29 -05002275 break;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002276 default:
2277 assert(0); // We've already verified update type so should never get here
2278 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06002279 }
2280 // All checks passed so update contents are good
2281 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12002282}
Tobin Ehlisf320b192017-03-14 11:22:50 -06002283// Update the common AllocateDescriptorSetsData
2284void cvdescriptorset::UpdateAllocateDescriptorSetsData(const layer_data *dev_data, const VkDescriptorSetAllocateInfo *p_alloc_info,
2285 AllocateDescriptorSetsData *ds_data) {
2286 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
2287 auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
2288 if (layout) {
2289 ds_data->layout_nodes[i] = layout;
2290 // Count total descriptors required per type
2291 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
2292 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
2293 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
2294 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
2295 }
2296 }
2297 // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
2298 }
Petr Kraus13c98a62017-12-09 00:22:39 +01002299}
Tobin Ehlisee471462016-05-26 11:21:59 -06002300// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Tobin Ehlisf320b192017-03-14 11:22:50 -06002301bool cvdescriptorset::ValidateAllocateDescriptorSets(const core_validation::layer_data *dev_data,
2302 const VkDescriptorSetAllocateInfo *p_alloc_info,
2303 const AllocateDescriptorSetsData *ds_data) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002304 bool skip = false;
Tobin Ehlisf320b192017-03-14 11:22:50 -06002305 auto report_data = core_validation::GetReportData(dev_data);
Jeff Bolzfdf96072018-04-10 14:32:18 -05002306 auto pool_state = GetDescriptorPoolState(dev_data, p_alloc_info->descriptorPool);
Tobin Ehlisee471462016-05-26 11:21:59 -06002307
2308 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlisb2e1e2c2017-02-08 09:16:32 -07002309 auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
John Zulauf5562d062018-01-24 11:54:05 -07002310 if (layout) { // nullptr layout indicates no valid layout handle for this device, validated/logged in object_tracker
2311 if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR) {
2312 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 -06002313 HandleToUint64(p_alloc_info->pSetLayouts[i]), "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-00308",
John Zulauf5562d062018-01-24 11:54:05 -07002314 "Layout 0x%" PRIxLEAST64 " specified at pSetLayouts[%" PRIu32
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002315 "] in vkAllocateDescriptorSets() was created with invalid flag %s set.",
John Zulauf5562d062018-01-24 11:54:05 -07002316 HandleToUint64(p_alloc_info->pSetLayouts[i]), i,
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002317 "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR");
John Zulauf5562d062018-01-24 11:54:05 -07002318 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05002319 if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT &&
2320 !(pool_state->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) {
2321 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 -06002322 0, "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-03044",
Jeff Bolzfdf96072018-04-10 14:32:18 -05002323 "Descriptor set layout create flags and pool create flags mismatch for index (%d)", i);
2324 }
Tobin Ehlisee471462016-05-26 11:21:59 -06002325 }
2326 }
Mark Lobodzinski28426ae2017-06-01 07:56:38 -06002327 if (!GetDeviceExtensions(dev_data)->vk_khr_maintenance1) {
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002328 // Track number of descriptorSets allowable in this pool
2329 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002330 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 -06002331 HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorSetCount-00306",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002332 "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002333 ". This pool only has %d descriptorSets remaining.",
2334 p_alloc_info->descriptorSetCount, HandleToUint64(pool_state->pool), pool_state->availableSets);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002335 }
2336 // Determine whether descriptor counts are satisfiable
Jeff Bolze54ae892018-09-08 12:16:29 -05002337 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
2338 if (ds_data->required_descriptors_by_type.at(it->first) > pool_state->availableDescriptorTypeCount[it->first]) {
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002339 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 -06002340 HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorPool-00307",
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002341 "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64
Mark Lobodzinski487a0d12018-03-30 10:09:03 -06002342 ". This pool only has %d descriptors of this type remaining.",
Jeff Bolze54ae892018-09-08 12:16:29 -05002343 ds_data->required_descriptors_by_type.at(it->first), string_VkDescriptorType(VkDescriptorType(it->first)),
2344 HandleToUint64(pool_state->pool), pool_state->availableDescriptorTypeCount[it->first]);
Mike Schuchardt64b5bb72017-03-21 16:33:26 -06002345 }
Tobin Ehlisee471462016-05-26 11:21:59 -06002346 }
2347 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06002348
Jeff Bolzfdf96072018-04-10 14:32:18 -05002349 const auto *count_allocate_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext);
2350
2351 if (count_allocate_info) {
2352 if (count_allocate_info->descriptorSetCount != 0 &&
2353 count_allocate_info->descriptorSetCount != p_alloc_info->descriptorSetCount) {
2354 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 -06002355 "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-descriptorSetCount-03045",
Jeff Bolzfdf96072018-04-10 14:32:18 -05002356 "VkDescriptorSetAllocateInfo::descriptorSetCount (%d) != "
2357 "VkDescriptorSetVariableDescriptorCountAllocateInfoEXT::descriptorSetCount (%d)",
2358 p_alloc_info->descriptorSetCount, count_allocate_info->descriptorSetCount);
2359 }
2360 if (count_allocate_info->descriptorSetCount == p_alloc_info->descriptorSetCount) {
2361 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
2362 auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
2363 if (count_allocate_info->pDescriptorCounts[i] > layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())) {
2364 skip |= log_msg(
2365 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 -06002366 "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-pSetLayouts-03046",
2367 "pDescriptorCounts[%d] = (%d), binding's descriptorCount = (%d)", i,
Jeff Bolzfdf96072018-04-10 14:32:18 -05002368 count_allocate_info->pDescriptorCounts[i], layout->GetDescriptorCountFromBinding(layout->GetMaxBinding()));
2369 }
2370 }
2371 }
2372 }
2373
Mark Lobodzinskibdc3b022017-04-24 09:11:35 -06002374 return skip;
Tobin Ehlisee471462016-05-26 11:21:59 -06002375}
2376// Decrement allocated sets from the pool and insert new sets into set_map
Tobin Ehlis4e380592016-06-02 12:41:47 -06002377void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
2378 const VkDescriptorSet *descriptor_sets,
2379 const AllocateDescriptorSetsData *ds_data,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -06002380 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map,
Tobin Ehlis4e380592016-06-02 12:41:47 -06002381 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map,
John Zulauf48a6a702017-12-22 17:14:54 -07002382 layer_data *dev_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06002383 auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
Mark Lobodzinskic9430182017-06-13 13:00:05 -06002384 // Account for sets and individual descriptors allocated from pool
Tobin Ehlisee471462016-05-26 11:21:59 -06002385 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Jeff Bolze54ae892018-09-08 12:16:29 -05002386 for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) {
2387 pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06002388 }
Jeff Bolzfdf96072018-04-10 14:32:18 -05002389
2390 const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext);
2391 bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount;
2392
Mark Lobodzinskic9430182017-06-13 13:00:05 -06002393 // Create tracking object for each descriptor set; insert into global map and the pool's set.
Tobin Ehlisee471462016-05-26 11:21:59 -06002394 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Jeff Bolzfdf96072018-04-10 14:32:18 -05002395 uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0;
2396
Tobin Ehlis93f22372016-10-12 14:34:12 -06002397 auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i],
Jeff Bolzfdf96072018-04-10 14:32:18 -05002398 variable_count, dev_data);
Tobin Ehlisee471462016-05-26 11:21:59 -06002399
2400 pool_state->sets.insert(new_ds);
2401 new_ds->in_use.store(0);
2402 (*set_map)[descriptor_sets[i]] = new_ds;
2403 }
2404}
John Zulauf48a6a702017-12-22 17:14:54 -07002405
2406cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map,
2407 GLOBAL_CB_NODE *cb_state)
2408 : filtered_map_(), orig_map_(in_map) {
2409 if (ds.GetTotalDescriptorCount() > kManyDescriptors_) {
2410 filtered_map_.reset(new std::map<uint32_t, descriptor_req>());
2411 ds.FilterAndTrackBindingReqs(cb_state, orig_map_, filtered_map_.get());
2412 }
2413}
2414cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map,
2415 GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *pipeline)
2416 : filtered_map_(), orig_map_(in_map) {
2417 if (ds.GetTotalDescriptorCount() > kManyDescriptors_) {
2418 filtered_map_.reset(new std::map<uint32_t, descriptor_req>());
2419 ds.FilterAndTrackBindingReqs(cb_state, pipeline, orig_map_, filtered_map_.get());
2420 }
Artem Kharytoniuk2456f992018-01-12 14:17:41 +01002421}