blob: 52c0b33939c44ad6ce34f81193b776c9fe19acc4 [file] [log] [blame]
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
5 *
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>
19 */
20
21#include "descriptor_sets.h"
22#include "vk_enum_string_helper.h"
23#include "vk_safe_struct.h"
24#include <sstream>
25
26// Construct DescriptorSetLayout instance from given create info
Tobin Ehlis154c2692016-10-25 09:36:53 -060027cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060028 const VkDescriptorSetLayout layout)
29 : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) {
30 uint32_t global_index = 0;
31 for (uint32_t i = 0; i < binding_count_; ++i) {
32 descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
Tobin Ehlis154c2692016-10-25 09:36:53 -060033 binding_to_index_map_.emplace(p_create_info->pBindings[i].binding, i);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060034 binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index;
35 global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0;
36 binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index;
Tobin Ehlis789c4ed2016-10-17 13:51:57 -060037 global_index += p_create_info->pBindings[i].descriptorCount ? 1 : 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060038 bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i]));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060039 // In cases where we should ignore pImmutableSamplers make sure it's NULL
40 if ((p_create_info->pBindings[i].pImmutableSamplers) &&
41 ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) &&
42 (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060043 bindings_.back().pImmutableSamplers = nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060044 }
45 if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
46 p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Tobin Ehlisef0de162016-06-20 13:07:34 -060047 dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060048 }
49 }
50}
Tobin Ehlis154c2692016-10-25 09:36:53 -060051
52// Validate descriptor set layout create info
53bool cvdescriptorset::DescriptorSetLayout::ValidateCreateInfo(debug_report_data *report_data,
54 const VkDescriptorSetLayoutCreateInfo *create_info) {
55 bool skip = false;
56 std::unordered_set<uint32_t> bindings;
57 for (uint32_t i = 0; i < create_info->bindingCount; ++i) {
58 if (bindings.count(create_info->pBindings[i].binding)) {
59 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
60 VALIDATION_ERROR_02345, "DS", "duplicated binding number in VkDescriptorSetLayoutBinding. %s",
61 validation_error_map[VALIDATION_ERROR_02345]);
62 }
63 bindings.insert(create_info->pBindings[i].binding);
64 }
65 return skip;
66}
67
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060068// put all bindings into the given set
69void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const {
70 for (auto binding_index_pair : binding_to_index_map_)
71 binding_set->insert(binding_index_pair.first);
72}
Tobin Ehlis56a30942016-05-19 08:00:00 -060073
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060074VkDescriptorSetLayoutBinding const *
75cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060076 const auto &bi_itr = binding_to_index_map_.find(binding);
77 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060078 return bindings_[bi_itr->second].ptr();
Tobin Ehlis0bc30632016-05-05 10:16:02 -060079 }
80 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060081}
82VkDescriptorSetLayoutBinding const *
83cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
84 if (index >= bindings_.size())
85 return nullptr;
Tobin Ehlis664e6012016-05-05 11:04:44 -060086 return bindings_[index].ptr();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060087}
88// Return descriptorCount for given binding, 0 if index is unavailable
89uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060090 const auto &bi_itr = binding_to_index_map_.find(binding);
91 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060092 return bindings_[bi_itr->second].descriptorCount;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060093 }
94 return 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060095}
96// Return descriptorCount for given index, 0 if index is unavailable
97uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const {
98 if (index >= bindings_.size())
99 return 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600100 return bindings_[index].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600101}
102// For the given binding, return descriptorType
103VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const {
104 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600105 const auto &bi_itr = binding_to_index_map_.find(binding);
106 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600107 return bindings_[bi_itr->second].descriptorType;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600108 }
109 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600110}
111// For the given index, return descriptorType
112VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const {
113 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600114 return bindings_[index].descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600115}
116// For the given global index, return descriptorType
117// Currently just counting up through bindings_, may improve this in future
118VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const {
119 uint32_t global_offset = 0;
120 for (auto binding : bindings_) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600121 global_offset += binding.descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600122 if (index < global_offset)
Tobin Ehlis664e6012016-05-05 11:04:44 -0600123 return binding.descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600124 }
125 assert(0); // requested global index is out of bounds
126 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
127}
128// For the given binding, return stageFlags
129VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const {
130 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600131 const auto &bi_itr = binding_to_index_map_.find(binding);
132 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600133 return bindings_[bi_itr->second].stageFlags;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600134 }
135 return VkShaderStageFlags(0);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600136}
137// For the given binding, return start index
138uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const {
139 assert(binding_to_global_start_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600140 const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding);
141 if (btgsi_itr != binding_to_global_start_index_map_.end()) {
142 return btgsi_itr->second;
143 }
144 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600145 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600146 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600147}
148// For the given binding, return end index
149uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const {
150 assert(binding_to_global_end_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600151 const auto &btgei_itr = binding_to_global_end_index_map_.find(binding);
152 if (btgei_itr != binding_to_global_end_index_map_.end()) {
153 return btgei_itr->second;
154 }
155 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600156 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600157 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600158}
159// For given binding, return ptr to ImmutableSampler array
160VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
161 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600162 const auto &bi_itr = binding_to_index_map_.find(binding);
163 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600164 return bindings_[bi_itr->second].pImmutableSamplers;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600165 }
166 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600167}
168// For given index, return ptr to ImmutableSampler array
169VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
170 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600171 return bindings_[index].pImmutableSamplers;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600172}
173// If our layout is compatible with rh_ds_layout, return true,
174// else return false and fill in error_msg will description of what causes incompatibility
175bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const {
176 // Trivial case
177 if (layout_ == rh_ds_layout->GetDescriptorSetLayout())
178 return true;
179 if (descriptor_count_ != rh_ds_layout->descriptor_count_) {
180 std::stringstream error_str;
181 error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
182 << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors.";
183 *error_msg = error_str.str();
184 return false; // trivial fail case
185 }
186 // Descriptor counts match so need to go through bindings one-by-one
187 // and verify that type and stageFlags match
188 for (auto binding : bindings_) {
189 // TODO : Do we also need to check immutable samplers?
190 // VkDescriptorSetLayoutBinding *rh_binding;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600191 if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600192 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600193 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of "
194 << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600195 << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600196 << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600197 *error_msg = error_str.str();
198 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600199 } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600200 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600201 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '"
202 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600203 << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '"
Tobin Ehlis664e6012016-05-05 11:04:44 -0600204 << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600205 *error_msg = error_str.str();
206 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600207 } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600208 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600209 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags "
210 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600211 << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600212 << rh_ds_layout->GetStageFlagsFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600213 *error_msg = error_str.str();
214 return false;
215 }
216 }
217 return true;
218}
219
220bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const {
221 if (!binding_to_index_map_.count(binding + 1))
222 return false;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600223 auto const &bi_itr = binding_to_index_map_.find(binding);
224 if (bi_itr != binding_to_index_map_.end()) {
225 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
226 if (next_bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600227 auto type = bindings_[bi_itr->second].descriptorType;
228 auto stage_flags = bindings_[bi_itr->second].stageFlags;
229 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
230 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
231 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
232 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) {
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600233 return false;
234 }
235 return true;
236 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600237 }
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600238 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600239}
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600240// Starting at offset descriptor of given binding, parse over update_count
241// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
242// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
243// If so, return true. If not, fill in error_msg and return false
244bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count,
245 const char *type, const VkDescriptorSet set,
246 std::string *error_msg) const {
247 // Verify consecutive bindings match (if needed)
248 auto orig_binding = current_binding;
249 // Track count of descriptors in the current_bindings that are remaining to be updated
250 auto binding_remaining = GetDescriptorCountFromBinding(current_binding);
251 // First, it's legal to offset beyond your own binding so handle that case
252 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
253 while (offset >= binding_remaining) {
254 // Advance to next binding, decrement offset by binding size
255 offset -= binding_remaining;
256 binding_remaining = GetDescriptorCountFromBinding(++current_binding);
257 }
258 binding_remaining -= offset;
259 while (update_count > binding_remaining) { // While our updates overstep current binding
260 // Verify next consecutive binding matches type, stage flags & immutable sampler use
261 if (!IsNextBindingConsistent(current_binding++)) {
262 std::stringstream error_str;
263 error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #"
264 << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the "
265 "next binding is not consistent with current binding so this update is invalid.";
266 *error_msg = error_str.str();
267 return false;
268 }
269 // For sake of this check consider the bindings updated and grab count for next binding
270 update_count -= binding_remaining;
271 binding_remaining = GetDescriptorCountFromBinding(current_binding);
272 }
273 return true;
274}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600275
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600276cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
277 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
278
Tobin Ehlis93f22372016-10-12 14:34:12 -0600279cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
280 const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data)
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600281 : some_update_(false), set_(set), pool_state_(nullptr), p_layout_(layout), device_data_(dev_data) {
282 pool_state_ = getDescriptorPoolState(dev_data, pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600283 // Foreach binding, create default descriptors of given type
284 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
285 auto type = p_layout_->GetTypeFromIndex(i);
286 switch (type) {
287 case VK_DESCRIPTOR_TYPE_SAMPLER: {
288 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
289 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
290 if (immut_sampler)
Chris Forbescb621ea2016-05-30 11:47:31 +1200291 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600292 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200293 descriptors_.emplace_back(new SamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600294 }
295 break;
296 }
297 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
298 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
299 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
300 if (immut)
Chris Forbescb621ea2016-05-30 11:47:31 +1200301 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600302 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200303 descriptors_.emplace_back(new ImageSamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600304 }
305 break;
306 }
307 // ImageDescriptors
308 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
309 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
310 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
311 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200312 descriptors_.emplace_back(new ImageDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600313 break;
314 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
315 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
316 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200317 descriptors_.emplace_back(new TexelDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600318 break;
319 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
320 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
321 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
322 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
323 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200324 descriptors_.emplace_back(new BufferDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600325 break;
326 default:
Tobin Ehlis81f17852016-05-05 09:04:33 -0600327 assert(0); // Bad descriptor type specified
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600328 break;
329 }
330 }
331}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600332
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600333cvdescriptorset::DescriptorSet::~DescriptorSet() {
334 InvalidateBoundCmdBuffers();
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600335}
Chris Forbes57989132016-07-26 17:06:10 +1200336
337
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700338static std::string string_descriptor_req_view_type(descriptor_req req) {
339 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200340 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
341 if (req & (1 << i)) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700342 if (result.size()) result += ", ";
343 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200344 }
345 }
346
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700347 if (!result.size())
348 result = "(none)";
349
350 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200351}
352
353
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600354// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
355bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const {
356 return layout->IsCompatible(p_layout_, error);
357}
Chris Forbes57989132016-07-26 17:06:10 +1200358
Tobin Ehlis3066db62016-08-22 08:12:23 -0600359// 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 -0600360// This includes validating that all descriptors in the given bindings are updated,
361// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
362// Return true if state is acceptable, or false and write an error message into error string
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600363bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600364 const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
iostrows5eb97652016-06-02 15:56:26 +0200365 auto dyn_offset_index = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200366 for (auto binding_pair : bindings) {
367 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600368 if (!p_layout_->HasBinding(binding)) {
369 std::stringstream error_str;
370 error_str << "Attempting to validate DrawState for binding #" << binding
371 << " which is an invalid binding for this descriptor set.";
372 *error = error_str.str();
373 return false;
374 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600375 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600376 if (descriptors_[start_idx]->IsImmutableSampler()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600377 // Nothing to do for strictly immutable sampler
378 } else {
379 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600380 for (uint32_t i = start_idx; i <= end_idx; ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600381 if (!descriptors_[i]->updated) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600382 std::stringstream error_str;
383 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
384 << " is being used in draw but has not been updated.";
385 *error = error_str.str();
386 return false;
387 } else {
Chris Forbes57989132016-07-26 17:06:10 +1200388 auto descriptor_class = descriptors_[i]->GetClass();
389 if (descriptor_class == GeneralBuffer) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600390 // Verify that buffers are valid
Tobin Ehlis81f17852016-05-05 09:04:33 -0600391 auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer();
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600392 auto buffer_node = getBufferNode(device_data_, buffer);
393 if (!buffer_node) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600394 std::stringstream error_str;
395 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
396 << " references invalid buffer " << buffer << ".";
397 *error = error_str.str();
398 return false;
399 } else {
Tobin Ehlis54108272016-10-11 14:26:49 -0600400 auto mem_entry = getMemObjInfo(device_data_, buffer_node->binding.mem);
Tobin Ehlis997b2582016-06-02 08:43:37 -0600401 if (!mem_entry) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600402 std::stringstream error_str;
403 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
Tobin Ehlis54108272016-10-11 14:26:49 -0600404 << " uses buffer " << buffer << " that references invalid memory "
405 << buffer_node->binding.mem << ".";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600406 *error = error_str.str();
407 return false;
408 }
409 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600410 if (descriptors_[i]->IsDynamic()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600411 // Validate that dynamic offsets are within the buffer
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600412 auto buffer_size = buffer_node->createInfo.size;
Tobin Ehlis81f17852016-05-05 09:04:33 -0600413 auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange();
414 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600415 auto dyn_offset = dynamic_offsets[dyn_offset_index++];
416 if (VK_WHOLE_SIZE == range) {
417 if ((dyn_offset + desc_offset) > buffer_size) {
418 std::stringstream error_str;
419 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
420 << " uses buffer " << buffer
421 << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
422 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
423 << buffer_size << ".";
424 *error = error_str.str();
425 return false;
426 }
427 } else {
428 if ((dyn_offset + desc_offset + range) > buffer_size) {
429 std::stringstream error_str;
430 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
431 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
432 << " combined with offset " << desc_offset << " and range " << range
433 << " that oversteps the buffer size of " << buffer_size << ".";
434 *error = error_str.str();
435 return false;
436 }
437 }
438 }
439 }
Chris Forbes57989132016-07-26 17:06:10 +1200440 else if (descriptor_class == ImageSampler || descriptor_class == Image) {
441 auto image_view = (descriptor_class == ImageSampler)
442 ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView()
443 : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView();
444 auto reqs = binding_pair.second;
445
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600446 auto image_view_state = getImageViewState(device_data_, image_view);
447 assert(image_view_state);
448 auto image_view_ci = image_view_state->create_info;
Chris Forbes57989132016-07-26 17:06:10 +1200449
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600450 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
Chris Forbes57989132016-07-26 17:06:10 +1200451 // bad view type
452 std::stringstream error_str;
453 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
454 << " requires an image view of type " << string_descriptor_req_view_type(reqs)
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600455 << " but got " << string_VkImageViewType(image_view_ci.viewType) << ".";
Chris Forbes57989132016-07-26 17:06:10 +1200456 *error = error_str.str();
457 return false;
458 }
459
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600460 auto image_node = getImageState(device_data_, image_view_ci.image);
Chris Forbes57989132016-07-26 17:06:10 +1200461 assert(image_node);
462
463 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) &&
464 image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
465 std::stringstream error_str;
466 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
467 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
468 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
469 *error = error_str.str();
470 return false;
471 }
472
473 if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) &&
474 image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
475 std::stringstream error_str;
476 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
477 << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
478 *error = error_str.str();
479 return false;
480 }
481 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600482 }
483 }
484 }
485 }
486 return true;
487}
Chris Forbes57989132016-07-26 17:06:10 +1200488
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600489// For given bindings, place any update buffers or images into the passed-in unordered_sets
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600490uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600491 std::unordered_set<VkBuffer> *buffer_set,
492 std::unordered_set<VkImageView> *image_set) const {
493 auto num_updates = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200494 for (auto binding_pair : bindings) {
495 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600496 // If a binding doesn't exist, skip it
497 if (!p_layout_->HasBinding(binding)) {
498 continue;
499 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600500 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600501 if (descriptors_[start_idx]->IsStorage()) {
502 if (Image == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600503 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600504 if (descriptors_[start_idx + i]->updated) {
505 image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600506 num_updates++;
507 }
508 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600509 } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600510 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600511 if (descriptors_[start_idx + i]->updated) {
512 auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -0600513 auto bv_state = getBufferViewState(device_data_, bufferview);
514 if (bv_state) {
515 buffer_set->insert(bv_state->create_info.buffer);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600516 num_updates++;
517 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600518 }
519 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600520 } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600521 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600522 if (descriptors_[start_idx + i]->updated) {
523 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600524 num_updates++;
525 }
526 }
527 }
528 }
529 }
530 return num_updates;
531}
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600532// Set is being deleted or updates so invalidate all bound cmd buffers
533void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() {
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600534 core_validation::invalidateCommandBuffers(cb_bindings,
535 {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT});
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600536}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600537// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600538void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600539 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
540 // perform update
541 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
542 descriptors_[start_idx + di]->WriteUpdate(update, di);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600543 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600544 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600545 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600546
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600547 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600548}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600549// Validate Copy update
550bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600551 const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code,
552 std::string *error_msg) {
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600553 // Verify idle ds
554 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600555 // TODO : Re-using Allocate Idle error code, need copy update idle error code
556 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600557 std::stringstream error_str;
558 error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
559 << " that is in use by a command buffer.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600560 *error_msg = error_str.str();
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600561 return false;
562 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600563 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600564 *error_code = VALIDATION_ERROR_00966;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600565 std::stringstream error_str;
566 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600567 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600568 return false;
569 }
570 if (!src_set->HasBinding(update->srcBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600571 *error_code = VALIDATION_ERROR_00964;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600572 std::stringstream error_str;
573 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600574 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600575 return false;
576 }
577 // src & dst set bindings are valid
578 // Check bounds of src & dst
579 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
580 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
581 // SRC update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600582 *error_code = VALIDATION_ERROR_00965;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600583 std::stringstream error_str;
584 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
585 << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding)
586 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
587 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600588 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600589 return false;
590 }
591 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
592 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
593 // DST update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600594 *error_code = VALIDATION_ERROR_00967;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600595 std::stringstream error_str;
596 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
597 << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
598 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
599 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600600 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600601 return false;
602 }
603 // Check that types match
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600604 // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more
605 // fine-grained error codes
606 *error_code = VALIDATION_ERROR_00968;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600607 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
608 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
609 if (src_type != dst_type) {
610 std::stringstream error_str;
611 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
612 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
613 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600614 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600615 return false;
616 }
617 // Verify consistency of src & dst bindings if update crosses binding boundaries
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600618 if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600619 "copy update from", src_set->GetSet(), error_msg)) ||
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600620 (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600621 set_, error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600622 return false;
623 }
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600624 // First make sure source descriptors are updated
625 for (uint32_t i = 0; i < update->descriptorCount; ++i) {
626 if (!src_set->descriptors_[src_start_idx + i]) {
627 std::stringstream error_str;
628 error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset "
629 << update->srcArrayElement + i << " has not been updated.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600630 *error_msg = error_str.str();
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600631 return false;
632 }
633 }
634 // Update parameters all look good and descriptor updated so verify update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600635 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg))
Tobin Ehlis300888c2016-05-18 13:43:26 -0600636 return false;
637
638 // All checks passed so update is good
639 return true;
640}
641// Perform Copy update
642void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600643 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
644 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600645 // Update parameters all look good so perform update
646 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600647 descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600648 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600649 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600650 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600651
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600652 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600653}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600654
Tobin Ehlisf9519102016-08-17 09:49:13 -0600655// Bind cb_node to this set and this set to cb_node.
656// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
657// to be used in a draw by the given cb_node
Tobin Ehlisf9519102016-08-17 09:49:13 -0600658void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, const std::unordered_set<uint32_t> &bindings) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600659 // bind cb to this descriptor set
660 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600661 // Add bindings for descriptor set, the set's pool, and individual objects in the set
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600662 cb_node->object_bindings.insert({reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT});
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600663 pool_state_->cb_bindings.insert(cb_node);
664 cb_node->object_bindings.insert(
665 {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT});
Tobin Ehlisf9519102016-08-17 09:49:13 -0600666 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
667 // resources
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600668 for (auto binding : bindings) {
669 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
670 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
671 for (uint32_t i = start_idx; i <= end_idx; ++i) {
672 descriptors_[i]->BindCommandBuffer(device_data_, cb_node);
673 }
674 }
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600675}
676
Tobin Ehlis300888c2016-05-18 13:43:26 -0600677cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600678 updated = false;
679 descriptor_class = PlainSampler;
680};
681
Tobin Ehlis300888c2016-05-18 13:43:26 -0600682cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600683 updated = false;
684 descriptor_class = PlainSampler;
685 if (immut) {
686 sampler_ = *immut;
687 immutable_ = true;
688 updated = true;
689 }
690}
Tobin Ehlise2f80292016-06-02 10:08:53 -0600691// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
692bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) {
693 return (getSamplerNode(dev_data, sampler) != nullptr);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600694}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600695
Tobin Ehlis554bf382016-05-24 11:14:43 -0600696bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600697 const core_validation::layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code,
698 std::string *error_msg) {
699 // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases.
700 *error_code = VALIDATION_ERROR_00943;
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600701 auto iv_state = getImageViewState(dev_data, image_view);
702 if (!iv_state) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600703 std::stringstream error_str;
704 error_str << "Invalid VkImageView: " << image_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600705 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600706 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600707 }
Tobin Ehlis81280962016-07-20 14:04:20 -0600708 // 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 -0600709 // Validate that imageLayout is compatible with aspect_mask and image format
710 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600711 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
712 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600713 VkFormat format = VK_FORMAT_MAX_ENUM;
714 VkImageUsageFlags usage = 0;
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600715 auto image_node = getImageState(dev_data, image);
Tobin Ehlis1c9c55f2016-06-02 11:49:22 -0600716 if (image_node) {
717 format = image_node->createInfo.format;
718 usage = image_node->createInfo.usage;
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600719 // Validate that memory is bound to image
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600720 if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600721 // TODO : Need new code(s) for language in 11.6 Memory Association
722 *error_msg = "No memory bound to image.";
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600723 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600724 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600725 } else {
Tobin Ehlis1809f912016-05-25 09:24:36 -0600726 // Also need to check the swapchains.
Tobin Ehlis969a5262016-06-02 12:13:32 -0600727 auto swapchain = getSwapchainFromImage(dev_data, image);
728 if (swapchain) {
Tobin Ehlis4e380592016-06-02 12:41:47 -0600729 auto swapchain_node = getSwapchainNode(dev_data, swapchain);
730 if (swapchain_node) {
731 format = swapchain_node->createInfo.imageFormat;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600732 }
733 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600734 }
735 // First validate that format and layout are compatible
736 if (format == VK_FORMAT_MAX_ENUM) {
737 std::stringstream error_str;
738 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600739 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600740 return false;
741 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600742 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
743 // vkCreateImageView(). What's the best way to create unique id for these cases?
Tobin Ehlis1809f912016-05-25 09:24:36 -0600744 bool ds = vk_format_is_depth_or_stencil(format);
745 switch (image_layout) {
746 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
747 // Only Color bit must be set
748 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600749 std::stringstream error_str;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600750 error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does "
751 "not have VK_IMAGE_ASPECT_COLOR_BIT set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600752 *error_msg = error_str.str();
Tobin Ehlis554bf382016-05-24 11:14:43 -0600753 return false;
754 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600755 // format must NOT be DS
756 if (ds) {
757 std::stringstream error_str;
758 error_str << "ImageView (" << image_view
759 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
760 << string_VkFormat(format) << " which is not a color format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600761 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600762 return false;
763 }
764 break;
765 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
766 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
767 // Depth or stencil bit must be set, but both must NOT be set
768 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
769 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
770 // both must NOT be set
771 std::stringstream error_str;
772 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600773 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600774 return false;
775 }
776 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
777 // Neither were set
778 std::stringstream error_str;
779 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
780 << " but does not have STENCIL or DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600781 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600782 return false;
783 }
784 // format must be DS
785 if (!ds) {
786 std::stringstream error_str;
787 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
788 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600789 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600790 return false;
791 }
792 break;
793 default:
Mike Weiblencce7ec72016-10-17 19:33:05 -0600794 // For other layouts if the source is depth/stencil image, both aspect bits must not be set
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600795 if (ds) {
796 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
797 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
798 // both must NOT be set
799 std::stringstream error_str;
800 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
801 << " and is using depth/stencil image of format " << string_VkFormat(format)
802 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
803 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
804 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
805 "reads respectively.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600806 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600807 return false;
808 }
809 }
810 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600811 break;
812 }
813 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600814 // 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 -0600815 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
816 // under vkCreateImage()
817 // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with
818 // identify swizzle
Tobin Ehlis1809f912016-05-25 09:24:36 -0600819 std::string error_usage_bit;
820 switch (type) {
821 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
822 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
823 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
824 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
825 }
826 break;
827 }
828 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
829 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
830 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600831 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
832 std::stringstream error_str;
833 // TODO : Need to create custom enum error code for this case
834 error_str << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
835 << string_VkImageLayout(image_layout)
836 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can "
837 "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
838 *error_msg = error_str.str();
839 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600840 }
841 break;
842 }
843 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
844 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
845 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
846 }
847 break;
848 }
849 default:
850 break;
851 }
852 if (!error_usage_bit.empty()) {
853 std::stringstream error_str;
854 error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage
855 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
856 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600857 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600858 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600859 }
860 return true;
861}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600862
Tobin Ehlis300888c2016-05-18 13:43:26 -0600863void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
864 sampler_ = update->pImageInfo[index].sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600865 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600866}
867
Tobin Ehlis300888c2016-05-18 13:43:26 -0600868void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600869 if (!immutable_) {
870 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600871 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600872 }
873 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600874}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600875
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600876void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
877 if (!immutable_) {
878 auto sampler_node = getSamplerNode(dev_data, sampler_);
879 if (sampler_node)
880 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
881 }
882}
883
Tobin Ehlis300888c2016-05-18 13:43:26 -0600884cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor()
885 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600886 updated = false;
887 descriptor_class = ImageSampler;
888}
889
Tobin Ehlis300888c2016-05-18 13:43:26 -0600890cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
891 : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600892 updated = false;
893 descriptor_class = ImageSampler;
894 if (immut) {
895 sampler_ = *immut;
896 immutable_ = true;
897 updated = true;
898 }
899}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600900
Tobin Ehlis300888c2016-05-18 13:43:26 -0600901void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600902 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600903 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600904 sampler_ = image_info.sampler;
905 image_view_ = image_info.imageView;
906 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600907}
908
Tobin Ehlis300888c2016-05-18 13:43:26 -0600909void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600910 if (!immutable_) {
911 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600912 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600913 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600914 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
915 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600916 updated = true;
917 image_view_ = image_view;
918 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600919}
920
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600921void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data,
922 GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600923 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600924 if (!immutable_) {
925 auto sampler_node = getSamplerNode(dev_data, sampler_);
926 if (sampler_node)
927 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
928 }
Tobin Ehlis81e46372016-08-17 13:33:44 -0600929 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600930 auto iv_state = getImageViewState(dev_data, image_view_);
931 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600932 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600933 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600934}
935
Tobin Ehlis300888c2016-05-18 13:43:26 -0600936cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
937 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600938 updated = false;
939 descriptor_class = Image;
940 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type)
941 storage_ = true;
942};
943
Tobin Ehlis300888c2016-05-18 13:43:26 -0600944void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600945 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600946 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600947 image_view_ = image_info.imageView;
948 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600949}
950
Tobin Ehlis300888c2016-05-18 13:43:26 -0600951void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600952 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
953 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600954 updated = true;
955 image_view_ = image_view;
956 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600957}
958
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600959void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600960 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600961 auto iv_state = getImageViewState(dev_data, image_view_);
962 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600963 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600964 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600965}
966
Tobin Ehlis300888c2016-05-18 13:43:26 -0600967cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
968 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600969 updated = false;
970 descriptor_class = GeneralBuffer;
971 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
972 dynamic_ = true;
973 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
974 storage_ = true;
975 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
976 dynamic_ = true;
977 storage_ = true;
978 }
979}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600980void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600981 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600982 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600983 buffer_ = buffer_info.buffer;
984 offset_ = buffer_info.offset;
985 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600986}
987
Tobin Ehlis300888c2016-05-18 13:43:26 -0600988void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
989 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600990 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600991 buffer_ = buff_desc->buffer_;
992 offset_ = buff_desc->offset_;
993 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600994}
995
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600996void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600997 auto buffer_node = getBufferNode(dev_data, buffer_);
998 if (buffer_node)
999 core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001000}
1001
Tobin Ehlis300888c2016-05-18 13:43:26 -06001002cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001003 updated = false;
1004 descriptor_class = TexelBuffer;
1005 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type)
1006 storage_ = true;
1007};
Tobin Ehlis56a30942016-05-19 08:00:00 -06001008
Tobin Ehlis300888c2016-05-18 13:43:26 -06001009void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001010 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001011 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001012}
1013
Tobin Ehlis300888c2016-05-18 13:43:26 -06001014void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1015 updated = true;
1016 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1017}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001018
1019void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis8b872462016-09-14 08:12:08 -06001020 auto bv_state = getBufferViewState(dev_data, buffer_view_);
1021 if (bv_state) {
Tobin Ehlis2515c0e2016-09-28 07:12:28 -06001022 core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001023 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001024}
1025
Tobin Ehlis300888c2016-05-18 13:43:26 -06001026// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1027// sets, and then calls their respective Validate[Write|Copy]Update functions.
1028// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1029// be skipped, then true is returned.
1030// If there is no issue with the update, then false is returned.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001031bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data,
1032 const core_validation::layer_data *dev_data, uint32_t write_count,
1033 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1034 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001035 bool skip_call = false;
1036 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001037 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001038 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001039 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1040 if (!set_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001041 skip_call |=
1042 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Tobin Ehlis56a30942016-05-19 08:00:00 -06001043 reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001044 "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.",
1045 reinterpret_cast<uint64_t &>(dest_set));
1046 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001047 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001048 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001049 if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001050 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001051 reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001052 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001053 " with error: %s. %s",
1054 reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001055 }
1056 }
1057 }
1058 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001059 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001060 auto dst_set = p_cds[i].dstSet;
1061 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001062 auto src_node = core_validation::getSetNode(dev_data, src_set);
1063 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1064 if (!src_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001065 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001066 reinterpret_cast<uint64_t &>(src_set), __LINE__, VALIDATION_ERROR_00971, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001067 "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001068 " that has not been allocated. %s",
1069 reinterpret_cast<uint64_t &>(src_set), validation_error_map[VALIDATION_ERROR_00971]);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001070 } else if (!dst_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001071 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001072 reinterpret_cast<uint64_t &>(dst_set), __LINE__, VALIDATION_ERROR_00972, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001073 "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001074 " that has not been allocated. %s",
1075 reinterpret_cast<uint64_t &>(dst_set), validation_error_map[VALIDATION_ERROR_00972]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001076 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001077 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001078 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001079 if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) {
1080 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1081 reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS",
1082 "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64
1083 " to Descriptor Set 0x%" PRIx64 " with error: %s. %s",
1084 reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set),
1085 error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001086 }
1087 }
1088 }
1089 return skip_call;
1090}
1091// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1092// sets, and then calls their respective Perform[Write|Copy]Update functions.
1093// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1094// with the same set of updates.
1095// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1096// calling down the chain.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001097void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count,
1098 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1099 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001100 // Write updates first
1101 uint32_t i = 0;
1102 for (i = 0; i < write_count; ++i) {
1103 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001104 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1105 if (set_node) {
1106 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001107 }
1108 }
1109 // Now copy updates
1110 for (i = 0; i < copy_count; ++i) {
1111 auto dst_set = p_cds[i].dstSet;
1112 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001113 auto src_node = core_validation::getSetNode(dev_data, src_set);
1114 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1115 if (src_node && dst_node) {
1116 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001117 }
1118 }
1119}
1120// Validate the state for a given write update but don't actually perform the update
1121// If an error would occur for this update, return false and fill in details in error_msg string
1122bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001123 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001124 // Verify idle ds
1125 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001126 // TODO : Re-using Allocate Idle error code, need write update idle error code
1127 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001128 std::stringstream error_str;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001129 error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
1130 << " that is in use by a command buffer.";
1131 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001132 return false;
1133 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001134 // Verify dst binding exists
1135 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001136 *error_code = VALIDATION_ERROR_00936;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001137 std::stringstream error_str;
1138 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << ".";
1139 *error_msg = error_str.str();
1140 return false;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001141 }
1142 // We know that binding is valid, verify update and do update on each descriptor
1143 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
1144 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
1145 if (type != update->descriptorType) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001146 *error_code = VALIDATION_ERROR_00937;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001147 std::stringstream error_str;
1148 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
1149 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
1150 *error_msg = error_str.str();
1151 return false;
1152 }
1153 if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001154 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001155 std::stringstream error_str;
1156 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1157 << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount
1158 << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
1159 << " combined with update array element offset of " << update->dstArrayElement
1160 << " oversteps the size of this descriptor set.";
1161 *error_msg = error_str.str();
1162 return false;
1163 }
1164 // Verify consecutive bindings match (if needed)
1165 if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001166 set_, error_msg)) {
1167 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001168 return false;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001169 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001170 // Update is within bounds and consistent so last step is to validate update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001171 if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) {
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001172 std::stringstream error_str;
1173 error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding
1174 << " failed with error message: " << error_msg->c_str();
1175 *error_msg = error_str.str();
1176 return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001177 }
1178 // All checks passed, update is clean
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001179 return true;
Tobin Ehlis03d61de2016-05-17 08:31:46 -06001180}
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001181// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001182// 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 -06001183bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_NODE const *buffer_node, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001184 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001185 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001186 auto usage = buffer_node->createInfo.usage;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001187 std::string error_usage_bit;
1188 switch (type) {
1189 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1190 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001191 *error_code = VALIDATION_ERROR_00950;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001192 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1193 }
1194 break;
1195 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1196 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001197 *error_code = VALIDATION_ERROR_00951;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001198 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1199 }
1200 break;
1201 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1202 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1203 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001204 *error_code = VALIDATION_ERROR_00946;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001205 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1206 }
1207 break;
1208 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1209 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1210 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001211 *error_code = VALIDATION_ERROR_00947;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001212 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1213 }
1214 break;
1215 default:
1216 break;
1217 }
1218 if (!error_usage_bit.empty()) {
1219 std::stringstream error_str;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001220 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage
1221 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1222 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001223 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001224 return false;
1225 }
1226 return true;
1227}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001228// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1229// 1. buffer is valid
1230// 2. buffer was created with correct usage flags
1231// 3. offset is less than buffer size
1232// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001233// 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 -06001234bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001235 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
1236 // TODO : Defaulting to 00962 for all cases here. Need to create new error codes for a few cases below.
1237 *error_code = VALIDATION_ERROR_00962;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001238 // First make sure that buffer is valid
1239 auto buffer_node = getBufferNode(device_data_, buffer_info->buffer);
1240 if (!buffer_node) {
1241 std::stringstream error_str;
1242 error_str << "Invalid VkBuffer: " << buffer_info->buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001243 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001244 return false;
1245 }
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001246 if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001247 // TODO : This is a repeat code, need new code(s) for language in 11.6 Memory Association
1248 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001249 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001250 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001251 // Verify usage bits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001252 if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
1253 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001254 return false;
1255 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001256 // TODO : Need to also validate device limit offset requirements captured in VALIDATION_ERROR_00944,945
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001257 // offset must be less than buffer size
1258 if (buffer_info->offset > buffer_node->createInfo.size) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001259 *error_code = VALIDATION_ERROR_00959;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001260 std::stringstream error_str;
1261 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer
1262 << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001263 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001264 return false;
1265 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001266 // TODO : Need to also validate device limit range requirements captured in VALIDATION_ERROR_00948,949
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001267 if (buffer_info->range != VK_WHOLE_SIZE) {
1268 // Range must be VK_WHOLE_SIZE or > 0
1269 if (!buffer_info->range) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001270 *error_code = VALIDATION_ERROR_00960;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001271 std::stringstream error_str;
1272 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001273 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001274 return false;
1275 }
1276 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
1277 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001278 *error_code = VALIDATION_ERROR_00961;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001279 std::stringstream error_str;
1280 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
1281 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001282 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001283 return false;
1284 }
1285 }
1286 return true;
1287}
1288
Tobin Ehlis300888c2016-05-18 13:43:26 -06001289// Verify that the contents of the update are ok, but don't perform actual update
1290bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001291 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1292 std::string *error_msg) const {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001293 switch (update->descriptorType) {
1294 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1295 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1296 // Validate image
1297 auto image_view = update->pImageInfo[di].imageView;
1298 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001299 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001300 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001301 error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1302 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001303 return false;
1304 }
1305 }
1306 // Intentional fall-through to validate sampler
1307 }
1308 case VK_DESCRIPTOR_TYPE_SAMPLER: {
1309 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1310 if (!descriptors_[index + di].get()->IsImmutableSampler()) {
Tobin Ehlise2f80292016-06-02 10:08:53 -06001311 if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001312 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001313 std::stringstream error_str;
1314 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
1315 << update->pImageInfo[di].sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001316 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001317 return false;
1318 }
1319 } else {
1320 // TODO : Warn here
1321 }
1322 }
1323 break;
1324 }
1325 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1326 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1327 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1328 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1329 auto image_view = update->pImageInfo[di].imageView;
1330 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001331 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001332 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001333 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
1334 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001335 return false;
1336 }
1337 }
1338 break;
1339 }
1340 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1341 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
1342 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1343 auto buffer_view = update->pTexelBufferView[di];
Tobin Ehlis8b872462016-09-14 08:12:08 -06001344 auto bv_state = getBufferViewState(device_data_, buffer_view);
1345 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001346 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001347 std::stringstream error_str;
1348 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001349 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001350 return false;
1351 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001352 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001353 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), update->descriptorType, error_code, error_msg)) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001354 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001355 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
1356 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001357 return false;
1358 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001359 }
1360 break;
1361 }
1362 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1363 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1364 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1365 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1366 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001367 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001368 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001369 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
1370 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001371 return false;
1372 }
1373 }
1374 break;
1375 }
1376 default:
1377 assert(0); // We've already verified update type so should never get here
1378 break;
1379 }
1380 // All checks passed so update contents are good
1381 return true;
1382}
1383// Verify that the contents of the update are ok, but don't perform actual update
1384bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001385 VkDescriptorType type, uint32_t index,
1386 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1387 std::string *error_msg) const {
1388 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
1389 // for write updates
Tobin Ehlis300888c2016-05-18 13:43:26 -06001390 switch (src_set->descriptors_[index]->descriptor_class) {
1391 case PlainSampler: {
1392 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1393 if (!src_set->descriptors_[index + di]->IsImmutableSampler()) {
1394 auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001395 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001396 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001397 std::stringstream error_str;
1398 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001399 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001400 return false;
1401 }
1402 } else {
1403 // TODO : Warn here
1404 }
1405 }
1406 break;
1407 }
1408 case ImageSampler: {
1409 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1410 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get());
1411 // First validate sampler
1412 if (!img_samp_desc->IsImmutableSampler()) {
1413 auto update_sampler = img_samp_desc->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001414 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001415 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001416 std::stringstream error_str;
1417 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001418 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001419 return false;
1420 }
1421 } else {
1422 // TODO : Warn here
1423 }
1424 // Validate image
1425 auto image_view = img_samp_desc->GetImageView();
1426 auto image_layout = img_samp_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001427 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001428 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001429 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1430 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001431 return false;
1432 }
1433 }
Alex Smithd8f14792016-09-23 12:18:51 +01001434 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001435 }
1436 case Image: {
1437 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1438 auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get());
1439 auto image_view = img_desc->GetImageView();
1440 auto image_layout = img_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001441 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001442 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001443 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
1444 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001445 return false;
1446 }
1447 }
1448 break;
1449 }
1450 case TexelBuffer: {
1451 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1452 auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -06001453 auto bv_state = getBufferViewState(device_data_, buffer_view);
1454 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001455 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001456 std::stringstream error_str;
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001457 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001458 *error_msg = error_str.str();
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001459 return false;
1460 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001461 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001462 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001463 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001464 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
1465 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001466 return false;
1467 }
1468 }
1469 break;
1470 }
1471 case GeneralBuffer: {
1472 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1473 auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001474 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001475 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001476 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
1477 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001478 return false;
1479 }
1480 }
1481 break;
1482 }
1483 default:
1484 assert(0); // We've already verified update type so should never get here
1485 break;
1486 }
1487 // All checks passed so update contents are good
1488 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12001489}
Tobin Ehlisee471462016-05-26 11:21:59 -06001490// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Tobin Ehlis815e8132016-06-02 13:02:17 -06001491bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data,
1492 const VkDescriptorSetAllocateInfo *p_alloc_info,
1493 const core_validation::layer_data *dev_data,
1494 AllocateDescriptorSetsData *ds_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001495 bool skip_call = false;
Tobin Ehlisee471462016-05-26 11:21:59 -06001496
1497 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001498 auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
1499 if (!layout) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001500 skip_call |=
1501 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
1502 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
1503 "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call",
1504 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]));
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001505 } else {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001506 ds_data->layout_nodes[i] = layout;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001507 // Count total descriptors required per type
Tobin Ehlis815e8132016-06-02 13:02:17 -06001508 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
1509 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001510 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
1511 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
1512 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001513 }
1514 }
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001515 auto pool_state = getDescriptorPoolState(dev_data, p_alloc_info->descriptorPool);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001516 // Track number of descriptorSets allowable in this pool
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001517 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001518 skip_call |= log_msg(
1519 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001520 reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001521 "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.",
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001522 p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableSets);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001523 }
1524 // Determine whether descriptor counts are satisfiable
1525 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001526 if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) {
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001527 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001528 reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001529 "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64
1530 ". This pool only has %d descriptors of this type remaining.",
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001531 ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)),
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001532 reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i]);
Tobin Ehlisee471462016-05-26 11:21:59 -06001533 }
1534 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001535
Tobin Ehlisee471462016-05-26 11:21:59 -06001536 return skip_call;
1537}
1538// Decrement allocated sets from the pool and insert new sets into set_map
Tobin Ehlis4e380592016-06-02 12:41:47 -06001539void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
1540 const VkDescriptorSet *descriptor_sets,
1541 const AllocateDescriptorSetsData *ds_data,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -06001542 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map,
Tobin Ehlis4e380592016-06-02 12:41:47 -06001543 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map,
1544 const core_validation::layer_data *dev_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001545 auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001546 /* Account for sets and individual descriptors allocated from pool */
Tobin Ehlisee471462016-05-26 11:21:59 -06001547 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001548 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
1549 pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i];
1550 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001551 /* Create tracking object for each descriptor set; insert into
1552 * global map and the pool's set.
1553 */
1554 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis93f22372016-10-12 14:34:12 -06001555 auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i],
1556 dev_data);
Tobin Ehlisee471462016-05-26 11:21:59 -06001557
1558 pool_state->sets.insert(new_ds);
1559 new_ds->in_use.store(0);
1560 (*set_map)[descriptor_sets[i]] = new_ds;
1561 }
1562}