Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2018 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2018 Valve Corporation |
| 3 | * Copyright (c) 2015-2018 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2018 Google Inc. |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 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> |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 19 | * John Zulauf <jzulauf@lunarg.com> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 20 | */ |
| 21 | |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 22 | // Allow use of STL min and max functions in Windows |
| 23 | #define NOMINMAX |
| 24 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 25 | #include "descriptor_sets.h" |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 26 | #include "hash_vk_types.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 27 | #include "vk_enum_string_helper.h" |
| 28 | #include "vk_safe_struct.h" |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 29 | #include "vk_typemap_helper.h" |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 30 | #include "buffer_validation.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 31 | #include <sstream> |
Mark Lobodzinski | 2eee5d8 | 2016-12-02 15:33:18 -0700 | [diff] [blame] | 32 | #include <algorithm> |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 33 | #include <memory> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 34 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 35 | // ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended |
| 36 | // state that comes from a different array/structure so they can stay together |
| 37 | // while being sorted by binding number. |
| 38 | struct ExtendedBinding { |
| 39 | ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlagsEXT f) : layout_binding(l), binding_flags(f) {} |
| 40 | |
| 41 | const VkDescriptorSetLayoutBinding *layout_binding; |
| 42 | VkDescriptorBindingFlagsEXT binding_flags; |
| 43 | }; |
| 44 | |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 45 | struct BindingNumCmp { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 46 | bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const { |
| 47 | return a.layout_binding->binding < b.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 48 | } |
| 49 | }; |
| 50 | |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 51 | using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef; |
| 52 | using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId; |
| 53 | |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 54 | // Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information) |
| 55 | cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 56 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 57 | DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) { |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 58 | return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info)); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 59 | } |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 60 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 61 | // Construct DescriptorSetLayout instance from given create info |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 62 | // Proactively reserve and resize as possible, as the reallocation was visible in profiling |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 63 | cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info) |
| 64 | : flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 65 | const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(p_create_info->pNext); |
| 66 | |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 67 | binding_type_stats_ = {0, 0, 0}; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 68 | std::set<ExtendedBinding, BindingNumCmp> sorted_bindings; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 69 | const uint32_t input_bindings_count = p_create_info->bindingCount; |
| 70 | // Sort the input bindings in binding number order, eliminating duplicates |
| 71 | for (uint32_t i = 0; i < input_bindings_count; i++) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 72 | VkDescriptorBindingFlagsEXT flags = 0; |
| 73 | if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) { |
| 74 | flags = flags_create_info->pBindingFlags[i]; |
| 75 | } |
| 76 | sorted_bindings.insert(ExtendedBinding(p_create_info->pBindings + i, flags)); |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // Store the create info in the sorted order from above |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 80 | std::map<uint32_t, uint32_t> binding_to_dyn_count; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 81 | uint32_t index = 0; |
| 82 | binding_count_ = static_cast<uint32_t>(sorted_bindings.size()); |
| 83 | bindings_.reserve(binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 84 | binding_flags_.reserve(binding_count_); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 85 | binding_to_index_map_.reserve(binding_count_); |
| 86 | for (auto input_binding : sorted_bindings) { |
| 87 | // Add to binding and map, s.t. it is robust to invalid duplication of binding_num |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 88 | const auto binding_num = input_binding.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 89 | binding_to_index_map_[binding_num] = index++; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 90 | bindings_.emplace_back(input_binding.layout_binding); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 91 | auto &binding_info = bindings_.back(); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 92 | binding_flags_.emplace_back(input_binding.binding_flags); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 93 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 94 | descriptor_count_ += binding_info.descriptorCount; |
| 95 | if (binding_info.descriptorCount > 0) { |
| 96 | non_empty_bindings_.insert(binding_num); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 97 | } |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 98 | |
| 99 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 100 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { |
| 101 | binding_to_dyn_count[binding_num] = binding_info.descriptorCount; |
| 102 | dynamic_descriptor_count_ += binding_info.descriptorCount; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 103 | binding_type_stats_.dynamic_buffer_count++; |
| 104 | } else if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) || |
| 105 | (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) { |
| 106 | binding_type_stats_.non_dynamic_buffer_count++; |
| 107 | } else { |
| 108 | binding_type_stats_.image_sampler_count++; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 109 | } |
| 110 | } |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 111 | assert(bindings_.size() == binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 112 | assert(binding_flags_.size() == binding_count_); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 113 | uint32_t global_index = 0; |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 114 | binding_to_global_index_range_map_.reserve(binding_count_); |
| 115 | // Vector order is finalized so create maps of bindings to descriptors and descriptors to indices |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 116 | for (uint32_t i = 0; i < binding_count_; ++i) { |
| 117 | auto binding_num = bindings_[i].binding; |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 118 | auto final_index = global_index + bindings_[i].descriptorCount; |
| 119 | binding_to_global_index_range_map_[binding_num] = IndexRange(global_index, final_index); |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 120 | if (final_index != global_index) { |
| 121 | global_start_to_index_map_[global_index] = i; |
| 122 | } |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 123 | global_index = final_index; |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 124 | } |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 125 | |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 126 | // Now create dyn offset array mapping for any dynamic descriptors |
| 127 | uint32_t dyn_array_idx = 0; |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 128 | binding_to_dynamic_array_idx_map_.reserve(binding_to_dyn_count.size()); |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 129 | for (const auto &bc_pair : binding_to_dyn_count) { |
| 130 | binding_to_dynamic_array_idx_map_[bc_pair.first] = dyn_array_idx; |
| 131 | dyn_array_idx += bc_pair.second; |
| 132 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 133 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 134 | |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 135 | size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const { |
| 136 | hash_util::HashCombiner hc; |
| 137 | hc << flags_; |
| 138 | hc.Combine(bindings_); |
| 139 | return hc.Value(); |
| 140 | } |
| 141 | // |
| 142 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 143 | // Return valid index or "end" i.e. binding_count_; |
| 144 | // The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given |
| 145 | // Common code for all binding lookups. |
| 146 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const { |
| 147 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 148 | if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second; |
| 149 | return GetBindingCount(); |
| 150 | } |
| 151 | VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex( |
| 152 | const uint32_t index) const { |
| 153 | if (index >= bindings_.size()) return nullptr; |
| 154 | return bindings_[index].ptr(); |
| 155 | } |
| 156 | // Return descriptorCount for given index, 0 if index is unavailable |
| 157 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const { |
| 158 | if (index >= bindings_.size()) return 0; |
| 159 | return bindings_[index].descriptorCount; |
| 160 | } |
| 161 | // For the given index, return descriptorType |
| 162 | VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const { |
| 163 | assert(index < bindings_.size()); |
| 164 | if (index < bindings_.size()) return bindings_[index].descriptorType; |
| 165 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 166 | } |
| 167 | // For the given index, return stageFlags |
| 168 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const { |
| 169 | assert(index < bindings_.size()); |
| 170 | if (index < bindings_.size()) return bindings_[index].stageFlags; |
| 171 | return VkShaderStageFlags(0); |
| 172 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 173 | // Return binding flags for given index, 0 if index is unavailable |
| 174 | VkDescriptorBindingFlagsEXT cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex( |
| 175 | const uint32_t index) const { |
| 176 | if (index >= binding_flags_.size()) return 0; |
| 177 | return binding_flags_[index]; |
| 178 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 179 | |
| 180 | // For the given global index, return index |
| 181 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromGlobalIndex(const uint32_t global_index) const { |
| 182 | auto start_it = global_start_to_index_map_.upper_bound(global_index); |
| 183 | uint32_t index = binding_count_; |
| 184 | assert(start_it != global_start_to_index_map_.cbegin()); |
| 185 | if (start_it != global_start_to_index_map_.cbegin()) { |
| 186 | --start_it; |
| 187 | index = start_it->second; |
| 188 | #ifndef NDEBUG |
| 189 | const auto &range = GetGlobalIndexRangeFromBinding(bindings_[index].binding); |
| 190 | assert(range.start <= global_index && global_index < range.end); |
| 191 | #endif |
| 192 | } |
| 193 | return index; |
| 194 | } |
| 195 | |
| 196 | // For the given binding, return the global index range |
| 197 | // As start and end are often needed in pairs, get both with a single hash lookup. |
| 198 | const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding( |
| 199 | const uint32_t binding) const { |
| 200 | assert(binding_to_global_index_range_map_.count(binding)); |
| 201 | // In error case max uint32_t so index is out of bounds to break ASAP |
| 202 | const static IndexRange kInvalidRange = {0xFFFFFFFF, 0xFFFFFFFF}; |
| 203 | const auto &range_it = binding_to_global_index_range_map_.find(binding); |
| 204 | if (range_it != binding_to_global_index_range_map_.end()) { |
| 205 | return range_it->second; |
| 206 | } |
| 207 | return kInvalidRange; |
| 208 | } |
| 209 | |
| 210 | // For given binding, return ptr to ImmutableSampler array |
| 211 | VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const { |
| 212 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 213 | if (bi_itr != binding_to_index_map_.end()) { |
| 214 | return bindings_[bi_itr->second].pImmutableSamplers; |
| 215 | } |
| 216 | return nullptr; |
| 217 | } |
| 218 | // Move to next valid binding having a non-zero binding count |
| 219 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const { |
| 220 | auto it = non_empty_bindings_.upper_bound(binding); |
| 221 | assert(it != non_empty_bindings_.cend()); |
| 222 | if (it != non_empty_bindings_.cend()) return *it; |
| 223 | return GetMaxBinding() + 1; |
| 224 | } |
| 225 | // For given index, return ptr to ImmutableSampler array |
| 226 | VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 227 | if (index < bindings_.size()) { |
| 228 | return bindings_[index].pImmutableSamplers; |
| 229 | } |
| 230 | return nullptr; |
| 231 | } |
| 232 | // If our layout is compatible with rh_ds_layout, return true, |
| 233 | // else return false and fill in error_msg will description of what causes incompatibility |
| 234 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *const rh_ds_layout, |
| 235 | std::string *error_msg) const { |
| 236 | // Trivial case |
| 237 | if (layout_ == rh_ds_layout->GetDescriptorSetLayout()) return true; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 238 | if (GetLayoutDef() == rh_ds_layout->GetLayoutDef()) return true; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 239 | bool detailed_compat_check = |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 240 | GetLayoutDef()->IsCompatible(layout_, rh_ds_layout->GetDescriptorSetLayout(), rh_ds_layout->GetLayoutDef(), error_msg); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 241 | // The detailed check should never tell us mismatching DSL are compatible |
| 242 | assert(!detailed_compat_check); |
| 243 | return detailed_compat_check; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 244 | } |
| 245 | |
John Zulauf | df3c5c1 | 2018-03-06 16:44:43 -0700 | [diff] [blame] | 246 | // Do a detailed compatibility check of this def (referenced by ds_layout), vs. the rhs (layout and def) |
| 247 | // Should only be called if trivial accept has failed, and in that context should return false. |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 248 | bool cvdescriptorset::DescriptorSetLayoutDef::IsCompatible(VkDescriptorSetLayout ds_layout, VkDescriptorSetLayout rh_ds_layout, |
| 249 | DescriptorSetLayoutDef const *const rh_ds_layout_def, |
| 250 | std::string *error_msg) const { |
| 251 | if (descriptor_count_ != rh_ds_layout_def->descriptor_count_) { |
| 252 | std::stringstream error_str; |
| 253 | error_str << "DescriptorSetLayout " << ds_layout << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout " |
| 254 | << rh_ds_layout << ", which comes from pipelineLayout, has " << rh_ds_layout_def->descriptor_count_ |
| 255 | << " descriptors."; |
| 256 | *error_msg = error_str.str(); |
| 257 | return false; // trivial fail case |
| 258 | } |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 259 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 260 | // Descriptor counts match so need to go through bindings one-by-one |
| 261 | // and verify that type and stageFlags match |
| 262 | for (auto binding : bindings_) { |
| 263 | // TODO : Do we also need to check immutable samplers? |
| 264 | // VkDescriptorSetLayoutBinding *rh_binding; |
| 265 | if (binding.descriptorCount != rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding)) { |
| 266 | std::stringstream error_str; |
| 267 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " has a descriptorCount of " |
| 268 | << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout " |
| 269 | << rh_ds_layout << ", which comes from pipelineLayout, has a descriptorCount of " |
| 270 | << rh_ds_layout_def->GetDescriptorCountFromBinding(binding.binding); |
| 271 | *error_msg = error_str.str(); |
| 272 | return false; |
| 273 | } else if (binding.descriptorType != rh_ds_layout_def->GetTypeFromBinding(binding.binding)) { |
| 274 | std::stringstream error_str; |
| 275 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " is type '" |
| 276 | << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding |
| 277 | << " for DescriptorSetLayout " << rh_ds_layout << ", which comes from pipelineLayout, is type '" |
| 278 | << string_VkDescriptorType(rh_ds_layout_def->GetTypeFromBinding(binding.binding)) << "'"; |
| 279 | *error_msg = error_str.str(); |
| 280 | return false; |
| 281 | } else if (binding.stageFlags != rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding)) { |
| 282 | std::stringstream error_str; |
| 283 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << ds_layout << " has stageFlags " |
| 284 | << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " << rh_ds_layout |
| 285 | << ", which comes from pipelineLayout, has stageFlags " |
| 286 | << rh_ds_layout_def->GetStageFlagsFromBinding(binding.binding); |
| 287 | *error_msg = error_str.str(); |
| 288 | return false; |
| 289 | } |
| 290 | } |
| 291 | return true; |
| 292 | } |
| 293 | |
| 294 | bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const { |
| 295 | if (!binding_to_index_map_.count(binding + 1)) return false; |
| 296 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 297 | if (bi_itr != binding_to_index_map_.end()) { |
| 298 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 299 | if (next_bi_itr != binding_to_index_map_.end()) { |
| 300 | auto type = bindings_[bi_itr->second].descriptorType; |
| 301 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 302 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 303 | auto flags = binding_flags_[bi_itr->second]; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 304 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 305 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 306 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) || |
| 307 | (flags != binding_flags_[next_bi_itr->second])) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | return true; |
| 311 | } |
| 312 | } |
| 313 | return false; |
| 314 | } |
| 315 | // Starting at offset descriptor of given binding, parse over update_count |
| 316 | // descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent |
| 317 | // Consistency means that their type, stage flags, and whether or not they use immutable samplers matches |
| 318 | // If so, return true. If not, fill in error_msg and return false |
| 319 | bool cvdescriptorset::DescriptorSetLayoutDef::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, |
| 320 | uint32_t update_count, const char *type, |
| 321 | const VkDescriptorSet set, std::string *error_msg) const { |
| 322 | // Verify consecutive bindings match (if needed) |
| 323 | auto orig_binding = current_binding; |
| 324 | // Track count of descriptors in the current_bindings that are remaining to be updated |
| 325 | auto binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 326 | // First, it's legal to offset beyond your own binding so handle that case |
| 327 | // Really this is just searching for the binding in which the update begins and adjusting offset accordingly |
| 328 | while (offset >= binding_remaining) { |
| 329 | // Advance to next binding, decrement offset by binding size |
| 330 | offset -= binding_remaining; |
| 331 | binding_remaining = GetDescriptorCountFromBinding(++current_binding); |
| 332 | } |
| 333 | binding_remaining -= offset; |
| 334 | while (update_count > binding_remaining) { // While our updates overstep current binding |
| 335 | // Verify next consecutive binding matches type, stage flags & immutable sampler use |
| 336 | if (!IsNextBindingConsistent(current_binding++)) { |
| 337 | std::stringstream error_str; |
| 338 | error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #" |
| 339 | << update_count |
| 340 | << " descriptors being updated but this update oversteps the bounds of this binding and the next binding is " |
| 341 | "not consistent with current binding so this update is invalid."; |
| 342 | *error_msg = error_str.str(); |
| 343 | return false; |
| 344 | } |
| 345 | // For sake of this check consider the bindings updated and grab count for next binding |
| 346 | update_count -= binding_remaining; |
| 347 | binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 348 | } |
| 349 | return true; |
| 350 | } |
| 351 | |
| 352 | // The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the |
| 353 | // handle invariant portion |
| 354 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, |
| 355 | const VkDescriptorSetLayout layout) |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 356 | : layout_(layout), layout_destroyed_(false), layout_id_(GetCanonicalId(p_create_info)) {} |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 357 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 358 | // Validate descriptor set layout create info |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 359 | bool cvdescriptorset::DescriptorSetLayout::ValidateCreateInfo( |
| 360 | const debug_report_data *report_data, const VkDescriptorSetLayoutCreateInfo *create_info, const bool push_descriptor_ext, |
| 361 | const uint32_t max_push_descriptors, const bool descriptor_indexing_ext, |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 362 | const VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features, |
| 363 | const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features, |
| 364 | const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props) { |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 365 | bool skip = false; |
| 366 | std::unordered_set<uint32_t> bindings; |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 367 | uint64_t total_descriptors = 0; |
| 368 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 369 | const auto *flags_create_info = lvl_find_in_chain<VkDescriptorSetLayoutBindingFlagsCreateInfoEXT>(create_info->pNext); |
| 370 | |
| 371 | const bool push_descriptor_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 372 | if (push_descriptor_set && !push_descriptor_ext) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 373 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 374 | kVUID_Core_DrawState_ExtensionNotEnabled, |
Mark Lobodzinski | fb5a3e6 | 2018-04-13 10:46:48 -0600 | [diff] [blame] | 375 | "Attempted to use %s in %s but its required extension %s has not been enabled.\n", |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 376 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR", "VkDescriptorSetLayoutCreateInfo::flags", |
| 377 | VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); |
| 378 | } |
| 379 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 380 | const bool update_after_bind_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT); |
| 381 | if (update_after_bind_set && !descriptor_indexing_ext) { |
| 382 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 383 | kVUID_Core_DrawState_ExtensionNotEnabled, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 384 | "Attemped to use %s in %s but its required extension %s has not been enabled.\n", |
| 385 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT", "VkDescriptorSetLayoutCreateInfo::flags", |
| 386 | VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME); |
| 387 | } |
| 388 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 389 | auto valid_type = [push_descriptor_set](const VkDescriptorType type) { |
| 390 | return !push_descriptor_set || |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 391 | ((type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) && (type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) && |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 392 | (type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 395 | uint32_t max_binding = 0; |
| 396 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 397 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 398 | const auto &binding_info = create_info->pBindings[i]; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 399 | max_binding = std::max(max_binding, binding_info.binding); |
| 400 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 401 | if (!bindings.insert(binding_info.binding).second) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 402 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 403 | "VUID-VkDescriptorSetLayoutCreateInfo-binding-00279", |
| 404 | "duplicated binding number in VkDescriptorSetLayoutBinding."); |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 405 | } |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 406 | if (!valid_type(binding_info.descriptorType)) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 407 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 408 | (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) |
| 409 | ? "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208" |
| 410 | : "VUID-VkDescriptorSetLayoutCreateInfo-flags-00280", |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 411 | "invalid type %s ,for push descriptors in VkDescriptorSetLayoutBinding entry %" PRIu32 ".", |
| 412 | string_VkDescriptorType(binding_info.descriptorType), i); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 413 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 414 | |
| 415 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
| 416 | if ((binding_info.descriptorCount % 4) != 0) { |
| 417 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 418 | "VUID-VkDescriptorSetLayoutBinding-descriptorType-02209", |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 419 | "descriptorCount =(%" PRIu32 ") must be a multiple of 4", binding_info.descriptorCount); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 420 | } |
| 421 | if (binding_info.descriptorCount > inline_uniform_block_props->maxInlineUniformBlockSize) { |
| 422 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 423 | "VUID-VkDescriptorSetLayoutBinding-descriptorType-02210", |
| 424 | "descriptorCount =(%" PRIu32 ") must be less than or equal to maxInlineUniformBlockSize", |
| 425 | binding_info.descriptorCount); |
| 426 | } |
| 427 | } |
| 428 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 429 | total_descriptors += binding_info.descriptorCount; |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 430 | } |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 431 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 432 | if (flags_create_info) { |
| 433 | if (flags_create_info->bindingCount != 0 && flags_create_info->bindingCount != create_info->bindingCount) { |
| 434 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 435 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-bindingCount-03002", |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 436 | "VkDescriptorSetLayoutCreateInfo::bindingCount (%d) != " |
| 437 | "VkDescriptorSetLayoutBindingFlagsCreateInfoEXT::bindingCount (%d)", |
| 438 | create_info->bindingCount, flags_create_info->bindingCount); |
| 439 | } |
| 440 | |
| 441 | if (flags_create_info->bindingCount == create_info->bindingCount) { |
| 442 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
| 443 | const auto &binding_info = create_info->pBindings[i]; |
| 444 | |
| 445 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT) { |
| 446 | if (!update_after_bind_set) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 447 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 448 | "VUID-VkDescriptorSetLayoutCreateInfo-flags-03000", |
| 449 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER && |
| 453 | !descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 454 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 455 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 456 | "descriptorBindingUniformBufferUpdateAfterBind-03005", |
| 457 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 458 | } |
| 459 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || |
| 460 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || |
| 461 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) && |
| 462 | !descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 463 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 464 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 465 | "descriptorBindingSampledImageUpdateAfterBind-03006", |
| 466 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 467 | } |
| 468 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE && |
| 469 | !descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 470 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 471 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 472 | "descriptorBindingStorageImageUpdateAfterBind-03007", |
| 473 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 474 | } |
| 475 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER && |
| 476 | !descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 477 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 478 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 479 | "descriptorBindingStorageBufferUpdateAfterBind-03008", |
| 480 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 481 | } |
| 482 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER && |
| 483 | !descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 484 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 485 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 486 | "descriptorBindingUniformTexelBufferUpdateAfterBind-03009", |
| 487 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 488 | } |
| 489 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER && |
| 490 | !descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 491 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 492 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 493 | "descriptorBindingStorageTexelBufferUpdateAfterBind-03010", |
| 494 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 495 | } |
| 496 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT || |
| 497 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 498 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 499 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 500 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-None-03011", |
| 501 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 502 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 503 | |
| 504 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT && |
| 505 | !inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind) { |
| 506 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 507 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-" |
| 508 | "descriptorBindingInlineUniformBlockUpdateAfterBind-02211", |
| 509 | "Invalid flags (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT) for " |
| 510 | "VkDescriptorSetLayoutBinding entry %" PRIu32 |
| 511 | " with descriptorBindingInlineUniformBlockUpdateAfterBind not enabled", |
| 512 | i); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 513 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT) { |
| 517 | if (!descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 518 | skip |= log_msg( |
| 519 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 520 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingUpdateUnusedWhilePending-03012", |
| 521 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT) { |
| 526 | if (!descriptor_indexing_features->descriptorBindingPartiallyBound) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 527 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 528 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingPartiallyBound-03013", |
| 529 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT) { |
| 534 | if (binding_info.binding != max_binding) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 535 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 536 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03004", |
| 537 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | if (!descriptor_indexing_features->descriptorBindingVariableDescriptorCount) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 541 | skip |= log_msg( |
| 542 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 543 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-descriptorBindingVariableDescriptorCount-03014", |
| 544 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 545 | } |
| 546 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 547 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 548 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 549 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-pBindingFlags-03015", |
| 550 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | if (push_descriptor_set && |
| 555 | (flags_create_info->pBindingFlags[i] & |
| 556 | (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | |
| 557 | VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT))) { |
| 558 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 559 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfoEXT-flags-03003", |
| 560 | "Invalid flags for VkDescriptorSetLayoutBinding entry %" PRIu32, i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 566 | if ((push_descriptor_set) && (total_descriptors > max_push_descriptors)) { |
| 567 | const char *undefined = push_descriptor_ext ? "" : " -- undefined"; |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 568 | skip |= |
| 569 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 570 | "VUID-VkDescriptorSetLayoutCreateInfo-flags-00281", |
| 571 | "for push descriptor, total descriptor count in layout (%" PRIu64 |
| 572 | ") must not be greater than VkPhysicalDevicePushDescriptorPropertiesKHR::maxPushDescriptors (%" PRIu32 "%s).", |
| 573 | total_descriptors, max_push_descriptors, undefined); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 576 | return skip; |
| 577 | } |
| 578 | |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 579 | cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count) |
| 580 | : required_descriptors_by_type{}, layout_nodes(count, nullptr) {} |
| 581 | |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 582 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 583 | const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count, |
| 584 | layer_data *dev_data) |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 585 | : some_update_(false), |
| 586 | set_(set), |
| 587 | pool_state_(nullptr), |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 588 | p_layout_(layout), |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 589 | device_data_(dev_data), |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 590 | limits_(GetPhysDevProperties(dev_data)->properties.limits), |
| 591 | variable_count_(variable_count) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 592 | pool_state_ = GetDescriptorPoolState(dev_data, pool); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 593 | // Foreach binding, create default descriptors of given type |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 594 | descriptors_.reserve(p_layout_->GetTotalDescriptorCount()); |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 595 | for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) { |
| 596 | auto type = p_layout_->GetTypeFromIndex(i); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 597 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 598 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 599 | auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 600 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 601 | if (immut_sampler) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 602 | descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di)); |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 603 | some_update_ = true; // Immutable samplers are updated at creation |
| 604 | } else |
Chris Forbes | 9f34085 | 2017-05-09 08:51:38 -0700 | [diff] [blame] | 605 | descriptors_.emplace_back(new SamplerDescriptor(nullptr)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 606 | } |
| 607 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 608 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 609 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 610 | auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 611 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 612 | if (immut) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 613 | descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di)); |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 614 | some_update_ = true; // Immutable samplers are updated at creation |
| 615 | } else |
Chris Forbes | 9f34085 | 2017-05-09 08:51:38 -0700 | [diff] [blame] | 616 | descriptors_.emplace_back(new ImageSamplerDescriptor(nullptr)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 617 | } |
| 618 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 619 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 620 | // ImageDescriptors |
| 621 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 622 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 623 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 624 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 625 | descriptors_.emplace_back(new ImageDescriptor(type)); |
| 626 | break; |
| 627 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 628 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 629 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 630 | descriptors_.emplace_back(new TexelDescriptor(type)); |
| 631 | break; |
| 632 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 633 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 634 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 635 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 636 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 637 | descriptors_.emplace_back(new BufferDescriptor(type)); |
| 638 | break; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 639 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: |
| 640 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
| 641 | descriptors_.emplace_back(new InlineUniformDescriptor(type)); |
| 642 | break; |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 643 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NVX: |
| 644 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
| 645 | descriptors_.emplace_back(new AccelerationStructureDescriptor(type)); |
| 646 | break; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 647 | default: |
| 648 | assert(0); // Bad descriptor type specified |
| 649 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 653 | |
Mark Lobodzinski | 729a8d3 | 2017-01-26 12:16:30 -0700 | [diff] [blame] | 654 | cvdescriptorset::DescriptorSet::~DescriptorSet() { InvalidateBoundCmdBuffers(); } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 655 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 656 | static std::string StringDescriptorReqViewType(descriptor_req req) { |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 657 | std::string result(""); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 658 | for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) { |
| 659 | if (req & (1 << i)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 660 | if (result.size()) result += ", "; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 661 | result += string_VkImageViewType(VkImageViewType(i)); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 665 | if (!result.size()) result = "(none)"; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 666 | |
| 667 | return result; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 668 | } |
| 669 | |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 670 | static char const *StringDescriptorReqComponentType(descriptor_req req) { |
| 671 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT"; |
| 672 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT"; |
| 673 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT"; |
| 674 | return "(none)"; |
| 675 | } |
| 676 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 677 | // Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec? |
Tobin Ehlis | 6dc57dd | 2017-06-21 10:08:52 -0600 | [diff] [blame] | 678 | bool cvdescriptorset::DescriptorSet::IsCompatible(DescriptorSetLayout const *const layout, std::string *error) const { |
| 679 | return layout->IsCompatible(p_layout_.get(), error); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 680 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 681 | |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 682 | static unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) { |
| 683 | if (FormatIsSInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT; |
| 684 | if (FormatIsUInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT; |
| 685 | if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT; |
| 686 | if (fmt == VK_FORMAT_UNDEFINED) return 0; |
| 687 | // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader. |
| 688 | return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT; |
| 689 | } |
| 690 | |
Tobin Ehlis | 3066db6 | 2016-08-22 08:12:23 -0600 | [diff] [blame] | 691 | // 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] | 692 | // This includes validating that all descriptors in the given bindings are updated, |
| 693 | // that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers. |
| 694 | // Return true if state is acceptable, or false and write an error message into error string |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 695 | bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings, |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 696 | const std::vector<uint32_t> &dynamic_offsets, GLOBAL_CB_NODE *cb_node, |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 697 | const char *caller, std::string *error) const { |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 698 | for (auto binding_pair : bindings) { |
| 699 | auto binding = binding_pair.first; |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 700 | if (!p_layout_->HasBinding(binding)) { |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 701 | std::stringstream error_str; |
| 702 | error_str << "Attempting to validate DrawState for binding #" << binding |
| 703 | << " which is an invalid binding for this descriptor set."; |
| 704 | *error = error_str.str(); |
| 705 | return false; |
| 706 | } |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 707 | IndexRange index_range = p_layout_->GetGlobalIndexRangeFromBinding(binding); |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 708 | auto array_idx = 0; // Track array idx if we're dealing with array descriptors |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 709 | |
| 710 | if (IsVariableDescriptorCount(binding)) { |
| 711 | // Only validate the first N descriptors if it uses variable_count |
| 712 | index_range.end = index_range.start + GetVariableDescriptorCount(); |
| 713 | } |
| 714 | |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 715 | for (uint32_t i = index_range.start; i < index_range.end; ++i, ++array_idx) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 716 | if ((p_layout_->GetDescriptorBindingFlagsFromBinding(binding) & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT_EXT) || |
| 717 | descriptors_[i]->GetClass() == InlineUniform) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 718 | // Can't validate the descriptor because it may not have been updated, |
| 719 | // or the view could have been destroyed |
| 720 | continue; |
| 721 | } else if (!descriptors_[i]->updated) { |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 722 | std::stringstream error_str; |
| 723 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 724 | << " is being used in draw but has not been updated."; |
| 725 | *error = error_str.str(); |
| 726 | return false; |
| 727 | } else { |
| 728 | auto descriptor_class = descriptors_[i]->GetClass(); |
| 729 | if (descriptor_class == GeneralBuffer) { |
| 730 | // Verify that buffers are valid |
| 731 | auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer(); |
| 732 | auto buffer_node = GetBufferState(device_data_, buffer); |
| 733 | if (!buffer_node) { |
| 734 | std::stringstream error_str; |
| 735 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 736 | << " references invalid buffer " << buffer << "."; |
| 737 | *error = error_str.str(); |
| 738 | return false; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 739 | } else if (!buffer_node->sparse) { |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 740 | for (auto mem_binding : buffer_node->GetBoundMemory()) { |
| 741 | if (!GetMemObjInfo(device_data_, mem_binding)) { |
| 742 | std::stringstream error_str; |
| 743 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 744 | << " uses buffer " << buffer << " that references invalid memory " << mem_binding << "."; |
| 745 | *error = error_str.str(); |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 746 | return false; |
| 747 | } |
| 748 | } |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 749 | } |
| 750 | if (descriptors_[i]->IsDynamic()) { |
| 751 | // Validate that dynamic offsets are within the buffer |
| 752 | auto buffer_size = buffer_node->createInfo.size; |
| 753 | auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange(); |
| 754 | auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset(); |
| 755 | auto dyn_offset = dynamic_offsets[GetDynamicOffsetIndexFromBinding(binding) + array_idx]; |
| 756 | if (VK_WHOLE_SIZE == range) { |
| 757 | if ((dyn_offset + desc_offset) > buffer_size) { |
| 758 | std::stringstream error_str; |
| 759 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 760 | << " uses buffer " << buffer << " with update range of VK_WHOLE_SIZE has dynamic offset " |
| 761 | << dyn_offset << " combined with offset " << desc_offset |
| 762 | << " that oversteps the buffer size of " << buffer_size << "."; |
| 763 | *error = error_str.str(); |
| 764 | return false; |
| 765 | } |
| 766 | } else { |
| 767 | if ((dyn_offset + desc_offset + range) > buffer_size) { |
| 768 | std::stringstream error_str; |
| 769 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 770 | << " uses buffer " << buffer << " with dynamic offset " << dyn_offset |
| 771 | << " combined with offset " << desc_offset << " and range " << range |
| 772 | << " that oversteps the buffer size of " << buffer_size << "."; |
| 773 | *error = error_str.str(); |
| 774 | return false; |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | } else if (descriptor_class == ImageSampler || descriptor_class == Image) { |
| 779 | VkImageView image_view; |
| 780 | VkImageLayout image_layout; |
| 781 | if (descriptor_class == ImageSampler) { |
| 782 | image_view = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView(); |
| 783 | image_layout = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageLayout(); |
| 784 | } else { |
| 785 | image_view = static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView(); |
| 786 | image_layout = static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageLayout(); |
| 787 | } |
| 788 | auto reqs = binding_pair.second; |
| 789 | |
| 790 | auto image_view_state = GetImageViewState(device_data_, image_view); |
Tobin Ehlis | 836a137 | 2017-07-14 11:25:21 -0600 | [diff] [blame] | 791 | if (nullptr == image_view_state) { |
| 792 | // Image view must have been destroyed since initial update. Could potentially flag the descriptor |
| 793 | // as "invalid" (updated = false) at DestroyImageView() time and detect this error at bind time |
| 794 | std::stringstream error_str; |
| 795 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 796 | << " is using imageView " << image_view << " that has been destroyed."; |
| 797 | *error = error_str.str(); |
| 798 | return false; |
| 799 | } |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 800 | auto image_view_ci = image_view_state->create_info; |
| 801 | |
| 802 | if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) { |
| 803 | // bad view type |
| 804 | std::stringstream error_str; |
| 805 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 806 | << " requires an image view of type " << StringDescriptorReqViewType(reqs) << " but got " |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 807 | << string_VkImageViewType(image_view_ci.viewType) << "."; |
| 808 | *error = error_str.str(); |
| 809 | return false; |
| 810 | } |
| 811 | |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 812 | auto format_bits = DescriptorRequirementsBitsFromFormat(image_view_ci.format); |
| 813 | if (!(reqs & format_bits)) { |
| 814 | // bad component type |
| 815 | std::stringstream error_str; |
| 816 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i << " requires " |
| 817 | << StringDescriptorReqComponentType(reqs) << " component type, but bound descriptor format is " |
| 818 | << string_VkFormat(image_view_ci.format) << "."; |
| 819 | *error = error_str.str(); |
| 820 | return false; |
| 821 | } |
| 822 | |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 823 | auto image_node = GetImageState(device_data_, image_view_ci.image); |
| 824 | assert(image_node); |
| 825 | // Verify Image Layout |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 826 | // Copy first mip level into sub_layers and loop over each mip level to verify layout |
| 827 | VkImageSubresourceLayers sub_layers; |
| 828 | sub_layers.aspectMask = image_view_ci.subresourceRange.aspectMask; |
| 829 | sub_layers.baseArrayLayer = image_view_ci.subresourceRange.baseArrayLayer; |
| 830 | sub_layers.layerCount = image_view_ci.subresourceRange.layerCount; |
| 831 | bool hit_error = false; |
| 832 | for (auto cur_level = image_view_ci.subresourceRange.baseMipLevel; |
| 833 | cur_level < image_view_ci.subresourceRange.levelCount; ++cur_level) { |
| 834 | sub_layers.mipLevel = cur_level; |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 835 | // No "invalid layout" VUID required for this call, since the optimal_layout parameter is UNDEFINED. |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 836 | VerifyImageLayout(device_data_, cb_node, image_node, sub_layers, image_layout, VK_IMAGE_LAYOUT_UNDEFINED, |
Cort Stratton | 7df3096 | 2018-05-17 19:45:57 -0700 | [diff] [blame] | 837 | caller, kVUIDUndefined, "VUID-VkDescriptorImageInfo-imageLayout-00344", &hit_error); |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 838 | if (hit_error) { |
| 839 | *error = |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 840 | "Image layout specified at vkUpdateDescriptorSets() time doesn't match actual image layout at time " |
| 841 | "descriptor is used. See previous error callback for specific details."; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 842 | return false; |
| 843 | } |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 844 | } |
| 845 | // Verify Sample counts |
| 846 | if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 847 | std::stringstream error_str; |
| 848 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 849 | << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got " |
| 850 | << string_VkSampleCountFlagBits(image_node->createInfo.samples) << "."; |
| 851 | *error = error_str.str(); |
| 852 | return false; |
| 853 | } |
| 854 | if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 855 | std::stringstream error_str; |
| 856 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 857 | << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT."; |
| 858 | *error = error_str.str(); |
| 859 | return false; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 860 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 861 | } |
Tobin Ehlis | b1a2e4b | 2018-03-16 07:54:24 -0600 | [diff] [blame] | 862 | if (descriptor_class == ImageSampler || descriptor_class == PlainSampler) { |
| 863 | // Verify Sampler still valid |
| 864 | VkSampler sampler; |
| 865 | if (descriptor_class == ImageSampler) { |
| 866 | sampler = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetSampler(); |
| 867 | } else { |
| 868 | sampler = static_cast<SamplerDescriptor *>(descriptors_[i].get())->GetSampler(); |
| 869 | } |
| 870 | if (!ValidateSampler(sampler, device_data_)) { |
| 871 | std::stringstream error_str; |
| 872 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 873 | << " is using sampler " << sampler << " that has been destroyed."; |
| 874 | *error = error_str.str(); |
| 875 | return false; |
| 876 | } |
| 877 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | } |
| 881 | return true; |
| 882 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 883 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 884 | // For given bindings, place any update buffers or images into the passed-in unordered_sets |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 885 | uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 886 | std::unordered_set<VkBuffer> *buffer_set, |
| 887 | std::unordered_set<VkImageView> *image_set) const { |
| 888 | auto num_updates = 0; |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 889 | for (auto binding_pair : bindings) { |
| 890 | auto binding = binding_pair.first; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 891 | // If a binding doesn't exist, skip it |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 892 | if (!p_layout_->HasBinding(binding)) { |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 893 | continue; |
| 894 | } |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 895 | uint32_t start_idx = p_layout_->GetGlobalIndexRangeFromBinding(binding).start; |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 896 | if (descriptors_[start_idx]->IsStorage()) { |
| 897 | if (Image == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 898 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 899 | if (descriptors_[start_idx + i]->updated) { |
| 900 | image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 901 | num_updates++; |
| 902 | } |
| 903 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 904 | } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 905 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 906 | if (descriptors_[start_idx + i]->updated) { |
| 907 | auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 908 | auto bv_state = GetBufferViewState(device_data_, bufferview); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 909 | if (bv_state) { |
| 910 | buffer_set->insert(bv_state->create_info.buffer); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 911 | num_updates++; |
| 912 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 913 | } |
| 914 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 915 | } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 916 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 917 | if (descriptors_[start_idx + i]->updated) { |
| 918 | buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 919 | num_updates++; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | return num_updates; |
| 926 | } |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 927 | // Set is being deleted or updates so invalidate all bound cmd buffers |
| 928 | void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 929 | core_validation::InvalidateCommandBuffers(device_data_, cb_bindings, {HandleToUint64(set_), kVulkanObjectTypeDescriptorSet}); |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 930 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 931 | // Perform write update in given update struct |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 932 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) { |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 933 | // Perform update on a per-binding basis as consecutive updates roll over to next binding |
| 934 | auto descriptors_remaining = update->descriptorCount; |
| 935 | auto binding_being_updated = update->dstBinding; |
| 936 | auto offset = update->dstArrayElement; |
Tobin Ehlis | e16805c | 2017-08-09 09:10:37 -0600 | [diff] [blame] | 937 | uint32_t update_index = 0; |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 938 | while (descriptors_remaining) { |
| 939 | uint32_t update_count = std::min(descriptors_remaining, GetDescriptorCountFromBinding(binding_being_updated)); |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 940 | auto global_idx = p_layout_->GetGlobalIndexRangeFromBinding(binding_being_updated).start + offset; |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 941 | // Loop over the updates for a single binding at a time |
Tobin Ehlis | e16805c | 2017-08-09 09:10:37 -0600 | [diff] [blame] | 942 | for (uint32_t di = 0; di < update_count; ++di, ++update_index) { |
| 943 | descriptors_[global_idx + di]->WriteUpdate(update, update_index); |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 944 | } |
| 945 | // Roll over to next binding in case of consecutive update |
| 946 | descriptors_remaining -= update_count; |
| 947 | offset = 0; |
| 948 | binding_being_updated++; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 949 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 950 | if (update->descriptorCount) some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 951 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 952 | if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
| 953 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) { |
| 954 | InvalidateBoundCmdBuffers(); |
| 955 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 956 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 957 | // Validate Copy update |
| 958 | bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 959 | const DescriptorSet *src_set, std::string *error_code, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 960 | std::string *error_msg) { |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 961 | // Verify dst layout still valid |
| 962 | if (p_layout_->IsDestroyed()) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 963 | *error_code = "VUID-VkCopyDescriptorSet-dstSet-parameter"; |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 964 | string_sprintf(error_msg, |
| 965 | "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set dstSet 0x%" PRIxLEAST64 |
| 966 | " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64, |
| 967 | HandleToUint64(set_), HandleToUint64(p_layout_->GetDescriptorSetLayout())); |
| 968 | return false; |
| 969 | } |
| 970 | |
| 971 | // Verify src layout still valid |
| 972 | if (src_set->p_layout_->IsDestroyed()) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 973 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-parameter"; |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 974 | string_sprintf( |
| 975 | error_msg, |
| 976 | "Cannot call vkUpdateDescriptorSets() to perform copy update of dstSet 0x%" PRIxLEAST64 |
| 977 | " from descriptor set srcSet 0x%" PRIxLEAST64 " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64, |
| 978 | HandleToUint64(set_), HandleToUint64(src_set->set_), HandleToUint64(src_set->p_layout_->GetDescriptorSetLayout())); |
| 979 | return false; |
| 980 | } |
| 981 | |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 982 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 983 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-00347"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 984 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 985 | error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 986 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 987 | return false; |
| 988 | } |
| 989 | if (!src_set->HasBinding(update->srcBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 990 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-00345"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 991 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 992 | error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 993 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 994 | return false; |
| 995 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 996 | // Verify idle ds |
| 997 | if (in_use.load() && |
| 998 | !(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
| 999 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) { |
| 1000 | // TODO : Re-using Free Idle error code, need copy update idle error code |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1001 | *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1002 | std::stringstream error_str; |
| 1003 | error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_ |
| 1004 | << " that is in use by a command buffer"; |
| 1005 | *error_msg = error_str.str(); |
| 1006 | return false; |
| 1007 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1008 | // src & dst set bindings are valid |
| 1009 | // Check bounds of src & dst |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1010 | auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1011 | if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) { |
| 1012 | // SRC update out of bounds |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1013 | *error_code = "VUID-VkCopyDescriptorSet-srcArrayElement-00346"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1014 | std::stringstream error_str; |
| 1015 | error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1016 | << " with offset index of " << src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1017 | << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1018 | << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1019 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1020 | return false; |
| 1021 | } |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1022 | auto dst_start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement; |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1023 | if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1024 | // DST update out of bounds |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1025 | *error_code = "VUID-VkCopyDescriptorSet-dstArrayElement-00348"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1026 | std::stringstream error_str; |
| 1027 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1028 | << " with offset index of " << p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1029 | << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1030 | << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1031 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | // Check that types match |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1035 | // TODO : Base default error case going from here is "VUID-VkAcquireNextImageInfoKHR-semaphore-parameter"2ba which covers all |
| 1036 | // consistency issues, need more fine-grained error codes |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1037 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-00349"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1038 | auto src_type = src_set->GetTypeFromBinding(update->srcBinding); |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1039 | auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1040 | if (src_type != dst_type) { |
| 1041 | std::stringstream error_str; |
| 1042 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type " |
| 1043 | << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #" |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1044 | << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1045 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1046 | return false; |
| 1047 | } |
| 1048 | // Verify consistency of src & dst bindings if update crosses binding boundaries |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 1049 | if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1050 | "copy update from", src_set->GetSet(), error_msg)) || |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1051 | (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1052 | set_, error_msg))) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1053 | return false; |
| 1054 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1055 | |
| 1056 | if ((src_set->GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) && |
| 1057 | !(GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1058 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01918"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1059 | std::stringstream error_str; |
| 1060 | error_str << "If pname:srcSet's (" << update->srcSet |
| 1061 | << ") layout was created with the " |
| 1062 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag " |
| 1063 | "set, then pname:dstSet's (" |
| 1064 | << update->dstSet |
| 1065 | << ") layout must: also have been created with the " |
| 1066 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set"; |
| 1067 | *error_msg = error_str.str(); |
| 1068 | return false; |
| 1069 | } |
| 1070 | |
| 1071 | if (!(src_set->GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT) && |
| 1072 | (GetLayout()->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1073 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01919"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1074 | std::stringstream error_str; |
| 1075 | error_str << "If pname:srcSet's (" << update->srcSet |
| 1076 | << ") layout was created without the " |
| 1077 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag " |
| 1078 | "set, then pname:dstSet's (" |
| 1079 | << update->dstSet |
| 1080 | << ") layout must: also have been created without the " |
| 1081 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT flag set"; |
| 1082 | *error_msg = error_str.str(); |
| 1083 | return false; |
| 1084 | } |
| 1085 | |
| 1086 | if ((src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) && |
| 1087 | !(GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1088 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01920"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1089 | std::stringstream error_str; |
| 1090 | error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet |
| 1091 | << ") was allocated was created " |
| 1092 | "with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag " |
| 1093 | "set, then the descriptor pool from which pname:dstSet (" |
| 1094 | << update->dstSet |
| 1095 | << ") was allocated must: " |
| 1096 | "also have been created with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set"; |
| 1097 | *error_msg = error_str.str(); |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | if (!(src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT) && |
| 1102 | (GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1103 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01921"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1104 | std::stringstream error_str; |
| 1105 | error_str << "If the descriptor pool from which pname:srcSet (" << update->srcSet |
| 1106 | << ") was allocated was created " |
| 1107 | "without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag " |
| 1108 | "set, then the descriptor pool from which pname:dstSet (" |
| 1109 | << update->dstSet |
| 1110 | << ") was allocated must: " |
| 1111 | "also have been created without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT flag set"; |
| 1112 | *error_msg = error_str.str(); |
| 1113 | return false; |
| 1114 | } |
| 1115 | |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1116 | if (src_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
| 1117 | if ((update->srcArrayElement % 4) != 0) { |
| 1118 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02223"; |
| 1119 | std::stringstream error_str; |
| 1120 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1121 | << "srcArrayElement " << update->srcArrayElement << " not a multiple of 4"; |
| 1122 | *error_msg = error_str.str(); |
| 1123 | return false; |
| 1124 | } |
| 1125 | if ((update->dstArrayElement % 4) != 0) { |
| 1126 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02224"; |
| 1127 | std::stringstream error_str; |
| 1128 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1129 | << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4"; |
| 1130 | *error_msg = error_str.str(); |
| 1131 | return false; |
| 1132 | } |
| 1133 | if ((update->descriptorCount % 4) != 0) { |
| 1134 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02225"; |
| 1135 | std::stringstream error_str; |
| 1136 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1137 | << "descriptorCount " << update->descriptorCount << " not a multiple of 4"; |
| 1138 | *error_msg = error_str.str(); |
| 1139 | return false; |
| 1140 | } |
| 1141 | } |
| 1142 | |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 1143 | // Update parameters all look good and descriptor updated so verify update contents |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1144 | if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg)) return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1145 | |
| 1146 | // All checks passed so update is good |
| 1147 | return true; |
| 1148 | } |
| 1149 | // Perform Copy update |
| 1150 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) { |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1151 | auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement; |
| 1152 | auto dst_start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1153 | // Update parameters all look good so perform update |
| 1154 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 1155 | auto src = src_set->descriptors_[src_start_idx + di].get(); |
| 1156 | auto dst = descriptors_[dst_start_idx + di].get(); |
| 1157 | if (src->updated) { |
| 1158 | dst->CopyUpdate(src); |
| 1159 | some_update_ = true; |
| 1160 | } else { |
| 1161 | dst->updated = false; |
| 1162 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1163 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1164 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1165 | if (!(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
| 1166 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) { |
| 1167 | InvalidateBoundCmdBuffers(); |
| 1168 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1169 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1170 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1171 | // Update the drawing state for the affected descriptors. |
| 1172 | // Set cb_node to this set and this set to cb_node. |
| 1173 | // Add the bindings of the descriptor |
| 1174 | // Set the layout based on the current descriptor layout (will mask subsequent layer mismatch errors) |
| 1175 | // TODO: Modify the UpdateDrawState virtural functions to *only* set initial layout and not change layouts |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 1176 | // Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going |
| 1177 | // to be used in a draw by the given cb_node |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1178 | void cvdescriptorset::DescriptorSet::UpdateDrawState(GLOBAL_CB_NODE *cb_node, |
| 1179 | const std::map<uint32_t, descriptor_req> &binding_req_map) { |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 1180 | // bind cb to this descriptor set |
| 1181 | cb_bindings.insert(cb_node); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 1182 | // Add bindings for descriptor set, the set's pool, and individual objects in the set |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1183 | cb_node->object_bindings.insert({HandleToUint64(set_), kVulkanObjectTypeDescriptorSet}); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 1184 | pool_state_->cb_bindings.insert(cb_node); |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1185 | cb_node->object_bindings.insert({HandleToUint64(pool_state_->pool), kVulkanObjectTypeDescriptorPool}); |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 1186 | // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's |
| 1187 | // resources |
Tobin Ehlis | 022528b | 2016-12-29 12:22:32 -0700 | [diff] [blame] | 1188 | for (auto binding_req_pair : binding_req_map) { |
| 1189 | auto binding = binding_req_pair.first; |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1190 | auto range = p_layout_->GetGlobalIndexRangeFromBinding(binding); |
| 1191 | for (uint32_t i = range.start; i < range.end; ++i) { |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1192 | descriptors_[i]->UpdateDrawState(device_data_, cb_node); |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 1193 | } |
| 1194 | } |
| 1195 | } |
| 1196 | |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1197 | void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, |
| 1198 | const BindingReqMap &in_req, BindingReqMap *out_req, |
| 1199 | TrackedBindings *bindings) { |
| 1200 | assert(out_req); |
| 1201 | assert(bindings); |
| 1202 | const auto binding = binding_req_pair.first; |
| 1203 | // Use insert and look at the boolean ("was inserted") in the returned pair to see if this is a new set member. |
| 1204 | // Saves one hash lookup vs. find ... compare w/ end ... insert. |
| 1205 | const auto it_bool_pair = bindings->insert(binding); |
| 1206 | if (it_bool_pair.second) { |
| 1207 | out_req->emplace(binding_req_pair); |
| 1208 | } |
| 1209 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 1210 | |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1211 | void cvdescriptorset::DescriptorSet::FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, |
| 1212 | const BindingReqMap &in_req, BindingReqMap *out_req, |
| 1213 | TrackedBindings *bindings, uint32_t limit) { |
| 1214 | if (bindings->size() < limit) FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, bindings); |
| 1215 | } |
| 1216 | |
| 1217 | void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(GLOBAL_CB_NODE *cb_state, const BindingReqMap &in_req, |
| 1218 | BindingReqMap *out_req) { |
| 1219 | TrackedBindings &bound = cached_validation_[cb_state].command_binding_and_usage; |
| 1220 | if (bound.size() == GetBindingCount()) { |
| 1221 | return; // All bindings are bound, out req is empty |
| 1222 | } |
| 1223 | for (const auto &binding_req_pair : in_req) { |
| 1224 | const auto binding = binding_req_pair.first; |
| 1225 | // If a binding doesn't exist, or has already been bound, skip it |
| 1226 | if (p_layout_->HasBinding(binding)) { |
| 1227 | FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, &bound); |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | void cvdescriptorset::DescriptorSet::FilterAndTrackBindingReqs(GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *pipeline, |
| 1233 | const BindingReqMap &in_req, BindingReqMap *out_req) { |
| 1234 | auto &validated = cached_validation_[cb_state]; |
| 1235 | auto &image_sample_val = validated.image_samplers[pipeline]; |
| 1236 | auto *const dynamic_buffers = &validated.dynamic_buffers; |
| 1237 | auto *const non_dynamic_buffers = &validated.non_dynamic_buffers; |
| 1238 | const auto &stats = p_layout_->GetBindingTypeStats(); |
| 1239 | for (const auto &binding_req_pair : in_req) { |
| 1240 | auto binding = binding_req_pair.first; |
| 1241 | VkDescriptorSetLayoutBinding const *layout_binding = p_layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding); |
| 1242 | if (!layout_binding) { |
| 1243 | continue; |
| 1244 | } |
| 1245 | // Caching criteria differs per type. |
| 1246 | // If image_layout have changed , the image descriptors need to be validated against them. |
| 1247 | if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) || |
| 1248 | (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
| 1249 | FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, dynamic_buffers, stats.dynamic_buffer_count); |
| 1250 | } else if ((layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) || |
| 1251 | (layout_binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)) { |
| 1252 | FilterAndTrackOneBindingReq(binding_req_pair, in_req, out_req, non_dynamic_buffers, stats.non_dynamic_buffer_count); |
| 1253 | } else { |
| 1254 | // This is rather crude, as the changed layouts may not impact the bound descriptors, |
| 1255 | // but the simple "versioning" is a simple "dirt" test. |
| 1256 | auto &version = image_sample_val[binding]; // Take advantage of default construtor zero initialzing new entries |
| 1257 | if (version != cb_state->image_layout_change_count) { |
| 1258 | version = cb_state->image_layout_change_count; |
| 1259 | out_req->emplace(binding_req_pair); |
| 1260 | } |
| 1261 | } |
| 1262 | } |
| 1263 | } |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 1264 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1265 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1266 | updated = false; |
| 1267 | descriptor_class = PlainSampler; |
| 1268 | if (immut) { |
| 1269 | sampler_ = *immut; |
| 1270 | immutable_ = true; |
| 1271 | updated = true; |
| 1272 | } |
| 1273 | } |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1274 | // Validate given sampler. Currently this only checks to make sure it exists in the samplerMap |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1275 | bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const layer_data *dev_data) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1276 | return (GetSamplerState(dev_data, sampler) != nullptr); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1277 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1278 | |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 1279 | bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1280 | const layer_data *dev_data, std::string *error_code, std::string *error_msg) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1281 | // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases. |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1282 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00326"; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1283 | auto iv_state = GetImageViewState(dev_data, image_view); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 1284 | if (!iv_state) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1285 | std::stringstream error_str; |
| 1286 | error_str << "Invalid VkImageView: " << image_view; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1287 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1288 | return false; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1289 | } |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 1290 | // 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] | 1291 | // Validate that imageLayout is compatible with aspect_mask and image format |
| 1292 | // and validate that image usage bits are correct for given usage |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 1293 | VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask; |
| 1294 | VkImage image = iv_state->create_info.image; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1295 | VkFormat format = VK_FORMAT_MAX_ENUM; |
| 1296 | VkImageUsageFlags usage = 0; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1297 | auto image_node = GetImageState(dev_data, image); |
Tobin Ehlis | 1c9c55f | 2016-06-02 11:49:22 -0600 | [diff] [blame] | 1298 | if (image_node) { |
| 1299 | format = image_node->createInfo.format; |
| 1300 | usage = image_node->createInfo.usage; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 1301 | // Validate that memory is bound to image |
Tobin Ehlis | 2cb8eb2 | 2017-01-03 14:09:57 -0700 | [diff] [blame] | 1302 | // TODO: This should have its own valid usage id apart from 2524 which is from CreateImageView case. The only |
| 1303 | // the error here occurs is if memory bound to a created imageView has been freed. |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1304 | if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()", |
| 1305 | "VUID-VkImageViewCreateInfo-image-01020")) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1306 | *error_code = "VUID-VkImageViewCreateInfo-image-01020"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1307 | *error_msg = "No memory bound to image."; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 1308 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 1309 | } |
Chris Forbes | 67757ff | 2017-07-21 13:59:01 -0700 | [diff] [blame] | 1310 | |
| 1311 | // KHR_maintenance1 allows rendering into 2D or 2DArray views which slice a 3D image, |
| 1312 | // but not binding them to descriptor sets. |
| 1313 | if (image_node->createInfo.imageType == VK_IMAGE_TYPE_3D && |
| 1314 | (iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D || |
| 1315 | iv_state->create_info.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1316 | *error_code = "VUID-VkDescriptorImageInfo-imageView-00343"; |
Chris Forbes | 67757ff | 2017-07-21 13:59:01 -0700 | [diff] [blame] | 1317 | *error_msg = "ImageView must not be a 2D or 2DArray view of a 3D image"; |
| 1318 | return false; |
| 1319 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1320 | } |
| 1321 | // First validate that format and layout are compatible |
| 1322 | if (format == VK_FORMAT_MAX_ENUM) { |
| 1323 | std::stringstream error_str; |
| 1324 | error_str << "Invalid image (" << image << ") in imageView (" << image_view << ")."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1325 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1326 | return false; |
| 1327 | } |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1328 | // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under |
| 1329 | // vkCreateImageView(). What's the best way to create unique id for these cases? |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 1330 | bool ds = FormatIsDepthOrStencil(format); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1331 | switch (image_layout) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1332 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 1333 | // Only Color bit must be set |
| 1334 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1335 | std::stringstream error_str; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1336 | error_str |
| 1337 | << "ImageView (" << image_view |
| 1338 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does not have VK_IMAGE_ASPECT_COLOR_BIT set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1339 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1340 | return false; |
| 1341 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1342 | // format must NOT be DS |
| 1343 | if (ds) { |
| 1344 | std::stringstream error_str; |
| 1345 | error_str << "ImageView (" << image_view |
| 1346 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is " |
| 1347 | << string_VkFormat(format) << " which is not a color format."; |
| 1348 | *error_msg = error_str.str(); |
| 1349 | return false; |
| 1350 | } |
| 1351 | break; |
| 1352 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 1353 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 1354 | // Depth or stencil bit must be set, but both must NOT be set |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 1355 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1356 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1357 | // both must NOT be set |
| 1358 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1359 | error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1360 | *error_msg = error_str.str(); |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 1361 | return false; |
| 1362 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1363 | } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1364 | // Neither were set |
| 1365 | std::stringstream error_str; |
| 1366 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 1367 | << " but does not have STENCIL or DEPTH aspects set"; |
| 1368 | *error_msg = error_str.str(); |
| 1369 | return false; |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 1370 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1371 | // format must be DS |
| 1372 | if (!ds) { |
| 1373 | std::stringstream error_str; |
| 1374 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 1375 | << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format."; |
| 1376 | *error_msg = error_str.str(); |
| 1377 | return false; |
| 1378 | } |
| 1379 | break; |
| 1380 | default: |
| 1381 | // For other layouts if the source is depth/stencil image, both aspect bits must not be set |
| 1382 | if (ds) { |
| 1383 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 1384 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 1385 | // both must NOT be set |
| 1386 | std::stringstream error_str; |
| 1387 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 1388 | << " and is using depth/stencil image of format " << string_VkFormat(format) |
| 1389 | << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil " |
| 1390 | "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 1391 | "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil " |
| 1392 | "reads respectively."; |
| 1393 | *error_msg = error_str.str(); |
| 1394 | return false; |
| 1395 | } |
| 1396 | } |
| 1397 | } |
| 1398 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1399 | } |
| 1400 | // Now validate that usage flags are correctly set for given type of update |
Tobin Ehlis | fb4cf71 | 2016-10-10 14:02:48 -0600 | [diff] [blame] | 1401 | // As we're switching per-type, if any type has specific layout requirements, check those here as well |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1402 | // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images |
| 1403 | // under vkCreateImage() |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1404 | // TODO : Need to also validate case "VUID-VkWriteDescriptorSet-descriptorType-00336" where STORAGE_IMAGE & INPUT_ATTACH types |
| 1405 | // must have been created with identify swizzle |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1406 | std::string error_usage_bit; |
| 1407 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1408 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1409 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 1410 | if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { |
| 1411 | error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT"; |
| 1412 | } |
| 1413 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1414 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1415 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 1416 | if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 1417 | error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT"; |
| 1418 | } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) { |
| 1419 | std::stringstream error_str; |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1420 | // TODO : Need to create custom enum error codes for these cases |
| 1421 | if (image_node->shared_presentable) { |
| 1422 | if (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != image_layout) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1423 | error_str << "ImageView (" << image_view |
| 1424 | << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type with a front-buffered image is being updated with " |
| 1425 | "layout " |
| 1426 | << string_VkImageLayout(image_layout) |
| 1427 | << " but according to spec section 13.1 Descriptor Types, 'Front-buffered images that report " |
| 1428 | "support for VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT must be in the " |
| 1429 | "VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR layout.'"; |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1430 | *error_msg = error_str.str(); |
| 1431 | return false; |
| 1432 | } |
| 1433 | } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1434 | error_str << "ImageView (" << image_view |
| 1435 | << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout " |
| 1436 | << string_VkImageLayout(image_layout) |
| 1437 | << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage " |
| 1438 | "images can only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'"; |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 1439 | *error_msg = error_str.str(); |
| 1440 | return false; |
| 1441 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1442 | } |
| 1443 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1444 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1445 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 1446 | if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
| 1447 | error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT"; |
| 1448 | } |
| 1449 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1450 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1451 | default: |
| 1452 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1453 | } |
| 1454 | if (!error_usage_bit.empty()) { |
| 1455 | std::stringstream error_str; |
| 1456 | error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage |
| 1457 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 1458 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1459 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 1460 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1461 | } |
| 1462 | return true; |
| 1463 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1464 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1465 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 1466 | if (!immutable_) { |
| 1467 | sampler_ = update->pImageInfo[index].sampler; |
| 1468 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1469 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1470 | } |
| 1471 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1472 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1473 | if (!immutable_) { |
| 1474 | auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1475 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1476 | } |
| 1477 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1478 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1479 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1480 | void cvdescriptorset::SamplerDescriptor::UpdateDrawState(layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1481 | if (!immutable_) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1482 | auto sampler_state = GetSamplerState(dev_data, sampler_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1483 | if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1487 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut) |
Chris Forbes | 9f34085 | 2017-05-09 08:51:38 -0700 | [diff] [blame] | 1488 | : 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] | 1489 | updated = false; |
| 1490 | descriptor_class = ImageSampler; |
| 1491 | if (immut) { |
| 1492 | sampler_ = *immut; |
| 1493 | immutable_ = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1494 | } |
| 1495 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1496 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1497 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1498 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1499 | const auto &image_info = update->pImageInfo[index]; |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 1500 | if (!immutable_) { |
| 1501 | sampler_ = image_info.sampler; |
| 1502 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1503 | image_view_ = image_info.imageView; |
| 1504 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1505 | } |
| 1506 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1507 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1508 | if (!immutable_) { |
| 1509 | auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1510 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1511 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1512 | auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_; |
| 1513 | auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1514 | updated = true; |
| 1515 | image_view_ = image_view; |
| 1516 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1517 | } |
| 1518 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1519 | void cvdescriptorset::ImageSamplerDescriptor::UpdateDrawState(layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1520 | // First add binding for any non-immutable sampler |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1521 | if (!immutable_) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1522 | auto sampler_state = GetSamplerState(dev_data, sampler_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1523 | if (sampler_state) core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1524 | } |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1525 | // Add binding for image |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1526 | auto iv_state = GetImageViewState(dev_data, image_view_); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 1527 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 1528 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1529 | } |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1530 | SetImageViewLayout(dev_data, cb_node, image_view_, image_layout_); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1531 | } |
| 1532 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1533 | cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type) |
| 1534 | : 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] | 1535 | updated = false; |
| 1536 | descriptor_class = Image; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1537 | if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) storage_ = true; |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1538 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1539 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1540 | void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1541 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1542 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1543 | image_view_ = image_info.imageView; |
| 1544 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1545 | } |
| 1546 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1547 | void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1548 | auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_; |
| 1549 | auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1550 | updated = true; |
| 1551 | image_view_ = image_view; |
| 1552 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1553 | } |
| 1554 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1555 | void cvdescriptorset::ImageDescriptor::UpdateDrawState(layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1556 | // Add binding for image |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1557 | auto iv_state = GetImageViewState(dev_data, image_view_); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 1558 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 1559 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1560 | } |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1561 | SetImageViewLayout(dev_data, cb_node, image_view_, image_layout_); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1562 | } |
| 1563 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1564 | cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type) |
| 1565 | : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1566 | updated = false; |
| 1567 | descriptor_class = GeneralBuffer; |
| 1568 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 1569 | dynamic_ = true; |
| 1570 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) { |
| 1571 | storage_ = true; |
| 1572 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 1573 | dynamic_ = true; |
| 1574 | storage_ = true; |
| 1575 | } |
| 1576 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1577 | void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1578 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1579 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1580 | buffer_ = buffer_info.buffer; |
| 1581 | offset_ = buffer_info.offset; |
| 1582 | range_ = buffer_info.range; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1583 | } |
| 1584 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1585 | void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) { |
| 1586 | auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1587 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1588 | buffer_ = buff_desc->buffer_; |
| 1589 | offset_ = buff_desc->offset_; |
| 1590 | range_ = buff_desc->range_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1591 | } |
| 1592 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1593 | void cvdescriptorset::BufferDescriptor::UpdateDrawState(layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1594 | auto buffer_node = GetBufferState(dev_data, buffer_); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1595 | if (buffer_node) core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1596 | } |
| 1597 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1598 | 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] | 1599 | updated = false; |
| 1600 | descriptor_class = TexelBuffer; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1601 | if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) storage_ = true; |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 1602 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1603 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1604 | void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1605 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1606 | buffer_view_ = update->pTexelBufferView[index]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1607 | } |
| 1608 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1609 | void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) { |
| 1610 | updated = true; |
| 1611 | buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_; |
| 1612 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1613 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame^] | 1614 | void cvdescriptorset::TexelDescriptor::UpdateDrawState(layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1615 | auto bv_state = GetBufferViewState(dev_data, buffer_view_); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1616 | if (bv_state) { |
Tobin Ehlis | 2515c0e | 2016-09-28 07:12:28 -0600 | [diff] [blame] | 1617 | core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1618 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1619 | } |
| 1620 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1621 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1622 | // sets, and then calls their respective Validate[Write|Copy]Update functions. |
| 1623 | // If the update hits an issue for which the callback returns "true", meaning that the call down the chain should |
| 1624 | // be skipped, then true is returned. |
| 1625 | // If there is no issue with the update, then false is returned. |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1626 | bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data, const layer_data *dev_data, |
| 1627 | uint32_t write_count, const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1628 | const VkCopyDescriptorSet *p_cds) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1629 | bool skip = false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1630 | // Validate Write updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1631 | for (uint32_t i = 0; i < write_count; i++) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1632 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1633 | auto set_node = core_validation::GetSetNode(dev_data, dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1634 | if (!set_node) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1635 | skip |= |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1636 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1637 | HandleToUint64(dest_set), kVUID_Core_DrawState_InvalidDescriptorSet, |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1638 | "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.", |
Petr Kraus | bc7f544 | 2017-05-14 23:43:38 +0200 | [diff] [blame] | 1639 | HandleToUint64(dest_set)); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1640 | } else { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1641 | std::string error_code; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1642 | std::string error_str; |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1643 | if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1644 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1645 | HandleToUint64(dest_set), error_code, |
Artem Kharytoniuk | 2456f99 | 2018-01-12 14:17:41 +0100 | [diff] [blame] | 1646 | "vkUpdateDescriptorSets() failed write update validation for Descriptor Set 0x%" PRIx64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1647 | " with error: %s.", |
| 1648 | HandleToUint64(dest_set), error_str.c_str()); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | // Now validate copy updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1653 | for (uint32_t i = 0; i < copy_count; ++i) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1654 | auto dst_set = p_cds[i].dstSet; |
| 1655 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1656 | auto src_node = core_validation::GetSetNode(dev_data, src_set); |
| 1657 | auto dst_node = core_validation::GetSetNode(dev_data, dst_set); |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 1658 | // Object_tracker verifies that src & dest descriptor set are valid |
| 1659 | assert(src_node); |
| 1660 | assert(dst_node); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1661 | std::string error_code; |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 1662 | std::string error_str; |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1663 | if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1664 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Mark Lobodzinski | 8852949 | 2018-04-01 10:38:15 -0600 | [diff] [blame] | 1665 | HandleToUint64(dst_set), error_code, |
Artem Kharytoniuk | 2456f99 | 2018-01-12 14:17:41 +0100 | [diff] [blame] | 1666 | "vkUpdateDescriptorSets() failed copy update from Descriptor Set 0x%" PRIx64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1667 | " to Descriptor Set 0x%" PRIx64 " with error: %s.", |
| 1668 | HandleToUint64(src_set), HandleToUint64(dst_set), error_str.c_str()); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1669 | } |
| 1670 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 1671 | return skip; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1672 | } |
| 1673 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1674 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 1675 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 1676 | // with the same set of updates. |
| 1677 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 1678 | // calling down the chain. |
Tobin Ehlis | 58c884f | 2017-02-08 12:15:27 -0700 | [diff] [blame] | 1679 | void cvdescriptorset::PerformUpdateDescriptorSets(const layer_data *dev_data, uint32_t write_count, |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1680 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 1681 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1682 | // Write updates first |
| 1683 | uint32_t i = 0; |
| 1684 | for (i = 0; i < write_count; ++i) { |
| 1685 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1686 | auto set_node = core_validation::GetSetNode(dev_data, dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1687 | if (set_node) { |
| 1688 | set_node->PerformWriteUpdate(&p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1689 | } |
| 1690 | } |
| 1691 | // Now copy updates |
| 1692 | for (i = 0; i < copy_count; ++i) { |
| 1693 | auto dst_set = p_cds[i].dstSet; |
| 1694 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1695 | auto src_node = core_validation::GetSetNode(dev_data, src_set); |
| 1696 | auto dst_node = core_validation::GetSetNode(dev_data, dst_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1697 | if (src_node && dst_node) { |
| 1698 | dst_node->PerformCopyUpdate(&p_cds[i], src_node); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | } |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1702 | // This helper function carries out the state updates for descriptor updates peformed via update templates. It basically collects |
| 1703 | // data and leverages the PerformUpdateDescriptor helper functions to do this. |
| 1704 | void cvdescriptorset::PerformUpdateDescriptorSetsWithTemplateKHR(layer_data *device_data, VkDescriptorSet descriptorSet, |
| 1705 | std::unique_ptr<TEMPLATE_STATE> const &template_state, |
| 1706 | const void *pData) { |
| 1707 | auto const &create_info = template_state->create_info; |
| 1708 | |
| 1709 | // Create a vector of write structs |
| 1710 | std::vector<VkWriteDescriptorSet> desc_writes; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1711 | std::vector<VkWriteDescriptorSetInlineUniformBlockEXT> inline_infos(create_info.descriptorUpdateEntryCount); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1712 | auto layout_obj = GetDescriptorSetLayout(device_data, create_info.descriptorSetLayout); |
| 1713 | |
| 1714 | // Create a WriteDescriptorSet struct for each template update entry |
| 1715 | for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) { |
| 1716 | auto binding_count = layout_obj->GetDescriptorCountFromBinding(create_info.pDescriptorUpdateEntries[i].dstBinding); |
| 1717 | auto binding_being_updated = create_info.pDescriptorUpdateEntries[i].dstBinding; |
| 1718 | auto dst_array_element = create_info.pDescriptorUpdateEntries[i].dstArrayElement; |
| 1719 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 1720 | desc_writes.reserve(desc_writes.size() + create_info.pDescriptorUpdateEntries[i].descriptorCount); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1721 | for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) { |
| 1722 | desc_writes.emplace_back(); |
| 1723 | auto &write_entry = desc_writes.back(); |
| 1724 | |
| 1725 | size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride; |
| 1726 | char *update_entry = (char *)(pData) + offset; |
| 1727 | |
| 1728 | if (dst_array_element >= binding_count) { |
| 1729 | dst_array_element = 0; |
Mark Lobodzinski | 4aa479d | 2017-03-10 09:14:00 -0700 | [diff] [blame] | 1730 | binding_being_updated = layout_obj->GetNextValidBinding(binding_being_updated); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | write_entry.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 1734 | write_entry.pNext = NULL; |
| 1735 | write_entry.dstSet = descriptorSet; |
| 1736 | write_entry.dstBinding = binding_being_updated; |
| 1737 | write_entry.dstArrayElement = dst_array_element; |
| 1738 | write_entry.descriptorCount = 1; |
| 1739 | write_entry.descriptorType = create_info.pDescriptorUpdateEntries[i].descriptorType; |
| 1740 | |
| 1741 | switch (create_info.pDescriptorUpdateEntries[i].descriptorType) { |
| 1742 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 1743 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 1744 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1745 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 1746 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1747 | write_entry.pImageInfo = reinterpret_cast<VkDescriptorImageInfo *>(update_entry); |
| 1748 | break; |
| 1749 | |
| 1750 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1751 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1752 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1753 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1754 | write_entry.pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry); |
| 1755 | break; |
| 1756 | |
| 1757 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1758 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1759 | write_entry.pTexelBufferView = reinterpret_cast<VkBufferView *>(update_entry); |
| 1760 | break; |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 1761 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: { |
| 1762 | VkWriteDescriptorSetInlineUniformBlockEXT *inline_info = &inline_infos[i]; |
| 1763 | inline_info->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT; |
| 1764 | inline_info->pNext = nullptr; |
| 1765 | inline_info->dataSize = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 1766 | inline_info->pData = update_entry; |
| 1767 | write_entry.pNext = inline_info; |
| 1768 | // skip the rest of the array, they just represent bytes in the update |
| 1769 | j = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 1770 | break; |
| 1771 | } |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 1772 | default: |
| 1773 | assert(0); |
| 1774 | break; |
| 1775 | } |
| 1776 | dst_array_element++; |
| 1777 | } |
| 1778 | } |
| 1779 | PerformUpdateDescriptorSets(device_data, static_cast<uint32_t>(desc_writes.size()), desc_writes.data(), 0, NULL); |
| 1780 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1781 | // Validate the state for a given write update but don't actually perform the update |
| 1782 | // If an error would occur for this update, return false and fill in details in error_msg string |
| 1783 | bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1784 | std::string *error_code, std::string *error_msg) { |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 1785 | // Verify dst layout still valid |
| 1786 | if (p_layout_->IsDestroyed()) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1787 | *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320"; |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 1788 | string_sprintf(error_msg, |
| 1789 | "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set 0x%" PRIxLEAST64 |
| 1790 | " created with destroyed VkDescriptorSetLayout 0x%" PRIxLEAST64, |
| 1791 | HandleToUint64(set_), HandleToUint64(p_layout_->GetDescriptorSetLayout())); |
| 1792 | return false; |
| 1793 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1794 | // Verify dst binding exists |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1795 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1796 | *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315"; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1797 | std::stringstream error_str; |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1798 | error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1799 | *error_msg = error_str.str(); |
| 1800 | return false; |
Tobin Ehlis | 59a5efc | 2016-11-21 09:41:57 -0700 | [diff] [blame] | 1801 | } else { |
| 1802 | // Make sure binding isn't empty |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1803 | if (0 == p_layout_->GetDescriptorCountFromBinding(update->dstBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1804 | *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316"; |
Tobin Ehlis | 59a5efc | 2016-11-21 09:41:57 -0700 | [diff] [blame] | 1805 | std::stringstream error_str; |
| 1806 | error_str << "DescriptorSet " << set_ << " cannot updated binding " << update->dstBinding << " that has 0 descriptors"; |
| 1807 | *error_msg = error_str.str(); |
| 1808 | return false; |
| 1809 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1810 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1811 | // Verify idle ds |
| 1812 | if (in_use.load() && |
| 1813 | !(p_layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
| 1814 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) { |
| 1815 | // TODO : Re-using Free Idle error code, need write update idle error code |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1816 | *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1817 | std::stringstream error_str; |
| 1818 | error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_ |
| 1819 | << " that is in use by a command buffer"; |
| 1820 | *error_msg = error_str.str(); |
| 1821 | return false; |
| 1822 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1823 | // We know that binding is valid, verify update and do update on each descriptor |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1824 | auto start_idx = p_layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement; |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1825 | auto type = p_layout_->GetTypeFromBinding(update->dstBinding); |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1826 | if (type != update->descriptorType) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1827 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319"; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1828 | std::stringstream error_str; |
| 1829 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type " |
| 1830 | << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType); |
| 1831 | *error_msg = error_str.str(); |
| 1832 | return false; |
| 1833 | } |
Tobin Ehlis | 7b40235 | 2016-12-15 07:51:20 -0700 | [diff] [blame] | 1834 | if (update->descriptorCount > (descriptors_.size() - start_idx)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1835 | *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321"; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1836 | std::stringstream error_str; |
| 1837 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
Tobin Ehlis | 7b40235 | 2016-12-15 07:51:20 -0700 | [diff] [blame] | 1838 | << descriptors_.size() - start_idx |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1839 | << " descriptors in that binding and all successive bindings of the set, but update of " |
| 1840 | << update->descriptorCount << " descriptors combined with update array element offset of " |
| 1841 | << update->dstArrayElement << " oversteps the available number of consecutive descriptors"; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1842 | *error_msg = error_str.str(); |
| 1843 | return false; |
| 1844 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1845 | if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
| 1846 | if ((update->dstArrayElement % 4) != 0) { |
| 1847 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219"; |
| 1848 | std::stringstream error_str; |
| 1849 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
| 1850 | << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4"; |
| 1851 | *error_msg = error_str.str(); |
| 1852 | return false; |
| 1853 | } |
| 1854 | if ((update->descriptorCount % 4) != 0) { |
| 1855 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220"; |
| 1856 | std::stringstream error_str; |
| 1857 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
| 1858 | << "descriptorCount " << update->descriptorCount << " not a multiple of 4"; |
| 1859 | *error_msg = error_str.str(); |
| 1860 | return false; |
| 1861 | } |
| 1862 | const auto *write_inline_info = lvl_find_in_chain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext); |
| 1863 | if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) { |
| 1864 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221"; |
| 1865 | std::stringstream error_str; |
| 1866 | if (!write_inline_info) { |
| 1867 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
| 1868 | << "VkWriteDescriptorSetInlineUniformBlockEXT missing"; |
| 1869 | } else { |
| 1870 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 1871 | << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize |
| 1872 | << " not equal to " |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1873 | << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount; |
| 1874 | } |
| 1875 | *error_msg = error_str.str(); |
| 1876 | return false; |
| 1877 | } |
| 1878 | // This error is probably unreachable due to the previous two errors |
| 1879 | if (write_inline_info && (write_inline_info->dataSize % 4) != 0) { |
| 1880 | *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222"; |
| 1881 | std::stringstream error_str; |
| 1882 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 1883 | << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize |
| 1884 | << " not a multiple of 4"; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1885 | *error_msg = error_str.str(); |
| 1886 | return false; |
| 1887 | } |
| 1888 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1889 | // Verify consecutive bindings match (if needed) |
Tobin Ehlis | 7cd8c79 | 2017-06-20 08:30:39 -0600 | [diff] [blame] | 1890 | if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1891 | set_, error_msg)) { |
Tobin Ehlis | 48fbd69 | 2017-01-04 09:17:01 -0700 | [diff] [blame] | 1892 | // TODO : Should break out "consecutive binding updates" language into valid usage statements |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1893 | *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321"; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1894 | return false; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1895 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1896 | // Update is within bounds and consistent so last step is to validate update contents |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1897 | if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) { |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1898 | std::stringstream error_str; |
| 1899 | error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding |
| 1900 | << " failed with error message: " << error_msg->c_str(); |
| 1901 | *error_msg = error_str.str(); |
| 1902 | return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1903 | } |
| 1904 | // All checks passed, update is clean |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1905 | return true; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 1906 | } |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1907 | // For the given buffer, verify that its creation parameters are appropriate for the given type |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1908 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame] | 1909 | bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1910 | std::string *error_code, std::string *error_msg) const { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1911 | // Verify that usage bits set correctly for given type |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 1912 | auto usage = buffer_node->createInfo.usage; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1913 | std::string error_usage_bit; |
| 1914 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1915 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1916 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1917 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00334"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1918 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; |
| 1919 | } |
| 1920 | break; |
| 1921 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1922 | if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1923 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00335"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1924 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; |
| 1925 | } |
| 1926 | break; |
| 1927 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1928 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1929 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1930 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00330"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1931 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; |
| 1932 | } |
| 1933 | break; |
| 1934 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1935 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1936 | if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1937 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00331"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 1938 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; |
| 1939 | } |
| 1940 | break; |
| 1941 | default: |
| 1942 | break; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1943 | } |
| 1944 | if (!error_usage_bit.empty()) { |
| 1945 | std::stringstream error_str; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1946 | error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage |
| 1947 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 1948 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1949 | *error_msg = error_str.str(); |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1950 | return false; |
| 1951 | } |
| 1952 | return true; |
| 1953 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1954 | // For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes: |
| 1955 | // 1. buffer is valid |
| 1956 | // 2. buffer was created with correct usage flags |
| 1957 | // 3. offset is less than buffer size |
| 1958 | // 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)] |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 1959 | // 5. range and offset are within the device's limits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1960 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1961 | bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1962 | std::string *error_code, std::string *error_msg) const { |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1963 | // First make sure that buffer is valid |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 1964 | auto buffer_node = GetBufferState(device_data_, buffer_info->buffer); |
Tobin Ehlis | fa8b618 | 2016-12-22 13:40:45 -0700 | [diff] [blame] | 1965 | // Any invalid buffer should already be caught by object_tracker |
| 1966 | assert(buffer_node); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1967 | if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()", |
| 1968 | "VUID-VkWriteDescriptorSet-descriptorType-00329")) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1969 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00329"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1970 | *error_msg = "No memory bound to buffer."; |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 1971 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 1972 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1973 | // Verify usage bits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1974 | if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) { |
| 1975 | // error_msg will have been updated by ValidateBufferUsage() |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1976 | return false; |
| 1977 | } |
| 1978 | // offset must be less than buffer size |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 1979 | if (buffer_info->offset >= buffer_node->createInfo.size) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1980 | *error_code = "VUID-VkDescriptorBufferInfo-offset-00340"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1981 | std::stringstream error_str; |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 1982 | error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than or equal to buffer " |
| 1983 | << buffer_node->buffer << " size of " << buffer_node->createInfo.size; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1984 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1985 | return false; |
| 1986 | } |
| 1987 | if (buffer_info->range != VK_WHOLE_SIZE) { |
| 1988 | // Range must be VK_WHOLE_SIZE or > 0 |
| 1989 | if (!buffer_info->range) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1990 | *error_code = "VUID-VkDescriptorBufferInfo-range-00341"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1991 | std::stringstream error_str; |
| 1992 | error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1993 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1994 | return false; |
| 1995 | } |
| 1996 | // Range must be VK_WHOLE_SIZE or <= (buffer size - offset) |
| 1997 | if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1998 | *error_code = "VUID-VkDescriptorBufferInfo-range-00342"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1999 | std::stringstream error_str; |
| 2000 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size (" |
| 2001 | << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2002 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2003 | return false; |
| 2004 | } |
| 2005 | } |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2006 | // Check buffer update sizes against device limits |
| 2007 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER == type || VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 2008 | auto max_ub_range = limits_.maxUniformBufferRange; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2009 | if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_ub_range) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2010 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2011 | std::stringstream error_str; |
| 2012 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range |
| 2013 | << " which is greater than this device's maxUniformBufferRange (" << max_ub_range << ")"; |
| 2014 | *error_msg = error_str.str(); |
| 2015 | return false; |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2016 | } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_ub_range) { |
| 2017 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332"; |
| 2018 | std::stringstream error_str; |
Peter Kohaut | 18f413d | 2018-07-16 13:15:42 +0200 | [diff] [blame] | 2019 | error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range " |
| 2020 | << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's " |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2021 | << "maxUniformBufferRange (" << max_ub_range << ")"; |
| 2022 | *error_msg = error_str.str(); |
| 2023 | return false; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2024 | } |
| 2025 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type || VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 2026 | auto max_sb_range = limits_.maxStorageBufferRange; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2027 | if (buffer_info->range != VK_WHOLE_SIZE && buffer_info->range > max_sb_range) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2028 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2029 | std::stringstream error_str; |
| 2030 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range |
| 2031 | << " which is greater than this device's maxStorageBufferRange (" << max_sb_range << ")"; |
| 2032 | *error_msg = error_str.str(); |
| 2033 | return false; |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2034 | } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_sb_range) { |
| 2035 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333"; |
| 2036 | std::stringstream error_str; |
Peter Kohaut | 18f413d | 2018-07-16 13:15:42 +0200 | [diff] [blame] | 2037 | error_str << "VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range " |
| 2038 | << "(" << (buffer_node->createInfo.size - buffer_info->offset) << ") is greater than this device's " |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2039 | << "maxStorageBufferRange (" << max_sb_range << ")"; |
| 2040 | *error_msg = error_str.str(); |
| 2041 | return false; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2042 | } |
| 2043 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2044 | return true; |
| 2045 | } |
| 2046 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2047 | // Verify that the contents of the update are ok, but don't perform actual update |
| 2048 | bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2049 | std::string *error_code, std::string *error_msg) const { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2050 | switch (update->descriptorType) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2051 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 2052 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2053 | // Validate image |
| 2054 | auto image_view = update->pImageInfo[di].imageView; |
| 2055 | auto image_layout = update->pImageInfo[di].imageLayout; |
| 2056 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2057 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2058 | error_str << "Attempted write update to combined image sampler descriptor failed due to: " |
| 2059 | << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2060 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2061 | return false; |
| 2062 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2063 | } |
| 2064 | } |
Tobin Ehlis | 648b1cf | 2018-04-13 15:24:13 -0600 | [diff] [blame] | 2065 | // fall through |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2066 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 2067 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2068 | if (!descriptors_[index + di].get()->IsImmutableSampler()) { |
| 2069 | if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2070 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2071 | std::stringstream error_str; |
| 2072 | error_str << "Attempted write update to sampler descriptor with invalid sampler: " |
| 2073 | << update->pImageInfo[di].sampler << "."; |
| 2074 | *error_msg = error_str.str(); |
| 2075 | return false; |
| 2076 | } |
| 2077 | } else { |
| 2078 | // TODO : Warn here |
| 2079 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2080 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2081 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2082 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2083 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 2084 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 2085 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 2086 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2087 | auto image_view = update->pImageInfo[di].imageView; |
| 2088 | auto image_layout = update->pImageInfo[di].imageLayout; |
| 2089 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
| 2090 | std::stringstream error_str; |
| 2091 | error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str(); |
| 2092 | *error_msg = error_str.str(); |
| 2093 | return false; |
| 2094 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2095 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2096 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2097 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2098 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 2099 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| 2100 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2101 | auto buffer_view = update->pTexelBufferView[di]; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2102 | auto bv_state = GetBufferViewState(device_data_, buffer_view); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2103 | if (!bv_state) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2104 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2105 | std::stringstream error_str; |
| 2106 | error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 2107 | *error_msg = error_str.str(); |
| 2108 | return false; |
| 2109 | } |
| 2110 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | df0d62a | 2017-10-11 08:48:00 -0600 | [diff] [blame] | 2111 | auto buffer_state = GetBufferState(device_data_, buffer); |
| 2112 | // Verify that buffer underlying the view hasn't been destroyed prematurely |
| 2113 | if (!buffer_state) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2114 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323"; |
Tobin Ehlis | df0d62a | 2017-10-11 08:48:00 -0600 | [diff] [blame] | 2115 | std::stringstream error_str; |
| 2116 | error_str << "Attempted write update to texel buffer descriptor failed because underlying buffer (" << buffer |
| 2117 | << ") has been destroyed: " << error_msg->c_str(); |
| 2118 | *error_msg = error_str.str(); |
| 2119 | return false; |
| 2120 | } else if (!ValidateBufferUsage(buffer_state, update->descriptorType, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2121 | std::stringstream error_str; |
| 2122 | error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 2123 | *error_msg = error_str.str(); |
| 2124 | return false; |
| 2125 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2126 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2127 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2128 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2129 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 2130 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 2131 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 2132 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 2133 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2134 | if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) { |
| 2135 | std::stringstream error_str; |
| 2136 | error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 2137 | *error_msg = error_str.str(); |
| 2138 | return false; |
| 2139 | } |
| 2140 | } |
| 2141 | break; |
| 2142 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2143 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: |
| 2144 | break; |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2145 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NVX: |
| 2146 | // XXX TODO |
| 2147 | break; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2148 | default: |
| 2149 | assert(0); // We've already verified update type so should never get here |
| 2150 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2151 | } |
| 2152 | // All checks passed so update contents are good |
| 2153 | return true; |
| 2154 | } |
| 2155 | // Verify that the contents of the update are ok, but don't perform actual update |
| 2156 | bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2157 | VkDescriptorType type, uint32_t index, std::string *error_code, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2158 | std::string *error_msg) const { |
| 2159 | // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are |
| 2160 | // for write updates |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2161 | switch (src_set->descriptors_[index]->descriptor_class) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2162 | case PlainSampler: { |
| 2163 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2164 | const auto src_desc = src_set->descriptors_[index + di].get(); |
| 2165 | if (!src_desc->updated) continue; |
| 2166 | if (!src_desc->IsImmutableSampler()) { |
| 2167 | auto update_sampler = static_cast<SamplerDescriptor *>(src_desc)->GetSampler(); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2168 | if (!ValidateSampler(update_sampler, device_data_)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2169 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2170 | std::stringstream error_str; |
| 2171 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 2172 | *error_msg = error_str.str(); |
| 2173 | return false; |
| 2174 | } |
| 2175 | } else { |
| 2176 | // TODO : Warn here |
| 2177 | } |
| 2178 | } |
| 2179 | break; |
| 2180 | } |
| 2181 | case ImageSampler: { |
| 2182 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2183 | const auto src_desc = src_set->descriptors_[index + di].get(); |
| 2184 | if (!src_desc->updated) continue; |
| 2185 | auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_desc); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2186 | // First validate sampler |
| 2187 | if (!img_samp_desc->IsImmutableSampler()) { |
| 2188 | auto update_sampler = img_samp_desc->GetSampler(); |
| 2189 | if (!ValidateSampler(update_sampler, device_data_)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2190 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2191 | std::stringstream error_str; |
| 2192 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
| 2193 | *error_msg = error_str.str(); |
| 2194 | return false; |
| 2195 | } |
| 2196 | } else { |
| 2197 | // TODO : Warn here |
| 2198 | } |
| 2199 | // Validate image |
| 2200 | auto image_view = img_samp_desc->GetImageView(); |
| 2201 | auto image_layout = img_samp_desc->GetImageLayout(); |
| 2202 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2203 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2204 | error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2205 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2206 | return false; |
| 2207 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2208 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2209 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2210 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2211 | case Image: { |
| 2212 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2213 | const auto src_desc = src_set->descriptors_[index + di].get(); |
| 2214 | if (!src_desc->updated) continue; |
| 2215 | auto img_desc = static_cast<const ImageDescriptor *>(src_desc); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2216 | auto image_view = img_desc->GetImageView(); |
| 2217 | auto image_layout = img_desc->GetImageLayout(); |
| 2218 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2219 | std::stringstream error_str; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2220 | error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2221 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2222 | return false; |
| 2223 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2224 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2225 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2226 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2227 | case TexelBuffer: { |
| 2228 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2229 | const auto src_desc = src_set->descriptors_[index + di].get(); |
| 2230 | if (!src_desc->updated) continue; |
| 2231 | auto buffer_view = static_cast<TexelDescriptor *>(src_desc)->GetBufferView(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2232 | auto bv_state = GetBufferViewState(device_data_, buffer_view); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2233 | if (!bv_state) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2234 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00323"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2235 | std::stringstream error_str; |
| 2236 | error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
| 2237 | *error_msg = error_str.str(); |
| 2238 | return false; |
| 2239 | } |
| 2240 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2241 | if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2242 | std::stringstream error_str; |
| 2243 | error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 2244 | *error_msg = error_str.str(); |
| 2245 | return false; |
| 2246 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2247 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2248 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2249 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2250 | case GeneralBuffer: { |
| 2251 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2252 | const auto src_desc = src_set->descriptors_[index + di].get(); |
| 2253 | if (!src_desc->updated) continue; |
| 2254 | auto buffer = static_cast<BufferDescriptor *>(src_desc)->GetBuffer(); |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2255 | if (!ValidateBufferUsage(GetBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2256 | std::stringstream error_str; |
| 2257 | error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 2258 | *error_msg = error_str.str(); |
| 2259 | return false; |
| 2260 | } |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 2261 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2262 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2263 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2264 | case InlineUniform: |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2265 | case AccelerationStructure: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2266 | break; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2267 | default: |
| 2268 | assert(0); // We've already verified update type so should never get here |
| 2269 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2270 | } |
| 2271 | // All checks passed so update contents are good |
| 2272 | return true; |
Chris Forbes | b4e0bdb | 2016-05-31 16:34:40 +1200 | [diff] [blame] | 2273 | } |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 2274 | // Update the common AllocateDescriptorSetsData |
| 2275 | void cvdescriptorset::UpdateAllocateDescriptorSetsData(const layer_data *dev_data, const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 2276 | AllocateDescriptorSetsData *ds_data) { |
| 2277 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 2278 | auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
| 2279 | if (layout) { |
| 2280 | ds_data->layout_nodes[i] = layout; |
| 2281 | // Count total descriptors required per type |
| 2282 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 2283 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
| 2284 | uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType); |
| 2285 | ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount; |
| 2286 | } |
| 2287 | } |
| 2288 | // Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call |
| 2289 | } |
Petr Kraus | 13c98a6 | 2017-12-09 00:22:39 +0100 | [diff] [blame] | 2290 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2291 | // Verify that the state at allocate time is correct, but don't actually allocate the sets yet |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 2292 | bool cvdescriptorset::ValidateAllocateDescriptorSets(const core_validation::layer_data *dev_data, |
| 2293 | const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 2294 | const AllocateDescriptorSetsData *ds_data) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2295 | bool skip = false; |
Tobin Ehlis | f320b19 | 2017-03-14 11:22:50 -0600 | [diff] [blame] | 2296 | auto report_data = core_validation::GetReportData(dev_data); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2297 | auto pool_state = GetDescriptorPoolState(dev_data, p_alloc_info->descriptorPool); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2298 | |
| 2299 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | b2e1e2c | 2017-02-08 09:16:32 -0700 | [diff] [blame] | 2300 | auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 2301 | if (layout) { // nullptr layout indicates no valid layout handle for this device, validated/logged in object_tracker |
| 2302 | if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR) { |
| 2303 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2304 | HandleToUint64(p_alloc_info->pSetLayouts[i]), "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-00308", |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 2305 | "Layout 0x%" PRIxLEAST64 " specified at pSetLayouts[%" PRIu32 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2306 | "] in vkAllocateDescriptorSets() was created with invalid flag %s set.", |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 2307 | HandleToUint64(p_alloc_info->pSetLayouts[i]), i, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2308 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR"); |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 2309 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2310 | if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT_EXT && |
| 2311 | !(pool_state->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT)) { |
| 2312 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2313 | 0, "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-03044", |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2314 | "Descriptor set layout create flags and pool create flags mismatch for index (%d)", i); |
| 2315 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2316 | } |
| 2317 | } |
Mark Lobodzinski | 28426ae | 2017-06-01 07:56:38 -0600 | [diff] [blame] | 2318 | if (!GetDeviceExtensions(dev_data)->vk_khr_maintenance1) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2319 | // Track number of descriptorSets allowable in this pool |
| 2320 | if (pool_state->availableSets < p_alloc_info->descriptorSetCount) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2321 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2322 | HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorSetCount-00306", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2323 | "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2324 | ". This pool only has %d descriptorSets remaining.", |
| 2325 | p_alloc_info->descriptorSetCount, HandleToUint64(pool_state->pool), pool_state->availableSets); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2326 | } |
| 2327 | // Determine whether descriptor counts are satisfiable |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2328 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 2329 | if (ds_data->required_descriptors_by_type.at(it->first) > pool_state->availableDescriptorTypeCount[it->first]) { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2330 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2331 | HandleToUint64(pool_state->pool), "VUID-VkDescriptorSetAllocateInfo-descriptorPool-00307", |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2332 | "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64 |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 2333 | ". This pool only has %d descriptors of this type remaining.", |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 2334 | ds_data->required_descriptors_by_type.at(it->first), |
| 2335 | string_VkDescriptorType(VkDescriptorType(it->first)), HandleToUint64(pool_state->pool), |
| 2336 | pool_state->availableDescriptorTypeCount[it->first]); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 2337 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2338 | } |
| 2339 | } |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 2340 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2341 | const auto *count_allocate_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext); |
| 2342 | |
| 2343 | if (count_allocate_info) { |
| 2344 | if (count_allocate_info->descriptorSetCount != 0 && |
| 2345 | count_allocate_info->descriptorSetCount != p_alloc_info->descriptorSetCount) { |
| 2346 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2347 | "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-descriptorSetCount-03045", |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2348 | "VkDescriptorSetAllocateInfo::descriptorSetCount (%d) != " |
| 2349 | "VkDescriptorSetVariableDescriptorCountAllocateInfoEXT::descriptorSetCount (%d)", |
| 2350 | p_alloc_info->descriptorSetCount, count_allocate_info->descriptorSetCount); |
| 2351 | } |
| 2352 | if (count_allocate_info->descriptorSetCount == p_alloc_info->descriptorSetCount) { |
| 2353 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
| 2354 | auto layout = GetDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
| 2355 | if (count_allocate_info->pDescriptorCounts[i] > layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())) { |
| 2356 | skip |= log_msg( |
| 2357 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, 0, |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2358 | "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfoEXT-pSetLayouts-03046", |
| 2359 | "pDescriptorCounts[%d] = (%d), binding's descriptorCount = (%d)", i, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2360 | count_allocate_info->pDescriptorCounts[i], layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())); |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| 2365 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2366 | return skip; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2367 | } |
| 2368 | // 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] | 2369 | void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 2370 | const VkDescriptorSet *descriptor_sets, |
| 2371 | const AllocateDescriptorSetsData *ds_data, |
Tobin Ehlis | bd711bd | 2016-10-12 14:27:30 -0600 | [diff] [blame] | 2372 | std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map, |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 2373 | std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map, |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 2374 | layer_data *dev_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2375 | auto pool_state = (*pool_map)[p_alloc_info->descriptorPool]; |
Mark Lobodzinski | c943018 | 2017-06-13 13:00:05 -0600 | [diff] [blame] | 2376 | // Account for sets and individual descriptors allocated from pool |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2377 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2378 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
| 2379 | pool_state->availableDescriptorTypeCount[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 2380 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2381 | |
| 2382 | const auto *variable_count_info = lvl_find_in_chain<VkDescriptorSetVariableDescriptorCountAllocateInfoEXT>(p_alloc_info->pNext); |
| 2383 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == p_alloc_info->descriptorSetCount; |
| 2384 | |
Mark Lobodzinski | c943018 | 2017-06-13 13:00:05 -0600 | [diff] [blame] | 2385 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2386 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2387 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 2388 | |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 2389 | auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i], |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 2390 | variable_count, dev_data); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 2391 | |
| 2392 | pool_state->sets.insert(new_ds); |
| 2393 | new_ds->in_use.store(0); |
| 2394 | (*set_map)[descriptor_sets[i]] = new_ds; |
| 2395 | } |
| 2396 | } |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 2397 | |
| 2398 | cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map, |
| 2399 | GLOBAL_CB_NODE *cb_state) |
| 2400 | : filtered_map_(), orig_map_(in_map) { |
| 2401 | if (ds.GetTotalDescriptorCount() > kManyDescriptors_) { |
| 2402 | filtered_map_.reset(new std::map<uint32_t, descriptor_req>()); |
| 2403 | ds.FilterAndTrackBindingReqs(cb_state, orig_map_, filtered_map_.get()); |
| 2404 | } |
| 2405 | } |
| 2406 | cvdescriptorset::PrefilterBindRequestMap::PrefilterBindRequestMap(cvdescriptorset::DescriptorSet &ds, const BindingReqMap &in_map, |
| 2407 | GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *pipeline) |
| 2408 | : filtered_map_(), orig_map_(in_map) { |
| 2409 | if (ds.GetTotalDescriptorCount() > kManyDescriptors_) { |
| 2410 | filtered_map_.reset(new std::map<uint32_t, descriptor_req>()); |
| 2411 | ds.FilterAndTrackBindingReqs(cb_state, pipeline, orig_map_, filtered_map_.get()); |
| 2412 | } |
Artem Kharytoniuk | 2456f99 | 2018-01-12 14:17:41 +0100 | [diff] [blame] | 2413 | } |