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