Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1 | /* 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 |
| 27 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(debug_report_data *report_data, |
| 28 | const VkDescriptorSetLayoutCreateInfo *p_create_info, |
| 29 | const VkDescriptorSetLayout layout) |
| 30 | : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) { |
| 31 | uint32_t global_index = 0; |
| 32 | for (uint32_t i = 0; i < binding_count_; ++i) { |
| 33 | descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
| 34 | if (!binding_to_index_map_.emplace(p_create_info->pBindings[i].binding, i).second) { |
| 35 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
| 36 | reinterpret_cast<uint64_t &>(layout_), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 37 | "duplicated binding number in " |
| 38 | "VkDescriptorSetLayoutBinding"); |
| 39 | } |
| 40 | binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index; |
| 41 | global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0; |
| 42 | binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index; |
| 43 | global_index++; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 44 | bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i])); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 45 | // In cases where we should ignore pImmutableSamplers make sure it's NULL |
| 46 | if ((p_create_info->pBindings[i].pImmutableSamplers) && |
| 47 | ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) && |
| 48 | (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 49 | bindings_.back().pImmutableSamplers = nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 50 | } |
| 51 | if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 52 | p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { |
Tobin Ehlis | ef0de16 | 2016-06-20 13:07:34 -0600 | [diff] [blame] | 53 | dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 57 | // put all bindings into the given set |
| 58 | void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const { |
| 59 | for (auto binding_index_pair : binding_to_index_map_) |
| 60 | binding_set->insert(binding_index_pair.first); |
| 61 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 62 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 63 | VkDescriptorSetLayoutBinding const * |
| 64 | cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 65 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 66 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 67 | return bindings_[bi_itr->second].ptr(); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 68 | } |
| 69 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 70 | } |
| 71 | VkDescriptorSetLayoutBinding const * |
| 72 | cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const { |
| 73 | if (index >= bindings_.size()) |
| 74 | return nullptr; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 75 | return bindings_[index].ptr(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 76 | } |
| 77 | // Return descriptorCount for given binding, 0 if index is unavailable |
| 78 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 79 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 80 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 81 | return bindings_[bi_itr->second].descriptorCount; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 82 | } |
| 83 | return 0; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 84 | } |
| 85 | // Return descriptorCount for given index, 0 if index is unavailable |
| 86 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const { |
| 87 | if (index >= bindings_.size()) |
| 88 | return 0; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 89 | return bindings_[index].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 90 | } |
| 91 | // For the given binding, return descriptorType |
| 92 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const { |
| 93 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 94 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 95 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 96 | return bindings_[bi_itr->second].descriptorType; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 97 | } |
| 98 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 99 | } |
| 100 | // For the given index, return descriptorType |
| 101 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const { |
| 102 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 103 | return bindings_[index].descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 104 | } |
| 105 | // For the given global index, return descriptorType |
| 106 | // Currently just counting up through bindings_, may improve this in future |
| 107 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const { |
| 108 | uint32_t global_offset = 0; |
| 109 | for (auto binding : bindings_) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 110 | global_offset += binding.descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 111 | if (index < global_offset) |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 112 | return binding.descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 113 | } |
| 114 | assert(0); // requested global index is out of bounds |
| 115 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 116 | } |
| 117 | // For the given binding, return stageFlags |
| 118 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const { |
| 119 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 120 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 121 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 122 | return bindings_[bi_itr->second].stageFlags; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 123 | } |
| 124 | return VkShaderStageFlags(0); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 125 | } |
| 126 | // For the given binding, return start index |
| 127 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const { |
| 128 | assert(binding_to_global_start_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 129 | const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding); |
| 130 | if (btgsi_itr != binding_to_global_start_index_map_.end()) { |
| 131 | return btgsi_itr->second; |
| 132 | } |
| 133 | // In error case max uint32_t so index is out of bounds to break ASAP |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 134 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 135 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 136 | } |
| 137 | // For the given binding, return end index |
| 138 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const { |
| 139 | assert(binding_to_global_end_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 140 | const auto &btgei_itr = binding_to_global_end_index_map_.find(binding); |
| 141 | if (btgei_itr != binding_to_global_end_index_map_.end()) { |
| 142 | return btgei_itr->second; |
| 143 | } |
| 144 | // In error case max uint32_t so index is out of bounds to break ASAP |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 145 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 146 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 147 | } |
| 148 | // For given binding, return ptr to ImmutableSampler array |
| 149 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const { |
| 150 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 151 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 152 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 153 | return bindings_[bi_itr->second].pImmutableSamplers; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 154 | } |
| 155 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 156 | } |
| 157 | // For given index, return ptr to ImmutableSampler array |
| 158 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 159 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 160 | return bindings_[index].pImmutableSamplers; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 161 | } |
| 162 | // If our layout is compatible with rh_ds_layout, return true, |
| 163 | // else return false and fill in error_msg will description of what causes incompatibility |
| 164 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const { |
| 165 | // Trivial case |
| 166 | if (layout_ == rh_ds_layout->GetDescriptorSetLayout()) |
| 167 | return true; |
| 168 | if (descriptor_count_ != rh_ds_layout->descriptor_count_) { |
| 169 | std::stringstream error_str; |
| 170 | error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout " |
| 171 | << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors."; |
| 172 | *error_msg = error_str.str(); |
| 173 | return false; // trivial fail case |
| 174 | } |
| 175 | // Descriptor counts match so need to go through bindings one-by-one |
| 176 | // and verify that type and stageFlags match |
| 177 | for (auto binding : bindings_) { |
| 178 | // TODO : Do we also need to check immutable samplers? |
| 179 | // VkDescriptorSetLayoutBinding *rh_binding; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 180 | if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 181 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 182 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of " |
| 183 | << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 184 | << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 185 | << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 186 | *error_msg = error_str.str(); |
| 187 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 188 | } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 189 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 190 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '" |
| 191 | << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 192 | << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '" |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 193 | << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 194 | *error_msg = error_str.str(); |
| 195 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 196 | } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 197 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 198 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags " |
| 199 | << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 200 | << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 201 | << rh_ds_layout->GetStageFlagsFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 202 | *error_msg = error_str.str(); |
| 203 | return false; |
| 204 | } |
| 205 | } |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const { |
| 210 | if (!binding_to_index_map_.count(binding + 1)) |
| 211 | return false; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 212 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 213 | if (bi_itr != binding_to_index_map_.end()) { |
| 214 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 215 | if (next_bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 216 | auto type = bindings_[bi_itr->second].descriptorType; |
| 217 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 218 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
| 219 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 220 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
| 221 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 222 | return false; |
| 223 | } |
| 224 | return true; |
| 225 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 226 | } |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 227 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 228 | } |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 229 | // Starting at offset descriptor of given binding, parse over update_count |
| 230 | // descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent |
| 231 | // Consistency means that their type, stage flags, and whether or not they use immutable samplers matches |
| 232 | // If so, return true. If not, fill in error_msg and return false |
| 233 | bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count, |
| 234 | const char *type, const VkDescriptorSet set, |
| 235 | std::string *error_msg) const { |
| 236 | // Verify consecutive bindings match (if needed) |
| 237 | auto orig_binding = current_binding; |
| 238 | // Track count of descriptors in the current_bindings that are remaining to be updated |
| 239 | auto binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 240 | // First, it's legal to offset beyond your own binding so handle that case |
| 241 | // Really this is just searching for the binding in which the update begins and adjusting offset accordingly |
| 242 | while (offset >= binding_remaining) { |
| 243 | // Advance to next binding, decrement offset by binding size |
| 244 | offset -= binding_remaining; |
| 245 | binding_remaining = GetDescriptorCountFromBinding(++current_binding); |
| 246 | } |
| 247 | binding_remaining -= offset; |
| 248 | while (update_count > binding_remaining) { // While our updates overstep current binding |
| 249 | // Verify next consecutive binding matches type, stage flags & immutable sampler use |
| 250 | if (!IsNextBindingConsistent(current_binding++)) { |
| 251 | std::stringstream error_str; |
| 252 | error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #" |
| 253 | << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the " |
| 254 | "next binding is not consistent with current binding so this update is invalid."; |
| 255 | *error_msg = error_str.str(); |
| 256 | return false; |
| 257 | } |
| 258 | // For sake of this check consider the bindings updated and grab count for next binding |
| 259 | update_count -= binding_remaining; |
| 260 | binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 261 | } |
| 262 | return true; |
| 263 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 264 | |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 265 | cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count) |
| 266 | : required_descriptors_by_type{}, layout_nodes(count, nullptr) {} |
| 267 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 268 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const DescriptorSetLayout *layout, |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 269 | const core_validation::layer_data *dev_data) |
| 270 | : some_update_(false), set_(set), p_layout_(layout), device_data_(dev_data) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 271 | // 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 Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 279 | descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 280 | else |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 281 | descriptors_.emplace_back(new SamplerDescriptor()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 282 | } |
| 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 Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 289 | descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 290 | else |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 291 | descriptors_.emplace_back(new ImageSamplerDescriptor()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 292 | } |
| 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 Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 300 | descriptors_.emplace_back(new ImageDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 301 | 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 Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 305 | descriptors_.emplace_back(new TexelDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 306 | 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 Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 312 | descriptors_.emplace_back(new BufferDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 313 | break; |
| 314 | default: |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 315 | assert(0); // Bad descriptor type specified |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 316 | break; |
| 317 | } |
| 318 | } |
| 319 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 320 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 321 | cvdescriptorset::DescriptorSet::~DescriptorSet() { |
| 322 | InvalidateBoundCmdBuffers(); |
| 323 | // Remove link to any cmd buffers |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 324 | for (auto cb : cb_bindings) { |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 325 | for (uint32_t i=0; i<VK_PIPELINE_BIND_POINT_RANGE_SIZE; ++i) { |
| 326 | cb->lastBound[i].uniqueBoundSets.erase(this); |
| 327 | } |
| 328 | } |
| 329 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 330 | // Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec? |
| 331 | bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const { |
| 332 | return layout->IsCompatible(p_layout_, error); |
| 333 | } |
| 334 | // Validate that the state of this set is appropriate for the given bindings and dynami_offsets at Draw time |
| 335 | // This includes validating that all descriptors in the given bindings are updated, |
| 336 | // that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers. |
| 337 | // Return true if state is acceptable, or false and write an error message into error string |
| 338 | bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::unordered_set<uint32_t> &bindings, |
| 339 | const std::vector<uint32_t> &dynamic_offsets, std::string *error) const { |
iostrows | 5eb9765 | 2016-06-02 15:56:26 +0200 | [diff] [blame] | 340 | auto dyn_offset_index = 0; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 341 | for (auto binding : bindings) { |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 342 | if (!p_layout_->HasBinding(binding)) { |
| 343 | std::stringstream error_str; |
| 344 | error_str << "Attempting to validate DrawState for binding #" << binding |
| 345 | << " which is an invalid binding for this descriptor set."; |
| 346 | *error = error_str.str(); |
| 347 | return false; |
| 348 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 349 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 350 | if (descriptors_[start_idx]->IsImmutableSampler()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 351 | // Nothing to do for strictly immutable sampler |
| 352 | } else { |
| 353 | auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 354 | for (uint32_t i = start_idx; i <= end_idx; ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 355 | if (!descriptors_[i]->updated) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 356 | std::stringstream error_str; |
| 357 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 358 | << " is being used in draw but has not been updated."; |
| 359 | *error = error_str.str(); |
| 360 | return false; |
| 361 | } else { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 362 | if (GeneralBuffer == descriptors_[i]->GetClass()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 363 | // Verify that buffers are valid |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 364 | auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer(); |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 365 | auto buffer_node = getBufferNode(device_data_, buffer); |
| 366 | if (!buffer_node) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 367 | std::stringstream error_str; |
| 368 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 369 | << " references invalid buffer " << buffer << "."; |
| 370 | *error = error_str.str(); |
| 371 | return false; |
| 372 | } else { |
Tobin Ehlis | 997b258 | 2016-06-02 08:43:37 -0600 | [diff] [blame] | 373 | auto mem_entry = getMemObjInfo(device_data_, buffer_node->mem); |
| 374 | if (!mem_entry) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 375 | std::stringstream error_str; |
| 376 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 377 | << " uses buffer " << buffer << " that references invalid memory " << buffer_node->mem |
| 378 | << "."; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 379 | *error = error_str.str(); |
| 380 | return false; |
| 381 | } |
| 382 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 383 | if (descriptors_[i]->IsDynamic()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 384 | // Validate that dynamic offsets are within the buffer |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 385 | auto buffer_size = buffer_node->createInfo.size; |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 386 | auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange(); |
| 387 | auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 388 | auto dyn_offset = dynamic_offsets[dyn_offset_index++]; |
| 389 | if (VK_WHOLE_SIZE == range) { |
| 390 | if ((dyn_offset + desc_offset) > buffer_size) { |
| 391 | std::stringstream error_str; |
| 392 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 393 | << " uses buffer " << buffer |
| 394 | << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset |
| 395 | << " combined with offset " << desc_offset << " that oversteps the buffer size of " |
| 396 | << buffer_size << "."; |
| 397 | *error = error_str.str(); |
| 398 | return false; |
| 399 | } |
| 400 | } else { |
| 401 | if ((dyn_offset + desc_offset + range) > buffer_size) { |
| 402 | std::stringstream error_str; |
| 403 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 404 | << " uses buffer " << buffer << " with dynamic offset " << dyn_offset |
| 405 | << " combined with offset " << desc_offset << " and range " << range |
| 406 | << " that oversteps the buffer size of " << buffer_size << "."; |
| 407 | *error = error_str.str(); |
| 408 | return false; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | return true; |
| 418 | } |
| 419 | // For given bindings, place any update buffers or images into the passed-in unordered_sets |
| 420 | uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::unordered_set<uint32_t> &bindings, |
| 421 | std::unordered_set<VkBuffer> *buffer_set, |
| 422 | std::unordered_set<VkImageView> *image_set) const { |
| 423 | auto num_updates = 0; |
| 424 | for (auto binding : bindings) { |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 425 | // If a binding doesn't exist, skip it |
| 426 | if (!p_layout_->HasBinding(binding)) { |
| 427 | continue; |
| 428 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 429 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 430 | if (descriptors_[start_idx]->IsStorage()) { |
| 431 | if (Image == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 432 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 433 | if (descriptors_[start_idx + i]->updated) { |
| 434 | image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 435 | num_updates++; |
| 436 | } |
| 437 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 438 | } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 439 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 440 | if (descriptors_[start_idx + i]->updated) { |
| 441 | auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView(); |
Tobin Ehlis | 424859c | 2016-06-02 09:43:11 -0600 | [diff] [blame] | 442 | auto bv_info = getBufferViewInfo(device_data_, bufferview); |
| 443 | if (bv_info) { |
| 444 | buffer_set->insert(bv_info->buffer); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 445 | num_updates++; |
| 446 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 447 | } |
| 448 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 449 | } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 450 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 451 | if (descriptors_[start_idx + i]->updated) { |
| 452 | buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 453 | num_updates++; |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | return num_updates; |
| 460 | } |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 461 | // Set is being deleted or updates so invalidate all bound cmd buffers |
| 462 | void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() { |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 463 | core_validation::invalidateCommandBuffers(cb_bindings, |
| 464 | {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT}); |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 465 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 466 | // Perform write update in given update struct |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 467 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 468 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 469 | // perform update |
| 470 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 471 | descriptors_[start_idx + di]->WriteUpdate(update, di); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 472 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 473 | if (update->descriptorCount) |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 474 | some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 475 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 476 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 477 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 478 | // Validate Copy update |
| 479 | bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update, |
| 480 | const DescriptorSet *src_set, std::string *error) { |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 481 | // Verify idle ds |
| 482 | if (in_use.load()) { |
| 483 | std::stringstream error_str; |
| 484 | error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_ |
| 485 | << " that is in use by a command buffer."; |
| 486 | *error = error_str.str(); |
| 487 | return false; |
| 488 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 489 | if (!p_layout_->HasBinding(update->dstBinding)) { |
| 490 | std::stringstream error_str; |
| 491 | error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << "."; |
| 492 | *error = error_str.str(); |
| 493 | return false; |
| 494 | } |
| 495 | if (!src_set->HasBinding(update->srcBinding)) { |
| 496 | std::stringstream error_str; |
| 497 | error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << "."; |
| 498 | *error = error_str.str(); |
| 499 | return false; |
| 500 | } |
| 501 | // src & dst set bindings are valid |
| 502 | // Check bounds of src & dst |
| 503 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 504 | if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) { |
| 505 | // SRC update out of bounds |
| 506 | std::stringstream error_str; |
| 507 | error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding |
| 508 | << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding) |
| 509 | << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount |
| 510 | << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << "."; |
| 511 | *error = error_str.str(); |
| 512 | return false; |
| 513 | } |
| 514 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 515 | if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
| 516 | // DST update out of bounds |
| 517 | std::stringstream error_str; |
| 518 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding |
| 519 | << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) |
| 520 | << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount |
| 521 | << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << "."; |
| 522 | *error = error_str.str(); |
| 523 | return false; |
| 524 | } |
| 525 | // Check that types match |
| 526 | auto src_type = src_set->GetTypeFromBinding(update->srcBinding); |
| 527 | auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 528 | if (src_type != dst_type) { |
| 529 | std::stringstream error_str; |
| 530 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type " |
| 531 | << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #" |
| 532 | << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match."; |
| 533 | *error = error_str.str(); |
| 534 | return false; |
| 535 | } |
| 536 | // Verify consistency of src & dst bindings if update crosses binding boundaries |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 537 | if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount, |
| 538 | "copy update from", src_set->GetSet(), error)) || |
| 539 | (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to", |
| 540 | set_, error))) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 541 | return false; |
| 542 | } |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 543 | // First make sure source descriptors are updated |
| 544 | for (uint32_t i = 0; i < update->descriptorCount; ++i) { |
| 545 | if (!src_set->descriptors_[src_start_idx + i]) { |
| 546 | std::stringstream error_str; |
| 547 | error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset " |
| 548 | << update->srcArrayElement + i << " has not been updated."; |
| 549 | *error = error_str.str(); |
| 550 | return false; |
| 551 | } |
| 552 | } |
| 553 | // Update parameters all look good and descriptor updated so verify update contents |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 554 | if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error)) |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 555 | return false; |
| 556 | |
| 557 | // All checks passed so update is good |
| 558 | return true; |
| 559 | } |
| 560 | // Perform Copy update |
| 561 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 562 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 563 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 564 | // Update parameters all look good so perform update |
| 565 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 566 | descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 567 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 568 | if (update->descriptorCount) |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 569 | some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 570 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 571 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 572 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 573 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 574 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 575 | updated = false; |
| 576 | descriptor_class = PlainSampler; |
| 577 | }; |
| 578 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 579 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 580 | updated = false; |
| 581 | descriptor_class = PlainSampler; |
| 582 | if (immut) { |
| 583 | sampler_ = *immut; |
| 584 | immutable_ = true; |
| 585 | updated = true; |
| 586 | } |
| 587 | } |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 588 | // Validate given sampler. Currently this only checks to make sure it exists in the samplerMap |
| 589 | bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) { |
| 590 | return (getSamplerNode(dev_data, sampler) != nullptr); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 591 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 592 | |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 593 | bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, |
Tobin Ehlis | d5fb09e | 2016-06-02 10:54:09 -0600 | [diff] [blame] | 594 | const core_validation::layer_data *dev_data, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 595 | std::string *error) { |
Tobin Ehlis | d5fb09e | 2016-06-02 10:54:09 -0600 | [diff] [blame] | 596 | auto iv_data = getImageViewData(dev_data, image_view); |
| 597 | if (!iv_data) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 598 | std::stringstream error_str; |
| 599 | error_str << "Invalid VkImageView: " << image_view; |
| 600 | *error = error_str.str(); |
| 601 | return false; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 602 | } |
| 603 | // Validate that imageLayout is compatible with aspect_mask and image format |
| 604 | // and validate that image usage bits are correct for given usage |
Tobin Ehlis | d5fb09e | 2016-06-02 10:54:09 -0600 | [diff] [blame] | 605 | VkImageAspectFlags aspect_mask = iv_data->subresourceRange.aspectMask; |
| 606 | VkImage image = iv_data->image; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 607 | VkFormat format = VK_FORMAT_MAX_ENUM; |
| 608 | VkImageUsageFlags usage = 0; |
Tobin Ehlis | 1c9c55f | 2016-06-02 11:49:22 -0600 | [diff] [blame] | 609 | auto image_node = getImageNode(dev_data, image); |
| 610 | if (image_node) { |
| 611 | format = image_node->createInfo.format; |
| 612 | usage = image_node->createInfo.usage; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 613 | } else { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 614 | // Also need to check the swapchains. |
Tobin Ehlis | 969a526 | 2016-06-02 12:13:32 -0600 | [diff] [blame] | 615 | auto swapchain = getSwapchainFromImage(dev_data, image); |
| 616 | if (swapchain) { |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 617 | auto swapchain_node = getSwapchainNode(dev_data, swapchain); |
| 618 | if (swapchain_node) { |
| 619 | format = swapchain_node->createInfo.imageFormat; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 620 | } |
| 621 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 622 | } |
| 623 | // First validate that format and layout are compatible |
| 624 | if (format == VK_FORMAT_MAX_ENUM) { |
| 625 | std::stringstream error_str; |
| 626 | error_str << "Invalid image (" << image << ") in imageView (" << image_view << ")."; |
| 627 | *error = error_str.str(); |
| 628 | return false; |
| 629 | } |
| 630 | bool ds = vk_format_is_depth_or_stencil(format); |
| 631 | switch (image_layout) { |
| 632 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 633 | // Only Color bit must be set |
| 634 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 635 | std::stringstream error_str; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 636 | error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does " |
| 637 | "not have VK_IMAGE_ASPECT_COLOR_BIT set."; |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 638 | *error = error_str.str(); |
| 639 | return false; |
| 640 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 641 | // format must NOT be DS |
| 642 | if (ds) { |
| 643 | std::stringstream error_str; |
| 644 | error_str << "ImageView (" << image_view |
| 645 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is " |
| 646 | << string_VkFormat(format) << " which is not a color format."; |
| 647 | *error = error_str.str(); |
| 648 | return false; |
| 649 | } |
| 650 | break; |
| 651 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 652 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 653 | // Depth or stencil bit must be set, but both must NOT be set |
| 654 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 655 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 656 | // both must NOT be set |
| 657 | std::stringstream error_str; |
| 658 | error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set"; |
| 659 | *error = error_str.str(); |
| 660 | return false; |
| 661 | } |
| 662 | } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 663 | // Neither were set |
| 664 | std::stringstream error_str; |
| 665 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 666 | << " but does not have STENCIL or DEPTH aspects set"; |
| 667 | *error = error_str.str(); |
| 668 | return false; |
| 669 | } |
| 670 | // format must be DS |
| 671 | if (!ds) { |
| 672 | std::stringstream error_str; |
| 673 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 674 | << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format."; |
| 675 | *error = error_str.str(); |
| 676 | return false; |
| 677 | } |
| 678 | break; |
| 679 | default: |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 680 | // For other layouts if the source is ds image, both aspect bits must not be set |
| 681 | if (ds) { |
| 682 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 683 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 684 | // both must NOT be set |
| 685 | std::stringstream error_str; |
| 686 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 687 | << " and is using depth/stencil image of format " << string_VkFormat(format) |
| 688 | << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil " |
| 689 | "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 690 | "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil " |
| 691 | "reads respectively."; |
| 692 | *error = error_str.str(); |
| 693 | return false; |
| 694 | } |
| 695 | } |
| 696 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 697 | break; |
| 698 | } |
| 699 | // Now validate that usage flags are correctly set for given type of update |
| 700 | std::string error_usage_bit; |
| 701 | switch (type) { |
| 702 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 703 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 704 | if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { |
| 705 | error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT"; |
| 706 | } |
| 707 | break; |
| 708 | } |
| 709 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 710 | if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 711 | error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT"; |
| 712 | } |
| 713 | break; |
| 714 | } |
| 715 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 716 | if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
| 717 | error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT"; |
| 718 | } |
| 719 | break; |
| 720 | } |
| 721 | default: |
| 722 | break; |
| 723 | } |
| 724 | if (!error_usage_bit.empty()) { |
| 725 | std::stringstream error_str; |
| 726 | error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage |
| 727 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 728 | << error_usage_bit << " set."; |
| 729 | *error = error_str.str(); |
| 730 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 731 | } |
| 732 | return true; |
| 733 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 734 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 735 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
| 736 | sampler_ = update->pImageInfo[index].sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 737 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 738 | } |
| 739 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 740 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 741 | if (!immutable_) { |
| 742 | auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 743 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 744 | } |
| 745 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 746 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 747 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 748 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor() |
| 749 | : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 750 | updated = false; |
| 751 | descriptor_class = ImageSampler; |
| 752 | } |
| 753 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 754 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut) |
| 755 | : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 756 | updated = false; |
| 757 | descriptor_class = ImageSampler; |
| 758 | if (immut) { |
| 759 | sampler_ = *immut; |
| 760 | immutable_ = true; |
| 761 | updated = true; |
| 762 | } |
| 763 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 764 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 765 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 766 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 767 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 768 | sampler_ = image_info.sampler; |
| 769 | image_view_ = image_info.imageView; |
| 770 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 771 | } |
| 772 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 773 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 774 | if (!immutable_) { |
| 775 | auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 776 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 777 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 778 | auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_; |
| 779 | auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 780 | updated = true; |
| 781 | image_view_ = image_view; |
| 782 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 783 | } |
| 784 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 785 | cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type) |
| 786 | : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 787 | updated = false; |
| 788 | descriptor_class = Image; |
| 789 | if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) |
| 790 | storage_ = true; |
| 791 | }; |
| 792 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 793 | void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 794 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 795 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 796 | image_view_ = image_info.imageView; |
| 797 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 798 | } |
| 799 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 800 | void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 801 | auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_; |
| 802 | auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 803 | updated = true; |
| 804 | image_view_ = image_view; |
| 805 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 806 | } |
| 807 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 808 | cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type) |
| 809 | : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 810 | updated = false; |
| 811 | descriptor_class = GeneralBuffer; |
| 812 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 813 | dynamic_ = true; |
| 814 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) { |
| 815 | storage_ = true; |
| 816 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 817 | dynamic_ = true; |
| 818 | storage_ = true; |
| 819 | } |
| 820 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 821 | void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 822 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 823 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 824 | buffer_ = buffer_info.buffer; |
| 825 | offset_ = buffer_info.offset; |
| 826 | range_ = buffer_info.range; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 827 | } |
| 828 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 829 | void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) { |
| 830 | auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 831 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 832 | buffer_ = buff_desc->buffer_; |
| 833 | offset_ = buff_desc->offset_; |
| 834 | range_ = buff_desc->range_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 835 | } |
| 836 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 837 | cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 838 | updated = false; |
| 839 | descriptor_class = TexelBuffer; |
| 840 | if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) |
| 841 | storage_ = true; |
| 842 | }; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 843 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 844 | void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 845 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 846 | buffer_view_ = update->pTexelBufferView[index]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 847 | } |
| 848 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 849 | void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) { |
| 850 | updated = true; |
| 851 | buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_; |
| 852 | } |
| 853 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 854 | // sets, and then calls their respective Validate[Write|Copy]Update functions. |
| 855 | // If the update hits an issue for which the callback returns "true", meaning that the call down the chain should |
| 856 | // be skipped, then true is returned. |
| 857 | // If there is no issue with the update, then false is returned. |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 858 | bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data, |
| 859 | const core_validation::layer_data *dev_data, uint32_t write_count, |
| 860 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 861 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 862 | bool skip_call = false; |
| 863 | // Validate Write updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 864 | for (uint32_t i = 0; i < write_count; i++) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 865 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 866 | auto set_node = core_validation::getSetNode(dev_data, dest_set); |
| 867 | if (!set_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 868 | skip_call |= |
| 869 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 870 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 871 | "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.", |
| 872 | reinterpret_cast<uint64_t &>(dest_set)); |
| 873 | } else { |
| 874 | std::string error_str; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 875 | if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_str)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 876 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 877 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_WRITE_UPDATE, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 878 | "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64 |
| 879 | " with error: %s", |
| 880 | reinterpret_cast<uint64_t &>(dest_set), error_str.c_str()); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | // Now validate copy updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 885 | for (uint32_t i = 0; i < copy_count; ++i) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 886 | auto dst_set = p_cds[i].dstSet; |
| 887 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 888 | auto src_node = core_validation::getSetNode(dev_data, src_set); |
| 889 | auto dst_node = core_validation::getSetNode(dev_data, dst_set); |
| 890 | if (!src_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 891 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 892 | reinterpret_cast<uint64_t &>(src_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 893 | "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64 |
| 894 | " that has not been allocated.", |
| 895 | reinterpret_cast<uint64_t &>(src_set)); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 896 | } else if (!dst_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 897 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 898 | reinterpret_cast<uint64_t &>(dst_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 899 | "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64 |
| 900 | " that has not been allocated.", |
| 901 | reinterpret_cast<uint64_t &>(dst_set)); |
| 902 | } else { |
| 903 | std::string error_str; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 904 | if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_str)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 905 | skip_call |= |
| 906 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 585f66d | 2016-07-01 18:23:58 -0600 | [diff] [blame] | 907 | reinterpret_cast<uint64_t &>(dst_set), __LINE__, DRAWSTATE_INVALID_COPY_UPDATE, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 908 | "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64 |
| 909 | " to Descriptor Set 0x%" PRIx64 " with error: %s", |
| 910 | reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set), error_str.c_str()); |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | return skip_call; |
| 915 | } |
| 916 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 917 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 918 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 919 | // with the same set of updates. |
| 920 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 921 | // calling down the chain. |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 922 | void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count, |
| 923 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 924 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 925 | // Write updates first |
| 926 | uint32_t i = 0; |
| 927 | for (i = 0; i < write_count; ++i) { |
| 928 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 929 | auto set_node = core_validation::getSetNode(dev_data, dest_set); |
| 930 | if (set_node) { |
| 931 | set_node->PerformWriteUpdate(&p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | // Now copy updates |
| 935 | for (i = 0; i < copy_count; ++i) { |
| 936 | auto dst_set = p_cds[i].dstSet; |
| 937 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 938 | auto src_node = core_validation::getSetNode(dev_data, src_set); |
| 939 | auto dst_node = core_validation::getSetNode(dev_data, dst_set); |
| 940 | if (src_node && dst_node) { |
| 941 | dst_node->PerformCopyUpdate(&p_cds[i], src_node); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | } |
| 945 | // Validate the state for a given write update but don't actually perform the update |
| 946 | // If an error would occur for this update, return false and fill in details in error_msg string |
| 947 | bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update, |
| 948 | std::string *error_msg) { |
| 949 | // Verify idle ds |
| 950 | if (in_use.load()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 951 | std::stringstream error_str; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 952 | error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_ |
| 953 | << " that is in use by a command buffer."; |
| 954 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 955 | return false; |
| 956 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 957 | // Verify dst binding exists |
| 958 | if (!p_layout_->HasBinding(update->dstBinding)) { |
| 959 | std::stringstream error_str; |
| 960 | error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << "."; |
| 961 | *error_msg = error_str.str(); |
| 962 | return false; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 963 | } |
| 964 | // We know that binding is valid, verify update and do update on each descriptor |
| 965 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 966 | auto type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 967 | if (type != update->descriptorType) { |
| 968 | std::stringstream error_str; |
| 969 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type " |
| 970 | << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType); |
| 971 | *error_msg = error_str.str(); |
| 972 | return false; |
| 973 | } |
| 974 | if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
| 975 | std::stringstream error_str; |
| 976 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
| 977 | << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount |
| 978 | << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) |
| 979 | << " combined with update array element offset of " << update->dstArrayElement |
| 980 | << " oversteps the size of this descriptor set."; |
| 981 | *error_msg = error_str.str(); |
| 982 | return false; |
| 983 | } |
| 984 | // Verify consecutive bindings match (if needed) |
| 985 | if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to", |
| 986 | set_, error_msg)) |
| 987 | return false; |
| 988 | // Update is within bounds and consistent so last step is to validate update contents |
| 989 | if (!VerifyWriteUpdateContents(update, start_idx, error_msg)) { |
| 990 | std::stringstream error_str; |
| 991 | error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding |
| 992 | << " failed with error message: " << error_msg->c_str(); |
| 993 | *error_msg = error_str.str(); |
| 994 | return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 995 | } |
| 996 | // All checks passed, update is clean |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 997 | return true; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 998 | } |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 999 | // For the given buffer, verify that its creation parameters are appropriate for the given type |
| 1000 | // If there's an error, update the error string with details and return false, else return true |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1001 | bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_NODE const *buffer_node, VkDescriptorType type, |
| 1002 | std::string *error) const { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1003 | // Verify that usage bits set correctly for given type |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 1004 | auto usage = buffer_node->createInfo.usage; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1005 | std::string error_usage_bit; |
| 1006 | switch (type) { |
| 1007 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1008 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { |
| 1009 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; |
| 1010 | } |
| 1011 | break; |
| 1012 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1013 | if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { |
| 1014 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; |
| 1015 | } |
| 1016 | break; |
| 1017 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1018 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1019 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
| 1020 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; |
| 1021 | } |
| 1022 | break; |
| 1023 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1024 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1025 | if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { |
| 1026 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; |
| 1027 | } |
| 1028 | break; |
| 1029 | default: |
| 1030 | break; |
| 1031 | } |
| 1032 | if (!error_usage_bit.empty()) { |
| 1033 | std::stringstream error_str; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1034 | error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage |
| 1035 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 1036 | << error_usage_bit << " set."; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1037 | *error = error_str.str(); |
| 1038 | return false; |
| 1039 | } |
| 1040 | return true; |
| 1041 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1042 | // For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes: |
| 1043 | // 1. buffer is valid |
| 1044 | // 2. buffer was created with correct usage flags |
| 1045 | // 3. offset is less than buffer size |
| 1046 | // 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)] |
| 1047 | // If there's an error, update the error string with details and return false, else return true |
| 1048 | bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, |
| 1049 | std::string *error) const { |
| 1050 | // First make sure that buffer is valid |
| 1051 | auto buffer_node = getBufferNode(device_data_, buffer_info->buffer); |
| 1052 | if (!buffer_node) { |
| 1053 | std::stringstream error_str; |
| 1054 | error_str << "Invalid VkBuffer: " << buffer_info->buffer; |
| 1055 | *error = error_str.str(); |
| 1056 | return false; |
| 1057 | } |
| 1058 | // Verify usage bits |
| 1059 | if (!ValidateBufferUsage(buffer_node, type, error)) { |
| 1060 | // error will have been updated by ValidateBufferUsage() |
| 1061 | return false; |
| 1062 | } |
| 1063 | // offset must be less than buffer size |
| 1064 | if (buffer_info->offset > buffer_node->createInfo.size) { |
| 1065 | std::stringstream error_str; |
| 1066 | error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer |
| 1067 | << " size of " << buffer_node->createInfo.size; |
| 1068 | *error = error_str.str(); |
| 1069 | return false; |
| 1070 | } |
| 1071 | if (buffer_info->range != VK_WHOLE_SIZE) { |
| 1072 | // Range must be VK_WHOLE_SIZE or > 0 |
| 1073 | if (!buffer_info->range) { |
| 1074 | std::stringstream error_str; |
| 1075 | error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed."; |
| 1076 | *error = error_str.str(); |
| 1077 | return false; |
| 1078 | } |
| 1079 | // Range must be VK_WHOLE_SIZE or <= (buffer size - offset) |
| 1080 | if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) { |
| 1081 | std::stringstream error_str; |
| 1082 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size (" |
| 1083 | << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset; |
| 1084 | *error = error_str.str(); |
| 1085 | return false; |
| 1086 | } |
| 1087 | } |
| 1088 | return true; |
| 1089 | } |
| 1090 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1091 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1092 | bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index, |
| 1093 | std::string *error) const { |
| 1094 | switch (update->descriptorType) { |
| 1095 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 1096 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1097 | // Validate image |
| 1098 | auto image_view = update->pImageInfo[di].imageView; |
| 1099 | auto image_layout = update->pImageInfo[di].imageLayout; |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1100 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1101 | std::stringstream error_str; |
| 1102 | error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error->c_str(); |
| 1103 | *error = error_str.str(); |
| 1104 | return false; |
| 1105 | } |
| 1106 | } |
| 1107 | // Intentional fall-through to validate sampler |
| 1108 | } |
| 1109 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 1110 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1111 | if (!descriptors_[index + di].get()->IsImmutableSampler()) { |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1112 | if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1113 | std::stringstream error_str; |
| 1114 | error_str << "Attempted write update to sampler descriptor with invalid sampler: " |
| 1115 | << update->pImageInfo[di].sampler << "."; |
| 1116 | *error = error_str.str(); |
| 1117 | return false; |
| 1118 | } |
| 1119 | } else { |
| 1120 | // TODO : Warn here |
| 1121 | } |
| 1122 | } |
| 1123 | break; |
| 1124 | } |
| 1125 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1126 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1127 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 1128 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1129 | auto image_view = update->pImageInfo[di].imageView; |
| 1130 | auto image_layout = update->pImageInfo[di].imageLayout; |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1131 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1132 | std::stringstream error_str; |
| 1133 | error_str << "Attempted write update to image descriptor failed due to: " << error->c_str(); |
| 1134 | *error = error_str.str(); |
| 1135 | return false; |
| 1136 | } |
| 1137 | } |
| 1138 | break; |
| 1139 | } |
| 1140 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1141 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| 1142 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1143 | auto buffer_view = update->pTexelBufferView[di]; |
Tobin Ehlis | 424859c | 2016-06-02 09:43:11 -0600 | [diff] [blame] | 1144 | auto bv_info = getBufferViewInfo(device_data_, buffer_view); |
| 1145 | if (!bv_info) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1146 | std::stringstream error_str; |
| 1147 | error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 1148 | *error = error_str.str(); |
| 1149 | return false; |
| 1150 | } |
Tobin Ehlis | 424859c | 2016-06-02 09:43:11 -0600 | [diff] [blame] | 1151 | auto buffer = bv_info->buffer; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1152 | if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), update->descriptorType, error)) { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1153 | std::stringstream error_str; |
| 1154 | error_str << "Attempted write update to texel buffer descriptor failed due to: " << error->c_str(); |
| 1155 | *error = error_str.str(); |
| 1156 | return false; |
| 1157 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1158 | } |
| 1159 | break; |
| 1160 | } |
| 1161 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1162 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1163 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1164 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 1165 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1166 | if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1167 | std::stringstream error_str; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1168 | error_str << "Attempted write update to buffer descriptor failed due to: " << error->c_str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1169 | *error = error_str.str(); |
| 1170 | return false; |
| 1171 | } |
| 1172 | } |
| 1173 | break; |
| 1174 | } |
| 1175 | default: |
| 1176 | assert(0); // We've already verified update type so should never get here |
| 1177 | break; |
| 1178 | } |
| 1179 | // All checks passed so update contents are good |
| 1180 | return true; |
| 1181 | } |
| 1182 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1183 | bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1184 | VkDescriptorType type, uint32_t index, std::string *error) const { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1185 | switch (src_set->descriptors_[index]->descriptor_class) { |
| 1186 | case PlainSampler: { |
| 1187 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1188 | if (!src_set->descriptors_[index + di]->IsImmutableSampler()) { |
| 1189 | auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler(); |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1190 | if (!ValidateSampler(update_sampler, device_data_)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1191 | std::stringstream error_str; |
| 1192 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 1193 | *error = error_str.str(); |
| 1194 | return false; |
| 1195 | } |
| 1196 | } else { |
| 1197 | // TODO : Warn here |
| 1198 | } |
| 1199 | } |
| 1200 | break; |
| 1201 | } |
| 1202 | case ImageSampler: { |
| 1203 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1204 | auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1205 | // First validate sampler |
| 1206 | if (!img_samp_desc->IsImmutableSampler()) { |
| 1207 | auto update_sampler = img_samp_desc->GetSampler(); |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1208 | if (!ValidateSampler(update_sampler, device_data_)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1209 | std::stringstream error_str; |
| 1210 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 1211 | *error = error_str.str(); |
| 1212 | return false; |
| 1213 | } |
| 1214 | } else { |
| 1215 | // TODO : Warn here |
| 1216 | } |
| 1217 | // Validate image |
| 1218 | auto image_view = img_samp_desc->GetImageView(); |
| 1219 | auto image_layout = img_samp_desc->GetImageLayout(); |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1220 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1221 | std::stringstream error_str; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1222 | error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error->c_str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1223 | *error = error_str.str(); |
| 1224 | return false; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | case Image: { |
| 1229 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1230 | auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1231 | auto image_view = img_desc->GetImageView(); |
| 1232 | auto image_layout = img_desc->GetImageLayout(); |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1233 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1234 | std::stringstream error_str; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1235 | error_str << "Attempted copy update to image descriptor failed due to: " << error->c_str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1236 | *error = error_str.str(); |
| 1237 | return false; |
| 1238 | } |
| 1239 | } |
| 1240 | break; |
| 1241 | } |
| 1242 | case TexelBuffer: { |
| 1243 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1244 | auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView(); |
Tobin Ehlis | 424859c | 2016-06-02 09:43:11 -0600 | [diff] [blame] | 1245 | auto bv_info = getBufferViewInfo(device_data_, buffer_view); |
| 1246 | if (!bv_info) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1247 | std::stringstream error_str; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1248 | error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 1249 | *error = error_str.str(); |
| 1250 | return false; |
| 1251 | } |
Tobin Ehlis | 424859c | 2016-06-02 09:43:11 -0600 | [diff] [blame] | 1252 | auto buffer = bv_info->buffer; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1253 | if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error)) { |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1254 | std::stringstream error_str; |
| 1255 | error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error->c_str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1256 | *error = error_str.str(); |
| 1257 | return false; |
| 1258 | } |
| 1259 | } |
| 1260 | break; |
| 1261 | } |
| 1262 | case GeneralBuffer: { |
| 1263 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1264 | auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1265 | if (!ValidateBufferUsage(getBufferNode(device_data_, buffer), type, error)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1266 | std::stringstream error_str; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1267 | error_str << "Attempted copy update to buffer descriptor failed due to: " << error->c_str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1268 | *error = error_str.str(); |
| 1269 | return false; |
| 1270 | } |
| 1271 | } |
| 1272 | break; |
| 1273 | } |
| 1274 | default: |
| 1275 | assert(0); // We've already verified update type so should never get here |
| 1276 | break; |
| 1277 | } |
| 1278 | // All checks passed so update contents are good |
| 1279 | return true; |
Chris Forbes | b4e0bdb | 2016-05-31 16:34:40 +1200 | [diff] [blame] | 1280 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1281 | // Verify that the state at allocate time is correct, but don't actually allocate the sets yet |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1282 | bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data, |
| 1283 | const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1284 | const core_validation::layer_data *dev_data, |
| 1285 | AllocateDescriptorSetsData *ds_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1286 | bool skip_call = false; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1287 | |
| 1288 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1289 | auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
| 1290 | if (!layout) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1291 | skip_call |= |
| 1292 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
| 1293 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 1294 | "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", |
| 1295 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i])); |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1296 | } else { |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1297 | ds_data->layout_nodes[i] = layout; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1298 | // Count total descriptors required per type |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1299 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 1300 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1301 | uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType); |
| 1302 | ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount; |
| 1303 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1304 | } |
| 1305 | } |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1306 | auto pool_node = getPoolNode(dev_data, p_alloc_info->descriptorPool); |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1307 | // Track number of descriptorSets allowable in this pool |
| 1308 | if (pool_node->availableSets < p_alloc_info->descriptorSetCount) { |
| 1309 | skip_call |= log_msg( |
| 1310 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
| 1311 | reinterpret_cast<uint64_t &>(pool_node->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS", |
| 1312 | "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.", |
| 1313 | p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_node->pool), pool_node->availableSets); |
| 1314 | } |
| 1315 | // Determine whether descriptor counts are satisfiable |
| 1316 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
| 1317 | if (ds_data->required_descriptors_by_type[i] > pool_node->availableDescriptorTypeCount[i]) { |
| 1318 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
| 1319 | reinterpret_cast<const uint64_t &>(pool_node->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, |
| 1320 | "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64 |
| 1321 | ". This pool only has %d descriptors of this type remaining.", |
| 1322 | ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)), |
| 1323 | reinterpret_cast<uint64_t &>(pool_node->pool), pool_node->availableDescriptorTypeCount[i]); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1324 | } |
| 1325 | } |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1326 | |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1327 | return skip_call; |
| 1328 | } |
| 1329 | // Decrement allocated sets from the pool and insert new sets into set_map |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1330 | void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1331 | const VkDescriptorSet *descriptor_sets, |
| 1332 | const AllocateDescriptorSetsData *ds_data, |
| 1333 | std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE *> *pool_map, |
| 1334 | std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map, |
| 1335 | const core_validation::layer_data *dev_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1336 | auto pool_state = (*pool_map)[p_alloc_info->descriptorPool]; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1337 | /* Account for sets and individual descriptors allocated from pool */ |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1338 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1339 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
| 1340 | pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i]; |
| 1341 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1342 | /* Create tracking object for each descriptor set; insert into |
| 1343 | * global map and the pool's set. |
| 1344 | */ |
| 1345 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1346 | auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], ds_data->layout_nodes[i], dev_data); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1347 | |
| 1348 | pool_state->sets.insert(new_ds); |
| 1349 | new_ds->in_use.store(0); |
| 1350 | (*set_map)[descriptor_sets[i]] = new_ds; |
| 1351 | } |
| 1352 | } |