blob: 500957c0d0e6876671fe6e81c5945a0f49d053b5 [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 Ehlisfdcb63f2016-10-25 20:56:47 -060033 binding_to_index_map_[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) {
Tobin Ehlisfdcb63f2016-10-25 20:56:47 -060058 if (!bindings.insert(create_info->pBindings[i].binding).second) {
Tobin Ehlis154c2692016-10-25 09:36:53 -060059 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 }
Tobin Ehlis154c2692016-10-25 09:36:53 -060063 }
64 return skip;
65}
66
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060067// put all bindings into the given set
68void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const {
69 for (auto binding_index_pair : binding_to_index_map_)
70 binding_set->insert(binding_index_pair.first);
71}
Tobin Ehlis56a30942016-05-19 08:00:00 -060072
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060073VkDescriptorSetLayoutBinding const *
74cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060075 const auto &bi_itr = binding_to_index_map_.find(binding);
76 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060077 return bindings_[bi_itr->second].ptr();
Tobin Ehlis0bc30632016-05-05 10:16:02 -060078 }
79 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060080}
81VkDescriptorSetLayoutBinding const *
82cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
83 if (index >= bindings_.size())
84 return nullptr;
Tobin Ehlis664e6012016-05-05 11:04:44 -060085 return bindings_[index].ptr();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060086}
87// Return descriptorCount for given binding, 0 if index is unavailable
88uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060089 const auto &bi_itr = binding_to_index_map_.find(binding);
90 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060091 return bindings_[bi_itr->second].descriptorCount;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060092 }
93 return 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060094}
95// Return descriptorCount for given index, 0 if index is unavailable
96uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const {
97 if (index >= bindings_.size())
98 return 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060099 return bindings_[index].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600100}
101// For the given binding, return descriptorType
102VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const {
103 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600104 const auto &bi_itr = binding_to_index_map_.find(binding);
105 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600106 return bindings_[bi_itr->second].descriptorType;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600107 }
108 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600109}
110// For the given index, return descriptorType
111VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const {
112 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600113 return bindings_[index].descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600114}
115// For the given global index, return descriptorType
116// Currently just counting up through bindings_, may improve this in future
117VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const {
118 uint32_t global_offset = 0;
119 for (auto binding : bindings_) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600120 global_offset += binding.descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600121 if (index < global_offset)
Tobin Ehlis664e6012016-05-05 11:04:44 -0600122 return binding.descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600123 }
124 assert(0); // requested global index is out of bounds
125 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
126}
127// For the given binding, return stageFlags
128VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const {
129 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600130 const auto &bi_itr = binding_to_index_map_.find(binding);
131 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600132 return bindings_[bi_itr->second].stageFlags;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600133 }
134 return VkShaderStageFlags(0);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600135}
136// For the given binding, return start index
137uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const {
138 assert(binding_to_global_start_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600139 const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding);
140 if (btgsi_itr != binding_to_global_start_index_map_.end()) {
141 return btgsi_itr->second;
142 }
143 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600144 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600145 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600146}
147// For the given binding, return end index
148uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const {
149 assert(binding_to_global_end_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600150 const auto &btgei_itr = binding_to_global_end_index_map_.find(binding);
151 if (btgei_itr != binding_to_global_end_index_map_.end()) {
152 return btgei_itr->second;
153 }
154 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600155 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600156 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600157}
158// For given binding, return ptr to ImmutableSampler array
159VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
160 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600161 const auto &bi_itr = binding_to_index_map_.find(binding);
162 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600163 return bindings_[bi_itr->second].pImmutableSamplers;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600164 }
165 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600166}
167// For given index, return ptr to ImmutableSampler array
168VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
169 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600170 return bindings_[index].pImmutableSamplers;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600171}
172// If our layout is compatible with rh_ds_layout, return true,
173// else return false and fill in error_msg will description of what causes incompatibility
174bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const {
175 // Trivial case
176 if (layout_ == rh_ds_layout->GetDescriptorSetLayout())
177 return true;
178 if (descriptor_count_ != rh_ds_layout->descriptor_count_) {
179 std::stringstream error_str;
180 error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
181 << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors.";
182 *error_msg = error_str.str();
183 return false; // trivial fail case
184 }
185 // Descriptor counts match so need to go through bindings one-by-one
186 // and verify that type and stageFlags match
187 for (auto binding : bindings_) {
188 // TODO : Do we also need to check immutable samplers?
189 // VkDescriptorSetLayoutBinding *rh_binding;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600190 if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600191 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600192 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of "
193 << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600194 << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600195 << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600196 *error_msg = error_str.str();
197 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600198 } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600199 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600200 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '"
201 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600202 << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '"
Tobin Ehlis664e6012016-05-05 11:04:44 -0600203 << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600204 *error_msg = error_str.str();
205 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600206 } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600207 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600208 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags "
209 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600210 << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600211 << rh_ds_layout->GetStageFlagsFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600212 *error_msg = error_str.str();
213 return false;
214 }
215 }
216 return true;
217}
218
219bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const {
220 if (!binding_to_index_map_.count(binding + 1))
221 return false;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600222 auto const &bi_itr = binding_to_index_map_.find(binding);
223 if (bi_itr != binding_to_index_map_.end()) {
224 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
225 if (next_bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600226 auto type = bindings_[bi_itr->second].descriptorType;
227 auto stage_flags = bindings_[bi_itr->second].stageFlags;
228 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
229 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
230 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
231 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) {
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600232 return false;
233 }
234 return true;
235 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600236 }
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600237 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600238}
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600239// Starting at offset descriptor of given binding, parse over update_count
240// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
241// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
242// If so, return true. If not, fill in error_msg and return false
243bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count,
244 const char *type, const VkDescriptorSet set,
245 std::string *error_msg) const {
246 // Verify consecutive bindings match (if needed)
247 auto orig_binding = current_binding;
248 // Track count of descriptors in the current_bindings that are remaining to be updated
249 auto binding_remaining = GetDescriptorCountFromBinding(current_binding);
250 // First, it's legal to offset beyond your own binding so handle that case
251 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
252 while (offset >= binding_remaining) {
253 // Advance to next binding, decrement offset by binding size
254 offset -= binding_remaining;
255 binding_remaining = GetDescriptorCountFromBinding(++current_binding);
256 }
257 binding_remaining -= offset;
258 while (update_count > binding_remaining) { // While our updates overstep current binding
259 // Verify next consecutive binding matches type, stage flags & immutable sampler use
260 if (!IsNextBindingConsistent(current_binding++)) {
261 std::stringstream error_str;
262 error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #"
263 << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the "
264 "next binding is not consistent with current binding so this update is invalid.";
265 *error_msg = error_str.str();
266 return false;
267 }
268 // For sake of this check consider the bindings updated and grab count for next binding
269 update_count -= binding_remaining;
270 binding_remaining = GetDescriptorCountFromBinding(current_binding);
271 }
272 return true;
273}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600274
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600275cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
276 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
277
Tobin Ehlis93f22372016-10-12 14:34:12 -0600278cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
279 const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data)
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600280 : some_update_(false), set_(set), pool_state_(nullptr), p_layout_(layout), device_data_(dev_data) {
281 pool_state_ = getDescriptorPoolState(dev_data, pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600282 // Foreach binding, create default descriptors of given type
283 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
284 auto type = p_layout_->GetTypeFromIndex(i);
285 switch (type) {
286 case VK_DESCRIPTOR_TYPE_SAMPLER: {
287 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
288 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
289 if (immut_sampler)
Chris Forbescb621ea2016-05-30 11:47:31 +1200290 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600291 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200292 descriptors_.emplace_back(new SamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600293 }
294 break;
295 }
296 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
297 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
298 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
299 if (immut)
Chris Forbescb621ea2016-05-30 11:47:31 +1200300 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600301 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200302 descriptors_.emplace_back(new ImageSamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600303 }
304 break;
305 }
306 // ImageDescriptors
307 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
308 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
309 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
310 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200311 descriptors_.emplace_back(new ImageDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600312 break;
313 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
314 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
315 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200316 descriptors_.emplace_back(new TexelDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600317 break;
318 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
319 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
320 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
321 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
322 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200323 descriptors_.emplace_back(new BufferDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600324 break;
325 default:
Tobin Ehlis81f17852016-05-05 09:04:33 -0600326 assert(0); // Bad descriptor type specified
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600327 break;
328 }
329 }
330}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600331
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600332cvdescriptorset::DescriptorSet::~DescriptorSet() {
333 InvalidateBoundCmdBuffers();
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600334}
Chris Forbes57989132016-07-26 17:06:10 +1200335
336
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700337static std::string string_descriptor_req_view_type(descriptor_req req) {
338 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200339 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
340 if (req & (1 << i)) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700341 if (result.size()) result += ", ";
342 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200343 }
344 }
345
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700346 if (!result.size())
347 result = "(none)";
348
349 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200350}
351
352
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600353// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
354bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const {
355 return layout->IsCompatible(p_layout_, error);
356}
Chris Forbes57989132016-07-26 17:06:10 +1200357
Tobin Ehlis3066db62016-08-22 08:12:23 -0600358// 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 -0600359// This includes validating that all descriptors in the given bindings are updated,
360// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
361// Return true if state is acceptable, or false and write an error message into error string
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600362bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600363 const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
iostrows5eb97652016-06-02 15:56:26 +0200364 auto dyn_offset_index = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200365 for (auto binding_pair : bindings) {
366 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600367 if (!p_layout_->HasBinding(binding)) {
368 std::stringstream error_str;
369 error_str << "Attempting to validate DrawState for binding #" << binding
370 << " which is an invalid binding for this descriptor set.";
371 *error = error_str.str();
372 return false;
373 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600374 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600375 if (descriptors_[start_idx]->IsImmutableSampler()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600376 // Nothing to do for strictly immutable sampler
377 } else {
378 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600379 for (uint32_t i = start_idx; i <= end_idx; ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600380 if (!descriptors_[i]->updated) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600381 std::stringstream error_str;
382 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
383 << " is being used in draw but has not been updated.";
384 *error = error_str.str();
385 return false;
386 } else {
Chris Forbes57989132016-07-26 17:06:10 +1200387 auto descriptor_class = descriptors_[i]->GetClass();
388 if (descriptor_class == GeneralBuffer) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600389 // Verify that buffers are valid
Tobin Ehlis81f17852016-05-05 09:04:33 -0600390 auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer();
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600391 auto buffer_node = getBufferNode(device_data_, buffer);
392 if (!buffer_node) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600393 std::stringstream error_str;
394 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
395 << " references invalid buffer " << buffer << ".";
396 *error = error_str.str();
397 return false;
398 } else {
Tobin Ehlis54108272016-10-11 14:26:49 -0600399 auto mem_entry = getMemObjInfo(device_data_, buffer_node->binding.mem);
Tobin Ehlis997b2582016-06-02 08:43:37 -0600400 if (!mem_entry) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600401 std::stringstream error_str;
402 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
Tobin Ehlis54108272016-10-11 14:26:49 -0600403 << " uses buffer " << buffer << " that references invalid memory "
404 << buffer_node->binding.mem << ".";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600405 *error = error_str.str();
406 return false;
407 }
408 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600409 if (descriptors_[i]->IsDynamic()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600410 // Validate that dynamic offsets are within the buffer
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600411 auto buffer_size = buffer_node->createInfo.size;
Tobin Ehlis81f17852016-05-05 09:04:33 -0600412 auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange();
413 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600414 auto dyn_offset = dynamic_offsets[dyn_offset_index++];
415 if (VK_WHOLE_SIZE == range) {
416 if ((dyn_offset + desc_offset) > buffer_size) {
417 std::stringstream error_str;
418 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
419 << " uses buffer " << buffer
420 << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
421 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
422 << buffer_size << ".";
423 *error = error_str.str();
424 return false;
425 }
426 } else {
427 if ((dyn_offset + desc_offset + range) > buffer_size) {
428 std::stringstream error_str;
429 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
430 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
431 << " combined with offset " << desc_offset << " and range " << range
432 << " that oversteps the buffer size of " << buffer_size << ".";
433 *error = error_str.str();
434 return false;
435 }
436 }
437 }
438 }
Chris Forbes57989132016-07-26 17:06:10 +1200439 else if (descriptor_class == ImageSampler || descriptor_class == Image) {
440 auto image_view = (descriptor_class == ImageSampler)
441 ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView()
442 : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView();
443 auto reqs = binding_pair.second;
444
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600445 auto image_view_state = getImageViewState(device_data_, image_view);
446 assert(image_view_state);
447 auto image_view_ci = image_view_state->create_info;
Chris Forbes57989132016-07-26 17:06:10 +1200448
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600449 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
Chris Forbes57989132016-07-26 17:06:10 +1200450 // bad view type
451 std::stringstream error_str;
452 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
453 << " requires an image view of type " << string_descriptor_req_view_type(reqs)
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600454 << " but got " << string_VkImageViewType(image_view_ci.viewType) << ".";
Chris Forbes57989132016-07-26 17:06:10 +1200455 *error = error_str.str();
456 return false;
457 }
458
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600459 auto image_node = getImageState(device_data_, image_view_ci.image);
Chris Forbes57989132016-07-26 17:06:10 +1200460 assert(image_node);
461
462 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) &&
463 image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
464 std::stringstream error_str;
465 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
466 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
467 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
468 *error = error_str.str();
469 return false;
470 }
471
472 if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) &&
473 image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
474 std::stringstream error_str;
475 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
476 << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
477 *error = error_str.str();
478 return false;
479 }
480 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600481 }
482 }
483 }
484 }
485 return true;
486}
Chris Forbes57989132016-07-26 17:06:10 +1200487
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600488// For given bindings, place any update buffers or images into the passed-in unordered_sets
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600489uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600490 std::unordered_set<VkBuffer> *buffer_set,
491 std::unordered_set<VkImageView> *image_set) const {
492 auto num_updates = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200493 for (auto binding_pair : bindings) {
494 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600495 // If a binding doesn't exist, skip it
496 if (!p_layout_->HasBinding(binding)) {
497 continue;
498 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600499 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600500 if (descriptors_[start_idx]->IsStorage()) {
501 if (Image == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600502 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600503 if (descriptors_[start_idx + i]->updated) {
504 image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600505 num_updates++;
506 }
507 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600508 } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600509 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600510 if (descriptors_[start_idx + i]->updated) {
511 auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -0600512 auto bv_state = getBufferViewState(device_data_, bufferview);
513 if (bv_state) {
514 buffer_set->insert(bv_state->create_info.buffer);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600515 num_updates++;
516 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600517 }
518 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600519 } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600520 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600521 if (descriptors_[start_idx + i]->updated) {
522 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600523 num_updates++;
524 }
525 }
526 }
527 }
528 }
529 return num_updates;
530}
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600531// Set is being deleted or updates so invalidate all bound cmd buffers
532void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() {
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600533 core_validation::invalidateCommandBuffers(cb_bindings,
534 {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT});
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600535}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600536// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600537void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600538 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
539 // perform update
540 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
541 descriptors_[start_idx + di]->WriteUpdate(update, di);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600542 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600543 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600544 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600545
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600546 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600547}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600548// Validate Copy update
549bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600550 const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code,
551 std::string *error_msg) {
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600552 // Verify idle ds
553 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600554 // TODO : Re-using Allocate Idle error code, need copy update idle error code
555 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600556 std::stringstream error_str;
557 error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
558 << " that is in use by a command buffer.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600559 *error_msg = error_str.str();
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600560 return false;
561 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600562 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600563 *error_code = VALIDATION_ERROR_00966;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600564 std::stringstream error_str;
565 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600566 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600567 return false;
568 }
569 if (!src_set->HasBinding(update->srcBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600570 *error_code = VALIDATION_ERROR_00964;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600571 std::stringstream error_str;
572 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600573 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600574 return false;
575 }
576 // src & dst set bindings are valid
577 // Check bounds of src & dst
578 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
579 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
580 // SRC update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600581 *error_code = VALIDATION_ERROR_00965;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600582 std::stringstream error_str;
583 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
584 << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding)
585 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
586 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600587 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600588 return false;
589 }
590 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
591 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
592 // DST update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600593 *error_code = VALIDATION_ERROR_00967;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600594 std::stringstream error_str;
595 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
596 << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
597 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
598 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600599 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600600 return false;
601 }
602 // Check that types match
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600603 // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more
604 // fine-grained error codes
605 *error_code = VALIDATION_ERROR_00968;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600606 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
607 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
608 if (src_type != dst_type) {
609 std::stringstream error_str;
610 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
611 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
612 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600613 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600614 return false;
615 }
616 // Verify consistency of src & dst bindings if update crosses binding boundaries
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600617 if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600618 "copy update from", src_set->GetSet(), error_msg)) ||
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600619 (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600620 set_, error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600621 return false;
622 }
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600623 // First make sure source descriptors are updated
624 for (uint32_t i = 0; i < update->descriptorCount; ++i) {
625 if (!src_set->descriptors_[src_start_idx + i]) {
626 std::stringstream error_str;
627 error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset "
628 << update->srcArrayElement + i << " has not been updated.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600629 *error_msg = error_str.str();
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600630 return false;
631 }
632 }
633 // Update parameters all look good and descriptor updated so verify update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600634 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg))
Tobin Ehlis300888c2016-05-18 13:43:26 -0600635 return false;
636
637 // All checks passed so update is good
638 return true;
639}
640// Perform Copy update
641void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600642 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
643 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600644 // Update parameters all look good so perform update
645 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600646 descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600647 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600648 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600649 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600650
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600651 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600652}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600653
Tobin Ehlisf9519102016-08-17 09:49:13 -0600654// Bind cb_node to this set and this set to cb_node.
655// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
656// to be used in a draw by the given cb_node
Tobin Ehlisf9519102016-08-17 09:49:13 -0600657void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, const std::unordered_set<uint32_t> &bindings) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600658 // bind cb to this descriptor set
659 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600660 // Add bindings for descriptor set, the set's pool, and individual objects in the set
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600661 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 -0600662 pool_state_->cb_bindings.insert(cb_node);
663 cb_node->object_bindings.insert(
664 {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT});
Tobin Ehlisf9519102016-08-17 09:49:13 -0600665 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
666 // resources
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600667 for (auto binding : bindings) {
668 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
669 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
670 for (uint32_t i = start_idx; i <= end_idx; ++i) {
671 descriptors_[i]->BindCommandBuffer(device_data_, cb_node);
672 }
673 }
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600674}
675
Tobin Ehlis300888c2016-05-18 13:43:26 -0600676cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600677 updated = false;
678 descriptor_class = PlainSampler;
679};
680
Tobin Ehlis300888c2016-05-18 13:43:26 -0600681cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600682 updated = false;
683 descriptor_class = PlainSampler;
684 if (immut) {
685 sampler_ = *immut;
686 immutable_ = true;
687 updated = true;
688 }
689}
Tobin Ehlise2f80292016-06-02 10:08:53 -0600690// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
691bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) {
692 return (getSamplerNode(dev_data, sampler) != nullptr);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600693}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600694
Tobin Ehlis554bf382016-05-24 11:14:43 -0600695bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600696 const core_validation::layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code,
697 std::string *error_msg) {
698 // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases.
699 *error_code = VALIDATION_ERROR_00943;
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600700 auto iv_state = getImageViewState(dev_data, image_view);
701 if (!iv_state) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600702 std::stringstream error_str;
703 error_str << "Invalid VkImageView: " << image_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600704 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600705 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600706 }
Tobin Ehlis81280962016-07-20 14:04:20 -0600707 // 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 -0600708 // Validate that imageLayout is compatible with aspect_mask and image format
709 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600710 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
711 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600712 VkFormat format = VK_FORMAT_MAX_ENUM;
713 VkImageUsageFlags usage = 0;
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600714 auto image_node = getImageState(dev_data, image);
Tobin Ehlis1c9c55f2016-06-02 11:49:22 -0600715 if (image_node) {
716 format = image_node->createInfo.format;
717 usage = image_node->createInfo.usage;
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600718 // Validate that memory is bound to image
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600719 if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600720 // TODO : Need new code(s) for language in 11.6 Memory Association
721 *error_msg = "No memory bound to image.";
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600722 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600723 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600724 } else {
Tobin Ehlis1809f912016-05-25 09:24:36 -0600725 // Also need to check the swapchains.
Tobin Ehlis969a5262016-06-02 12:13:32 -0600726 auto swapchain = getSwapchainFromImage(dev_data, image);
727 if (swapchain) {
Tobin Ehlis4e380592016-06-02 12:41:47 -0600728 auto swapchain_node = getSwapchainNode(dev_data, swapchain);
729 if (swapchain_node) {
730 format = swapchain_node->createInfo.imageFormat;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600731 }
732 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600733 }
734 // First validate that format and layout are compatible
735 if (format == VK_FORMAT_MAX_ENUM) {
736 std::stringstream error_str;
737 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600738 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600739 return false;
740 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600741 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
742 // vkCreateImageView(). What's the best way to create unique id for these cases?
Tobin Ehlis1809f912016-05-25 09:24:36 -0600743 bool ds = vk_format_is_depth_or_stencil(format);
744 switch (image_layout) {
745 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
746 // Only Color bit must be set
747 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600748 std::stringstream error_str;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600749 error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does "
750 "not have VK_IMAGE_ASPECT_COLOR_BIT set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600751 *error_msg = error_str.str();
Tobin Ehlis554bf382016-05-24 11:14:43 -0600752 return false;
753 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600754 // format must NOT be DS
755 if (ds) {
756 std::stringstream error_str;
757 error_str << "ImageView (" << image_view
758 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
759 << string_VkFormat(format) << " which is not a color format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600760 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600761 return false;
762 }
763 break;
764 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
765 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
766 // Depth or stencil bit must be set, but both must NOT be set
767 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
768 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
769 // both must NOT be set
770 std::stringstream error_str;
771 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600772 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600773 return false;
774 }
775 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
776 // Neither were set
777 std::stringstream error_str;
778 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
779 << " but does not have STENCIL or DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600780 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600781 return false;
782 }
783 // format must be DS
784 if (!ds) {
785 std::stringstream error_str;
786 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
787 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600788 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600789 return false;
790 }
791 break;
792 default:
Mike Weiblencce7ec72016-10-17 19:33:05 -0600793 // For other layouts if the source is depth/stencil image, both aspect bits must not be set
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600794 if (ds) {
795 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
796 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
797 // both must NOT be set
798 std::stringstream error_str;
799 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
800 << " and is using depth/stencil image of format " << string_VkFormat(format)
801 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
802 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
803 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
804 "reads respectively.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600805 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600806 return false;
807 }
808 }
809 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600810 break;
811 }
812 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600813 // 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 -0600814 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
815 // under vkCreateImage()
816 // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with
817 // identify swizzle
Tobin Ehlis1809f912016-05-25 09:24:36 -0600818 std::string error_usage_bit;
819 switch (type) {
820 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
821 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
822 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
823 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
824 }
825 break;
826 }
827 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
828 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
829 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600830 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
831 std::stringstream error_str;
832 // TODO : Need to create custom enum error code for this case
833 error_str << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
834 << string_VkImageLayout(image_layout)
835 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can "
836 "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
837 *error_msg = error_str.str();
838 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600839 }
840 break;
841 }
842 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
843 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
844 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
845 }
846 break;
847 }
848 default:
849 break;
850 }
851 if (!error_usage_bit.empty()) {
852 std::stringstream error_str;
853 error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage
854 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
855 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600856 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600857 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600858 }
859 return true;
860}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600861
Tobin Ehlis300888c2016-05-18 13:43:26 -0600862void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
863 sampler_ = update->pImageInfo[index].sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600864 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600865}
866
Tobin Ehlis300888c2016-05-18 13:43:26 -0600867void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600868 if (!immutable_) {
869 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600870 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600871 }
872 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600873}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600874
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600875void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
876 if (!immutable_) {
877 auto sampler_node = getSamplerNode(dev_data, sampler_);
878 if (sampler_node)
879 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
880 }
881}
882
Tobin Ehlis300888c2016-05-18 13:43:26 -0600883cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor()
884 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600885 updated = false;
886 descriptor_class = ImageSampler;
887}
888
Tobin Ehlis300888c2016-05-18 13:43:26 -0600889cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
890 : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600891 updated = false;
892 descriptor_class = ImageSampler;
893 if (immut) {
894 sampler_ = *immut;
895 immutable_ = true;
896 updated = true;
897 }
898}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600899
Tobin Ehlis300888c2016-05-18 13:43:26 -0600900void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600901 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600902 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600903 sampler_ = image_info.sampler;
904 image_view_ = image_info.imageView;
905 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600906}
907
Tobin Ehlis300888c2016-05-18 13:43:26 -0600908void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600909 if (!immutable_) {
910 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600911 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600912 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600913 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
914 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600915 updated = true;
916 image_view_ = image_view;
917 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600918}
919
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600920void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data,
921 GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600922 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600923 if (!immutable_) {
924 auto sampler_node = getSamplerNode(dev_data, sampler_);
925 if (sampler_node)
926 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
927 }
Tobin Ehlis81e46372016-08-17 13:33:44 -0600928 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600929 auto iv_state = getImageViewState(dev_data, image_view_);
930 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600931 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600932 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600933}
934
Tobin Ehlis300888c2016-05-18 13:43:26 -0600935cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
936 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600937 updated = false;
938 descriptor_class = Image;
939 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type)
940 storage_ = true;
941};
942
Tobin Ehlis300888c2016-05-18 13:43:26 -0600943void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600944 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600945 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600946 image_view_ = image_info.imageView;
947 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600948}
949
Tobin Ehlis300888c2016-05-18 13:43:26 -0600950void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600951 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
952 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600953 updated = true;
954 image_view_ = image_view;
955 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600956}
957
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600958void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600959 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600960 auto iv_state = getImageViewState(dev_data, image_view_);
961 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600962 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600963 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600964}
965
Tobin Ehlis300888c2016-05-18 13:43:26 -0600966cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
967 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600968 updated = false;
969 descriptor_class = GeneralBuffer;
970 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
971 dynamic_ = true;
972 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
973 storage_ = true;
974 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
975 dynamic_ = true;
976 storage_ = true;
977 }
978}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600979void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600980 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600981 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600982 buffer_ = buffer_info.buffer;
983 offset_ = buffer_info.offset;
984 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600985}
986
Tobin Ehlis300888c2016-05-18 13:43:26 -0600987void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
988 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600989 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600990 buffer_ = buff_desc->buffer_;
991 offset_ = buff_desc->offset_;
992 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600993}
994
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600995void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600996 auto buffer_node = getBufferNode(dev_data, buffer_);
997 if (buffer_node)
998 core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600999}
1000
Tobin Ehlis300888c2016-05-18 13:43:26 -06001001cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001002 updated = false;
1003 descriptor_class = TexelBuffer;
1004 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type)
1005 storage_ = true;
1006};
Tobin Ehlis56a30942016-05-19 08:00:00 -06001007
Tobin Ehlis300888c2016-05-18 13:43:26 -06001008void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001009 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001010 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001011}
1012
Tobin Ehlis300888c2016-05-18 13:43:26 -06001013void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1014 updated = true;
1015 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1016}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001017
1018void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis8b872462016-09-14 08:12:08 -06001019 auto bv_state = getBufferViewState(dev_data, buffer_view_);
1020 if (bv_state) {
Tobin Ehlis2515c0e2016-09-28 07:12:28 -06001021 core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001022 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001023}
1024
Tobin Ehlis300888c2016-05-18 13:43:26 -06001025// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1026// sets, and then calls their respective Validate[Write|Copy]Update functions.
1027// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1028// be skipped, then true is returned.
1029// If there is no issue with the update, then false is returned.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001030bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data,
1031 const core_validation::layer_data *dev_data, uint32_t write_count,
1032 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1033 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001034 bool skip_call = false;
1035 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001036 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001037 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001038 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1039 if (!set_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001040 skip_call |=
1041 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 -06001042 reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001043 "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.",
1044 reinterpret_cast<uint64_t &>(dest_set));
1045 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001046 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001047 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001048 if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001049 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 -06001050 reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001051 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001052 " with error: %s. %s",
1053 reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001054 }
1055 }
1056 }
1057 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001058 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001059 auto dst_set = p_cds[i].dstSet;
1060 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001061 auto src_node = core_validation::getSetNode(dev_data, src_set);
1062 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1063 if (!src_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001064 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 -06001065 reinterpret_cast<uint64_t &>(src_set), __LINE__, VALIDATION_ERROR_00971, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001066 "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001067 " that has not been allocated. %s",
1068 reinterpret_cast<uint64_t &>(src_set), validation_error_map[VALIDATION_ERROR_00971]);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001069 } else if (!dst_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001070 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 -06001071 reinterpret_cast<uint64_t &>(dst_set), __LINE__, VALIDATION_ERROR_00972, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001072 "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001073 " that has not been allocated. %s",
1074 reinterpret_cast<uint64_t &>(dst_set), validation_error_map[VALIDATION_ERROR_00972]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001075 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001076 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001077 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001078 if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) {
1079 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1080 reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS",
1081 "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64
1082 " to Descriptor Set 0x%" PRIx64 " with error: %s. %s",
1083 reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set),
1084 error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001085 }
1086 }
1087 }
1088 return skip_call;
1089}
1090// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1091// sets, and then calls their respective Perform[Write|Copy]Update functions.
1092// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1093// with the same set of updates.
1094// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1095// calling down the chain.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001096void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count,
1097 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1098 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001099 // Write updates first
1100 uint32_t i = 0;
1101 for (i = 0; i < write_count; ++i) {
1102 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001103 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1104 if (set_node) {
1105 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001106 }
1107 }
1108 // Now copy updates
1109 for (i = 0; i < copy_count; ++i) {
1110 auto dst_set = p_cds[i].dstSet;
1111 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001112 auto src_node = core_validation::getSetNode(dev_data, src_set);
1113 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1114 if (src_node && dst_node) {
1115 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001116 }
1117 }
1118}
1119// Validate the state for a given write update but don't actually perform the update
1120// If an error would occur for this update, return false and fill in details in error_msg string
1121bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001122 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001123 // Verify idle ds
1124 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001125 // TODO : Re-using Allocate Idle error code, need write update idle error code
1126 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001127 std::stringstream error_str;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001128 error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
1129 << " that is in use by a command buffer.";
1130 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001131 return false;
1132 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001133 // Verify dst binding exists
1134 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001135 *error_code = VALIDATION_ERROR_00936;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001136 std::stringstream error_str;
1137 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << ".";
1138 *error_msg = error_str.str();
1139 return false;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001140 }
1141 // We know that binding is valid, verify update and do update on each descriptor
1142 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
1143 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
1144 if (type != update->descriptorType) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001145 *error_code = VALIDATION_ERROR_00937;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001146 std::stringstream error_str;
1147 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
1148 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
1149 *error_msg = error_str.str();
1150 return false;
1151 }
1152 if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001153 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001154 std::stringstream error_str;
1155 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1156 << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount
1157 << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
1158 << " combined with update array element offset of " << update->dstArrayElement
1159 << " oversteps the size of this descriptor set.";
1160 *error_msg = error_str.str();
1161 return false;
1162 }
1163 // Verify consecutive bindings match (if needed)
1164 if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001165 set_, error_msg)) {
1166 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001167 return false;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001168 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001169 // Update is within bounds and consistent so last step is to validate update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001170 if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) {
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001171 std::stringstream error_str;
1172 error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding
1173 << " failed with error message: " << error_msg->c_str();
1174 *error_msg = error_str.str();
1175 return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001176 }
1177 // All checks passed, update is clean
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001178 return true;
Tobin Ehlis03d61de2016-05-17 08:31:46 -06001179}
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001180// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001181// 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 -06001182bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_NODE const *buffer_node, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001183 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001184 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001185 auto usage = buffer_node->createInfo.usage;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001186 std::string error_usage_bit;
1187 switch (type) {
1188 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1189 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001190 *error_code = VALIDATION_ERROR_00950;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001191 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1192 }
1193 break;
1194 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1195 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001196 *error_code = VALIDATION_ERROR_00951;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001197 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1198 }
1199 break;
1200 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1201 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1202 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001203 *error_code = VALIDATION_ERROR_00946;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001204 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1205 }
1206 break;
1207 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1208 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1209 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001210 *error_code = VALIDATION_ERROR_00947;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001211 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1212 }
1213 break;
1214 default:
1215 break;
1216 }
1217 if (!error_usage_bit.empty()) {
1218 std::stringstream error_str;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001219 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage
1220 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1221 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001222 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001223 return false;
1224 }
1225 return true;
1226}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001227// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1228// 1. buffer is valid
1229// 2. buffer was created with correct usage flags
1230// 3. offset is less than buffer size
1231// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001232// 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 -06001233bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001234 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
1235 // TODO : Defaulting to 00962 for all cases here. Need to create new error codes for a few cases below.
1236 *error_code = VALIDATION_ERROR_00962;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001237 // First make sure that buffer is valid
1238 auto buffer_node = getBufferNode(device_data_, buffer_info->buffer);
1239 if (!buffer_node) {
1240 std::stringstream error_str;
1241 error_str << "Invalid VkBuffer: " << buffer_info->buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001242 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001243 return false;
1244 }
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001245 if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001246 // TODO : This is a repeat code, need new code(s) for language in 11.6 Memory Association
1247 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001248 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001249 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001250 // Verify usage bits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001251 if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
1252 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001253 return false;
1254 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001255 // TODO : Need to also validate device limit offset requirements captured in VALIDATION_ERROR_00944,945
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001256 // offset must be less than buffer size
1257 if (buffer_info->offset > buffer_node->createInfo.size) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001258 *error_code = VALIDATION_ERROR_00959;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001259 std::stringstream error_str;
1260 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer
1261 << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001262 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001263 return false;
1264 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001265 // TODO : Need to also validate device limit range requirements captured in VALIDATION_ERROR_00948,949
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001266 if (buffer_info->range != VK_WHOLE_SIZE) {
1267 // Range must be VK_WHOLE_SIZE or > 0
1268 if (!buffer_info->range) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001269 *error_code = VALIDATION_ERROR_00960;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001270 std::stringstream error_str;
1271 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001272 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001273 return false;
1274 }
1275 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
1276 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001277 *error_code = VALIDATION_ERROR_00961;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001278 std::stringstream error_str;
1279 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
1280 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001281 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001282 return false;
1283 }
1284 }
1285 return true;
1286}
1287
Tobin Ehlis300888c2016-05-18 13:43:26 -06001288// Verify that the contents of the update are ok, but don't perform actual update
1289bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001290 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1291 std::string *error_msg) const {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001292 switch (update->descriptorType) {
1293 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1294 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1295 // Validate image
1296 auto image_view = update->pImageInfo[di].imageView;
1297 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001298 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001299 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001300 error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1301 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001302 return false;
1303 }
1304 }
1305 // Intentional fall-through to validate sampler
1306 }
1307 case VK_DESCRIPTOR_TYPE_SAMPLER: {
1308 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1309 if (!descriptors_[index + di].get()->IsImmutableSampler()) {
Tobin Ehlise2f80292016-06-02 10:08:53 -06001310 if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001311 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001312 std::stringstream error_str;
1313 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
1314 << update->pImageInfo[di].sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001315 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001316 return false;
1317 }
1318 } else {
1319 // TODO : Warn here
1320 }
1321 }
1322 break;
1323 }
1324 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1325 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1326 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1327 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1328 auto image_view = update->pImageInfo[di].imageView;
1329 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001330 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001331 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001332 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
1333 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001334 return false;
1335 }
1336 }
1337 break;
1338 }
1339 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1340 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
1341 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1342 auto buffer_view = update->pTexelBufferView[di];
Tobin Ehlis8b872462016-09-14 08:12:08 -06001343 auto bv_state = getBufferViewState(device_data_, buffer_view);
1344 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001345 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001346 std::stringstream error_str;
1347 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001348 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001349 return false;
1350 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001351 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001352 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), update->descriptorType, error_code, error_msg)) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001353 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001354 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
1355 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001356 return false;
1357 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001358 }
1359 break;
1360 }
1361 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1362 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1363 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1364 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1365 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001366 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001367 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001368 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
1369 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001370 return false;
1371 }
1372 }
1373 break;
1374 }
1375 default:
1376 assert(0); // We've already verified update type so should never get here
1377 break;
1378 }
1379 // All checks passed so update contents are good
1380 return true;
1381}
1382// Verify that the contents of the update are ok, but don't perform actual update
1383bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001384 VkDescriptorType type, uint32_t index,
1385 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1386 std::string *error_msg) const {
1387 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
1388 // for write updates
Tobin Ehlis300888c2016-05-18 13:43:26 -06001389 switch (src_set->descriptors_[index]->descriptor_class) {
1390 case PlainSampler: {
1391 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1392 if (!src_set->descriptors_[index + di]->IsImmutableSampler()) {
1393 auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001394 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001395 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001396 std::stringstream error_str;
1397 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001398 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001399 return false;
1400 }
1401 } else {
1402 // TODO : Warn here
1403 }
1404 }
1405 break;
1406 }
1407 case ImageSampler: {
1408 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1409 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get());
1410 // First validate sampler
1411 if (!img_samp_desc->IsImmutableSampler()) {
1412 auto update_sampler = img_samp_desc->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001413 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001414 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001415 std::stringstream error_str;
1416 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001417 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001418 return false;
1419 }
1420 } else {
1421 // TODO : Warn here
1422 }
1423 // Validate image
1424 auto image_view = img_samp_desc->GetImageView();
1425 auto image_layout = img_samp_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001426 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001427 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001428 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1429 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001430 return false;
1431 }
1432 }
Alex Smithd8f14792016-09-23 12:18:51 +01001433 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001434 }
1435 case Image: {
1436 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1437 auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get());
1438 auto image_view = img_desc->GetImageView();
1439 auto image_layout = img_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001440 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001441 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001442 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
1443 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001444 return false;
1445 }
1446 }
1447 break;
1448 }
1449 case TexelBuffer: {
1450 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1451 auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -06001452 auto bv_state = getBufferViewState(device_data_, buffer_view);
1453 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001454 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001455 std::stringstream error_str;
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001456 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001457 *error_msg = error_str.str();
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001458 return false;
1459 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001460 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001461 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001462 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001463 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
1464 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001465 return false;
1466 }
1467 }
1468 break;
1469 }
1470 case GeneralBuffer: {
1471 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1472 auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001473 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001474 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001475 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
1476 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001477 return false;
1478 }
1479 }
1480 break;
1481 }
1482 default:
1483 assert(0); // We've already verified update type so should never get here
1484 break;
1485 }
1486 // All checks passed so update contents are good
1487 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12001488}
Tobin Ehlisee471462016-05-26 11:21:59 -06001489// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Tobin Ehlis815e8132016-06-02 13:02:17 -06001490bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data,
1491 const VkDescriptorSetAllocateInfo *p_alloc_info,
1492 const core_validation::layer_data *dev_data,
1493 AllocateDescriptorSetsData *ds_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001494 bool skip_call = false;
Tobin Ehlisee471462016-05-26 11:21:59 -06001495
1496 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001497 auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
1498 if (!layout) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001499 skip_call |=
1500 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
1501 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
1502 "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call",
1503 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]));
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001504 } else {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001505 ds_data->layout_nodes[i] = layout;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001506 // Count total descriptors required per type
Tobin Ehlis815e8132016-06-02 13:02:17 -06001507 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
1508 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001509 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
1510 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
1511 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001512 }
1513 }
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001514 auto pool_state = getDescriptorPoolState(dev_data, p_alloc_info->descriptorPool);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001515 // Track number of descriptorSets allowable in this pool
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001516 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001517 skip_call |= log_msg(
1518 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001519 reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001520 "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.",
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001521 p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableSets);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001522 }
1523 // Determine whether descriptor counts are satisfiable
1524 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001525 if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) {
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001526 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 -06001527 reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001528 "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64
1529 ". This pool only has %d descriptors of this type remaining.",
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001530 ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)),
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001531 reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i]);
Tobin Ehlisee471462016-05-26 11:21:59 -06001532 }
1533 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001534
Tobin Ehlisee471462016-05-26 11:21:59 -06001535 return skip_call;
1536}
1537// Decrement allocated sets from the pool and insert new sets into set_map
Tobin Ehlis4e380592016-06-02 12:41:47 -06001538void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
1539 const VkDescriptorSet *descriptor_sets,
1540 const AllocateDescriptorSetsData *ds_data,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -06001541 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map,
Tobin Ehlis4e380592016-06-02 12:41:47 -06001542 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map,
1543 const core_validation::layer_data *dev_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001544 auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001545 /* Account for sets and individual descriptors allocated from pool */
Tobin Ehlisee471462016-05-26 11:21:59 -06001546 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001547 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
1548 pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i];
1549 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001550 /* Create tracking object for each descriptor set; insert into
1551 * global map and the pool's set.
1552 */
1553 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis93f22372016-10-12 14:34:12 -06001554 auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i],
1555 dev_data);
Tobin Ehlisee471462016-05-26 11:21:59 -06001556
1557 pool_state->sets.insert(new_ds);
1558 new_ds->in_use.store(0);
1559 (*set_map)[descriptor_sets[i]] = new_ds;
1560 }
1561}