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