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 | |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 21 | // Allow use of STL min and max functions in Windows |
| 22 | #define NOMINMAX |
| 23 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 24 | #include "descriptor_sets.h" |
| 25 | #include "vk_enum_string_helper.h" |
| 26 | #include "vk_safe_struct.h" |
| 27 | #include <sstream> |
Mark Lobodzinski | 2eee5d8 | 2016-12-02 15:33:18 -0700 | [diff] [blame] | 28 | #include <algorithm> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 29 | |
| 30 | // Construct DescriptorSetLayout instance from given create info |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 31 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 32 | const VkDescriptorSetLayout layout) |
| 33 | : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) { |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 34 | // Dyn array indicies are ordered by binding # and array index of any array within the binding |
| 35 | // so we store up bindings w/ count in ordered map in order to create dyn array mappings below |
| 36 | std::map<uint32_t, uint32_t> binding_to_dyn_count; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 37 | for (uint32_t i = 0; i < binding_count_; ++i) { |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 38 | auto binding_num = p_create_info->pBindings[i].binding; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 39 | descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 40 | uint32_t insert_index = 0; // Track vector index where we insert element |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 41 | if (bindings_.empty() || binding_num > bindings_.back().binding) { |
| 42 | bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i])); |
Jamie Madill | 3f5fd49 | 2016-12-19 15:59:18 -0500 | [diff] [blame] | 43 | insert_index = static_cast<uint32_t>(bindings_.size()) - 1; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 44 | } else { // out-of-order binding number, need to insert into vector in-order |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 45 | auto it = bindings_.begin(); |
| 46 | // Find currently binding's spot in vector |
| 47 | while (binding_num > it->binding) { |
| 48 | assert(it != bindings_.end()); |
| 49 | ++insert_index; |
| 50 | ++it; |
| 51 | } |
| 52 | bindings_.insert(it, safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i])); |
| 53 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 54 | // In cases where we should ignore pImmutableSamplers make sure it's NULL |
| 55 | if ((p_create_info->pBindings[i].pImmutableSamplers) && |
| 56 | ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) && |
| 57 | (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) { |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 58 | bindings_[insert_index].pImmutableSamplers = nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 59 | } |
| 60 | if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 61 | p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 62 | binding_to_dyn_count[p_create_info->pBindings[i].binding] = p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | ef0de16 | 2016-06-20 13:07:34 -0600 | [diff] [blame] | 63 | dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 64 | } |
| 65 | } |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 66 | assert(bindings_.size() == binding_count_); |
| 67 | uint32_t global_index = 0; |
| 68 | // Vector order is finalized so create maps of bindings to indices |
| 69 | for (uint32_t i = 0; i < binding_count_; ++i) { |
| 70 | auto binding_num = bindings_[i].binding; |
| 71 | binding_to_index_map_[binding_num] = i; |
| 72 | binding_to_global_start_index_map_[binding_num] = global_index; |
| 73 | global_index += bindings_[i].descriptorCount ? bindings_[i].descriptorCount - 1 : 0; |
| 74 | binding_to_global_end_index_map_[binding_num] = global_index; |
| 75 | global_index += bindings_[i].descriptorCount ? 1 : 0; |
| 76 | } |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 77 | // Now create dyn offset array mapping for any dynamic descriptors |
| 78 | uint32_t dyn_array_idx = 0; |
| 79 | for (const auto &bc_pair : binding_to_dyn_count) { |
| 80 | binding_to_dynamic_array_idx_map_[bc_pair.first] = dyn_array_idx; |
| 81 | dyn_array_idx += bc_pair.second; |
| 82 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 83 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 84 | |
| 85 | // Validate descriptor set layout create info |
| 86 | bool cvdescriptorset::DescriptorSetLayout::ValidateCreateInfo(debug_report_data *report_data, |
| 87 | const VkDescriptorSetLayoutCreateInfo *create_info) { |
| 88 | bool skip = false; |
| 89 | std::unordered_set<uint32_t> bindings; |
| 90 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
Tobin Ehlis | fdcb63f | 2016-10-25 20:56:47 -0600 | [diff] [blame] | 91 | if (!bindings.insert(create_info->pBindings[i].binding).second) { |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 92 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 93 | VALIDATION_ERROR_02345, "DS", "duplicated binding number in VkDescriptorSetLayoutBinding. %s", |
| 94 | validation_error_map[VALIDATION_ERROR_02345]); |
| 95 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 96 | } |
| 97 | return skip; |
| 98 | } |
| 99 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 100 | // put all bindings into the given set |
| 101 | void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 102 | for (auto binding_index_pair : binding_to_index_map_) binding_set->insert(binding_index_pair.first); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 103 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 104 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 105 | VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding( |
| 106 | const uint32_t binding) const { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 107 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 108 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 109 | return bindings_[bi_itr->second].ptr(); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 110 | } |
| 111 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 112 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 113 | VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex( |
| 114 | const uint32_t index) const { |
| 115 | if (index >= bindings_.size()) return nullptr; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 116 | return bindings_[index].ptr(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 117 | } |
| 118 | // Return descriptorCount for given binding, 0 if index is unavailable |
| 119 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const { |
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].descriptorCount; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 123 | } |
| 124 | return 0; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 125 | } |
| 126 | // Return descriptorCount for given index, 0 if index is unavailable |
| 127 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 128 | if (index >= bindings_.size()) return 0; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 129 | return bindings_[index].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 130 | } |
| 131 | // For the given binding, return descriptorType |
| 132 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const { |
| 133 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 134 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 135 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 136 | return bindings_[bi_itr->second].descriptorType; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 137 | } |
| 138 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 139 | } |
| 140 | // For the given index, return descriptorType |
| 141 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const { |
| 142 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 143 | return bindings_[index].descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 144 | } |
| 145 | // For the given global index, return descriptorType |
| 146 | // Currently just counting up through bindings_, may improve this in future |
| 147 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const { |
| 148 | uint32_t global_offset = 0; |
| 149 | for (auto binding : bindings_) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 150 | global_offset += binding.descriptorCount; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 151 | if (index < global_offset) return binding.descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 152 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 153 | assert(0); // requested global index is out of bounds |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 154 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 155 | } |
| 156 | // For the given binding, return stageFlags |
| 157 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const { |
| 158 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 159 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 160 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 161 | return bindings_[bi_itr->second].stageFlags; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 162 | } |
| 163 | return VkShaderStageFlags(0); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 164 | } |
| 165 | // For the given binding, return start index |
| 166 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const { |
| 167 | assert(binding_to_global_start_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 168 | const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding); |
| 169 | if (btgsi_itr != binding_to_global_start_index_map_.end()) { |
| 170 | return btgsi_itr->second; |
| 171 | } |
| 172 | // 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] | 173 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 174 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 175 | } |
| 176 | // For the given binding, return end index |
| 177 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const { |
| 178 | assert(binding_to_global_end_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 179 | const auto &btgei_itr = binding_to_global_end_index_map_.find(binding); |
| 180 | if (btgei_itr != binding_to_global_end_index_map_.end()) { |
| 181 | return btgei_itr->second; |
| 182 | } |
| 183 | // 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] | 184 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 185 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 186 | } |
| 187 | // For given binding, return ptr to ImmutableSampler array |
| 188 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const { |
| 189 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 190 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 191 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 192 | return bindings_[bi_itr->second].pImmutableSamplers; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 193 | } |
| 194 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 195 | } |
Mark Lobodzinski | 4aa479d | 2017-03-10 09:14:00 -0700 | [diff] [blame] | 196 | // Move to next valid binding having a non-zero binding count |
| 197 | uint32_t cvdescriptorset::DescriptorSetLayout::GetNextValidBinding(const uint32_t binding) const { |
| 198 | uint32_t new_binding = binding; |
| 199 | do { |
| 200 | new_binding++; |
| 201 | } while (GetDescriptorCountFromBinding(new_binding) == 0); |
| 202 | return new_binding; |
| 203 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 204 | // For given index, return ptr to ImmutableSampler array |
| 205 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 206 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 207 | return bindings_[index].pImmutableSamplers; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 208 | } |
| 209 | // If our layout is compatible with rh_ds_layout, return true, |
| 210 | // else return false and fill in error_msg will description of what causes incompatibility |
| 211 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const { |
| 212 | // Trivial case |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 213 | if (layout_ == rh_ds_layout->GetDescriptorSetLayout()) return true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 214 | if (descriptor_count_ != rh_ds_layout->descriptor_count_) { |
| 215 | std::stringstream error_str; |
| 216 | error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout " |
| 217 | << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors."; |
| 218 | *error_msg = error_str.str(); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 219 | return false; // trivial fail case |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 220 | } |
| 221 | // Descriptor counts match so need to go through bindings one-by-one |
| 222 | // and verify that type and stageFlags match |
| 223 | for (auto binding : bindings_) { |
| 224 | // TODO : Do we also need to check immutable samplers? |
| 225 | // VkDescriptorSetLayoutBinding *rh_binding; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 226 | if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 227 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 228 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of " |
| 229 | << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 230 | << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 231 | << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 232 | *error_msg = error_str.str(); |
| 233 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 234 | } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 235 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 236 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '" |
| 237 | << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 238 | << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '" |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 239 | << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 240 | *error_msg = error_str.str(); |
| 241 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 242 | } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 243 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 244 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags " |
| 245 | << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 246 | << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 247 | << rh_ds_layout->GetStageFlagsFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 248 | *error_msg = error_str.str(); |
| 249 | return false; |
| 250 | } |
| 251 | } |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 256 | if (!binding_to_index_map_.count(binding + 1)) return false; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 257 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 258 | if (bi_itr != binding_to_index_map_.end()) { |
| 259 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 260 | if (next_bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 261 | auto type = bindings_[bi_itr->second].descriptorType; |
| 262 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 263 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
| 264 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 265 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
| 266 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 267 | return false; |
| 268 | } |
| 269 | return true; |
| 270 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 271 | } |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 272 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 273 | } |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 274 | // Starting at offset descriptor of given binding, parse over update_count |
| 275 | // descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent |
| 276 | // Consistency means that their type, stage flags, and whether or not they use immutable samplers matches |
| 277 | // If so, return true. If not, fill in error_msg and return false |
| 278 | bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count, |
| 279 | const char *type, const VkDescriptorSet set, |
| 280 | std::string *error_msg) const { |
| 281 | // Verify consecutive bindings match (if needed) |
| 282 | auto orig_binding = current_binding; |
| 283 | // Track count of descriptors in the current_bindings that are remaining to be updated |
| 284 | auto binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 285 | // First, it's legal to offset beyond your own binding so handle that case |
| 286 | // Really this is just searching for the binding in which the update begins and adjusting offset accordingly |
| 287 | while (offset >= binding_remaining) { |
| 288 | // Advance to next binding, decrement offset by binding size |
| 289 | offset -= binding_remaining; |
| 290 | binding_remaining = GetDescriptorCountFromBinding(++current_binding); |
| 291 | } |
| 292 | binding_remaining -= offset; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 293 | while (update_count > binding_remaining) { // While our updates overstep current binding |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 294 | // Verify next consecutive binding matches type, stage flags & immutable sampler use |
| 295 | if (!IsNextBindingConsistent(current_binding++)) { |
| 296 | std::stringstream error_str; |
| 297 | error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #" |
| 298 | << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the " |
| 299 | "next binding is not consistent with current binding so this update is invalid."; |
| 300 | *error_msg = error_str.str(); |
| 301 | return false; |
| 302 | } |
| 303 | // For sake of this check consider the bindings updated and grab count for next binding |
| 304 | update_count -= binding_remaining; |
| 305 | binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 306 | } |
| 307 | return true; |
| 308 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 309 | |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 310 | cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count) |
| 311 | : required_descriptors_by_type{}, layout_nodes(count, nullptr) {} |
| 312 | |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 313 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool, |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 314 | const DescriptorSetLayout *layout, const layer_data *dev_data) |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 315 | : some_update_(false), |
| 316 | set_(set), |
| 317 | pool_state_(nullptr), |
| 318 | p_layout_(layout), |
| 319 | device_data_(dev_data), |
Mark Lobodzinski | efd933b | 2017-02-10 12:09:23 -0700 | [diff] [blame] | 320 | limits_(GetPhysDevProperties(dev_data)->properties.limits) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 321 | pool_state_ = GetDescriptorPoolState(dev_data, pool); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 322 | // Foreach binding, create default descriptors of given type |
| 323 | for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) { |
| 324 | auto type = p_layout_->GetTypeFromIndex(i); |
| 325 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 326 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 327 | auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 328 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 329 | if (immut_sampler) |
| 330 | descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di)); |
| 331 | else |
| 332 | descriptors_.emplace_back(new SamplerDescriptor()); |
| 333 | } |
| 334 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 335 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 336 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 337 | auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 338 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 339 | if (immut) |
| 340 | descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di)); |
| 341 | else |
| 342 | descriptors_.emplace_back(new ImageSamplerDescriptor()); |
| 343 | } |
| 344 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 345 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 346 | // ImageDescriptors |
| 347 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 348 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 349 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 350 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
| 351 | descriptors_.emplace_back(new ImageDescriptor(type)); |
| 352 | break; |
| 353 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 354 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 355 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
| 356 | descriptors_.emplace_back(new TexelDescriptor(type)); |
| 357 | break; |
| 358 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 359 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 360 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 361 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 362 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
| 363 | descriptors_.emplace_back(new BufferDescriptor(type)); |
| 364 | break; |
| 365 | default: |
| 366 | assert(0); // Bad descriptor type specified |
| 367 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 371 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 372 | cvdescriptorset::DescriptorSet::~DescriptorSet() { InvalidateBoundCmdBuffers(); } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 373 | |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 374 | static std::string string_descriptor_req_view_type(descriptor_req req) { |
| 375 | std::string result(""); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 376 | for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) { |
| 377 | if (req & (1 << i)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 378 | if (result.size()) result += ", "; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 379 | result += string_VkImageViewType(VkImageViewType(i)); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 383 | if (!result.size()) result = "(none)"; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 384 | |
| 385 | return result; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 386 | } |
| 387 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 388 | // Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec? |
| 389 | bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const { |
| 390 | return layout->IsCompatible(p_layout_, error); |
| 391 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 392 | |
Tobin Ehlis | 3066db6 | 2016-08-22 08:12:23 -0600 | [diff] [blame] | 393 | // Validate that the state of this set is appropriate for the given bindings and dynamic_offsets at Draw time |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 394 | // This includes validating that all descriptors in the given bindings are updated, |
| 395 | // that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers. |
| 396 | // Return true if state is acceptable, or false and write an error message into error string |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 397 | bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 398 | const std::vector<uint32_t> &dynamic_offsets, std::string *error) const { |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 399 | for (auto binding_pair : bindings) { |
| 400 | auto binding = binding_pair.first; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 401 | if (!p_layout_->HasBinding(binding)) { |
| 402 | std::stringstream error_str; |
| 403 | error_str << "Attempting to validate DrawState for binding #" << binding |
| 404 | << " which is an invalid binding for this descriptor set."; |
| 405 | *error = error_str.str(); |
| 406 | return false; |
| 407 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 408 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 409 | if (descriptors_[start_idx]->IsImmutableSampler()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 410 | // Nothing to do for strictly immutable sampler |
| 411 | } else { |
| 412 | auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 413 | auto array_idx = 0; // Track array idx if we're dealing with array descriptors |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 414 | for (uint32_t i = start_idx; i <= end_idx; ++i, ++array_idx) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 415 | if (!descriptors_[i]->updated) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 416 | std::stringstream error_str; |
| 417 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 418 | << " is being used in draw but has not been updated."; |
| 419 | *error = error_str.str(); |
| 420 | return false; |
| 421 | } else { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 422 | auto descriptor_class = descriptors_[i]->GetClass(); |
| 423 | if (descriptor_class == GeneralBuffer) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 424 | // Verify that buffers are valid |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 425 | auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 426 | auto buffer_node = GetBufferState(device_data_, buffer); |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 427 | if (!buffer_node) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 428 | std::stringstream error_str; |
| 429 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 430 | << " references invalid buffer " << buffer << "."; |
| 431 | *error = error_str.str(); |
| 432 | return false; |
| 433 | } else { |
Tobin Ehlis | 640a81c | 2016-11-15 15:37:18 -0700 | [diff] [blame] | 434 | for (auto mem_binding : buffer_node->GetBoundMemory()) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 435 | if (!GetMemObjInfo(device_data_, mem_binding)) { |
Tobin Ehlis | 640a81c | 2016-11-15 15:37:18 -0700 | [diff] [blame] | 436 | std::stringstream error_str; |
| 437 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 438 | << " uses buffer " << buffer << " that references invalid memory " << mem_binding |
| 439 | << "."; |
| 440 | *error = error_str.str(); |
| 441 | return false; |
| 442 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 443 | } |
| 444 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 445 | if (descriptors_[i]->IsDynamic()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 446 | // Validate that dynamic offsets are within the buffer |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 447 | auto buffer_size = buffer_node->createInfo.size; |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 448 | auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange(); |
| 449 | auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset(); |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 450 | auto dyn_offset = dynamic_offsets[GetDynamicOffsetIndexFromBinding(binding) + array_idx]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 451 | if (VK_WHOLE_SIZE == range) { |
| 452 | if ((dyn_offset + desc_offset) > buffer_size) { |
| 453 | std::stringstream error_str; |
| 454 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 455 | << " uses buffer " << buffer |
| 456 | << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset |
| 457 | << " combined with offset " << desc_offset << " that oversteps the buffer size of " |
| 458 | << buffer_size << "."; |
| 459 | *error = error_str.str(); |
| 460 | return false; |
| 461 | } |
| 462 | } else { |
| 463 | if ((dyn_offset + desc_offset + range) > buffer_size) { |
| 464 | std::stringstream error_str; |
| 465 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 466 | << " uses buffer " << buffer << " with dynamic offset " << dyn_offset |
| 467 | << " combined with offset " << desc_offset << " and range " << range |
| 468 | << " that oversteps the buffer size of " << buffer_size << "."; |
| 469 | *error = error_str.str(); |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | } |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 474 | } else if (descriptor_class == ImageSampler || descriptor_class == Image) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 475 | auto image_view = (descriptor_class == ImageSampler) |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 476 | ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView() |
| 477 | : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView(); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 478 | auto reqs = binding_pair.second; |
| 479 | |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 480 | auto image_view_state = GetImageViewState(device_data_, image_view); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 481 | assert(image_view_state); |
| 482 | auto image_view_ci = image_view_state->create_info; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 483 | |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 484 | if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 485 | // bad view type |
| 486 | std::stringstream error_str; |
| 487 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 488 | << " requires an image view of type " << string_descriptor_req_view_type(reqs) << " but got " |
| 489 | << string_VkImageViewType(image_view_ci.viewType) << "."; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 490 | *error = error_str.str(); |
| 491 | return false; |
| 492 | } |
| 493 | |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 494 | auto image_node = GetImageState(device_data_, image_view_ci.image); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 495 | assert(image_node); |
| 496 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 497 | if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 498 | std::stringstream error_str; |
| 499 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 500 | << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got " |
| 501 | << string_VkSampleCountFlagBits(image_node->createInfo.samples) << "."; |
| 502 | *error = error_str.str(); |
| 503 | return false; |
| 504 | } |
| 505 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 506 | if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 507 | std::stringstream error_str; |
| 508 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 509 | << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT."; |
| 510 | *error = error_str.str(); |
| 511 | return false; |
| 512 | } |
| 513 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | return true; |
| 519 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 520 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 521 | // For given bindings, place any update buffers or images into the passed-in unordered_sets |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 522 | uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 523 | std::unordered_set<VkBuffer> *buffer_set, |
| 524 | std::unordered_set<VkImageView> *image_set) const { |
| 525 | auto num_updates = 0; |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 526 | for (auto binding_pair : bindings) { |
| 527 | auto binding = binding_pair.first; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 528 | // If a binding doesn't exist, skip it |
| 529 | if (!p_layout_->HasBinding(binding)) { |
| 530 | continue; |
| 531 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 532 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 533 | if (descriptors_[start_idx]->IsStorage()) { |
| 534 | if (Image == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 535 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 536 | if (descriptors_[start_idx + i]->updated) { |
| 537 | image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 538 | num_updates++; |
| 539 | } |
| 540 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 541 | } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 542 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 543 | if (descriptors_[start_idx + i]->updated) { |
| 544 | auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 545 | auto bv_state = GetBufferViewState(device_data_, bufferview); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 546 | if (bv_state) { |
| 547 | buffer_set->insert(bv_state->create_info.buffer); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 548 | num_updates++; |
| 549 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 550 | } |
| 551 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 552 | } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 553 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 554 | if (descriptors_[start_idx + i]->updated) { |
| 555 | buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 556 | num_updates++; |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | return num_updates; |
| 563 | } |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 564 | // Set is being deleted or updates so invalidate all bound cmd buffers |
| 565 | void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() { |
Tobin Ehlis | fe5731a | 2016-11-21 08:31:01 -0700 | [diff] [blame] | 566 | core_validation::invalidateCommandBuffers(device_data_, cb_bindings, |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 567 | {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] | 568 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 569 | // Perform write update in given update struct |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 570 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) { |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 571 | // Perform update on a per-binding basis as consecutive updates roll over to next binding |
| 572 | auto descriptors_remaining = update->descriptorCount; |
| 573 | auto binding_being_updated = update->dstBinding; |
| 574 | auto offset = update->dstArrayElement; |
| 575 | while (descriptors_remaining) { |
| 576 | uint32_t update_count = std::min(descriptors_remaining, GetDescriptorCountFromBinding(binding_being_updated)); |
| 577 | auto global_idx = p_layout_->GetGlobalStartIndexFromBinding(binding_being_updated) + offset; |
| 578 | // Loop over the updates for a single binding at a time |
| 579 | for (uint32_t di = 0; di < update_count; ++di) { |
| 580 | descriptors_[global_idx + di]->WriteUpdate(update, di); |
| 581 | } |
| 582 | // Roll over to next binding in case of consecutive update |
| 583 | descriptors_remaining -= update_count; |
| 584 | offset = 0; |
| 585 | binding_being_updated++; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 586 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 587 | if (update->descriptorCount) some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 588 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 589 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 590 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 591 | // Validate Copy update |
| 592 | bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 593 | const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 594 | std::string *error_msg) { |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 595 | // Verify idle ds |
| 596 | if (in_use.load()) { |
Tobin Ehlis | 2cb8eb2 | 2017-01-03 14:09:57 -0700 | [diff] [blame] | 597 | // TODO : Re-using Free Idle error code, need copy update idle error code |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 598 | *error_code = VALIDATION_ERROR_00919; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 599 | std::stringstream error_str; |
| 600 | error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_ |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 601 | << " that is in use by a command buffer"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 602 | *error_msg = error_str.str(); |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 603 | return false; |
| 604 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 605 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 606 | *error_code = VALIDATION_ERROR_00966; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 607 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 608 | error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 609 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 610 | return false; |
| 611 | } |
| 612 | if (!src_set->HasBinding(update->srcBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 613 | *error_code = VALIDATION_ERROR_00964; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 614 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 615 | error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 616 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 617 | return false; |
| 618 | } |
| 619 | // src & dst set bindings are valid |
| 620 | // Check bounds of src & dst |
| 621 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 622 | if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) { |
| 623 | // SRC update out of bounds |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 624 | *error_code = VALIDATION_ERROR_00965; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 625 | std::stringstream error_str; |
| 626 | error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding |
| 627 | << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding) |
| 628 | << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 629 | << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 630 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 631 | return false; |
| 632 | } |
| 633 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 634 | if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
| 635 | // DST update out of bounds |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 636 | *error_code = VALIDATION_ERROR_00967; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 637 | std::stringstream error_str; |
| 638 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding |
| 639 | << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) |
| 640 | << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 641 | << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 642 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 643 | return false; |
| 644 | } |
| 645 | // Check that types match |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 646 | // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more |
| 647 | // fine-grained error codes |
| 648 | *error_code = VALIDATION_ERROR_00968; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 649 | auto src_type = src_set->GetTypeFromBinding(update->srcBinding); |
| 650 | auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 651 | if (src_type != dst_type) { |
| 652 | std::stringstream error_str; |
| 653 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type " |
| 654 | << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #" |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 655 | << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 656 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 657 | return false; |
| 658 | } |
| 659 | // Verify consistency of src & dst bindings if update crosses binding boundaries |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 660 | if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 661 | "copy update from", src_set->GetSet(), error_msg)) || |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 662 | (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 663 | set_, error_msg))) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 664 | return false; |
| 665 | } |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 666 | // First make sure source descriptors are updated |
| 667 | for (uint32_t i = 0; i < update->descriptorCount; ++i) { |
| 668 | if (!src_set->descriptors_[src_start_idx + i]) { |
| 669 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 670 | error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding |
| 671 | << " but descriptor at array offset " << update->srcArrayElement + i << " has not been updated"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 672 | *error_msg = error_str.str(); |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 673 | return false; |
| 674 | } |
| 675 | } |
| 676 | // Update parameters all look good and descriptor updated so verify update contents |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 677 | if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg)) return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 678 | |
| 679 | // All checks passed so update is good |
| 680 | return true; |
| 681 | } |
| 682 | // Perform Copy update |
| 683 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 684 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 685 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 686 | // Update parameters all look good so perform update |
| 687 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 688 | 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] | 689 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 690 | if (update->descriptorCount) some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 691 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 692 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 693 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 694 | |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 695 | // Bind cb_node to this set and this set to cb_node. |
| 696 | // Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going |
| 697 | // to be used in a draw by the given cb_node |
Tobin Ehlis | 276d3d3 | 2016-12-21 09:21:06 -0700 | [diff] [blame] | 698 | void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, |
Tobin Ehlis | 022528b | 2016-12-29 12:22:32 -0700 | [diff] [blame] | 699 | const std::map<uint32_t, descriptor_req> &binding_req_map) { |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 700 | // bind cb to this descriptor set |
| 701 | cb_bindings.insert(cb_node); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 702 | // Add bindings for descriptor set, the set's pool, and individual objects in the set |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 703 | cb_node->object_bindings.insert({reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT}); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 704 | pool_state_->cb_bindings.insert(cb_node); |
| 705 | cb_node->object_bindings.insert( |
| 706 | {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT}); |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 707 | // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's |
| 708 | // resources |
Tobin Ehlis | 022528b | 2016-12-29 12:22:32 -0700 | [diff] [blame] | 709 | for (auto binding_req_pair : binding_req_map) { |
| 710 | auto binding = binding_req_pair.first; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 711 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
| 712 | auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding); |
| 713 | for (uint32_t i = start_idx; i <= end_idx; ++i) { |
| 714 | descriptors_[i]->BindCommandBuffer(device_data_, cb_node); |
| 715 | } |
| 716 | } |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 717 | } |
| 718 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 719 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 720 | updated = false; |
| 721 | descriptor_class = PlainSampler; |
| 722 | }; |
| 723 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 724 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 725 | updated = false; |
| 726 | descriptor_class = PlainSampler; |
| 727 | if (immut) { |
| 728 | sampler_ = *immut; |
| 729 | immutable_ = true; |
| 730 | updated = true; |
| 731 | } |
| 732 | } |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 733 | // Validate given sampler. Currently this only checks to make sure it exists in the samplerMap |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 734 | bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const layer_data *dev_data) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 735 | return (GetSamplerState(dev_data, sampler) != nullptr); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 736 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 737 | |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 738 | bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 739 | const layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 740 | std::string *error_msg) { |
| 741 | // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases. |
| 742 | *error_code = VALIDATION_ERROR_00943; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 743 | auto iv_state = GetImageViewState(dev_data, image_view); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 744 | if (!iv_state) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 745 | std::stringstream error_str; |
| 746 | error_str << "Invalid VkImageView: " << image_view; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 747 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 748 | return false; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 749 | } |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 750 | // Note that when an imageview is created, we validated that memory is bound so no need to re-check here |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 751 | // Validate that imageLayout is compatible with aspect_mask and image format |
| 752 | // and validate that image usage bits are correct for given usage |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 753 | VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask; |
| 754 | VkImage image = iv_state->create_info.image; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 755 | VkFormat format = VK_FORMAT_MAX_ENUM; |
| 756 | VkImageUsageFlags usage = 0; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 757 | auto image_node = GetImageState(dev_data, image); |
Tobin Ehlis | 1c9c55f | 2016-06-02 11:49:22 -0600 | [diff] [blame] | 758 | if (image_node) { |
| 759 | format = image_node->createInfo.format; |
| 760 | usage = image_node->createInfo.usage; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 761 | // Validate that memory is bound to image |
Tobin Ehlis | 2cb8eb2 | 2017-01-03 14:09:57 -0700 | [diff] [blame] | 762 | // TODO: This should have its own valid usage id apart from 2524 which is from CreateImageView case. The only |
| 763 | // the error here occurs is if memory bound to a created imageView has been freed. |
Tobin Ehlis | e1995fc | 2016-12-22 12:45:09 -0700 | [diff] [blame] | 764 | if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()", VALIDATION_ERROR_02524)) { |
Tobin Ehlis | de1a0f9 | 2016-12-22 12:26:32 -0700 | [diff] [blame] | 765 | *error_code = VALIDATION_ERROR_02524; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 766 | *error_msg = "No memory bound to image."; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 767 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 768 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 769 | } else { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 770 | // Also need to check the swapchains. |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 771 | auto swapchain = GetSwapchainFromImage(dev_data, image); |
Tobin Ehlis | 969a526 | 2016-06-02 12:13:32 -0600 | [diff] [blame] | 772 | if (swapchain) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 773 | auto swapchain_node = GetSwapchainNode(dev_data, swapchain); |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 774 | if (swapchain_node) { |
| 775 | format = swapchain_node->createInfo.imageFormat; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 776 | } |
| 777 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 778 | } |
| 779 | // First validate that format and layout are compatible |
| 780 | if (format == VK_FORMAT_MAX_ENUM) { |
| 781 | std::stringstream error_str; |
| 782 | error_str << "Invalid image (" << image << ") in imageView (" << image_view << ")."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 783 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 784 | return false; |
| 785 | } |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 786 | // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under |
| 787 | // vkCreateImageView(). What's the best way to create unique id for these cases? |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 788 | bool ds = FormatIsDepthOrStencil(format); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 789 | switch (image_layout) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 790 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 791 | // Only Color bit must be set |
| 792 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 793 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 794 | error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does " |
| 795 | "not have VK_IMAGE_ASPECT_COLOR_BIT set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 796 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 797 | return false; |
| 798 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 799 | // format must NOT be DS |
| 800 | if (ds) { |
| 801 | std::stringstream error_str; |
| 802 | error_str << "ImageView (" << image_view |
| 803 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is " |
| 804 | << string_VkFormat(format) << " which is not a color format."; |
| 805 | *error_msg = error_str.str(); |
| 806 | return false; |
| 807 | } |
| 808 | break; |
| 809 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 810 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 811 | // Depth or stencil bit must be set, but both must NOT be set |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 812 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 813 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 814 | // both must NOT be set |
| 815 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 816 | error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 817 | *error_msg = error_str.str(); |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 818 | return false; |
| 819 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 820 | } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 821 | // Neither were set |
| 822 | std::stringstream error_str; |
| 823 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 824 | << " but does not have STENCIL or DEPTH aspects set"; |
| 825 | *error_msg = error_str.str(); |
| 826 | return false; |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 827 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 828 | // format must be DS |
| 829 | if (!ds) { |
| 830 | std::stringstream error_str; |
| 831 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 832 | << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format."; |
| 833 | *error_msg = error_str.str(); |
| 834 | return false; |
| 835 | } |
| 836 | break; |
| 837 | default: |
| 838 | // For other layouts if the source is depth/stencil image, both aspect bits must not be set |
| 839 | if (ds) { |
| 840 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 841 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 842 | // both must NOT be set |
| 843 | std::stringstream error_str; |
| 844 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 845 | << " and is using depth/stencil image of format " << string_VkFormat(format) |
| 846 | << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil " |
| 847 | "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 848 | "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil " |
| 849 | "reads respectively."; |
| 850 | *error_msg = error_str.str(); |
| 851 | return false; |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 856 | } |
| 857 | // Now validate that usage flags are correctly set for given type of update |
Tobin Ehlis | fb4cf71 | 2016-10-10 14:02:48 -0600 | [diff] [blame] | 858 | // As we're switching per-type, if any type has specific layout requirements, check those here as well |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 859 | // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images |
| 860 | // under vkCreateImage() |
| 861 | // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with |
| 862 | // identify swizzle |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 863 | std::string error_usage_bit; |
| 864 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 865 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 866 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 867 | if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { |
| 868 | error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT"; |
| 869 | } |
| 870 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 871 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 872 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 873 | if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 874 | error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT"; |
| 875 | } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) { |
| 876 | std::stringstream error_str; |
| 877 | // TODO : Need to create custom enum error code for this case |
| 878 | error_str |
| 879 | << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout " |
| 880 | << string_VkImageLayout(image_layout) |
| 881 | << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can " |
| 882 | "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'"; |
| 883 | *error_msg = error_str.str(); |
| 884 | return false; |
| 885 | } |
| 886 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 887 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 888 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 889 | if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
| 890 | error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT"; |
| 891 | } |
| 892 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 893 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 894 | default: |
| 895 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 896 | } |
| 897 | if (!error_usage_bit.empty()) { |
| 898 | std::stringstream error_str; |
| 899 | error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage |
| 900 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 901 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 902 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 903 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 904 | } |
| 905 | return true; |
| 906 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 907 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 908 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
| 909 | sampler_ = update->pImageInfo[index].sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 910 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 911 | } |
| 912 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 913 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 914 | if (!immutable_) { |
| 915 | auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 916 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 917 | } |
| 918 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 919 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 920 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 921 | void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 922 | if (!immutable_) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 923 | auto sampler_state = GetSamplerState(dev_data, sampler_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 924 | if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 928 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor() |
| 929 | : 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] | 930 | updated = false; |
| 931 | descriptor_class = ImageSampler; |
| 932 | } |
| 933 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 934 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut) |
| 935 | : 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] | 936 | updated = false; |
| 937 | descriptor_class = ImageSampler; |
| 938 | if (immut) { |
| 939 | sampler_ = *immut; |
| 940 | immutable_ = true; |
| 941 | updated = true; |
| 942 | } |
| 943 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 944 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 945 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 946 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 947 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 948 | sampler_ = image_info.sampler; |
| 949 | image_view_ = image_info.imageView; |
| 950 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 951 | } |
| 952 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 953 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 954 | if (!immutable_) { |
| 955 | auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 956 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 957 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 958 | auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_; |
| 959 | auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 960 | updated = true; |
| 961 | image_view_ = image_view; |
| 962 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 963 | } |
| 964 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 965 | void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 966 | // First add binding for any non-immutable sampler |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 967 | if (!immutable_) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 968 | auto sampler_state = GetSamplerState(dev_data, sampler_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 969 | if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 970 | } |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 971 | // Add binding for image |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 972 | auto iv_state = GetImageViewState(dev_data, image_view_); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 973 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 974 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 975 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 976 | } |
| 977 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 978 | cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type) |
| 979 | : 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] | 980 | updated = false; |
| 981 | descriptor_class = Image; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 982 | if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) storage_ = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 983 | }; |
| 984 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 985 | void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 986 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 987 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 988 | image_view_ = image_info.imageView; |
| 989 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 990 | } |
| 991 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 992 | void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 993 | auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_; |
| 994 | auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 995 | updated = true; |
| 996 | image_view_ = image_view; |
| 997 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 998 | } |
| 999 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1000 | void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1001 | // Add binding for image |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1002 | auto iv_state = GetImageViewState(dev_data, image_view_); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 1003 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 1004 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1005 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1006 | } |
| 1007 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1008 | cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type) |
| 1009 | : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1010 | updated = false; |
| 1011 | descriptor_class = GeneralBuffer; |
| 1012 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 1013 | dynamic_ = true; |
| 1014 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) { |
| 1015 | storage_ = true; |
| 1016 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 1017 | dynamic_ = true; |
| 1018 | storage_ = true; |
| 1019 | } |
| 1020 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1021 | void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1022 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1023 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1024 | buffer_ = buffer_info.buffer; |
| 1025 | offset_ = buffer_info.offset; |
| 1026 | range_ = buffer_info.range; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1027 | } |
| 1028 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1029 | void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) { |
| 1030 | auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1031 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1032 | buffer_ = buff_desc->buffer_; |
| 1033 | offset_ = buff_desc->offset_; |
| 1034 | range_ = buff_desc->range_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1035 | } |
| 1036 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1037 | void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1038 | auto buffer_node = GetBufferState(dev_data, buffer_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1039 | if (buffer_node) core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1040 | } |
| 1041 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1042 | 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] | 1043 | updated = false; |
| 1044 | descriptor_class = TexelBuffer; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1045 | if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) storage_ = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1046 | }; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1047 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1048 | void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1049 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1050 | buffer_view_ = update->pTexelBufferView[index]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1051 | } |
| 1052 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1053 | void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) { |
| 1054 | updated = true; |
| 1055 | buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_; |
| 1056 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1057 | |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1058 | void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1059 | auto bv_state = GetBufferViewState(dev_data, buffer_view_); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1060 | if (bv_state) { |
Tobin Ehlis | 2515c0e | 2016-09-28 07:12:28 -0600 | [diff] [blame] | 1061 | core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1062 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1063 | } |
| 1064 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1065 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1066 | // sets, and then calls their respective Validate[Write|Copy]Update functions. |
| 1067 | // If the update hits an issue for which the callback returns "true", meaning that the call down the chain should |
| 1068 | // be skipped, then true is returned. |
| 1069 | // If there is no issue with the update, then false is returned. |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1070 | bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data, const layer_data *dev_data, |
| 1071 | uint32_t write_count, const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1072 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1073 | bool skip_call = false; |
| 1074 | // Validate Write updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1075 | for (uint32_t i = 0; i < write_count; i++) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1076 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1077 | auto set_node = core_validation::GetSetNode(dev_data, dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1078 | if (!set_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1079 | skip_call |= |
| 1080 | 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] | 1081 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1082 | "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.", |
| 1083 | reinterpret_cast<uint64_t &>(dest_set)); |
| 1084 | } else { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1085 | UNIQUE_VALIDATION_ERROR_CODE error_code; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1086 | std::string error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1087 | if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1088 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1089 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1090 | "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64 |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1091 | " with error: %s. %s", |
| 1092 | reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | // Now validate copy updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1097 | for (uint32_t i = 0; i < copy_count; ++i) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1098 | auto dst_set = p_cds[i].dstSet; |
| 1099 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1100 | auto src_node = core_validation::GetSetNode(dev_data, src_set); |
| 1101 | auto dst_node = core_validation::GetSetNode(dev_data, dst_set); |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 1102 | // Object_tracker verifies that src & dest descriptor set are valid |
| 1103 | assert(src_node); |
| 1104 | assert(dst_node); |
| 1105 | UNIQUE_VALIDATION_ERROR_CODE error_code; |
| 1106 | std::string error_str; |
| 1107 | if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1108 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 1109 | reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS", |
| 1110 | "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64 |
| 1111 | " to Descriptor Set 0x%" PRIx64 " with error: %s. %s", |
| 1112 | reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set), error_str.c_str(), |
| 1113 | validation_error_map[error_code]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | return skip_call; |
| 1117 | } |
| 1118 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1119 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 1120 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 1121 | // with the same set of updates. |
| 1122 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 1123 | // calling down the chain. |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1124 | void cvdescriptorset::PerformUpdateDescriptorSets(const layer_data *dev_data, uint32_t write_count, |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1125 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 1126 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1127 | // Write updates first |
| 1128 | uint32_t i = 0; |
| 1129 | for (i = 0; i < write_count; ++i) { |
| 1130 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1131 | auto set_node = core_validation::GetSetNode(dev_data, dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1132 | if (set_node) { |
| 1133 | set_node->PerformWriteUpdate(&p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | // Now copy updates |
| 1137 | for (i = 0; i < copy_count; ++i) { |
| 1138 | auto dst_set = p_cds[i].dstSet; |
| 1139 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1140 | auto src_node = core_validation::GetSetNode(dev_data, src_set); |
| 1141 | auto dst_node = core_validation::GetSetNode(dev_data, dst_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1142 | if (src_node && dst_node) { |
| 1143 | dst_node->PerformCopyUpdate(&p_cds[i], src_node); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | } |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1147 | // This helper function carries out the state updates for descriptor updates peformed via update templates. It basically collects |
| 1148 | // data and leverages the PerformUpdateDescriptor helper functions to do this. |
| 1149 | void cvdescriptorset::PerformUpdateDescriptorSetsWithTemplateKHR(layer_data *device_data, VkDescriptorSet descriptorSet, |
| 1150 | std::unique_ptr<TEMPLATE_STATE> const &template_state, |
| 1151 | const void *pData) { |
| 1152 | auto const &create_info = template_state->create_info; |
| 1153 | |
| 1154 | // Create a vector of write structs |
| 1155 | std::vector<VkWriteDescriptorSet> desc_writes; |
| 1156 | auto layout_obj = GetDescriptorSetLayout(device_data, create_info.descriptorSetLayout); |
| 1157 | |
| 1158 | // Create a WriteDescriptorSet struct for each template update entry |
| 1159 | for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) { |
| 1160 | auto binding_count = layout_obj->GetDescriptorCountFromBinding(create_info.pDescriptorUpdateEntries[i].dstBinding); |
| 1161 | auto binding_being_updated = create_info.pDescriptorUpdateEntries[i].dstBinding; |
| 1162 | auto dst_array_element = create_info.pDescriptorUpdateEntries[i].dstArrayElement; |
| 1163 | |
| 1164 | for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) { |
| 1165 | desc_writes.emplace_back(); |
| 1166 | auto &write_entry = desc_writes.back(); |
| 1167 | |
| 1168 | size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride; |
| 1169 | char *update_entry = (char *)(pData) + offset; |
| 1170 | |
| 1171 | if (dst_array_element >= binding_count) { |
| 1172 | dst_array_element = 0; |
Mark Lobodzinski | 4aa479d | 2017-03-10 09:14:00 -0700 | [diff] [blame] | 1173 | binding_being_updated = layout_obj->GetNextValidBinding(binding_being_updated); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | write_entry.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1177 | write_entry.pNext = NULL; |
| 1178 | write_entry.dstSet = descriptorSet; |
| 1179 | write_entry.dstBinding = binding_being_updated; |
| 1180 | write_entry.dstArrayElement = dst_array_element; |
| 1181 | write_entry.descriptorCount = 1; |
| 1182 | write_entry.descriptorType = create_info.pDescriptorUpdateEntries[i].descriptorType; |
| 1183 | |
| 1184 | switch (create_info.pDescriptorUpdateEntries[i].descriptorType) { |
| 1185 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 1186 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 1187 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1188 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 1189 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1190 | write_entry.pImageInfo = reinterpret_cast<VkDescriptorImageInfo *>(update_entry); |
| 1191 | break; |
| 1192 | |
| 1193 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1194 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1195 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1196 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1197 | write_entry.pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry); |
| 1198 | break; |
| 1199 | |
| 1200 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1201 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1202 | write_entry.pTexelBufferView = reinterpret_cast<VkBufferView *>(update_entry); |
| 1203 | break; |
| 1204 | default: |
| 1205 | assert(0); |
| 1206 | break; |
| 1207 | } |
| 1208 | dst_array_element++; |
| 1209 | } |
| 1210 | } |
| 1211 | PerformUpdateDescriptorSets(device_data, static_cast<uint32_t>(desc_writes.size()), desc_writes.data(), 0, NULL); |
| 1212 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1213 | // Validate the state for a given write update but don't actually perform the update |
| 1214 | // If an error would occur for this update, return false and fill in details in error_msg string |
| 1215 | bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1216 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1217 | // Verify idle ds |
| 1218 | if (in_use.load()) { |
Tobin Ehlis | 2cb8eb2 | 2017-01-03 14:09:57 -0700 | [diff] [blame] | 1219 | // TODO : Re-using Free Idle error code, need write update idle error code |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1220 | *error_code = VALIDATION_ERROR_00919; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1221 | std::stringstream error_str; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1222 | error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_ |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1223 | << " that is in use by a command buffer"; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1224 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1225 | return false; |
| 1226 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1227 | // Verify dst binding exists |
| 1228 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1229 | *error_code = VALIDATION_ERROR_00936; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1230 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1231 | error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1232 | *error_msg = error_str.str(); |
| 1233 | return false; |
Tobin Ehlis | 59a5efc | 2016-11-21 09:41:57 -0700 | [diff] [blame] | 1234 | } else { |
| 1235 | // Make sure binding isn't empty |
| 1236 | if (0 == p_layout_->GetDescriptorCountFromBinding(update->dstBinding)) { |
| 1237 | *error_code = VALIDATION_ERROR_02348; |
| 1238 | std::stringstream error_str; |
| 1239 | error_str << "DescriptorSet " << set_ << " cannot updated binding " << update->dstBinding << " that has 0 descriptors"; |
| 1240 | *error_msg = error_str.str(); |
| 1241 | return false; |
| 1242 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1243 | } |
| 1244 | // We know that binding is valid, verify update and do update on each descriptor |
| 1245 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 1246 | auto type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 1247 | if (type != update->descriptorType) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1248 | *error_code = VALIDATION_ERROR_00937; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1249 | std::stringstream error_str; |
| 1250 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type " |
| 1251 | << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType); |
| 1252 | *error_msg = error_str.str(); |
| 1253 | return false; |
| 1254 | } |
Tobin Ehlis | 7b40235 | 2016-12-15 07:51:20 -0700 | [diff] [blame] | 1255 | if (update->descriptorCount > (descriptors_.size() - start_idx)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1256 | *error_code = VALIDATION_ERROR_00938; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1257 | std::stringstream error_str; |
| 1258 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
Tobin Ehlis | 7b40235 | 2016-12-15 07:51:20 -0700 | [diff] [blame] | 1259 | << descriptors_.size() - start_idx |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1260 | << " descriptors in that binding and all successive bindings of the set, but update of " |
| 1261 | << update->descriptorCount << " descriptors combined with update array element offset of " |
| 1262 | << update->dstArrayElement << " oversteps the available number of consecutive descriptors"; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1263 | *error_msg = error_str.str(); |
| 1264 | return false; |
| 1265 | } |
| 1266 | // Verify consecutive bindings match (if needed) |
| 1267 | if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1268 | set_, error_msg)) { |
Tobin Ehlis | 48fbd69 | 2017-01-04 09:17:01 -0700 | [diff] [blame] | 1269 | // TODO : Should break out "consecutive binding updates" language into valid usage statements |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1270 | *error_code = VALIDATION_ERROR_00938; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1271 | return false; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1272 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1273 | // Update is within bounds and consistent so last step is to validate update contents |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1274 | if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) { |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1275 | std::stringstream error_str; |
| 1276 | error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding |
| 1277 | << " failed with error message: " << error_msg->c_str(); |
| 1278 | *error_msg = error_str.str(); |
| 1279 | return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1280 | } |
| 1281 | // All checks passed, update is clean |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1282 | return true; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 1283 | } |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1284 | // For the given buffer, verify that its creation parameters are appropriate for the given type |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1285 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame] | 1286 | bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1287 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1288 | // Verify that usage bits set correctly for given type |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 1289 | auto usage = buffer_node->createInfo.usage; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1290 | std::string error_usage_bit; |
| 1291 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1292 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1293 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { |
| 1294 | *error_code = VALIDATION_ERROR_00950; |
| 1295 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; |
| 1296 | } |
| 1297 | break; |
| 1298 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1299 | if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { |
| 1300 | *error_code = VALIDATION_ERROR_00951; |
| 1301 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; |
| 1302 | } |
| 1303 | break; |
| 1304 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1305 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1306 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
| 1307 | *error_code = VALIDATION_ERROR_00946; |
| 1308 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; |
| 1309 | } |
| 1310 | break; |
| 1311 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1312 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1313 | if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { |
| 1314 | *error_code = VALIDATION_ERROR_00947; |
| 1315 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; |
| 1316 | } |
| 1317 | break; |
| 1318 | default: |
| 1319 | break; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1320 | } |
| 1321 | if (!error_usage_bit.empty()) { |
| 1322 | std::stringstream error_str; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1323 | error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage |
| 1324 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 1325 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1326 | *error_msg = error_str.str(); |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1327 | return false; |
| 1328 | } |
| 1329 | return true; |
| 1330 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1331 | // For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes: |
| 1332 | // 1. buffer is valid |
| 1333 | // 2. buffer was created with correct usage flags |
| 1334 | // 3. offset is less than buffer size |
| 1335 | // 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)] |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 1336 | // 5. range and offset are within the device's limits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1337 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1338 | bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1339 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const { |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1340 | // First make sure that buffer is valid |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1341 | auto buffer_node = GetBufferState(device_data_, buffer_info->buffer); |
Tobin Ehlis | fa8b618 | 2016-12-22 13:40:45 -0700 | [diff] [blame] | 1342 | // Any invalid buffer should already be caught by object_tracker |
| 1343 | assert(buffer_node); |
Tobin Ehlis | e1995fc | 2016-12-22 12:45:09 -0700 | [diff] [blame] | 1344 | if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()", VALIDATION_ERROR_02525)) { |
Tobin Ehlis | de1a0f9 | 2016-12-22 12:26:32 -0700 | [diff] [blame] | 1345 | *error_code = VALIDATION_ERROR_02525; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1346 | *error_msg = "No memory bound to buffer."; |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 1347 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 1348 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1349 | // Verify usage bits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1350 | if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) { |
| 1351 | // error_msg will have been updated by ValidateBufferUsage() |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1352 | return false; |
| 1353 | } |
| 1354 | // offset must be less than buffer size |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 1355 | if (buffer_info->offset >= buffer_node->createInfo.size) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1356 | *error_code = VALIDATION_ERROR_00959; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1357 | std::stringstream error_str; |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 1358 | error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than or equal to buffer " |
| 1359 | << buffer_node->buffer << " size of " << buffer_node->createInfo.size; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1360 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1361 | return false; |
| 1362 | } |
| 1363 | if (buffer_info->range != VK_WHOLE_SIZE) { |
| 1364 | // Range must be VK_WHOLE_SIZE or > 0 |
| 1365 | if (!buffer_info->range) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1366 | *error_code = VALIDATION_ERROR_00960; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1367 | std::stringstream error_str; |
| 1368 | error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1369 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1370 | return false; |
| 1371 | } |
| 1372 | // Range must be VK_WHOLE_SIZE or <= (buffer size - offset) |
| 1373 | if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1374 | *error_code = VALIDATION_ERROR_00961; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1375 | std::stringstream error_str; |
| 1376 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size (" |
| 1377 | << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1378 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
| 1381 | } |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 1382 | // Check buffer update sizes against device limits |
| 1383 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type || VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 1384 | auto max_ub_range = limits_.maxUniformBufferRange; |
| 1385 | // TODO : If range is WHOLE_SIZE, need to make sure underlying buffer size doesn't exceed device max |
| 1386 | if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_ub_range) { |
| 1387 | *error_code = VALIDATION_ERROR_00948; |
| 1388 | std::stringstream error_str; |
| 1389 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range |
| 1390 | << " which is greater than this device's maxUniformBufferRange (" << max_ub_range << ")"; |
| 1391 | *error_msg = error_str.str(); |
| 1392 | return false; |
| 1393 | } |
| 1394 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type || VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 1395 | auto max_sb_range = limits_.maxStorageBufferRange; |
| 1396 | // TODO : If range is WHOLE_SIZE, need to make sure underlying buffer size doesn't exceed device max |
| 1397 | if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_sb_range) { |
| 1398 | *error_code = VALIDATION_ERROR_00949; |
| 1399 | std::stringstream error_str; |
| 1400 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range |
| 1401 | << " which is greater than this device's maxStorageBufferRange (" << max_sb_range << ")"; |
| 1402 | *error_msg = error_str.str(); |
| 1403 | return false; |
| 1404 | } |
| 1405 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1406 | return true; |
| 1407 | } |
| 1408 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1409 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1410 | bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1411 | UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 1412 | std::string *error_msg) const { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1413 | switch (update->descriptorType) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1414 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 1415 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1416 | // Validate image |
| 1417 | auto image_view = update->pImageInfo[di].imageView; |
| 1418 | auto image_layout = update->pImageInfo[di].imageLayout; |
| 1419 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1420 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1421 | error_str << "Attempted write update to combined image sampler descriptor failed due to: " |
| 1422 | << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1423 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1424 | return false; |
| 1425 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1426 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1427 | // Intentional fall-through to validate sampler |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1428 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1429 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 1430 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1431 | if (!descriptors_[index + di].get()->IsImmutableSampler()) { |
| 1432 | if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) { |
| 1433 | *error_code = VALIDATION_ERROR_00942; |
| 1434 | std::stringstream error_str; |
| 1435 | error_str << "Attempted write update to sampler descriptor with invalid sampler: " |
| 1436 | << update->pImageInfo[di].sampler << "."; |
| 1437 | *error_msg = error_str.str(); |
| 1438 | return false; |
| 1439 | } |
| 1440 | } else { |
| 1441 | // TODO : Warn here |
| 1442 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1443 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1444 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1445 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1446 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1447 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1448 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 1449 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1450 | auto image_view = update->pImageInfo[di].imageView; |
| 1451 | auto image_layout = update->pImageInfo[di].imageLayout; |
| 1452 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
| 1453 | std::stringstream error_str; |
| 1454 | error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str(); |
| 1455 | *error_msg = error_str.str(); |
| 1456 | return false; |
| 1457 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1458 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1459 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1460 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1461 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1462 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| 1463 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1464 | auto buffer_view = update->pTexelBufferView[di]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1465 | auto bv_state = GetBufferViewState(device_data_, buffer_view); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1466 | if (!bv_state) { |
| 1467 | *error_code = VALIDATION_ERROR_00940; |
| 1468 | std::stringstream error_str; |
| 1469 | error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 1470 | *error_msg = error_str.str(); |
| 1471 | return false; |
| 1472 | } |
| 1473 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1474 | if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), update->descriptorType, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1475 | std::stringstream error_str; |
| 1476 | error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 1477 | *error_msg = error_str.str(); |
| 1478 | return false; |
| 1479 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1480 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1481 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1482 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1483 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1484 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1485 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1486 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 1487 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1488 | if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) { |
| 1489 | std::stringstream error_str; |
| 1490 | error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 1491 | *error_msg = error_str.str(); |
| 1492 | return false; |
| 1493 | } |
| 1494 | } |
| 1495 | break; |
| 1496 | } |
| 1497 | default: |
| 1498 | assert(0); // We've already verified update type so should never get here |
| 1499 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1500 | } |
| 1501 | // All checks passed so update contents are good |
| 1502 | return true; |
| 1503 | } |
| 1504 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1505 | bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1506 | VkDescriptorType type, uint32_t index, |
| 1507 | UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 1508 | std::string *error_msg) const { |
| 1509 | // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are |
| 1510 | // for write updates |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1511 | switch (src_set->descriptors_[index]->descriptor_class) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1512 | case PlainSampler: { |
| 1513 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1514 | if (!src_set->descriptors_[index + di]->IsImmutableSampler()) { |
| 1515 | auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler(); |
| 1516 | if (!ValidateSampler(update_sampler, device_data_)) { |
| 1517 | *error_code = VALIDATION_ERROR_00942; |
| 1518 | std::stringstream error_str; |
| 1519 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 1520 | *error_msg = error_str.str(); |
| 1521 | return false; |
| 1522 | } |
| 1523 | } else { |
| 1524 | // TODO : Warn here |
| 1525 | } |
| 1526 | } |
| 1527 | break; |
| 1528 | } |
| 1529 | case ImageSampler: { |
| 1530 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1531 | auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1532 | // First validate sampler |
| 1533 | if (!img_samp_desc->IsImmutableSampler()) { |
| 1534 | auto update_sampler = img_samp_desc->GetSampler(); |
| 1535 | if (!ValidateSampler(update_sampler, device_data_)) { |
| 1536 | *error_code = VALIDATION_ERROR_00942; |
| 1537 | std::stringstream error_str; |
| 1538 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 1539 | *error_msg = error_str.str(); |
| 1540 | return false; |
| 1541 | } |
| 1542 | } else { |
| 1543 | // TODO : Warn here |
| 1544 | } |
| 1545 | // Validate image |
| 1546 | auto image_view = img_samp_desc->GetImageView(); |
| 1547 | auto image_layout = img_samp_desc->GetImageLayout(); |
| 1548 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1549 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1550 | error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1551 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1552 | return false; |
| 1553 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1554 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1555 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1556 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1557 | case Image: { |
| 1558 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1559 | auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1560 | auto image_view = img_desc->GetImageView(); |
| 1561 | auto image_layout = img_desc->GetImageLayout(); |
| 1562 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1563 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1564 | error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1565 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1568 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1569 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1570 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1571 | case TexelBuffer: { |
| 1572 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1573 | auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1574 | auto bv_state = GetBufferViewState(device_data_, buffer_view); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1575 | if (!bv_state) { |
| 1576 | *error_code = VALIDATION_ERROR_00940; |
| 1577 | std::stringstream error_str; |
| 1578 | error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 1579 | *error_msg = error_str.str(); |
| 1580 | return false; |
| 1581 | } |
| 1582 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1583 | if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1584 | std::stringstream error_str; |
| 1585 | error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 1586 | *error_msg = error_str.str(); |
| 1587 | return false; |
| 1588 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1589 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1590 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1591 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1592 | case GeneralBuffer: { |
| 1593 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1594 | auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1595 | if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1596 | std::stringstream error_str; |
| 1597 | error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 1598 | *error_msg = error_str.str(); |
| 1599 | return false; |
| 1600 | } |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1601 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1602 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1603 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1604 | default: |
| 1605 | assert(0); // We've already verified update type so should never get here |
| 1606 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1607 | } |
| 1608 | // All checks passed so update contents are good |
| 1609 | return true; |
Chris Forbes | b4e0bdb | 2016-05-31 16:34:40 +1200 | [diff] [blame] | 1610 | } |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 1611 | // Update the common AllocateDescriptorSetsData |
| 1612 | void cvdescriptorset::UpdateAllocateDescriptorSetsData(const layer_data *dev_data, const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1613 | AllocateDescriptorSetsData *ds_data) { |
| 1614 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 1615 | auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
| 1616 | if (layout) { |
| 1617 | ds_data->layout_nodes[i] = layout; |
| 1618 | // Count total descriptors required per type |
| 1619 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 1620 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
| 1621 | uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType); |
| 1622 | ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount; |
| 1623 | } |
| 1624 | } |
| 1625 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 1626 | } |
| 1627 | }; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1628 | // Verify that the state at allocate time is correct, but don't actually allocate the sets yet |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 1629 | bool cvdescriptorset::ValidateAllocateDescriptorSets(const core_validation::layer_data *dev_data, |
| 1630 | const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1631 | const AllocateDescriptorSetsData *ds_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1632 | bool skip_call = false; |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 1633 | auto report_data = core_validation::GetReportData(dev_data); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1634 | |
| 1635 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1636 | auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1637 | if (!layout) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1638 | skip_call |= |
| 1639 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
| 1640 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 1641 | "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", |
| 1642 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i])); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1643 | } |
| 1644 | } |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1645 | if (!GetDeviceExtensions(dev_data)->khr_maintenance1_enabled) { |
| 1646 | auto pool_state = GetDescriptorPoolState(dev_data, p_alloc_info->descriptorPool); |
| 1647 | // Track number of descriptorSets allowable in this pool |
| 1648 | if (pool_state->availableSets < p_alloc_info->descriptorSetCount) { |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1649 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 1650 | reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, VALIDATION_ERROR_00911, "DS", |
| 1651 | "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 |
| 1652 | ". This pool only has %d descriptorSets remaining. %s", |
| 1653 | p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), |
| 1654 | pool_state->availableSets, validation_error_map[VALIDATION_ERROR_00911]); |
| 1655 | } |
| 1656 | // Determine whether descriptor counts are satisfiable |
| 1657 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
| 1658 | if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) { |
| 1659 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
| 1660 | reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, VALIDATION_ERROR_00912, "DS", |
| 1661 | "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64 |
| 1662 | ". This pool only has %d descriptors of this type remaining. %s", |
| 1663 | ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)), |
| 1664 | reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i], |
| 1665 | validation_error_map[VALIDATION_ERROR_00912]); |
| 1666 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1667 | } |
| 1668 | } |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1669 | |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1670 | return skip_call; |
| 1671 | } |
| 1672 | // 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] | 1673 | void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1674 | const VkDescriptorSet *descriptor_sets, |
| 1675 | const AllocateDescriptorSetsData *ds_data, |
Tobin Ehlis | bd711bd | 2016-10-12 14:27:30 -0600 | [diff] [blame] | 1676 | std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map, |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1677 | std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map, |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1678 | const layer_data *dev_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1679 | auto pool_state = (*pool_map)[p_alloc_info->descriptorPool]; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1680 | /* Account for sets and individual descriptors allocated from pool */ |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1681 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1682 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
| 1683 | pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i]; |
| 1684 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1685 | /* Create tracking object for each descriptor set; insert into |
| 1686 | * global map and the pool's set. |
| 1687 | */ |
| 1688 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 1689 | auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i], |
| 1690 | dev_data); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1691 | |
| 1692 | pool_state->sets.insert(new_ds); |
| 1693 | new_ds->in_use.store(0); |
| 1694 | (*set_map)[descriptor_sets[i]] = new_ds; |
| 1695 | } |
| 1696 | } |