blob: 0c6747d66599d6efb110923e025d2128d3c1083c [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,
Tobin Ehlisa1a88a92016-10-25 07:43:27 -060036 reinterpret_cast<uint64_t &>(layout_), __LINE__, VALIDATION_ERROR_02345, "DS",
37 "duplicated binding number in VkDescriptorSetLayoutBinding. %s", validation_error_map[VALIDATION_ERROR_02345]);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060038 }
39 binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index;
40 global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0;
41 binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index;
Tobin Ehlis789c4ed2016-10-17 13:51:57 -060042 global_index += p_create_info->pBindings[i].descriptorCount ? 1 : 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060043 bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i]));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060044 // In cases where we should ignore pImmutableSamplers make sure it's NULL
45 if ((p_create_info->pBindings[i].pImmutableSamplers) &&
46 ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) &&
47 (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060048 bindings_.back().pImmutableSamplers = nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060049 }
50 if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
51 p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
Tobin Ehlisef0de162016-06-20 13:07:34 -060052 dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060053 }
54 }
55}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060056// put all bindings into the given set
57void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const {
58 for (auto binding_index_pair : binding_to_index_map_)
59 binding_set->insert(binding_index_pair.first);
60}
Tobin Ehlis56a30942016-05-19 08:00:00 -060061
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060062VkDescriptorSetLayoutBinding const *
63cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060064 const auto &bi_itr = binding_to_index_map_.find(binding);
65 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060066 return bindings_[bi_itr->second].ptr();
Tobin Ehlis0bc30632016-05-05 10:16:02 -060067 }
68 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060069}
70VkDescriptorSetLayoutBinding const *
71cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
72 if (index >= bindings_.size())
73 return nullptr;
Tobin Ehlis664e6012016-05-05 11:04:44 -060074 return bindings_[index].ptr();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060075}
76// Return descriptorCount for given binding, 0 if index is unavailable
77uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const {
Tobin Ehlis0bc30632016-05-05 10:16:02 -060078 const auto &bi_itr = binding_to_index_map_.find(binding);
79 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060080 return bindings_[bi_itr->second].descriptorCount;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060081 }
82 return 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060083}
84// Return descriptorCount for given index, 0 if index is unavailable
85uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const {
86 if (index >= bindings_.size())
87 return 0;
Tobin Ehlis664e6012016-05-05 11:04:44 -060088 return bindings_[index].descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060089}
90// For the given binding, return descriptorType
91VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const {
92 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -060093 const auto &bi_itr = binding_to_index_map_.find(binding);
94 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -060095 return bindings_[bi_itr->second].descriptorType;
Tobin Ehlis0bc30632016-05-05 10:16:02 -060096 }
97 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060098}
99// For the given index, return descriptorType
100VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const {
101 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600102 return bindings_[index].descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600103}
104// For the given global index, return descriptorType
105// Currently just counting up through bindings_, may improve this in future
106VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const {
107 uint32_t global_offset = 0;
108 for (auto binding : bindings_) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600109 global_offset += binding.descriptorCount;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600110 if (index < global_offset)
Tobin Ehlis664e6012016-05-05 11:04:44 -0600111 return binding.descriptorType;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600112 }
113 assert(0); // requested global index is out of bounds
114 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
115}
116// For the given binding, return stageFlags
117VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const {
118 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600119 const auto &bi_itr = binding_to_index_map_.find(binding);
120 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600121 return bindings_[bi_itr->second].stageFlags;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600122 }
123 return VkShaderStageFlags(0);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600124}
125// For the given binding, return start index
126uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const {
127 assert(binding_to_global_start_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600128 const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding);
129 if (btgsi_itr != binding_to_global_start_index_map_.end()) {
130 return btgsi_itr->second;
131 }
132 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600133 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600134 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600135}
136// For the given binding, return end index
137uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const {
138 assert(binding_to_global_end_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600139 const auto &btgei_itr = binding_to_global_end_index_map_.find(binding);
140 if (btgei_itr != binding_to_global_end_index_map_.end()) {
141 return btgei_itr->second;
142 }
143 // In error case max uint32_t so index is out of bounds to break ASAP
Tobin Ehlis58c59582016-06-21 12:34:33 -0600144 assert(0);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600145 return 0xFFFFFFFF;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600146}
147// For given binding, return ptr to ImmutableSampler array
148VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
149 assert(binding_to_index_map_.count(binding));
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600150 const auto &bi_itr = binding_to_index_map_.find(binding);
151 if (bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600152 return bindings_[bi_itr->second].pImmutableSamplers;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600153 }
154 return nullptr;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600155}
156// For given index, return ptr to ImmutableSampler array
157VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
158 assert(index < bindings_.size());
Tobin Ehlis664e6012016-05-05 11:04:44 -0600159 return bindings_[index].pImmutableSamplers;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600160}
161// If our layout is compatible with rh_ds_layout, return true,
162// else return false and fill in error_msg will description of what causes incompatibility
163bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const {
164 // Trivial case
165 if (layout_ == rh_ds_layout->GetDescriptorSetLayout())
166 return true;
167 if (descriptor_count_ != rh_ds_layout->descriptor_count_) {
168 std::stringstream error_str;
169 error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
170 << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors.";
171 *error_msg = error_str.str();
172 return false; // trivial fail case
173 }
174 // Descriptor counts match so need to go through bindings one-by-one
175 // and verify that type and stageFlags match
176 for (auto binding : bindings_) {
177 // TODO : Do we also need to check immutable samplers?
178 // VkDescriptorSetLayoutBinding *rh_binding;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600179 if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600180 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600181 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of "
182 << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600183 << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600184 << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600185 *error_msg = error_str.str();
186 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600187 } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600188 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600189 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '"
190 << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600191 << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '"
Tobin Ehlis664e6012016-05-05 11:04:44 -0600192 << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600193 *error_msg = error_str.str();
194 return false;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600195 } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600196 std::stringstream error_str;
Tobin Ehlis664e6012016-05-05 11:04:44 -0600197 error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags "
198 << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout "
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600199 << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags "
Tobin Ehlis664e6012016-05-05 11:04:44 -0600200 << rh_ds_layout->GetStageFlagsFromBinding(binding.binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600201 *error_msg = error_str.str();
202 return false;
203 }
204 }
205 return true;
206}
207
208bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const {
209 if (!binding_to_index_map_.count(binding + 1))
210 return false;
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600211 auto const &bi_itr = binding_to_index_map_.find(binding);
212 if (bi_itr != binding_to_index_map_.end()) {
213 const auto &next_bi_itr = binding_to_index_map_.find(binding + 1);
214 if (next_bi_itr != binding_to_index_map_.end()) {
Tobin Ehlis664e6012016-05-05 11:04:44 -0600215 auto type = bindings_[bi_itr->second].descriptorType;
216 auto stage_flags = bindings_[bi_itr->second].stageFlags;
217 auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false;
218 if ((type != bindings_[next_bi_itr->second].descriptorType) ||
219 (stage_flags != bindings_[next_bi_itr->second].stageFlags) ||
220 (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) {
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600221 return false;
222 }
223 return true;
224 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600225 }
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600226 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600227}
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600228// Starting at offset descriptor of given binding, parse over update_count
229// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
230// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
231// If so, return true. If not, fill in error_msg and return false
232bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count,
233 const char *type, const VkDescriptorSet set,
234 std::string *error_msg) const {
235 // Verify consecutive bindings match (if needed)
236 auto orig_binding = current_binding;
237 // Track count of descriptors in the current_bindings that are remaining to be updated
238 auto binding_remaining = GetDescriptorCountFromBinding(current_binding);
239 // First, it's legal to offset beyond your own binding so handle that case
240 // Really this is just searching for the binding in which the update begins and adjusting offset accordingly
241 while (offset >= binding_remaining) {
242 // Advance to next binding, decrement offset by binding size
243 offset -= binding_remaining;
244 binding_remaining = GetDescriptorCountFromBinding(++current_binding);
245 }
246 binding_remaining -= offset;
247 while (update_count > binding_remaining) { // While our updates overstep current binding
248 // Verify next consecutive binding matches type, stage flags & immutable sampler use
249 if (!IsNextBindingConsistent(current_binding++)) {
250 std::stringstream error_str;
251 error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #"
252 << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the "
253 "next binding is not consistent with current binding so this update is invalid.";
254 *error_msg = error_str.str();
255 return false;
256 }
257 // For sake of this check consider the bindings updated and grab count for next binding
258 update_count -= binding_remaining;
259 binding_remaining = GetDescriptorCountFromBinding(current_binding);
260 }
261 return true;
262}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600263
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600264cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count)
265 : required_descriptors_by_type{}, layout_nodes(count, nullptr) {}
266
Tobin Ehlis93f22372016-10-12 14:34:12 -0600267cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool,
268 const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data)
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600269 : some_update_(false), set_(set), pool_state_(nullptr), p_layout_(layout), device_data_(dev_data) {
270 pool_state_ = getDescriptorPoolState(dev_data, pool);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600271 // Foreach binding, create default descriptors of given type
272 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
273 auto type = p_layout_->GetTypeFromIndex(i);
274 switch (type) {
275 case VK_DESCRIPTOR_TYPE_SAMPLER: {
276 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
277 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
278 if (immut_sampler)
Chris Forbescb621ea2016-05-30 11:47:31 +1200279 descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600280 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200281 descriptors_.emplace_back(new SamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600282 }
283 break;
284 }
285 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
286 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
287 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
288 if (immut)
Chris Forbescb621ea2016-05-30 11:47:31 +1200289 descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600290 else
Chris Forbescb621ea2016-05-30 11:47:31 +1200291 descriptors_.emplace_back(new ImageSamplerDescriptor());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600292 }
293 break;
294 }
295 // ImageDescriptors
296 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
297 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
298 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
299 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200300 descriptors_.emplace_back(new ImageDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600301 break;
302 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
303 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
304 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200305 descriptors_.emplace_back(new TexelDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600306 break;
307 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
308 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
309 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
310 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
311 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
Chris Forbescb621ea2016-05-30 11:47:31 +1200312 descriptors_.emplace_back(new BufferDescriptor(type));
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600313 break;
314 default:
Tobin Ehlis81f17852016-05-05 09:04:33 -0600315 assert(0); // Bad descriptor type specified
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600316 break;
317 }
318 }
319}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600320
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600321cvdescriptorset::DescriptorSet::~DescriptorSet() {
322 InvalidateBoundCmdBuffers();
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600323}
Chris Forbes57989132016-07-26 17:06:10 +1200324
325
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700326static std::string string_descriptor_req_view_type(descriptor_req req) {
327 std::string result("");
Chris Forbes57989132016-07-26 17:06:10 +1200328 for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) {
329 if (req & (1 << i)) {
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700330 if (result.size()) result += ", ";
331 result += string_VkImageViewType(VkImageViewType(i));
Chris Forbes57989132016-07-26 17:06:10 +1200332 }
333 }
334
Chris Forbes6e58ebd2016-08-31 12:58:14 -0700335 if (!result.size())
336 result = "(none)";
337
338 return result;
Chris Forbes57989132016-07-26 17:06:10 +1200339}
340
341
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600342// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
343bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const {
344 return layout->IsCompatible(p_layout_, error);
345}
Chris Forbes57989132016-07-26 17:06:10 +1200346
Tobin Ehlis3066db62016-08-22 08:12:23 -0600347// 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 -0600348// This includes validating that all descriptors in the given bindings are updated,
349// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
350// Return true if state is acceptable, or false and write an error message into error string
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600351bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600352 const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
iostrows5eb97652016-06-02 15:56:26 +0200353 auto dyn_offset_index = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200354 for (auto binding_pair : bindings) {
355 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600356 if (!p_layout_->HasBinding(binding)) {
357 std::stringstream error_str;
358 error_str << "Attempting to validate DrawState for binding #" << binding
359 << " which is an invalid binding for this descriptor set.";
360 *error = error_str.str();
361 return false;
362 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600363 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600364 if (descriptors_[start_idx]->IsImmutableSampler()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600365 // Nothing to do for strictly immutable sampler
366 } else {
367 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600368 for (uint32_t i = start_idx; i <= end_idx; ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600369 if (!descriptors_[i]->updated) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600370 std::stringstream error_str;
371 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
372 << " is being used in draw but has not been updated.";
373 *error = error_str.str();
374 return false;
375 } else {
Chris Forbes57989132016-07-26 17:06:10 +1200376 auto descriptor_class = descriptors_[i]->GetClass();
377 if (descriptor_class == GeneralBuffer) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600378 // Verify that buffers are valid
Tobin Ehlis81f17852016-05-05 09:04:33 -0600379 auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer();
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600380 auto buffer_node = getBufferNode(device_data_, buffer);
381 if (!buffer_node) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600382 std::stringstream error_str;
383 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
384 << " references invalid buffer " << buffer << ".";
385 *error = error_str.str();
386 return false;
387 } else {
Tobin Ehlis54108272016-10-11 14:26:49 -0600388 auto mem_entry = getMemObjInfo(device_data_, buffer_node->binding.mem);
Tobin Ehlis997b2582016-06-02 08:43:37 -0600389 if (!mem_entry) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600390 std::stringstream error_str;
391 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
Tobin Ehlis54108272016-10-11 14:26:49 -0600392 << " uses buffer " << buffer << " that references invalid memory "
393 << buffer_node->binding.mem << ".";
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600394 *error = error_str.str();
395 return false;
396 }
397 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600398 if (descriptors_[i]->IsDynamic()) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600399 // Validate that dynamic offsets are within the buffer
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600400 auto buffer_size = buffer_node->createInfo.size;
Tobin Ehlis81f17852016-05-05 09:04:33 -0600401 auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange();
402 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600403 auto dyn_offset = dynamic_offsets[dyn_offset_index++];
404 if (VK_WHOLE_SIZE == range) {
405 if ((dyn_offset + desc_offset) > buffer_size) {
406 std::stringstream error_str;
407 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
408 << " uses buffer " << buffer
409 << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
410 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
411 << buffer_size << ".";
412 *error = error_str.str();
413 return false;
414 }
415 } else {
416 if ((dyn_offset + desc_offset + range) > buffer_size) {
417 std::stringstream error_str;
418 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
419 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
420 << " combined with offset " << desc_offset << " and range " << range
421 << " that oversteps the buffer size of " << buffer_size << ".";
422 *error = error_str.str();
423 return false;
424 }
425 }
426 }
427 }
Chris Forbes57989132016-07-26 17:06:10 +1200428 else if (descriptor_class == ImageSampler || descriptor_class == Image) {
429 auto image_view = (descriptor_class == ImageSampler)
430 ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView()
431 : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView();
432 auto reqs = binding_pair.second;
433
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600434 auto image_view_state = getImageViewState(device_data_, image_view);
435 assert(image_view_state);
436 auto image_view_ci = image_view_state->create_info;
Chris Forbes57989132016-07-26 17:06:10 +1200437
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600438 if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) {
Chris Forbes57989132016-07-26 17:06:10 +1200439 // bad view type
440 std::stringstream error_str;
441 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
442 << " requires an image view of type " << string_descriptor_req_view_type(reqs)
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600443 << " but got " << string_VkImageViewType(image_view_ci.viewType) << ".";
Chris Forbes57989132016-07-26 17:06:10 +1200444 *error = error_str.str();
445 return false;
446 }
447
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600448 auto image_node = getImageState(device_data_, image_view_ci.image);
Chris Forbes57989132016-07-26 17:06:10 +1200449 assert(image_node);
450
451 if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) &&
452 image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) {
453 std::stringstream error_str;
454 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
455 << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got "
456 << string_VkSampleCountFlagBits(image_node->createInfo.samples) << ".";
457 *error = error_str.str();
458 return false;
459 }
460
461 if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) &&
462 image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) {
463 std::stringstream error_str;
464 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
465 << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.";
466 *error = error_str.str();
467 return false;
468 }
469 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600470 }
471 }
472 }
473 }
474 return true;
475}
Chris Forbes57989132016-07-26 17:06:10 +1200476
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600477// For given bindings, place any update buffers or images into the passed-in unordered_sets
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600478uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600479 std::unordered_set<VkBuffer> *buffer_set,
480 std::unordered_set<VkImageView> *image_set) const {
481 auto num_updates = 0;
Chris Forbesc7090a82016-07-25 18:10:41 +1200482 for (auto binding_pair : bindings) {
483 auto binding = binding_pair.first;
Tobin Ehlis58c59582016-06-21 12:34:33 -0600484 // If a binding doesn't exist, skip it
485 if (!p_layout_->HasBinding(binding)) {
486 continue;
487 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600488 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
Tobin Ehlis81f17852016-05-05 09:04:33 -0600489 if (descriptors_[start_idx]->IsStorage()) {
490 if (Image == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600491 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600492 if (descriptors_[start_idx + i]->updated) {
493 image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600494 num_updates++;
495 }
496 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600497 } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600498 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600499 if (descriptors_[start_idx + i]->updated) {
500 auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -0600501 auto bv_state = getBufferViewState(device_data_, bufferview);
502 if (bv_state) {
503 buffer_set->insert(bv_state->create_info.buffer);
Tobin Ehlis0bc30632016-05-05 10:16:02 -0600504 num_updates++;
505 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600506 }
507 }
Tobin Ehlis81f17852016-05-05 09:04:33 -0600508 } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600509 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
Tobin Ehlis81f17852016-05-05 09:04:33 -0600510 if (descriptors_[start_idx + i]->updated) {
511 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600512 num_updates++;
513 }
514 }
515 }
516 }
517 }
518 return num_updates;
519}
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600520// Set is being deleted or updates so invalidate all bound cmd buffers
521void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() {
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600522 core_validation::invalidateCommandBuffers(cb_bindings,
523 {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT});
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600524}
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600525// Perform write update in given update struct
Tobin Ehlis300888c2016-05-18 13:43:26 -0600526void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600527 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
528 // perform update
529 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
530 descriptors_[start_idx + di]->WriteUpdate(update, di);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600531 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600532 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600533 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600534
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600535 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600536}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600537// Validate Copy update
538bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600539 const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code,
540 std::string *error_msg) {
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600541 // Verify idle ds
542 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600543 // TODO : Re-using Allocate Idle error code, need copy update idle error code
544 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600545 std::stringstream error_str;
546 error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
547 << " that is in use by a command buffer.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600548 *error_msg = error_str.str();
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600549 return false;
550 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600551 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600552 *error_code = VALIDATION_ERROR_00966;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600553 std::stringstream error_str;
554 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600555 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600556 return false;
557 }
558 if (!src_set->HasBinding(update->srcBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600559 *error_code = VALIDATION_ERROR_00964;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600560 std::stringstream error_str;
561 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600562 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600563 return false;
564 }
565 // src & dst set bindings are valid
566 // Check bounds of src & dst
567 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
568 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
569 // SRC update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600570 *error_code = VALIDATION_ERROR_00965;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600571 std::stringstream error_str;
572 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
573 << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding)
574 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
575 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600576 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600577 return false;
578 }
579 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
580 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
581 // DST update out of bounds
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600582 *error_code = VALIDATION_ERROR_00967;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600583 std::stringstream error_str;
584 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
585 << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
586 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
587 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600588 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600589 return false;
590 }
591 // Check that types match
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600592 // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more
593 // fine-grained error codes
594 *error_code = VALIDATION_ERROR_00968;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600595 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
596 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
597 if (src_type != dst_type) {
598 std::stringstream error_str;
599 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
600 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
601 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600602 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600603 return false;
604 }
605 // Verify consistency of src & dst bindings if update crosses binding boundaries
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600606 if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600607 "copy update from", src_set->GetSet(), error_msg)) ||
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600608 (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600609 set_, error_msg))) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600610 return false;
611 }
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600612 // First make sure source descriptors are updated
613 for (uint32_t i = 0; i < update->descriptorCount; ++i) {
614 if (!src_set->descriptors_[src_start_idx + i]) {
615 std::stringstream error_str;
616 error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset "
617 << update->srcArrayElement + i << " has not been updated.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600618 *error_msg = error_str.str();
Tobin Ehlisd41e7b62016-05-19 07:56:18 -0600619 return false;
620 }
621 }
622 // Update parameters all look good and descriptor updated so verify update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600623 if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg))
Tobin Ehlis300888c2016-05-18 13:43:26 -0600624 return false;
625
626 // All checks passed so update is good
627 return true;
628}
629// Perform Copy update
630void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600631 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
632 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600633 // Update parameters all look good so perform update
634 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis300888c2016-05-18 13:43:26 -0600635 descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get());
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600636 }
Tobin Ehlis56a30942016-05-19 08:00:00 -0600637 if (update->descriptorCount)
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600638 some_update_ = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600639
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600640 InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600641}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600642
Tobin Ehlisf9519102016-08-17 09:49:13 -0600643// Bind cb_node to this set and this set to cb_node.
644// Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going
645// to be used in a draw by the given cb_node
Tobin Ehlisf9519102016-08-17 09:49:13 -0600646void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, const std::unordered_set<uint32_t> &bindings) {
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600647 // bind cb to this descriptor set
648 cb_bindings.insert(cb_node);
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600649 // Add bindings for descriptor set, the set's pool, and individual objects in the set
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600650 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 -0600651 pool_state_->cb_bindings.insert(cb_node);
652 cb_node->object_bindings.insert(
653 {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT});
Tobin Ehlisf9519102016-08-17 09:49:13 -0600654 // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's
655 // resources
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600656 for (auto binding : bindings) {
657 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
658 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
659 for (uint32_t i = start_idx; i <= end_idx; ++i) {
660 descriptors_[i]->BindCommandBuffer(device_data_, cb_node);
661 }
662 }
Tobin Ehlis9252c2b2016-07-21 14:40:22 -0600663}
664
Tobin Ehlis300888c2016-05-18 13:43:26 -0600665cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600666 updated = false;
667 descriptor_class = PlainSampler;
668};
669
Tobin Ehlis300888c2016-05-18 13:43:26 -0600670cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600671 updated = false;
672 descriptor_class = PlainSampler;
673 if (immut) {
674 sampler_ = *immut;
675 immutable_ = true;
676 updated = true;
677 }
678}
Tobin Ehlise2f80292016-06-02 10:08:53 -0600679// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap
680bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) {
681 return (getSamplerNode(dev_data, sampler) != nullptr);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600682}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600683
Tobin Ehlis554bf382016-05-24 11:14:43 -0600684bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600685 const core_validation::layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code,
686 std::string *error_msg) {
687 // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases.
688 *error_code = VALIDATION_ERROR_00943;
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600689 auto iv_state = getImageViewState(dev_data, image_view);
690 if (!iv_state) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600691 std::stringstream error_str;
692 error_str << "Invalid VkImageView: " << image_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600693 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600694 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600695 }
Tobin Ehlis81280962016-07-20 14:04:20 -0600696 // 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 -0600697 // Validate that imageLayout is compatible with aspect_mask and image format
698 // and validate that image usage bits are correct for given usage
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600699 VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask;
700 VkImage image = iv_state->create_info.image;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600701 VkFormat format = VK_FORMAT_MAX_ENUM;
702 VkImageUsageFlags usage = 0;
Tobin Ehlis30df15c2016-10-12 17:17:57 -0600703 auto image_node = getImageState(dev_data, image);
Tobin Ehlis1c9c55f2016-06-02 11:49:22 -0600704 if (image_node) {
705 format = image_node->createInfo.format;
706 usage = image_node->createInfo.usage;
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600707 // Validate that memory is bound to image
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600708 if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600709 // TODO : Need new code(s) for language in 11.6 Memory Association
710 *error_msg = "No memory bound to image.";
Tobin Ehlis029d2fe2016-09-21 09:19:15 -0600711 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -0600712 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600713 } else {
Tobin Ehlis1809f912016-05-25 09:24:36 -0600714 // Also need to check the swapchains.
Tobin Ehlis969a5262016-06-02 12:13:32 -0600715 auto swapchain = getSwapchainFromImage(dev_data, image);
716 if (swapchain) {
Tobin Ehlis4e380592016-06-02 12:41:47 -0600717 auto swapchain_node = getSwapchainNode(dev_data, swapchain);
718 if (swapchain_node) {
719 format = swapchain_node->createInfo.imageFormat;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600720 }
721 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600722 }
723 // First validate that format and layout are compatible
724 if (format == VK_FORMAT_MAX_ENUM) {
725 std::stringstream error_str;
726 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600727 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600728 return false;
729 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600730 // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under
731 // vkCreateImageView(). What's the best way to create unique id for these cases?
Tobin Ehlis1809f912016-05-25 09:24:36 -0600732 bool ds = vk_format_is_depth_or_stencil(format);
733 switch (image_layout) {
734 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
735 // Only Color bit must be set
736 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600737 std::stringstream error_str;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600738 error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does "
739 "not have VK_IMAGE_ASPECT_COLOR_BIT set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600740 *error_msg = error_str.str();
Tobin Ehlis554bf382016-05-24 11:14:43 -0600741 return false;
742 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600743 // format must NOT be DS
744 if (ds) {
745 std::stringstream error_str;
746 error_str << "ImageView (" << image_view
747 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
748 << string_VkFormat(format) << " which is not a color format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600749 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600750 return false;
751 }
752 break;
753 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
754 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
755 // Depth or stencil bit must be set, but both must NOT be set
756 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
757 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
758 // both must NOT be set
759 std::stringstream error_str;
760 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600761 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600762 return false;
763 }
764 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
765 // Neither were set
766 std::stringstream error_str;
767 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
768 << " but does not have STENCIL or DEPTH aspects set";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600769 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600770 return false;
771 }
772 // format must be DS
773 if (!ds) {
774 std::stringstream error_str;
775 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
776 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600777 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600778 return false;
779 }
780 break;
781 default:
Mike Weiblencce7ec72016-10-17 19:33:05 -0600782 // For other layouts if the source is depth/stencil image, both aspect bits must not be set
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600783 if (ds) {
784 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
785 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
786 // both must NOT be set
787 std::stringstream error_str;
788 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
789 << " and is using depth/stencil image of format " << string_VkFormat(format)
790 << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil "
791 "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or "
792 "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil "
793 "reads respectively.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600794 *error_msg = error_str.str();
Tobin Ehlisbbf3f912016-06-15 13:03:58 -0600795 return false;
796 }
797 }
798 }
Tobin Ehlis1809f912016-05-25 09:24:36 -0600799 break;
800 }
801 // Now validate that usage flags are correctly set for given type of update
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600802 // 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 -0600803 // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images
804 // under vkCreateImage()
805 // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with
806 // identify swizzle
Tobin Ehlis1809f912016-05-25 09:24:36 -0600807 std::string error_usage_bit;
808 switch (type) {
809 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
810 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
811 if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
812 error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT";
813 }
814 break;
815 }
816 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
817 if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) {
818 error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT";
Tobin Ehlisfb4cf712016-10-10 14:02:48 -0600819 } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) {
820 std::stringstream error_str;
821 // TODO : Need to create custom enum error code for this case
822 error_str << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
823 << string_VkImageLayout(image_layout)
824 << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can "
825 "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'";
826 *error_msg = error_str.str();
827 return false;
Tobin Ehlis1809f912016-05-25 09:24:36 -0600828 }
829 break;
830 }
831 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: {
832 if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
833 error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT";
834 }
835 break;
836 }
837 default:
838 break;
839 }
840 if (!error_usage_bit.empty()) {
841 std::stringstream error_str;
842 error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage
843 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
844 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600845 *error_msg = error_str.str();
Tobin Ehlis1809f912016-05-25 09:24:36 -0600846 return false;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600847 }
848 return true;
849}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600850
Tobin Ehlis300888c2016-05-18 13:43:26 -0600851void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
852 sampler_ = update->pImageInfo[index].sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600853 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600854}
855
Tobin Ehlis300888c2016-05-18 13:43:26 -0600856void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600857 if (!immutable_) {
858 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600859 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600860 }
861 updated = true;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600862}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600863
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600864void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
865 if (!immutable_) {
866 auto sampler_node = getSamplerNode(dev_data, sampler_);
867 if (sampler_node)
868 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
869 }
870}
871
Tobin Ehlis300888c2016-05-18 13:43:26 -0600872cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor()
873 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600874 updated = false;
875 descriptor_class = ImageSampler;
876}
877
Tobin Ehlis300888c2016-05-18 13:43:26 -0600878cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut)
879 : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600880 updated = false;
881 descriptor_class = ImageSampler;
882 if (immut) {
883 sampler_ = *immut;
884 immutable_ = true;
885 updated = true;
886 }
887}
Tobin Ehlis56a30942016-05-19 08:00:00 -0600888
Tobin Ehlis300888c2016-05-18 13:43:26 -0600889void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600890 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600891 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600892 sampler_ = image_info.sampler;
893 image_view_ = image_info.imageView;
894 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600895}
896
Tobin Ehlis300888c2016-05-18 13:43:26 -0600897void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600898 if (!immutable_) {
899 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600900 sampler_ = update_sampler;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600901 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600902 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
903 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600904 updated = true;
905 image_view_ = image_view;
906 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600907}
908
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600909void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data,
910 GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600911 // First add binding for any non-immutable sampler
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600912 if (!immutable_) {
913 auto sampler_node = getSamplerNode(dev_data, sampler_);
914 if (sampler_node)
915 core_validation::AddCommandBufferBindingSampler(cb_node, sampler_node);
916 }
Tobin Ehlis81e46372016-08-17 13:33:44 -0600917 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600918 auto iv_state = getImageViewState(dev_data, image_view_);
919 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600920 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600921 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600922}
923
Tobin Ehlis300888c2016-05-18 13:43:26 -0600924cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type)
925 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600926 updated = false;
927 descriptor_class = Image;
928 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type)
929 storage_ = true;
930};
931
Tobin Ehlis300888c2016-05-18 13:43:26 -0600932void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600933 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600934 const auto &image_info = update->pImageInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600935 image_view_ = image_info.imageView;
936 image_layout_ = image_info.imageLayout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600937}
938
Tobin Ehlis300888c2016-05-18 13:43:26 -0600939void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600940 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
941 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600942 updated = true;
943 image_view_ = image_view;
944 image_layout_ = image_layout;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600945}
946
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600947void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600948 // Add binding for image
Tobin Ehlis8b26a382016-09-14 08:02:49 -0600949 auto iv_state = getImageViewState(dev_data, image_view_);
950 if (iv_state) {
Tobin Ehlis15b8ea02016-09-19 14:02:58 -0600951 core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -0600952 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600953}
954
Tobin Ehlis300888c2016-05-18 13:43:26 -0600955cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type)
956 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600957 updated = false;
958 descriptor_class = GeneralBuffer;
959 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
960 dynamic_ = true;
961 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
962 storage_ = true;
963 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
964 dynamic_ = true;
965 storage_ = true;
966 }
967}
Tobin Ehlis300888c2016-05-18 13:43:26 -0600968void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600969 updated = true;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600970 const auto &buffer_info = update->pBufferInfo[index];
Tobin Ehlis300888c2016-05-18 13:43:26 -0600971 buffer_ = buffer_info.buffer;
972 offset_ = buffer_info.offset;
973 range_ = buffer_info.range;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600974}
975
Tobin Ehlis300888c2016-05-18 13:43:26 -0600976void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) {
977 auto buff_desc = static_cast<const BufferDescriptor *>(src);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600978 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600979 buffer_ = buff_desc->buffer_;
980 offset_ = buff_desc->offset_;
981 range_ = buff_desc->range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600982}
983
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600984void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis81e46372016-08-17 13:33:44 -0600985 auto buffer_node = getBufferNode(dev_data, buffer_);
986 if (buffer_node)
987 core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node);
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600988}
989
Tobin Ehlis300888c2016-05-18 13:43:26 -0600990cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600991 updated = false;
992 descriptor_class = TexelBuffer;
993 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type)
994 storage_ = true;
995};
Tobin Ehlis56a30942016-05-19 08:00:00 -0600996
Tobin Ehlis300888c2016-05-18 13:43:26 -0600997void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600998 updated = true;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600999 buffer_view_ = update->pTexelBufferView[index];
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001000}
1001
Tobin Ehlis300888c2016-05-18 13:43:26 -06001002void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) {
1003 updated = true;
1004 buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_;
1005}
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001006
1007void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) {
Tobin Ehlis8b872462016-09-14 08:12:08 -06001008 auto bv_state = getBufferViewState(dev_data, buffer_view_);
1009 if (bv_state) {
Tobin Ehlis2515c0e2016-09-28 07:12:28 -06001010 core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state);
Tobin Ehlis81e46372016-08-17 13:33:44 -06001011 }
Tobin Ehlis8020eea2016-08-17 11:10:41 -06001012}
1013
Tobin Ehlis300888c2016-05-18 13:43:26 -06001014// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1015// sets, and then calls their respective Validate[Write|Copy]Update functions.
1016// If the update hits an issue for which the callback returns "true", meaning that the call down the chain should
1017// be skipped, then true is returned.
1018// If there is no issue with the update, then false is returned.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001019bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data,
1020 const core_validation::layer_data *dev_data, uint32_t write_count,
1021 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1022 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001023 bool skip_call = false;
1024 // Validate Write updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001025 for (uint32_t i = 0; i < write_count; i++) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001026 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001027 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1028 if (!set_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001029 skip_call |=
1030 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 -06001031 reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001032 "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.",
1033 reinterpret_cast<uint64_t &>(dest_set));
1034 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001035 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001036 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001037 if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001038 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 -06001039 reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001040 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001041 " with error: %s. %s",
1042 reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001043 }
1044 }
1045 }
1046 // Now validate copy updates
Tobin Ehlis56a30942016-05-19 08:00:00 -06001047 for (uint32_t i = 0; i < copy_count; ++i) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001048 auto dst_set = p_cds[i].dstSet;
1049 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001050 auto src_node = core_validation::getSetNode(dev_data, src_set);
1051 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1052 if (!src_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001053 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 -06001054 reinterpret_cast<uint64_t &>(src_set), __LINE__, VALIDATION_ERROR_00971, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001055 "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001056 " that has not been allocated. %s",
1057 reinterpret_cast<uint64_t &>(src_set), validation_error_map[VALIDATION_ERROR_00971]);
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001058 } else if (!dst_node) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001059 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 -06001060 reinterpret_cast<uint64_t &>(dst_set), __LINE__, VALIDATION_ERROR_00972, "DS",
Tobin Ehlis300888c2016-05-18 13:43:26 -06001061 "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001062 " that has not been allocated. %s",
1063 reinterpret_cast<uint64_t &>(dst_set), validation_error_map[VALIDATION_ERROR_00972]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001064 } else {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001065 UNIQUE_VALIDATION_ERROR_CODE error_code;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001066 std::string error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001067 if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) {
1068 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT,
1069 reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS",
1070 "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64
1071 " to Descriptor Set 0x%" PRIx64 " with error: %s. %s",
1072 reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set),
1073 error_str.c_str(), validation_error_map[error_code]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001074 }
1075 }
1076 }
1077 return skip_call;
1078}
1079// This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated
1080// sets, and then calls their respective Perform[Write|Copy]Update functions.
1081// Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets()
1082// with the same set of updates.
1083// This is split from the validate code to allow validation prior to calling down the chain, and then update after
1084// calling down the chain.
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001085void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count,
1086 const VkWriteDescriptorSet *p_wds, uint32_t copy_count,
1087 const VkCopyDescriptorSet *p_cds) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001088 // Write updates first
1089 uint32_t i = 0;
1090 for (i = 0; i < write_count; ++i) {
1091 auto dest_set = p_wds[i].dstSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001092 auto set_node = core_validation::getSetNode(dev_data, dest_set);
1093 if (set_node) {
1094 set_node->PerformWriteUpdate(&p_wds[i]);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001095 }
1096 }
1097 // Now copy updates
1098 for (i = 0; i < copy_count; ++i) {
1099 auto dst_set = p_cds[i].dstSet;
1100 auto src_set = p_cds[i].srcSet;
Tobin Ehlis6a72dc72016-06-01 16:41:17 -06001101 auto src_node = core_validation::getSetNode(dev_data, src_set);
1102 auto dst_node = core_validation::getSetNode(dev_data, dst_set);
1103 if (src_node && dst_node) {
1104 dst_node->PerformCopyUpdate(&p_cds[i], src_node);
Tobin Ehlis300888c2016-05-18 13:43:26 -06001105 }
1106 }
1107}
1108// Validate the state for a given write update but don't actually perform the update
1109// If an error would occur for this update, return false and fill in details in error_msg string
1110bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001111 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001112 // Verify idle ds
1113 if (in_use.load()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001114 // TODO : Re-using Allocate Idle error code, need write update idle error code
1115 *error_code = VALIDATION_ERROR_00919;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001116 std::stringstream error_str;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001117 error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
1118 << " that is in use by a command buffer.";
1119 *error_msg = error_str.str();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001120 return false;
1121 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001122 // Verify dst binding exists
1123 if (!p_layout_->HasBinding(update->dstBinding)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001124 *error_code = VALIDATION_ERROR_00936;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001125 std::stringstream error_str;
1126 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << ".";
1127 *error_msg = error_str.str();
1128 return false;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001129 }
1130 // We know that binding is valid, verify update and do update on each descriptor
1131 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
1132 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
1133 if (type != update->descriptorType) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001134 *error_code = VALIDATION_ERROR_00937;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001135 std::stringstream error_str;
1136 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
1137 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
1138 *error_msg = error_str.str();
1139 return false;
1140 }
1141 if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001142 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001143 std::stringstream error_str;
1144 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
1145 << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount
1146 << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
1147 << " combined with update array element offset of " << update->dstArrayElement
1148 << " oversteps the size of this descriptor set.";
1149 *error_msg = error_str.str();
1150 return false;
1151 }
1152 // Verify consecutive bindings match (if needed)
1153 if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001154 set_, error_msg)) {
1155 *error_code = VALIDATION_ERROR_00938;
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001156 return false;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001157 }
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001158 // Update is within bounds and consistent so last step is to validate update contents
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001159 if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) {
Tobin Ehlis57ae28f2016-05-24 12:35:57 -06001160 std::stringstream error_str;
1161 error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding
1162 << " failed with error message: " << error_msg->c_str();
1163 *error_msg = error_str.str();
1164 return false;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001165 }
1166 // All checks passed, update is clean
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001167 return true;
Tobin Ehlis03d61de2016-05-17 08:31:46 -06001168}
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001169// For the given buffer, verify that its creation parameters are appropriate for the given type
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001170// 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 -06001171bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_NODE const *buffer_node, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001172 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001173 // Verify that usage bits set correctly for given type
Tobin Ehlis94bc5d22016-06-02 07:46:52 -06001174 auto usage = buffer_node->createInfo.usage;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001175 std::string error_usage_bit;
1176 switch (type) {
1177 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1178 if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001179 *error_code = VALIDATION_ERROR_00950;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001180 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT";
1181 }
1182 break;
1183 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1184 if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001185 *error_code = VALIDATION_ERROR_00951;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001186 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT";
1187 }
1188 break;
1189 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1190 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1191 if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001192 *error_code = VALIDATION_ERROR_00946;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001193 error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT";
1194 }
1195 break;
1196 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1197 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1198 if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001199 *error_code = VALIDATION_ERROR_00947;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001200 error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT";
1201 }
1202 break;
1203 default:
1204 break;
1205 }
1206 if (!error_usage_bit.empty()) {
1207 std::stringstream error_str;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001208 error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage
1209 << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have "
1210 << error_usage_bit << " set.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001211 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001212 return false;
1213 }
1214 return true;
1215}
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001216// For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes:
1217// 1. buffer is valid
1218// 2. buffer was created with correct usage flags
1219// 3. offset is less than buffer size
1220// 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)]
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001221// 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 -06001222bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001223 UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const {
1224 // TODO : Defaulting to 00962 for all cases here. Need to create new error codes for a few cases below.
1225 *error_code = VALIDATION_ERROR_00962;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001226 // First make sure that buffer is valid
1227 auto buffer_node = getBufferNode(device_data_, buffer_info->buffer);
1228 if (!buffer_node) {
1229 std::stringstream error_str;
1230 error_str << "Invalid VkBuffer: " << buffer_info->buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001231 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001232 return false;
1233 }
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001234 if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()")) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001235 // TODO : This is a repeat code, need new code(s) for language in 11.6 Memory Association
1236 *error_msg = "No memory bound to buffer.";
Tobin Ehlis81280962016-07-20 14:04:20 -06001237 return false;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06001238 }
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001239 // Verify usage bits
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001240 if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) {
1241 // error_msg will have been updated by ValidateBufferUsage()
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001242 return false;
1243 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001244 // TODO : Need to also validate device limit offset requirements captured in VALIDATION_ERROR_00944,945
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001245 // offset must be less than buffer size
1246 if (buffer_info->offset > buffer_node->createInfo.size) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001247 *error_code = VALIDATION_ERROR_00959;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001248 std::stringstream error_str;
1249 error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer
1250 << " size of " << buffer_node->createInfo.size;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001251 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001252 return false;
1253 }
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001254 // TODO : Need to also validate device limit range requirements captured in VALIDATION_ERROR_00948,949
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001255 if (buffer_info->range != VK_WHOLE_SIZE) {
1256 // Range must be VK_WHOLE_SIZE or > 0
1257 if (!buffer_info->range) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001258 *error_code = VALIDATION_ERROR_00960;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001259 std::stringstream error_str;
1260 error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed.";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001261 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001262 return false;
1263 }
1264 // Range must be VK_WHOLE_SIZE or <= (buffer size - offset)
1265 if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001266 *error_code = VALIDATION_ERROR_00961;
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001267 std::stringstream error_str;
1268 error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size ("
1269 << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001270 *error_msg = error_str.str();
Tobin Ehlis3d38f082016-07-01 17:36:48 -06001271 return false;
1272 }
1273 }
1274 return true;
1275}
1276
Tobin Ehlis300888c2016-05-18 13:43:26 -06001277// Verify that the contents of the update are ok, but don't perform actual update
1278bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001279 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1280 std::string *error_msg) const {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001281 switch (update->descriptorType) {
1282 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
1283 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1284 // Validate image
1285 auto image_view = update->pImageInfo[di].imageView;
1286 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001287 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001288 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001289 error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1290 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001291 return false;
1292 }
1293 }
1294 // Intentional fall-through to validate sampler
1295 }
1296 case VK_DESCRIPTOR_TYPE_SAMPLER: {
1297 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1298 if (!descriptors_[index + di].get()->IsImmutableSampler()) {
Tobin Ehlise2f80292016-06-02 10:08:53 -06001299 if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001300 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001301 std::stringstream error_str;
1302 error_str << "Attempted write update to sampler descriptor with invalid sampler: "
1303 << update->pImageInfo[di].sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001304 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001305 return false;
1306 }
1307 } else {
1308 // TODO : Warn here
1309 }
1310 }
1311 break;
1312 }
1313 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1314 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1315 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: {
1316 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1317 auto image_view = update->pImageInfo[di].imageView;
1318 auto image_layout = update->pImageInfo[di].imageLayout;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001319 if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001320 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001321 error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str();
1322 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001323 return false;
1324 }
1325 }
1326 break;
1327 }
1328 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1329 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: {
1330 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1331 auto buffer_view = update->pTexelBufferView[di];
Tobin Ehlis8b872462016-09-14 08:12:08 -06001332 auto bv_state = getBufferViewState(device_data_, buffer_view);
1333 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001334 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001335 std::stringstream error_str;
1336 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001337 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001338 return false;
1339 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001340 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001341 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), update->descriptorType, error_code, error_msg)) {
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001342 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001343 error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str();
1344 *error_msg = error_str.str();
Tobin Ehlis6bd2b982016-05-24 12:33:42 -06001345 return false;
1346 }
Tobin Ehlis300888c2016-05-18 13:43:26 -06001347 }
1348 break;
1349 }
1350 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1351 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1352 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1353 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: {
1354 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001355 if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001356 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001357 error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str();
1358 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001359 return false;
1360 }
1361 }
1362 break;
1363 }
1364 default:
1365 assert(0); // We've already verified update type so should never get here
1366 break;
1367 }
1368 // All checks passed so update contents are good
1369 return true;
1370}
1371// Verify that the contents of the update are ok, but don't perform actual update
1372bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001373 VkDescriptorType type, uint32_t index,
1374 UNIQUE_VALIDATION_ERROR_CODE *error_code,
1375 std::string *error_msg) const {
1376 // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are
1377 // for write updates
Tobin Ehlis300888c2016-05-18 13:43:26 -06001378 switch (src_set->descriptors_[index]->descriptor_class) {
1379 case PlainSampler: {
1380 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1381 if (!src_set->descriptors_[index + di]->IsImmutableSampler()) {
1382 auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001383 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001384 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001385 std::stringstream error_str;
1386 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001387 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001388 return false;
1389 }
1390 } else {
1391 // TODO : Warn here
1392 }
1393 }
1394 break;
1395 }
1396 case ImageSampler: {
1397 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1398 auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get());
1399 // First validate sampler
1400 if (!img_samp_desc->IsImmutableSampler()) {
1401 auto update_sampler = img_samp_desc->GetSampler();
Tobin Ehlise2f80292016-06-02 10:08:53 -06001402 if (!ValidateSampler(update_sampler, device_data_)) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001403 *error_code = VALIDATION_ERROR_00942;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001404 std::stringstream error_str;
1405 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001406 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001407 return false;
1408 }
1409 } else {
1410 // TODO : Warn here
1411 }
1412 // Validate image
1413 auto image_view = img_samp_desc->GetImageView();
1414 auto image_layout = img_samp_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001415 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001416 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001417 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str();
1418 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001419 return false;
1420 }
1421 }
Alex Smithd8f14792016-09-23 12:18:51 +01001422 break;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001423 }
1424 case Image: {
1425 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1426 auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get());
1427 auto image_view = img_desc->GetImageView();
1428 auto image_layout = img_desc->GetImageLayout();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001429 if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001430 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001431 error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str();
1432 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001433 return false;
1434 }
1435 }
1436 break;
1437 }
1438 case TexelBuffer: {
1439 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1440 auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView();
Tobin Ehlis8b872462016-09-14 08:12:08 -06001441 auto bv_state = getBufferViewState(device_data_, buffer_view);
1442 if (!bv_state) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001443 *error_code = VALIDATION_ERROR_00940;
Tobin Ehlis300888c2016-05-18 13:43:26 -06001444 std::stringstream error_str;
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001445 error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001446 *error_msg = error_str.str();
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001447 return false;
1448 }
Tobin Ehlis8b872462016-09-14 08:12:08 -06001449 auto buffer = bv_state->create_info.buffer;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001450 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehliscbcf2342016-05-24 13:07:12 -06001451 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001452 error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str();
1453 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001454 return false;
1455 }
1456 }
1457 break;
1458 }
1459 case GeneralBuffer: {
1460 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
1461 auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer();
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001462 if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error_code, error_msg)) {
Tobin Ehlis300888c2016-05-18 13:43:26 -06001463 std::stringstream error_str;
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001464 error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str();
1465 *error_msg = error_str.str();
Tobin Ehlis300888c2016-05-18 13:43:26 -06001466 return false;
1467 }
1468 }
1469 break;
1470 }
1471 default:
1472 assert(0); // We've already verified update type so should never get here
1473 break;
1474 }
1475 // All checks passed so update contents are good
1476 return true;
Chris Forbesb4e0bdb2016-05-31 16:34:40 +12001477}
Tobin Ehlisee471462016-05-26 11:21:59 -06001478// Verify that the state at allocate time is correct, but don't actually allocate the sets yet
Tobin Ehlis815e8132016-06-02 13:02:17 -06001479bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data,
1480 const VkDescriptorSetAllocateInfo *p_alloc_info,
1481 const core_validation::layer_data *dev_data,
1482 AllocateDescriptorSetsData *ds_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001483 bool skip_call = false;
Tobin Ehlisee471462016-05-26 11:21:59 -06001484
1485 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001486 auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]);
1487 if (!layout) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001488 skip_call |=
1489 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
1490 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
1491 "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call",
1492 reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]));
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001493 } else {
Tobin Ehlis815e8132016-06-02 13:02:17 -06001494 ds_data->layout_nodes[i] = layout;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001495 // Count total descriptors required per type
Tobin Ehlis815e8132016-06-02 13:02:17 -06001496 for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
1497 const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001498 uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType);
1499 ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount;
1500 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001501 }
1502 }
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001503 auto pool_state = getDescriptorPoolState(dev_data, p_alloc_info->descriptorPool);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001504 // Track number of descriptorSets allowable in this pool
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001505 if (pool_state->availableSets < p_alloc_info->descriptorSetCount) {
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001506 skip_call |= log_msg(
1507 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001508 reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS",
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001509 "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.",
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001510 p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableSets);
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001511 }
1512 // Determine whether descriptor counts are satisfiable
1513 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001514 if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) {
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001515 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 -06001516 reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -06001517 "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64
1518 ". This pool only has %d descriptors of this type remaining.",
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001519 ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)),
Tobin Ehlis15e6f792016-10-12 15:01:39 -06001520 reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i]);
Tobin Ehlisee471462016-05-26 11:21:59 -06001521 }
1522 }
Tobin Ehlis5d749ea2016-07-18 13:14:01 -06001523
Tobin Ehlisee471462016-05-26 11:21:59 -06001524 return skip_call;
1525}
1526// Decrement allocated sets from the pool and insert new sets into set_map
Tobin Ehlis4e380592016-06-02 12:41:47 -06001527void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info,
1528 const VkDescriptorSet *descriptor_sets,
1529 const AllocateDescriptorSetsData *ds_data,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -06001530 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map,
Tobin Ehlis4e380592016-06-02 12:41:47 -06001531 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map,
1532 const core_validation::layer_data *dev_data) {
Tobin Ehlisee471462016-05-26 11:21:59 -06001533 auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001534 /* Account for sets and individual descriptors allocated from pool */
Tobin Ehlisee471462016-05-26 11:21:59 -06001535 pool_state->availableSets -= p_alloc_info->descriptorSetCount;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -06001536 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) {
1537 pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i];
1538 }
Tobin Ehlisee471462016-05-26 11:21:59 -06001539 /* Create tracking object for each descriptor set; insert into
1540 * global map and the pool's set.
1541 */
1542 for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
Tobin Ehlis93f22372016-10-12 14:34:12 -06001543 auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i],
1544 dev_data);
Tobin Ehlisee471462016-05-26 11:21:59 -06001545
1546 pool_state->sets.insert(new_ds);
1547 new_ds->in_use.store(0);
1548 (*set_map)[descriptor_sets[i]] = new_ds;
1549 }
1550}