blob: 1e22f82ccb597c1539564956995cd0ac7172fa9e [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
27cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(debug_report_data *report_data,
28 const VkDescriptorSetLayoutCreateInfo *p_create_info,
29 const VkDescriptorSetLayout layout)
30 : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) {
31 uint32_t global_index = 0;
32 for (uint32_t i = 0; i < binding_count_; ++i) {
33 descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
34 if (!binding_to_index_map_.emplace(p_create_info->pBindings[i].binding, i).second) {
35 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
36 reinterpret_cast<uint64_t &>(layout_), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
37 "duplicated binding number in "
38 "VkDescriptorSetLayoutBinding");
39 }
40 binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index;
41 global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0;
42 binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index;
Tobin Ehlis789c4ed2016-10-17 13:51:57 -060043 global_index += p_create_info->pBindings[i].descriptorCount ? 1 : 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060044 bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i]));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060045 // In cases where we should ignore pImmutableSamplers make sure it's NULL
46 if ((p_create_info->pBindings[i].pImmutableSamplers) &&
47 ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) &&
48 (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060049 bindings_.back().pImmutableSamplers = nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060050 }
51 if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
52 p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Tobin Ehlisef0de162016-06-20 13:07:34 -060053 dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060054 }
55 }
56}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060057// put all bindings into the given set
58void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const {
59 for (auto binding_index_pair : binding_to_index_map_)
60 binding_set->insert(binding_index_pair.first);
61}
Tobin Ehlis56a30942016-05-19 08:00:00 -060062
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060063VkDescriptorSetLayoutBinding const *
64cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060065 const auto &bi_itr = binding_to_index_map_.find(binding);
66 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060067 return bindings_[bi_itr->second].ptr();
Tobin Ehlis0bc30632016-05-05 10:16:02 -060068 }
69 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060070}
71VkDescriptorSetLayoutBinding const *
72cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
73 if (index >= bindings_.size())
74 return nullptr;
Tobin Ehlis664e6012016-05-05 11:04:44 -060075 return bindings_[index].ptr();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060076}
77// Return descriptorCount for given binding, 0 if index is unavailable
78uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060079 const auto &bi_itr = binding_to_index_map_.find(binding);
80 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060081 return bindings_[bi_itr->second].descriptorCount;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060082 }
83 return 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060084}
85// Return descriptorCount for given index, 0 if index is unavailable
86uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const {
87 if (index >= bindings_.size())
88 return 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060089 return bindings_[index].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060090}
91// For the given binding, return descriptorType
92VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const {
93 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -060094 const auto &bi_itr = binding_to_index_map_.find(binding);
95 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060096 return bindings_[bi_itr->second].descriptorType;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060097 }
98 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060099}
100// For the given index, return descriptorType
101VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const {
102 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600103 return bindings_[index].descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600104}
105// For the given global index, return descriptorType
106// Currently just counting up through bindings_, may improve this in future
107VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const {
108 uint32_t global_offset = 0;
109 for (auto binding : bindings_) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600110 global_offset += binding.descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600111 if (index < global_offset)
Tobin Ehlis664e6012016-05-05 11:04:44 -0600112 return binding.descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600113 }
114 assert(0); // requested global index is out of bounds
115 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
116}
117// For the given binding, return stageFlags
118VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const {
119 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600120 const auto &bi_itr = binding_to_index_map_.find(binding);
121 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600122 return bindings_[bi_itr->second].stageFlags;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600123 }
124 return VkShaderStageFlags(0);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600125}
126// For the given binding, return start index
127uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const {
128 assert(binding_to_global_start_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600129 const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding);
130 if (btgsi_itr != binding_to_global_start_index_map_.end()) {
131 return btgsi_itr->second;
132 }
133 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600134 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600135 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600136}
137// For the given binding, return end index
138uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const {
139 assert(binding_to_global_end_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600140 const auto &btgei_itr = binding_to_global_end_index_map_.find(binding);
141 if (btgei_itr != binding_to_global_end_index_map_.end()) {
142 return btgei_itr->second;
143 }
144 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600145 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600146 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600147}
148// For given binding, return ptr to ImmutableSampler array
149VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
150 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600151 const auto &bi_itr = binding_to_index_map_.find(binding);
152 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600153 return bindings_[bi_itr->second].pImmutableSamplers;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600154 }
155 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600156}
157// For given index, return ptr to ImmutableSampler array
158VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
159 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600160 return bindings_[index].pImmutableSamplers;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600161}
162// If our layout is compatible with rh_ds_layout, return true,
163// else return false and fill in error_msg will description of what causes incompatibility
164bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const {
165 // Trivial case
166 if (layout_ == rh_ds_layout->GetDescriptorSetLayout())
167 return true;
168 if (descriptor_count_ != rh_ds_layout->descriptor_count_) {
169 std::stringstream error_str;
170 error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
171 << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors.";
172 *error_msg = error_str.str();
173 return false; // trivial fail case
174 }
175 // Descriptor counts match so need to go through bindings one-by-one
176 // and verify that type and stageFlags match
177 for (auto binding : bindings_) {
178 // TODO : Do we also need to check immutable samplers?
179 // VkDescriptorSetLayoutBinding *rh_binding;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600180 if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600181 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600182 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of "
183 << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600184 << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600185 << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600186 *error_msg = error_str.str();
187 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600188 } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600189 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600190 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '"
191 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600192 << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '"
Tobin Ehlis664e6012016-05-05 11:04:44 -0600193 << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600194 *error_msg = error_str.str();
195 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600196 } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600197 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600198 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags "
199 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600200 << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600201 << rh_ds_layout->GetStageFlagsFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600202 *error_msg = error_str.str();
203 return false;
204 }
205 }
206 return true;
207}
208
209bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const {
210 if (!binding_to_index_map_.count(binding + 1))
211 return false;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600212 auto const &bi_itr = binding_to_index_map_.find(binding);
213 if (bi_itr != binding_to_index_map_.end()) {
214 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
215 if (next_bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600216 auto type = bindings_[bi_itr->second].descriptorType;
217 auto stage_flags = bindings_[bi_itr->second].stageFlags;
218 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
219 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
220 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
221 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) {
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600222 return false;
223 }
224 return true;
225 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600226 }
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600227 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600228}
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600229// Starting at offset descriptor of given binding, parse over update_count
230// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
231// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
232// If so, return true. If not, fill in error_msg and return false
233bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count,
234 const char *type, const VkDescriptorSet set,
235 std::string *error_msg) const {
236 // Verify consecutive bindings match (if needed)
237 auto orig_binding = current_binding;
238 // Track count of descriptors in the current_bindings that are remaining to be updated
239 auto binding_remaining = GetDescriptorCountFromBinding(current_binding);
240 // First, it's legal to offset beyond your own binding so handle that case
241 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
242 while (offset >= binding_remaining) {
243 // Advance to next binding, decrement offset by binding size
244 offset -= binding_remaining;
245 binding_remaining = GetDescriptorCountFromBinding(++current_binding);
246 }
247 binding_remaining -= offset;
248 while (update_count > binding_remaining) { // While our updates overstep current binding
249 // Verify next consecutive binding matches type, stage flags & immutable sampler use
250 if (!IsNextBindingConsistent(current_binding++)) {
251 std::stringstream error_str;
252 error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #"
253 << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the "
254 "next binding is not consistent with current binding so this update is invalid.";
255 *error_msg = error_str.str();
256 return false;
257 }
258 // For sake of this check consider the bindings updated and grab count for next binding
259 update_count -= binding_remaining;
260 binding_remaining = GetDescriptorCountFromBinding(current_binding);
261 }
262 return true;
263}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600264
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600265cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
266 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
267
Tobin Ehlis93f22372016-10-12 14:34:12 -0600268cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
269 const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data)
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600270 : some_update_(false), set_(set), pool_state_(nullptr), p_layout_(layout), device_data_(dev_data) {
271 pool_state_ = getDescriptorPoolState(dev_data, pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600272 // Foreach binding, create default descriptors of given type
273 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
274 auto type = p_layout_->GetTypeFromIndex(i);
275 switch (type) {
276 case VK_DESCRIPTOR_TYPE_SAMPLER: {
277 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
278 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
279 if (immut_sampler)
Chris Forbescb621ea2016-05-30 11:47:31 +1200280 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600281 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200282 descriptors_.emplace_back(new SamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600283 }
284 break;
285 }
286 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
287 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
288 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
289 if (immut)
Chris Forbescb621ea2016-05-30 11:47:31 +1200290 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600291 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200292 descriptors_.emplace_back(new ImageSamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600293 }
294 break;
295 }
296 // ImageDescriptors
297 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
298 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
299 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
300 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200301 descriptors_.emplace_back(new ImageDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600302 break;
303 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
304 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
305 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200306 descriptors_.emplace_back(new TexelDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600307 break;
308 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
309 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
310 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
311 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
312 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200313 descriptors_.emplace_back(new BufferDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600314 break;
315 default:
Tobin Ehlis81f17852016-05-05 09:04:33 -0600316 assert(0); // Bad descriptor type specified
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600317 break;
318 }
319 }
320}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600321
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600322cvdescriptorset::DescriptorSet::~DescriptorSet() {
323 InvalidateBoundCmdBuffers();
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600324}
Chris Forbes57989132016-07-26 17:06:10 +1200325
326
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700327static std::string string_descriptor_req_view_type(descriptor_req req) {
328 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200329 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
330 if (req & (1 << i)) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700331 if (result.size()) result += ", ";
332 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200333 }
334 }
335
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700336 if (!result.size())
337 result = "(none)";
338
339 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200340}
341
342
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600343// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
344bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const {
345 return layout->IsCompatible(p_layout_, error);
346}
Chris Forbes57989132016-07-26 17:06:10 +1200347
Tobin Ehlis3066db62016-08-22 08:12:23 -0600348// 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 -0600349// This includes validating that all descriptors in the given bindings are updated,
350// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
351// Return true if state is acceptable, or false and write an error message into error string
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600352bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600353 const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
iostrows5eb97652016-06-02 15:56:26 +0200354 auto dyn_offset_index = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200355 for (auto binding_pair : bindings) {
356 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600357 if (!p_layout_->HasBinding(binding)) {
358 std::stringstream error_str;
359 error_str << "Attempting to validate DrawState for binding #" << binding
360 << " which is an invalid binding for this descriptor set.";
361 *error = error_str.str();
362 return false;
363 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600364 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600365 if (descriptors_[start_idx]->IsImmutableSampler()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600366 // Nothing to do for strictly immutable sampler
367 } else {
368 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600369 for (uint32_t i = start_idx; i <= end_idx; ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600370 if (!descriptors_[i]->updated) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600371 std::stringstream error_str;
372 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
373 << " is being used in draw but has not been updated.";
374 *error = error_str.str();
375 return false;
376 } else {
Chris Forbes57989132016-07-26 17:06:10 +1200377 auto descriptor_class = descriptors_[i]->GetClass();
378 if (descriptor_class == GeneralBuffer) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600379 // Verify that buffers are valid
Tobin Ehlis81f17852016-05-05 09:04:33 -0600380 auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer();
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600381 auto buffer_node = getBufferNode(device_data_, buffer);
382 if (!buffer_node) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600383 std::stringstream error_str;
384 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
385 << " references invalid buffer " << buffer << ".";
386 *error = error_str.str();
387 return false;
388 } else {
Tobin Ehlis54108272016-10-11 14:26:49 -0600389 auto mem_entry = getMemObjInfo(device_data_, buffer_node->binding.mem);
Tobin Ehlis997b2582016-06-02 08:43:37 -0600390 if (!mem_entry) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600391 std::stringstream error_str;
392 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
Tobin Ehlis54108272016-10-11 14:26:49 -0600393 << " uses buffer " << buffer << " that references invalid memory "
394 << buffer_node->binding.mem << ".";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600395 *error = error_str.str();
396 return false;
397 }
398 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600399 if (descriptors_[i]->IsDynamic()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600400 // Validate that dynamic offsets are within the buffer
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600401 auto buffer_size = buffer_node->createInfo.size;
Tobin Ehlis81f17852016-05-05 09:04:33 -0600402 auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange();
403 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600404 auto dyn_offset = dynamic_offsets[dyn_offset_index++];
405 if (VK_WHOLE_SIZE == range) {
406 if ((dyn_offset + desc_offset) > buffer_size) {
407 std::stringstream error_str;
408 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
409 << " uses buffer " << buffer
410 << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
411 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
412 << buffer_size << ".";
413 *error = error_str.str();
414 return false;
415 }
416 } else {
417 if ((dyn_offset + desc_offset + range) > buffer_size) {
418 std::stringstream error_str;
419 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
420 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
421 << " combined with offset " << desc_offset << " and range " << range
422 << " that oversteps the buffer size of " << buffer_size << ".";
423 *error = error_str.str();
424 return false;
425 }
426 }
427 }
428 }
Chris Forbes57989132016-07-26 17:06:10 +1200429 else if (descriptor_class == ImageSampler || descriptor_class == Image) {
430 auto image_view = (descriptor_class == ImageSampler)
431 ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView()
432 : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView();
433 auto reqs = binding_pair.second;
434
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600435 auto image_view_state = getImageViewState(device_data_, image_view);
436 assert(image_view_state);
437 auto image_view_ci = image_view_state->create_info;
Chris Forbes57989132016-07-26 17:06:10 +1200438
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600439 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
Chris Forbes57989132016-07-26 17:06:10 +1200440 // bad view type
441 std::stringstream error_str;
442 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
443 << " requires an image view of type " << string_descriptor_req_view_type(reqs)
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600444 << " but got " << string_VkImageViewType(image_view_ci.viewType) << ".";
Chris Forbes57989132016-07-26 17:06:10 +1200445 *error = error_str.str();
446 return false;
447 }
448
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600449 auto image_node = getImageState(device_data_, image_view_ci.image);
Chris Forbes57989132016-07-26 17:06:10 +1200450 assert(image_node);
451
452 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) &&
453 image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
454 std::stringstream error_str;
455 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
456 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
457 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
458 *error = error_str.str();
459 return false;
460 }
461
462 if ((reqs & DESCRIPTOR_REQ_MULTI_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 multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
467 *error = error_str.str();
468 return false;
469 }
470 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600471 }
472 }
473 }
474 }
475 return true;
476}
Chris Forbes57989132016-07-26 17:06:10 +1200477
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600478// For given bindings, place any update buffers or images into the passed-in unordered_sets
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600479uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600480 std::unordered_set<VkBuffer> *buffer_set,
481 std::unordered_set<VkImageView> *image_set) const {
482 auto num_updates = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200483 for (auto binding_pair : bindings) {
484 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600485 // If a binding doesn't exist, skip it
486 if (!p_layout_->HasBinding(binding)) {
487 continue;
488 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600489 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600490 if (descriptors_[start_idx]->IsStorage()) {
491 if (Image == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600492 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600493 if (descriptors_[start_idx + i]->updated) {
494 image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600495 num_updates++;
496 }
497 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600498 } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600499 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600500 if (descriptors_[start_idx + i]->updated) {
501 auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -0600502 auto bv_state = getBufferViewState(device_data_, bufferview);
503 if (bv_state) {
504 buffer_set->insert(bv_state->create_info.buffer);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600505 num_updates++;
506 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600507 }
508 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600509 } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600510 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600511 if (descriptors_[start_idx + i]->updated) {
512 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600513 num_updates++;
514 }
515 }
516 }
517 }
518 }
519 return num_updates;
520}
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600521// Set is being deleted or updates so invalidate all bound cmd buffers
522void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() {
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600523 core_validation::invalidateCommandBuffers(cb_bindings,
524 {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT});
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600525}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600526// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600527void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600528 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
529 // perform update
530 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
531 descriptors_[start_idx + di]->WriteUpdate(update, di);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600532 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600533 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600534 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600535
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600536 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600537}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600538// Validate Copy update
539bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600540 const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code,
541 std::string *error_msg) {
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600542 // Verify idle ds
543 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600544 // TODO : Re-using Allocate Idle error code, need copy update idle error code
545 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600546 std::stringstream error_str;
547 error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
548 << " that is in use by a command buffer.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600549 *error_msg = error_str.str();
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600550 return false;
551 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600552 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600553 *error_code = VALIDATION_ERROR_00966;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600554 std::stringstream error_str;
555 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600556 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600557 return false;
558 }
559 if (!src_set->HasBinding(update->srcBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600560 *error_code = VALIDATION_ERROR_00964;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600561 std::stringstream error_str;
562 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600563 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600564 return false;
565 }
566 // src & dst set bindings are valid
567 // Check bounds of src & dst
568 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
569 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
570 // SRC update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600571 *error_code = VALIDATION_ERROR_00965;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600572 std::stringstream error_str;
573 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
574 << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding)
575 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
576 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600577 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600578 return false;
579 }
580 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
581 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
582 // DST update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600583 *error_code = VALIDATION_ERROR_00967;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600584 std::stringstream error_str;
585 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
586 << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
587 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
588 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600589 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600590 return false;
591 }
592 // Check that types match
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600593 // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more
594 // fine-grained error codes
595 *error_code = VALIDATION_ERROR_00968;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600596 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
597 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
598 if (src_type != dst_type) {
599 std::stringstream error_str;
600 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
601 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
602 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600603 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600604 return false;
605 }
606 // Verify consistency of src & dst bindings if update crosses binding boundaries
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600607 if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600608 "copy update from", src_set->GetSet(), error_msg)) ||
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600609 (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600610 set_, error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600611 return false;
612 }
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600613 // First make sure source descriptors are updated
614 for (uint32_t i = 0; i < update->descriptorCount; ++i) {
615 if (!src_set->descriptors_[src_start_idx + i]) {
616 std::stringstream error_str;
617 error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset "
618 << update->srcArrayElement + i << " has not been updated.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600619 *error_msg = error_str.str();
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600620 return false;
621 }
622 }
623 // Update parameters all look good and descriptor updated so verify update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600624 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg))
Tobin Ehlis300888c2016-05-18 13:43:26 -0600625 return false;
626
627 // All checks passed so update is good
628 return true;
629}
630// Perform Copy update
631void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600632 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
633 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600634 // Update parameters all look good so perform update
635 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600636 descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600637 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600638 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600639 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600640
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600641 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600642}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600643
Tobin Ehlisf9519102016-08-17 09:49:13 -0600644// Bind cb_node to this set and this set to cb_node.
645// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
646// to be used in a draw by the given cb_node
Tobin Ehlisf9519102016-08-17 09:49:13 -0600647void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, const std::unordered_set<uint32_t> &bindings) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600648 // bind cb to this descriptor set
649 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600650 // Add bindings for descriptor set, the set's pool, and individual objects in the set
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600651 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 -0600652 pool_state_->cb_bindings.insert(cb_node);
653 cb_node->object_bindings.insert(
654 {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT});
Tobin Ehlisf9519102016-08-17 09:49:13 -0600655 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
656 // resources
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600657 for (auto binding : bindings) {
658 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
659 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
660 for (uint32_t i = start_idx; i <= end_idx; ++i) {
661 descriptors_[i]->BindCommandBuffer(device_data_, cb_node);
662 }
663 }
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600664}
665
Tobin Ehlis300888c2016-05-18 13:43:26 -0600666cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600667 updated = false;
668 descriptor_class = PlainSampler;
669};
670
Tobin Ehlis300888c2016-05-18 13:43:26 -0600671cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600672 updated = false;
673 descriptor_class = PlainSampler;
674 if (immut) {
675 sampler_ = *immut;
676 immutable_ = true;
677 updated = true;
678 }
679}
Tobin Ehlise2f80292016-06-02 10:08:53 -0600680// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
681bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) {
682 return (getSamplerNode(dev_data, sampler) != nullptr);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600683}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600684
Tobin Ehlis554bf382016-05-24 11:14:43 -0600685bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600686 const core_validation::layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code,
687 std::string *error_msg) {
688 // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases.
689 *error_code = VALIDATION_ERROR_00943;
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600690 auto iv_state = getImageViewState(dev_data, image_view);
691 if (!iv_state) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600692 std::stringstream error_str;
693 error_str << "Invalid VkImageView: " << image_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600694 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600695 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600696 }
Tobin Ehlis81280962016-07-20 14:04:20 -0600697 // 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 -0600698 // Validate that imageLayout is compatible with aspect_mask and image format
699 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600700 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
701 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600702 VkFormat format = VK_FORMAT_MAX_ENUM;
703 VkImageUsageFlags usage = 0;
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600704 auto image_node = getImageState(dev_data, image);
Tobin Ehlis1c9c55f2016-06-02 11:49:22 -0600705 if (image_node) {
706 format = image_node->createInfo.format;
707 usage = image_node->createInfo.usage;
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600708 // Validate that memory is bound to image
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600709 if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600710 // TODO : Need new code(s) for language in 11.6 Memory Association
711 *error_msg = "No memory bound to image.";
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600712 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600713 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600714 } else {
Tobin Ehlis1809f912016-05-25 09:24:36 -0600715 // Also need to check the swapchains.
Tobin Ehlis969a5262016-06-02 12:13:32 -0600716 auto swapchain = getSwapchainFromImage(dev_data, image);
717 if (swapchain) {
Tobin Ehlis4e380592016-06-02 12:41:47 -0600718 auto swapchain_node = getSwapchainNode(dev_data, swapchain);
719 if (swapchain_node) {
720 format = swapchain_node->createInfo.imageFormat;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600721 }
722 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600723 }
724 // First validate that format and layout are compatible
725 if (format == VK_FORMAT_MAX_ENUM) {
726 std::stringstream error_str;
727 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600728 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600729 return false;
730 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600731 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
732 // vkCreateImageView(). What's the best way to create unique id for these cases?
Tobin Ehlis1809f912016-05-25 09:24:36 -0600733 bool ds = vk_format_is_depth_or_stencil(format);
734 switch (image_layout) {
735 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
736 // Only Color bit must be set
737 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600738 std::stringstream error_str;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600739 error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does "
740 "not have VK_IMAGE_ASPECT_COLOR_BIT set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600741 *error_msg = error_str.str();
Tobin Ehlis554bf382016-05-24 11:14:43 -0600742 return false;
743 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600744 // format must NOT be DS
745 if (ds) {
746 std::stringstream error_str;
747 error_str << "ImageView (" << image_view
748 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
749 << string_VkFormat(format) << " which is not a color format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600750 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600751 return false;
752 }
753 break;
754 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
755 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
756 // Depth or stencil bit must be set, but both must NOT be set
757 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
758 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
759 // both must NOT be set
760 std::stringstream error_str;
761 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600762 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600763 return false;
764 }
765 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
766 // Neither were set
767 std::stringstream error_str;
768 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
769 << " but does not have STENCIL or DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600770 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600771 return false;
772 }
773 // format must be DS
774 if (!ds) {
775 std::stringstream error_str;
776 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
777 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600778 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600779 return false;
780 }
781 break;
782 default:
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600783 // For other layouts if the source is ds image, both aspect bits must not be set
784 if (ds) {
785 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
786 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
787 // both must NOT be set
788 std::stringstream error_str;
789 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
790 << " and is using depth/stencil image of format " << string_VkFormat(format)
791 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
792 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
793 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
794 "reads respectively.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600795 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600796 return false;
797 }
798 }
799 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600800 break;
801 }
802 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600803 // 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 -0600804 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
805 // under vkCreateImage()
806 // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with
807 // identify swizzle
Tobin Ehlis1809f912016-05-25 09:24:36 -0600808 std::string error_usage_bit;
809 switch (type) {
810 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
811 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
812 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
813 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
814 }
815 break;
816 }
817 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
818 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
819 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600820 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
821 std::stringstream error_str;
822 // TODO : Need to create custom enum error code for this case
823 error_str << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
824 << string_VkImageLayout(image_layout)
825 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can "
826 "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
827 *error_msg = error_str.str();
828 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600829 }
830 break;
831 }
832 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
833 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
834 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
835 }
836 break;
837 }
838 default:
839 break;
840 }
841 if (!error_usage_bit.empty()) {
842 std::stringstream error_str;
843 error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage
844 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
845 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600846 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600847 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600848 }
849 return true;
850}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600851
Tobin Ehlis300888c2016-05-18 13:43:26 -0600852void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
853 sampler_ = update->pImageInfo[index].sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600854 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600855}
856
Tobin Ehlis300888c2016-05-18 13:43:26 -0600857void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600858 if (!immutable_) {
859 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600860 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600861 }
862 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600863}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600864
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600865void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
866 if (!immutable_) {
867 auto sampler_node = getSamplerNode(dev_data, sampler_);
868 if (sampler_node)
869 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
870 }
871}
872
Tobin Ehlis300888c2016-05-18 13:43:26 -0600873cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor()
874 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600875 updated = false;
876 descriptor_class = ImageSampler;
877}
878
Tobin Ehlis300888c2016-05-18 13:43:26 -0600879cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
880 : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600881 updated = false;
882 descriptor_class = ImageSampler;
883 if (immut) {
884 sampler_ = *immut;
885 immutable_ = true;
886 updated = true;
887 }
888}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600889
Tobin Ehlis300888c2016-05-18 13:43:26 -0600890void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600891 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600892 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600893 sampler_ = image_info.sampler;
894 image_view_ = image_info.imageView;
895 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600896}
897
Tobin Ehlis300888c2016-05-18 13:43:26 -0600898void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600899 if (!immutable_) {
900 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600901 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600902 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600903 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
904 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600905 updated = true;
906 image_view_ = image_view;
907 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600908}
909
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600910void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data,
911 GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600912 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600913 if (!immutable_) {
914 auto sampler_node = getSamplerNode(dev_data, sampler_);
915 if (sampler_node)
916 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
917 }
Tobin Ehlis81e46372016-08-17 13:33:44 -0600918 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600919 auto iv_state = getImageViewState(dev_data, image_view_);
920 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600921 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600922 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600923}
924
Tobin Ehlis300888c2016-05-18 13:43:26 -0600925cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
926 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600927 updated = false;
928 descriptor_class = Image;
929 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type)
930 storage_ = true;
931};
932
Tobin Ehlis300888c2016-05-18 13:43:26 -0600933void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600934 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600935 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600936 image_view_ = image_info.imageView;
937 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600938}
939
Tobin Ehlis300888c2016-05-18 13:43:26 -0600940void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600941 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
942 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600943 updated = true;
944 image_view_ = image_view;
945 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600946}
947
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600948void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600949 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600950 auto iv_state = getImageViewState(dev_data, image_view_);
951 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600952 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600953 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600954}
955
Tobin Ehlis300888c2016-05-18 13:43:26 -0600956cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
957 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600958 updated = false;
959 descriptor_class = GeneralBuffer;
960 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
961 dynamic_ = true;
962 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
963 storage_ = true;
964 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
965 dynamic_ = true;
966 storage_ = true;
967 }
968}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600969void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600970 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600971 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600972 buffer_ = buffer_info.buffer;
973 offset_ = buffer_info.offset;
974 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600975}
976
Tobin Ehlis300888c2016-05-18 13:43:26 -0600977void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
978 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600979 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600980 buffer_ = buff_desc->buffer_;
981 offset_ = buff_desc->offset_;
982 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600983}
984
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600985void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600986 auto buffer_node = getBufferNode(dev_data, buffer_);
987 if (buffer_node)
988 core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600989}
990
Tobin Ehlis300888c2016-05-18 13:43:26 -0600991cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600992 updated = false;
993 descriptor_class = TexelBuffer;
994 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type)
995 storage_ = true;
996};
Tobin Ehlis56a30942016-05-19 08:00:00 -0600997
Tobin Ehlis300888c2016-05-18 13:43:26 -0600998void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600999 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001000 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001001}
1002
Tobin Ehlis300888c2016-05-18 13:43:26 -06001003void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1004 updated = true;
1005 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1006}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001007
1008void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis8b872462016-09-14 08:12:08 -06001009 auto bv_state = getBufferViewState(dev_data, buffer_view_);
1010 if (bv_state) {
Tobin Ehlis2515c0e2016-09-28 07:12:28 -06001011 core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001012 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001013}
1014
Tobin Ehlis300888c2016-05-18 13:43:26 -06001015// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1016// sets, and then calls their respective Validate[Write|Copy]Update functions.
1017// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1018// be skipped, then true is returned.
1019// If there is no issue with the update, then false is returned.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001020bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data,
1021 const core_validation::layer_data *dev_data, uint32_t write_count,
1022 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1023 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001024 bool skip_call = false;
1025 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001026 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001027 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001028 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1029 if (!set_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001030 skip_call |=
1031 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 -06001032 reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001033 "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.",
1034 reinterpret_cast<uint64_t &>(dest_set));
1035 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001036 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001037 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001038 if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001039 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 -06001040 reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001041 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001042 " with error: %s. %s",
1043 reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001044 }
1045 }
1046 }
1047 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001048 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001049 auto dst_set = p_cds[i].dstSet;
1050 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001051 auto src_node = core_validation::getSetNode(dev_data, src_set);
1052 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1053 if (!src_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001054 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 -06001055 reinterpret_cast<uint64_t &>(src_set), __LINE__, VALIDATION_ERROR_00971, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001056 "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001057 " that has not been allocated. %s",
1058 reinterpret_cast<uint64_t &>(src_set), validation_error_map[VALIDATION_ERROR_00971]);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001059 } else if (!dst_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001060 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 -06001061 reinterpret_cast<uint64_t &>(dst_set), __LINE__, VALIDATION_ERROR_00972, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001062 "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001063 " that has not been allocated. %s",
1064 reinterpret_cast<uint64_t &>(dst_set), validation_error_map[VALIDATION_ERROR_00972]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001065 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001066 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001067 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001068 if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) {
1069 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1070 reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS",
1071 "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64
1072 " to Descriptor Set 0x%" PRIx64 " with error: %s. %s",
1073 reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set),
1074 error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001075 }
1076 }
1077 }
1078 return skip_call;
1079}
1080// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1081// sets, and then calls their respective Perform[Write|Copy]Update functions.
1082// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1083// with the same set of updates.
1084// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1085// calling down the chain.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001086void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count,
1087 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1088 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001089 // Write updates first
1090 uint32_t i = 0;
1091 for (i = 0; i < write_count; ++i) {
1092 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001093 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1094 if (set_node) {
1095 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001096 }
1097 }
1098 // Now copy updates
1099 for (i = 0; i < copy_count; ++i) {
1100 auto dst_set = p_cds[i].dstSet;
1101 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001102 auto src_node = core_validation::getSetNode(dev_data, src_set);
1103 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1104 if (src_node && dst_node) {
1105 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001106 }
1107 }
1108}
1109// Validate the state for a given write update but don't actually perform the update
1110// If an error would occur for this update, return false and fill in details in error_msg string
1111bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001112 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001113 // Verify idle ds
1114 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001115 // TODO : Re-using Allocate Idle error code, need write update idle error code
1116 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001117 std::stringstream error_str;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001118 error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
1119 << " that is in use by a command buffer.";
1120 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001121 return false;
1122 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001123 // Verify dst binding exists
1124 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001125 *error_code = VALIDATION_ERROR_00936;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001126 std::stringstream error_str;
1127 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << ".";
1128 *error_msg = error_str.str();
1129 return false;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001130 }
1131 // We know that binding is valid, verify update and do update on each descriptor
1132 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
1133 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
1134 if (type != update->descriptorType) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001135 *error_code = VALIDATION_ERROR_00937;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001136 std::stringstream error_str;
1137 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
1138 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
1139 *error_msg = error_str.str();
1140 return false;
1141 }
1142 if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001143 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001144 std::stringstream error_str;
1145 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1146 << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount
1147 << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
1148 << " combined with update array element offset of " << update->dstArrayElement
1149 << " oversteps the size of this descriptor set.";
1150 *error_msg = error_str.str();
1151 return false;
1152 }
1153 // Verify consecutive bindings match (if needed)
1154 if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001155 set_, error_msg)) {
1156 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001157 return false;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001158 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001159 // Update is within bounds and consistent so last step is to validate update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001160 if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) {
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001161 std::stringstream error_str;
1162 error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding
1163 << " failed with error message: " << error_msg->c_str();
1164 *error_msg = error_str.str();
1165 return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001166 }
1167 // All checks passed, update is clean
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001168 return true;
Tobin Ehlis03d61de2016-05-17 08:31:46 -06001169}
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001170// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001171// 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 -06001172bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_NODE const *buffer_node, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001173 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001174 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001175 auto usage = buffer_node->createInfo.usage;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001176 std::string error_usage_bit;
1177 switch (type) {
1178 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1179 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001180 *error_code = VALIDATION_ERROR_00950;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001181 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1182 }
1183 break;
1184 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1185 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001186 *error_code = VALIDATION_ERROR_00951;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001187 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1188 }
1189 break;
1190 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1191 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1192 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001193 *error_code = VALIDATION_ERROR_00946;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001194 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1195 }
1196 break;
1197 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1198 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1199 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001200 *error_code = VALIDATION_ERROR_00947;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001201 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1202 }
1203 break;
1204 default:
1205 break;
1206 }
1207 if (!error_usage_bit.empty()) {
1208 std::stringstream error_str;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001209 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage
1210 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1211 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001212 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001213 return false;
1214 }
1215 return true;
1216}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001217// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1218// 1. buffer is valid
1219// 2. buffer was created with correct usage flags
1220// 3. offset is less than buffer size
1221// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001222// 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 -06001223bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001224 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
1225 // TODO : Defaulting to 00962 for all cases here. Need to create new error codes for a few cases below.
1226 *error_code = VALIDATION_ERROR_00962;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001227 // First make sure that buffer is valid
1228 auto buffer_node = getBufferNode(device_data_, buffer_info->buffer);
1229 if (!buffer_node) {
1230 std::stringstream error_str;
1231 error_str << "Invalid VkBuffer: " << buffer_info->buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001232 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001233 return false;
1234 }
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001235 if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001236 // TODO : This is a repeat code, need new code(s) for language in 11.6 Memory Association
1237 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001238 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001239 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001240 // Verify usage bits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001241 if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
1242 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001243 return false;
1244 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001245 // TODO : Need to also validate device limit offset requirements captured in VALIDATION_ERROR_00944,945
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001246 // offset must be less than buffer size
1247 if (buffer_info->offset > buffer_node->createInfo.size) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001248 *error_code = VALIDATION_ERROR_00959;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001249 std::stringstream error_str;
1250 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer
1251 << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001252 *error_msg = error_str.str();
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 range requirements captured in VALIDATION_ERROR_00948,949
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001256 if (buffer_info->range != VK_WHOLE_SIZE) {
1257 // Range must be VK_WHOLE_SIZE or > 0
1258 if (!buffer_info->range) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001259 *error_code = VALIDATION_ERROR_00960;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001260 std::stringstream error_str;
1261 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001262 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001263 return false;
1264 }
1265 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
1266 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001267 *error_code = VALIDATION_ERROR_00961;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001268 std::stringstream error_str;
1269 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
1270 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001271 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001272 return false;
1273 }
1274 }
1275 return true;
1276}
1277
Tobin Ehlis300888c2016-05-18 13:43:26 -06001278// Verify that the contents of the update are ok, but don't perform actual update
1279bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001280 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1281 std::string *error_msg) const {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001282 switch (update->descriptorType) {
1283 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1284 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1285 // Validate image
1286 auto image_view = update->pImageInfo[di].imageView;
1287 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001288 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001289 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001290 error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1291 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001292 return false;
1293 }
1294 }
1295 // Intentional fall-through to validate sampler
1296 }
1297 case VK_DESCRIPTOR_TYPE_SAMPLER: {
1298 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1299 if (!descriptors_[index + di].get()->IsImmutableSampler()) {
Tobin Ehlise2f80292016-06-02 10:08:53 -06001300 if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001301 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001302 std::stringstream error_str;
1303 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
1304 << update->pImageInfo[di].sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001305 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001306 return false;
1307 }
1308 } else {
1309 // TODO : Warn here
1310 }
1311 }
1312 break;
1313 }
1314 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1315 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1316 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1317 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1318 auto image_view = update->pImageInfo[di].imageView;
1319 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001320 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001321 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001322 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
1323 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001324 return false;
1325 }
1326 }
1327 break;
1328 }
1329 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1330 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
1331 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1332 auto buffer_view = update->pTexelBufferView[di];
Tobin Ehlis8b872462016-09-14 08:12:08 -06001333 auto bv_state = getBufferViewState(device_data_, buffer_view);
1334 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001335 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001336 std::stringstream error_str;
1337 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001338 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001339 return false;
1340 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001341 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001342 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), update->descriptorType, error_code, error_msg)) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001343 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001344 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
1345 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001346 return false;
1347 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001348 }
1349 break;
1350 }
1351 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1352 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1353 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1354 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1355 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001356 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001357 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001358 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
1359 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001360 return false;
1361 }
1362 }
1363 break;
1364 }
1365 default:
1366 assert(0); // We've already verified update type so should never get here
1367 break;
1368 }
1369 // All checks passed so update contents are good
1370 return true;
1371}
1372// Verify that the contents of the update are ok, but don't perform actual update
1373bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001374 VkDescriptorType type, uint32_t index,
1375 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1376 std::string *error_msg) const {
1377 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
1378 // for write updates
Tobin Ehlis300888c2016-05-18 13:43:26 -06001379 switch (src_set->descriptors_[index]->descriptor_class) {
1380 case PlainSampler: {
1381 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1382 if (!src_set->descriptors_[index + di]->IsImmutableSampler()) {
1383 auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001384 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001385 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001386 std::stringstream error_str;
1387 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001388 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001389 return false;
1390 }
1391 } else {
1392 // TODO : Warn here
1393 }
1394 }
1395 break;
1396 }
1397 case ImageSampler: {
1398 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1399 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get());
1400 // First validate sampler
1401 if (!img_samp_desc->IsImmutableSampler()) {
1402 auto update_sampler = img_samp_desc->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001403 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001404 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001405 std::stringstream error_str;
1406 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001407 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001408 return false;
1409 }
1410 } else {
1411 // TODO : Warn here
1412 }
1413 // Validate image
1414 auto image_view = img_samp_desc->GetImageView();
1415 auto image_layout = img_samp_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001416 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001417 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001418 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1419 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001420 return false;
1421 }
1422 }
Alex Smithd8f14792016-09-23 12:18:51 +01001423 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001424 }
1425 case Image: {
1426 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1427 auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get());
1428 auto image_view = img_desc->GetImageView();
1429 auto image_layout = img_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001430 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001431 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001432 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
1433 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001434 return false;
1435 }
1436 }
1437 break;
1438 }
1439 case TexelBuffer: {
1440 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1441 auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -06001442 auto bv_state = getBufferViewState(device_data_, buffer_view);
1443 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001444 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001445 std::stringstream error_str;
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001446 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001447 *error_msg = error_str.str();
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001448 return false;
1449 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001450 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001451 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001452 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001453 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
1454 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001455 return false;
1456 }
1457 }
1458 break;
1459 }
1460 case GeneralBuffer: {
1461 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1462 auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001463 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001464 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001465 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
1466 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001467 return false;
1468 }
1469 }
1470 break;
1471 }
1472 default:
1473 assert(0); // We've already verified update type so should never get here
1474 break;
1475 }
1476 // All checks passed so update contents are good
1477 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12001478}
Tobin Ehlisee471462016-05-26 11:21:59 -06001479// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Tobin Ehlis815e8132016-06-02 13:02:17 -06001480bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data,
1481 const VkDescriptorSetAllocateInfo *p_alloc_info,
1482 const core_validation::layer_data *dev_data,
1483 AllocateDescriptorSetsData *ds_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001484 bool skip_call = false;
Tobin Ehlisee471462016-05-26 11:21:59 -06001485
1486 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001487 auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
1488 if (!layout) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001489 skip_call |=
1490 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
1491 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
1492 "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call",
1493 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]));
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001494 } else {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001495 ds_data->layout_nodes[i] = layout;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001496 // Count total descriptors required per type
Tobin Ehlis815e8132016-06-02 13:02:17 -06001497 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
1498 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001499 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
1500 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
1501 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001502 }
1503 }
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001504 auto pool_state = getDescriptorPoolState(dev_data, p_alloc_info->descriptorPool);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001505 // Track number of descriptorSets allowable in this pool
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001506 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001507 skip_call |= log_msg(
1508 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001509 reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001510 "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.",
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001511 p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableSets);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001512 }
1513 // Determine whether descriptor counts are satisfiable
1514 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001515 if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) {
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001516 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 -06001517 reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001518 "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64
1519 ". This pool only has %d descriptors of this type remaining.",
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001520 ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)),
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001521 reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i]);
Tobin Ehlisee471462016-05-26 11:21:59 -06001522 }
1523 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001524
Tobin Ehlisee471462016-05-26 11:21:59 -06001525 return skip_call;
1526}
1527// Decrement allocated sets from the pool and insert new sets into set_map
Tobin Ehlis4e380592016-06-02 12:41:47 -06001528void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
1529 const VkDescriptorSet *descriptor_sets,
1530 const AllocateDescriptorSetsData *ds_data,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -06001531 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map,
Tobin Ehlis4e380592016-06-02 12:41:47 -06001532 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map,
1533 const core_validation::layer_data *dev_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001534 auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001535 /* Account for sets and individual descriptors allocated from pool */
Tobin Ehlisee471462016-05-26 11:21:59 -06001536 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001537 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
1538 pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i];
1539 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001540 /* Create tracking object for each descriptor set; insert into
1541 * global map and the pool's set.
1542 */
1543 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis93f22372016-10-12 14:34:12 -06001544 auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i],
1545 dev_data);
Tobin Ehlisee471462016-05-26 11:21:59 -06001546
1547 pool_state->sets.insert(new_ds);
1548 new_ds->in_use.store(0);
1549 (*set_map)[descriptor_sets[i]] = new_ds;
1550 }
1551}