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