sfricke-samsung | 691299b | 2021-01-01 20:48:48 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2021 Valve Corporation |
| 3 | * Copyright (c) 2015-2021 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2021 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> |
Jeremy Kniager | e682743 | 2020-04-01 09:05:56 -0600 | [diff] [blame] | 20 | * Jeremy Kniager <jeremyk@lunarg.com> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 21 | */ |
| 22 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 23 | #include "chassis.h" |
Mark Lobodzinski | 76d7666 | 2019-02-14 14:38:21 -0700 | [diff] [blame] | 24 | #include "core_validation_error_enums.h" |
| 25 | #include "core_validation.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 26 | #include "descriptor_sets.h" |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 27 | #include "hash_vk_types.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 28 | #include "vk_enum_string_helper.h" |
| 29 | #include "vk_safe_struct.h" |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 30 | #include "vk_typemap_helper.h" |
Tobin Ehlis | c826645 | 2017-04-07 12:20:30 -0600 | [diff] [blame] | 31 | #include "buffer_validation.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 32 | #include <sstream> |
Mark Lobodzinski | 2eee5d8 | 2016-12-02 15:33:18 -0700 | [diff] [blame] | 33 | #include <algorithm> |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 34 | #include <array> |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 35 | #include <memory> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 36 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 37 | // ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended |
| 38 | // state that comes from a different array/structure so they can stay together |
| 39 | // while being sorted by binding number. |
| 40 | struct ExtendedBinding { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 41 | ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlags f) : layout_binding(l), binding_flags(f) {} |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 42 | |
| 43 | const VkDescriptorSetLayoutBinding *layout_binding; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 44 | VkDescriptorBindingFlags binding_flags; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 47 | struct BindingNumCmp { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 48 | bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const { |
| 49 | return a.layout_binding->binding < b.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 50 | } |
| 51 | }; |
| 52 | |
John Zulauf | 613fd98 | 2019-06-04 15:14:41 -0600 | [diff] [blame] | 53 | using DescriptorSet = cvdescriptorset::DescriptorSet; |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 54 | using DescriptorSetLayout = cvdescriptorset::DescriptorSetLayout; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 55 | using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef; |
| 56 | using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId; |
| 57 | |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 58 | // Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information) |
| 59 | cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 60 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 61 | DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) { |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 62 | return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info)); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 63 | } |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 64 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 65 | // Construct DescriptorSetLayout instance from given create info |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 66 | // 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] | 67 | cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info) |
| 68 | : flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 69 | const auto *flags_create_info = LvlFindInChain<VkDescriptorSetLayoutBindingFlagsCreateInfo>(p_create_info->pNext); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 70 | |
sfricke-samsung | 0d00aed | 2021-03-08 23:31:17 -0800 | [diff] [blame] | 71 | binding_type_stats_ = {0, 0}; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 72 | std::set<ExtendedBinding, BindingNumCmp> sorted_bindings; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 73 | const uint32_t input_bindings_count = p_create_info->bindingCount; |
| 74 | // Sort the input bindings in binding number order, eliminating duplicates |
| 75 | for (uint32_t i = 0; i < input_bindings_count; i++) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 76 | VkDescriptorBindingFlags flags = 0; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 77 | if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) { |
| 78 | flags = flags_create_info->pBindingFlags[i]; |
| 79 | } |
Jeremy Gebben | fc6f815 | 2021-03-18 16:58:55 -0600 | [diff] [blame] | 80 | sorted_bindings.emplace(p_create_info->pBindings + i, flags); |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | // Store the create info in the sorted order from above |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 84 | uint32_t index = 0; |
| 85 | binding_count_ = static_cast<uint32_t>(sorted_bindings.size()); |
| 86 | bindings_.reserve(binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 87 | binding_flags_.reserve(binding_count_); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 88 | binding_to_index_map_.reserve(binding_count_); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 89 | for (const auto &input_binding : sorted_bindings) { |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 90 | // 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] | 91 | const auto binding_num = input_binding.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 92 | binding_to_index_map_[binding_num] = index++; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 93 | bindings_.emplace_back(input_binding.layout_binding); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 94 | auto &binding_info = bindings_.back(); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 95 | binding_flags_.emplace_back(input_binding.binding_flags); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 96 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 97 | descriptor_count_ += binding_info.descriptorCount; |
| 98 | if (binding_info.descriptorCount > 0) { |
| 99 | non_empty_bindings_.insert(binding_num); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 100 | } |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 101 | |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 102 | if (IsDynamicDescriptor(binding_info.descriptorType)) { |
sfricke-samsung | 0d00aed | 2021-03-08 23:31:17 -0800 | [diff] [blame] | 103 | dynamic_descriptor_count_ += binding_info.descriptorCount; |
| 104 | } |
| 105 | |
| 106 | // Get stats depending on descriptor type for caching later |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 107 | if (IsBufferDescriptor(binding_info.descriptorType)) { |
| 108 | if (IsDynamicDescriptor(binding_info.descriptorType)) { |
| 109 | binding_type_stats_.dynamic_buffer_count++; |
| 110 | } else { |
| 111 | binding_type_stats_.non_dynamic_buffer_count++; |
| 112 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 113 | } |
| 114 | } |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 115 | assert(bindings_.size() == binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 116 | assert(binding_flags_.size() == binding_count_); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 117 | uint32_t global_index = 0; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 118 | global_index_range_.reserve(binding_count_); |
| 119 | // 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] | 120 | for (uint32_t i = 0; i < binding_count_; ++i) { |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 121 | auto final_index = global_index + bindings_[i].descriptorCount; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 122 | global_index_range_.emplace_back(global_index, final_index); |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 123 | global_index = final_index; |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 124 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 125 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 126 | |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 127 | size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const { |
| 128 | hash_util::HashCombiner hc; |
| 129 | hc << flags_; |
| 130 | hc.Combine(bindings_); |
John Zulauf | 223b69d | 2018-11-09 16:00:59 -0700 | [diff] [blame] | 131 | hc.Combine(binding_flags_); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 132 | return hc.Value(); |
| 133 | } |
| 134 | // |
| 135 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 136 | // Return valid index or "end" i.e. binding_count_; |
| 137 | // The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given |
| 138 | // Common code for all binding lookups. |
| 139 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const { |
| 140 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 141 | if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second; |
| 142 | return GetBindingCount(); |
| 143 | } |
| 144 | VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex( |
| 145 | const uint32_t index) const { |
| 146 | if (index >= bindings_.size()) return nullptr; |
| 147 | return bindings_[index].ptr(); |
| 148 | } |
| 149 | // Return descriptorCount for given index, 0 if index is unavailable |
| 150 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const { |
| 151 | if (index >= bindings_.size()) return 0; |
| 152 | return bindings_[index].descriptorCount; |
| 153 | } |
| 154 | // For the given index, return descriptorType |
| 155 | VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const { |
| 156 | assert(index < bindings_.size()); |
| 157 | if (index < bindings_.size()) return bindings_[index].descriptorType; |
| 158 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 159 | } |
| 160 | // For the given index, return stageFlags |
| 161 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const { |
| 162 | assert(index < bindings_.size()); |
| 163 | if (index < bindings_.size()) return bindings_[index].stageFlags; |
| 164 | return VkShaderStageFlags(0); |
| 165 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 166 | // Return binding flags for given index, 0 if index is unavailable |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 167 | VkDescriptorBindingFlags cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex(const uint32_t index) const { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 168 | if (index >= binding_flags_.size()) return 0; |
| 169 | return binding_flags_[index]; |
| 170 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 171 | |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 172 | const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromIndex(uint32_t index) const { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 173 | const static IndexRange k_invalid_range = {0xFFFFFFFF, 0xFFFFFFFF}; |
| 174 | if (index >= binding_flags_.size()) return k_invalid_range; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 175 | return global_index_range_[index]; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 176 | } |
| 177 | |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 178 | // For the given binding, return the global index range (half open) |
| 179 | // 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] | 180 | const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding( |
| 181 | const uint32_t binding) const { |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 182 | uint32_t index = GetIndexFromBinding(binding); |
| 183 | return GetGlobalIndexRangeFromIndex(index); |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | // For given binding, return ptr to ImmutableSampler array |
| 187 | VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const { |
| 188 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 189 | if (bi_itr != binding_to_index_map_.end()) { |
| 190 | return bindings_[bi_itr->second].pImmutableSamplers; |
| 191 | } |
| 192 | return nullptr; |
| 193 | } |
| 194 | // Move to next valid binding having a non-zero binding count |
| 195 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const { |
| 196 | auto it = non_empty_bindings_.upper_bound(binding); |
| 197 | assert(it != non_empty_bindings_.cend()); |
| 198 | if (it != non_empty_bindings_.cend()) return *it; |
| 199 | return GetMaxBinding() + 1; |
| 200 | } |
| 201 | // For given index, return ptr to ImmutableSampler array |
| 202 | VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 203 | if (index < bindings_.size()) { |
| 204 | return bindings_[index].pImmutableSamplers; |
| 205 | } |
| 206 | return nullptr; |
| 207 | } |
John Zulauf | 9ce3b25 | 2019-06-06 15:20:22 -0600 | [diff] [blame] | 208 | |
| 209 | // If our layout is compatible with rh_ds_layout, return true. |
| 210 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *rh_ds_layout) const { |
| 211 | bool compatible = (this == rh_ds_layout) || (GetLayoutDef() == rh_ds_layout->GetLayoutDef()); |
| 212 | return compatible; |
| 213 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 214 | |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 215 | // TODO: Find a way to add smarts to the autogenerated version of this |
| 216 | static std::string smart_string_VkShaderStageFlags(VkShaderStageFlags stage_flags) { |
| 217 | if (stage_flags == VK_SHADER_STAGE_ALL) { |
| 218 | return string_VkShaderStageFlagBits(VK_SHADER_STAGE_ALL); |
| 219 | } |
| 220 | |
| 221 | return string_VkShaderStageFlags(stage_flags); |
| 222 | } |
| 223 | |
| 224 | // If our layout is compatible with bound_dsl, return true, |
| 225 | // else return false and fill in error_msg will description of what causes incompatibility |
| 226 | bool cvdescriptorset::VerifySetLayoutCompatibility(const debug_report_data *report_data, DescriptorSetLayout const *layout_dsl, |
| 227 | DescriptorSetLayout const *bound_dsl, std::string *error_msg) { |
| 228 | // Short circuit the detailed check. |
| 229 | if (layout_dsl->IsCompatible(bound_dsl)) return true; |
| 230 | |
| 231 | // Do a detailed compatibility check of this lhs def (referenced by layout_dsl), vs. the rhs (layout and def) |
John Zulauf | 9ce3b25 | 2019-06-06 15:20:22 -0600 | [diff] [blame] | 232 | // Should only be run if trivial accept has failed, and in that context should return false. |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 233 | VkDescriptorSetLayout layout_dsl_handle = layout_dsl->GetDescriptorSetLayout(); |
| 234 | VkDescriptorSetLayout bound_dsl_handle = bound_dsl->GetDescriptorSetLayout(); |
| 235 | DescriptorSetLayoutDef const *layout_ds_layout_def = layout_dsl->GetLayoutDef(); |
| 236 | DescriptorSetLayoutDef const *bound_ds_layout_def = bound_dsl->GetLayoutDef(); |
John Zulauf | 9ce3b25 | 2019-06-06 15:20:22 -0600 | [diff] [blame] | 237 | |
| 238 | // Check descriptor counts |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 239 | const auto bound_total_count = bound_ds_layout_def->GetTotalDescriptorCount(); |
| 240 | if (layout_ds_layout_def->GetTotalDescriptorCount() != bound_ds_layout_def->GetTotalDescriptorCount()) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 241 | std::stringstream error_str; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 242 | error_str << report_data->FormatHandle(layout_dsl_handle) << " from pipeline layout has " |
| 243 | << layout_ds_layout_def->GetTotalDescriptorCount() << " total descriptors, but " |
| 244 | << report_data->FormatHandle(bound_dsl_handle) << ", which is bound, has " << bound_total_count |
| 245 | << " total descriptors."; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 246 | *error_msg = error_str.str(); |
| 247 | return false; // trivial fail case |
| 248 | } |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 249 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 250 | // Descriptor counts match so need to go through bindings one-by-one |
| 251 | // and verify that type and stageFlags match |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 252 | for (const auto &layout_binding : layout_ds_layout_def->GetBindings()) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 253 | // TODO : Do we also need to check immutable samplers? |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 254 | const auto bound_binding = bound_ds_layout_def->GetBindingInfoFromBinding(layout_binding.binding); |
| 255 | if (layout_binding.descriptorCount != bound_binding->descriptorCount) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 256 | std::stringstream error_str; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 257 | error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle) |
| 258 | << " from pipeline layout has a descriptorCount of " << layout_binding.descriptorCount << " but binding " |
| 259 | << layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle) |
| 260 | << ", which is bound, has a descriptorCount of " << bound_binding->descriptorCount; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 261 | *error_msg = error_str.str(); |
| 262 | return false; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 263 | } else if (layout_binding.descriptorType != bound_binding->descriptorType) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 264 | std::stringstream error_str; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 265 | error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle) |
| 266 | << " from pipeline layout is type '" << string_VkDescriptorType(layout_binding.descriptorType) |
| 267 | << "' but binding " << layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle) |
| 268 | << ", which is bound, is type '" << string_VkDescriptorType(bound_binding->descriptorType) << "'"; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 269 | *error_msg = error_str.str(); |
| 270 | return false; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 271 | } else if (layout_binding.stageFlags != bound_binding->stageFlags) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 272 | std::stringstream error_str; |
John Zulauf | f43695f | 2019-09-13 17:56:26 -0600 | [diff] [blame] | 273 | error_str << "Binding " << layout_binding.binding << " for " << report_data->FormatHandle(layout_dsl_handle) |
| 274 | << " from pipeline layout has stageFlags " << smart_string_VkShaderStageFlags(layout_binding.stageFlags) |
| 275 | << " but binding " << layout_binding.binding << " for " << report_data->FormatHandle(bound_dsl_handle) |
| 276 | << ", which is bound, has stageFlags " << smart_string_VkShaderStageFlags(bound_binding->stageFlags); |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 277 | *error_msg = error_str.str(); |
| 278 | return false; |
| 279 | } |
| 280 | } |
Tony-LunarG | 692b8b4 | 2019-09-30 16:07:26 -0600 | [diff] [blame] | 281 | |
| 282 | const auto &ds_layout_flags = layout_ds_layout_def->GetBindingFlags(); |
| 283 | const auto &bound_layout_flags = bound_ds_layout_def->GetBindingFlags(); |
| 284 | if (bound_layout_flags != ds_layout_flags) { |
| 285 | std::stringstream error_str; |
| 286 | assert(ds_layout_flags.size() == bound_layout_flags.size()); |
| 287 | size_t i; |
| 288 | for (i = 0; i < ds_layout_flags.size(); i++) { |
| 289 | if (ds_layout_flags[i] != bound_layout_flags[i]) break; |
| 290 | } |
| 291 | error_str << report_data->FormatHandle(layout_dsl_handle) |
| 292 | << " from pipeline layout does not have the same binding flags at binding " << i << " ( " |
| 293 | << string_VkDescriptorBindingFlagsEXT(ds_layout_flags[i]) << " ) as " |
| 294 | << report_data->FormatHandle(bound_dsl_handle) << " ( " |
| 295 | << string_VkDescriptorBindingFlagsEXT(bound_layout_flags[i]) << " ), which is bound"; |
| 296 | *error_msg = error_str.str(); |
| 297 | return false; |
| 298 | } |
| 299 | |
John Zulauf | 9ce3b25 | 2019-06-06 15:20:22 -0600 | [diff] [blame] | 300 | // No detailed check should succeed if the trivial check failed -- or the dictionary has failed somehow. |
| 301 | bool compatible = true; |
| 302 | assert(!compatible); |
| 303 | return compatible; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const { |
| 307 | if (!binding_to_index_map_.count(binding + 1)) return false; |
| 308 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 309 | if (bi_itr != binding_to_index_map_.end()) { |
| 310 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 311 | if (next_bi_itr != binding_to_index_map_.end()) { |
| 312 | auto type = bindings_[bi_itr->second].descriptorType; |
| 313 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 314 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 315 | auto flags = binding_flags_[bi_itr->second]; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 316 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 317 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 318 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) || |
| 319 | (flags != binding_flags_[next_bi_itr->second])) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 320 | return false; |
| 321 | } |
| 322 | return true; |
| 323 | } |
| 324 | } |
| 325 | return false; |
| 326 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 327 | |
| 328 | // The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the |
| 329 | // handle invariant portion |
| 330 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, |
| 331 | const VkDescriptorSetLayout layout) |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 332 | : BASE_NODE(layout, kVulkanObjectTypeDescriptorSetLayout), layout_id_(GetCanonicalId(p_create_info)) {} |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 333 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 334 | // Validate descriptor set layout create info |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 335 | bool cvdescriptorset::ValidateDescriptorSetLayoutCreateInfo( |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 336 | const ValidationObject *val_obj, const VkDescriptorSetLayoutCreateInfo *create_info, const bool push_descriptor_ext, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 337 | const uint32_t max_push_descriptors, const bool descriptor_indexing_ext, |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 338 | const VkPhysicalDeviceVulkan12Features *core12_features, |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 339 | const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features, |
ziga-lunarg | 637356a | 2021-07-19 12:36:34 +0200 | [diff] [blame] | 340 | const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props, |
| 341 | const VkPhysicalDeviceAccelerationStructureFeaturesKHR *acceleration_structure_features, |
| 342 | const DeviceExtensions *device_extensions) { |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 343 | bool skip = false; |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 344 | layer_data::unordered_set<uint32_t> bindings; |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 345 | uint64_t total_descriptors = 0; |
| 346 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 347 | const auto *flags_create_info = LvlFindInChain<VkDescriptorSetLayoutBindingFlagsCreateInfo>(create_info->pNext); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 348 | |
| 349 | 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] | 350 | if (push_descriptor_set && !push_descriptor_ext) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 351 | skip |= val_obj->LogError( |
| 352 | val_obj->device, kVUID_Core_DrawState_ExtensionNotEnabled, |
| 353 | "vkCreateDescriptorSetLayout(): Attempted to use %s in %s but its required extension %s has not been enabled.\n", |
| 354 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR", "VkDescriptorSetLayoutCreateInfo::flags", |
| 355 | VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 358 | const bool update_after_bind_set = !!(create_info->flags & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 359 | if (update_after_bind_set && !descriptor_indexing_ext) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 360 | skip |= val_obj->LogError( |
| 361 | val_obj->device, kVUID_Core_DrawState_ExtensionNotEnabled, |
| 362 | "vkCreateDescriptorSetLayout(): Attemped to use %s in %s but its required extension %s has not been enabled.\n", |
| 363 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT", "VkDescriptorSetLayoutCreateInfo::flags", |
| 364 | VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 365 | } |
| 366 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 367 | auto valid_type = [push_descriptor_set](const VkDescriptorType type) { |
| 368 | return !push_descriptor_set || |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 369 | ((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] | 370 | (type != VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 371 | }; |
| 372 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 373 | uint32_t max_binding = 0; |
| 374 | |
ziga-lunarg | 185ef28 | 2021-07-19 13:13:28 +0200 | [diff] [blame] | 375 | uint32_t update_after_bind = create_info->bindingCount; |
| 376 | uint32_t uniform_buffer_dynamic = create_info->bindingCount; |
| 377 | uint32_t storage_buffer_dynamic = create_info->bindingCount; |
| 378 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 379 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 380 | const auto &binding_info = create_info->pBindings[i]; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 381 | max_binding = std::max(max_binding, binding_info.binding); |
| 382 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 383 | if (!bindings.insert(binding_info.binding).second) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 384 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-binding-00279", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 385 | "vkCreateDescriptorSetLayout(): pBindings[%u] has duplicated binding number (%u).", i, |
| 386 | binding_info.binding); |
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 | if (!valid_type(binding_info.descriptorType)) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 389 | skip |= val_obj->LogError(val_obj->device, |
| 390 | (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) |
| 391 | ? "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208" |
| 392 | : "VUID-VkDescriptorSetLayoutCreateInfo-flags-00280", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 393 | "vkCreateDescriptorSetLayout(): pBindings[%u] has invalid type %s , for push descriptors.", i, |
| 394 | string_VkDescriptorType(binding_info.descriptorType)); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 395 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 396 | |
| 397 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
sfricke-samsung | c1e27c3 | 2021-01-16 09:32:49 -0800 | [diff] [blame] | 398 | if (!inline_uniform_block_features->inlineUniformBlock) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 399 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-04604", |
| 400 | "vkCreateDescriptorSetLayout(): pBindings[%u] is creating VkDescriptorSetLayout with " |
| 401 | "descriptor type VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT " |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 402 | "but the inlineUniformBlock feature is not enabled", |
| 403 | i); |
Tony-LunarG | d6744bc | 2019-08-23 09:57:10 -0600 | [diff] [blame] | 404 | } else { |
| 405 | if ((binding_info.descriptorCount % 4) != 0) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 406 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-02209", |
| 407 | "vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorCount =(%" PRIu32 |
| 408 | ") but must be a multiple of 4", |
| 409 | i, binding_info.descriptorCount); |
Tony-LunarG | d6744bc | 2019-08-23 09:57:10 -0600 | [diff] [blame] | 410 | } |
| 411 | if (binding_info.descriptorCount > inline_uniform_block_props->maxInlineUniformBlockSize) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 412 | skip |= |
| 413 | val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-02210", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 414 | "vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorCount =(%" PRIu32 |
| 415 | ") but must be less than or equal to maxInlineUniformBlockSize (%u)", |
| 416 | i, binding_info.descriptorCount, inline_uniform_block_props->maxInlineUniformBlockSize); |
Tony-LunarG | d6744bc | 2019-08-23 09:57:10 -0600 | [diff] [blame] | 417 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 418 | } |
ziga-lunarg | 185ef28 | 2021-07-19 13:13:28 +0200 | [diff] [blame] | 419 | } else if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) { |
| 420 | uniform_buffer_dynamic = i; |
| 421 | } else if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { |
| 422 | storage_buffer_dynamic = i; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 423 | } |
| 424 | |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 425 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || |
| 426 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) && |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 427 | binding_info.pImmutableSamplers && IsExtEnabled(device_extensions->vk_ext_custom_border_color)) { |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 428 | const CoreChecks *core_checks = reinterpret_cast<const CoreChecks *>(val_obj); |
| 429 | for (uint32_t j = 0; j < binding_info.descriptorCount; j++) { |
| 430 | const SAMPLER_STATE *sampler_state = core_checks->GetSamplerState(binding_info.pImmutableSamplers[j]); |
| 431 | if (sampler_state && (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 432 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT)) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 433 | skip |= val_obj->LogError( |
| 434 | val_obj->device, "VUID-VkDescriptorSetLayoutBinding-pImmutableSamplers-04009", |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 435 | "vkCreateDescriptorSetLayout(): pBindings[%u].pImmutableSamplers[%u] has VkSampler %s" |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 436 | " presented as immutable has a custom border color", |
Jeremy Gebben | da6b48f | 2021-05-13 10:46:18 -0600 | [diff] [blame] | 437 | i, j, val_obj->report_data->FormatHandle(binding_info.pImmutableSamplers[j]).c_str()); |
Tony-LunarG | 7337b31 | 2020-04-15 16:40:25 -0600 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
ziga-lunarg | 6d77079 | 2021-07-19 11:27:18 +0200 | [diff] [blame] | 442 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_MUTABLE_VALVE && binding_info.pImmutableSamplers != nullptr) { |
| 443 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBinding-descriptorType-04605", |
| 444 | "vkCreateDescriptorSetLayout(): pBindings[%u] has descriptorType " |
| 445 | "VK_DESCRIPTOR_TYPE_MUTABLE_VALVE but pImmutableSamplers is not NULL.", |
| 446 | i); |
| 447 | } |
| 448 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 449 | total_descriptors += binding_info.descriptorCount; |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 450 | } |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 451 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 452 | if (flags_create_info) { |
| 453 | if (flags_create_info->bindingCount != 0 && flags_create_info->bindingCount != create_info->bindingCount) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 454 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-bindingCount-03002", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 455 | "vkCreateDescriptorSetLayout(): VkDescriptorSetLayoutCreateInfo::bindingCount (%d) != " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 456 | "VkDescriptorSetLayoutBindingFlagsCreateInfo::bindingCount (%d)", |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 457 | create_info->bindingCount, flags_create_info->bindingCount); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | if (flags_create_info->bindingCount == create_info->bindingCount) { |
| 461 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
| 462 | const auto &binding_info = create_info->pBindings[i]; |
| 463 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 464 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT) { |
ziga-lunarg | 185ef28 | 2021-07-19 13:13:28 +0200 | [diff] [blame] | 465 | update_after_bind = i; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 466 | if (!update_after_bind_set) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 467 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-flags-03000", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 468 | "vkCreateDescriptorSetLayout(): pBindings[%u] does not have " |
| 469 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT.", |
| 470 | i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 474 | !core12_features->descriptorBindingUniformBufferUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 475 | skip |= val_obj->LogError( |
| 476 | val_obj->device, |
| 477 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 478 | "descriptorBindingUniformBufferUpdateAfterBind-03005", |
| 479 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 480 | "for %s since descriptorBindingUniformBufferUpdateAfterBind is not enabled.", |
| 481 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 482 | } |
| 483 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER || |
| 484 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER || |
| 485 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 486 | !core12_features->descriptorBindingSampledImageUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 487 | skip |= val_obj->LogError( |
| 488 | val_obj->device, |
| 489 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 490 | "descriptorBindingSampledImageUpdateAfterBind-03006", |
| 491 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 492 | "for %s since descriptorBindingSampledImageUpdateAfterBind is not enabled.", |
| 493 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 494 | } |
| 495 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 496 | !core12_features->descriptorBindingStorageImageUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 497 | skip |= val_obj->LogError( |
| 498 | val_obj->device, |
| 499 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 500 | "descriptorBindingStorageImageUpdateAfterBind-03007", |
| 501 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 502 | "for %s since descriptorBindingStorageImageUpdateAfterBind is not enabled.", |
| 503 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 504 | } |
| 505 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 506 | !core12_features->descriptorBindingStorageBufferUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 507 | skip |= val_obj->LogError( |
| 508 | val_obj->device, |
| 509 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 510 | "descriptorBindingStorageBufferUpdateAfterBind-03008", |
| 511 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 512 | "for %s since descriptorBindingStorageBufferUpdateAfterBind is not enabled.", |
| 513 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 514 | } |
| 515 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 516 | !core12_features->descriptorBindingUniformTexelBufferUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 517 | skip |= val_obj->LogError( |
| 518 | val_obj->device, |
| 519 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 520 | "descriptorBindingUniformTexelBufferUpdateAfterBind-03009", |
| 521 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 522 | "for %s since descriptorBindingUniformTexelBufferUpdateAfterBind is not enabled.", |
| 523 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 524 | } |
| 525 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER && |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 526 | !core12_features->descriptorBindingStorageTexelBufferUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 527 | skip |= val_obj->LogError( |
| 528 | val_obj->device, |
| 529 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 530 | "descriptorBindingStorageTexelBufferUpdateAfterBind-03010", |
| 531 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 532 | "for %s since descriptorBindingStorageTexelBufferUpdateAfterBind is not enabled.", |
| 533 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 534 | } |
| 535 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT || |
| 536 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 537 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 538 | skip |= val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-None-03011", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 539 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have " |
| 540 | "VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT for %s.", |
| 541 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 542 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 543 | |
| 544 | if (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT && |
| 545 | !inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 546 | skip |= val_obj->LogError( |
| 547 | val_obj->device, |
| 548 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 549 | "descriptorBindingInlineUniformBlockUpdateAfterBind-02211", |
| 550 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 551 | "for %s since descriptorBindingInlineUniformBlockUpdateAfterBind is not enabled.", |
| 552 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 553 | } |
ziga-lunarg | 637356a | 2021-07-19 12:36:34 +0200 | [diff] [blame] | 554 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR || |
| 555 | binding_info.descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV) && |
| 556 | !acceleration_structure_features->descriptorBindingAccelerationStructureUpdateAfterBind) { |
| 557 | skip |= val_obj->LogError(val_obj->device, |
| 558 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-" |
| 559 | "descriptorBindingAccelerationStructureUpdateAfterBind-03570", |
| 560 | "vkCreateDescriptorSetLayout(): pBindings[%" PRIu32 |
| 561 | "] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 562 | "for %s if " |
| 563 | "VkPhysicalDeviceAccelerationStructureFeaturesKHR::" |
| 564 | "descriptorBindingAccelerationStructureUpdateAfterBind is not enabled.", |
| 565 | i, string_VkDescriptorType(binding_info.descriptorType)); |
| 566 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 567 | } |
| 568 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 569 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 570 | if (!core12_features->descriptorBindingUpdateUnusedWhilePending) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 571 | skip |= val_obj->LogError( |
| 572 | val_obj->device, |
Mike Schuchardt | 65847d9 | 2019-12-20 13:50:47 -0800 | [diff] [blame] | 573 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingUpdateUnusedWhilePending-03012", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 574 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have " |
| 575 | "VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT for %s since " |
| 576 | "descriptorBindingUpdateUnusedWhilePending is not enabled.", |
| 577 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 581 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 582 | if (!core12_features->descriptorBindingPartiallyBound) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 583 | skip |= val_obj->LogError( |
| 584 | val_obj->device, |
| 585 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingPartiallyBound-03013", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 586 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT for " |
| 587 | "%s since descriptorBindingPartiallyBound is not enabled.", |
| 588 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 592 | if (flags_create_info->pBindingFlags[i] & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 593 | if (binding_info.binding != max_binding) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 594 | skip |= val_obj->LogError( |
| 595 | val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03004", |
| 596 | "vkCreateDescriptorSetLayout(): pBindings[%u] has VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT " |
| 597 | "but %u is the largest value of all the bindings.", |
| 598 | i, binding_info.binding); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 599 | } |
| 600 | |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 601 | if (!core12_features->descriptorBindingVariableDescriptorCount) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 602 | skip |= val_obj->LogError( |
| 603 | val_obj->device, |
Mike Schuchardt | 65847d9 | 2019-12-20 13:50:47 -0800 | [diff] [blame] | 604 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingVariableDescriptorCount-03014", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 605 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have " |
| 606 | "VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for %s since " |
| 607 | "descriptorBindingVariableDescriptorCount is not enabled.", |
| 608 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 609 | } |
sfricke-samsung | 4ba7d6e | 2021-03-06 20:56:35 -0800 | [diff] [blame] | 610 | if ((binding_info.descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) || |
| 611 | (binding_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 612 | skip |= val_obj->LogError(val_obj->device, |
| 613 | "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03015", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 614 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have " |
| 615 | "VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for %s.", |
| 616 | i, string_VkDescriptorType(binding_info.descriptorType)); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | if (push_descriptor_set && |
| 621 | (flags_create_info->pBindingFlags[i] & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 622 | (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | |
| 623 | VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT))) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 624 | skip |= val_obj->LogError( |
| 625 | val_obj->device, "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-flags-03003", |
| 626 | "vkCreateDescriptorSetLayout(): pBindings[%u] can't have VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT, " |
| 627 | "VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT, or " |
| 628 | "VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT for with " |
| 629 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR.", |
| 630 | i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | |
ziga-lunarg | 185ef28 | 2021-07-19 13:13:28 +0200 | [diff] [blame] | 636 | if (update_after_bind < create_info->bindingCount) { |
| 637 | if (uniform_buffer_dynamic < create_info->bindingCount) { |
| 638 | skip |= |
| 639 | val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-descriptorType-03001", |
| 640 | "vkCreateDescriptorSetLayout(): binding (%" PRIi32 |
| 641 | ") has VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 642 | "flag, but binding (%" PRIi32 ") has descriptor type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC.", |
| 643 | update_after_bind, uniform_buffer_dynamic); |
| 644 | } |
| 645 | if (storage_buffer_dynamic < create_info->bindingCount) { |
| 646 | skip |= |
| 647 | val_obj->LogError(val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-descriptorType-03001", |
| 648 | "vkCreateDescriptorSetLayout(): binding (%" PRIi32 |
| 649 | ") has VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT " |
| 650 | "flag, but binding (%" PRIi32 ") has descriptor type VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC.", |
| 651 | update_after_bind, storage_buffer_dynamic); |
| 652 | } |
| 653 | } |
| 654 | |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 655 | if ((push_descriptor_set) && (total_descriptors > max_push_descriptors)) { |
| 656 | const char *undefined = push_descriptor_ext ? "" : " -- undefined"; |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 657 | skip |= val_obj->LogError( |
| 658 | val_obj->device, "VUID-VkDescriptorSetLayoutCreateInfo-flags-00281", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 659 | "vkCreateDescriptorSetLayout(): for push descriptor, total descriptor count in layout (%" PRIu64 |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 660 | ") must not be greater than VkPhysicalDevicePushDescriptorPropertiesKHR::maxPushDescriptors (%" PRIu32 "%s).", |
| 661 | total_descriptors, max_push_descriptors, undefined); |
John Zulauf | 0fdeab3 | 2018-01-23 11:27:35 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 664 | return skip; |
| 665 | } |
| 666 | |
Mark Lobodzinski | e12b6e3 | 2020-06-29 11:44:15 -0600 | [diff] [blame] | 667 | void cvdescriptorset::AllocateDescriptorSetsData::Init(uint32_t count) { |
| 668 | layout_nodes.resize(count); |
Mark Lobodzinski | e12b6e3 | 2020-06-29 11:44:15 -0600 | [diff] [blame] | 669 | } |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 670 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 671 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, DESCRIPTOR_POOL_STATE *pool_state, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 672 | const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count, |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 673 | const cvdescriptorset::DescriptorSet::StateTracker *state_data) |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 674 | : BASE_NODE(set, kVulkanObjectTypeDescriptorSet), |
| 675 | some_update_(false), |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 676 | pool_state_(pool_state), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 677 | layout_(layout), |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 678 | state_data_(state_data), |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 679 | variable_count_(variable_count), |
| 680 | change_count_(0) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 681 | if (pool_state_) { |
| 682 | pool_state_->AddParent(this); |
| 683 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 684 | // Foreach binding, create default descriptors of given type |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 685 | descriptors_.reserve(layout_->GetTotalDescriptorCount()); |
| 686 | descriptor_store_.resize(layout_->GetTotalDescriptorCount()); |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 687 | auto free_descriptor = descriptor_store_.data(); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 688 | for (uint32_t i = 0; i < layout_->GetBindingCount(); ++i) { |
| 689 | auto type = layout_->GetTypeFromIndex(i); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 690 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 691 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 692 | auto immut_sampler = layout_->GetImmutableSamplerPtrFromIndex(i); |
| 693 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 694 | if (immut_sampler) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 695 | descriptors_.emplace_back(new ((free_descriptor++)->Sampler()) |
| 696 | SamplerDescriptor(state_data, immut_sampler + di)); |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 697 | some_update_ = true; // Immutable samplers are updated at creation |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 698 | } else { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 699 | descriptors_.emplace_back(new ((free_descriptor++)->Sampler()) SamplerDescriptor(state_data, nullptr)); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 700 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 701 | descriptors_.back()->AddParent(this); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 702 | } |
| 703 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 704 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 705 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 706 | auto immut = layout_->GetImmutableSamplerPtrFromIndex(i); |
| 707 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 708 | if (immut) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 709 | descriptors_.emplace_back(new ((free_descriptor++)->ImageSampler()) |
| 710 | ImageSamplerDescriptor(state_data, immut + di)); |
Tobin Ehlis | 082c751 | 2017-05-08 11:24:57 -0600 | [diff] [blame] | 711 | some_update_ = true; // Immutable samplers are updated at creation |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 712 | } else { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 713 | descriptors_.emplace_back(new ((free_descriptor++)->ImageSampler()) |
| 714 | ImageSamplerDescriptor(state_data, nullptr)); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 715 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 716 | descriptors_.back()->AddParent(this); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 717 | } |
| 718 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 719 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 720 | // ImageDescriptors |
| 721 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 722 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 723 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 724 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 725 | descriptors_.emplace_back(new ((free_descriptor++)->Image()) ImageDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 726 | descriptors_.back()->AddParent(this); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 727 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 728 | break; |
| 729 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 730 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 731 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 732 | descriptors_.emplace_back(new ((free_descriptor++)->Texel()) TexelDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 733 | descriptors_.back()->AddParent(this); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 734 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 735 | break; |
sfricke-samsung | 4ca3565 | 2021-03-05 02:22:10 -0800 | [diff] [blame] | 736 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 737 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 738 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 739 | descriptors_.emplace_back(new ((free_descriptor++)->Buffer()) BufferDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 740 | descriptors_.back()->AddParent(this); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 741 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 742 | break; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 743 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 744 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 745 | descriptors_.emplace_back(new ((free_descriptor++)->InlineUniform()) InlineUniformDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 746 | descriptors_.back()->AddParent(this); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 747 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 748 | break; |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 749 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 750 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 751 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
John Zulauf | e4850d4 | 2019-12-30 16:10:55 -0700 | [diff] [blame] | 752 | descriptors_.emplace_back(new ((free_descriptor++)->AccelerationStructure()) |
| 753 | AccelerationStructureDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 754 | descriptors_.back()->AddParent(this); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 755 | } |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 756 | break; |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 757 | case VK_DESCRIPTOR_TYPE_MUTABLE_VALVE: |
| 758 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 759 | descriptors_.emplace_back(new ((free_descriptor++)->InlineUniform()) MutableDescriptor()); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 760 | descriptors_.back()->AddParent(this); |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 761 | } |
| 762 | break; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 763 | default: |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 764 | if (IsDynamicDescriptor(type) && IsBufferDescriptor(type)) { |
| 765 | for (uint32_t di = 0; di < layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 766 | dynamic_offset_idx_to_descriptor_list_.push_back(descriptors_.size()); |
| 767 | descriptors_.emplace_back(new ((free_descriptor++)->Buffer()) BufferDescriptor(type)); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 768 | descriptors_.back()->AddParent(this); |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 769 | } |
| 770 | } else { |
| 771 | assert(0); // Bad descriptor type specified |
| 772 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 773 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 777 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 778 | void cvdescriptorset::DescriptorSet::Destroy() { |
| 779 | if (pool_state_) { |
| 780 | pool_state_->RemoveParent(this); |
| 781 | } |
| 782 | for (auto &desc: descriptors_) { |
| 783 | desc->RemoveParent(this); |
| 784 | } |
| 785 | BASE_NODE::Destroy(); |
| 786 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 787 | |
Jeremy Gebben | 90ce416 | 2021-08-25 14:23:07 -0600 | [diff] [blame] | 788 | static std::string StringDescriptorReqViewType(DescriptorReqFlags req) { |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 789 | std::string result(""); |
Mark Lobodzinski | 29f451a | 2020-02-10 16:15:30 -0700 | [diff] [blame] | 790 | for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; i++) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 791 | if (req & (1 << i)) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 792 | if (result.size()) result += ", "; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 793 | result += string_VkImageViewType(VkImageViewType(i)); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 797 | if (!result.size()) result = "(none)"; |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 798 | |
| 799 | return result; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 800 | } |
| 801 | |
Jeremy Gebben | 90ce416 | 2021-08-25 14:23:07 -0600 | [diff] [blame] | 802 | static char const *StringDescriptorReqComponentType(DescriptorReqFlags req) { |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 803 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_SINT) return "SINT"; |
| 804 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_UINT) return "UINT"; |
| 805 | if (req & DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT) return "FLOAT"; |
| 806 | return "(none)"; |
| 807 | } |
| 808 | |
Jeff Bolz | 6cede83 | 2019-08-09 23:30:39 -0500 | [diff] [blame] | 809 | unsigned DescriptorRequirementsBitsFromFormat(VkFormat fmt) { |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 810 | if (FormatIsSInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_SINT; |
| 811 | if (FormatIsUInt(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_UINT; |
sfricke-samsung | ed028b0 | 2021-09-06 23:14:51 -0700 | [diff] [blame] | 812 | // Formats such as VK_FORMAT_D16_UNORM_S8_UINT are both |
Chris Forbes | da01e8d | 2018-08-27 15:36:57 -0700 | [diff] [blame] | 813 | if (FormatIsDepthAndStencil(fmt)) return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT | DESCRIPTOR_REQ_COMPONENT_TYPE_UINT; |
| 814 | if (fmt == VK_FORMAT_UNDEFINED) return 0; |
| 815 | // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader. |
| 816 | return DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT; |
| 817 | } |
| 818 | |
Tobin Ehlis | 3066db6 | 2016-08-22 08:12:23 -0600 | [diff] [blame] | 819 | // 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] | 820 | // This includes validating that all descriptors in the given bindings are updated, |
| 821 | // that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers. |
| 822 | // Return true if state is acceptable, or false and write an error message into error string |
locke-lunarg | b8d7a7a | 2020-10-25 16:01:52 -0600 | [diff] [blame] | 823 | bool CoreChecks::ValidateDrawState(const DescriptorSet *descriptor_set, const BindingReqMap &bindings, |
| 824 | const std::vector<uint32_t> &dynamic_offsets, const CMD_BUFFER_STATE *cb_node, |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 825 | const std::vector<IMAGE_VIEW_STATE *> *attachments, const std::vector<SUBPASS_INFO> *subpasses, |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 826 | const char *caller, const DrawDispatchVuid &vuids) const { |
Jeremy Gebben | 37ed31e | 2021-04-23 12:12:10 -0600 | [diff] [blame] | 827 | layer_data::optional<layer_data::unordered_map<VkImageView, VkImageLayout>> checked_layouts; |
Karl Schultz | 2171f93 | 2021-03-19 10:47:01 -0600 | [diff] [blame] | 828 | if (descriptor_set->GetTotalDescriptorCount() > cvdescriptorset::PrefilterBindRequestMap::kManyDescriptors_) { |
| 829 | checked_layouts.emplace(); |
| 830 | } |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 831 | bool result = false; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 832 | VkFramebuffer framebuffer = cb_node->activeFramebuffer ? cb_node->activeFramebuffer->framebuffer() : VK_NULL_HANDLE; |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 833 | for (const auto &binding_pair : bindings) { |
| 834 | const auto binding = binding_pair.first; |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 835 | DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), binding); |
| 836 | if (binding_it.AtEnd()) { // End at construction is the condition for an invalid binding. |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 837 | auto set = descriptor_set->GetSet(); |
locke-lunarg | 1328e8e | 2020-08-20 12:40:08 -0600 | [diff] [blame] | 838 | result |= LogError(set, vuids.descriptor_valid, |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 839 | "%s encountered the following validation error at %s time: Attempting to " |
| 840 | "validate DrawState for binding #%u which is an invalid binding for this descriptor set.", |
| 841 | report_data->FormatHandle(set).c_str(), caller, binding); |
| 842 | return result; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 843 | } |
Jeff Bolz | 6cede83 | 2019-08-09 23:30:39 -0500 | [diff] [blame] | 844 | |
| 845 | if (binding_it.GetDescriptorBindingFlags() & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 846 | (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT)) { |
Jeff Bolz | 6cede83 | 2019-08-09 23:30:39 -0500 | [diff] [blame] | 847 | // Can't validate the descriptor because it may not have been updated, |
| 848 | // or the view could have been destroyed |
| 849 | continue; |
| 850 | } |
John Zulauf | 81dd1f1 | 2021-01-26 16:49:16 -0700 | [diff] [blame] | 851 | // // This is a record time only path |
| 852 | const bool record_time_validate = true; |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 853 | result |= ValidateDescriptorSetBindingData(cb_node, descriptor_set, dynamic_offsets, binding_pair, framebuffer, attachments, |
Karl Schultz | 2171f93 | 2021-03-19 10:47:01 -0600 | [diff] [blame] | 854 | subpasses, record_time_validate, caller, vuids, checked_layouts); |
unknown | 3087a64 | 2019-09-26 17:21:05 -0600 | [diff] [blame] | 855 | } |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 856 | return result; |
unknown | 3087a64 | 2019-09-26 17:21:05 -0600 | [diff] [blame] | 857 | } |
Jeff Bolz | 6cede83 | 2019-08-09 23:30:39 -0500 | [diff] [blame] | 858 | |
locke-lunarg | b8be822 | 2020-10-20 00:34:37 -0600 | [diff] [blame] | 859 | bool CoreChecks::ValidateDescriptorSetBindingData(const CMD_BUFFER_STATE *cb_node, const DescriptorSet *descriptor_set, |
| 860 | const std::vector<uint32_t> &dynamic_offsets, |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 861 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, |
Mark Lobodzinski | 85ebd40 | 2020-12-03 12:56:07 -0700 | [diff] [blame] | 862 | VkFramebuffer framebuffer, const std::vector<IMAGE_VIEW_STATE *> *attachments, |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 863 | const std::vector<SUBPASS_INFO> *subpasses, bool record_time_validate, |
Karl Schultz | 2171f93 | 2021-03-19 10:47:01 -0600 | [diff] [blame] | 864 | const char *caller, const DrawDispatchVuid &vuids, |
Jeremy Gebben | 37ed31e | 2021-04-23 12:12:10 -0600 | [diff] [blame] | 865 | layer_data::optional<layer_data::unordered_map<VkImageView, VkImageLayout>> &checked_layouts) const { |
unknown | 3087a64 | 2019-09-26 17:21:05 -0600 | [diff] [blame] | 866 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 867 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 868 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 869 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 870 | using SamplerDescriptor = cvdescriptorset::SamplerDescriptor; |
| 871 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 872 | using AccelerationStructureDescriptor = cvdescriptorset::AccelerationStructureDescriptor; |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 873 | const auto binding = binding_info.first; |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 874 | bool skip = false; |
unknown | 3087a64 | 2019-09-26 17:21:05 -0600 | [diff] [blame] | 875 | DescriptorSetLayout::ConstBindingIterator binding_it(descriptor_set->GetLayout().get(), binding); |
| 876 | { |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 877 | // Copy the range, the end range is subject to update based on variable length descriptor arrays. |
| 878 | cvdescriptorset::IndexRange index_range = binding_it.GetGlobalIndexRange(); |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 879 | 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] | 880 | |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 881 | if (binding_it.IsVariableDescriptorCount()) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 882 | // Only validate the first N descriptors if it uses variable_count |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 883 | index_range.end = index_range.start + descriptor_set->GetVariableDescriptorCount(); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 884 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 885 | for (uint32_t i = index_range.start; !skip && i < index_range.end; ++i, ++array_idx) { |
Locke | b994adf | 2019-03-29 23:52:31 -0600 | [diff] [blame] | 886 | uint32_t index = i - index_range.start; |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 887 | const auto *descriptor = descriptor_set->GetDescriptorFromGlobalIndex(i); |
Jeremy Gebben | 550ebbd | 2021-03-11 05:04:52 -0700 | [diff] [blame] | 888 | const auto descriptor_class = descriptor->GetClass(); |
Locke | b994adf | 2019-03-29 23:52:31 -0600 | [diff] [blame] | 889 | |
Jeremy Gebben | 550ebbd | 2021-03-11 05:04:52 -0700 | [diff] [blame] | 890 | if (descriptor_class == DescriptorClass::InlineUniform) { |
Jeff Bolz | 6cede83 | 2019-08-09 23:30:39 -0500 | [diff] [blame] | 891 | // Can't validate the descriptor because it may not have been updated. |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 892 | continue; |
John Zulauf | 382e191 | 2019-06-10 15:27:44 -0600 | [diff] [blame] | 893 | } else if (!descriptor->updated) { |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 894 | auto set = descriptor_set->GetSet(); |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 895 | return LogError( |
| 896 | set, vuids.descriptor_valid, |
| 897 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in binding #%" PRIu32 |
| 898 | " index %" PRIu32 |
| 899 | " is being used in draw but has never been updated via vkUpdateDescriptorSets() or a similar call.", |
| 900 | report_data->FormatHandle(set).c_str(), caller, binding, index); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 901 | } |
| 902 | switch (descriptor_class) { |
| 903 | case DescriptorClass::GeneralBuffer: { |
| 904 | const auto *buffer_desc = static_cast<const BufferDescriptor *>(descriptor); |
| 905 | skip = |
| 906 | ValidateGeneralBufferDescriptor(caller, vuids, cb_node, descriptor_set, *buffer_desc, binding_info, index); |
| 907 | } break; |
| 908 | case DescriptorClass::ImageSampler: { |
| 909 | const auto *image_sampler_desc = static_cast<const ImageSamplerDescriptor *>(descriptor); |
| 910 | skip = ValidateImageDescriptor(caller, vuids, cb_node, descriptor_set, *image_sampler_desc, binding_info, index, |
| 911 | record_time_validate, attachments, subpasses, framebuffer, binding_it.GetType(), |
| 912 | checked_layouts); |
| 913 | if (!skip) { |
| 914 | skip = ValidateSamplerDescriptor(caller, vuids, cb_node, descriptor_set, binding_info, index, |
| 915 | image_sampler_desc->GetSampler(), image_sampler_desc->IsImmutableSampler(), |
| 916 | image_sampler_desc->GetSamplerState()); |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 917 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 918 | } break; |
| 919 | case DescriptorClass::Image: { |
| 920 | const auto *image_desc = static_cast<const ImageDescriptor *>(descriptor); |
| 921 | skip = ValidateImageDescriptor(caller, vuids, cb_node, descriptor_set, *image_desc, binding_info, index, |
| 922 | record_time_validate, attachments, subpasses, framebuffer, binding_it.GetType(), |
| 923 | checked_layouts); |
| 924 | } break; |
| 925 | case DescriptorClass::PlainSampler: { |
| 926 | const auto *sampler_desc = static_cast<const SamplerDescriptor *>(descriptor); |
| 927 | skip = ValidateSamplerDescriptor(caller, vuids, cb_node, descriptor_set, binding_info, index, |
| 928 | sampler_desc->GetSampler(), sampler_desc->IsImmutableSampler(), |
| 929 | sampler_desc->GetSamplerState()); |
| 930 | } break; |
| 931 | case DescriptorClass::TexelBuffer: { |
| 932 | const auto *texel_desc = static_cast<const TexelDescriptor *>(descriptor); |
| 933 | skip = ValidateTexelDescriptor(caller, vuids, cb_node, descriptor_set, *texel_desc, binding_info, index); |
| 934 | } break; |
| 935 | case DescriptorClass::AccelerationStructure: { |
| 936 | const auto *accel_desc = static_cast<const AccelerationStructureDescriptor *>(descriptor); |
| 937 | skip = ValidateAccelerationDescriptor(caller, vuids, cb_node, descriptor_set, *accel_desc, binding_info, index); |
| 938 | } break; |
| 939 | default: |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | return skip; |
| 945 | } |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 946 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 947 | bool CoreChecks::ValidateGeneralBufferDescriptor(const char *caller, const DrawDispatchVuid &vuids, const CMD_BUFFER_STATE *cb_node, |
| 948 | const cvdescriptorset::DescriptorSet *descriptor_set, |
| 949 | const cvdescriptorset::BufferDescriptor &descriptor, |
| 950 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, |
| 951 | uint32_t index) const { |
| 952 | // Verify that buffers are valid |
| 953 | auto buffer = descriptor.GetBuffer(); |
| 954 | auto buffer_node = descriptor.GetBufferState(); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 955 | if ((!buffer_node && !enabled_features.robustness2_features.nullDescriptor) || (buffer_node && buffer_node->Destroyed())) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 956 | auto set = descriptor_set->GetSet(); |
| 957 | return LogError(set, vuids.descriptor_valid, |
| 958 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 959 | "binding #%" PRIu32 " index %" PRIu32 " is using buffer %s that is invalid or has been destroyed.", |
| 960 | report_data->FormatHandle(set).c_str(), caller, binding_info.first, index, |
| 961 | report_data->FormatHandle(buffer).c_str()); |
| 962 | } |
| 963 | if (buffer) { |
| 964 | if (buffer_node && !buffer_node->sparse) { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 965 | for (const auto &item: buffer_node->GetBoundMemory()) { |
| 966 | auto &binding = item.second; |
| 967 | if (binding.mem_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 968 | auto set = descriptor_set->GetSet(); |
| 969 | return LogError(set, vuids.descriptor_valid, |
| 970 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 971 | "binding #%" PRIu32 " index %" PRIu32 " is uses buffer %s that references invalid memory %s.", |
| 972 | report_data->FormatHandle(set).c_str(), caller, binding_info.first, index, |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 973 | report_data->FormatHandle(buffer).c_str(), |
| 974 | report_data->FormatHandle(binding.mem_state->mem()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | } |
| 978 | if (enabled_features.core11.protectedMemory == VK_TRUE) { |
| 979 | if (ValidateProtectedBuffer(cb_node, buffer_node, caller, vuids.unprotected_command_buffer, |
| 980 | "Buffer is in a descriptorSet")) { |
| 981 | return true; |
| 982 | } |
| 983 | if (binding_info.second.is_writable && |
| 984 | ValidateUnprotectedBuffer(cb_node, buffer_node, caller, vuids.protected_command_buffer, |
| 985 | "Buffer is in a descriptorSet")) { |
| 986 | return true; |
| 987 | } |
| 988 | } |
| 989 | } |
| 990 | return false; |
| 991 | } |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 992 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 993 | bool CoreChecks::ValidateImageDescriptor(const char *caller, const DrawDispatchVuid &vuids, const CMD_BUFFER_STATE *cb_node, |
| 994 | const cvdescriptorset::DescriptorSet *descriptor_set, |
| 995 | const cvdescriptorset::ImageDescriptor &image_descriptor, |
| 996 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, uint32_t index, |
| 997 | bool record_time_validate, const std::vector<IMAGE_VIEW_STATE *> *attachments, |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 998 | const std::vector<SUBPASS_INFO> *subpasses, VkFramebuffer framebuffer, |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 999 | VkDescriptorType descriptor_type, |
Jeremy Gebben | 37ed31e | 2021-04-23 12:12:10 -0600 | [diff] [blame] | 1000 | layer_data::optional<layer_data::unordered_map<VkImageView, VkImageLayout>> &checked_layouts) const { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1001 | std::vector<const SAMPLER_STATE *> sampler_states; |
| 1002 | VkImageView image_view = image_descriptor.GetImageView(); |
| 1003 | const IMAGE_VIEW_STATE *image_view_state = image_descriptor.GetImageViewState(); |
| 1004 | VkImageLayout image_layout = image_descriptor.GetImageLayout(); |
| 1005 | const auto binding = binding_info.first; |
| 1006 | const auto reqs = binding_info.second.reqs; |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 1007 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1008 | if (image_descriptor.GetClass() == cvdescriptorset::DescriptorClass::ImageSampler) { |
| 1009 | sampler_states.emplace_back( |
| 1010 | static_cast<const cvdescriptorset::ImageSamplerDescriptor &>(image_descriptor).GetSamplerState()); |
| 1011 | } else { |
| 1012 | if (binding_info.second.samplers_used_by_image.size() > index) { |
| 1013 | for (auto &sampler : binding_info.second.samplers_used_by_image[index]) { |
| 1014 | // NOTE: This check _shouldn't_ be necessary due to the checks made in IsSpecificDescriptorType in |
| 1015 | // shader_validation.cpp. However, without this check some traces still crash. |
| 1016 | if (sampler.second && (sampler.second->GetClass() == cvdescriptorset::DescriptorClass::PlainSampler)) { |
| 1017 | const auto *sampler_state = |
| 1018 | static_cast<const cvdescriptorset::SamplerDescriptor *>(sampler.second)->GetSamplerState(); |
| 1019 | if (sampler_state) sampler_states.emplace_back(sampler_state); |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
locke-lunarg | 4e1e463 | 2020-10-26 01:52:19 -0600 | [diff] [blame] | 1024 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1025 | if ((!image_view_state && !enabled_features.robustness2_features.nullDescriptor) || |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1026 | (image_view_state && image_view_state->Destroyed())) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1027 | // Image view must have been destroyed since initial update. Could potentially flag the descriptor |
| 1028 | // as "invalid" (updated = false) at DestroyImageView() time and detect this error at bind time |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1029 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1030 | auto set = descriptor_set->GetSet(); |
| 1031 | return LogError(set, vuids.descriptor_valid, |
| 1032 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1033 | "binding #%" PRIu32 " index %" PRIu32 " is using imageView %s that is invalid or has been destroyed.", |
| 1034 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1035 | report_data->FormatHandle(image_view).c_str()); |
| 1036 | } |
| 1037 | if (image_view) { |
| 1038 | const auto &image_view_ci = image_view_state->create_info; |
| 1039 | const auto *image_state = image_view_state->image_state.get(); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 1040 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1041 | if (reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) { |
| 1042 | if (~reqs & (1 << image_view_ci.viewType)) { |
| 1043 | auto set = descriptor_set->GetSet(); |
| 1044 | return LogError(set, vuids.descriptor_valid, |
| 1045 | "Descriptor set %s encountered the following validation error at %s time: Descriptor " |
| 1046 | "in binding #%" PRIu32 " index %" PRIu32 " requires an image view of type %s but got %s.", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 1047 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1048 | StringDescriptorReqViewType(reqs).c_str(), string_VkImageViewType(image_view_ci.viewType)); |
| 1049 | } |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 1050 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1051 | if (!(reqs & image_view_state->descriptor_format_bits)) { |
| 1052 | // bad component type |
| 1053 | auto set = descriptor_set->GetSet(); |
| 1054 | return LogError(set, vuids.descriptor_valid, |
| 1055 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1056 | "Descriptor in binding " |
| 1057 | "#%" PRIu32 " index %" PRIu32 " requires %s component type, but bound descriptor format is %s.", |
| 1058 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1059 | StringDescriptorReqComponentType(reqs), string_VkFormat(image_view_ci.format)); |
| 1060 | } |
| 1061 | } |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1062 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1063 | // NOTE: Submit time validation of UPDATE_AFTER_BIND image layout is not possible with the |
| 1064 | // image layout tracking as currently implemented, so only record_time_validation is done |
| 1065 | if (!disabled[image_layout_validation] && record_time_validate) { |
| 1066 | // Verify Image Layout |
| 1067 | // No "invalid layout" VUID required for this call, since the optimal_layout parameter is UNDEFINED. |
| 1068 | // The caller provides a checked_layouts map when there are a large number of layouts to check, |
| 1069 | // making it worthwhile to keep track of verified layouts and not recheck them. |
| 1070 | bool already_validated = false; |
| 1071 | if (checked_layouts) { |
| 1072 | auto search = checked_layouts->find(image_view); |
| 1073 | if (search != checked_layouts->end() && search->second == image_layout) { |
| 1074 | already_validated = true; |
| 1075 | } |
| 1076 | } |
| 1077 | if (!already_validated) { |
| 1078 | bool hit_error = false; |
| 1079 | VerifyImageLayout(cb_node, image_state, image_view_state->normalized_subresource_range, |
| 1080 | image_view_ci.subresourceRange.aspectMask, image_layout, VK_IMAGE_LAYOUT_UNDEFINED, caller, |
| 1081 | kVUIDUndefined, "VUID-VkDescriptorImageInfo-imageLayout-00344", &hit_error); |
| 1082 | if (hit_error) { |
| 1083 | auto set = descriptor_set->GetSet(); |
| 1084 | return LogError(set, vuids.descriptor_valid, |
| 1085 | "Descriptor set %s encountered the following validation error at %s time: Image layout " |
| 1086 | "specified " |
| 1087 | "at vkUpdateDescriptorSet* or vkCmdPushDescriptorSet* time " |
| 1088 | "doesn't match actual image layout at time descriptor is used. See previous error callback for " |
| 1089 | "specific details.", |
| 1090 | report_data->FormatHandle(set).c_str(), caller); |
| 1091 | } |
| 1092 | if (checked_layouts) { |
| 1093 | checked_layouts->emplace(image_view, image_layout); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1097 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1098 | // Verify Sample counts |
| 1099 | if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && image_view_state->samples != VK_SAMPLE_COUNT_1_BIT) { |
| 1100 | auto set = descriptor_set->GetSet(); |
| 1101 | return LogError(set, vuids.descriptor_valid, |
| 1102 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1103 | "binding #%" PRIu32 " index %" PRIu32 " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got %s.", |
| 1104 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1105 | string_VkSampleCountFlagBits(image_view_state->samples)); |
| 1106 | } |
| 1107 | if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && image_view_state->samples == VK_SAMPLE_COUNT_1_BIT) { |
| 1108 | auto set = descriptor_set->GetSet(); |
| 1109 | return LogError(set, vuids.descriptor_valid, |
| 1110 | "Descriptor set %s encountered the following validation error at %s time: Descriptor " |
| 1111 | "in binding #%" PRIu32 " index %" PRIu32 |
| 1112 | " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT.", |
| 1113 | report_data->FormatHandle(set).c_str(), caller, binding, index); |
| 1114 | } |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 1115 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1116 | // Verify VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT |
| 1117 | if ((reqs & DESCRIPTOR_REQ_VIEW_ATOMIC_OPERATION) && (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) && |
| 1118 | !(image_view_state->format_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT)) { |
| 1119 | auto set = descriptor_set->GetSet(); |
| 1120 | LogObjectList objlist(set); |
| 1121 | objlist.add(image_view); |
| 1122 | return LogError(objlist, vuids.imageview_atomic, |
| 1123 | "Descriptor set %s encountered the following validation error at %s time: Descriptor " |
| 1124 | "in binding #%" PRIu32 " index %" PRIu32 |
| 1125 | ", %s, format %s, doesn't " |
| 1126 | "contain VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT.", |
| 1127 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1128 | report_data->FormatHandle(image_view).c_str(), string_VkFormat(image_view_ci.format)); |
| 1129 | } |
locke-lunarg | 654a905 | 2020-10-13 16:28:42 -0600 | [diff] [blame] | 1130 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1131 | // Verify if attachments are used in DescriptorSet |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 1132 | if (attachments && attachments->size() > 0 && subpasses && (descriptor_type != VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) { |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 1133 | bool ds_aspect = (image_view_state->normalized_subresource_range.aspectMask & |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1134 | (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) |
| 1135 | ? true |
| 1136 | : false; |
| 1137 | uint32_t att_index = 0; |
| 1138 | for (const auto &view_state : *attachments) { |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 1139 | const SUBPASS_INFO& subpass = (*subpasses)[att_index]; |
| 1140 | if (!subpass.used || !view_state || view_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1141 | continue; |
| 1142 | } |
Ricardo Garcia | fe2b768 | 2021-07-30 10:44:57 +0200 | [diff] [blame] | 1143 | if (ds_aspect && (subpass.usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || |
| 1144 | subpass.usage == VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1145 | if ((image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL || |
| 1146 | image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL || |
| 1147 | image_layout == VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL) && |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 1148 | (subpass.layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL || |
| 1149 | subpass.layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL || |
| 1150 | subpass.layout == VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL)) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1151 | continue; |
Chris Forbes | 1f7f3ca | 2017-05-08 13:54:50 -0700 | [diff] [blame] | 1152 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1153 | if ((image_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL && |
Niels Möller | 1f945f6 | 2021-07-12 15:06:02 +0200 | [diff] [blame] | 1154 | subpass.layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL) || |
| 1155 | (subpass.layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL && |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1156 | image_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL)) { |
| 1157 | continue; |
| 1158 | } |
| 1159 | } |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1160 | if (view_state->image_view() == image_view) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1161 | auto set = descriptor_set->GetSet(); |
| 1162 | LogObjectList objlist(set); |
| 1163 | objlist.add(image_view); |
| 1164 | objlist.add(framebuffer); |
| 1165 | return LogError(objlist, vuids.image_subresources, |
| 1166 | "Descriptor set %s encountered the following validation error at %s time: %s is used in " |
| 1167 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 " and %s attachment # %" PRIu32 ".", |
| 1168 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(image_view).c_str(), |
| 1169 | binding, index, report_data->FormatHandle(framebuffer).c_str(), att_index); |
| 1170 | } else { |
| 1171 | if (image_view_state->OverlapSubresource(*view_state)) { |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 1172 | auto set = descriptor_set->GetSet(); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1173 | LogObjectList objlist(set); |
| 1174 | objlist.add(image_view); |
| 1175 | objlist.add(framebuffer); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1176 | objlist.add(view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1177 | return LogError( |
| 1178 | objlist, vuids.image_subresources, |
| 1179 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1180 | "Image subresources of %s in " |
| 1181 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 " and %s in %s attachment # %" PRIu32 " overlap.", |
| 1182 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(image_view).c_str(), binding, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1183 | index, report_data->FormatHandle(view_state->image_view()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1184 | report_data->FormatHandle(framebuffer).c_str(), att_index); |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 1185 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1186 | } |
| 1187 | ++att_index; |
| 1188 | } |
| 1189 | if (enabled_features.core11.protectedMemory == VK_TRUE) { |
| 1190 | if (ValidateProtectedImage(cb_node, image_view_state->image_state.get(), caller, vuids.unprotected_command_buffer, |
| 1191 | "Image is in a descriptorSet")) { |
| 1192 | return true; |
| 1193 | } |
| 1194 | if (binding_info.second.is_writable && |
| 1195 | ValidateUnprotectedImage(cb_node, image_view_state->image_state.get(), caller, vuids.protected_command_buffer, |
| 1196 | "Image is in a descriptorSet")) { |
| 1197 | return true; |
| 1198 | } |
| 1199 | } |
| 1200 | } |
Chris Forbes | e92dd1d | 2019-01-21 15:58:57 -0800 | [diff] [blame] | 1201 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1202 | for (const auto *sampler_state : sampler_states) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1203 | if (!sampler_state || sampler_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1204 | continue; |
| 1205 | } |
locke-lunarg | 25b6c35 | 2020-08-06 17:44:18 -0600 | [diff] [blame] | 1206 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1207 | // TODO: Validate 04015 for DescriptorClass::PlainSampler |
| 1208 | if ((sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT || |
| 1209 | sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) && |
| 1210 | (sampler_state->customCreateInfo.format == VK_FORMAT_UNDEFINED)) { |
| 1211 | if (image_view_state->create_info.format == VK_FORMAT_B4G4R4A4_UNORM_PACK16 || |
| 1212 | image_view_state->create_info.format == VK_FORMAT_B5G6R5_UNORM_PACK16 || |
| 1213 | image_view_state->create_info.format == VK_FORMAT_B5G5R5A1_UNORM_PACK16) { |
| 1214 | auto set = descriptor_set->GetSet(); |
| 1215 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1216 | objlist.add(sampler_state->sampler()); |
| 1217 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1218 | return LogError(objlist, "VUID-VkSamplerCustomBorderColorCreateInfoEXT-format-04015", |
| 1219 | "Descriptor set %s encountered the following validation error at %s time: Sampler %s in " |
| 1220 | "binding #%" PRIu32 " index %" PRIu32 |
| 1221 | " has a custom border color with format = VK_FORMAT_UNDEFINED and is used to " |
| 1222 | "sample an image view %s with format %s", |
| 1223 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1224 | report_data->FormatHandle(sampler_state->sampler()).c_str(), binding, index, |
| 1225 | report_data->FormatHandle(image_view_state->image_view()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1226 | string_VkFormat(image_view_state->create_info.format)); |
| 1227 | } |
| 1228 | } |
| 1229 | VkFilter sampler_mag_filter = sampler_state->createInfo.magFilter; |
| 1230 | VkFilter sampler_min_filter = sampler_state->createInfo.minFilter; |
| 1231 | VkBool32 sampler_compare_enable = sampler_state->createInfo.compareEnable; |
| 1232 | if ((sampler_mag_filter == VK_FILTER_LINEAR || sampler_min_filter == VK_FILTER_LINEAR) && |
| 1233 | (sampler_compare_enable == VK_FALSE) && |
| 1234 | !(image_view_state->format_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) { |
| 1235 | auto set = descriptor_set->GetSet(); |
| 1236 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1237 | objlist.add(sampler_state->sampler()); |
| 1238 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1239 | return LogError(objlist, vuids.linear_sampler, |
| 1240 | "Descriptor set %s encountered the following validation error at %s time: Sampler " |
| 1241 | "(%s) is set to use VK_FILTER_LINEAR with " |
| 1242 | "compareEnable is set to VK_TRUE, but image view's (%s) format (%s) does not " |
| 1243 | "contain VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT in its format features.", |
| 1244 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1245 | report_data->FormatHandle(sampler_state->sampler()).c_str(), |
| 1246 | report_data->FormatHandle(image_view_state->image_view()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1247 | string_VkFormat(image_view_state->create_info.format)); |
| 1248 | } |
| 1249 | if (sampler_mag_filter == VK_FILTER_CUBIC_EXT || sampler_min_filter == VK_FILTER_CUBIC_EXT) { |
| 1250 | if (!(image_view_state->format_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT)) { |
| 1251 | auto set = descriptor_set->GetSet(); |
| 1252 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1253 | objlist.add(sampler_state->sampler()); |
| 1254 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1255 | return LogError(objlist, vuids.cubic_sampler, |
| 1256 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1257 | "Sampler (%s) is set to use VK_FILTER_CUBIC_EXT, then " |
| 1258 | "image view's (%s) format (%s) MUST contain " |
| 1259 | "VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_EXT in its format features.", |
| 1260 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1261 | report_data->FormatHandle(sampler_state->sampler()).c_str(), |
| 1262 | report_data->FormatHandle(image_view_state->image_view()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1263 | string_VkFormat(image_view_state->create_info.format)); |
| 1264 | } |
| 1265 | |
| 1266 | if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) { |
| 1267 | const auto reduction_mode_info = |
| 1268 | LvlFindInChain<VkSamplerReductionModeCreateInfo>(sampler_state->createInfo.pNext); |
| 1269 | if (reduction_mode_info && |
| 1270 | (reduction_mode_info->reductionMode == VK_SAMPLER_REDUCTION_MODE_MIN || |
| 1271 | reduction_mode_info->reductionMode == VK_SAMPLER_REDUCTION_MODE_MAX) && |
| 1272 | !image_view_state->filter_cubic_props.filterCubicMinmax) { |
| 1273 | auto set = descriptor_set->GetSet(); |
| 1274 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1275 | objlist.add(sampler_state->sampler()); |
| 1276 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1277 | return LogError(objlist, vuids.filter_cubic_min_max, |
| 1278 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1279 | "Sampler (%s) is set to use VK_FILTER_CUBIC_EXT & %s, " |
| 1280 | "but image view (%s) doesn't support filterCubicMinmax.", |
| 1281 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1282 | report_data->FormatHandle(sampler_state->sampler()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1283 | string_VkSamplerReductionMode(reduction_mode_info->reductionMode), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1284 | report_data->FormatHandle(image_view_state->image_view()).c_str()); |
Chris Forbes | e92dd1d | 2019-01-21 15:58:57 -0800 | [diff] [blame] | 1285 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1286 | |
| 1287 | if (!image_view_state->filter_cubic_props.filterCubic) { |
| 1288 | auto set = descriptor_set->GetSet(); |
| 1289 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1290 | objlist.add(sampler_state->sampler()); |
| 1291 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1292 | return LogError(objlist, vuids.filter_cubic, |
| 1293 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1294 | "Sampler (%s) is set to use VK_FILTER_CUBIC_EXT, " |
| 1295 | "but image view (%s) doesn't support filterCubic.", |
| 1296 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1297 | report_data->FormatHandle(sampler_state->sampler()).c_str(), |
| 1298 | report_data->FormatHandle(image_view_state->image_view()).c_str()); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 1299 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1300 | } |
locke-lunarg | 4e1e463 | 2020-10-26 01:52:19 -0600 | [diff] [blame] | 1301 | |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1302 | if (IsExtEnabled(device_extensions.vk_img_filter_cubic)) { |
| 1303 | if (image_view_state->create_info.viewType & |
| 1304 | (VK_IMAGE_VIEW_TYPE_3D | VK_IMAGE_VIEW_TYPE_CUBE | VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)) { |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 1305 | auto set = descriptor_set->GetSet(); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1306 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1307 | objlist.add(sampler_state->sampler()); |
| 1308 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1309 | return LogError(objlist, vuids.img_filter_cubic, |
| 1310 | "Descriptor set %s encountered the following validation error at %s time: Sampler " |
| 1311 | "(%s)is set to use VK_FILTER_CUBIC_EXT while the VK_IMG_filter_cubic extension " |
| 1312 | "is enabled, but image view (%s) has an invalid imageViewType (%s).", |
| 1313 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1314 | report_data->FormatHandle(sampler_state->sampler()).c_str(), |
| 1315 | report_data->FormatHandle(image_view_state->image_view()).c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1316 | string_VkImageViewType(image_view_state->create_info.viewType)); |
Tobin Ehlis | b1a2e4b | 2018-03-16 07:54:24 -0600 | [diff] [blame] | 1317 | } |
| 1318 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1319 | } |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1320 | |
| 1321 | if ((image_state->createInfo.flags & VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV) && |
| 1322 | (sampler_state->createInfo.addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE || |
| 1323 | sampler_state->createInfo.addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE || |
| 1324 | sampler_state->createInfo.addressModeW != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE)) { |
| 1325 | std::string address_mode_letter = |
| 1326 | (sampler_state->createInfo.addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) |
| 1327 | ? "U" |
| 1328 | : (sampler_state->createInfo.addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) ? "V" : "W"; |
| 1329 | VkSamplerAddressMode address_mode = |
| 1330 | (sampler_state->createInfo.addressModeU != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) |
| 1331 | ? sampler_state->createInfo.addressModeU |
| 1332 | : (sampler_state->createInfo.addressModeV != VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE) |
| 1333 | ? sampler_state->createInfo.addressModeV |
| 1334 | : sampler_state->createInfo.addressModeW; |
| 1335 | auto set = descriptor_set->GetSet(); |
| 1336 | LogObjectList objlist(set); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1337 | objlist.add(sampler_state->sampler()); |
| 1338 | objlist.add(image_state->image()); |
| 1339 | objlist.add(image_view_state->image_view()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1340 | return LogError(objlist, vuids.corner_sampled_address_mode, |
| 1341 | "Descriptor set %s encountered the following validation error at %s time: Image " |
| 1342 | "(%s) in image view (%s) is created with flag " |
| 1343 | "VK_IMAGE_CREATE_CORNER_SAMPLED_BIT_NV and can only be sampled using " |
| 1344 | "VK_SAMPLER_ADDRESS_MODE_CLAMP_EDGE, but sampler (%s) has " |
| 1345 | "createInfo.addressMode%s set to %s.", |
| 1346 | report_data->FormatHandle(set).c_str(), caller, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1347 | report_data->FormatHandle(image_state->image()).c_str(), |
| 1348 | report_data->FormatHandle(image_view_state->image_view()).c_str(), |
| 1349 | report_data->FormatHandle(sampler_state->sampler()).c_str(), address_mode_letter.c_str(), |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1350 | string_VkSamplerAddressMode(address_mode)); |
| 1351 | } |
| 1352 | |
| 1353 | // UnnormalizedCoordinates sampler validations |
| 1354 | if (sampler_state->createInfo.unnormalizedCoordinates) { |
| 1355 | // If ImageView is used by a unnormalizedCoordinates sampler, it needs to check ImageView type |
| 1356 | if (image_view_ci.viewType == VK_IMAGE_VIEW_TYPE_3D || image_view_ci.viewType == VK_IMAGE_VIEW_TYPE_CUBE || |
| 1357 | image_view_ci.viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY || |
| 1358 | image_view_ci.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY || |
| 1359 | image_view_ci.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { |
| 1360 | auto set = descriptor_set->GetSet(); |
| 1361 | LogObjectList objlist(set); |
| 1362 | objlist.add(image_view); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1363 | objlist.add(sampler_state->sampler()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1364 | return LogError(objlist, vuids.sampler_imageview_type, |
| 1365 | "Descriptor set %s encountered the following validation error at %s time: %s, type: %s in " |
| 1366 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 "is used by %s.", |
| 1367 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(image_view).c_str(), |
| 1368 | string_VkImageViewType(image_view_ci.viewType), binding, index, |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1369 | report_data->FormatHandle(sampler_state->sampler()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | // sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* |
| 1373 | // instructions with ImplicitLod, Dref or Proj in their name |
| 1374 | if (reqs & DESCRIPTOR_REQ_SAMPLER_IMPLICITLOD_DREF_PROJ) { |
| 1375 | auto set = descriptor_set->GetSet(); |
| 1376 | LogObjectList objlist(set); |
| 1377 | objlist.add(image_view); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1378 | objlist.add(sampler_state->sampler()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1379 | return LogError(objlist, vuids.sampler_implicitLod_dref_proj, |
| 1380 | "Descriptor set %s encountered the following validation error at %s time: %s in " |
| 1381 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 |
| 1382 | " is used by %s that uses invalid operator.", |
| 1383 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(image_view).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1384 | binding, index, report_data->FormatHandle(sampler_state->sampler()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | // sampler must not be used with any of the SPIR-V OpImageSample* or OpImageSparseSample* |
| 1388 | // instructions that includes a LOD bias or any offset values |
| 1389 | if (reqs & DESCRIPTOR_REQ_SAMPLER_BIAS_OFFSET) { |
| 1390 | auto set = descriptor_set->GetSet(); |
| 1391 | LogObjectList objlist(set); |
| 1392 | objlist.add(image_view); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1393 | objlist.add(sampler_state->sampler()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1394 | return LogError(objlist, vuids.sampler_bias_offset, |
| 1395 | "Descriptor set %s encountered the following validation error at %s time: %s in " |
| 1396 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 |
| 1397 | " is used by %s that uses invalid bias or offset operator.", |
| 1398 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(image_view).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1399 | binding, index, report_data->FormatHandle(sampler_state->sampler()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | } |
| 1404 | return false; |
| 1405 | } |
| 1406 | |
| 1407 | bool CoreChecks::ValidateTexelDescriptor(const char *caller, const DrawDispatchVuid &vuids, const CMD_BUFFER_STATE *cb_node, |
| 1408 | const cvdescriptorset::DescriptorSet *descriptor_set, |
| 1409 | const cvdescriptorset::TexelDescriptor &texel_descriptor, |
| 1410 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, |
| 1411 | uint32_t index) const { |
| 1412 | auto buffer_view = texel_descriptor.GetBufferView(); |
| 1413 | auto buffer_view_state = texel_descriptor.GetBufferViewState(); |
| 1414 | const auto binding = binding_info.first; |
| 1415 | const auto reqs = binding_info.second.reqs; |
| 1416 | if ((!buffer_view_state && !enabled_features.robustness2_features.nullDescriptor) || |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1417 | (buffer_view_state && buffer_view_state->Destroyed())) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1418 | auto set = descriptor_set->GetSet(); |
| 1419 | return LogError(set, vuids.descriptor_valid, |
| 1420 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1421 | "binding #%" PRIu32 " index %" PRIu32 " is using bufferView %s that is invalid or has been destroyed.", |
| 1422 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1423 | report_data->FormatHandle(buffer_view).c_str()); |
| 1424 | } |
| 1425 | if (buffer_view) { |
| 1426 | auto buffer = buffer_view_state->create_info.buffer; |
| 1427 | auto buffer_state = buffer_view_state->buffer_state.get(); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1428 | if (buffer_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1429 | auto set = descriptor_set->GetSet(); |
| 1430 | return LogError(set, vuids.descriptor_valid, |
| 1431 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1432 | "binding #%" PRIu32 " index %" PRIu32 " is using buffer %s that has been destroyed.", |
| 1433 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1434 | report_data->FormatHandle(buffer).c_str()); |
| 1435 | } |
| 1436 | auto format_bits = DescriptorRequirementsBitsFromFormat(buffer_view_state->create_info.format); |
| 1437 | |
| 1438 | if (!(reqs & format_bits)) { |
| 1439 | // bad component type |
| 1440 | auto set = descriptor_set->GetSet(); |
| 1441 | return LogError(set, vuids.descriptor_valid, |
| 1442 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1443 | "binding #%" PRIu32 " index %" PRIu32 " requires %s component type, but bound descriptor format is %s.", |
| 1444 | report_data->FormatHandle(set).c_str(), caller, binding, index, StringDescriptorReqComponentType(reqs), |
| 1445 | string_VkFormat(buffer_view_state->create_info.format)); |
| 1446 | } |
| 1447 | |
| 1448 | // Verify VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT |
| 1449 | if ((reqs & DESCRIPTOR_REQ_VIEW_ATOMIC_OPERATION) && |
| 1450 | (descriptor_set->GetTypeFromBinding(binding) == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) && |
| 1451 | !(buffer_view_state->format_features & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT)) { |
| 1452 | auto set = descriptor_set->GetSet(); |
| 1453 | LogObjectList objlist(set); |
| 1454 | objlist.add(buffer_view); |
| 1455 | return LogError(objlist, "UNASSIGNED-None-MismatchAtomicBufferFeature", |
| 1456 | "Descriptor set %s encountered the following validation error at %s time: Descriptor " |
| 1457 | "in binding #%" PRIu32 " index %" PRIu32 |
| 1458 | ", %s, format %s, doesn't " |
| 1459 | "contain VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT.", |
| 1460 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1461 | report_data->FormatHandle(buffer_view).c_str(), string_VkFormat(buffer_view_state->create_info.format)); |
| 1462 | } |
| 1463 | if (enabled_features.core11.protectedMemory == VK_TRUE) { |
| 1464 | if (ValidateProtectedBuffer(cb_node, buffer_view_state->buffer_state.get(), caller, vuids.unprotected_command_buffer, |
| 1465 | "Buffer is in a descriptorSet")) { |
| 1466 | return true; |
| 1467 | } |
| 1468 | if (binding_info.second.is_writable && |
| 1469 | ValidateUnprotectedBuffer(cb_node, buffer_view_state->buffer_state.get(), caller, vuids.protected_command_buffer, |
| 1470 | "Buffer is in a descriptorSet")) { |
| 1471 | return true; |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | return false; |
| 1476 | } |
| 1477 | |
| 1478 | bool CoreChecks::ValidateAccelerationDescriptor(const char *caller, const DrawDispatchVuid &vuids, const CMD_BUFFER_STATE *cb_node, |
| 1479 | const cvdescriptorset::DescriptorSet *descriptor_set, |
| 1480 | const cvdescriptorset::AccelerationStructureDescriptor &descriptor, |
| 1481 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, |
| 1482 | uint32_t index) const { |
| 1483 | // Verify that acceleration structures are valid |
| 1484 | const auto binding = binding_info.first; |
| 1485 | if (descriptor.is_khr()) { |
| 1486 | auto acc = descriptor.GetAccelerationStructure(); |
| 1487 | auto acc_node = descriptor.GetAccelerationStructureStateKHR(); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1488 | if (!acc_node || acc_node->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1489 | if (acc != VK_NULL_HANDLE || !enabled_features.robustness2_features.nullDescriptor) { |
| 1490 | auto set = descriptor_set->GetSet(); |
| 1491 | return LogError(set, vuids.descriptor_valid, |
| 1492 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1493 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 |
| 1494 | " is using acceleration structure %s that is invalid or has been destroyed.", |
| 1495 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1496 | report_data->FormatHandle(acc).c_str()); |
| 1497 | } |
| 1498 | } else { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1499 | for (const auto &item: acc_node->GetBoundMemory()) { |
| 1500 | auto &mem_binding = item.second; |
| 1501 | if (mem_binding.mem_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1502 | auto set = descriptor_set->GetSet(); |
| 1503 | return LogError(set, vuids.descriptor_valid, |
| 1504 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1505 | "binding #%" PRIu32 " index %" PRIu32 |
| 1506 | " is using acceleration structure %s that references invalid memory %s.", |
| 1507 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1508 | report_data->FormatHandle(acc).c_str(), |
| 1509 | report_data->FormatHandle(mem_binding.mem_state->mem()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | } |
| 1513 | } else { |
| 1514 | auto acc = descriptor.GetAccelerationStructureNV(); |
| 1515 | auto acc_node = descriptor.GetAccelerationStructureStateNV(); |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1516 | if (!acc_node || acc_node->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1517 | if (acc != VK_NULL_HANDLE || !enabled_features.robustness2_features.nullDescriptor) { |
| 1518 | auto set = descriptor_set->GetSet(); |
| 1519 | return LogError(set, vuids.descriptor_valid, |
| 1520 | "Descriptor set %s encountered the following validation error at %s time: " |
| 1521 | "Descriptor in binding #%" PRIu32 " index %" PRIu32 |
| 1522 | " is using acceleration structure %s that is invalid or has been destroyed.", |
| 1523 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
| 1524 | report_data->FormatHandle(acc).c_str()); |
| 1525 | } |
| 1526 | } else { |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1527 | for (const auto &item : acc_node->GetBoundMemory()) { |
| 1528 | auto &mem_binding = item.second; |
| 1529 | if (mem_binding.mem_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1530 | auto set = descriptor_set->GetSet(); |
| 1531 | return LogError(set, vuids.descriptor_valid, |
| 1532 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1533 | "binding #%" PRIu32 " index %" PRIu32 |
| 1534 | " is using acceleration structure %s that references invalid memory %s.", |
| 1535 | report_data->FormatHandle(set).c_str(), caller, binding, index, |
Jeremy Gebben | 6fbf824 | 2021-06-21 09:14:46 -0600 | [diff] [blame] | 1536 | report_data->FormatHandle(acc).c_str(), |
| 1537 | report_data->FormatHandle(mem_binding.mem_state->mem()).c_str()); |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
| 1545 | // If the validation is related to both of image and sampler, |
| 1546 | // please leave it in (descriptor_class == DescriptorClass::ImageSampler || descriptor_class == |
| 1547 | // DescriptorClass::Image) Here is to validate for only sampler. |
| 1548 | bool CoreChecks::ValidateSamplerDescriptor(const char *caller, const DrawDispatchVuid &vuids, const CMD_BUFFER_STATE *cb_node, |
| 1549 | const cvdescriptorset::DescriptorSet *descriptor_set, |
| 1550 | const std::pair<const uint32_t, DescriptorRequirement> &binding_info, uint32_t index, |
| 1551 | VkSampler sampler, bool is_immutable, const SAMPLER_STATE *sampler_state) const { |
| 1552 | // Verify Sampler still valid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1553 | if (!sampler_state || sampler_state->Destroyed()) { |
Jeremy Gebben | e151b6b | 2021-04-09 18:03:06 -0600 | [diff] [blame] | 1554 | auto set = descriptor_set->GetSet(); |
| 1555 | return LogError(set, vuids.descriptor_valid, |
| 1556 | "Descriptor set %s encountered the following validation error at %s time: Descriptor in " |
| 1557 | "binding #%" PRIu32 " index %" PRIu32 " is using sampler %s that is invalid or has been destroyed.", |
| 1558 | report_data->FormatHandle(set).c_str(), caller, binding_info.first, index, |
| 1559 | report_data->FormatHandle(sampler).c_str()); |
| 1560 | } else { |
| 1561 | if (sampler_state->samplerConversion && !is_immutable) { |
| 1562 | auto set = descriptor_set->GetSet(); |
| 1563 | return LogError(set, vuids.descriptor_valid, |
| 1564 | "Descriptor set %s encountered the following validation error at %s time: sampler (%s) " |
| 1565 | "in the descriptor set (%s) contains a YCBCR conversion (%s), then the sampler MUST " |
| 1566 | "also exist as an immutable sampler.", |
| 1567 | report_data->FormatHandle(set).c_str(), caller, report_data->FormatHandle(sampler).c_str(), |
| 1568 | report_data->FormatHandle(descriptor_set->GetSet()).c_str(), |
| 1569 | report_data->FormatHandle(sampler_state->samplerConversion).c_str()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1570 | } |
| 1571 | } |
Tony-LunarG | ace473a | 2020-05-06 12:48:04 -0600 | [diff] [blame] | 1572 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1573 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 1574 | |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 1575 | // Loop through the write updates to do for a push descriptor set, ignoring dstSet |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1576 | void cvdescriptorset::DescriptorSet::PerformPushDescriptorsUpdate(ValidationStateTracker *dev_data, uint32_t write_count, |
| 1577 | const VkWriteDescriptorSet *p_wds) { |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 1578 | assert(IsPushDescriptor()); |
| 1579 | for (uint32_t i = 0; i < write_count; i++) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1580 | PerformWriteUpdate(dev_data, &p_wds[i]); |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 1581 | } |
Jason Macnak | 83cfd58 | 2019-07-31 10:14:24 -0700 | [diff] [blame] | 1582 | |
| 1583 | push_descriptor_set_writes.clear(); |
| 1584 | push_descriptor_set_writes.reserve(static_cast<std::size_t>(write_count)); |
| 1585 | for (uint32_t i = 0; i < write_count; i++) { |
| 1586 | push_descriptor_set_writes.push_back(safe_VkWriteDescriptorSet(&p_wds[i])); |
| 1587 | } |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1590 | // Perform write update in given update struct |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1591 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(ValidationStateTracker *dev_data, const VkWriteDescriptorSet *update) { |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1592 | // Perform update on a per-binding basis as consecutive updates roll over to next binding |
| 1593 | auto descriptors_remaining = update->descriptorCount; |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1594 | auto offset = update->dstArrayElement; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1595 | auto orig_binding = DescriptorSetLayout::ConstBindingIterator(layout_.get(), update->dstBinding); |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 1596 | auto current_binding = orig_binding; |
| 1597 | |
Tobin Ehlis | e16805c | 2017-08-09 09:10:37 -0600 | [diff] [blame] | 1598 | uint32_t update_index = 0; |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 1599 | // Verify next consecutive binding matches type, stage flags & immutable sampler use and if AtEnd |
| 1600 | while (descriptors_remaining && orig_binding.IsConsistent(current_binding)) { |
| 1601 | const auto &index_range = current_binding.GetGlobalIndexRange(); |
| 1602 | auto global_idx = index_range.start + offset; |
| 1603 | // global_idx is which descriptor is needed to update. If global_idx > index_range.end, it means the descriptor isn't in |
| 1604 | // this binding, maybe in next binding. |
| 1605 | if (global_idx >= index_range.end) { |
| 1606 | offset -= current_binding.GetDescriptorCount(); |
| 1607 | ++current_binding; |
| 1608 | continue; |
| 1609 | } |
| 1610 | |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1611 | // Loop over the updates for a single binding at a time |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 1612 | uint32_t update_count = std::min(descriptors_remaining, current_binding.GetDescriptorCount() - offset); |
Tobin Ehlis | e16805c | 2017-08-09 09:10:37 -0600 | [diff] [blame] | 1613 | for (uint32_t di = 0; di < update_count; ++di, ++update_index) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1614 | descriptors_[global_idx + di]->WriteUpdate(this, state_data_, update, update_index); |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 1615 | } |
| 1616 | // Roll over to next binding in case of consecutive update |
| 1617 | descriptors_remaining -= update_count; |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 1618 | if (descriptors_remaining) { |
| 1619 | // Starting offset is beyond the current binding. Check consistency, update counters and advance to the next binding, |
| 1620 | // looking for the start point. All bindings (even those skipped) must be consistent with the update and with the |
| 1621 | // original binding. |
| 1622 | offset = 0; |
| 1623 | ++current_binding; |
| 1624 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1625 | } |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 1626 | if (update->descriptorCount) { |
| 1627 | some_update_ = true; |
| 1628 | change_count_++; |
| 1629 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1630 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1631 | if (!IsPushDescriptor() && !(layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1632 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1633 | Invalidate(false); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1634 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1635 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1636 | // Validate Copy update |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 1637 | bool CoreChecks::ValidateCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *dst_set, const DescriptorSet *src_set, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 1638 | const char *func_name, std::string *error_code, std::string *error_msg) const { |
Jeff Bolz | 6aad174 | 2019-10-16 11:10:09 -0500 | [diff] [blame] | 1639 | auto dst_layout = dst_set->GetLayout().get(); |
| 1640 | auto src_layout = src_set->GetLayout().get(); |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1641 | |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 1642 | // Verify dst layout still valid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1643 | if (dst_layout->Destroyed()) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1644 | *error_code = "VUID-VkCopyDescriptorSet-dstSet-parameter"; |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 1645 | std::ostringstream str; |
| 1646 | str << "Cannot call " << func_name << " to perform copy update on dstSet " << report_data->FormatHandle(dst_set->GetSet()) |
| 1647 | << " created with destroyed " << report_data->FormatHandle(dst_layout->GetDescriptorSetLayout()) << "."; |
| 1648 | *error_msg = str.str(); |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 1649 | return false; |
| 1650 | } |
| 1651 | |
| 1652 | // Verify src layout still valid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1653 | if (src_layout->Destroyed()) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1654 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-parameter"; |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 1655 | std::ostringstream str; |
| 1656 | str << "Cannot call " << func_name << " to perform copy update on dstSet " << report_data->FormatHandle(dst_set->GetSet()) |
| 1657 | << " from srcSet " << report_data->FormatHandle(src_set->GetSet()) << " created with destroyed " |
| 1658 | << report_data->FormatHandle(src_layout->GetDescriptorSetLayout()) << "."; |
| 1659 | *error_msg = str.str(); |
John Zulauf | 5dfd45c | 2018-01-17 11:06:34 -0700 | [diff] [blame] | 1660 | return false; |
| 1661 | } |
| 1662 | |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1663 | if (!dst_layout->HasBinding(update->dstBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1664 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-00347"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1665 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1666 | error_str << "DescriptorSet " << report_data->FormatHandle(dst_set->GetSet()) |
| 1667 | << " does not have copy update dest binding of " << update->dstBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1668 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1669 | return false; |
| 1670 | } |
| 1671 | if (!src_set->HasBinding(update->srcBinding)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1672 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-00345"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1673 | std::stringstream error_str; |
sourav parmar | f4a7825 | 2020-04-10 13:04:21 -0700 | [diff] [blame] | 1674 | error_str << "DescriptorSet " << report_data->FormatHandle(src_set->GetSet()) |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1675 | << " does not have copy update src binding of " << update->srcBinding; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1676 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1677 | return false; |
| 1678 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1679 | // Verify idle ds |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1680 | if (dst_set->InUse() && |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1681 | !(dst_layout->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1682 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1683 | // 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] | 1684 | *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1685 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1686 | error_str << "Cannot call " << func_name << " to perform copy update on descriptor set " |
| 1687 | << report_data->FormatHandle(dst_set->GetSet()) << " that is in use by a command buffer"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1688 | *error_msg = error_str.str(); |
| 1689 | return false; |
| 1690 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1691 | // src & dst set bindings are valid |
| 1692 | // Check bounds of src & dst |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1693 | auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1694 | if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) { |
| 1695 | // SRC update out of bounds |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1696 | *error_code = "VUID-VkCopyDescriptorSet-srcArrayElement-00346"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1697 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1698 | error_str << "Attempting copy update from descriptorSet " << report_data->FormatHandle(update->srcSet) << " binding#" |
| 1699 | << update->srcBinding << " with offset index of " |
| 1700 | << src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start << " plus update array offset of " |
| 1701 | << update->srcArrayElement << " and update of " << update->descriptorCount |
Tobin Ehlis | 1d81edd | 2016-11-21 09:50:49 -0700 | [diff] [blame] | 1702 | << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1703 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1706 | auto dst_start_idx = dst_layout->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement; |
| 1707 | if ((dst_start_idx + update->descriptorCount) > dst_layout->GetTotalDescriptorCount()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1708 | // DST update out of bounds |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1709 | *error_code = "VUID-VkCopyDescriptorSet-dstArrayElement-00348"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1710 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1711 | error_str << "Attempting copy update to descriptorSet " << report_data->FormatHandle(dst_set->GetSet()) << " binding#" |
| 1712 | << update->dstBinding << " with offset index of " |
| 1713 | << dst_layout->GetGlobalIndexRangeFromBinding(update->dstBinding).start << " plus update array offset of " |
| 1714 | << update->dstArrayElement << " and update of " << update->descriptorCount |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1715 | << " descriptors oversteps total number of descriptors in set: " << dst_layout->GetTotalDescriptorCount(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1716 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
| 1719 | // Check that types match |
Shannon McPherson | afe5512 | 2020-05-25 16:20:19 -0600 | [diff] [blame] | 1720 | // TODO : Base default error case going from here is "VUID-VkAcquireNextImageInfoKHR-semaphore-parameter" 2ba which covers all |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 1721 | // consistency issues, need more fine-grained error codes |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1722 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-00349"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1723 | auto src_type = src_set->GetTypeFromBinding(update->srcBinding); |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1724 | auto dst_type = dst_layout->GetTypeFromBinding(update->dstBinding); |
Ricardo Garcia | 14f4f76 | 2021-04-13 11:36:12 +0200 | [diff] [blame] | 1725 | if (src_type != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE && dst_type != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE && src_type != dst_type) { |
sourav parmar | f4a7825 | 2020-04-10 13:04:21 -0700 | [diff] [blame] | 1726 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02632"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1727 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1728 | error_str << "Attempting copy update to descriptorSet " << report_data->FormatHandle(dst_set->GetSet()) << " binding #" |
| 1729 | << update->dstBinding << " with type " << string_VkDescriptorType(dst_type) << " from descriptorSet " |
| 1730 | << report_data->FormatHandle(src_set->GetSet()) << " binding #" << update->srcBinding << " with type " |
| 1731 | << string_VkDescriptorType(src_type) << ". Types do not match"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1732 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1733 | return false; |
| 1734 | } |
| 1735 | // Verify consistency of src & dst bindings if update crosses binding boundaries |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1736 | if ((!VerifyUpdateConsistency(report_data, DescriptorSetLayout::ConstBindingIterator(src_layout, update->srcBinding), |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 1737 | update->srcArrayElement, update->descriptorCount, "copy update from", src_set->GetSet(), |
| 1738 | error_msg)) || |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1739 | (!VerifyUpdateConsistency(report_data, DescriptorSetLayout::ConstBindingIterator(dst_layout, update->dstBinding), |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 1740 | update->dstArrayElement, update->descriptorCount, "copy update to", dst_set->GetSet(), |
| 1741 | error_msg))) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1742 | return false; |
| 1743 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1744 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1745 | if ((src_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) && |
| 1746 | !(dst_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1747 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01918"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1748 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1749 | error_str << "If pname:srcSet's (" << report_data->FormatHandle(update->srcSet) |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1750 | << ") layout was created with the " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1751 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT flag " |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1752 | "set, then pname:dstSet's (" |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1753 | << report_data->FormatHandle(update->dstSet) |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1754 | << ") layout must: also have been created with the " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1755 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT flag set"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1756 | *error_msg = error_str.str(); |
| 1757 | return false; |
| 1758 | } |
| 1759 | |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 1760 | if (IsExtEnabled(device_extensions.vk_valve_mutable_descriptor_type)) { |
Mike Schuchardt | 294a159 | 2021-05-12 15:38:00 -0700 | [diff] [blame] | 1761 | if (!(src_layout->GetCreateFlags() & (VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT | |
| 1762 | VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_VALVE)) && |
| 1763 | (dst_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT)) { |
| 1764 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-04885"; |
| 1765 | std::stringstream error_str; |
| 1766 | error_str << "If pname:srcSet's (" << report_data->FormatHandle(update->srcSet) |
| 1767 | << ") layout was created with neither ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT nor " |
| 1768 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_VALVE flags set, then pname:dstSet's (" |
| 1769 | << report_data->FormatHandle(update->dstSet) |
| 1770 | << ") layout must: have been created without the " |
| 1771 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT flag set"; |
| 1772 | *error_msg = error_str.str(); |
| 1773 | return false; |
| 1774 | } |
| 1775 | } else { |
| 1776 | if (!(src_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) && |
| 1777 | (dst_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT)) { |
| 1778 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-04886"; |
| 1779 | std::stringstream error_str; |
| 1780 | error_str << "If pname:srcSet's (" << report_data->FormatHandle(update->srcSet) |
| 1781 | << ") layout was created without the ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT flag " |
| 1782 | "set, then pname:dstSet's (" |
| 1783 | << report_data->FormatHandle(update->dstSet) |
| 1784 | << ") layout must: also have been created without the " |
| 1785 | "ename:VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT flag set"; |
| 1786 | *error_msg = error_str.str(); |
| 1787 | return false; |
| 1788 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1789 | } |
| 1790 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1791 | if ((src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT) && |
| 1792 | !(dst_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 1793 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-01920"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1794 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1795 | error_str << "If the descriptor pool from which pname:srcSet (" << report_data->FormatHandle(update->srcSet) |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1796 | << ") was allocated was created " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1797 | "with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT flag " |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1798 | "set, then the descriptor pool from which pname:dstSet (" |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 1799 | << report_data->FormatHandle(update->dstSet) |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1800 | << ") was allocated must: " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1801 | "also have been created with the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT flag set"; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1802 | *error_msg = error_str.str(); |
| 1803 | return false; |
| 1804 | } |
| 1805 | |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 1806 | if (IsExtEnabled(device_extensions.vk_valve_mutable_descriptor_type)) { |
Mike Schuchardt | 294a159 | 2021-05-12 15:38:00 -0700 | [diff] [blame] | 1807 | if (!(src_set->GetPoolState()->createInfo.flags & |
| 1808 | (VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE)) && |
| 1809 | (dst_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT)) { |
| 1810 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-04887"; |
| 1811 | std::stringstream error_str; |
| 1812 | error_str << "If the descriptor pool from which pname:srcSet (" << report_data->FormatHandle(update->srcSet) |
| 1813 | << ") was allocated was created with neither ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT nor " |
| 1814 | "ename:VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE flags set, then the descriptor pool from which " |
| 1815 | "pname:dstSet (" |
| 1816 | << report_data->FormatHandle(update->dstSet) |
| 1817 | << ") was allocated must: have been created without the " |
| 1818 | "ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT flag set"; |
| 1819 | *error_msg = error_str.str(); |
| 1820 | return false; |
| 1821 | } |
| 1822 | } else { |
| 1823 | if (!(src_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT) && |
| 1824 | (dst_set->GetPoolState()->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT)) { |
| 1825 | *error_code = "VUID-VkCopyDescriptorSet-srcSet-04888"; |
| 1826 | std::stringstream error_str; |
| 1827 | error_str << "If the descriptor pool from which pname:srcSet (" << report_data->FormatHandle(update->srcSet) |
| 1828 | << ") was allocated was created without the ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT flag set, " |
| 1829 | "then the descriptor pool from which pname:dstSet (" |
| 1830 | << report_data->FormatHandle(update->dstSet) |
| 1831 | << ") was allocated must: also have been created without the " |
| 1832 | "ename:VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT flag set"; |
| 1833 | *error_msg = error_str.str(); |
| 1834 | return false; |
| 1835 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1836 | } |
| 1837 | |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1838 | if (src_type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
| 1839 | if ((update->srcArrayElement % 4) != 0) { |
| 1840 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02223"; |
| 1841 | std::stringstream error_str; |
| 1842 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1843 | << "srcArrayElement " << update->srcArrayElement << " not a multiple of 4"; |
| 1844 | *error_msg = error_str.str(); |
| 1845 | return false; |
| 1846 | } |
| 1847 | if ((update->dstArrayElement % 4) != 0) { |
| 1848 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02224"; |
| 1849 | std::stringstream error_str; |
| 1850 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1851 | << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4"; |
| 1852 | *error_msg = error_str.str(); |
| 1853 | return false; |
| 1854 | } |
| 1855 | if ((update->descriptorCount % 4) != 0) { |
| 1856 | *error_code = "VUID-VkCopyDescriptorSet-srcBinding-02225"; |
| 1857 | std::stringstream error_str; |
| 1858 | error_str << "Attempting copy update to VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT binding with " |
| 1859 | << "descriptorCount " << update->descriptorCount << " not a multiple of 4"; |
| 1860 | *error_msg = error_str.str(); |
| 1861 | return false; |
| 1862 | } |
| 1863 | } |
| 1864 | |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 1865 | // Update parameters all look good and descriptor updated so verify update contents |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 1866 | if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, dst_set, dst_type, dst_start_idx, func_name, error_code, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1867 | error_msg)) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 1868 | return false; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1869 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1870 | |
| 1871 | // All checks passed so update is good |
| 1872 | return true; |
| 1873 | } |
| 1874 | // Perform Copy update |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1875 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(ValidationStateTracker *dev_data, const VkCopyDescriptorSet *update, |
| 1876 | const DescriptorSet *src_set) { |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1877 | auto src_start_idx = src_set->GetGlobalIndexRangeFromBinding(update->srcBinding).start + update->srcArrayElement; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1878 | auto dst_start_idx = layout_->GetGlobalIndexRangeFromBinding(update->dstBinding).start + update->dstArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1879 | // Update parameters all look good so perform update |
| 1880 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 1881 | auto src = src_set->descriptors_[src_start_idx + di].get(); |
| 1882 | auto dst = descriptors_[dst_start_idx + di].get(); |
| 1883 | if (src->updated) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1884 | dst->CopyUpdate(this, state_data_, src); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 1885 | some_update_ = true; |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 1886 | change_count_++; |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 1887 | } else { |
| 1888 | dst->updated = false; |
| 1889 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1890 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1891 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1892 | if (!(layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1893 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 1894 | Invalidate(false); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1895 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1896 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1897 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame] | 1898 | // Update the drawing state for the affected descriptors. |
| 1899 | // Set cb_node to this set and this set to cb_node. |
| 1900 | // Add the bindings of the descriptor |
| 1901 | // Set the layout based on the current descriptor layout (will mask subsequent layer mismatch errors) |
| 1902 | // 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] | 1903 | // Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going |
| 1904 | // to be used in a draw by the given cb_node |
Jeremy Kniager | e682743 | 2020-04-01 09:05:56 -0600 | [diff] [blame] | 1905 | void cvdescriptorset::DescriptorSet::UpdateDrawState(ValidationStateTracker *device_data, CMD_BUFFER_STATE *cb_node, |
| 1906 | CMD_TYPE cmd_type, const PIPELINE_STATE *pipe, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame^] | 1907 | const BindingReqMap &binding_req_map) { |
Tony-LunarG | 7782280 | 2020-05-28 16:35:46 -0600 | [diff] [blame] | 1908 | if (!device_data->disabled[command_buffer_state] && !IsPushDescriptor()) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1909 | cb_node->AddChild(this); |
Jeff Bolz | afa429a | 2019-08-14 09:59:22 -0500 | [diff] [blame] | 1910 | } |
Jeff Bolz | e18e724 | 2019-08-12 20:55:22 -0500 | [diff] [blame] | 1911 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1912 | // Descriptor UpdateDrawState only call image layout validation callbacks. If it is disabled, skip the entire loop. |
| 1913 | if (device_data->disabled[image_layout_validation]) { |
Jeff Bolz | e18e724 | 2019-08-12 20:55:22 -0500 | [diff] [blame] | 1914 | return; |
| 1915 | } |
| 1916 | |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 1917 | // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's |
| 1918 | // resources |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1919 | CMD_BUFFER_STATE::CmdDrawDispatchInfo cmd_info = {}; |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 1920 | for (const auto &binding_req_pair : binding_req_map) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1921 | auto index = layout_->GetIndexFromBinding(binding_req_pair.first); |
locke-g | b3ce08f | 2019-09-30 12:30:56 -0600 | [diff] [blame] | 1922 | |
Tony-LunarG | 62c5dba | 2018-12-20 14:27:23 -0700 | [diff] [blame] | 1923 | // We aren't validating descriptors created with PARTIALLY_BOUND or UPDATE_AFTER_BIND, so don't record state |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1924 | auto flags = layout_->GetDescriptorBindingFlagsFromIndex(index); |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1925 | if (flags & (VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT)) { |
| 1926 | if (!(flags & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT)) { |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 1927 | cmd_info.binding_infos.emplace_back(binding_req_pair); |
locke-g | b3ce08f | 2019-09-30 12:30:56 -0600 | [diff] [blame] | 1928 | } |
Tony-LunarG | 62c5dba | 2018-12-20 14:27:23 -0700 | [diff] [blame] | 1929 | continue; |
| 1930 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1931 | auto range = layout_->GetGlobalIndexRangeFromIndex(index); |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 1932 | for (uint32_t i = range.start; i < range.end; ++i) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 1933 | const auto descriptor_class = descriptors_[i]->GetClass(); |
| 1934 | switch (descriptor_class) { |
| 1935 | case DescriptorClass::Image: |
| 1936 | case DescriptorClass::ImageSampler: { |
| 1937 | auto *image_desc = static_cast<ImageDescriptor *>(descriptors_[i].get()); |
| 1938 | image_desc->UpdateDrawState(device_data, cb_node); |
| 1939 | break; |
| 1940 | } |
| 1941 | default: |
| 1942 | break; |
| 1943 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 1944 | } |
| 1945 | } |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1946 | |
| 1947 | if (cmd_info.binding_infos.size() > 0) { |
| 1948 | cmd_info.cmd_type = cmd_type; |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1949 | if (cb_node->activeFramebuffer) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1950 | cmd_info.framebuffer = cb_node->activeFramebuffer->framebuffer(); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 1951 | cmd_info.attachments = cb_node->active_attachments; |
| 1952 | cmd_info.subpasses = cb_node->active_subpasses; |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1953 | } |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1954 | cb_node->validate_descriptorsets_in_queuesubmit[GetSet()].emplace_back(cmd_info); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 1955 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 1956 | } |
| 1957 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1958 | void cvdescriptorset::DescriptorSet::FilterOneBindingReq(const BindingReqMap::value_type &binding_req_pair, BindingReqMap *out_req, |
| 1959 | const TrackedBindings &bindings, uint32_t limit) { |
| 1960 | if (bindings.size() < limit) { |
| 1961 | const auto it = bindings.find(binding_req_pair.first); |
| 1962 | if (it == bindings.cend()) out_req->emplace(binding_req_pair); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1963 | } |
| 1964 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 1965 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1966 | void cvdescriptorset::DescriptorSet::FilterBindingReqs(const CMD_BUFFER_STATE &cb_state, const PIPELINE_STATE &pipeline, |
| 1967 | const BindingReqMap &in_req, BindingReqMap *out_req) const { |
| 1968 | // For const cleanliness we have to find in the maps... |
| 1969 | const auto validated_it = cached_validation_.find(&cb_state); |
| 1970 | if (validated_it == cached_validation_.cend()) { |
| 1971 | // We have nothing validated, copy in to out |
| 1972 | for (const auto &binding_req_pair : in_req) { |
| 1973 | out_req->emplace(binding_req_pair); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1974 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1975 | return; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1976 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1977 | const auto &validated = validated_it->second; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1978 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1979 | const auto image_sample_version_it = validated.image_samplers.find(&pipeline); |
| 1980 | const VersionedBindings *image_sample_version = nullptr; |
| 1981 | if (image_sample_version_it != validated.image_samplers.cend()) { |
| 1982 | image_sample_version = &(image_sample_version_it->second); |
| 1983 | } |
| 1984 | const auto &dynamic_buffers = validated.dynamic_buffers; |
| 1985 | const auto &non_dynamic_buffers = validated.non_dynamic_buffers; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1986 | const auto &stats = layout_->GetBindingTypeStats(); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1987 | for (const auto &binding_req_pair : in_req) { |
| 1988 | auto binding = binding_req_pair.first; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1989 | VkDescriptorSetLayoutBinding const *layout_binding = layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1990 | if (!layout_binding) { |
| 1991 | continue; |
| 1992 | } |
| 1993 | // Caching criteria differs per type. |
| 1994 | // If image_layout have changed , the image descriptors need to be validated against them. |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 1995 | if (IsBufferDescriptor(layout_binding->descriptorType)) { |
| 1996 | if (IsDynamicDescriptor(layout_binding->descriptorType)) { |
| 1997 | FilterOneBindingReq(binding_req_pair, out_req, dynamic_buffers, stats.dynamic_buffer_count); |
| 1998 | } else { |
| 1999 | FilterOneBindingReq(binding_req_pair, out_req, non_dynamic_buffers, stats.non_dynamic_buffer_count); |
| 2000 | } |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 2001 | } else { |
| 2002 | // This is rather crude, as the changed layouts may not impact the bound descriptors, |
| 2003 | // but the simple "versioning" is a simple "dirt" test. |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 2004 | bool stale = true; |
| 2005 | if (image_sample_version) { |
| 2006 | const auto version_it = image_sample_version->find(binding); |
| 2007 | if (version_it != image_sample_version->cend() && (version_it->second == cb_state.image_layout_change_count)) { |
| 2008 | stale = false; |
| 2009 | } |
| 2010 | } |
| 2011 | if (stale) { |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 2012 | out_req->emplace(binding_req_pair); |
| 2013 | } |
| 2014 | } |
| 2015 | } |
| 2016 | } |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 2017 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 2018 | void cvdescriptorset::DescriptorSet::UpdateValidationCache(const CMD_BUFFER_STATE &cb_state, const PIPELINE_STATE &pipeline, |
| 2019 | const BindingReqMap &updated_bindings) { |
| 2020 | // For const cleanliness we have to find in the maps... |
| 2021 | auto &validated = cached_validation_[&cb_state]; |
| 2022 | |
| 2023 | auto &image_sample_version = validated.image_samplers[&pipeline]; |
| 2024 | auto &dynamic_buffers = validated.dynamic_buffers; |
| 2025 | auto &non_dynamic_buffers = validated.non_dynamic_buffers; |
| 2026 | for (const auto &binding_req_pair : updated_bindings) { |
| 2027 | auto binding = binding_req_pair.first; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2028 | VkDescriptorSetLayoutBinding const *layout_binding = layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding); |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 2029 | if (!layout_binding) { |
| 2030 | continue; |
| 2031 | } |
| 2032 | // Caching criteria differs per type. |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 2033 | if (IsBufferDescriptor(layout_binding->descriptorType)) { |
| 2034 | if (IsDynamicDescriptor(layout_binding->descriptorType)) { |
| 2035 | dynamic_buffers.emplace(binding); |
| 2036 | } else { |
| 2037 | non_dynamic_buffers.emplace(binding); |
| 2038 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 2039 | } else { |
| 2040 | // Save the layout change version... |
| 2041 | image_sample_version[binding] = cb_state.image_layout_change_count; |
| 2042 | } |
| 2043 | } |
| 2044 | } |
| 2045 | |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 2046 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const ValidationStateTracker *dev_data, const VkSampler *immut) |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2047 | : Descriptor(PlainSampler), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2048 | if (immut) { |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 2049 | sampler_state_ = dev_data->GetConstCastShared<SAMPLER_STATE>(*immut); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2050 | immutable_ = true; |
| 2051 | updated = true; |
| 2052 | } |
| 2053 | } |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 2054 | // 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] | 2055 | bool CoreChecks::ValidateSampler(const VkSampler sampler) const { return (GetSamplerState(sampler) != nullptr); } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2056 | |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2057 | bool CoreChecks::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, |
John Zulauf | bd9b341 | 2019-08-22 17:16:11 -0600 | [diff] [blame] | 2058 | const char *func_name, std::string *error_code, std::string *error_msg) const { |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2059 | auto iv_state = GetImageViewState(image_view); |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2060 | assert(iv_state); |
| 2061 | |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 2062 | // 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] | 2063 | // Validate that imageLayout is compatible with aspect_mask and image format |
| 2064 | // and validate that image usage bits are correct for given usage |
Jeremy Gebben | b4d1701 | 2021-07-08 13:18:15 -0600 | [diff] [blame] | 2065 | VkImageAspectFlags aspect_mask = iv_state->normalized_subresource_range.aspectMask; |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 2066 | VkImage image = iv_state->create_info.image; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2067 | VkFormat format = VK_FORMAT_MAX_ENUM; |
| 2068 | VkImageUsageFlags usage = 0; |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2069 | auto image_node = GetImageState(image); |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2070 | assert(image_node); |
Chris Forbes | 67757ff | 2017-07-21 13:59:01 -0700 | [diff] [blame] | 2071 | |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2072 | format = image_node->createInfo.format; |
| 2073 | usage = image_node->createInfo.usage; |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2074 | const auto stencil_usage_info = LvlFindInChain<VkImageStencilUsageCreateInfo>(image_node->createInfo.pNext); |
Ricardo Garcia | 3f5984c | 2020-04-09 10:56:34 +0200 | [diff] [blame] | 2075 | if (stencil_usage_info) { |
| 2076 | usage |= stencil_usage_info->stencilUsage; |
| 2077 | } |
Mark Lobodzinski | 03d0006 | 2020-06-15 14:35:45 -0600 | [diff] [blame] | 2078 | |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2079 | // Validate that memory is bound to image |
sfricke-samsung | 52dbd08 | 2021-09-23 11:17:58 -0700 | [diff] [blame] | 2080 | if (ValidateMemoryIsBoundToImage(image_node, func_name, kVUID_Core_Bound_Resource_FreedMemoryAccess)) { |
| 2081 | *error_code = kVUID_Core_Bound_Resource_FreedMemoryAccess; |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2082 | *error_msg = "No memory bound to image."; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2083 | return false; |
| 2084 | } |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2085 | |
| 2086 | // KHR_maintenance1 allows rendering into 2D or 2DArray views which slice a 3D image, |
| 2087 | // but not binding them to descriptor sets. |
Jeremy Gebben | 11a68a3 | 2021-07-29 11:59:22 -0600 | [diff] [blame] | 2088 | if (iv_state->IsDepthSliced()) { |
Mark Lobodzinski | 3fc3d75 | 2019-06-24 14:22:46 -0600 | [diff] [blame] | 2089 | *error_code = "VUID-VkDescriptorImageInfo-imageView-00343"; |
| 2090 | *error_msg = "ImageView must not be a 2D or 2DArray view of a 3D image"; |
| 2091 | return false; |
| 2092 | } |
| 2093 | |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2094 | // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under |
| 2095 | // vkCreateImageView(). What's the best way to create unique id for these cases? |
sfricke-samsung | 52dbd08 | 2021-09-23 11:17:58 -0700 | [diff] [blame] | 2096 | *error_code = kVUID_Core_DrawState_InvalidImageView; |
Dave Houlton | 1d2022c | 2017-03-29 11:43:58 -0600 | [diff] [blame] | 2097 | bool ds = FormatIsDepthOrStencil(format); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2098 | switch (image_layout) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2099 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 2100 | // Only Color bit must be set |
| 2101 | 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] | 2102 | std::stringstream error_str; |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2103 | error_str |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2104 | << "ImageView (" << report_data->FormatHandle(image_view) |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2105 | << ") 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] | 2106 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2107 | return false; |
| 2108 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2109 | // format must NOT be DS |
| 2110 | if (ds) { |
| 2111 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2112 | error_str << "ImageView (" << report_data->FormatHandle(image_view) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2113 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is " |
| 2114 | << string_VkFormat(format) << " which is not a color format."; |
| 2115 | *error_msg = error_str.str(); |
| 2116 | return false; |
| 2117 | } |
| 2118 | break; |
| 2119 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 2120 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 2121 | // 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] | 2122 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2123 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2124 | // both must NOT be set |
| 2125 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2126 | error_str << "ImageView (" << report_data->FormatHandle(image_view) |
Mark Lobodzinski | 6b04292 | 2019-06-21 14:46:42 -0600 | [diff] [blame] | 2127 | << ") has both STENCIL and DEPTH aspects set"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2128 | *error_msg = error_str.str(); |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 2129 | return false; |
| 2130 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2131 | } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 2132 | // Neither were set |
| 2133 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2134 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ") has layout " |
Mark Lobodzinski | 6b04292 | 2019-06-21 14:46:42 -0600 | [diff] [blame] | 2135 | << 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] | 2136 | *error_msg = error_str.str(); |
| 2137 | return false; |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 2138 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2139 | // format must be DS |
| 2140 | if (!ds) { |
| 2141 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2142 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ") has layout " |
Mark Lobodzinski | 6b04292 | 2019-06-21 14:46:42 -0600 | [diff] [blame] | 2143 | << string_VkImageLayout(image_layout) << " but the image format is " << string_VkFormat(format) |
| 2144 | << " which is not a depth/stencil format."; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2145 | *error_msg = error_str.str(); |
| 2146 | return false; |
| 2147 | } |
| 2148 | break; |
| 2149 | default: |
| 2150 | // For other layouts if the source is depth/stencil image, both aspect bits must not be set |
| 2151 | if (ds) { |
| 2152 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 2153 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 2154 | // both must NOT be set |
| 2155 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2156 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ") has layout " |
Mark Lobodzinski | 6b04292 | 2019-06-21 14:46:42 -0600 | [diff] [blame] | 2157 | << string_VkImageLayout(image_layout) << " and is using depth/stencil image of format " |
| 2158 | << string_VkFormat(format) |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2159 | << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil " |
| 2160 | "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 2161 | "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil " |
| 2162 | "reads respectively."; |
Mark Lobodzinski | 4d05d7a | 2019-06-25 09:12:06 -0600 | [diff] [blame] | 2163 | *error_code = "VUID-VkDescriptorImageInfo-imageView-01976"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2164 | *error_msg = error_str.str(); |
| 2165 | return false; |
| 2166 | } |
| 2167 | } |
| 2168 | } |
| 2169 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2170 | } |
| 2171 | // 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] | 2172 | // 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] | 2173 | // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images |
| 2174 | // under vkCreateImage() |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2175 | const char *error_usage_bit = nullptr; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2176 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2177 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
sfricke-samsung | 088f124 | 2020-06-06 02:15:35 -0700 | [diff] [blame] | 2178 | if (iv_state->samplerConversion != VK_NULL_HANDLE) { |
| 2179 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-01946"; |
| 2180 | std::stringstream error_str; |
| 2181 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ")" |
| 2182 | << "used as a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE can't be created with VkSamplerYcbcrConversion"; |
| 2183 | *error_msg = error_str.str(); |
| 2184 | return false; |
| 2185 | } |
| 2186 | // drop through |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2187 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 2188 | if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { |
| 2189 | error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT"; |
sfricke-samsung | 7923f21 | 2020-02-29 21:17:35 -0800 | [diff] [blame] | 2190 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00337"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2191 | } |
| 2192 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2193 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2194 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 2195 | if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 2196 | error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT"; |
sfricke-samsung | 7923f21 | 2020-02-29 21:17:35 -0800 | [diff] [blame] | 2197 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00339"; |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 2198 | } else if ((VK_IMAGE_LAYOUT_GENERAL != image_layout) && |
| 2199 | (!IsExtEnabled(device_extensions.vk_khr_shared_presentable_image) || |
| 2200 | (VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR != image_layout))) { |
sfricke-samsung | f105898 | 2020-09-10 22:36:49 -0700 | [diff] [blame] | 2201 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-04152"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2202 | std::stringstream error_str; |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2203 | error_str << "Descriptor update with descriptorType VK_DESCRIPTOR_TYPE_STORAGE_IMAGE" |
| 2204 | << " is being updated with invalid imageLayout " << string_VkImageLayout(image_layout) << " for image " |
| 2205 | << report_data->FormatHandle(image) << " in imageView " << report_data->FormatHandle(image_view) |
| 2206 | << ". Allowed layouts are: VK_IMAGE_LAYOUT_GENERAL"; |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 2207 | if (IsExtEnabled(device_extensions.vk_khr_shared_presentable_image)) { |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2208 | error_str << " or VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR"; |
Tobin Ehlis | bb03e5f | 2017-05-11 08:52:51 -0600 | [diff] [blame] | 2209 | } |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2210 | *error_msg = error_str.str(); |
| 2211 | return false; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2212 | } |
| 2213 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2214 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2215 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 2216 | if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
| 2217 | error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT"; |
sfricke-samsung | 7923f21 | 2020-02-29 21:17:35 -0800 | [diff] [blame] | 2218 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00338"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2219 | } |
| 2220 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2221 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2222 | default: |
| 2223 | break; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2224 | } |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2225 | if (error_usage_bit) { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2226 | std::stringstream error_str; |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2227 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ") with usage mask " << std::hex << std::showbase |
| 2228 | << usage << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 2229 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2230 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 2231 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2232 | } |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2233 | |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2234 | // All the following types share the same image layouts |
| 2235 | // checkf or Storage Images above |
| 2236 | if ((type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) || (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) || |
| 2237 | (type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) { |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2238 | // Test that the layout is compatible with the descriptorType for the two sampled image types |
| 2239 | const static std::array<VkImageLayout, 3> valid_layouts = { |
Jeremy Hayes | d0549f6 | 2019-06-05 10:15:36 -0600 | [diff] [blame] | 2240 | {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] | 2241 | |
| 2242 | struct ExtensionLayout { |
| 2243 | VkImageLayout layout; |
Tony-LunarG | 2ec96bb | 2019-11-26 13:43:02 -0700 | [diff] [blame] | 2244 | ExtEnabled DeviceExtensions::*extension; |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2245 | }; |
Ricardo Garcia | 602c202 | 2021-07-30 10:42:17 +0200 | [diff] [blame] | 2246 | const static std::array<ExtensionLayout, 7> extended_layouts{{ |
Jeremy Gebben | 579aaca | 2021-02-15 13:36:18 -0700 | [diff] [blame] | 2247 | // Note double brace req'd for aggregate initialization |
| 2248 | {VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, &DeviceExtensions::vk_khr_shared_presentable_image}, |
| 2249 | {VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL, &DeviceExtensions::vk_khr_maintenance2}, |
| 2250 | {VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL, &DeviceExtensions::vk_khr_maintenance2}, |
Mike Schuchardt | c57de4a | 2021-07-20 17:26:32 -0700 | [diff] [blame] | 2251 | {VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR, &DeviceExtensions::vk_khr_synchronization2}, |
| 2252 | {VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, &DeviceExtensions::vk_khr_synchronization2}, |
Ricardo Garcia | 602c202 | 2021-07-30 10:42:17 +0200 | [diff] [blame] | 2253 | {VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL, &DeviceExtensions::vk_khr_separate_depth_stencil_layouts}, |
| 2254 | {VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL, &DeviceExtensions::vk_khr_separate_depth_stencil_layouts}, |
Jeremy Gebben | 579aaca | 2021-02-15 13:36:18 -0700 | [diff] [blame] | 2255 | }}; |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2256 | auto is_layout = [image_layout, this](const ExtensionLayout &ext_layout) { |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 2257 | return IsExtEnabled(device_extensions.*(ext_layout.extension)) && (ext_layout.layout == image_layout); |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2258 | }; |
| 2259 | |
| 2260 | bool valid_layout = (std::find(valid_layouts.cbegin(), valid_layouts.cend(), image_layout) != valid_layouts.cend()) || |
| 2261 | std::any_of(extended_layouts.cbegin(), extended_layouts.cend(), is_layout); |
| 2262 | |
| 2263 | if (!valid_layout) { |
sfricke-samsung | f105898 | 2020-09-10 22:36:49 -0700 | [diff] [blame] | 2264 | // The following works as currently all 3 descriptor types share the same set of valid layouts |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2265 | switch (type) { |
| 2266 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
Shannon McPherson | 2c793ba | 2020-08-28 12:13:24 -0600 | [diff] [blame] | 2267 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-04149"; |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2268 | break; |
| 2269 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
Shannon McPherson | 2c793ba | 2020-08-28 12:13:24 -0600 | [diff] [blame] | 2270 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-04150"; |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2271 | break; |
| 2272 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
sfricke-samsung | f105898 | 2020-09-10 22:36:49 -0700 | [diff] [blame] | 2273 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-04151"; |
sfricke-samsung | ada55a1 | 2020-08-15 03:39:41 -0700 | [diff] [blame] | 2274 | break; |
| 2275 | default: |
| 2276 | break; |
| 2277 | } |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2278 | std::stringstream error_str; |
| 2279 | error_str << "Descriptor update with descriptorType " << string_VkDescriptorType(type) |
Mark Lobodzinski | 74eddba | 2019-06-21 14:16:33 -0600 | [diff] [blame] | 2280 | << " is being updated with invalid imageLayout " << string_VkImageLayout(image_layout) << " for image " |
Mark Lobodzinski | 298f0fd | 2020-04-09 11:50:19 -0600 | [diff] [blame] | 2281 | << report_data->FormatHandle(image) << " in imageView " << report_data->FormatHandle(image_view) |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2282 | << ". Allowed layouts are: VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, " |
| 2283 | << "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL"; |
| 2284 | for (auto &ext_layout : extended_layouts) { |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 2285 | if (IsExtEnabled(device_extensions.*(ext_layout.extension))) { |
John Zulauf | f4c0788 | 2019-01-24 14:03:36 -0700 | [diff] [blame] | 2286 | error_str << ", " << string_VkImageLayout(ext_layout.layout); |
| 2287 | } |
| 2288 | } |
| 2289 | *error_msg = error_str.str(); |
| 2290 | return false; |
| 2291 | } |
| 2292 | } |
| 2293 | |
sfricke-samsung | bd0e805 | 2020-06-06 01:36:39 -0700 | [diff] [blame] | 2294 | if ((type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) || (type == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) { |
| 2295 | const VkComponentMapping components = iv_state->create_info.components; |
| 2296 | if (IsIdentitySwizzle(components) == false) { |
| 2297 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00336"; |
| 2298 | std::stringstream error_str; |
| 2299 | error_str << "ImageView (" << report_data->FormatHandle(image_view) << ") has a non-identiy swizzle component, " |
| 2300 | << " r swizzle = " << string_VkComponentSwizzle(components.r) << "," |
| 2301 | << " g swizzle = " << string_VkComponentSwizzle(components.g) << "," |
| 2302 | << " b swizzle = " << string_VkComponentSwizzle(components.b) << "," |
| 2303 | << " a swizzle = " << string_VkComponentSwizzle(components.a) << "."; |
| 2304 | *error_msg = error_str.str(); |
| 2305 | return false; |
| 2306 | } |
| 2307 | } |
| 2308 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2309 | return true; |
| 2310 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2311 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2312 | // Helper template to change shared pointer members of a Descriptor, while |
| 2313 | // correctly managing links to the parent DescriptorSet. |
| 2314 | // src and dst are shared pointers. |
| 2315 | template <typename T> |
| 2316 | static void ReplaceStatePtr(DescriptorSet *set_state, T &dst, const T &src) { |
| 2317 | if (dst) { |
| 2318 | dst->RemoveParent(set_state); |
| 2319 | } |
| 2320 | dst = src; |
| 2321 | if (dst) { |
| 2322 | dst->AddParent(set_state); |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2327 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 2328 | if (!immutable_) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2329 | ReplaceStatePtr(set_state, sampler_state_ , dev_data->GetConstCastShared<SAMPLER_STATE>(update->pImageInfo[index].sampler)); |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 2330 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2331 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2332 | } |
| 2333 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2334 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2335 | const Descriptor *src) { |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2336 | updated = true; |
| 2337 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2338 | if (src->descriptor_class == Mutable) { |
| 2339 | this->descriptor_class = Mutable; |
| 2340 | return; |
| 2341 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2342 | auto *sampler_src = static_cast<const SamplerDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2343 | if (!immutable_) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2344 | ReplaceStatePtr(set_state, sampler_state_, sampler_src->sampler_state_); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 2345 | } |
| 2346 | } |
| 2347 | |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 2348 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const ValidationStateTracker *dev_data, const VkSampler *immut) |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2349 | : ImageDescriptor(ImageSampler), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2350 | if (immut) { |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 2351 | sampler_state_ = dev_data->GetConstCastShared<SAMPLER_STATE>(*immut); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2352 | immutable_ = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2353 | } |
| 2354 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2355 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2356 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 2357 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2358 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2359 | const auto &image_info = update->pImageInfo[index]; |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 2360 | if (!immutable_) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2361 | ReplaceStatePtr(set_state, sampler_state_, dev_data->GetConstCastShared<SAMPLER_STATE>(image_info.sampler)); |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 2362 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2363 | image_layout_ = image_info.imageLayout; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2364 | ReplaceStatePtr(set_state, image_view_state_, dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2365 | } |
| 2366 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2367 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2368 | const Descriptor *src) { |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2369 | updated = true; |
| 2370 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2371 | if (src->descriptor_class == Mutable) { |
| 2372 | this->descriptor_class = Mutable; |
| 2373 | return; |
| 2374 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2375 | auto *image_src = static_cast<const ImageSamplerDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2376 | if (!immutable_) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2377 | ReplaceStatePtr(set_state, sampler_state_, image_src->sampler_state_); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2378 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2379 | ImageDescriptor::CopyUpdate(set_state, dev_data, src); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 2380 | } |
| 2381 | |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2382 | cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type) |
| 2383 | : Descriptor(Image), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {} |
| 2384 | |
| 2385 | cvdescriptorset::ImageDescriptor::ImageDescriptor(DescriptorClass class_) |
| 2386 | : Descriptor(class_), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) {} |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2387 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2388 | void cvdescriptorset::ImageDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2389 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2390 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2391 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2392 | image_layout_ = image_info.imageLayout; |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 2393 | image_view_state_ = dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2394 | } |
| 2395 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2396 | void cvdescriptorset::ImageDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2397 | const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2398 | updated = true; |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2399 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2400 | if (src->descriptor_class == Mutable) { |
| 2401 | this->descriptor_class = Mutable; |
| 2402 | return; |
| 2403 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2404 | auto *image_src = static_cast<const ImageDescriptor *>(src); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2405 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2406 | image_layout_ = image_src->image_layout_; |
| 2407 | ReplaceStatePtr(set_state, image_view_state_, image_src->image_view_state_); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2408 | } |
| 2409 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 2410 | void cvdescriptorset::ImageDescriptor::UpdateDrawState(ValidationStateTracker *dev_data, CMD_BUFFER_STATE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 2411 | // Add binding for image |
Jeff Bolz | faffeb3 | 2019-10-04 12:47:16 -0500 | [diff] [blame] | 2412 | auto iv_state = GetImageViewState(); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 2413 | if (iv_state) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2414 | dev_data->CallSetImageViewInitialLayoutCallback(cb_node, *iv_state, image_layout_); |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 2415 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 2416 | } |
| 2417 | |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2418 | cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type) |
| 2419 | : Descriptor(GeneralBuffer), offset_(0), range_(0) {} |
| 2420 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2421 | void cvdescriptorset::BufferDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2422 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2423 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2424 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2425 | offset_ = buffer_info.offset; |
| 2426 | range_ = buffer_info.range; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2427 | ReplaceStatePtr(set_state, buffer_state_, dev_data->GetConstCastShared<BUFFER_STATE>(buffer_info.buffer)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2428 | } |
| 2429 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2430 | void cvdescriptorset::BufferDescriptor::CopyUpdate(DescriptorSet* set_state, const ValidationStateTracker *dev_data, |
| 2431 | const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2432 | updated = true; |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2433 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2434 | if (src->descriptor_class == Mutable) { |
| 2435 | this->descriptor_class = Mutable; |
| 2436 | return; |
| 2437 | } |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 2438 | const auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2439 | offset_ = buff_desc->offset_; |
| 2440 | range_ = buff_desc->range_; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2441 | ReplaceStatePtr(set_state, buffer_state_, buff_desc->buffer_state_); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 2442 | } |
| 2443 | |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2444 | cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : Descriptor(TexelBuffer) {} |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2445 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2446 | void cvdescriptorset::TexelDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2447 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2448 | updated = true; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2449 | ReplaceStatePtr(set_state, buffer_view_state_, |
| 2450 | dev_data->GetConstCastShared<BUFFER_VIEW_STATE>(update->pTexelBufferView[index])); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 2451 | } |
| 2452 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2453 | void cvdescriptorset::TexelDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2454 | const Descriptor *src) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2455 | updated = true; |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2456 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2457 | if (src->descriptor_class == Mutable) { |
| 2458 | this->descriptor_class = Mutable; |
| 2459 | return; |
| 2460 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2461 | ReplaceStatePtr(set_state, buffer_view_state_, static_cast<const TexelDescriptor *>(src)->buffer_view_state_); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 2462 | } |
| 2463 | |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2464 | cvdescriptorset::AccelerationStructureDescriptor::AccelerationStructureDescriptor(const VkDescriptorType type) |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2465 | : Descriptor(AccelerationStructure), acc_(VK_NULL_HANDLE), acc_nv_(VK_NULL_HANDLE) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2466 | is_khr_ = false; |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2467 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2468 | void cvdescriptorset::AccelerationStructureDescriptor::WriteUpdate(DescriptorSet *set_state, |
| 2469 | const ValidationStateTracker *dev_data, |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2470 | const VkWriteDescriptorSet *update, const uint32_t index) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2471 | const auto *acc_info = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureKHR>(update->pNext); |
| 2472 | const auto *acc_info_nv = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureNV>(update->pNext); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2473 | assert(acc_info || acc_info_nv); |
| 2474 | is_khr_ = (acc_info != NULL); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2475 | updated = true; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2476 | if (is_khr_) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2477 | acc_ = acc_info->pAccelerationStructures[index]; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2478 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_)); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2479 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2480 | acc_nv_ = acc_info_nv->pAccelerationStructures[index]; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2481 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_)); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2482 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2483 | } |
| 2484 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2485 | void cvdescriptorset::AccelerationStructureDescriptor::CopyUpdate(DescriptorSet *set_state, |
| 2486 | const ValidationStateTracker *dev_data, const Descriptor *src) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2487 | auto acc_desc = static_cast<const AccelerationStructureDescriptor *>(src); |
| 2488 | updated = true; |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 2489 | // Mutable descriptors not currently tracked or validated. If copied from mutable, set to mutable to keep from validating. |
| 2490 | if (src->descriptor_class == Mutable) { |
| 2491 | this->descriptor_class = Mutable; |
| 2492 | return; |
| 2493 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2494 | if (is_khr_) { |
| 2495 | acc_ = acc_desc->acc_; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2496 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_)); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2497 | } else { |
| 2498 | acc_nv_ = acc_desc->acc_nv_; |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2499 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_)); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2500 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2501 | } |
| 2502 | |
Jeremy Gebben | 059ab50 | 2021-04-26 11:25:02 -0600 | [diff] [blame] | 2503 | cvdescriptorset::MutableDescriptor::MutableDescriptor() : Descriptor(Mutable) { active_descriptor_class_ = NoDescriptorClass; } |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 2504 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2505 | void cvdescriptorset::MutableDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 2506 | const VkWriteDescriptorSet *update, const uint32_t index) { |
| 2507 | updated = true; |
| 2508 | } |
| 2509 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 2510 | void cvdescriptorset::MutableDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
| 2511 | const Descriptor *src) { |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 2512 | updated = true; |
| 2513 | } |
| 2514 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2515 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 2516 | // sets, and then calls their respective Validate[Write|Copy]Update functions. |
| 2517 | // If the update hits an issue for which the callback returns "true", meaning that the call down the chain should |
| 2518 | // be skipped, then true is returned. |
| 2519 | // If there is no issue with the update, then false is returned. |
Mark Lobodzinski | 3840ca0 | 2019-03-08 18:36:11 -0700 | [diff] [blame] | 2520 | bool CoreChecks::ValidateUpdateDescriptorSets(uint32_t write_count, const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2521 | const VkCopyDescriptorSet *p_cds, const char *func_name) const { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2522 | bool skip = false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2523 | // Validate Write updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2524 | for (uint32_t i = 0; i < write_count; i++) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2525 | auto dest_set = p_wds[i].dstSet; |
Mark Lobodzinski | fc2f0d3 | 2019-03-06 11:25:39 -0700 | [diff] [blame] | 2526 | auto set_node = GetSetNode(dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 2527 | if (!set_node) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2528 | skip |= LogError(dest_set, kVUID_Core_DrawState_InvalidDescriptorSet, |
| 2529 | "Cannot call %s on %s that has not been allocated in pDescriptorWrites[%u].", func_name, |
| 2530 | report_data->FormatHandle(dest_set).c_str(), i); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2531 | } else { |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2532 | std::string error_code; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2533 | std::string error_str; |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 2534 | if (!ValidateWriteUpdate(set_node, &p_wds[i], func_name, &error_code, &error_str, false)) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2535 | skip |= |
| 2536 | LogError(dest_set, error_code, "%s pDescriptorWrites[%u] failed write update validation for %s with error: %s.", |
| 2537 | func_name, i, report_data->FormatHandle(dest_set).c_str(), error_str.c_str()); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2538 | } |
| 2539 | } |
sourav parmar | a24fb7b | 2020-05-26 10:50:04 -0700 | [diff] [blame] | 2540 | if (p_wds[i].pNext) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2541 | const auto *pnext_struct = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureKHR>(p_wds[i].pNext); |
Mark Lobodzinski | 17dc460 | 2020-05-29 07:48:40 -0600 | [diff] [blame] | 2542 | if (pnext_struct) { |
| 2543 | for (uint32_t j = 0; j < pnext_struct->accelerationStructureCount; ++j) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2544 | const ACCELERATION_STRUCTURE_STATE_KHR *as_state = |
| 2545 | GetAccelerationStructureStateKHR(pnext_struct->pAccelerationStructures[j]); |
| 2546 | if (as_state && (as_state->create_infoKHR.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR && |
sourav parmar | 766e2a7 | 2020-12-03 16:17:11 -0800 | [diff] [blame] | 2547 | (as_state->create_infoKHR.type != VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR && |
| 2548 | as_state->create_infoKHR.type != VK_ACCELERATION_STRUCTURE_TYPE_GENERIC_KHR))) { |
sourav parmar | a24fb7b | 2020-05-26 10:50:04 -0700 | [diff] [blame] | 2549 | skip |= |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2550 | LogError(dest_set, "VUID-VkWriteDescriptorSetAccelerationStructureKHR-pAccelerationStructures-03579", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2551 | "%s: For pDescriptorWrites[%u] acceleration structure in pAccelerationStructures[%u] must " |
| 2552 | "have been created with " |
sourav parmar | bcee751 | 2020-12-28 14:34:49 -0800 | [diff] [blame] | 2553 | "VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR or VK_ACCELERATION_STRUCTURE_TYPE_GENERIC_KHR.", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2554 | func_name, i, j); |
sourav parmar | a24fb7b | 2020-05-26 10:50:04 -0700 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2558 | const auto *pnext_struct_nv = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureNV>(p_wds[i].pNext); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2559 | if (pnext_struct_nv) { |
| 2560 | for (uint32_t j = 0; j < pnext_struct_nv->accelerationStructureCount; ++j) { |
| 2561 | const ACCELERATION_STRUCTURE_STATE *as_state = |
| 2562 | GetAccelerationStructureStateNV(pnext_struct_nv->pAccelerationStructures[j]); |
| 2563 | if (as_state && (as_state->create_infoNV.sType == VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_NV && |
| 2564 | as_state->create_infoNV.info.type != VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV)) { |
| 2565 | skip |= LogError(dest_set, "VUID-VkWriteDescriptorSetAccelerationStructureNV-pAccelerationStructures-03748", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2566 | "%s: For pDescriptorWrites[%u] acceleration structure in pAccelerationStructures[%u] must " |
| 2567 | "have been created with" |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2568 | " VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_NV.", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2569 | func_name, i, j); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | } |
sourav parmar | a24fb7b | 2020-05-26 10:50:04 -0700 | [diff] [blame] | 2573 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2574 | } |
| 2575 | // Now validate copy updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 2576 | for (uint32_t i = 0; i < copy_count; ++i) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2577 | auto dst_set = p_cds[i].dstSet; |
| 2578 | auto src_set = p_cds[i].srcSet; |
Mark Lobodzinski | fc2f0d3 | 2019-03-06 11:25:39 -0700 | [diff] [blame] | 2579 | auto src_node = GetSetNode(src_set); |
| 2580 | auto dst_node = GetSetNode(dst_set); |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 2581 | // Object_tracker verifies that src & dest descriptor set are valid |
| 2582 | assert(src_node); |
| 2583 | assert(dst_node); |
Dave Houlton | d8ed021 | 2018-05-16 17:18:24 -0600 | [diff] [blame] | 2584 | std::string error_code; |
Tobin Ehlis | a171275 | 2017-01-04 09:41:47 -0700 | [diff] [blame] | 2585 | std::string error_str; |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2586 | if (!ValidateCopyUpdate(&p_cds[i], dst_node, src_node, func_name, &error_code, &error_str)) { |
Mark Lobodzinski | 9d38ea2 | 2020-03-16 18:22:16 -0600 | [diff] [blame] | 2587 | LogObjectList objlist(dst_set); |
| 2588 | objlist.add(src_set); |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2589 | skip |= LogError(objlist, error_code, "%s pDescriptorCopies[%u] failed copy update from %s to %s with error: %s.", |
| 2590 | func_name, i, report_data->FormatHandle(src_set).c_str(), report_data->FormatHandle(dst_set).c_str(), |
| 2591 | error_str.c_str()); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2592 | } |
| 2593 | } |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 2594 | return skip; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2595 | } |
| 2596 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 2597 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 2598 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 2599 | // with the same set of updates. |
| 2600 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 2601 | // calling down the chain. |
John Zulauf | e3b35f3 | 2019-06-25 14:21:21 -0600 | [diff] [blame] | 2602 | void cvdescriptorset::PerformUpdateDescriptorSets(ValidationStateTracker *dev_data, uint32_t write_count, |
| 2603 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 2604 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2605 | // Write updates first |
| 2606 | uint32_t i = 0; |
| 2607 | for (i = 0; i < write_count; ++i) { |
| 2608 | auto dest_set = p_wds[i].dstSet; |
Mark Lobodzinski | fc2f0d3 | 2019-03-06 11:25:39 -0700 | [diff] [blame] | 2609 | auto set_node = dev_data->GetSetNode(dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 2610 | if (set_node) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 2611 | set_node->PerformWriteUpdate(dev_data, &p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | // Now copy updates |
| 2615 | for (i = 0; i < copy_count; ++i) { |
| 2616 | auto dst_set = p_cds[i].dstSet; |
| 2617 | auto src_set = p_cds[i].srcSet; |
Mark Lobodzinski | fc2f0d3 | 2019-03-06 11:25:39 -0700 | [diff] [blame] | 2618 | auto src_node = dev_data->GetSetNode(src_set); |
| 2619 | auto dst_node = dev_data->GetSetNode(dst_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 2620 | if (src_node && dst_node) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 2621 | dst_node->PerformCopyUpdate(dev_data, &p_cds[i], src_node); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | } |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 2625 | |
John Zulauf | e3b35f3 | 2019-06-25 14:21:21 -0600 | [diff] [blame] | 2626 | cvdescriptorset::DecodedTemplateUpdate::DecodedTemplateUpdate(const ValidationStateTracker *device_data, |
| 2627 | VkDescriptorSet descriptorSet, const TEMPLATE_STATE *template_state, |
| 2628 | const void *pData, VkDescriptorSetLayout push_layout) { |
John Zulauf | b845eb2 | 2018-10-12 11:41:06 -0600 | [diff] [blame] | 2629 | auto const &create_info = template_state->create_info; |
| 2630 | inline_infos.resize(create_info.descriptorUpdateEntryCount); // Make sure we have one if we need it |
sourav parmar | 480d277 | 2021-01-24 22:24:54 -0800 | [diff] [blame] | 2631 | inline_infos_khr.resize(create_info.descriptorUpdateEntryCount); |
| 2632 | inline_infos_nv.resize(create_info.descriptorUpdateEntryCount); |
John Zulauf | b845eb2 | 2018-10-12 11:41:06 -0600 | [diff] [blame] | 2633 | desc_writes.reserve(create_info.descriptorUpdateEntryCount); // emplaced, so reserved without initialization |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 2634 | VkDescriptorSetLayout effective_dsl = create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET |
| 2635 | ? create_info.descriptorSetLayout |
| 2636 | : push_layout; |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 2637 | auto layout_obj = device_data->GetDescriptorSetLayoutShared(effective_dsl); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 2638 | |
| 2639 | // Create a WriteDescriptorSet struct for each template update entry |
| 2640 | for (uint32_t i = 0; i < create_info.descriptorUpdateEntryCount; i++) { |
| 2641 | auto binding_count = layout_obj->GetDescriptorCountFromBinding(create_info.pDescriptorUpdateEntries[i].dstBinding); |
| 2642 | auto binding_being_updated = create_info.pDescriptorUpdateEntries[i].dstBinding; |
| 2643 | auto dst_array_element = create_info.pDescriptorUpdateEntries[i].dstArrayElement; |
| 2644 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 2645 | desc_writes.reserve(desc_writes.size() + create_info.pDescriptorUpdateEntries[i].descriptorCount); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 2646 | for (uint32_t j = 0; j < create_info.pDescriptorUpdateEntries[i].descriptorCount; j++) { |
| 2647 | desc_writes.emplace_back(); |
| 2648 | auto &write_entry = desc_writes.back(); |
| 2649 | |
| 2650 | size_t offset = create_info.pDescriptorUpdateEntries[i].offset + j * create_info.pDescriptorUpdateEntries[i].stride; |
| 2651 | char *update_entry = (char *)(pData) + offset; |
| 2652 | |
| 2653 | if (dst_array_element >= binding_count) { |
| 2654 | dst_array_element = 0; |
Mark Lobodzinski | 4aa479d | 2017-03-10 09:14:00 -0700 | [diff] [blame] | 2655 | binding_being_updated = layout_obj->GetNextValidBinding(binding_being_updated); |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | write_entry.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 2659 | write_entry.pNext = NULL; |
| 2660 | write_entry.dstSet = descriptorSet; |
| 2661 | write_entry.dstBinding = binding_being_updated; |
| 2662 | write_entry.dstArrayElement = dst_array_element; |
| 2663 | write_entry.descriptorCount = 1; |
| 2664 | write_entry.descriptorType = create_info.pDescriptorUpdateEntries[i].descriptorType; |
| 2665 | |
| 2666 | switch (create_info.pDescriptorUpdateEntries[i].descriptorType) { |
| 2667 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 2668 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 2669 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 2670 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 2671 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 2672 | write_entry.pImageInfo = reinterpret_cast<VkDescriptorImageInfo *>(update_entry); |
| 2673 | break; |
| 2674 | |
| 2675 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 2676 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 2677 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 2678 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 2679 | write_entry.pBufferInfo = reinterpret_cast<VkDescriptorBufferInfo *>(update_entry); |
| 2680 | break; |
| 2681 | |
| 2682 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 2683 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 2684 | write_entry.pTexelBufferView = reinterpret_cast<VkBufferView *>(update_entry); |
| 2685 | break; |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 2686 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: { |
| 2687 | VkWriteDescriptorSetInlineUniformBlockEXT *inline_info = &inline_infos[i]; |
| 2688 | inline_info->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_INLINE_UNIFORM_BLOCK_EXT; |
| 2689 | inline_info->pNext = nullptr; |
| 2690 | inline_info->dataSize = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 2691 | inline_info->pData = update_entry; |
| 2692 | write_entry.pNext = inline_info; |
Ricardo Garcia | fee1573 | 2019-05-28 11:13:31 +0200 | [diff] [blame] | 2693 | // descriptorCount must match the dataSize member of the VkWriteDescriptorSetInlineUniformBlockEXT structure |
| 2694 | write_entry.descriptorCount = inline_info->dataSize; |
Dave Houlton | 142c4cb | 2018-10-17 15:04:41 -0600 | [diff] [blame] | 2695 | // skip the rest of the array, they just represent bytes in the update |
| 2696 | j = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 2697 | break; |
| 2698 | } |
sourav parmar | 480d277 | 2021-01-24 22:24:54 -0800 | [diff] [blame] | 2699 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: { |
| 2700 | VkWriteDescriptorSetAccelerationStructureKHR *inline_info_khr = &inline_infos_khr[i]; |
| 2701 | inline_info_khr->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR; |
| 2702 | inline_info_khr->pNext = nullptr; |
| 2703 | inline_info_khr->accelerationStructureCount = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 2704 | inline_info_khr->pAccelerationStructures = reinterpret_cast<VkAccelerationStructureKHR *>(update_entry); |
| 2705 | write_entry.pNext = inline_info_khr; |
| 2706 | break; |
| 2707 | } |
| 2708 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV: { |
| 2709 | VkWriteDescriptorSetAccelerationStructureNV *inline_info_nv = &inline_infos_nv[i]; |
| 2710 | inline_info_nv->sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_NV; |
| 2711 | inline_info_nv->pNext = nullptr; |
| 2712 | inline_info_nv->accelerationStructureCount = create_info.pDescriptorUpdateEntries[i].descriptorCount; |
| 2713 | inline_info_nv->pAccelerationStructures = reinterpret_cast<VkAccelerationStructureNV *>(update_entry); |
| 2714 | write_entry.pNext = inline_info_nv; |
| 2715 | break; |
| 2716 | } |
Mark Lobodzinski | 3d63a04 | 2017-03-09 16:24:13 -0700 | [diff] [blame] | 2717 | default: |
| 2718 | assert(0); |
| 2719 | break; |
| 2720 | } |
| 2721 | dst_array_element++; |
| 2722 | } |
| 2723 | } |
John Zulauf | b845eb2 | 2018-10-12 11:41:06 -0600 | [diff] [blame] | 2724 | } |
John Zulauf | b45fdc3 | 2018-10-12 15:14:17 -0600 | [diff] [blame] | 2725 | // These helper functions carry out the validate and record descriptor updates peformed via update templates. They decode |
| 2726 | // the templatized data and leverage the non-template UpdateDescriptor helper functions. |
Mark Lobodzinski | 3840ca0 | 2019-03-08 18:36:11 -0700 | [diff] [blame] | 2727 | bool CoreChecks::ValidateUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet, const TEMPLATE_STATE *template_state, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 2728 | const void *pData) const { |
John Zulauf | b45fdc3 | 2018-10-12 15:14:17 -0600 | [diff] [blame] | 2729 | // Translate the templated update into a normal update for validation... |
Mark Lobodzinski | 3840ca0 | 2019-03-08 18:36:11 -0700 | [diff] [blame] | 2730 | cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData); |
| 2731 | return ValidateUpdateDescriptorSets(static_cast<uint32_t>(decoded_update.desc_writes.size()), decoded_update.desc_writes.data(), |
| 2732 | 0, NULL, "vkUpdateDescriptorSetWithTemplate()"); |
John Zulauf | b45fdc3 | 2018-10-12 15:14:17 -0600 | [diff] [blame] | 2733 | } |
John Zulauf | b845eb2 | 2018-10-12 11:41:06 -0600 | [diff] [blame] | 2734 | |
John Zulauf | 4e7bcb5 | 2018-11-02 10:46:30 -0600 | [diff] [blame] | 2735 | std::string cvdescriptorset::DescriptorSet::StringifySetAndLayout() const { |
| 2736 | std::string out; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2737 | auto layout_handle = layout_->GetDescriptorSetLayout(); |
John Zulauf | 4e7bcb5 | 2018-11-02 10:46:30 -0600 | [diff] [blame] | 2738 | if (IsPushDescriptor()) { |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 2739 | std::ostringstream str; |
Tony-LunarG | 1d3ee2d | 2020-10-27 15:54:52 -0600 | [diff] [blame] | 2740 | str << "Push Descriptors defined with " << state_data_->report_data->FormatHandle(layout_handle); |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 2741 | out = str.str(); |
John Zulauf | 4e7bcb5 | 2018-11-02 10:46:30 -0600 | [diff] [blame] | 2742 | } else { |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 2743 | std::ostringstream str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2744 | str << state_data_->report_data->FormatHandle(GetSet()) << " allocated with " |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 2745 | << state_data_->report_data->FormatHandle(layout_handle); |
| 2746 | out = str.str(); |
John Zulauf | 4e7bcb5 | 2018-11-02 10:46:30 -0600 | [diff] [blame] | 2747 | } |
| 2748 | return out; |
| 2749 | }; |
| 2750 | |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 2751 | // 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] | 2752 | bool CoreChecks::ValidatePushDescriptorsUpdate(const DescriptorSet *push_set, uint32_t write_count, |
John Zulauf | bd9b341 | 2019-08-22 17:16:11 -0600 | [diff] [blame] | 2753 | const VkWriteDescriptorSet *p_wds, const char *func_name) const { |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 2754 | assert(push_set->IsPushDescriptor()); |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 2755 | bool skip = false; |
| 2756 | for (uint32_t i = 0; i < write_count; i++) { |
| 2757 | std::string error_code; |
| 2758 | std::string error_str; |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 2759 | if (!ValidateWriteUpdate(push_set, &p_wds[i], func_name, &error_code, &error_str, true)) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 2760 | skip |= LogError(push_set->GetDescriptorSetLayout(), error_code, |
| 2761 | "%s VkWriteDescriptorSet[%u] failed update validation: %s.", func_name, i, error_str.c_str()); |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 2762 | } |
| 2763 | } |
| 2764 | return skip; |
| 2765 | } |
| 2766 | |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2767 | // 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] | 2768 | // If there's an error, update the error_msg string with details and return false, else return true |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2769 | bool cvdescriptorset::ValidateBufferUsage(debug_report_data *report_data, BUFFER_STATE const *buffer_node, VkDescriptorType type, |
| 2770 | std::string *error_code, std::string *error_msg) { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2771 | // Verify that usage bits set correctly for given type |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 2772 | auto usage = buffer_node->createInfo.usage; |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2773 | const char *error_usage_bit = nullptr; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2774 | switch (type) { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2775 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 2776 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2777 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00334"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2778 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; |
| 2779 | } |
| 2780 | break; |
| 2781 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 2782 | if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2783 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00335"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2784 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; |
| 2785 | } |
| 2786 | break; |
| 2787 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 2788 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 2789 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2790 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00330"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2791 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; |
| 2792 | } |
| 2793 | break; |
| 2794 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 2795 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 2796 | if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2797 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00331"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2798 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; |
| 2799 | } |
| 2800 | break; |
| 2801 | default: |
| 2802 | break; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2803 | } |
Jeff Bolz | 6d3beaa | 2019-02-09 21:00:05 -0600 | [diff] [blame] | 2804 | if (error_usage_bit) { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2805 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2806 | error_str << "Buffer (" << report_data->FormatHandle(buffer_node->buffer()) << ") with usage mask " << std::hex |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2807 | << std::showbase << usage << " being used for a descriptor update of type " << string_VkDescriptorType(type) |
| 2808 | << " does not have " << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2809 | *error_msg = error_str.str(); |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 2810 | return false; |
| 2811 | } |
| 2812 | return true; |
| 2813 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2814 | // For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes: |
| 2815 | // 1. buffer is valid |
| 2816 | // 2. buffer was created with correct usage flags |
| 2817 | // 3. offset is less than buffer size |
| 2818 | // 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] | 2819 | // 5. range and offset are within the device's limits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2820 | // 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] | 2821 | bool CoreChecks::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, const char *func_name, |
John Zulauf | bd9b341 | 2019-08-22 17:16:11 -0600 | [diff] [blame] | 2822 | std::string *error_code, std::string *error_msg) const { |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2823 | // First make sure that buffer is valid |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2824 | auto buffer_node = GetBufferState(buffer_info->buffer); |
Tobin Ehlis | fa8b618 | 2016-12-22 13:40:45 -0700 | [diff] [blame] | 2825 | // Any invalid buffer should already be caught by object_tracker |
| 2826 | assert(buffer_node); |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2827 | if (ValidateMemoryIsBoundToBuffer(buffer_node, func_name, "VUID-VkWriteDescriptorSet-descriptorType-00329")) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2828 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00329"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2829 | *error_msg = "No memory bound to buffer."; |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 2830 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 2831 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2832 | // Verify usage bits |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2833 | if (!cvdescriptorset::ValidateBufferUsage(report_data, buffer_node, type, error_code, error_msg)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2834 | // error_msg will have been updated by ValidateBufferUsage() |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2835 | return false; |
| 2836 | } |
| 2837 | // offset must be less than buffer size |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 2838 | if (buffer_info->offset >= buffer_node->createInfo.size) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2839 | *error_code = "VUID-VkDescriptorBufferInfo-offset-00340"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2840 | std::stringstream error_str; |
Jeremy Hayes | d1a6a82 | 2017-03-09 14:39:45 -0700 | [diff] [blame] | 2841 | error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than or equal to buffer " |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2842 | << report_data->FormatHandle(buffer_node->buffer()) << " size of " << buffer_node->createInfo.size; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2843 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2844 | return false; |
| 2845 | } |
| 2846 | if (buffer_info->range != VK_WHOLE_SIZE) { |
| 2847 | // Range must be VK_WHOLE_SIZE or > 0 |
| 2848 | if (!buffer_info->range) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2849 | *error_code = "VUID-VkDescriptorBufferInfo-range-00341"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2850 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2851 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2852 | << " 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] | 2853 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2854 | return false; |
| 2855 | } |
| 2856 | // Range must be VK_WHOLE_SIZE or <= (buffer size - offset) |
| 2857 | if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2858 | *error_code = "VUID-VkDescriptorBufferInfo-range-00342"; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2859 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2860 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) << " VkDescriptorBufferInfo range is " |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2861 | << buffer_info->range << " which is greater than buffer size (" << buffer_node->createInfo.size |
| 2862 | << ") minus requested offset of " << buffer_info->offset; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2863 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2864 | return false; |
| 2865 | } |
| 2866 | } |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2867 | // Check buffer update sizes against device limits |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2868 | const auto &limits = phys_dev_props.limits; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2869 | 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] | 2870 | auto max_ub_range = limits.maxUniformBufferRange; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2871 | 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] | 2872 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2873 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2874 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) << " VkDescriptorBufferInfo range is " |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2875 | << buffer_info->range << " which is greater than this device's maxUniformBufferRange (" << max_ub_range |
| 2876 | << ")"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2877 | *error_msg = error_str.str(); |
| 2878 | return false; |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2879 | } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_ub_range) { |
| 2880 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00332"; |
| 2881 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2882 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2883 | << " VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range " |
Peter Kohaut | 18f413d | 2018-07-16 13:15:42 +0200 | [diff] [blame] | 2884 | << "(" << (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] | 2885 | << "maxUniformBufferRange (" << max_ub_range << ")"; |
| 2886 | *error_msg = error_str.str(); |
| 2887 | return false; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2888 | } |
| 2889 | } 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] | 2890 | auto max_sb_range = limits.maxStorageBufferRange; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2891 | 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] | 2892 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2893 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2894 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) << " VkDescriptorBufferInfo range is " |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2895 | << buffer_info->range << " which is greater than this device's maxStorageBufferRange (" << max_sb_range |
| 2896 | << ")"; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2897 | *error_msg = error_str.str(); |
| 2898 | return false; |
Peter Kohaut | 2794a29 | 2018-07-13 11:13:47 +0200 | [diff] [blame] | 2899 | } else if (buffer_info->range == VK_WHOLE_SIZE && (buffer_node->createInfo.size - buffer_info->offset) > max_sb_range) { |
| 2900 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00333"; |
| 2901 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2902 | error_str << "For buffer " << report_data->FormatHandle(buffer_node->buffer()) |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2903 | << " VkDescriptorBufferInfo range is VK_WHOLE_SIZE but effective range " |
Peter Kohaut | 18f413d | 2018-07-16 13:15:42 +0200 | [diff] [blame] | 2904 | << "(" << (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] | 2905 | << "maxStorageBufferRange (" << max_sb_range << ")"; |
| 2906 | *error_msg = error_str.str(); |
| 2907 | return false; |
Tobin Ehlis | c3b6c4c | 2017-02-02 17:26:40 -0700 | [diff] [blame] | 2908 | } |
| 2909 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 2910 | return true; |
| 2911 | } |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2912 | template <typename T> |
| 2913 | bool CoreChecks::ValidateAccelerationStructureUpdate(T acc_node, const char *func_name, std::string *error_code, |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2914 | std::string *error_msg) const { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 2915 | // Any invalid acc struct should already be caught by object_tracker |
| 2916 | assert(acc_node); |
| 2917 | if (ValidateMemoryIsBoundToAccelerationStructure(acc_node, func_name, kVUIDUndefined)) { |
| 2918 | *error_code = kVUIDUndefined; |
| 2919 | *error_msg = "No memory bound to acceleration structure."; |
| 2920 | return false; |
| 2921 | } |
| 2922 | return true; |
| 2923 | } |
| 2924 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 2925 | // Verify that the contents of the update are ok, but don't perform actual update |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 2926 | bool CoreChecks::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, |
| 2927 | VkDescriptorType src_type, uint32_t src_index, const DescriptorSet *dst_set, |
| 2928 | VkDescriptorType dst_type, uint32_t dst_index, const char *func_name, |
| 2929 | std::string *error_code, std::string *error_msg) const { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 2930 | // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are |
| 2931 | // for write updates |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2932 | using DescriptorClass = cvdescriptorset::DescriptorClass; |
| 2933 | using BufferDescriptor = cvdescriptorset::BufferDescriptor; |
| 2934 | using ImageDescriptor = cvdescriptorset::ImageDescriptor; |
| 2935 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
| 2936 | using SamplerDescriptor = cvdescriptorset::SamplerDescriptor; |
| 2937 | using TexelDescriptor = cvdescriptorset::TexelDescriptor; |
| 2938 | |
| 2939 | auto device_data = this; |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 2940 | |
| 2941 | if (dst_type == VK_DESCRIPTOR_TYPE_SAMPLER) { |
| 2942 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 2943 | const auto dst_desc = dst_set->GetDescriptorFromGlobalIndex(dst_index + di); |
| 2944 | if (!dst_desc->updated) continue; |
| 2945 | if (dst_desc->IsImmutableSampler()) { |
| 2946 | *error_code = "VUID-VkCopyDescriptorSet-dstBinding-02753"; |
| 2947 | std::stringstream error_str; |
| 2948 | error_str << "Attempted copy update to an immutable sampler descriptor."; |
| 2949 | *error_msg = error_str.str(); |
| 2950 | return false; |
| 2951 | } |
| 2952 | } |
| 2953 | } |
| 2954 | |
| 2955 | switch (src_set->GetDescriptorFromGlobalIndex(src_index)->descriptor_class) { |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2956 | case DescriptorClass::PlainSampler: { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2957 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 2958 | const auto src_desc = src_set->GetDescriptorFromGlobalIndex(src_index + di); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2959 | if (!src_desc->updated) continue; |
| 2960 | if (!src_desc->IsImmutableSampler()) { |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 2961 | auto update_sampler = static_cast<const SamplerDescriptor *>(src_desc)->GetSampler(); |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2962 | if (!ValidateSampler(update_sampler)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2963 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2964 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2965 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " |
| 2966 | << report_data->FormatHandle(update_sampler) << "."; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2967 | *error_msg = error_str.str(); |
| 2968 | return false; |
| 2969 | } |
| 2970 | } else { |
| 2971 | // TODO : Warn here |
| 2972 | } |
| 2973 | } |
| 2974 | break; |
| 2975 | } |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2976 | case DescriptorClass::ImageSampler: { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2977 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 2978 | const auto src_desc = src_set->GetDescriptorFromGlobalIndex(src_index + di); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 2979 | if (!src_desc->updated) continue; |
| 2980 | auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_desc); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2981 | // First validate sampler |
| 2982 | if (!img_samp_desc->IsImmutableSampler()) { |
| 2983 | auto update_sampler = img_samp_desc->GetSampler(); |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 2984 | if (!ValidateSampler(update_sampler)) { |
Dave Houlton | 00c154e | 2018-05-24 13:20:50 -0600 | [diff] [blame] | 2985 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2986 | std::stringstream error_str; |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 2987 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " |
| 2988 | << report_data->FormatHandle(update_sampler) << "."; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 2989 | *error_msg = error_str.str(); |
| 2990 | return false; |
| 2991 | } |
| 2992 | } else { |
| 2993 | // TODO : Warn here |
| 2994 | } |
| 2995 | // Validate image |
| 2996 | auto image_view = img_samp_desc->GetImageView(); |
| 2997 | auto image_layout = img_samp_desc->GetImageLayout(); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 2998 | if (image_view) { |
| 2999 | if (!ValidateImageUpdate(image_view, image_layout, src_type, func_name, error_code, error_msg)) { |
| 3000 | std::stringstream error_str; |
| 3001 | error_str << "Attempted copy update to combined image sampler descriptor failed due to: " |
| 3002 | << error_msg->c_str(); |
| 3003 | *error_msg = error_str.str(); |
| 3004 | return false; |
| 3005 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3006 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3007 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3008 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3009 | } |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3010 | case DescriptorClass::Image: { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3011 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 3012 | const auto src_desc = src_set->GetDescriptorFromGlobalIndex(src_index + di); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 3013 | if (!src_desc->updated) continue; |
| 3014 | auto img_desc = static_cast<const ImageDescriptor *>(src_desc); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3015 | auto image_view = img_desc->GetImageView(); |
| 3016 | auto image_layout = img_desc->GetImageLayout(); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3017 | if (image_view) { |
| 3018 | if (!ValidateImageUpdate(image_view, image_layout, src_type, func_name, error_code, error_msg)) { |
| 3019 | std::stringstream error_str; |
| 3020 | error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str(); |
| 3021 | *error_msg = error_str.str(); |
| 3022 | return false; |
| 3023 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3024 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3025 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3026 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3027 | } |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3028 | case DescriptorClass::TexelBuffer: { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3029 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 3030 | const auto src_desc = src_set->GetDescriptorFromGlobalIndex(src_index + di); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 3031 | if (!src_desc->updated) continue; |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 3032 | auto buffer_view = static_cast<const TexelDescriptor *>(src_desc)->GetBufferView(); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3033 | if (buffer_view) { |
| 3034 | auto bv_state = device_data->GetBufferViewState(buffer_view); |
| 3035 | if (!bv_state) { |
| 3036 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02994"; |
| 3037 | std::stringstream error_str; |
| 3038 | error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " |
| 3039 | << report_data->FormatHandle(buffer_view); |
| 3040 | *error_msg = error_str.str(); |
| 3041 | return false; |
| 3042 | } |
| 3043 | auto buffer = bv_state->create_info.buffer; |
| 3044 | if (!cvdescriptorset::ValidateBufferUsage(report_data, GetBufferState(buffer), src_type, error_code, |
| 3045 | error_msg)) { |
| 3046 | std::stringstream error_str; |
| 3047 | error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 3048 | *error_msg = error_str.str(); |
| 3049 | return false; |
| 3050 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3051 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3052 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3053 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3054 | } |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3055 | case DescriptorClass::GeneralBuffer: { |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3056 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 3057 | const auto src_desc = src_set->GetDescriptorFromGlobalIndex(src_index + di); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 3058 | if (!src_desc->updated) continue; |
John Zulauf | d9435c3 | 2019-06-05 15:55:36 -0600 | [diff] [blame] | 3059 | auto buffer = static_cast<const BufferDescriptor *>(src_desc)->GetBuffer(); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3060 | if (buffer) { |
| 3061 | if (!cvdescriptorset::ValidateBufferUsage(report_data, GetBufferState(buffer), src_type, error_code, |
| 3062 | error_msg)) { |
| 3063 | std::stringstream error_str; |
| 3064 | error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 3065 | *error_msg = error_str.str(); |
| 3066 | return false; |
| 3067 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3068 | } |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 3069 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3070 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3071 | } |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3072 | case DescriptorClass::InlineUniform: |
| 3073 | case DescriptorClass::AccelerationStructure: |
Ricardo Garcia | 14f4f76 | 2021-04-13 11:36:12 +0200 | [diff] [blame] | 3074 | case DescriptorClass::Mutable: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 3075 | break; |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 3076 | default: |
| 3077 | assert(0); // We've already verified update type so should never get here |
| 3078 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 3079 | } |
| 3080 | // All checks passed so update contents are good |
| 3081 | return true; |
Chris Forbes | b4e0bdb | 2016-05-31 16:34:40 +1200 | [diff] [blame] | 3082 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 3083 | // 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] | 3084 | bool CoreChecks::ValidateAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3085 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) const { |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 3086 | bool skip = false; |
Mark Lobodzinski | 7804bd4 | 2019-03-06 11:28:48 -0700 | [diff] [blame] | 3087 | auto pool_state = GetDescriptorPoolState(p_alloc_info->descriptorPool); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 3088 | |
| 3089 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3090 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 3091 | 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] | 3092 | if (layout->IsPushDescriptor()) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3093 | skip |= LogError(p_alloc_info->pSetLayouts[i], "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-00308", |
| 3094 | "%s specified at pSetLayouts[%" PRIu32 |
| 3095 | "] in vkAllocateDescriptorSets() was created with invalid flag %s set.", |
| 3096 | report_data->FormatHandle(p_alloc_info->pSetLayouts[i]).c_str(), i, |
| 3097 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR"); |
John Zulauf | 5562d06 | 2018-01-24 11:54:05 -0700 | [diff] [blame] | 3098 | } |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3099 | if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT && |
| 3100 | !(pool_state->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT)) { |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 3101 | skip |= LogError( |
| 3102 | device, "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-03044", |
| 3103 | "vkAllocateDescriptorSets(): Descriptor set layout create flags and pool create flags mismatch for index (%d)", |
| 3104 | i); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 3105 | } |
ziga-lunarg | 2ab9653 | 2021-07-19 11:06:41 +0200 | [diff] [blame] | 3106 | if (layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_VALVE && |
| 3107 | !(pool_state->createInfo.flags & VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE)) { |
| 3108 | skip |= LogError(device, "VUID-VkDescriptorSetAllocateInfo-pSetLayouts-04610", |
| 3109 | "vkAllocateDescriptorSets(): pSetLayouts[%d].flags contain " |
| 3110 | "VK_DESCRIPTOR_SET_LAYOUT_CREATE_HOST_ONLY_POOL_BIT_VALVE bit, but the pool was not created " |
| 3111 | "with the VK_DESCRIPTOR_POOL_CREATE_HOST_ONLY_BIT_VALVE bit.", |
| 3112 | i); |
| 3113 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 3114 | } |
| 3115 | } |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 3116 | if (!IsExtEnabled(device_extensions.vk_khr_maintenance1)) { |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 3117 | // Track number of descriptorSets allowable in this pool |
| 3118 | if (pool_state->availableSets < p_alloc_info->descriptorSetCount) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3119 | skip |= LogError(pool_state->pool, "VUID-VkDescriptorSetAllocateInfo-descriptorSetCount-00306", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 3120 | "vkAllocateDescriptorSets(): Unable to allocate %u descriptorSets from %s" |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3121 | ". This pool only has %d descriptorSets remaining.", |
| 3122 | p_alloc_info->descriptorSetCount, report_data->FormatHandle(pool_state->pool).c_str(), |
| 3123 | pool_state->availableSets); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 3124 | } |
| 3125 | // Determine whether descriptor counts are satisfiable |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 3126 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3127 | auto count_iter = pool_state->availableDescriptorTypeCount.find(it->first); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3128 | uint32_t available_count = (count_iter != pool_state->availableDescriptorTypeCount.end()) ? count_iter->second : 0; |
Jeff Bolz | 46c0ea0 | 2019-10-09 13:06:29 -0500 | [diff] [blame] | 3129 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3130 | if (ds_data->required_descriptors_by_type.at(it->first) > available_count) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3131 | skip |= LogError(pool_state->pool, "VUID-VkDescriptorSetAllocateInfo-descriptorPool-00307", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 3132 | "vkAllocateDescriptorSets(): Unable to allocate %u descriptors of type %s from %s" |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3133 | ". This pool only has %d descriptors of this type remaining.", |
| 3134 | ds_data->required_descriptors_by_type.at(it->first), |
| 3135 | string_VkDescriptorType(VkDescriptorType(it->first)), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3136 | report_data->FormatHandle(pool_state->pool).c_str(), available_count); |
Mike Schuchardt | 64b5bb7 | 2017-03-21 16:33:26 -0600 | [diff] [blame] | 3137 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 3138 | } |
| 3139 | } |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 3140 | |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3141 | const auto *count_allocate_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(p_alloc_info->pNext); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 3142 | |
| 3143 | if (count_allocate_info) { |
| 3144 | if (count_allocate_info->descriptorSetCount != 0 && |
| 3145 | count_allocate_info->descriptorSetCount != p_alloc_info->descriptorSetCount) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3146 | skip |= LogError(device, "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfo-descriptorSetCount-03045", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 3147 | "vkAllocateDescriptorSets(): VkDescriptorSetAllocateInfo::descriptorSetCount (%d) != " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3148 | "VkDescriptorSetVariableDescriptorCountAllocateInfo::descriptorSetCount (%d)", |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3149 | p_alloc_info->descriptorSetCount, count_allocate_info->descriptorSetCount); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 3150 | } |
| 3151 | if (count_allocate_info->descriptorSetCount == p_alloc_info->descriptorSetCount) { |
| 3152 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Jeff Bolz | 6ae3961 | 2019-10-11 20:57:36 -0500 | [diff] [blame] | 3153 | auto layout = GetDescriptorSetLayoutShared(p_alloc_info->pSetLayouts[i]); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 3154 | if (count_allocate_info->pDescriptorCounts[i] > layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())) { |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3155 | skip |= LogError(device, "VUID-VkDescriptorSetVariableDescriptorCountAllocateInfo-pSetLayouts-03046", |
sfricke-samsung | bda4a85 | 2021-03-06 20:58:01 -0800 | [diff] [blame] | 3156 | "vkAllocateDescriptorSets(): pDescriptorCounts[%d] = (%d), binding's descriptorCount = (%d)", |
| 3157 | i, count_allocate_info->pDescriptorCounts[i], |
Mark Lobodzinski | d18de90 | 2020-01-15 12:20:37 -0700 | [diff] [blame] | 3158 | layout->GetDescriptorCountFromBinding(layout->GetMaxBinding())); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | } |
| 3162 | } |
| 3163 | |
Mark Lobodzinski | bdc3b02 | 2017-04-24 09:11:35 -0600 | [diff] [blame] | 3164 | return skip; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 3165 | } |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 3166 | |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 3167 | const BindingReqMap &cvdescriptorset::PrefilterBindRequestMap::FilteredMap(const CMD_BUFFER_STATE &cb_state, |
| 3168 | const PIPELINE_STATE &pipeline) { |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 3169 | if (IsManyDescriptors()) { |
Karl Schultz | 7090a05 | 2020-11-10 08:54:21 -0700 | [diff] [blame] | 3170 | filtered_map_.reset(new BindingReqMap); |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 3171 | descriptor_set_.FilterBindingReqs(cb_state, pipeline, orig_map_, filtered_map_.get()); |
| 3172 | return *filtered_map_; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 3173 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 3174 | return orig_map_; |
Artem Kharytoniuk | 2456f99 | 2018-01-12 14:17:41 +0100 | [diff] [blame] | 3175 | } |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3176 | |
| 3177 | // Starting at offset descriptor of given binding, parse over update_count |
| 3178 | // descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent |
| 3179 | // Consistency means that their type, stage flags, and whether or not they use immutable samplers matches |
| 3180 | // If so, return true. If not, fill in error_msg and return false |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 3181 | bool cvdescriptorset::VerifyUpdateConsistency(debug_report_data *report_data, |
| 3182 | DescriptorSetLayout::ConstBindingIterator current_binding, uint32_t offset, |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3183 | uint32_t update_count, const char *type, const VkDescriptorSet set, |
| 3184 | std::string *error_msg) { |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3185 | bool pass = true; |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3186 | // Verify consecutive bindings match (if needed) |
| 3187 | auto orig_binding = current_binding; |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3188 | |
| 3189 | while (pass && update_count) { |
| 3190 | // First, it's legal to offset beyond your own binding so handle that case |
| 3191 | if (offset > 0) { |
| 3192 | const auto &index_range = current_binding.GetGlobalIndexRange(); |
| 3193 | // index_range.start + offset is which descriptor is needed to update. If it > index_range.end, it means the descriptor |
| 3194 | // isn't in this binding, maybe in next binding. |
| 3195 | if ((index_range.start + offset) >= index_range.end) { |
| 3196 | // Advance to next binding, decrement offset by binding size |
| 3197 | offset -= current_binding.GetDescriptorCount(); |
| 3198 | ++current_binding; |
| 3199 | // Verify next consecutive binding matches type, stage flags & immutable sampler use and if AtEnd |
| 3200 | if (!orig_binding.IsConsistent(current_binding)) { |
| 3201 | pass = false; |
| 3202 | } |
| 3203 | continue; |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3204 | } |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3205 | } |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3206 | |
| 3207 | update_count -= std::min(update_count, current_binding.GetDescriptorCount() - offset); |
| 3208 | if (update_count) { |
| 3209 | // Starting offset is beyond the current binding. Check consistency, update counters and advance to the next binding, |
| 3210 | // looking for the start point. All bindings (even those skipped) must be consistent with the update and with the |
| 3211 | // original binding. |
| 3212 | offset = 0; |
| 3213 | ++current_binding; |
| 3214 | // Verify next consecutive binding matches type, stage flags & immutable sampler use and if AtEnd |
| 3215 | if (!orig_binding.IsConsistent(current_binding)) { |
| 3216 | pass = false; |
| 3217 | } |
| 3218 | } |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3219 | } |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3220 | |
| 3221 | if (!pass) { |
| 3222 | std::stringstream error_str; |
| 3223 | error_str << "Attempting " << type; |
| 3224 | if (current_binding.Layout()->IsPushDescriptor()) { |
| 3225 | error_str << " push descriptors"; |
| 3226 | } else { |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 3227 | error_str << " descriptor set " << report_data->FormatHandle(set); |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3228 | } |
| 3229 | error_str << " binding #" << orig_binding.Binding() << " with #" << update_count |
| 3230 | << " descriptors being updated but this update oversteps the bounds of this binding and the next binding is " |
sfricke-samsung | 5de3488 | 2021-04-15 22:33:23 -0700 | [diff] [blame] | 3231 | "not consistent with current binding"; |
| 3232 | |
| 3233 | // Get what was not consistent in IsConsistent() as a more detailed error message |
| 3234 | const auto *binding_ci = orig_binding.GetDescriptorSetLayoutBindingPtr(); |
| 3235 | const auto *other_binding_ci = current_binding.GetDescriptorSetLayoutBindingPtr(); |
| 3236 | if (binding_ci == nullptr || other_binding_ci == nullptr) { |
| 3237 | error_str << " (No two valid DescriptorSetLayoutBinding to compare)"; |
| 3238 | } else if (binding_ci->descriptorType != other_binding_ci->descriptorType) { |
| 3239 | error_str << " (" << string_VkDescriptorType(binding_ci->descriptorType) |
| 3240 | << " != " << string_VkDescriptorType(other_binding_ci->descriptorType) << ")"; |
| 3241 | } else if (binding_ci->stageFlags != other_binding_ci->stageFlags) { |
| 3242 | error_str << " (" << string_VkShaderStageFlags(binding_ci->stageFlags) |
| 3243 | << " != " << string_VkShaderStageFlags(other_binding_ci->stageFlags) << ")"; |
| 3244 | } else if (!hash_util::similar_for_nullity(binding_ci->pImmutableSamplers, other_binding_ci->pImmutableSamplers)) { |
| 3245 | error_str << " (pImmutableSamplers don't match)"; |
| 3246 | } else if (orig_binding.GetDescriptorBindingFlags() != current_binding.GetDescriptorBindingFlags()) { |
| 3247 | error_str << " (" << string_VkDescriptorBindingFlags(orig_binding.GetDescriptorBindingFlags()) |
| 3248 | << " != " << string_VkDescriptorBindingFlags(current_binding.GetDescriptorBindingFlags()) << ")"; |
| 3249 | } |
| 3250 | |
| 3251 | error_str << " so this update is invalid"; |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 3252 | *error_msg = error_str.str(); |
| 3253 | } |
| 3254 | return pass; |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 3255 | } |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3256 | |
| 3257 | // Validate the state for a given write update but don't actually perform the update |
| 3258 | // 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] | 3259 | bool CoreChecks::ValidateWriteUpdate(const DescriptorSet *dest_set, const VkWriteDescriptorSet *update, const char *func_name, |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 3260 | std::string *error_code, std::string *error_msg, bool push) const { |
Jeff Bolz | 6aad174 | 2019-10-16 11:10:09 -0500 | [diff] [blame] | 3261 | const auto dest_layout = dest_set->GetLayout().get(); |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3262 | |
| 3263 | // Verify dst layout still valid |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3264 | if (dest_layout->Destroyed()) { |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3265 | *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320"; |
Mark Lobodzinski | 23e395e | 2020-04-09 10:17:31 -0600 | [diff] [blame] | 3266 | std::ostringstream str; |
| 3267 | str << "Cannot call " << func_name << " to perform write update on " << dest_set->StringifySetAndLayout() |
| 3268 | << " which has been destroyed"; |
| 3269 | *error_msg = str.str(); |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3270 | return false; |
| 3271 | } |
| 3272 | // Verify dst binding exists |
| 3273 | if (!dest_layout->HasBinding(update->dstBinding)) { |
| 3274 | *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315"; |
| 3275 | std::stringstream error_str; |
| 3276 | error_str << dest_set->StringifySetAndLayout() << " does not have binding " << update->dstBinding; |
| 3277 | *error_msg = error_str.str(); |
| 3278 | return false; |
| 3279 | } |
| 3280 | |
Jeff Bolz | 6aad174 | 2019-10-16 11:10:09 -0500 | [diff] [blame] | 3281 | DescriptorSetLayout::ConstBindingIterator dest(dest_layout, update->dstBinding); |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3282 | // Make sure binding isn't empty |
| 3283 | if (0 == dest.GetDescriptorCount()) { |
| 3284 | *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316"; |
| 3285 | std::stringstream error_str; |
| 3286 | error_str << dest_set->StringifySetAndLayout() << " cannot updated binding " << update->dstBinding |
| 3287 | << " that has 0 descriptors"; |
| 3288 | *error_msg = error_str.str(); |
| 3289 | return false; |
| 3290 | } |
| 3291 | |
| 3292 | // Verify idle ds |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 3293 | if (dest_set->InUse() && !(dest.GetDescriptorBindingFlags() & (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 3294 | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3295 | // TODO : Re-using Free Idle error code, need write update idle error code |
| 3296 | *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309"; |
| 3297 | std::stringstream error_str; |
| 3298 | error_str << "Cannot call " << func_name << " to perform write update on " << dest_set->StringifySetAndLayout() |
| 3299 | << " that is in use by a command buffer"; |
| 3300 | *error_msg = error_str.str(); |
| 3301 | return false; |
| 3302 | } |
| 3303 | // We know that binding is valid, verify update and do update on each descriptor |
| 3304 | auto start_idx = dest.GetGlobalIndexRange().start + update->dstArrayElement; |
| 3305 | auto type = dest.GetType(); |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 3306 | if ((type != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE) && (type != update->descriptorType)) { |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3307 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319"; |
| 3308 | std::stringstream error_str; |
| 3309 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding |
| 3310 | << " with type " << string_VkDescriptorType(type) << " but update type is " |
| 3311 | << string_VkDescriptorType(update->descriptorType); |
| 3312 | *error_msg = error_str.str(); |
| 3313 | return false; |
| 3314 | } |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3315 | if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) { |
| 3316 | if ((update->dstArrayElement % 4) != 0) { |
| 3317 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219"; |
| 3318 | std::stringstream error_str; |
| 3319 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding |
| 3320 | << " with " |
| 3321 | << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4"; |
| 3322 | *error_msg = error_str.str(); |
| 3323 | return false; |
| 3324 | } |
| 3325 | if ((update->descriptorCount % 4) != 0) { |
| 3326 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220"; |
| 3327 | std::stringstream error_str; |
| 3328 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding |
| 3329 | << " with " |
| 3330 | << "descriptorCount " << update->descriptorCount << " not a multiple of 4"; |
| 3331 | *error_msg = error_str.str(); |
| 3332 | return false; |
| 3333 | } |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3334 | const auto *write_inline_info = LvlFindInChain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext); |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3335 | if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) { |
| 3336 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221"; |
| 3337 | std::stringstream error_str; |
| 3338 | if (!write_inline_info) { |
| 3339 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" |
| 3340 | << update->dstBinding << " with " |
| 3341 | << "VkWriteDescriptorSetInlineUniformBlockEXT missing"; |
| 3342 | } else { |
| 3343 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" |
| 3344 | << update->dstBinding << " with " |
| 3345 | << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize |
| 3346 | << " not equal to " |
| 3347 | << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount; |
| 3348 | } |
| 3349 | *error_msg = error_str.str(); |
| 3350 | return false; |
| 3351 | } |
| 3352 | // This error is probably unreachable due to the previous two errors |
| 3353 | if (write_inline_info && (write_inline_info->dataSize % 4) != 0) { |
| 3354 | *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222"; |
| 3355 | std::stringstream error_str; |
| 3356 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding |
| 3357 | << " with " |
| 3358 | << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize |
| 3359 | << " not a multiple of 4"; |
| 3360 | *error_msg = error_str.str(); |
| 3361 | return false; |
| 3362 | } |
| 3363 | } |
sfricke-samsung | 941d48b | 2020-02-10 00:20:01 -0800 | [diff] [blame] | 3364 | // Verify all bindings update share identical properties across all items |
| 3365 | if (update->descriptorCount > 0) { |
| 3366 | // Save first binding information and error if something different is found |
| 3367 | DescriptorSetLayout::ConstBindingIterator current_binding(dest_layout, update->dstBinding); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3368 | VkShaderStageFlags stage_flags = current_binding.GetStageFlags(); |
| 3369 | VkDescriptorType descriptor_type = current_binding.GetType(); |
| 3370 | bool immutable_samplers = (current_binding.GetImmutableSamplerPtr() == nullptr); |
| 3371 | uint32_t dst_array_element = update->dstArrayElement; |
sfricke-samsung | 941d48b | 2020-02-10 00:20:01 -0800 | [diff] [blame] | 3372 | |
Jeff Bolz | 9198e88 | 2020-03-18 13:03:30 -0500 | [diff] [blame] | 3373 | for (uint32_t i = 0; i < update->descriptorCount;) { |
sfricke-samsung | 941d48b | 2020-02-10 00:20:01 -0800 | [diff] [blame] | 3374 | if (current_binding.AtEnd() == true) { |
| 3375 | break; // prevents setting error here if bindings don't exist |
| 3376 | } |
| 3377 | |
Quentin Huot-Marchand | 98d84dd | 2021-06-24 09:54:58 +0200 | [diff] [blame] | 3378 | // All consecutive bindings updated, except those with a descriptorCount of zero, must have identical descType and stageFlags |
| 3379 | if(current_binding.GetDescriptorCount() > 0) { |
| 3380 | // Check for consistent stageFlags and descriptorType |
| 3381 | if ((current_binding.GetStageFlags() != stage_flags) || (current_binding.GetType() != descriptor_type)) { |
| 3382 | *error_code = "VUID-VkWriteDescriptorSet-descriptorCount-00317"; |
| 3383 | std::stringstream error_str; |
| 3384 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding index #" |
| 3385 | << current_binding.GetIndex() << " (" << i << " from dstBinding offset)" |
| 3386 | << " with a different stageFlag and/or descriptorType from previous bindings." |
| 3387 | << " All bindings must have consecutive stageFlag and/or descriptorType across a VkWriteDescriptorSet"; |
| 3388 | *error_msg = error_str.str(); |
| 3389 | return false; |
| 3390 | } |
| 3391 | // Check if all immutableSamplers or not |
| 3392 | if ((current_binding.GetImmutableSamplerPtr() == nullptr) != immutable_samplers) { |
| 3393 | *error_code = "VUID-VkWriteDescriptorSet-descriptorCount-00318"; |
| 3394 | std::stringstream error_str; |
| 3395 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding index #" |
| 3396 | << current_binding.GetIndex() << " (" << i << " from dstBinding offset)" |
| 3397 | << " with a different usage of immutable samplers from previous bindings." |
| 3398 | << " All bindings must have all or none usage of immutable samplers across a VkWriteDescriptorSet"; |
| 3399 | *error_msg = error_str.str(); |
| 3400 | return false; |
| 3401 | } |
sfricke-samsung | 941d48b | 2020-02-10 00:20:01 -0800 | [diff] [blame] | 3402 | } |
Jeff Bolz | 9198e88 | 2020-03-18 13:03:30 -0500 | [diff] [blame] | 3403 | |
| 3404 | // Skip the remaining descriptors for this binding, and move to the next binding |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3405 | i += (current_binding.GetDescriptorCount() - dst_array_element); |
| 3406 | dst_array_element = 0; |
sfricke-samsung | 941d48b | 2020-02-10 00:20:01 -0800 | [diff] [blame] | 3407 | ++current_binding; |
| 3408 | } |
| 3409 | } |
| 3410 | |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3411 | // Verify consecutive bindings match (if needed) |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 3412 | if (!VerifyUpdateConsistency(report_data, DescriptorSetLayout::ConstBindingIterator(dest_layout, update->dstBinding), |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3413 | update->dstArrayElement, update->descriptorCount, "write update to", dest_set->GetSet(), |
| 3414 | error_msg)) { |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3415 | *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321"; |
| 3416 | return false; |
| 3417 | } |
Tony-LunarG | 1f79c95 | 2020-10-27 15:55:51 -0600 | [diff] [blame] | 3418 | // Verify write to variable descriptor |
| 3419 | if (dest_set->IsVariableDescriptorCount(update->dstBinding)) { |
| 3420 | if ((update->dstArrayElement + update->descriptorCount) > dest_set->GetVariableDescriptorCount()) { |
| 3421 | std::stringstream error_str; |
| 3422 | *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321"; |
| 3423 | error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding index #" |
| 3424 | << update->dstBinding << " array element " << update->dstArrayElement << " with " << update->descriptorCount |
| 3425 | << " writes but variable descriptor size is " << dest_set->GetVariableDescriptorCount(); |
| 3426 | *error_msg = error_str.str(); |
| 3427 | return false; |
| 3428 | } |
| 3429 | } |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3430 | // Update is within bounds and consistent so last step is to validate update contents |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 3431 | if (!VerifyWriteUpdateContents(dest_set, update, start_idx, func_name, error_code, error_msg, push)) { |
John Zulauf | 4956fff | 2019-06-04 16:54:38 -0600 | [diff] [blame] | 3432 | std::stringstream error_str; |
| 3433 | error_str << "Write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding |
| 3434 | << " failed with error message: " << error_msg->c_str(); |
| 3435 | *error_msg = error_str.str(); |
| 3436 | return false; |
| 3437 | } |
| 3438 | // All checks passed, update is clean |
| 3439 | return true; |
| 3440 | } |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3441 | |
| 3442 | // 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] | 3443 | bool CoreChecks::VerifyWriteUpdateContents(const DescriptorSet *dest_set, const VkWriteDescriptorSet *update, const uint32_t index, |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 3444 | const char *func_name, std::string *error_code, std::string *error_msg, |
| 3445 | bool push) const { |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3446 | using ImageSamplerDescriptor = cvdescriptorset::ImageSamplerDescriptor; |
Nathaniel Cesario | ff52151 | 2020-12-11 16:00:26 -0700 | [diff] [blame] | 3447 | using Descriptor = cvdescriptorset::Descriptor; |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3448 | |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3449 | switch (update->descriptorType) { |
| 3450 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 3451 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 3452 | // Validate image |
| 3453 | auto image_view = update->pImageInfo[di].imageView; |
| 3454 | auto image_layout = update->pImageInfo[di].imageLayout; |
Mark Lobodzinski | 3ca937b | 2020-02-14 14:56:06 -0700 | [diff] [blame] | 3455 | auto sampler = update->pImageInfo[di].sampler; |
sfricke-samsung | 27e5d5a | 2020-01-07 21:07:08 -0800 | [diff] [blame] | 3456 | auto iv_state = GetImageViewState(image_view); |
Nathaniel Cesario | ff52151 | 2020-12-11 16:00:26 -0700 | [diff] [blame] | 3457 | const ImageSamplerDescriptor *desc = |
| 3458 | (const ImageSamplerDescriptor *)dest_set->GetDescriptorFromGlobalIndex(index + di); |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3459 | if (image_view) { |
| 3460 | auto image_state = iv_state->image_state.get(); |
| 3461 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, func_name, error_code, error_msg)) { |
| 3462 | std::stringstream error_str; |
| 3463 | error_str << "Attempted write update to combined image sampler descriptor failed due to: " |
| 3464 | << error_msg->c_str(); |
| 3465 | *error_msg = error_str.str(); |
| 3466 | return false; |
| 3467 | } |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 3468 | if (IsExtEnabled(device_extensions.vk_khr_sampler_ycbcr_conversion)) { |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3469 | if (desc->IsImmutableSampler()) { |
| 3470 | auto sampler_state = GetSamplerState(desc->GetSampler()); |
| 3471 | if (iv_state && sampler_state) { |
| 3472 | if (iv_state->samplerConversion != sampler_state->samplerConversion) { |
| 3473 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-01948"; |
| 3474 | std::stringstream error_str; |
| 3475 | error_str |
| 3476 | << "Attempted write update to combined image sampler and image view and sampler ycbcr " |
| 3477 | "conversions are not identical, sampler: " |
| 3478 | << report_data->FormatHandle(desc->GetSampler()) |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3479 | << " image view: " << report_data->FormatHandle(iv_state->image_view()) << "."; |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3480 | *error_msg = error_str.str(); |
| 3481 | return false; |
| 3482 | } |
| 3483 | } |
| 3484 | } else { |
| 3485 | if (iv_state && (iv_state->samplerConversion != VK_NULL_HANDLE)) { |
| 3486 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02738"; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3487 | std::stringstream error_str; |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3488 | error_str << "Because dstSet (" << report_data->FormatHandle(update->dstSet) |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3489 | << ") is bound to image view (" << report_data->FormatHandle(iv_state->image_view()) |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3490 | << ") that includes a YCBCR conversion, it must have been allocated with a layout that " |
| 3491 | "includes an immutable sampler."; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3492 | *error_msg = error_str.str(); |
| 3493 | return false; |
| 3494 | } |
| 3495 | } |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3496 | } |
John Bauman | da8abff | 2020-10-19 21:25:21 +0000 | [diff] [blame] | 3497 | // If there is an immutable sampler then |sampler| isn't used, so the following VU does not apply. |
| 3498 | if (sampler && !desc->IsImmutableSampler() && FormatIsMultiplane(image_state->createInfo.format)) { |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3499 | // multiplane formats must be created with mutable format bit |
| 3500 | if (0 == (image_state->createInfo.flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) { |
| 3501 | *error_code = "VUID-VkDescriptorImageInfo-sampler-01564"; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3502 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3503 | error_str << "image " << report_data->FormatHandle(image_state->image()) |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3504 | << " combined image sampler is a multi-planar " |
| 3505 | << "format and was not was not created with the VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT"; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3506 | *error_msg = error_str.str(); |
| 3507 | return false; |
| 3508 | } |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3509 | // image view need aspect mask for only the planes supported of format |
| 3510 | VkImageAspectFlags legal_aspect_flags = (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT); |
| 3511 | legal_aspect_flags |= |
| 3512 | (FormatPlaneCount(image_state->createInfo.format) == 3) ? VK_IMAGE_ASPECT_PLANE_2_BIT : 0; |
| 3513 | if (0 != (iv_state->create_info.subresourceRange.aspectMask & (~legal_aspect_flags))) { |
| 3514 | *error_code = "VUID-VkDescriptorImageInfo-sampler-01564"; |
| 3515 | std::stringstream error_str; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3516 | error_str << "image " << report_data->FormatHandle(image_state->image()) |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3517 | << " combined image sampler is a multi-planar " |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 3518 | << "format and " << report_data->FormatHandle(iv_state->image_view()) |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3519 | << " aspectMask must only include " << string_VkImageAspectFlags(legal_aspect_flags); |
| 3520 | *error_msg = error_str.str(); |
| 3521 | return false; |
| 3522 | } |
sfricke-samsung | 27e5d5a | 2020-01-07 21:07:08 -0800 | [diff] [blame] | 3523 | } |
Nathaniel Cesario | 23afadd | 2020-11-17 12:51:45 -0700 | [diff] [blame] | 3524 | |
| 3525 | // Verify portability |
| 3526 | auto sampler_state = GetSamplerState(sampler); |
| 3527 | if (sampler_state) { |
sfricke-samsung | 45996a4 | 2021-09-16 13:45:27 -0700 | [diff] [blame] | 3528 | if (IsExtEnabled(device_extensions.vk_khr_portability_subset)) { |
Nathaniel Cesario | 23afadd | 2020-11-17 12:51:45 -0700 | [diff] [blame] | 3529 | if ((VK_FALSE == enabled_features.portability_subset_features.mutableComparisonSamplers) && |
| 3530 | (VK_FALSE != sampler_state->createInfo.compareEnable)) { |
| 3531 | LogError(device, "VUID-VkDescriptorImageInfo-mutableComparisonSamplers-04450", |
| 3532 | "%s (portability error): sampler comparison not available.", func_name); |
| 3533 | } |
| 3534 | } |
| 3535 | } |
sfricke-samsung | 27e5d5a | 2020-01-07 21:07:08 -0800 | [diff] [blame] | 3536 | } |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3537 | } |
| 3538 | } |
Mark Lobodzinski | ac72777 | 2020-01-08 10:47:30 -0700 | [diff] [blame] | 3539 | // Fall through |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3540 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 3541 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3542 | const auto *desc = static_cast<const Descriptor *>(dest_set->GetDescriptorFromGlobalIndex(index + di)); |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3543 | if (!desc->IsImmutableSampler()) { |
John Zulauf | c93c425 | 2019-06-25 09:19:49 -0600 | [diff] [blame] | 3544 | if (!ValidateSampler(update->pImageInfo[di].sampler)) { |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3545 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00325"; |
| 3546 | std::stringstream error_str; |
| 3547 | error_str << "Attempted write update to sampler descriptor with invalid sampler: " |
Mark Lobodzinski | db35b8b | 2020-04-09 08:46:59 -0600 | [diff] [blame] | 3548 | << report_data->FormatHandle(update->pImageInfo[di].sampler) << "."; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3549 | *error_msg = error_str.str(); |
| 3550 | return false; |
| 3551 | } |
ziga-lunarg | 6c46b24 | 2021-09-13 18:33:37 +0200 | [diff] [blame] | 3552 | } else if (update->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER && !push) { |
Mark Lobodzinski | f4ed6c1 | 2020-01-03 11:21:58 -0700 | [diff] [blame] | 3553 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02752"; |
| 3554 | std::stringstream error_str; |
| 3555 | error_str << "Attempted write update to an immutable sampler descriptor."; |
| 3556 | *error_msg = error_str.str(); |
| 3557 | return false; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | break; |
| 3561 | } |
| 3562 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 3563 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 3564 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 3565 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 3566 | auto image_view = update->pImageInfo[di].imageView; |
| 3567 | auto image_layout = update->pImageInfo[di].imageLayout; |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3568 | if (image_view) { |
| 3569 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, func_name, error_code, error_msg)) { |
| 3570 | std::stringstream error_str; |
| 3571 | error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str(); |
| 3572 | *error_msg = error_str.str(); |
| 3573 | return false; |
| 3574 | } |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | break; |
| 3578 | } |
| 3579 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 3580 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| 3581 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 3582 | auto buffer_view = update->pTexelBufferView[di]; |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3583 | if (buffer_view) { |
| 3584 | auto bv_state = GetBufferViewState(buffer_view); |
| 3585 | if (!bv_state) { |
| 3586 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02994"; |
| 3587 | std::stringstream error_str; |
| 3588 | error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " |
| 3589 | << report_data->FormatHandle(buffer_view); |
| 3590 | *error_msg = error_str.str(); |
| 3591 | return false; |
| 3592 | } |
| 3593 | auto buffer = bv_state->create_info.buffer; |
| 3594 | auto buffer_state = GetBufferState(buffer); |
| 3595 | // Verify that buffer underlying the view hasn't been destroyed prematurely |
| 3596 | if (!buffer_state) { |
| 3597 | *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02994"; |
| 3598 | std::stringstream error_str; |
| 3599 | error_str << "Attempted write update to texel buffer descriptor failed because underlying buffer (" |
| 3600 | << report_data->FormatHandle(buffer) << ") has been destroyed: " << error_msg->c_str(); |
| 3601 | *error_msg = error_str.str(); |
| 3602 | return false; |
| 3603 | } else if (!cvdescriptorset::ValidateBufferUsage(report_data, buffer_state, update->descriptorType, error_code, |
| 3604 | error_msg)) { |
| 3605 | std::stringstream error_str; |
| 3606 | error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 3607 | *error_msg = error_str.str(); |
| 3608 | return false; |
| 3609 | } |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3610 | } |
| 3611 | } |
| 3612 | break; |
| 3613 | } |
| 3614 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 3615 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 3616 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 3617 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 3618 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Jeff Bolz | 165818a | 2020-05-08 11:19:03 -0500 | [diff] [blame] | 3619 | if (update->pBufferInfo[di].buffer) { |
| 3620 | if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, func_name, error_code, error_msg)) { |
| 3621 | std::stringstream error_str; |
| 3622 | error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 3623 | *error_msg = error_str.str(); |
| 3624 | return false; |
| 3625 | } |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | break; |
| 3629 | } |
| 3630 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: |
| 3631 | break; |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3632 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV: { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 3633 | const auto *acc_info = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureNV>(update->pNext); |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3634 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 3635 | if (!ValidateAccelerationStructureUpdate(GetAccelerationStructureStateNV(acc_info->pAccelerationStructures[di]), |
Mark Lobodzinski | 85ebd40 | 2020-12-03 12:56:07 -0700 | [diff] [blame] | 3636 | func_name, error_code, error_msg)) { |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 3637 | std::stringstream error_str; |
| 3638 | error_str << "Attempted write update to acceleration structure descriptor failed due to: " |
| 3639 | << error_msg->c_str(); |
| 3640 | *error_msg = error_str.str(); |
| 3641 | return false; |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | } break; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 3646 | // KHR acceleration structures don't require memory to be bound manually to them. |
| 3647 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: |
| 3648 | break; |
John Zulauf | adb3f54 | 2019-06-04 17:01:00 -0600 | [diff] [blame] | 3649 | default: |
| 3650 | assert(0); // We've already verified update type so should never get here |
| 3651 | break; |
| 3652 | } |
| 3653 | // All checks passed so update contents are good |
| 3654 | return true; |
| 3655 | } |