Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
| 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> |
| 19 | */ |
| 20 | |
| 21 | #include "descriptor_sets.h" |
| 22 | #include "vk_enum_string_helper.h" |
| 23 | #include "vk_safe_struct.h" |
| 24 | #include <sstream> |
| 25 | |
| 26 | // Construct DescriptorSetLayout instance from given create info |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 27 | cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 28 | const VkDescriptorSetLayout layout) |
| 29 | : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) { |
| 30 | uint32_t global_index = 0; |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 31 | // Dyn array indicies are ordered by binding # and array index of any array within the binding |
| 32 | // so we store up bindings w/ count in ordered map in order to create dyn array mappings below |
| 33 | std::map<uint32_t, uint32_t> binding_to_dyn_count; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 34 | for (uint32_t i = 0; i < binding_count_; ++i) { |
| 35 | descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | fdcb63f | 2016-10-25 20:56:47 -0600 | [diff] [blame] | 36 | binding_to_index_map_[p_create_info->pBindings[i].binding] = i; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 37 | binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index; |
| 38 | global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0; |
| 39 | binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index; |
Tobin Ehlis | 789c4ed | 2016-10-17 13:51:57 -0600 | [diff] [blame] | 40 | global_index += p_create_info->pBindings[i].descriptorCount ? 1 : 0; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 41 | bindings_.push_back(safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i])); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 42 | // In cases where we should ignore pImmutableSamplers make sure it's NULL |
| 43 | if ((p_create_info->pBindings[i].pImmutableSamplers) && |
| 44 | ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) && |
| 45 | (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 46 | bindings_.back().pImmutableSamplers = nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 47 | } |
| 48 | if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC || |
| 49 | p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) { |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 50 | binding_to_dyn_count[p_create_info->pBindings[i].binding] = p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | ef0de16 | 2016-06-20 13:07:34 -0600 | [diff] [blame] | 51 | dynamic_descriptor_count_ += p_create_info->pBindings[i].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 52 | } |
| 53 | } |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 54 | // Now create dyn offset array mapping for any dynamic descriptors |
| 55 | uint32_t dyn_array_idx = 0; |
| 56 | for (const auto &bc_pair : binding_to_dyn_count) { |
| 57 | binding_to_dynamic_array_idx_map_[bc_pair.first] = dyn_array_idx; |
| 58 | dyn_array_idx += bc_pair.second; |
| 59 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 60 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 61 | |
| 62 | // Validate descriptor set layout create info |
| 63 | bool cvdescriptorset::DescriptorSetLayout::ValidateCreateInfo(debug_report_data *report_data, |
| 64 | const VkDescriptorSetLayoutCreateInfo *create_info) { |
| 65 | bool skip = false; |
| 66 | std::unordered_set<uint32_t> bindings; |
| 67 | for (uint32_t i = 0; i < create_info->bindingCount; ++i) { |
Tobin Ehlis | fdcb63f | 2016-10-25 20:56:47 -0600 | [diff] [blame] | 68 | if (!bindings.insert(create_info->pBindings[i].binding).second) { |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 69 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, |
| 70 | VALIDATION_ERROR_02345, "DS", "duplicated binding number in VkDescriptorSetLayoutBinding. %s", |
| 71 | validation_error_map[VALIDATION_ERROR_02345]); |
| 72 | } |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame] | 73 | } |
| 74 | return skip; |
| 75 | } |
| 76 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 77 | // put all bindings into the given set |
| 78 | void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const { |
| 79 | for (auto binding_index_pair : binding_to_index_map_) |
| 80 | binding_set->insert(binding_index_pair.first); |
| 81 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 82 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 83 | VkDescriptorSetLayoutBinding const * |
| 84 | cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 85 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 86 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 87 | return bindings_[bi_itr->second].ptr(); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 88 | } |
| 89 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 90 | } |
| 91 | VkDescriptorSetLayoutBinding const * |
| 92 | cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const { |
| 93 | if (index >= bindings_.size()) |
| 94 | return nullptr; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 95 | return bindings_[index].ptr(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 96 | } |
| 97 | // Return descriptorCount for given binding, 0 if index is unavailable |
| 98 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 99 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 100 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 101 | return bindings_[bi_itr->second].descriptorCount; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 102 | } |
| 103 | return 0; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 104 | } |
| 105 | // Return descriptorCount for given index, 0 if index is unavailable |
| 106 | uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const { |
| 107 | if (index >= bindings_.size()) |
| 108 | return 0; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 109 | return bindings_[index].descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 110 | } |
| 111 | // For the given binding, return descriptorType |
| 112 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const { |
| 113 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 114 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 115 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 116 | return bindings_[bi_itr->second].descriptorType; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 117 | } |
| 118 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 119 | } |
| 120 | // For the given index, return descriptorType |
| 121 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const { |
| 122 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 123 | return bindings_[index].descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 124 | } |
| 125 | // For the given global index, return descriptorType |
| 126 | // Currently just counting up through bindings_, may improve this in future |
| 127 | VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const { |
| 128 | uint32_t global_offset = 0; |
| 129 | for (auto binding : bindings_) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 130 | global_offset += binding.descriptorCount; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 131 | if (index < global_offset) |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 132 | return binding.descriptorType; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 133 | } |
| 134 | assert(0); // requested global index is out of bounds |
| 135 | return VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 136 | } |
| 137 | // For the given binding, return stageFlags |
| 138 | VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const { |
| 139 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 140 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 141 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 142 | return bindings_[bi_itr->second].stageFlags; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 143 | } |
| 144 | return VkShaderStageFlags(0); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 145 | } |
| 146 | // For the given binding, return start index |
| 147 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const { |
| 148 | assert(binding_to_global_start_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 149 | const auto &btgsi_itr = binding_to_global_start_index_map_.find(binding); |
| 150 | if (btgsi_itr != binding_to_global_start_index_map_.end()) { |
| 151 | return btgsi_itr->second; |
| 152 | } |
| 153 | // In error case max uint32_t so index is out of bounds to break ASAP |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 154 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 155 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 156 | } |
| 157 | // For the given binding, return end index |
| 158 | uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const { |
| 159 | assert(binding_to_global_end_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 160 | const auto &btgei_itr = binding_to_global_end_index_map_.find(binding); |
| 161 | if (btgei_itr != binding_to_global_end_index_map_.end()) { |
| 162 | return btgei_itr->second; |
| 163 | } |
| 164 | // In error case max uint32_t so index is out of bounds to break ASAP |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 165 | assert(0); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 166 | return 0xFFFFFFFF; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 167 | } |
| 168 | // For given binding, return ptr to ImmutableSampler array |
| 169 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const { |
| 170 | assert(binding_to_index_map_.count(binding)); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 171 | const auto &bi_itr = binding_to_index_map_.find(binding); |
| 172 | if (bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 173 | return bindings_[bi_itr->second].pImmutableSamplers; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 174 | } |
| 175 | return nullptr; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 176 | } |
| 177 | // For given index, return ptr to ImmutableSampler array |
| 178 | VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const { |
| 179 | assert(index < bindings_.size()); |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 180 | return bindings_[index].pImmutableSamplers; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 181 | } |
| 182 | // If our layout is compatible with rh_ds_layout, return true, |
| 183 | // else return false and fill in error_msg will description of what causes incompatibility |
| 184 | bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const { |
| 185 | // Trivial case |
| 186 | if (layout_ == rh_ds_layout->GetDescriptorSetLayout()) |
| 187 | return true; |
| 188 | if (descriptor_count_ != rh_ds_layout->descriptor_count_) { |
| 189 | std::stringstream error_str; |
| 190 | error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout " |
| 191 | << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors."; |
| 192 | *error_msg = error_str.str(); |
| 193 | return false; // trivial fail case |
| 194 | } |
| 195 | // Descriptor counts match so need to go through bindings one-by-one |
| 196 | // and verify that type and stageFlags match |
| 197 | for (auto binding : bindings_) { |
| 198 | // TODO : Do we also need to check immutable samplers? |
| 199 | // VkDescriptorSetLayoutBinding *rh_binding; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 200 | if (binding.descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 201 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 202 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of " |
| 203 | << binding.descriptorCount << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 204 | << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 205 | << rh_ds_layout->GetDescriptorCountFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 206 | *error_msg = error_str.str(); |
| 207 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 208 | } else if (binding.descriptorType != rh_ds_layout->GetTypeFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 209 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 210 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " is type '" |
| 211 | << string_VkDescriptorType(binding.descriptorType) << "' but binding " << binding.binding |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 212 | << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '" |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 213 | << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding.binding)) << "'"; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 214 | *error_msg = error_str.str(); |
| 215 | return false; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 216 | } else if (binding.stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding.binding)) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 217 | std::stringstream error_str; |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 218 | error_str << "Binding " << binding.binding << " for DescriptorSetLayout " << layout_ << " has stageFlags " |
| 219 | << binding.stageFlags << " but binding " << binding.binding << " for DescriptorSetLayout " |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 220 | << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags " |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 221 | << rh_ds_layout->GetStageFlagsFromBinding(binding.binding); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 222 | *error_msg = error_str.str(); |
| 223 | return false; |
| 224 | } |
| 225 | } |
| 226 | return true; |
| 227 | } |
| 228 | |
| 229 | bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const { |
| 230 | if (!binding_to_index_map_.count(binding + 1)) |
| 231 | return false; |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 232 | auto const &bi_itr = binding_to_index_map_.find(binding); |
| 233 | if (bi_itr != binding_to_index_map_.end()) { |
| 234 | const auto &next_bi_itr = binding_to_index_map_.find(binding + 1); |
| 235 | if (next_bi_itr != binding_to_index_map_.end()) { |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 236 | auto type = bindings_[bi_itr->second].descriptorType; |
| 237 | auto stage_flags = bindings_[bi_itr->second].stageFlags; |
| 238 | auto immut_samp = bindings_[bi_itr->second].pImmutableSamplers ? true : false; |
| 239 | if ((type != bindings_[next_bi_itr->second].descriptorType) || |
| 240 | (stage_flags != bindings_[next_bi_itr->second].stageFlags) || |
| 241 | (immut_samp != (bindings_[next_bi_itr->second].pImmutableSamplers ? true : false))) { |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | return true; |
| 245 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 246 | } |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 247 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 248 | } |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 249 | // Starting at offset descriptor of given binding, parse over update_count |
| 250 | // descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent |
| 251 | // Consistency means that their type, stage flags, and whether or not they use immutable samplers matches |
| 252 | // If so, return true. If not, fill in error_msg and return false |
| 253 | bool cvdescriptorset::DescriptorSetLayout::VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count, |
| 254 | const char *type, const VkDescriptorSet set, |
| 255 | std::string *error_msg) const { |
| 256 | // Verify consecutive bindings match (if needed) |
| 257 | auto orig_binding = current_binding; |
| 258 | // Track count of descriptors in the current_bindings that are remaining to be updated |
| 259 | auto binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 260 | // First, it's legal to offset beyond your own binding so handle that case |
| 261 | // Really this is just searching for the binding in which the update begins and adjusting offset accordingly |
| 262 | while (offset >= binding_remaining) { |
| 263 | // Advance to next binding, decrement offset by binding size |
| 264 | offset -= binding_remaining; |
| 265 | binding_remaining = GetDescriptorCountFromBinding(++current_binding); |
| 266 | } |
| 267 | binding_remaining -= offset; |
| 268 | while (update_count > binding_remaining) { // While our updates overstep current binding |
| 269 | // Verify next consecutive binding matches type, stage flags & immutable sampler use |
| 270 | if (!IsNextBindingConsistent(current_binding++)) { |
| 271 | std::stringstream error_str; |
| 272 | error_str << "Attempting " << type << " descriptor set " << set << " binding #" << orig_binding << " with #" |
| 273 | << update_count << " descriptors being updated but this update oversteps the bounds of this binding and the " |
| 274 | "next binding is not consistent with current binding so this update is invalid."; |
| 275 | *error_msg = error_str.str(); |
| 276 | return false; |
| 277 | } |
| 278 | // For sake of this check consider the bindings updated and grab count for next binding |
| 279 | update_count -= binding_remaining; |
| 280 | binding_remaining = GetDescriptorCountFromBinding(current_binding); |
| 281 | } |
| 282 | return true; |
| 283 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 284 | |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 285 | cvdescriptorset::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t count) |
| 286 | : required_descriptors_by_type{}, layout_nodes(count, nullptr) {} |
| 287 | |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 288 | cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const VkDescriptorPool pool, |
| 289 | const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data) |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 290 | : some_update_(false), set_(set), pool_state_(nullptr), p_layout_(layout), device_data_(dev_data) { |
| 291 | pool_state_ = getDescriptorPoolState(dev_data, pool); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 292 | // Foreach binding, create default descriptors of given type |
| 293 | for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) { |
| 294 | auto type = p_layout_->GetTypeFromIndex(i); |
| 295 | switch (type) { |
| 296 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 297 | auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 298 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 299 | if (immut_sampler) |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 300 | descriptors_.emplace_back(new SamplerDescriptor(immut_sampler + di)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 301 | else |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 302 | descriptors_.emplace_back(new SamplerDescriptor()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 303 | } |
| 304 | break; |
| 305 | } |
| 306 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 307 | auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i); |
| 308 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) { |
| 309 | if (immut) |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 310 | descriptors_.emplace_back(new ImageSamplerDescriptor(immut + di)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 311 | else |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 312 | descriptors_.emplace_back(new ImageSamplerDescriptor()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 313 | } |
| 314 | break; |
| 315 | } |
| 316 | // ImageDescriptors |
| 317 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 318 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 319 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 320 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 321 | descriptors_.emplace_back(new ImageDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 322 | break; |
| 323 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 324 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 325 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 326 | descriptors_.emplace_back(new TexelDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 327 | break; |
| 328 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 329 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 330 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 331 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 332 | for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) |
Chris Forbes | cb621ea | 2016-05-30 11:47:31 +1200 | [diff] [blame] | 333 | descriptors_.emplace_back(new BufferDescriptor(type)); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 334 | break; |
| 335 | default: |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 336 | assert(0); // Bad descriptor type specified |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 337 | break; |
| 338 | } |
| 339 | } |
| 340 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 341 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 342 | cvdescriptorset::DescriptorSet::~DescriptorSet() { |
| 343 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 344 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 345 | |
| 346 | |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 347 | static std::string string_descriptor_req_view_type(descriptor_req req) { |
| 348 | std::string result(""); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 349 | for (unsigned i = 0; i <= VK_IMAGE_VIEW_TYPE_END_RANGE; i++) { |
| 350 | if (req & (1 << i)) { |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 351 | if (result.size()) result += ", "; |
| 352 | result += string_VkImageViewType(VkImageViewType(i)); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Chris Forbes | 6e58ebd | 2016-08-31 12:58:14 -0700 | [diff] [blame] | 356 | if (!result.size()) |
| 357 | result = "(none)"; |
| 358 | |
| 359 | return result; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 363 | // Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec? |
| 364 | bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const { |
| 365 | return layout->IsCompatible(p_layout_, error); |
| 366 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 367 | |
Tobin Ehlis | 3066db6 | 2016-08-22 08:12:23 -0600 | [diff] [blame] | 368 | // Validate that the state of this set is appropriate for the given bindings and dynamic_offsets at Draw time |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 369 | // This includes validating that all descriptors in the given bindings are updated, |
| 370 | // that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers. |
| 371 | // Return true if state is acceptable, or false and write an error message into error string |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 372 | bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t, descriptor_req> &bindings, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 373 | const std::vector<uint32_t> &dynamic_offsets, std::string *error) const { |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 374 | for (auto binding_pair : bindings) { |
| 375 | auto binding = binding_pair.first; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 376 | if (!p_layout_->HasBinding(binding)) { |
| 377 | std::stringstream error_str; |
| 378 | error_str << "Attempting to validate DrawState for binding #" << binding |
| 379 | << " which is an invalid binding for this descriptor set."; |
| 380 | *error = error_str.str(); |
| 381 | return false; |
| 382 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 383 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 384 | if (descriptors_[start_idx]->IsImmutableSampler()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 385 | // Nothing to do for strictly immutable sampler |
| 386 | } else { |
| 387 | auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding); |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 388 | auto array_idx = 0; // Track array idx if we're dealing with array descriptors |
| 389 | for (uint32_t i = start_idx; i <= end_idx; ++i, ++array_idx) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 390 | if (!descriptors_[i]->updated) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 391 | std::stringstream error_str; |
| 392 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 393 | << " is being used in draw but has not been updated."; |
| 394 | *error = error_str.str(); |
| 395 | return false; |
| 396 | } else { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 397 | auto descriptor_class = descriptors_[i]->GetClass(); |
| 398 | if (descriptor_class == GeneralBuffer) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 399 | // Verify that buffers are valid |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 400 | auto buffer = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetBuffer(); |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 401 | auto buffer_node = getBufferState(device_data_, buffer); |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 402 | if (!buffer_node) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 403 | std::stringstream error_str; |
| 404 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 405 | << " references invalid buffer " << buffer << "."; |
| 406 | *error = error_str.str(); |
| 407 | return false; |
| 408 | } else { |
Tobin Ehlis | 640a81c | 2016-11-15 15:37:18 -0700 | [diff] [blame] | 409 | for (auto mem_binding : buffer_node->GetBoundMemory()) { |
| 410 | if (!getMemObjInfo(device_data_, mem_binding)) { |
| 411 | std::stringstream error_str; |
| 412 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 413 | << " uses buffer " << buffer << " that references invalid memory " << mem_binding |
| 414 | << "."; |
| 415 | *error = error_str.str(); |
| 416 | return false; |
| 417 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 418 | } |
| 419 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 420 | if (descriptors_[i]->IsDynamic()) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 421 | // Validate that dynamic offsets are within the buffer |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 422 | auto buffer_size = buffer_node->createInfo.size; |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 423 | auto range = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetRange(); |
| 424 | auto desc_offset = static_cast<BufferDescriptor *>(descriptors_[i].get())->GetOffset(); |
Tobin Ehlis | a3525e0 | 2016-11-17 10:50:52 -0700 | [diff] [blame] | 425 | auto dyn_offset = dynamic_offsets[GetDynamicOffsetIndexFromBinding(binding) + array_idx]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 426 | if (VK_WHOLE_SIZE == range) { |
| 427 | if ((dyn_offset + desc_offset) > buffer_size) { |
| 428 | std::stringstream error_str; |
| 429 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 430 | << " uses buffer " << buffer |
| 431 | << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset |
| 432 | << " combined with offset " << desc_offset << " that oversteps the buffer size of " |
| 433 | << buffer_size << "."; |
| 434 | *error = error_str.str(); |
| 435 | return false; |
| 436 | } |
| 437 | } else { |
| 438 | if ((dyn_offset + desc_offset + range) > buffer_size) { |
| 439 | std::stringstream error_str; |
| 440 | error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i |
| 441 | << " uses buffer " << buffer << " with dynamic offset " << dyn_offset |
| 442 | << " combined with offset " << desc_offset << " and range " << range |
| 443 | << " that oversteps the buffer size of " << buffer_size << "."; |
| 444 | *error = error_str.str(); |
| 445 | return false; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 450 | else if (descriptor_class == ImageSampler || descriptor_class == Image) { |
| 451 | auto image_view = (descriptor_class == ImageSampler) |
| 452 | ? static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetImageView() |
| 453 | : static_cast<ImageDescriptor *>(descriptors_[i].get())->GetImageView(); |
| 454 | auto reqs = binding_pair.second; |
| 455 | |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 456 | auto image_view_state = getImageViewState(device_data_, image_view); |
| 457 | assert(image_view_state); |
| 458 | auto image_view_ci = image_view_state->create_info; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 459 | |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 460 | if ((reqs & DESCRIPTOR_REQ_ALL_VIEW_TYPE_BITS) && (~reqs & (1 << image_view_ci.viewType))) { |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 461 | // bad view type |
| 462 | std::stringstream error_str; |
| 463 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 464 | << " requires an image view of type " << string_descriptor_req_view_type(reqs) |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 465 | << " but got " << string_VkImageViewType(image_view_ci.viewType) << "."; |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 466 | *error = error_str.str(); |
| 467 | return false; |
| 468 | } |
| 469 | |
Tobin Ehlis | 30df15c | 2016-10-12 17:17:57 -0600 | [diff] [blame] | 470 | auto image_node = getImageState(device_data_, image_view_ci.image); |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 471 | assert(image_node); |
| 472 | |
| 473 | if ((reqs & DESCRIPTOR_REQ_SINGLE_SAMPLE) && |
| 474 | image_node->createInfo.samples != VK_SAMPLE_COUNT_1_BIT) { |
| 475 | std::stringstream error_str; |
| 476 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 477 | << " requires bound image to have VK_SAMPLE_COUNT_1_BIT but got " |
| 478 | << string_VkSampleCountFlagBits(image_node->createInfo.samples) << "."; |
| 479 | *error = error_str.str(); |
| 480 | return false; |
| 481 | } |
| 482 | |
| 483 | if ((reqs & DESCRIPTOR_REQ_MULTI_SAMPLE) && |
| 484 | image_node->createInfo.samples == VK_SAMPLE_COUNT_1_BIT) { |
| 485 | std::stringstream error_str; |
| 486 | error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i |
| 487 | << " requires bound image to have multiple samples, but got VK_SAMPLE_COUNT_1_BIT."; |
| 488 | *error = error_str.str(); |
| 489 | return false; |
| 490 | } |
| 491 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | return true; |
| 497 | } |
Chris Forbes | 5798913 | 2016-07-26 17:06:10 +1200 | [diff] [blame] | 498 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 499 | // For given bindings, place any update buffers or images into the passed-in unordered_sets |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 500 | uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::map<uint32_t, descriptor_req> &bindings, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 501 | std::unordered_set<VkBuffer> *buffer_set, |
| 502 | std::unordered_set<VkImageView> *image_set) const { |
| 503 | auto num_updates = 0; |
Chris Forbes | c7090a8 | 2016-07-25 18:10:41 +1200 | [diff] [blame] | 504 | for (auto binding_pair : bindings) { |
| 505 | auto binding = binding_pair.first; |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 506 | // If a binding doesn't exist, skip it |
| 507 | if (!p_layout_->HasBinding(binding)) { |
| 508 | continue; |
| 509 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 510 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 511 | if (descriptors_[start_idx]->IsStorage()) { |
| 512 | if (Image == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 513 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 514 | if (descriptors_[start_idx + i]->updated) { |
| 515 | image_set->insert(static_cast<ImageDescriptor *>(descriptors_[start_idx + i].get())->GetImageView()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 516 | num_updates++; |
| 517 | } |
| 518 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 519 | } else if (TexelBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 520 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 521 | if (descriptors_[start_idx + i]->updated) { |
| 522 | auto bufferview = static_cast<TexelDescriptor *>(descriptors_[start_idx + i].get())->GetBufferView(); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 523 | auto bv_state = getBufferViewState(device_data_, bufferview); |
| 524 | if (bv_state) { |
| 525 | buffer_set->insert(bv_state->create_info.buffer); |
Tobin Ehlis | 0bc3063 | 2016-05-05 10:16:02 -0600 | [diff] [blame] | 526 | num_updates++; |
| 527 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 528 | } |
| 529 | } |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 530 | } else if (GeneralBuffer == descriptors_[start_idx]->descriptor_class) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 531 | for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) { |
Tobin Ehlis | 81f1785 | 2016-05-05 09:04:33 -0600 | [diff] [blame] | 532 | if (descriptors_[start_idx + i]->updated) { |
| 533 | buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_[start_idx + i].get())->GetBuffer()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 534 | num_updates++; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | return num_updates; |
| 541 | } |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 542 | // Set is being deleted or updates so invalidate all bound cmd buffers |
| 543 | void cvdescriptorset::DescriptorSet::InvalidateBoundCmdBuffers() { |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 544 | core_validation::invalidateCommandBuffers(cb_bindings, |
| 545 | {reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT}); |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 546 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 547 | // Perform write update in given update struct |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 548 | void cvdescriptorset::DescriptorSet::PerformWriteUpdate(const VkWriteDescriptorSet *update) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 549 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 550 | // perform update |
| 551 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 552 | descriptors_[start_idx + di]->WriteUpdate(update, di); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 553 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 554 | if (update->descriptorCount) |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 555 | some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 556 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 557 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 558 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 559 | // Validate Copy update |
| 560 | bool cvdescriptorset::DescriptorSet::ValidateCopyUpdate(const debug_report_data *report_data, const VkCopyDescriptorSet *update, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 561 | const DescriptorSet *src_set, UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 562 | std::string *error_msg) { |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 563 | // Verify idle ds |
| 564 | if (in_use.load()) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 565 | // TODO : Re-using Allocate Idle error code, need copy update idle error code |
| 566 | *error_code = VALIDATION_ERROR_00919; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 567 | std::stringstream error_str; |
| 568 | error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_ |
| 569 | << " that is in use by a command buffer."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 570 | *error_msg = error_str.str(); |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 571 | return false; |
| 572 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 573 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 574 | *error_code = VALIDATION_ERROR_00966; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 575 | std::stringstream error_str; |
| 576 | error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 577 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 578 | return false; |
| 579 | } |
| 580 | if (!src_set->HasBinding(update->srcBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 581 | *error_code = VALIDATION_ERROR_00964; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 582 | std::stringstream error_str; |
| 583 | error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 584 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 585 | return false; |
| 586 | } |
| 587 | // src & dst set bindings are valid |
| 588 | // Check bounds of src & dst |
| 589 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 590 | if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) { |
| 591 | // SRC update out of bounds |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 592 | *error_code = VALIDATION_ERROR_00965; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 593 | std::stringstream error_str; |
| 594 | error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding |
| 595 | << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding) |
| 596 | << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount |
| 597 | << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 598 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 602 | if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
| 603 | // DST update out of bounds |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 604 | *error_code = VALIDATION_ERROR_00967; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 605 | std::stringstream error_str; |
| 606 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding |
| 607 | << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) |
| 608 | << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount |
| 609 | << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 610 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 611 | return false; |
| 612 | } |
| 613 | // Check that types match |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 614 | // TODO : Base default error case going from here is VALIDATION_ERROR_00968 which covers all consistency issues, need more |
| 615 | // fine-grained error codes |
| 616 | *error_code = VALIDATION_ERROR_00968; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 617 | auto src_type = src_set->GetTypeFromBinding(update->srcBinding); |
| 618 | auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 619 | if (src_type != dst_type) { |
| 620 | std::stringstream error_str; |
| 621 | error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type " |
| 622 | << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #" |
| 623 | << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 624 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 625 | return false; |
| 626 | } |
| 627 | // Verify consistency of src & dst bindings if update crosses binding boundaries |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 628 | if ((!src_set->GetLayout()->VerifyUpdateConsistency(update->srcBinding, update->srcArrayElement, update->descriptorCount, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 629 | "copy update from", src_set->GetSet(), error_msg)) || |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 630 | (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "copy update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 631 | set_, error_msg))) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 632 | return false; |
| 633 | } |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 634 | // First make sure source descriptors are updated |
| 635 | for (uint32_t i = 0; i < update->descriptorCount; ++i) { |
| 636 | if (!src_set->descriptors_[src_start_idx + i]) { |
| 637 | std::stringstream error_str; |
| 638 | error_str << "Attempting copy update from descriptorSet " << src_set << " binding #" << update->srcBinding << " but descriptor at array offset " |
| 639 | << update->srcArrayElement + i << " has not been updated."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 640 | *error_msg = error_str.str(); |
Tobin Ehlis | d41e7b6 | 2016-05-19 07:56:18 -0600 | [diff] [blame] | 641 | return false; |
| 642 | } |
| 643 | } |
| 644 | // Update parameters all look good and descriptor updated so verify update contents |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 645 | if (!VerifyCopyUpdateContents(update, src_set, src_type, src_start_idx, error_code, error_msg)) |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 646 | return false; |
| 647 | |
| 648 | // All checks passed so update is good |
| 649 | return true; |
| 650 | } |
| 651 | // Perform Copy update |
| 652 | void cvdescriptorset::DescriptorSet::PerformCopyUpdate(const VkCopyDescriptorSet *update, const DescriptorSet *src_set) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 653 | auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement; |
| 654 | auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 655 | // Update parameters all look good so perform update |
| 656 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 657 | descriptors_[dst_start_idx + di]->CopyUpdate(src_set->descriptors_[src_start_idx + di].get()); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 658 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 659 | if (update->descriptorCount) |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 660 | some_update_ = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 661 | |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 662 | InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 663 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 664 | |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 665 | // Bind cb_node to this set and this set to cb_node. |
| 666 | // Prereq: This should be called for a set that has been confirmed to be active for the given cb_node, meaning it's going |
| 667 | // to be used in a draw by the given cb_node |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 668 | void cvdescriptorset::DescriptorSet::BindCommandBuffer(GLOBAL_CB_NODE *cb_node, const std::unordered_set<uint32_t> &bindings) { |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 669 | // bind cb to this descriptor set |
| 670 | cb_bindings.insert(cb_node); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 671 | // Add bindings for descriptor set, the set's pool, and individual objects in the set |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 672 | cb_node->object_bindings.insert({reinterpret_cast<uint64_t &>(set_), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT}); |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 673 | pool_state_->cb_bindings.insert(cb_node); |
| 674 | cb_node->object_bindings.insert( |
| 675 | {reinterpret_cast<uint64_t &>(pool_state_->pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT}); |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 676 | // For the active slots, use set# to look up descriptorSet from boundDescriptorSets, and bind all of that descriptor set's |
| 677 | // resources |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 678 | for (auto binding : bindings) { |
| 679 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding); |
| 680 | auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding); |
| 681 | for (uint32_t i = start_idx; i <= end_idx; ++i) { |
| 682 | descriptors_[i]->BindCommandBuffer(device_data_, cb_node); |
| 683 | } |
| 684 | } |
Tobin Ehlis | 9252c2b | 2016-07-21 14:40:22 -0600 | [diff] [blame] | 685 | } |
| 686 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 687 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor() : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 688 | updated = false; |
| 689 | descriptor_class = PlainSampler; |
| 690 | }; |
| 691 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 692 | cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : sampler_(VK_NULL_HANDLE), immutable_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 693 | updated = false; |
| 694 | descriptor_class = PlainSampler; |
| 695 | if (immut) { |
| 696 | sampler_ = *immut; |
| 697 | immutable_ = true; |
| 698 | updated = true; |
| 699 | } |
| 700 | } |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 701 | // Validate given sampler. Currently this only checks to make sure it exists in the samplerMap |
| 702 | bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) { |
Tobin Ehlis | fad7adf | 2016-10-20 06:50:37 -0600 | [diff] [blame] | 703 | return (getSamplerState(dev_data, sampler) != nullptr); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 704 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 705 | |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 706 | bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 707 | const core_validation::layer_data *dev_data, UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 708 | std::string *error_msg) { |
| 709 | // TODO : Defaulting to 00943 for all cases here. Need to create new error codes for various cases. |
| 710 | *error_code = VALIDATION_ERROR_00943; |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 711 | auto iv_state = getImageViewState(dev_data, image_view); |
| 712 | if (!iv_state) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 713 | std::stringstream error_str; |
| 714 | error_str << "Invalid VkImageView: " << image_view; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 715 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 716 | return false; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 717 | } |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 718 | // Note that when an imageview is created, we validated that memory is bound so no need to re-check here |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 719 | // Validate that imageLayout is compatible with aspect_mask and image format |
| 720 | // and validate that image usage bits are correct for given usage |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 721 | VkImageAspectFlags aspect_mask = iv_state->create_info.subresourceRange.aspectMask; |
| 722 | VkImage image = iv_state->create_info.image; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 723 | VkFormat format = VK_FORMAT_MAX_ENUM; |
| 724 | VkImageUsageFlags usage = 0; |
Tobin Ehlis | 30df15c | 2016-10-12 17:17:57 -0600 | [diff] [blame] | 725 | auto image_node = getImageState(dev_data, image); |
Tobin Ehlis | 1c9c55f | 2016-06-02 11:49:22 -0600 | [diff] [blame] | 726 | if (image_node) { |
| 727 | format = image_node->createInfo.format; |
| 728 | usage = image_node->createInfo.usage; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 729 | // Validate that memory is bound to image |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 730 | if (ValidateMemoryIsBoundToImage(dev_data, image_node, "vkUpdateDescriptorSets()")) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 731 | // TODO : Need new code(s) for language in 11.6 Memory Association |
| 732 | *error_msg = "No memory bound to image."; |
Tobin Ehlis | 029d2fe | 2016-09-21 09:19:15 -0600 | [diff] [blame] | 733 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 734 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 735 | } else { |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 736 | // Also need to check the swapchains. |
Tobin Ehlis | 969a526 | 2016-06-02 12:13:32 -0600 | [diff] [blame] | 737 | auto swapchain = getSwapchainFromImage(dev_data, image); |
| 738 | if (swapchain) { |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 739 | auto swapchain_node = getSwapchainNode(dev_data, swapchain); |
| 740 | if (swapchain_node) { |
| 741 | format = swapchain_node->createInfo.imageFormat; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 742 | } |
| 743 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 744 | } |
| 745 | // First validate that format and layout are compatible |
| 746 | if (format == VK_FORMAT_MAX_ENUM) { |
| 747 | std::stringstream error_str; |
| 748 | error_str << "Invalid image (" << image << ") in imageView (" << image_view << ")."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 749 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 750 | return false; |
| 751 | } |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 752 | // TODO : The various image aspect and format checks here are based on general spec language in 11.5 Image Views section under |
| 753 | // vkCreateImageView(). What's the best way to create unique id for these cases? |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 754 | bool ds = vk_format_is_depth_or_stencil(format); |
| 755 | switch (image_layout) { |
| 756 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
| 757 | // Only Color bit must be set |
| 758 | if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 759 | std::stringstream error_str; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 760 | error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does " |
| 761 | "not have VK_IMAGE_ASPECT_COLOR_BIT set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 762 | *error_msg = error_str.str(); |
Tobin Ehlis | 554bf38 | 2016-05-24 11:14:43 -0600 | [diff] [blame] | 763 | return false; |
| 764 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 765 | // format must NOT be DS |
| 766 | if (ds) { |
| 767 | std::stringstream error_str; |
| 768 | error_str << "ImageView (" << image_view |
| 769 | << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is " |
| 770 | << string_VkFormat(format) << " which is not a color format."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 771 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 772 | return false; |
| 773 | } |
| 774 | break; |
| 775 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
| 776 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
| 777 | // Depth or stencil bit must be set, but both must NOT be set |
| 778 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 779 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 780 | // both must NOT be set |
| 781 | std::stringstream error_str; |
| 782 | error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 783 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 784 | return false; |
| 785 | } |
| 786 | } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 787 | // Neither were set |
| 788 | std::stringstream error_str; |
| 789 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 790 | << " but does not have STENCIL or DEPTH aspects set"; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 791 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 792 | return false; |
| 793 | } |
| 794 | // format must be DS |
| 795 | if (!ds) { |
| 796 | std::stringstream error_str; |
| 797 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 798 | << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 799 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 800 | return false; |
| 801 | } |
| 802 | break; |
| 803 | default: |
Mike Weiblen | cce7ec7 | 2016-10-17 19:33:05 -0600 | [diff] [blame] | 804 | // For other layouts if the source is depth/stencil image, both aspect bits must not be set |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 805 | if (ds) { |
| 806 | if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) { |
| 807 | if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 808 | // both must NOT be set |
| 809 | std::stringstream error_str; |
| 810 | error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout) |
| 811 | << " and is using depth/stencil image of format " << string_VkFormat(format) |
| 812 | << " but it has both STENCIL and DEPTH aspects set, which is illegal. When using a depth/stencil " |
| 813 | "image in a descriptor set, please only set either VK_IMAGE_ASPECT_DEPTH_BIT or " |
| 814 | "VK_IMAGE_ASPECT_STENCIL_BIT depending on whether it will be used for depth reads or stencil " |
| 815 | "reads respectively."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 816 | *error_msg = error_str.str(); |
Tobin Ehlis | bbf3f91 | 2016-06-15 13:03:58 -0600 | [diff] [blame] | 817 | return false; |
| 818 | } |
| 819 | } |
| 820 | } |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 821 | break; |
| 822 | } |
| 823 | // Now validate that usage flags are correctly set for given type of update |
Tobin Ehlis | fb4cf71 | 2016-10-10 14:02:48 -0600 | [diff] [blame] | 824 | // As we're switching per-type, if any type has specific layout requirements, check those here as well |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 825 | // TODO : The various image usage bit requirements are in general spec language for VkImageUsageFlags bit block in 11.3 Images |
| 826 | // under vkCreateImage() |
| 827 | // TODO : Need to also validate case VALIDATION_ERROR_00952 where STORAGE_IMAGE & INPUT_ATTACH types must have been created with |
| 828 | // identify swizzle |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 829 | std::string error_usage_bit; |
| 830 | switch (type) { |
| 831 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 832 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 833 | if (!(usage & VK_IMAGE_USAGE_SAMPLED_BIT)) { |
| 834 | error_usage_bit = "VK_IMAGE_USAGE_SAMPLED_BIT"; |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 839 | if (!(usage & VK_IMAGE_USAGE_STORAGE_BIT)) { |
| 840 | error_usage_bit = "VK_IMAGE_USAGE_STORAGE_BIT"; |
Tobin Ehlis | fb4cf71 | 2016-10-10 14:02:48 -0600 | [diff] [blame] | 841 | } else if (VK_IMAGE_LAYOUT_GENERAL != image_layout) { |
| 842 | std::stringstream error_str; |
| 843 | // TODO : Need to create custom enum error code for this case |
| 844 | error_str << "ImageView (" << image_view << ") of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout " |
| 845 | << string_VkImageLayout(image_layout) |
| 846 | << " but according to spec section 13.1 Descriptor Types, 'Load and store operations on storage images can " |
| 847 | "only be done on images in VK_IMAGE_LAYOUT_GENERAL layout.'"; |
| 848 | *error_msg = error_str.str(); |
| 849 | return false; |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 850 | } |
| 851 | break; |
| 852 | } |
| 853 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: { |
| 854 | if (!(usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) { |
| 855 | error_usage_bit = "VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT"; |
| 856 | } |
| 857 | break; |
| 858 | } |
| 859 | default: |
| 860 | break; |
| 861 | } |
| 862 | if (!error_usage_bit.empty()) { |
| 863 | std::stringstream error_str; |
| 864 | error_str << "ImageView (" << image_view << ") with usage mask 0x" << usage |
| 865 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 866 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 867 | *error_msg = error_str.str(); |
Tobin Ehlis | 1809f91 | 2016-05-25 09:24:36 -0600 | [diff] [blame] | 868 | return false; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 869 | } |
| 870 | return true; |
| 871 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 872 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 873 | void cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
| 874 | sampler_ = update->pImageInfo[index].sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 875 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 876 | } |
| 877 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 878 | void cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 879 | if (!immutable_) { |
| 880 | auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 881 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 882 | } |
| 883 | updated = true; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 884 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 885 | |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 886 | void cvdescriptorset::SamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
| 887 | if (!immutable_) { |
Tobin Ehlis | fad7adf | 2016-10-20 06:50:37 -0600 | [diff] [blame] | 888 | auto sampler_state = getSamplerState(dev_data, sampler_); |
| 889 | if (sampler_state) |
| 890 | core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 894 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor() |
| 895 | : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 896 | updated = false; |
| 897 | descriptor_class = ImageSampler; |
| 898 | } |
| 899 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 900 | cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(const VkSampler *immut) |
| 901 | : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 902 | updated = false; |
| 903 | descriptor_class = ImageSampler; |
| 904 | if (immut) { |
| 905 | sampler_ = *immut; |
| 906 | immutable_ = true; |
| 907 | updated = true; |
| 908 | } |
| 909 | } |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 910 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 911 | void cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 912 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 913 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 914 | sampler_ = image_info.sampler; |
| 915 | image_view_ = image_info.imageView; |
| 916 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 917 | } |
| 918 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 919 | void cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 920 | if (!immutable_) { |
| 921 | auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 922 | sampler_ = update_sampler; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 923 | } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 924 | auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_; |
| 925 | auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 926 | updated = true; |
| 927 | image_view_ = image_view; |
| 928 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 929 | } |
| 930 | |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 931 | void cvdescriptorset::ImageSamplerDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, |
| 932 | GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 933 | // First add binding for any non-immutable sampler |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 934 | if (!immutable_) { |
Tobin Ehlis | fad7adf | 2016-10-20 06:50:37 -0600 | [diff] [blame] | 935 | auto sampler_state = getSamplerState(dev_data, sampler_); |
| 936 | if (sampler_state) |
| 937 | core_validation::AddCommandBufferBindingSampler(cb_node, sampler_state); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 938 | } |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 939 | // Add binding for image |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 940 | auto iv_state = getImageViewState(dev_data, image_view_); |
| 941 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 942 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 943 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 944 | } |
| 945 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 946 | cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type) |
| 947 | : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 948 | updated = false; |
| 949 | descriptor_class = Image; |
| 950 | if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type) |
| 951 | storage_ = true; |
| 952 | }; |
| 953 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 954 | void cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 955 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 956 | const auto &image_info = update->pImageInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 957 | image_view_ = image_info.imageView; |
| 958 | image_layout_ = image_info.imageLayout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 959 | } |
| 960 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 961 | void cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 962 | auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_; |
| 963 | auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 964 | updated = true; |
| 965 | image_view_ = image_view; |
| 966 | image_layout_ = image_layout; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 967 | } |
| 968 | |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 969 | void cvdescriptorset::ImageDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 970 | // Add binding for image |
Tobin Ehlis | 8b26a38 | 2016-09-14 08:02:49 -0600 | [diff] [blame] | 971 | auto iv_state = getImageViewState(dev_data, image_view_); |
| 972 | if (iv_state) { |
Tobin Ehlis | 15b8ea0 | 2016-09-19 14:02:58 -0600 | [diff] [blame] | 973 | core_validation::AddCommandBufferBindingImageView(dev_data, cb_node, iv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 974 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 975 | } |
| 976 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 977 | cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type) |
| 978 | : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 979 | updated = false; |
| 980 | descriptor_class = GeneralBuffer; |
| 981 | if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) { |
| 982 | dynamic_ = true; |
| 983 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) { |
| 984 | storage_ = true; |
| 985 | } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) { |
| 986 | dynamic_ = true; |
| 987 | storage_ = true; |
| 988 | } |
| 989 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 990 | void cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 991 | updated = true; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 992 | const auto &buffer_info = update->pBufferInfo[index]; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 993 | buffer_ = buffer_info.buffer; |
| 994 | offset_ = buffer_info.offset; |
| 995 | range_ = buffer_info.range; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 996 | } |
| 997 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 998 | void cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src) { |
| 999 | auto buff_desc = static_cast<const BufferDescriptor *>(src); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1000 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1001 | buffer_ = buff_desc->buffer_; |
| 1002 | offset_ = buff_desc->offset_; |
| 1003 | range_ = buff_desc->range_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1004 | } |
| 1005 | |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1006 | void cvdescriptorset::BufferDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1007 | auto buffer_node = getBufferState(dev_data, buffer_); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1008 | if (buffer_node) |
| 1009 | core_validation::AddCommandBufferBindingBuffer(dev_data, cb_node, buffer_node); |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1010 | } |
| 1011 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1012 | cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type) : buffer_view_(VK_NULL_HANDLE), storage_(false) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1013 | updated = false; |
| 1014 | descriptor_class = TexelBuffer; |
| 1015 | if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type) |
| 1016 | storage_ = true; |
| 1017 | }; |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1018 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1019 | void cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index) { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1020 | updated = true; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1021 | buffer_view_ = update->pTexelBufferView[index]; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1022 | } |
| 1023 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1024 | void cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src) { |
| 1025 | updated = true; |
| 1026 | buffer_view_ = static_cast<const TexelDescriptor *>(src)->buffer_view_; |
| 1027 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1028 | |
| 1029 | void cvdescriptorset::TexelDescriptor::BindCommandBuffer(const core_validation::layer_data *dev_data, GLOBAL_CB_NODE *cb_node) { |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1030 | auto bv_state = getBufferViewState(dev_data, buffer_view_); |
| 1031 | if (bv_state) { |
Tobin Ehlis | 2515c0e | 2016-09-28 07:12:28 -0600 | [diff] [blame] | 1032 | core_validation::AddCommandBufferBindingBufferView(dev_data, cb_node, bv_state); |
Tobin Ehlis | 81e4637 | 2016-08-17 13:33:44 -0600 | [diff] [blame] | 1033 | } |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 1034 | } |
| 1035 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1036 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1037 | // sets, and then calls their respective Validate[Write|Copy]Update functions. |
| 1038 | // If the update hits an issue for which the callback returns "true", meaning that the call down the chain should |
| 1039 | // be skipped, then true is returned. |
| 1040 | // If there is no issue with the update, then false is returned. |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1041 | bool cvdescriptorset::ValidateUpdateDescriptorSets(const debug_report_data *report_data, |
| 1042 | const core_validation::layer_data *dev_data, uint32_t write_count, |
| 1043 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 1044 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1045 | bool skip_call = false; |
| 1046 | // Validate Write updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1047 | for (uint32_t i = 0; i < write_count; i++) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1048 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1049 | auto set_node = core_validation::getSetNode(dev_data, dest_set); |
| 1050 | if (!set_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1051 | skip_call |= |
| 1052 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1053 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, DRAWSTATE_INVALID_DESCRIPTOR_SET, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1054 | "Cannot call vkUpdateDescriptorSets() on descriptor set 0x%" PRIxLEAST64 " that has not been allocated.", |
| 1055 | reinterpret_cast<uint64_t &>(dest_set)); |
| 1056 | } else { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1057 | UNIQUE_VALIDATION_ERROR_CODE error_code; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1058 | std::string error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1059 | if (!set_node->ValidateWriteUpdate(report_data, &p_wds[i], &error_code, &error_str)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1060 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1061 | reinterpret_cast<uint64_t &>(dest_set), __LINE__, error_code, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1062 | "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x%" PRIx64 |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1063 | " with error: %s. %s", |
| 1064 | reinterpret_cast<uint64_t &>(dest_set), error_str.c_str(), validation_error_map[error_code]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | // Now validate copy updates |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 1069 | for (uint32_t i = 0; i < copy_count; ++i) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1070 | auto dst_set = p_cds[i].dstSet; |
| 1071 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1072 | auto src_node = core_validation::getSetNode(dev_data, src_set); |
| 1073 | auto dst_node = core_validation::getSetNode(dev_data, dst_set); |
| 1074 | if (!src_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1075 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1076 | reinterpret_cast<uint64_t &>(src_set), __LINE__, VALIDATION_ERROR_00971, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1077 | "Cannot call vkUpdateDescriptorSets() to copy from descriptor set 0x%" PRIxLEAST64 |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1078 | " that has not been allocated. %s", |
| 1079 | reinterpret_cast<uint64_t &>(src_set), validation_error_map[VALIDATION_ERROR_00971]); |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1080 | } else if (!dst_node) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1081 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1082 | reinterpret_cast<uint64_t &>(dst_set), __LINE__, VALIDATION_ERROR_00972, "DS", |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1083 | "Cannot call vkUpdateDescriptorSets() to copy to descriptor set 0x%" PRIxLEAST64 |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1084 | " that has not been allocated. %s", |
| 1085 | reinterpret_cast<uint64_t &>(dst_set), validation_error_map[VALIDATION_ERROR_00972]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1086 | } else { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1087 | UNIQUE_VALIDATION_ERROR_CODE error_code; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1088 | std::string error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1089 | if (!dst_node->ValidateCopyUpdate(report_data, &p_cds[i], src_node, &error_code, &error_str)) { |
| 1090 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, |
| 1091 | reinterpret_cast<uint64_t &>(dst_set), __LINE__, error_code, "DS", |
| 1092 | "vkUpdateDescriptorsSets() failed copy update from Descriptor Set 0x%" PRIx64 |
| 1093 | " to Descriptor Set 0x%" PRIx64 " with error: %s. %s", |
| 1094 | reinterpret_cast<uint64_t &>(src_set), reinterpret_cast<uint64_t &>(dst_set), |
| 1095 | error_str.c_str(), validation_error_map[error_code]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | return skip_call; |
| 1100 | } |
| 1101 | // This is a helper function that iterates over a set of Write and Copy updates, pulls the DescriptorSet* for updated |
| 1102 | // sets, and then calls their respective Perform[Write|Copy]Update functions. |
| 1103 | // Prerequisite : ValidateUpdateDescriptorSets() should be called and return "false" prior to calling PerformUpdateDescriptorSets() |
| 1104 | // with the same set of updates. |
| 1105 | // This is split from the validate code to allow validation prior to calling down the chain, and then update after |
| 1106 | // calling down the chain. |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1107 | void cvdescriptorset::PerformUpdateDescriptorSets(const core_validation::layer_data *dev_data, uint32_t write_count, |
| 1108 | const VkWriteDescriptorSet *p_wds, uint32_t copy_count, |
| 1109 | const VkCopyDescriptorSet *p_cds) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1110 | // Write updates first |
| 1111 | uint32_t i = 0; |
| 1112 | for (i = 0; i < write_count; ++i) { |
| 1113 | auto dest_set = p_wds[i].dstSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1114 | auto set_node = core_validation::getSetNode(dev_data, dest_set); |
| 1115 | if (set_node) { |
| 1116 | set_node->PerformWriteUpdate(&p_wds[i]); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | // Now copy updates |
| 1120 | for (i = 0; i < copy_count; ++i) { |
| 1121 | auto dst_set = p_cds[i].dstSet; |
| 1122 | auto src_set = p_cds[i].srcSet; |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 1123 | auto src_node = core_validation::getSetNode(dev_data, src_set); |
| 1124 | auto dst_node = core_validation::getSetNode(dev_data, dst_set); |
| 1125 | if (src_node && dst_node) { |
| 1126 | dst_node->PerformCopyUpdate(&p_cds[i], src_node); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | // Validate the state for a given write update but don't actually perform the update |
| 1131 | // If an error would occur for this update, return false and fill in details in error_msg string |
| 1132 | bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data *report_data, const VkWriteDescriptorSet *update, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1133 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1134 | // Verify idle ds |
| 1135 | if (in_use.load()) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1136 | // TODO : Re-using Allocate Idle error code, need write update idle error code |
| 1137 | *error_code = VALIDATION_ERROR_00919; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1138 | std::stringstream error_str; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1139 | error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_ |
| 1140 | << " that is in use by a command buffer."; |
| 1141 | *error_msg = error_str.str(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1142 | return false; |
| 1143 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1144 | // Verify dst binding exists |
| 1145 | if (!p_layout_->HasBinding(update->dstBinding)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1146 | *error_code = VALIDATION_ERROR_00936; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1147 | std::stringstream error_str; |
| 1148 | error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << "."; |
| 1149 | *error_msg = error_str.str(); |
| 1150 | return false; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1151 | } |
| 1152 | // We know that binding is valid, verify update and do update on each descriptor |
| 1153 | auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement; |
| 1154 | auto type = p_layout_->GetTypeFromBinding(update->dstBinding); |
| 1155 | if (type != update->descriptorType) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1156 | *error_code = VALIDATION_ERROR_00937; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1157 | std::stringstream error_str; |
| 1158 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type " |
| 1159 | << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType); |
| 1160 | *error_msg = error_str.str(); |
| 1161 | return false; |
| 1162 | } |
| 1163 | if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1164 | *error_code = VALIDATION_ERROR_00938; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1165 | std::stringstream error_str; |
| 1166 | error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with " |
| 1167 | << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount |
| 1168 | << " descriptors starting at binding offset of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) |
| 1169 | << " combined with update array element offset of " << update->dstArrayElement |
| 1170 | << " oversteps the size of this descriptor set."; |
| 1171 | *error_msg = error_str.str(); |
| 1172 | return false; |
| 1173 | } |
| 1174 | // Verify consecutive bindings match (if needed) |
| 1175 | if (!p_layout_->VerifyUpdateConsistency(update->dstBinding, update->dstArrayElement, update->descriptorCount, "write update to", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1176 | set_, error_msg)) { |
| 1177 | *error_code = VALIDATION_ERROR_00938; |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1178 | return false; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1179 | } |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1180 | // Update is within bounds and consistent so last step is to validate update contents |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1181 | if (!VerifyWriteUpdateContents(update, start_idx, error_code, error_msg)) { |
Tobin Ehlis | 57ae28f | 2016-05-24 12:35:57 -0600 | [diff] [blame] | 1182 | std::stringstream error_str; |
| 1183 | error_str << "Write update to descriptor in set " << set_ << " binding #" << update->dstBinding |
| 1184 | << " failed with error message: " << error_msg->c_str(); |
| 1185 | *error_msg = error_str.str(); |
| 1186 | return false; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1187 | } |
| 1188 | // All checks passed, update is clean |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 1189 | return true; |
Tobin Ehlis | 03d61de | 2016-05-17 08:31:46 -0600 | [diff] [blame] | 1190 | } |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1191 | // For the given buffer, verify that its creation parameters are appropriate for the given type |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1192 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1193 | bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1194 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1195 | // Verify that usage bits set correctly for given type |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 1196 | auto usage = buffer_node->createInfo.usage; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1197 | std::string error_usage_bit; |
| 1198 | switch (type) { |
| 1199 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1200 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1201 | *error_code = VALIDATION_ERROR_00950; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1202 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; |
| 1203 | } |
| 1204 | break; |
| 1205 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1206 | if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1207 | *error_code = VALIDATION_ERROR_00951; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1208 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; |
| 1209 | } |
| 1210 | break; |
| 1211 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1212 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1213 | if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1214 | *error_code = VALIDATION_ERROR_00946; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1215 | error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; |
| 1216 | } |
| 1217 | break; |
| 1218 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1219 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1220 | if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1221 | *error_code = VALIDATION_ERROR_00947; |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1222 | error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; |
| 1223 | } |
| 1224 | break; |
| 1225 | default: |
| 1226 | break; |
| 1227 | } |
| 1228 | if (!error_usage_bit.empty()) { |
| 1229 | std::stringstream error_str; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1230 | error_str << "Buffer (" << buffer_node->buffer << ") with usage mask 0x" << usage |
| 1231 | << " being used for a descriptor update of type " << string_VkDescriptorType(type) << " does not have " |
| 1232 | << error_usage_bit << " set."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1233 | *error_msg = error_str.str(); |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1234 | return false; |
| 1235 | } |
| 1236 | return true; |
| 1237 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1238 | // For buffer descriptor updates, verify the buffer usage and VkDescriptorBufferInfo struct which includes: |
| 1239 | // 1. buffer is valid |
| 1240 | // 2. buffer was created with correct usage flags |
| 1241 | // 3. offset is less than buffer size |
| 1242 | // 4. range is either VK_WHOLE_SIZE or falls in (0, (buffer size - offset)] |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1243 | // If there's an error, update the error_msg string with details and return false, else return true |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1244 | bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkDescriptorBufferInfo const *buffer_info, VkDescriptorType type, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1245 | UNIQUE_VALIDATION_ERROR_CODE *error_code, std::string *error_msg) const { |
| 1246 | // TODO : Defaulting to 00962 for all cases here. Need to create new error codes for a few cases below. |
| 1247 | *error_code = VALIDATION_ERROR_00962; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1248 | // First make sure that buffer is valid |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1249 | auto buffer_node = getBufferState(device_data_, buffer_info->buffer); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1250 | if (!buffer_node) { |
| 1251 | std::stringstream error_str; |
| 1252 | error_str << "Invalid VkBuffer: " << buffer_info->buffer; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1253 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1254 | return false; |
| 1255 | } |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 1256 | if (ValidateMemoryIsBoundToBuffer(device_data_, buffer_node, "vkUpdateDescriptorSets()")) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1257 | // TODO : This is a repeat code, need new code(s) for language in 11.6 Memory Association |
| 1258 | *error_msg = "No memory bound to buffer."; |
Tobin Ehlis | 8128096 | 2016-07-20 14:04:20 -0600 | [diff] [blame] | 1259 | return false; |
Tobin Ehlis | fed999f | 2016-09-21 15:09:45 -0600 | [diff] [blame] | 1260 | } |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1261 | // Verify usage bits |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1262 | if (!ValidateBufferUsage(buffer_node, type, error_code, error_msg)) { |
| 1263 | // error_msg will have been updated by ValidateBufferUsage() |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1264 | return false; |
| 1265 | } |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1266 | // TODO : Need to also validate device limit offset requirements captured in VALIDATION_ERROR_00944,945 |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1267 | // offset must be less than buffer size |
| 1268 | if (buffer_info->offset > buffer_node->createInfo.size) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1269 | *error_code = VALIDATION_ERROR_00959; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1270 | std::stringstream error_str; |
| 1271 | error_str << "VkDescriptorBufferInfo offset of " << buffer_info->offset << " is greater than buffer " << buffer_node->buffer |
| 1272 | << " size of " << buffer_node->createInfo.size; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1273 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1274 | return false; |
| 1275 | } |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1276 | // TODO : Need to also validate device limit range requirements captured in VALIDATION_ERROR_00948,949 |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1277 | if (buffer_info->range != VK_WHOLE_SIZE) { |
| 1278 | // Range must be VK_WHOLE_SIZE or > 0 |
| 1279 | if (!buffer_info->range) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1280 | *error_code = VALIDATION_ERROR_00960; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1281 | std::stringstream error_str; |
| 1282 | error_str << "VkDescriptorBufferInfo range is not VK_WHOLE_SIZE and is zero, which is not allowed."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1283 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1284 | return false; |
| 1285 | } |
| 1286 | // Range must be VK_WHOLE_SIZE or <= (buffer size - offset) |
| 1287 | if (buffer_info->range > (buffer_node->createInfo.size - buffer_info->offset)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1288 | *error_code = VALIDATION_ERROR_00961; |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1289 | std::stringstream error_str; |
| 1290 | error_str << "VkDescriptorBufferInfo range is " << buffer_info->range << " which is greater than buffer size (" |
| 1291 | << buffer_node->createInfo.size << ") minus requested offset of " << buffer_info->offset; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1292 | *error_msg = error_str.str(); |
Tobin Ehlis | 3d38f08 | 2016-07-01 17:36:48 -0600 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | } |
| 1296 | return true; |
| 1297 | } |
| 1298 | |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1299 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1300 | bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1301 | UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 1302 | std::string *error_msg) const { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1303 | switch (update->descriptorType) { |
| 1304 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: { |
| 1305 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1306 | // Validate image |
| 1307 | auto image_view = update->pImageInfo[di].imageView; |
| 1308 | auto image_layout = update->pImageInfo[di].imageLayout; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1309 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1310 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1311 | error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error_msg->c_str(); |
| 1312 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
| 1315 | } |
| 1316 | // Intentional fall-through to validate sampler |
| 1317 | } |
| 1318 | case VK_DESCRIPTOR_TYPE_SAMPLER: { |
| 1319 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1320 | if (!descriptors_[index + di].get()->IsImmutableSampler()) { |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1321 | if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1322 | *error_code = VALIDATION_ERROR_00942; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1323 | std::stringstream error_str; |
| 1324 | error_str << "Attempted write update to sampler descriptor with invalid sampler: " |
| 1325 | << update->pImageInfo[di].sampler << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1326 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1327 | return false; |
| 1328 | } |
| 1329 | } else { |
| 1330 | // TODO : Warn here |
| 1331 | } |
| 1332 | } |
| 1333 | break; |
| 1334 | } |
| 1335 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1336 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1337 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: { |
| 1338 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1339 | auto image_view = update->pImageInfo[di].imageView; |
| 1340 | auto image_layout = update->pImageInfo[di].imageLayout; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1341 | if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1342 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1343 | error_str << "Attempted write update to image descriptor failed due to: " << error_msg->c_str(); |
| 1344 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1345 | return false; |
| 1346 | } |
| 1347 | } |
| 1348 | break; |
| 1349 | } |
| 1350 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1351 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { |
| 1352 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1353 | auto buffer_view = update->pTexelBufferView[di]; |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1354 | auto bv_state = getBufferViewState(device_data_, buffer_view); |
| 1355 | if (!bv_state) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1356 | *error_code = VALIDATION_ERROR_00940; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1357 | std::stringstream error_str; |
| 1358 | error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1359 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1360 | return false; |
| 1361 | } |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1362 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1363 | if (!ValidateBufferUsage(getBufferState(device_data_, buffer), update->descriptorType, error_code, error_msg)) { |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1364 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1365 | error_str << "Attempted write update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 1366 | *error_msg = error_str.str(); |
Tobin Ehlis | 6bd2b98 | 2016-05-24 12:33:42 -0600 | [diff] [blame] | 1367 | return false; |
| 1368 | } |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1369 | } |
| 1370 | break; |
| 1371 | } |
| 1372 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1373 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1374 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1375 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { |
| 1376 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1377 | if (!ValidateBufferUpdate(update->pBufferInfo + di, update->descriptorType, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1378 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1379 | error_str << "Attempted write update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 1380 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1381 | return false; |
| 1382 | } |
| 1383 | } |
| 1384 | break; |
| 1385 | } |
| 1386 | default: |
| 1387 | assert(0); // We've already verified update type so should never get here |
| 1388 | break; |
| 1389 | } |
| 1390 | // All checks passed so update contents are good |
| 1391 | return true; |
| 1392 | } |
| 1393 | // Verify that the contents of the update are ok, but don't perform actual update |
| 1394 | bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescriptorSet *update, const DescriptorSet *src_set, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1395 | VkDescriptorType type, uint32_t index, |
| 1396 | UNIQUE_VALIDATION_ERROR_CODE *error_code, |
| 1397 | std::string *error_msg) const { |
| 1398 | // Note : Repurposing some Write update error codes here as specific details aren't called out for copy updates like they are |
| 1399 | // for write updates |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1400 | switch (src_set->descriptors_[index]->descriptor_class) { |
| 1401 | case PlainSampler: { |
| 1402 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1403 | if (!src_set->descriptors_[index + di]->IsImmutableSampler()) { |
| 1404 | auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler(); |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1405 | if (!ValidateSampler(update_sampler, device_data_)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1406 | *error_code = VALIDATION_ERROR_00942; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1407 | std::stringstream error_str; |
| 1408 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1409 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1410 | return false; |
| 1411 | } |
| 1412 | } else { |
| 1413 | // TODO : Warn here |
| 1414 | } |
| 1415 | } |
| 1416 | break; |
| 1417 | } |
| 1418 | case ImageSampler: { |
| 1419 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1420 | auto img_samp_desc = static_cast<const ImageSamplerDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1421 | // First validate sampler |
| 1422 | if (!img_samp_desc->IsImmutableSampler()) { |
| 1423 | auto update_sampler = img_samp_desc->GetSampler(); |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 1424 | if (!ValidateSampler(update_sampler, device_data_)) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1425 | *error_code = VALIDATION_ERROR_00942; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1426 | std::stringstream error_str; |
| 1427 | error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1428 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
| 1431 | } else { |
| 1432 | // TODO : Warn here |
| 1433 | } |
| 1434 | // Validate image |
| 1435 | auto image_view = img_samp_desc->GetImageView(); |
| 1436 | auto image_layout = img_samp_desc->GetImageLayout(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1437 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1438 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1439 | error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error_msg->c_str(); |
| 1440 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1441 | return false; |
| 1442 | } |
| 1443 | } |
Alex Smith | d8f1479 | 2016-09-23 12:18:51 +0100 | [diff] [blame] | 1444 | break; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1445 | } |
| 1446 | case Image: { |
| 1447 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1448 | auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get()); |
| 1449 | auto image_view = img_desc->GetImageView(); |
| 1450 | auto image_layout = img_desc->GetImageLayout(); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1451 | if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1452 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1453 | error_str << "Attempted copy update to image descriptor failed due to: " << error_msg->c_str(); |
| 1454 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1455 | return false; |
| 1456 | } |
| 1457 | } |
| 1458 | break; |
| 1459 | } |
| 1460 | case TexelBuffer: { |
| 1461 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1462 | auto buffer_view = static_cast<TexelDescriptor *>(src_set->descriptors_[index + di].get())->GetBufferView(); |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1463 | auto bv_state = getBufferViewState(device_data_, buffer_view); |
| 1464 | if (!bv_state) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1465 | *error_code = VALIDATION_ERROR_00940; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1466 | std::stringstream error_str; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1467 | error_str << "Attempted copy update to texel buffer descriptor with invalid buffer view: " << buffer_view; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1468 | *error_msg = error_str.str(); |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1469 | return false; |
| 1470 | } |
Tobin Ehlis | 8b87246 | 2016-09-14 08:12:08 -0600 | [diff] [blame] | 1471 | auto buffer = bv_state->create_info.buffer; |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1472 | if (!ValidateBufferUsage(getBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 1473 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1474 | error_str << "Attempted copy update to texel buffer descriptor failed due to: " << error_msg->c_str(); |
| 1475 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1476 | return false; |
| 1477 | } |
| 1478 | } |
| 1479 | break; |
| 1480 | } |
| 1481 | case GeneralBuffer: { |
| 1482 | for (uint32_t di = 0; di < update->descriptorCount; ++di) { |
| 1483 | auto buffer = static_cast<BufferDescriptor *>(src_set->descriptors_[index + di].get())->GetBuffer(); |
Tobin Ehlis | 4668dce | 2016-11-16 09:30:23 -0700 | [diff] [blame^] | 1484 | if (!ValidateBufferUsage(getBufferState(device_data_, buffer), type, error_code, error_msg)) { |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1485 | std::stringstream error_str; |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1486 | error_str << "Attempted copy update to buffer descriptor failed due to: " << error_msg->c_str(); |
| 1487 | *error_msg = error_str.str(); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 1488 | return false; |
| 1489 | } |
| 1490 | } |
| 1491 | break; |
| 1492 | } |
| 1493 | default: |
| 1494 | assert(0); // We've already verified update type so should never get here |
| 1495 | break; |
| 1496 | } |
| 1497 | // All checks passed so update contents are good |
| 1498 | return true; |
Chris Forbes | b4e0bdb | 2016-05-31 16:34:40 +1200 | [diff] [blame] | 1499 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1500 | // Verify that the state at allocate time is correct, but don't actually allocate the sets yet |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1501 | bool cvdescriptorset::ValidateAllocateDescriptorSets(const debug_report_data *report_data, |
| 1502 | const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1503 | const core_validation::layer_data *dev_data, |
| 1504 | AllocateDescriptorSetsData *ds_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1505 | bool skip_call = false; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1506 | |
| 1507 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1508 | auto layout = getDescriptorSetLayout(dev_data, p_alloc_info->pSetLayouts[i]); |
| 1509 | if (!layout) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1510 | skip_call |= |
| 1511 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, |
| 1512 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i]), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS", |
| 1513 | "Unable to find set layout node for layout 0x%" PRIxLEAST64 " specified in vkAllocateDescriptorSets() call", |
| 1514 | reinterpret_cast<const uint64_t &>(p_alloc_info->pSetLayouts[i])); |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1515 | } else { |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1516 | ds_data->layout_nodes[i] = layout; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1517 | // Count total descriptors required per type |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 1518 | for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) { |
| 1519 | const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j); |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1520 | uint32_t typeIndex = static_cast<uint32_t>(binding_layout->descriptorType); |
| 1521 | ds_data->required_descriptors_by_type[typeIndex] += binding_layout->descriptorCount; |
| 1522 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1523 | } |
| 1524 | } |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1525 | auto pool_state = getDescriptorPoolState(dev_data, p_alloc_info->descriptorPool); |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1526 | // Track number of descriptorSets allowable in this pool |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1527 | if (pool_state->availableSets < p_alloc_info->descriptorSetCount) { |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1528 | skip_call |= log_msg( |
| 1529 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1530 | reinterpret_cast<uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, "DS", |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1531 | "Unable to allocate %u descriptorSets from pool 0x%" PRIxLEAST64 ". This pool only has %d descriptorSets remaining.", |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1532 | p_alloc_info->descriptorSetCount, reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableSets); |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1533 | } |
| 1534 | // Determine whether descriptor counts are satisfiable |
| 1535 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1536 | if (ds_data->required_descriptors_by_type[i] > pool_state->availableDescriptorTypeCount[i]) { |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1537 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1538 | reinterpret_cast<const uint64_t &>(pool_state->pool), __LINE__, DRAWSTATE_DESCRIPTOR_POOL_EMPTY, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 1539 | "DS", "Unable to allocate %u descriptors of type %s from pool 0x%" PRIxLEAST64 |
| 1540 | ". This pool only has %d descriptors of this type remaining.", |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1541 | ds_data->required_descriptors_by_type[i], string_VkDescriptorType(VkDescriptorType(i)), |
Tobin Ehlis | 15e6f79 | 2016-10-12 15:01:39 -0600 | [diff] [blame] | 1542 | reinterpret_cast<uint64_t &>(pool_state->pool), pool_state->availableDescriptorTypeCount[i]); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1543 | } |
| 1544 | } |
Tobin Ehlis | 5d749ea | 2016-07-18 13:14:01 -0600 | [diff] [blame] | 1545 | |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1546 | return skip_call; |
| 1547 | } |
| 1548 | // Decrement allocated sets from the pool and insert new sets into set_map |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1549 | void cvdescriptorset::PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *p_alloc_info, |
| 1550 | const VkDescriptorSet *descriptor_sets, |
| 1551 | const AllocateDescriptorSetsData *ds_data, |
Tobin Ehlis | bd711bd | 2016-10-12 14:27:30 -0600 | [diff] [blame] | 1552 | std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *pool_map, |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 1553 | std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map, |
| 1554 | const core_validation::layer_data *dev_data) { |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1555 | auto pool_state = (*pool_map)[p_alloc_info->descriptorPool]; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1556 | /* Account for sets and individual descriptors allocated from pool */ |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1557 | pool_state->availableSets -= p_alloc_info->descriptorSetCount; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 1558 | for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; i++) { |
| 1559 | pool_state->availableDescriptorTypeCount[i] -= ds_data->required_descriptors_by_type[i]; |
| 1560 | } |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1561 | /* Create tracking object for each descriptor set; insert into |
| 1562 | * global map and the pool's set. |
| 1563 | */ |
| 1564 | for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) { |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 1565 | auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], p_alloc_info->descriptorPool, ds_data->layout_nodes[i], |
| 1566 | dev_data); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 1567 | |
| 1568 | pool_state->sets.insert(new_ds); |
| 1569 | new_ds->in_use.store(0); |
| 1570 | (*set_map)[descriptor_sets[i]] = new_ds; |
| 1571 | } |
| 1572 | } |