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