Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2022 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2022 Valve Corporation |
| 3 | * Copyright (c) 2015-2022 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2022 Google Inc. |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 19 | * John Zulauf <jzulauf@lunarg.com> |
Jeremy Kniager | e682743 | 2020-04-01 09:05:56 -0600 | [diff] [blame] | 20 | * Jeremy Kniager <jeremyk@lunarg.com> |
Jeremy Gebben | bb718a3 | 2022-05-12 08:51:10 -0600 | [diff] [blame] | 21 | * Jeremy Gebben <jeremyg@lunarg.com> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include "descriptor_sets.h" |
Jeremy Gebben | bb718a3 | 2022-05-12 08:51:10 -0600 | [diff] [blame] | 25 | #include "cmd_buffer_state.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 26 | |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 27 | static DESCRIPTOR_POOL_STATE::TypeCountMap GetMaxTypeCounts(const VkDescriptorPoolCreateInfo *create_info) { |
| 28 | DESCRIPTOR_POOL_STATE::TypeCountMap counts; |
| 29 | // Collect maximums per descriptor type. |
| 30 | for (uint32_t i = 0; i < create_info->poolSizeCount; ++i) { |
| 31 | const auto &pool_size = create_info->pPoolSizes[i]; |
| 32 | uint32_t type = static_cast<uint32_t>(pool_size.type); |
| 33 | // Same descriptor types can appear several times |
| 34 | counts[type] += pool_size.descriptorCount; |
| 35 | } |
| 36 | return counts; |
| 37 | } |
| 38 | |
| 39 | DESCRIPTOR_POOL_STATE::DESCRIPTOR_POOL_STATE(ValidationStateTracker *dev, const VkDescriptorPool pool, |
| 40 | const VkDescriptorPoolCreateInfo *pCreateInfo) |
| 41 | : BASE_NODE(pool, kVulkanObjectTypeDescriptorPool), |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 42 | maxSets(pCreateInfo->maxSets), |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 43 | createInfo(pCreateInfo), |
| 44 | maxDescriptorTypeCount(GetMaxTypeCounts(pCreateInfo)), |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 45 | available_sets_(pCreateInfo->maxSets), |
| 46 | available_counts_(maxDescriptorTypeCount), |
| 47 | dev_data_(dev) {} |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 48 | |
| 49 | void DESCRIPTOR_POOL_STATE::Allocate(const VkDescriptorSetAllocateInfo *alloc_info, const VkDescriptorSet *descriptor_sets, |
| 50 | const cvdescriptorset::AllocateDescriptorSetsData *ds_data) { |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 51 | auto guard = WriteLock(); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 52 | // Account for sets and individual descriptors allocated from pool |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 53 | available_sets_ -= alloc_info->descriptorSetCount; |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 54 | for (auto it = ds_data->required_descriptors_by_type.begin(); it != ds_data->required_descriptors_by_type.end(); ++it) { |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 55 | available_counts_[it->first] -= ds_data->required_descriptors_by_type.at(it->first); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | const auto *variable_count_info = LvlFindInChain<VkDescriptorSetVariableDescriptorCountAllocateInfo>(alloc_info->pNext); |
| 59 | bool variable_count_valid = variable_count_info && variable_count_info->descriptorSetCount == alloc_info->descriptorSetCount; |
| 60 | |
| 61 | // Create tracking object for each descriptor set; insert into global map and the pool's set. |
| 62 | for (uint32_t i = 0; i < alloc_info->descriptorSetCount; i++) { |
| 63 | uint32_t variable_count = variable_count_valid ? variable_count_info->pDescriptorCounts[i] : 0; |
| 64 | |
| 65 | auto new_ds = std::make_shared<cvdescriptorset::DescriptorSet>(descriptor_sets[i], this, ds_data->layout_nodes[i], |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 66 | variable_count, dev_data_); |
| 67 | sets_.emplace(descriptor_sets[i], new_ds.get()); |
| 68 | dev_data_->Add(std::move(new_ds)); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | void DESCRIPTOR_POOL_STATE::Free(uint32_t count, const VkDescriptorSet *descriptor_sets) { |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 73 | auto guard = WriteLock(); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 74 | // Update available descriptor sets in pool |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 75 | available_sets_ += count; |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 76 | |
Jeremy Gebben | 082a983 | 2021-10-28 13:40:11 -0600 | [diff] [blame] | 77 | // For each freed descriptor add its resources back into the pool as available and remove from pool and device data |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 78 | for (uint32_t i = 0; i < count; ++i) { |
| 79 | if (descriptor_sets[i] != VK_NULL_HANDLE) { |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 80 | auto iter = sets_.find(descriptor_sets[i]); |
| 81 | assert(iter != sets_.end()); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 82 | auto *set_state = iter->second; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 83 | const auto &layout = set_state->Layout(); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 84 | uint32_t type_index = 0, descriptor_count = 0; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 85 | for (uint32_t j = 0; j < layout.GetBindingCount(); ++j) { |
| 86 | type_index = static_cast<uint32_t>(layout.GetTypeFromIndex(j)); |
| 87 | descriptor_count = layout.GetDescriptorCountFromIndex(j); |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 88 | available_counts_[type_index] += descriptor_count; |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 89 | } |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 90 | dev_data_->Destroy<cvdescriptorset::DescriptorSet>(iter->first); |
| 91 | sets_.erase(iter); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | void DESCRIPTOR_POOL_STATE::Reset() { |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 97 | auto guard = WriteLock(); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 98 | // For every set off of this pool, clear it, remove from setMap, and free cvdescriptorset::DescriptorSet |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 99 | for (auto entry : sets_) { |
| 100 | dev_data_->Destroy<cvdescriptorset::DescriptorSet>(entry.first); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 101 | } |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 102 | sets_.clear(); |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 103 | // Reset available count for each type and available sets for this pool |
Jeremy Gebben | 0d9143e | 2022-01-01 12:29:36 -0700 | [diff] [blame] | 104 | available_counts_ = maxDescriptorTypeCount; |
| 105 | available_sets_ = maxSets; |
| 106 | } |
| 107 | |
| 108 | bool DESCRIPTOR_POOL_STATE::InUse() const { |
| 109 | auto guard = ReadLock(); |
| 110 | for (const auto &entry : sets_) { |
| 111 | const auto *ds = entry.second; |
| 112 | if (ds && ds->InUse()) { |
| 113 | return true; |
| 114 | } |
| 115 | } |
| 116 | return false; |
Jeremy Gebben | 1fbebb8 | 2021-10-27 10:27:27 -0600 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | void DESCRIPTOR_POOL_STATE::Destroy() { |
| 120 | Reset(); |
| 121 | BASE_NODE::Destroy(); |
| 122 | } |
| 123 | |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 124 | // ExtendedBinding collects a VkDescriptorSetLayoutBinding and any extended |
| 125 | // state that comes from a different array/structure so they can stay together |
| 126 | // while being sorted by binding number. |
| 127 | struct ExtendedBinding { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 128 | ExtendedBinding(const VkDescriptorSetLayoutBinding *l, VkDescriptorBindingFlags f) : layout_binding(l), binding_flags(f) {} |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 129 | |
| 130 | const VkDescriptorSetLayoutBinding *layout_binding; |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 131 | VkDescriptorBindingFlags binding_flags; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 132 | }; |
| 133 | |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 134 | struct BindingNumCmp { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 135 | bool operator()(const ExtendedBinding &a, const ExtendedBinding &b) const { |
| 136 | return a.layout_binding->binding < b.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 137 | } |
| 138 | }; |
| 139 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 140 | cvdescriptorset::DescriptorClass cvdescriptorset::DescriptorTypeToClass(VkDescriptorType type) { |
| 141 | switch (type) { |
| 142 | case VK_DESCRIPTOR_TYPE_SAMPLER: |
| 143 | return PlainSampler; |
| 144 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 145 | return ImageSampler; |
| 146 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 147 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 148 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 149 | return Image; |
| 150 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 151 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 152 | return TexelBuffer; |
| 153 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 154 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 155 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 156 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 157 | return GeneralBuffer; |
| 158 | case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: |
| 159 | return InlineUniform; |
| 160 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: |
| 161 | case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV: |
| 162 | return AccelerationStructure; |
Mike Schuchardt | 2d523e5 | 2022-09-15 12:25:58 -0700 | [diff] [blame] | 163 | case VK_DESCRIPTOR_TYPE_MUTABLE_EXT: |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 164 | return Mutable; |
| 165 | default: |
| 166 | break; |
| 167 | } |
| 168 | return NoDescriptorClass; |
| 169 | } |
| 170 | |
| 171 | |
John Zulauf | 613fd98 | 2019-06-04 15:14:41 -0600 | [diff] [blame] | 172 | using DescriptorSet = cvdescriptorset::DescriptorSet; |
John Zulauf | 4a015c9 | 2019-06-04 09:50:05 -0600 | [diff] [blame] | 173 | using DescriptorSetLayout = cvdescriptorset::DescriptorSetLayout; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 174 | using DescriptorSetLayoutDef = cvdescriptorset::DescriptorSetLayoutDef; |
| 175 | using DescriptorSetLayoutId = cvdescriptorset::DescriptorSetLayoutId; |
| 176 | |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 177 | // Canonical dictionary of DescriptorSetLayoutDef (without any handle/device specific information) |
| 178 | cvdescriptorset::DescriptorSetLayoutDict descriptor_set_layout_dict; |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 179 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 180 | DescriptorSetLayoutId GetCanonicalId(const VkDescriptorSetLayoutCreateInfo *p_create_info) { |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 181 | return descriptor_set_layout_dict.look_up(DescriptorSetLayoutDef(p_create_info)); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 182 | } |
John Zulauf | 34ebf27 | 2018-02-16 13:08:47 -0700 | [diff] [blame] | 183 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 184 | // Construct DescriptorSetLayout instance from given create info |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 185 | // 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] | 186 | cvdescriptorset::DescriptorSetLayoutDef::DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info) |
| 187 | : flags_(p_create_info->flags), binding_count_(0), descriptor_count_(0), dynamic_descriptor_count_(0) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 188 | const auto *flags_create_info = LvlFindInChain<VkDescriptorSetLayoutBindingFlagsCreateInfo>(p_create_info->pNext); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 189 | |
sfricke-samsung | 0d00aed | 2021-03-08 23:31:17 -0800 | [diff] [blame] | 190 | binding_type_stats_ = {0, 0}; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 191 | std::set<ExtendedBinding, BindingNumCmp> sorted_bindings; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 192 | const uint32_t input_bindings_count = p_create_info->bindingCount; |
| 193 | // Sort the input bindings in binding number order, eliminating duplicates |
| 194 | for (uint32_t i = 0; i < input_bindings_count; i++) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 195 | VkDescriptorBindingFlags flags = 0; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 196 | if (flags_create_info && flags_create_info->bindingCount == p_create_info->bindingCount) { |
| 197 | flags = flags_create_info->pBindingFlags[i]; |
| 198 | } |
Jeremy Gebben | fc6f815 | 2021-03-18 16:58:55 -0600 | [diff] [blame] | 199 | sorted_bindings.emplace(p_create_info->pBindings + i, flags); |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Mike Schuchardt | 2d523e5 | 2022-09-15 12:25:58 -0700 | [diff] [blame] | 202 | const auto *mutable_descriptor_type_create_info = LvlFindInChain<VkMutableDescriptorTypeCreateInfoEXT>(p_create_info->pNext); |
ziga-lunarg | d67b5f5 | 2021-10-16 23:52:59 +0200 | [diff] [blame] | 203 | if (mutable_descriptor_type_create_info) { |
| 204 | mutable_types_.resize(mutable_descriptor_type_create_info->mutableDescriptorTypeListCount); |
| 205 | for (uint32_t i = 0; i < mutable_descriptor_type_create_info->mutableDescriptorTypeListCount; ++i) { |
| 206 | const auto &list = mutable_descriptor_type_create_info->pMutableDescriptorTypeLists[i]; |
| 207 | mutable_types_[i].reserve(list.descriptorTypeCount); |
| 208 | for (uint32_t j = 0; j < list.descriptorTypeCount; ++j) { |
| 209 | mutable_types_[i].push_back(list.pDescriptorTypes[j]); |
| 210 | } |
ziga-lunarg | 2ab8c47 | 2021-10-27 22:54:02 +0200 | [diff] [blame] | 211 | std::sort(mutable_types_[i].begin(), mutable_types_[i].end()); |
ziga-lunarg | d67b5f5 | 2021-10-16 23:52:59 +0200 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 215 | // Store the create info in the sorted order from above |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 216 | uint32_t index = 0; |
| 217 | binding_count_ = static_cast<uint32_t>(sorted_bindings.size()); |
| 218 | bindings_.reserve(binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 219 | binding_flags_.reserve(binding_count_); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 220 | binding_to_index_map_.reserve(binding_count_); |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 221 | for (const auto &input_binding : sorted_bindings) { |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 222 | // 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] | 223 | const auto binding_num = input_binding.layout_binding->binding; |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 224 | binding_to_index_map_[binding_num] = index++; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 225 | bindings_.emplace_back(input_binding.layout_binding); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 226 | auto &binding_info = bindings_.back(); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 227 | binding_flags_.emplace_back(input_binding.binding_flags); |
John Zulauf | 508d13a | 2018-01-05 15:10:34 -0700 | [diff] [blame] | 228 | |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 229 | descriptor_count_ += binding_info.descriptorCount; |
| 230 | if (binding_info.descriptorCount > 0) { |
| 231 | non_empty_bindings_.insert(binding_num); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 232 | } |
John Zulauf | b6d7120 | 2017-12-22 16:47:09 -0700 | [diff] [blame] | 233 | |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 234 | if (IsDynamicDescriptor(binding_info.descriptorType)) { |
sfricke-samsung | 0d00aed | 2021-03-08 23:31:17 -0800 | [diff] [blame] | 235 | dynamic_descriptor_count_ += binding_info.descriptorCount; |
| 236 | } |
| 237 | |
| 238 | // Get stats depending on descriptor type for caching later |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 239 | if (IsBufferDescriptor(binding_info.descriptorType)) { |
| 240 | if (IsDynamicDescriptor(binding_info.descriptorType)) { |
| 241 | binding_type_stats_.dynamic_buffer_count++; |
| 242 | } else { |
| 243 | binding_type_stats_.non_dynamic_buffer_count++; |
| 244 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 245 | } |
| 246 | } |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 247 | assert(bindings_.size() == binding_count_); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 248 | assert(binding_flags_.size() == binding_count_); |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 249 | uint32_t global_index = 0; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 250 | global_index_range_.reserve(binding_count_); |
| 251 | // 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] | 252 | for (uint32_t i = 0; i < binding_count_; ++i) { |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 253 | auto final_index = global_index + bindings_[i].descriptorCount; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 254 | global_index_range_.emplace_back(global_index, final_index); |
John Zulauf | c483f44 | 2017-12-15 14:02:06 -0700 | [diff] [blame] | 255 | global_index = final_index; |
Tobin Ehlis | 9637fb2 | 2016-12-12 15:59:34 -0700 | [diff] [blame] | 256 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 257 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 258 | |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 259 | size_t cvdescriptorset::DescriptorSetLayoutDef::hash() const { |
| 260 | hash_util::HashCombiner hc; |
| 261 | hc << flags_; |
| 262 | hc.Combine(bindings_); |
John Zulauf | 223b69d | 2018-11-09 16:00:59 -0700 | [diff] [blame] | 263 | hc.Combine(binding_flags_); |
John Zulauf | d47d061 | 2018-02-16 13:00:34 -0700 | [diff] [blame] | 264 | return hc.Value(); |
| 265 | } |
| 266 | // |
| 267 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 268 | // Return valid index or "end" i.e. binding_count_; |
| 269 | // The asserts in "Get" are reduced to the set where no valid answer(like null or 0) could be given |
| 270 | // Common code for all binding lookups. |
| 271 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetIndexFromBinding(uint32_t binding) const { |
| 272 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 273 | if (bi_itr != binding_to_index_map_.cend()) return bi_itr->second; |
| 274 | return GetBindingCount(); |
| 275 | } |
| 276 | VkDescriptorSetLayoutBinding const *cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorSetLayoutBindingPtrFromIndex( |
| 277 | const uint32_t index) const { |
| 278 | if (index >= bindings_.size()) return nullptr; |
| 279 | return bindings_[index].ptr(); |
| 280 | } |
| 281 | // Return descriptorCount for given index, 0 if index is unavailable |
| 282 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorCountFromIndex(const uint32_t index) const { |
| 283 | if (index >= bindings_.size()) return 0; |
| 284 | return bindings_[index].descriptorCount; |
| 285 | } |
| 286 | // For the given index, return descriptorType |
| 287 | VkDescriptorType cvdescriptorset::DescriptorSetLayoutDef::GetTypeFromIndex(const uint32_t index) const { |
| 288 | assert(index < bindings_.size()); |
| 289 | if (index < bindings_.size()) return bindings_[index].descriptorType; |
| 290 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 291 | } |
| 292 | // For the given index, return stageFlags |
| 293 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayoutDef::GetStageFlagsFromIndex(const uint32_t index) const { |
| 294 | assert(index < bindings_.size()); |
| 295 | if (index < bindings_.size()) return bindings_[index].stageFlags; |
| 296 | return VkShaderStageFlags(0); |
| 297 | } |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 298 | // Return binding flags for given index, 0 if index is unavailable |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 299 | VkDescriptorBindingFlags cvdescriptorset::DescriptorSetLayoutDef::GetDescriptorBindingFlagsFromIndex(const uint32_t index) const { |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 300 | if (index >= binding_flags_.size()) return 0; |
| 301 | return binding_flags_[index]; |
| 302 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 303 | |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 304 | const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromIndex(uint32_t index) const { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 305 | const static IndexRange k_invalid_range = {0xFFFFFFFF, 0xFFFFFFFF}; |
| 306 | if (index >= binding_flags_.size()) return k_invalid_range; |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 307 | return global_index_range_[index]; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 308 | } |
| 309 | |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 310 | // For the given binding, return the global index range (half open) |
| 311 | // 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] | 312 | const cvdescriptorset::IndexRange &cvdescriptorset::DescriptorSetLayoutDef::GetGlobalIndexRangeFromBinding( |
| 313 | const uint32_t binding) const { |
John Zulauf | 7705bfc | 2019-06-10 09:52:04 -0600 | [diff] [blame] | 314 | uint32_t index = GetIndexFromBinding(binding); |
| 315 | return GetGlobalIndexRangeFromIndex(index); |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 316 | } |
| 317 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 318 | // Move to next valid binding having a non-zero binding count |
| 319 | uint32_t cvdescriptorset::DescriptorSetLayoutDef::GetNextValidBinding(const uint32_t binding) const { |
| 320 | auto it = non_empty_bindings_.upper_bound(binding); |
| 321 | assert(it != non_empty_bindings_.cend()); |
| 322 | if (it != non_empty_bindings_.cend()) return *it; |
| 323 | return GetMaxBinding() + 1; |
| 324 | } |
| 325 | // For given index, return ptr to ImmutableSampler array |
| 326 | VkSampler const *cvdescriptorset::DescriptorSetLayoutDef::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 327 | if (index < bindings_.size()) { |
| 328 | return bindings_[index].pImmutableSamplers; |
| 329 | } |
| 330 | return nullptr; |
| 331 | } |
John Zulauf | 9ce3b25 | 2019-06-06 15:20:22 -0600 | [diff] [blame] | 332 | |
ziga-lunarg | d67b5f5 | 2021-10-16 23:52:59 +0200 | [diff] [blame] | 333 | bool cvdescriptorset::DescriptorSetLayoutDef::IsTypeMutable(const VkDescriptorType type, uint32_t binding) const { |
| 334 | if (binding < mutable_types_.size()) { |
| 335 | if (mutable_types_[binding].size() > 0) { |
| 336 | for (const auto mutable_type : mutable_types_[binding]) { |
| 337 | if (type == mutable_type) { |
| 338 | return true; |
| 339 | } |
| 340 | } |
| 341 | return false; |
| 342 | } |
| 343 | } |
Mike Schuchardt | 2d523e5 | 2022-09-15 12:25:58 -0700 | [diff] [blame] | 344 | // If mutableDescriptorTypeListCount is zero or if VkMutableDescriptorTypeCreateInfoEXT structure is not included in the pNext |
| 345 | // chain, the VkMutableDescriptorTypeListEXT for each element is considered to be zero or NULL for each member. |
ziga-lunarg | d67b5f5 | 2021-10-16 23:52:59 +0200 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
ziga-lunarg | 2ab8c47 | 2021-10-27 22:54:02 +0200 | [diff] [blame] | 349 | const std::vector<std::vector<VkDescriptorType>>& cvdescriptorset::DescriptorSetLayoutDef::GetMutableTypes() const { |
| 350 | return mutable_types_; |
| 351 | } |
| 352 | |
ziga-lunarg | e5d2854 | 2021-10-24 21:14:25 +0200 | [diff] [blame] | 353 | const std::vector<VkDescriptorType> &cvdescriptorset::DescriptorSetLayoutDef::GetMutableTypes(uint32_t binding) const { |
| 354 | if (binding >= mutable_types_.size()) { |
| 355 | static const std::vector<VkDescriptorType> empty = {}; |
| 356 | return empty; |
| 357 | } |
| 358 | return mutable_types_[binding]; |
| 359 | } |
| 360 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 361 | bool cvdescriptorset::DescriptorSetLayoutDef::IsNextBindingConsistent(const uint32_t binding) const { |
| 362 | if (!binding_to_index_map_.count(binding + 1)) return false; |
| 363 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 364 | if (bi_itr != binding_to_index_map_.end()) { |
| 365 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 366 | if (next_bi_itr != binding_to_index_map_.end()) { |
| 367 | auto type = bindings_[bi_itr->second].descriptorType; |
| 368 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 369 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 370 | auto flags = binding_flags_[bi_itr->second]; |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 371 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 372 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 373 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false)) || |
| 374 | (flags != binding_flags_[next_bi_itr->second])) { |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | return true; |
| 378 | } |
| 379 | } |
| 380 | return false; |
| 381 | } |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 382 | |
Jeremy Gebben | bb718a3 | 2022-05-12 08:51:10 -0600 | [diff] [blame] | 383 | // If our layout is compatible with rh_ds_layout, return true. |
| 384 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(DescriptorSetLayout const *rh_ds_layout) const { |
| 385 | bool compatible = (this == rh_ds_layout) || (GetLayoutDef() == rh_ds_layout->GetLayoutDef()); |
| 386 | return compatible; |
| 387 | } |
| 388 | |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 389 | // The DescriptorSetLayout stores the per handle data for a descriptor set layout, and references the common defintion for the |
| 390 | // handle invariant portion |
| 391 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, |
| 392 | const VkDescriptorSetLayout layout) |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 393 | : BASE_NODE(layout, kVulkanObjectTypeDescriptorSetLayout), layout_id_(GetCanonicalId(p_create_info)) {} |
John Zulauf | 1f8174b | 2018-02-16 12:58:37 -0700 | [diff] [blame] | 394 | |
Mark Lobodzinski | e12b6e3 | 2020-06-29 11:44:15 -0600 | [diff] [blame] | 395 | void cvdescriptorset::AllocateDescriptorSetsData::Init(uint32_t count) { |
| 396 | layout_nodes.resize(count); |
Mark Lobodzinski | e12b6e3 | 2020-06-29 11:44:15 -0600 | [diff] [blame] | 397 | } |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 398 | |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 399 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, DESCRIPTOR_POOL_STATE *pool_state, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 400 | const std::shared_ptr<DescriptorSetLayout const> &layout, uint32_t variable_count, |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 401 | const cvdescriptorset::DescriptorSet::StateTracker *state_data) |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 402 | : BASE_NODE(set, kVulkanObjectTypeDescriptorSet), |
| 403 | some_update_(false), |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 404 | pool_state_(pool_state), |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 405 | layout_(layout), |
John Zulauf | d2c3dae | 2019-12-12 11:02:17 -0700 | [diff] [blame] | 406 | state_data_(state_data), |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 407 | variable_count_(variable_count), |
| 408 | change_count_(0) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 409 | // Foreach binding, create default descriptors of given type |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 410 | auto binding_count = layout_->GetBindingCount(); |
| 411 | bindings_.reserve(binding_count); |
| 412 | bindings_store_.resize(binding_count); |
| 413 | auto free_binding = bindings_store_.data(); |
| 414 | for (uint32_t i = 0; i < binding_count; ++i) { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 415 | auto create_info = layout_->GetDescriptorSetLayoutBindingPtrFromIndex(i); |
| 416 | assert(create_info); |
| 417 | uint32_t descriptor_count = create_info->descriptorCount; |
| 418 | auto flags = layout_->GetDescriptorBindingFlagsFromIndex(i); |
| 419 | if (flags & VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT) { |
ziga-lunarg | 9b3f677 | 2022-04-17 20:33:42 +0200 | [diff] [blame] | 420 | descriptor_count = variable_count; |
| 421 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 422 | auto type = layout_->GetTypeFromIndex(i); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 423 | auto descriptor_class = DescriptorTypeToClass(type); |
| 424 | switch (descriptor_class) { |
| 425 | case PlainSampler: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 426 | auto binding = MakeBinding<SamplerBinding>(free_binding++, *create_info, descriptor_count, flags); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 427 | auto immut = layout_->GetImmutableSamplerPtrFromIndex(i); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 428 | if (immut) { |
| 429 | for (uint32_t di = 0; di < descriptor_count; ++di) { |
| 430 | auto sampler = state_data->GetConstCastShared<SAMPLER_STATE>(immut[di]); |
| 431 | if (sampler) { |
| 432 | some_update_ = true; // Immutable samplers are updated at creation |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 433 | binding->updated[di] = true; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 434 | binding->descriptors[di].SetSamplerState(std::move(sampler)); |
| 435 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 436 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 437 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 438 | bindings_.push_back(std::move(binding)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 439 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 440 | } |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 441 | case ImageSampler: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 442 | auto binding = MakeBinding<ImageSamplerBinding>(free_binding++, *create_info, descriptor_count, flags); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 443 | auto immut = layout_->GetImmutableSamplerPtrFromIndex(i); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 444 | if (immut) { |
| 445 | for (uint32_t di = 0; di < descriptor_count; ++di) { |
| 446 | auto sampler = state_data->GetConstCastShared<SAMPLER_STATE>(immut[di]); |
| 447 | if (sampler) { |
| 448 | some_update_ = true; // Immutable samplers are updated at creation |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 449 | binding->updated[di] = true; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 450 | binding->descriptors[di].SetSamplerState(std::move(sampler)); |
| 451 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 452 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 453 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 454 | bindings_.push_back(std::move(binding)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 455 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 456 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 457 | // ImageDescriptors |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 458 | case Image: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 459 | bindings_.push_back(MakeBinding<ImageBinding>(free_binding++, *create_info, descriptor_count, flags)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 460 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 461 | } |
| 462 | case TexelBuffer: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 463 | bindings_.push_back(MakeBinding<TexelBinding>(free_binding++, *create_info, descriptor_count, flags)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 464 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 465 | } |
| 466 | case GeneralBuffer: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 467 | auto binding = MakeBinding<BufferBinding>(free_binding++, *create_info, descriptor_count, flags); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 468 | if (IsDynamicDescriptor(type)) { |
| 469 | for (uint32_t di = 0; di < descriptor_count; ++di) { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 470 | dynamic_offset_idx_to_descriptor_list_.push_back({i, di}); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 471 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 472 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 473 | bindings_.push_back(std::move(binding)); |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 474 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 475 | } |
| 476 | case InlineUniform: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 477 | bindings_.push_back(MakeBinding<InlineUniformBinding>(free_binding++, *create_info, descriptor_count, flags)); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 478 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 479 | } |
| 480 | case AccelerationStructure: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 481 | bindings_.push_back( |
| 482 | MakeBinding<AccelerationStructureBinding>(free_binding++, *create_info, descriptor_count, flags)); |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 483 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 484 | } |
| 485 | case Mutable: { |
Jeremy Gebben | 0f6c60c | 2022-07-29 09:39:41 -0600 | [diff] [blame] | 486 | bindings_.push_back(MakeBinding<MutableBinding>(free_binding++, *create_info, descriptor_count, flags)); |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 487 | break; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 488 | } |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 489 | default: |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 490 | assert(0); // Bad descriptor type specified |
Mark Lobodzinski | 64318ba | 2017-01-26 13:34:13 -0700 | [diff] [blame] | 491 | break; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 495 | |
Jeremy Gebben | 610d3a6 | 2022-01-01 12:53:17 -0700 | [diff] [blame] | 496 | void cvdescriptorset::DescriptorSet::LinkChildNodes() { |
| 497 | // Connect child node(s), which cannot safely be done in the constructor. |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 498 | for (auto &binding : bindings_) { |
| 499 | binding->AddParent(this); |
Jeremy Gebben | 610d3a6 | 2022-01-01 12:53:17 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 503 | void cvdescriptorset::DescriptorSet::Destroy() { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 504 | for (auto &binding : bindings_) { |
| 505 | binding->RemoveParent(this); |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 506 | } |
| 507 | BASE_NODE::Destroy(); |
| 508 | } |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 509 | // 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] | 510 | void cvdescriptorset::DescriptorSet::PerformPushDescriptorsUpdate(ValidationStateTracker *dev_data, uint32_t write_count, |
| 511 | const VkWriteDescriptorSet *p_wds) { |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 512 | assert(IsPushDescriptor()); |
| 513 | for (uint32_t i = 0; i < write_count; i++) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 514 | PerformWriteUpdate(dev_data, &p_wds[i]); |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 515 | } |
Jason Macnak | 83cfd58 | 2019-07-31 10:14:24 -0700 | [diff] [blame] | 516 | |
| 517 | push_descriptor_set_writes.clear(); |
| 518 | push_descriptor_set_writes.reserve(static_cast<std::size_t>(write_count)); |
| 519 | for (uint32_t i = 0; i < write_count; i++) { |
| 520 | push_descriptor_set_writes.push_back(safe_VkWriteDescriptorSet(&p_wds[i])); |
| 521 | } |
John Zulauf | 1d27e0a | 2018-11-05 10:12:48 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 524 | // Perform write update in given update struct |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 525 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(ValidationStateTracker *dev_data, const VkWriteDescriptorSet *update) { |
Tobin Ehlis | f922ef8 | 2016-11-30 10:19:14 -0700 | [diff] [blame] | 526 | // Perform update on a per-binding basis as consecutive updates roll over to next binding |
| 527 | auto descriptors_remaining = update->descriptorCount; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 528 | auto iter = FindDescriptor(update->dstBinding, update->dstArrayElement); |
| 529 | assert(!iter.AtEnd()); |
| 530 | auto &orig_binding = iter.CurrentBinding(); |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 531 | |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 532 | // Verify next consecutive binding matches type, stage flags & immutable sampler use and if AtEnd |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 533 | for (uint32_t i = 0; i < descriptors_remaining; ++i, ++iter) { |
| 534 | if (iter.AtEnd() || !orig_binding.IsConsistent(iter.CurrentBinding())) { |
| 535 | break; |
locke-lunarg | e46b778 | 2019-09-10 01:44:20 -0600 | [diff] [blame] | 536 | } |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 537 | iter->WriteUpdate(this, state_data_, update, i, iter.CurrentBinding().IsBindless()); |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 538 | iter.updated(true); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 539 | } |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 540 | if (update->descriptorCount) { |
| 541 | some_update_ = true; |
| 542 | change_count_++; |
| 543 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 544 | |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 545 | if (!IsPushDescriptor() && !(orig_binding.binding_flags & (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | |
| 546 | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 547 | Invalidate(false); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 548 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 549 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 550 | // Perform Copy update |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 551 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(ValidationStateTracker *dev_data, const VkCopyDescriptorSet *update, |
| 552 | const DescriptorSet *src_set) { |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 553 | auto src_iter = src_set->FindDescriptor(update->srcBinding, update->srcArrayElement); |
| 554 | auto dst_iter = FindDescriptor(update->dstBinding, update->dstArrayElement); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 555 | // Update parameters all look good so perform update |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 556 | for (uint32_t i = 0; i < update->descriptorCount; ++i, ++src_iter, ++dst_iter) { |
| 557 | auto &src = *src_iter; |
| 558 | auto &dst = *dst_iter; |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 559 | if (src_iter.updated()) { |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 560 | dst.CopyUpdate(this, state_data_, &src, src_iter.CurrentBinding().IsBindless()); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 561 | some_update_ = true; |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 562 | change_count_++; |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 563 | dst_iter.updated(true); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 564 | } else { |
Jeremy Gebben | f4816f7 | 2022-07-15 08:56:06 -0600 | [diff] [blame] | 565 | dst_iter.updated(false); |
Józef Kucia | 5297e37 | 2017-10-13 22:31:34 +0200 | [diff] [blame] | 566 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 567 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 568 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 569 | if (!(layout_->GetDescriptorBindingFlagsFromBinding(update->dstBinding) & |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 570 | (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT | VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT))) { |
Jeremy Gebben | 9efe1cf | 2021-05-15 20:05:09 -0600 | [diff] [blame] | 571 | Invalidate(false); |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 572 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 573 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 574 | |
John Zulauf | 6f3d2bd | 2018-10-29 17:08:42 -0600 | [diff] [blame] | 575 | // Update the drawing state for the affected descriptors. |
| 576 | // Set cb_node to this set and this set to cb_node. |
| 577 | // Add the bindings of the descriptor |
| 578 | // Set the layout based on the current descriptor layout (will mask subsequent layer mismatch errors) |
| 579 | // 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] | 580 | // Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going |
| 581 | // to be used in a draw by the given cb_node |
Jeremy Kniager | e682743 | 2020-04-01 09:05:56 -0600 | [diff] [blame] | 582 | void cvdescriptorset::DescriptorSet::UpdateDrawState(ValidationStateTracker *device_data, CMD_BUFFER_STATE *cb_node, |
| 583 | CMD_TYPE cmd_type, const PIPELINE_STATE *pipe, |
sfricke-samsung | 85584a7 | 2021-09-30 21:43:38 -0700 | [diff] [blame] | 584 | const BindingReqMap &binding_req_map) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 585 | // Descriptor UpdateDrawState only call image layout validation callbacks. If it is disabled, skip the entire loop. |
| 586 | if (device_data->disabled[image_layout_validation]) { |
Jeff Bolz | e18e724 | 2019-08-12 20:55:22 -0500 | [diff] [blame] | 587 | return; |
| 588 | } |
| 589 | |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 590 | // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's |
| 591 | // resources |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 592 | CMD_BUFFER_STATE::CmdDrawDispatchInfo cmd_info = {}; |
John Zulauf | 79f0658 | 2021-02-27 18:38:39 -0700 | [diff] [blame] | 593 | for (const auto &binding_req_pair : binding_req_map) { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 594 | auto binding = GetBinding(binding_req_pair.first); |
| 595 | assert(binding); |
locke-g | b3ce08f | 2019-09-30 12:30:56 -0600 | [diff] [blame] | 596 | |
Tony-LunarG | 62c5dba | 2018-12-20 14:27:23 -0700 | [diff] [blame] | 597 | // We aren't validating descriptors created with PARTIALLY_BOUND or UPDATE_AFTER_BIND, so don't record state |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 598 | if (binding->IsBindless()) { |
| 599 | if (!(binding->binding_flags & VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT)) { |
locke-lunarg | 3604599 | 2020-08-20 16:54:37 -0600 | [diff] [blame] | 600 | cmd_info.binding_infos.emplace_back(binding_req_pair); |
locke-g | b3ce08f | 2019-09-30 12:30:56 -0600 | [diff] [blame] | 601 | } |
Tony-LunarG | 62c5dba | 2018-12-20 14:27:23 -0700 | [diff] [blame] | 602 | continue; |
| 603 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 604 | switch (binding->descriptor_class) { |
| 605 | case Image: { |
| 606 | auto *image_binding = static_cast<ImageBinding *>(binding); |
| 607 | for (uint32_t i = 0; i < image_binding->count; ++i) { |
| 608 | image_binding->descriptors[i].UpdateDrawState(device_data, cb_node); |
| 609 | } |
| 610 | break; |
| 611 | } |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 612 | case ImageSampler: { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 613 | auto *image_binding = static_cast<ImageSamplerBinding *>(binding); |
| 614 | for (uint32_t i = 0; i < image_binding->count; ++i) { |
| 615 | image_binding->descriptors[i].UpdateDrawState(device_data, cb_node); |
Jeremy Gebben | 3f6f5c8 | 2022-05-03 15:25:57 -0600 | [diff] [blame] | 616 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 617 | break; |
| 618 | } |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 619 | case Mutable: { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 620 | auto *mutable_binding = static_cast<MutableBinding *>(binding); |
| 621 | for (uint32_t i = 0; i < mutable_binding->count; ++i) { |
| 622 | mutable_binding->descriptors[i].UpdateDrawState(device_data, cb_node); |
Jeremy Gebben | 3f6f5c8 | 2022-05-03 15:25:57 -0600 | [diff] [blame] | 623 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 624 | break; |
| 625 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 626 | default: |
| 627 | break; |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 628 | } |
| 629 | } |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 630 | |
| 631 | if (cmd_info.binding_infos.size() > 0) { |
| 632 | cmd_info.cmd_type = cmd_type; |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 633 | if (cb_node->activeFramebuffer) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 634 | cmd_info.framebuffer = cb_node->activeFramebuffer->framebuffer(); |
locke-lunarg | fc78e93 | 2020-11-19 17:06:24 -0700 | [diff] [blame] | 635 | cmd_info.attachments = cb_node->active_attachments; |
| 636 | cmd_info.subpasses = cb_node->active_subpasses; |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 637 | } |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 638 | cb_node->validate_descriptorsets_in_queuesubmit[GetSet()].emplace_back(cmd_info); |
locke-lunarg | 540b225 | 2020-08-03 13:23:36 -0600 | [diff] [blame] | 639 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 640 | } |
| 641 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 642 | void cvdescriptorset::DescriptorSet::FilterOneBindingReq(const BindingReqMap::value_type &binding_req_pair, BindingReqMap *out_req, |
| 643 | const TrackedBindings &bindings, uint32_t limit) { |
| 644 | if (bindings.size() < limit) { |
| 645 | const auto it = bindings.find(binding_req_pair.first); |
| 646 | if (it == bindings.cend()) out_req->emplace(binding_req_pair); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
Mark Lobodzinski | 2872f4a | 2018-09-03 17:00:53 -0600 | [diff] [blame] | 649 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 650 | void cvdescriptorset::DescriptorSet::FilterBindingReqs(const CMD_BUFFER_STATE &cb_state, const PIPELINE_STATE &pipeline, |
| 651 | const BindingReqMap &in_req, BindingReqMap *out_req) const { |
| 652 | // For const cleanliness we have to find in the maps... |
Jeremy Gebben | 87db52f | 2021-10-14 13:55:09 -0600 | [diff] [blame] | 653 | const auto validated_it = cb_state.descriptorset_cache.find(this); |
| 654 | if (validated_it == cb_state.descriptorset_cache.end()) { |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 655 | // We have nothing validated, copy in to out |
| 656 | for (const auto &binding_req_pair : in_req) { |
| 657 | out_req->emplace(binding_req_pair); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 658 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 659 | return; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 660 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 661 | const auto &validated = validated_it->second; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 662 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 663 | const auto image_sample_version_it = validated.image_samplers.find(&pipeline); |
| 664 | const VersionedBindings *image_sample_version = nullptr; |
| 665 | if (image_sample_version_it != validated.image_samplers.cend()) { |
| 666 | image_sample_version = &(image_sample_version_it->second); |
| 667 | } |
| 668 | const auto &dynamic_buffers = validated.dynamic_buffers; |
| 669 | const auto &non_dynamic_buffers = validated.non_dynamic_buffers; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 670 | const auto &stats = layout_->GetBindingTypeStats(); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 671 | for (const auto &binding_req_pair : in_req) { |
| 672 | auto binding = binding_req_pair.first; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 673 | VkDescriptorSetLayoutBinding const *layout_binding = layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding); |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 674 | if (!layout_binding) { |
| 675 | continue; |
| 676 | } |
| 677 | // Caching criteria differs per type. |
| 678 | // If image_layout have changed , the image descriptors need to be validated against them. |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 679 | if (IsBufferDescriptor(layout_binding->descriptorType)) { |
| 680 | if (IsDynamicDescriptor(layout_binding->descriptorType)) { |
| 681 | FilterOneBindingReq(binding_req_pair, out_req, dynamic_buffers, stats.dynamic_buffer_count); |
| 682 | } else { |
| 683 | FilterOneBindingReq(binding_req_pair, out_req, non_dynamic_buffers, stats.non_dynamic_buffer_count); |
| 684 | } |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 685 | } else { |
| 686 | // This is rather crude, as the changed layouts may not impact the bound descriptors, |
| 687 | // but the simple "versioning" is a simple "dirt" test. |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 688 | bool stale = true; |
| 689 | if (image_sample_version) { |
| 690 | const auto version_it = image_sample_version->find(binding); |
| 691 | if (version_it != image_sample_version->cend() && (version_it->second == cb_state.image_layout_change_count)) { |
| 692 | stale = false; |
| 693 | } |
| 694 | } |
| 695 | if (stale) { |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 696 | out_req->emplace(binding_req_pair); |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | } |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 701 | |
Jeremy Gebben | 87db52f | 2021-10-14 13:55:09 -0600 | [diff] [blame] | 702 | void cvdescriptorset::DescriptorSet::UpdateValidationCache(CMD_BUFFER_STATE &cb_state, const PIPELINE_STATE &pipeline, |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 703 | const BindingReqMap &updated_bindings) { |
Jeremy Gebben | 87db52f | 2021-10-14 13:55:09 -0600 | [diff] [blame] | 704 | auto &validated = cb_state.descriptorset_cache[this]; |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 705 | |
| 706 | auto &image_sample_version = validated.image_samplers[&pipeline]; |
| 707 | auto &dynamic_buffers = validated.dynamic_buffers; |
| 708 | auto &non_dynamic_buffers = validated.non_dynamic_buffers; |
| 709 | for (const auto &binding_req_pair : updated_bindings) { |
| 710 | auto binding = binding_req_pair.first; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 711 | VkDescriptorSetLayoutBinding const *layout_binding = layout_->GetDescriptorSetLayoutBindingPtrFromBinding(binding); |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 712 | if (!layout_binding) { |
| 713 | continue; |
| 714 | } |
| 715 | // Caching criteria differs per type. |
sfricke-samsung | 60f29ec | 2021-03-10 20:37:25 -0800 | [diff] [blame] | 716 | if (IsBufferDescriptor(layout_binding->descriptorType)) { |
| 717 | if (IsDynamicDescriptor(layout_binding->descriptorType)) { |
| 718 | dynamic_buffers.emplace(binding); |
| 719 | } else { |
| 720 | non_dynamic_buffers.emplace(binding); |
| 721 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 722 | } else { |
| 723 | // Save the layout change version... |
| 724 | image_sample_version[binding] = cb_state.image_layout_change_count; |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 729 | // Helper template to change shared pointer members of a Descriptor, while |
| 730 | // correctly managing links to the parent DescriptorSet. |
| 731 | // src and dst are shared pointers. |
| 732 | template <typename T> |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 733 | static void ReplaceStatePtr(DescriptorSet *set_state, T &dst, const T &src, bool is_bindless) { |
| 734 | if (dst && !is_bindless) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 735 | dst->RemoveParent(set_state); |
| 736 | } |
| 737 | dst = src; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 738 | // For descriptor bindings with UPDATE_AFTER_BIND or PARTIALLY_BOUND only set the object as a child, but not the descriptor as a |
| 739 | // parent, so that destroying the object wont invalidate the descriptor |
| 740 | if (dst && !is_bindless) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 741 | dst->AddParent(set_state); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 746 | const VkWriteDescriptorSet *update, const uint32_t index, bool is_bindless) { |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 747 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 748 | ReplaceStatePtr(set_state, sampler_state_, dev_data->GetConstCastShared<SAMPLER_STATE>(update->pImageInfo[index].sampler), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 749 | is_bindless); |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 750 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 751 | } |
| 752 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 753 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 754 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 755 | if (src->GetClass() == Mutable) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 756 | auto *sampler_src = static_cast<const MutableDescriptor *>(src); |
| 757 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 758 | ReplaceStatePtr(set_state, sampler_state_, sampler_src->GetSharedSamplerState(), is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 759 | } |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 760 | return; |
| 761 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 762 | auto *sampler_src = static_cast<const SamplerDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 763 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 764 | ReplaceStatePtr(set_state, sampler_state_, sampler_src->sampler_state_, is_bindless); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 768 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 769 | const VkWriteDescriptorSet *update, const uint32_t index, |
| 770 | bool is_bindless) { |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 771 | const auto &image_info = update->pImageInfo[index]; |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 772 | if (!immutable_) { |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 773 | ReplaceStatePtr(set_state, sampler_state_, dev_data->GetConstCastShared<SAMPLER_STATE>(image_info.sampler), is_bindless); |
Chris Forbes | fea2c54 | 2018-04-13 09:34:15 -0700 | [diff] [blame] | 774 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 775 | image_layout_ = image_info.imageLayout; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 776 | ReplaceStatePtr(set_state, image_view_state_, dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 777 | is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 778 | } |
| 779 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 780 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 781 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 782 | if (src->GetClass() == Mutable) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 783 | auto *image_src = static_cast<const MutableDescriptor *>(src); |
| 784 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 785 | ReplaceStatePtr(set_state, sampler_state_, image_src->GetSharedSamplerState(), is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 786 | } |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 787 | ImageDescriptor::CopyUpdate(set_state, dev_data, src, is_bindless); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 788 | return; |
| 789 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 790 | auto *image_src = static_cast<const ImageSamplerDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 791 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 792 | ReplaceStatePtr(set_state, sampler_state_, image_src->sampler_state_, is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 793 | } |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 794 | ImageDescriptor::CopyUpdate(set_state, dev_data, src, is_bindless); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 795 | } |
| 796 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 797 | void cvdescriptorset::ImageDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 798 | const VkWriteDescriptorSet *update, const uint32_t index, bool is_bindless) { |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 799 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 800 | image_layout_ = image_info.imageLayout; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 801 | ReplaceStatePtr(set_state, image_view_state_, dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 802 | is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 803 | } |
| 804 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 805 | void cvdescriptorset::ImageDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 806 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 807 | if (src->GetClass() == Mutable) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 808 | auto *image_src = static_cast<const MutableDescriptor *>(src); |
| 809 | |
| 810 | image_layout_ = image_src->GetImageLayout(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 811 | ReplaceStatePtr(set_state, image_view_state_, image_src->GetSharedImageViewState(), is_bindless); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 812 | return; |
| 813 | } |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 814 | auto *image_src = static_cast<const ImageDescriptor *>(src); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 815 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 816 | image_layout_ = image_src->image_layout_; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 817 | ReplaceStatePtr(set_state, image_view_state_, image_src->image_view_state_, is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 818 | } |
| 819 | |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 820 | void cvdescriptorset::ImageDescriptor::UpdateDrawState(ValidationStateTracker *dev_data, CMD_BUFFER_STATE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 821 | // Add binding for image |
Jeff Bolz | faffeb3 | 2019-10-04 12:47:16 -0500 | [diff] [blame] | 822 | auto iv_state = GetImageViewState(); |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 823 | if (iv_state) { |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 824 | dev_data->CallSetImageViewInitialLayoutCallback(cb_node, *iv_state, image_layout_); |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 825 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 826 | } |
| 827 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 828 | void cvdescriptorset::BufferDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 829 | const VkWriteDescriptorSet *update, const uint32_t index, bool is_bindless) { |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 830 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 831 | offset_ = buffer_info.offset; |
| 832 | range_ = buffer_info.range; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 833 | auto buffer_state = dev_data->GetConstCastShared<BUFFER_STATE>(buffer_info.buffer); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 834 | ReplaceStatePtr(set_state, buffer_state_, buffer_state, is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 835 | } |
| 836 | |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 837 | void cvdescriptorset::BufferDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 838 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 839 | if (src->GetClass() == Mutable) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 840 | const auto buff_desc = static_cast<const MutableDescriptor *>(src); |
| 841 | offset_ = buff_desc->GetOffset(); |
| 842 | range_ = buff_desc->GetRange(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 843 | ReplaceStatePtr(set_state, buffer_state_, buff_desc->GetSharedBufferState(), is_bindless); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 844 | return; |
| 845 | } |
Karl Schultz | 76d16a4 | 2020-11-11 05:05:33 -0700 | [diff] [blame] | 846 | const auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 847 | offset_ = buff_desc->offset_; |
| 848 | range_ = buff_desc->range_; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 849 | ReplaceStatePtr(set_state, buffer_state_, buff_desc->buffer_state_, is_bindless); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 850 | } |
| 851 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 852 | void cvdescriptorset::TexelDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 853 | const VkWriteDescriptorSet *update, const uint32_t index, bool is_bindless) { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 854 | auto buffer_view = dev_data->GetConstCastShared<BUFFER_VIEW_STATE>(update->pTexelBufferView[index]); |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 855 | ReplaceStatePtr(set_state, buffer_view_state_, buffer_view, is_bindless); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 856 | } |
| 857 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 858 | void cvdescriptorset::TexelDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 859 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 860 | if (src->GetClass() == Mutable) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 861 | ReplaceStatePtr(set_state, buffer_view_state_, static_cast<const MutableDescriptor *>(src)->GetSharedBufferViewState(), |
| 862 | is_bindless); |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 863 | return; |
| 864 | } |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 865 | ReplaceStatePtr(set_state, buffer_view_state_, static_cast<const TexelDescriptor *>(src)->buffer_view_state_, is_bindless); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 866 | } |
| 867 | |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 868 | void cvdescriptorset::AccelerationStructureDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 869 | const VkWriteDescriptorSet *update, const uint32_t index, |
| 870 | bool is_bindless) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 871 | const auto *acc_info = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureKHR>(update->pNext); |
| 872 | const auto *acc_info_nv = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureNV>(update->pNext); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 873 | assert(acc_info || acc_info_nv); |
| 874 | is_khr_ = (acc_info != NULL); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 875 | if (is_khr_) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 876 | acc_ = acc_info->pAccelerationStructures[index]; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 877 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), is_bindless); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 878 | } else { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 879 | acc_nv_ = acc_info_nv->pAccelerationStructures[index]; |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 880 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), is_bindless); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 881 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 882 | } |
| 883 | |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 884 | void cvdescriptorset::AccelerationStructureDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 885 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 886 | if (src->GetClass() == Mutable) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 887 | auto acc_desc = static_cast<const MutableDescriptor *>(src); |
| 888 | if (is_khr_) { |
| 889 | acc_ = acc_desc->GetAccelerationStructure(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 890 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), |
| 891 | is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 892 | } else { |
| 893 | acc_nv_ = acc_desc->GetAccelerationStructureNV(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 894 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), |
| 895 | is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 896 | } |
Tony-LunarG | 8035832 | 2021-04-16 07:58:13 -0600 | [diff] [blame] | 897 | return; |
| 898 | } |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 899 | auto acc_desc = static_cast<const AccelerationStructureDescriptor *>(src); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 900 | if (is_khr_) { |
| 901 | acc_ = acc_desc->acc_; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 902 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), is_bindless); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 903 | } else { |
| 904 | acc_nv_ = acc_desc->acc_nv_; |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 905 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), is_bindless); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 906 | } |
Jeff Bolz | 95176d0 | 2020-04-01 00:36:16 -0500 | [diff] [blame] | 907 | } |
| 908 | |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 909 | cvdescriptorset::MutableDescriptor::MutableDescriptor() |
| 910 | : Descriptor(), |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 911 | buffer_size_(0), |
Mike Schuchardt | 2d523e5 | 2022-09-15 12:25:58 -0700 | [diff] [blame] | 912 | active_descriptor_type_(VK_DESCRIPTOR_TYPE_MUTABLE_EXT), |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 913 | immutable_(false), |
| 914 | image_layout_(VK_IMAGE_LAYOUT_UNDEFINED), |
| 915 | offset_(0), |
| 916 | range_(0), |
| 917 | is_khr_(false), |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 918 | acc_(VK_NULL_HANDLE) {} |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 919 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 920 | void cvdescriptorset::MutableDescriptor::WriteUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 921 | const VkWriteDescriptorSet *update, const uint32_t index, bool is_bindless) { |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 922 | VkDeviceSize buffer_size = 0; |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 923 | switch (DescriptorTypeToClass(update->descriptorType)) { |
| 924 | case DescriptorClass::PlainSampler: |
| 925 | if (!immutable_) { |
| 926 | ReplaceStatePtr(set_state, sampler_state_, |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 927 | dev_data->GetConstCastShared<SAMPLER_STATE>(update->pImageInfo[index].sampler), is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 928 | } |
| 929 | break; |
| 930 | case DescriptorClass::ImageSampler: { |
| 931 | const auto &image_info = update->pImageInfo[index]; |
| 932 | if (!immutable_) { |
| 933 | ReplaceStatePtr(set_state, sampler_state_, dev_data->GetConstCastShared<SAMPLER_STATE>(image_info.sampler), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 934 | is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 935 | } |
| 936 | image_layout_ = image_info.imageLayout; |
| 937 | ReplaceStatePtr(set_state, image_view_state_, dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 938 | is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 939 | break; |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 940 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 941 | case DescriptorClass::Image: { |
| 942 | const auto &image_info = update->pImageInfo[index]; |
| 943 | image_layout_ = image_info.imageLayout; |
| 944 | ReplaceStatePtr(set_state, image_view_state_, dev_data->GetConstCastShared<IMAGE_VIEW_STATE>(image_info.imageView), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 945 | is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 946 | break; |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 947 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 948 | case DescriptorClass::GeneralBuffer: { |
| 949 | const auto &buffer_info = update->pBufferInfo[index]; |
| 950 | offset_ = buffer_info.offset; |
| 951 | range_ = buffer_info.range; |
| 952 | const auto buffer_state = dev_data->GetConstCastShared<BUFFER_STATE>(update->pBufferInfo->buffer); |
| 953 | if (buffer_state) { |
| 954 | buffer_size = buffer_state->createInfo.size; |
| 955 | } |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 956 | ReplaceStatePtr(set_state, buffer_state_, buffer_state, is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 957 | break; |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 958 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 959 | case DescriptorClass::TexelBuffer: { |
| 960 | const auto buffer_view = dev_data->GetConstCastShared<BUFFER_VIEW_STATE>(update->pTexelBufferView[index]); |
| 961 | if (buffer_view) { |
| 962 | buffer_size = buffer_view->buffer_state->createInfo.size; |
| 963 | } |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 964 | ReplaceStatePtr(set_state, buffer_view_state_, buffer_view, is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 965 | break; |
| 966 | } |
| 967 | case DescriptorClass::AccelerationStructure: { |
| 968 | const auto *acc_info = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureKHR>(update->pNext); |
| 969 | const auto *acc_info_nv = LvlFindInChain<VkWriteDescriptorSetAccelerationStructureNV>(update->pNext); |
| 970 | assert(acc_info || acc_info_nv); |
| 971 | is_khr_ = (acc_info != NULL); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 972 | if (is_khr_) { |
| 973 | acc_ = acc_info->pAccelerationStructures[index]; |
| 974 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 975 | is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 976 | } else { |
| 977 | acc_nv_ = acc_info_nv->pAccelerationStructures[index]; |
| 978 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), |
Jeremy Gebben | 1b9fdb8 | 2022-06-15 15:31:32 -0600 | [diff] [blame] | 979 | is_bindless); |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 980 | } |
| 981 | break; |
| 982 | } |
| 983 | default: |
| 984 | break; |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 985 | } |
Jeremy Gebben | 080210f | 2022-05-05 13:37:08 -0600 | [diff] [blame] | 986 | SetDescriptorType(update->descriptorType, buffer_size); |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 987 | } |
| 988 | |
Jeremy Gebben | 5570abe | 2021-05-16 18:35:13 -0600 | [diff] [blame] | 989 | void cvdescriptorset::MutableDescriptor::CopyUpdate(DescriptorSet *set_state, const ValidationStateTracker *dev_data, |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 990 | const Descriptor *src, bool is_bindless) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 991 | if (src->GetClass() == DescriptorClass::PlainSampler) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 992 | auto *sampler_src = static_cast<const SamplerDescriptor *>(src); |
| 993 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 994 | ReplaceStatePtr(set_state, sampler_state_, sampler_src->GetSharedSamplerState(), is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 995 | } |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 996 | } else if (src->GetClass() == DescriptorClass::ImageSampler) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 997 | auto *image_src = static_cast<const ImageSamplerDescriptor *>(src); |
| 998 | if (!immutable_) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 999 | ReplaceStatePtr(set_state, sampler_state_, image_src->GetSharedSamplerState(), is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | image_layout_ = image_src->GetImageLayout(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1003 | ReplaceStatePtr(set_state, image_view_state_, image_src->GetSharedImageViewState(), is_bindless); |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1004 | } else if (src->GetClass() == DescriptorClass::Image) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1005 | auto *image_src = static_cast<const ImageDescriptor *>(src); |
| 1006 | |
| 1007 | image_layout_ = image_src->GetImageLayout(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1008 | ReplaceStatePtr(set_state, image_view_state_, image_src->GetSharedImageViewState(), is_bindless); |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1009 | } else if (src->GetClass() == DescriptorClass::TexelBuffer) { |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1010 | ReplaceStatePtr(set_state, buffer_view_state_, static_cast<const TexelDescriptor *>(src)->GetSharedBufferViewState(), |
| 1011 | is_bindless); |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1012 | } else if (src->GetClass() == DescriptorClass::GeneralBuffer) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1013 | const auto buff_desc = static_cast<const BufferDescriptor *>(src); |
| 1014 | offset_ = buff_desc->GetOffset(); |
| 1015 | range_ = buff_desc->GetRange(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1016 | ReplaceStatePtr(set_state, buffer_state_, buff_desc->GetSharedBufferState(), is_bindless); |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1017 | } else if (src->GetClass() == DescriptorClass::AccelerationStructure) { |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1018 | auto acc_desc = static_cast<const AccelerationStructureDescriptor *>(src); |
| 1019 | if (is_khr_) { |
| 1020 | acc_ = acc_desc->GetAccelerationStructure(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1021 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), |
| 1022 | is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1023 | } else { |
| 1024 | acc_nv_ = acc_desc->GetAccelerationStructureNV(); |
ziga-lunarg | b4f3f7d | 2022-04-17 15:36:03 +0200 | [diff] [blame] | 1025 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), |
| 1026 | is_bindless); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1027 | } |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1028 | } else if (src->GetClass() == DescriptorClass::Mutable) { |
| 1029 | const auto mutable_src = static_cast<const MutableDescriptor *>(src); |
| 1030 | auto active_class = DescriptorTypeToClass(mutable_src->ActiveType()); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1031 | switch (active_class) { |
| 1032 | case PlainSampler: { |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1033 | if (!immutable_) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1034 | ReplaceStatePtr(set_state, sampler_state_, mutable_src->GetSharedSamplerState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1035 | } |
| 1036 | } break; |
| 1037 | case ImageSampler: { |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1038 | if (!immutable_) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1039 | ReplaceStatePtr(set_state, sampler_state_, mutable_src->GetSharedSamplerState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1040 | } |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1041 | |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1042 | image_layout_ = mutable_src->GetImageLayout(); |
| 1043 | ReplaceStatePtr(set_state, image_view_state_, mutable_src->GetSharedImageViewState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1044 | } break; |
| 1045 | case Image: { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1046 | image_layout_ = mutable_src->GetImageLayout(); |
| 1047 | ReplaceStatePtr(set_state, image_view_state_, mutable_src->GetSharedImageViewState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1048 | } break; |
| 1049 | case GeneralBuffer: { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1050 | offset_ = mutable_src->GetOffset(); |
| 1051 | range_ = mutable_src->GetRange(); |
| 1052 | ReplaceStatePtr(set_state, buffer_state_, mutable_src->GetSharedBufferState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1053 | } break; |
| 1054 | case TexelBuffer: { |
| 1055 | ReplaceStatePtr(set_state, buffer_view_state_, |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1056 | mutable_src->GetSharedBufferViewState(), is_bindless); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1057 | } break; |
| 1058 | case AccelerationStructure: { |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1059 | if (is_khr_) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1060 | acc_ = mutable_src->GetAccelerationStructure(); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1061 | ReplaceStatePtr(set_state, acc_state_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE_KHR>(acc_), |
| 1062 | is_bindless); |
| 1063 | } else { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1064 | acc_nv_ = mutable_src->GetAccelerationStructureNV(); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1065 | ReplaceStatePtr(set_state, acc_state_nv_, dev_data->GetConstCastShared<ACCELERATION_STRUCTURE_STATE>(acc_nv_), |
| 1066 | is_bindless); |
| 1067 | } |
| 1068 | |
| 1069 | } break; |
| 1070 | default: |
| 1071 | break; |
| 1072 | } |
Jeremy Gebben | 5f823da | 2022-07-22 11:22:19 -0600 | [diff] [blame] | 1073 | SetDescriptorType(mutable_src->ActiveType(), mutable_src->GetBufferSize()); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | void cvdescriptorset::MutableDescriptor::UpdateDrawState(ValidationStateTracker *dev_data, CMD_BUFFER_STATE *cb_node) { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1078 | auto active_class = DescriptorTypeToClass(active_descriptor_type_); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1079 | if (active_class == Image || active_class == ImageSampler) { |
| 1080 | if (image_view_state_) { |
| 1081 | dev_data->CallSetImageViewInitialLayoutCallback(cb_node, *image_view_state_, image_layout_); |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | bool cvdescriptorset::MutableDescriptor::AddParent(BASE_NODE *base_node) { |
| 1087 | bool result = false; |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1088 | auto active_class = DescriptorTypeToClass(active_descriptor_type_); |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1089 | switch (active_class) { |
| 1090 | case PlainSampler: |
| 1091 | if (sampler_state_) { |
| 1092 | result |= sampler_state_->AddParent(base_node); |
| 1093 | } |
| 1094 | break; |
| 1095 | case ImageSampler: |
| 1096 | if (sampler_state_) { |
| 1097 | result |= sampler_state_->AddParent(base_node); |
| 1098 | } |
| 1099 | if (image_view_state_) { |
| 1100 | result = image_view_state_->AddParent(base_node); |
| 1101 | } |
| 1102 | break; |
| 1103 | case TexelBuffer: |
| 1104 | if (buffer_view_state_) { |
| 1105 | result = buffer_view_state_->AddParent(base_node); |
| 1106 | } |
| 1107 | break; |
| 1108 | case Image: |
| 1109 | if (image_view_state_) { |
| 1110 | result = image_view_state_->AddParent(base_node); |
| 1111 | } |
| 1112 | break; |
| 1113 | case GeneralBuffer: |
| 1114 | if (buffer_state_) { |
| 1115 | result = buffer_state_->AddParent(base_node); |
| 1116 | } |
| 1117 | break; |
| 1118 | case AccelerationStructure: |
| 1119 | if (acc_state_) { |
| 1120 | result |= acc_state_->AddParent(base_node); |
| 1121 | } |
| 1122 | if (acc_state_nv_) { |
| 1123 | result |= acc_state_nv_->AddParent(base_node); |
| 1124 | } |
Jeremy Gebben | bb718a3 | 2022-05-12 08:51:10 -0600 | [diff] [blame] | 1125 | break; |
| 1126 | default: |
| 1127 | break; |
ziga | da4b151 | 2021-11-28 15:53:06 +0100 | [diff] [blame] | 1128 | } |
| 1129 | return result; |
| 1130 | } |
| 1131 | void cvdescriptorset::MutableDescriptor::RemoveParent(BASE_NODE *base_node) { |
| 1132 | if (sampler_state_) { |
| 1133 | sampler_state_->RemoveParent(base_node); |
| 1134 | } |
| 1135 | if (image_view_state_) { |
| 1136 | image_view_state_->RemoveParent(base_node); |
| 1137 | } |
| 1138 | if (buffer_view_state_) { |
| 1139 | buffer_view_state_->RemoveParent(base_node); |
| 1140 | } |
| 1141 | if (buffer_state_) { |
| 1142 | buffer_state_->RemoveParent(base_node); |
| 1143 | } |
| 1144 | if (acc_state_) { |
| 1145 | acc_state_->RemoveParent(base_node); |
| 1146 | } |
| 1147 | if (acc_state_nv_) { |
| 1148 | acc_state_nv_->RemoveParent(base_node); |
| 1149 | } |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 1150 | } |
| 1151 | |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1152 | bool cvdescriptorset::MutableDescriptor::Invalid() const { |
Jeremy Gebben | c08f650 | 2022-07-15 09:55:06 -0600 | [diff] [blame] | 1153 | switch (ActiveClass()) { |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1154 | case PlainSampler: |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1155 | return !sampler_state_ || sampler_state_->Destroyed(); |
| 1156 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1157 | case ImageSampler: |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1158 | return !sampler_state_ || sampler_state_->Invalid() || !image_view_state_ || image_view_state_->Invalid(); |
| 1159 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1160 | case TexelBuffer: |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1161 | return !buffer_view_state_ || buffer_view_state_->Invalid(); |
| 1162 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1163 | case Image: |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1164 | return !image_view_state_ || image_view_state_->Invalid(); |
| 1165 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1166 | case GeneralBuffer: |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1167 | return !buffer_state_ || buffer_state_->Invalid(); |
| 1168 | |
Jeremy Gebben | 02f8320 | 2022-05-04 13:54:07 -0600 | [diff] [blame] | 1169 | case AccelerationStructure: |
| 1170 | if (is_khr_) { |
| 1171 | return !acc_state_ || acc_state_->Invalid(); |
| 1172 | } else { |
| 1173 | return !acc_state_nv_ || acc_state_nv_->Invalid(); |
| 1174 | } |
Jeremy Gebben | a08da23 | 2022-02-01 15:14:52 -0700 | [diff] [blame] | 1175 | default: |
| 1176 | return false; |
| 1177 | } |
| 1178 | } |
| 1179 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1180 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1181 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 1182 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 1183 | // with the same set of updates. |
| 1184 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 1185 | // calling down the chain. |
John Zulauf | e3b35f3 | 2019-06-25 14:21:21 -0600 | [diff] [blame] | 1186 | void cvdescriptorset::PerformUpdateDescriptorSets(ValidationStateTracker *dev_data, uint32_t write_count, |
| 1187 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 1188 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1189 | // Write updates first |
| 1190 | uint32_t i = 0; |
| 1191 | for (i = 0; i < write_count; ++i) { |
| 1192 | auto dest_set = p_wds[i].dstSet; |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 1193 | auto set_node = dev_data->Get<cvdescriptorset::DescriptorSet>(dest_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1194 | if (set_node) { |
Jeff Bolz | 41a1ced | 2019-10-11 11:40:49 -0500 | [diff] [blame] | 1195 | set_node->PerformWriteUpdate(dev_data, &p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | // Now copy updates |
| 1199 | for (i = 0; i < copy_count; ++i) { |
| 1200 | auto dst_set = p_cds[i].dstSet; |
| 1201 | auto src_set = p_cds[i].srcSet; |
Jeremy Gebben | b20a824 | 2021-11-05 15:14:43 -0600 | [diff] [blame] | 1202 | auto src_node = dev_data->Get<cvdescriptorset::DescriptorSet>(src_set); |
| 1203 | auto dst_node = dev_data->Get<cvdescriptorset::DescriptorSet>(dst_set); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1204 | if (src_node && dst_node) { |
Jeremy Gebben | 9f53710 | 2021-10-05 16:37:12 -0600 | [diff] [blame] | 1205 | dst_node->PerformCopyUpdate(dev_data, &p_cds[i], src_node.get()); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | } |
Jeff Bolz | dd4cfa1 | 2019-08-11 20:57:51 -0500 | [diff] [blame] | 1209 | const BindingReqMap &cvdescriptorset::PrefilterBindRequestMap::FilteredMap(const CMD_BUFFER_STATE &cb_state, |
| 1210 | const PIPELINE_STATE &pipeline) { |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1211 | if (IsManyDescriptors()) { |
Karl Schultz | 7090a05 | 2020-11-10 08:54:21 -0700 | [diff] [blame] | 1212 | filtered_map_.reset(new BindingReqMap); |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1213 | descriptor_set_.FilterBindingReqs(cb_state, pipeline, orig_map_, filtered_map_.get()); |
| 1214 | return *filtered_map_; |
John Zulauf | 48a6a70 | 2017-12-22 17:14:54 -0700 | [diff] [blame] | 1215 | } |
John Zulauf | fbf3c20 | 2019-07-17 14:57:14 -0600 | [diff] [blame] | 1216 | return orig_map_; |
Artem Kharytoniuk | 2456f99 | 2018-01-12 14:17:41 +0100 | [diff] [blame] | 1217 | } |