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