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