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