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