1/* Copyright (c) 2015-2016 The Khronos Group Inc. 2 * Copyright (c) 2015-2016 Valve Corporation 3 * Copyright (c) 2015-2016 LunarG, Inc. 4 * Copyright (C) 2015-2016 Google Inc. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Tobin Ehlis <tobine@google.com> 19 * John Zulauf <jzulauf@lunarg.com> 20 */ 21#ifndef CORE_VALIDATION_DESCRIPTOR_SETS_H_ 22#define CORE_VALIDATION_DESCRIPTOR_SETS_H_ 23 24#include "core_validation_error_enums.h" 25#include "vk_validation_error_messages.h" 26#include "core_validation_types.h" 27#include "vk_layer_logging.h" 28#include "vk_layer_utils.h" 29#include "vk_safe_struct.h" 30#include "vulkan/vk_layer.h" 31#include "vk_object_types.h" 32#include <map> 33#include <memory> 34#include <set> 35#include <unordered_map> 36#include <unordered_set> 37#include <vector> 38 39using core_validation::layer_data; 40 41// Descriptor Data structures 42namespace cvdescriptorset { 43 44// Utility structs/classes/types 45// Index range for global indices below, end is exclusive, i.e. [start,end) 46struct IndexRange { 47 IndexRange(uint32_t start_in, uint32_t end_in) : start(start_in), end(end_in) {} 48 IndexRange() = default; 49 uint32_t start; 50 uint32_t end; 51}; 52typedef std::map<uint32_t, descriptor_req> BindingReqMap; 53 54/* 55 * DescriptorSetLayout class 56 * 57 * Overview - This class encapsulates the Vulkan VkDescriptorSetLayout data (layout). 58 * A layout consists of some number of bindings, each of which has a binding#, a 59 * type, descriptor count, stage flags, and pImmutableSamplers. 60 * 61 * Index vs Binding - A layout is created with an array of VkDescriptorSetLayoutBinding 62 * where each array index will have a corresponding binding# that is defined in that struct. 63 * The binding#, then, is decoupled from VkDescriptorSetLayoutBinding index, which allows 64 * bindings to be defined out-of-order. This DescriptorSetLayout class, however, stores 65 * the bindings internally in-order. This is useful for operations which may "roll over" 66 * from a single binding to the next consecutive binding. 67 * 68 * Note that although the bindings are stored in-order, there still may be "gaps" in the 69 * binding#. For example, if the binding creation order is 8, 7, 10, 3, 4, then the 70 * internal binding array will have five entries stored in binding order 3, 4, 7, 8, 10. 71 * To process all of the bindings in a layout you can iterate from 0 to GetBindingCount() 72 * and use the Get*FromIndex() functions for each index. To just process a single binding, 73 * use the Get*FromBinding() functions. 74 * 75 * Global Index - The binding vector index has as many indices as there are bindings. 76 * This class also has the concept of a Global Index. For the global index functions, 77 * there are as many global indices as there are descriptors in the layout. 78 * For the global index, consider all of the bindings to be a flat array where 79 * descriptor 0 of of the lowest binding# is index 0 and each descriptor in the layout 80 * increments from there. So if the lowest binding# in this example had descriptorCount of 81 * 10, then the GlobalStartIndex of the 2nd lowest binding# will be 10 where 0-9 are the 82 * global indices for the lowest binding#. 83 */ 84class DescriptorSetLayout { 85 public: 86 // Constructors and destructor 87 DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, const VkDescriptorSetLayout layout); 88 // Validate create info - should be called prior to creation 89 static bool ValidateCreateInfo(const debug_report_data *, const VkDescriptorSetLayoutCreateInfo *, const bool, const uint32_t); 90 // Straightforward Get functions 91 VkDescriptorSetLayout GetDescriptorSetLayout() const { return layout_; }; 92 bool IsDestroyed() const { return layout_destroyed_; } 93 void MarkDestroyed() { layout_destroyed_ = true; } 94 uint32_t GetTotalDescriptorCount() const { return descriptor_count_; }; 95 uint32_t GetDynamicDescriptorCount() const { return dynamic_descriptor_count_; }; 96 VkDescriptorSetLayoutCreateFlags GetCreateFlags() const { return flags_; } 97 // For a given binding, return the number of descriptors in that binding and all successive bindings 98 uint32_t GetBindingCount() const { return binding_count_; }; 99 // Non-empty binding numbers in order 100 const std::set<uint32_t> &GetSortedBindingSet() const { return non_empty_bindings_; } 101 // Return true if given binding is present in this layout 102 bool HasBinding(const uint32_t binding) const { return binding_to_index_map_.count(binding) > 0; }; 103 // Return true if this layout is compatible with passed in layout from a pipelineLayout, 104 // else return false and update error_msg with description of incompatibility 105 bool IsCompatible(DescriptorSetLayout const *const, std::string *) const; 106 // Return true if binding 1 beyond given exists and has same type, stageFlags & immutable sampler use 107 bool IsNextBindingConsistent(const uint32_t) const; 108 uint32_t GetIndexFromBinding(uint32_t binding) const; 109 // Various Get functions that can either be passed a binding#, which will 110 // be automatically translated into the appropriate index, or the index# can be passed in directly 111 uint32_t GetMaxBinding() const { return bindings_[bindings_.size() - 1].binding; } 112 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t) const; 113 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromBinding(uint32_t binding) const { 114 return GetDescriptorSetLayoutBindingPtrFromIndex(GetIndexFromBinding(binding)); 115 } 116 uint32_t GetDescriptorCountFromIndex(const uint32_t) const; 117 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const { 118 return GetDescriptorCountFromIndex(GetIndexFromBinding(binding)); 119 } 120 VkDescriptorType GetTypeFromIndex(const uint32_t) const; 121 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { return GetTypeFromIndex(GetIndexFromBinding(binding)); } 122 VkShaderStageFlags GetStageFlagsFromIndex(const uint32_t) const; 123 VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t binding) const { 124 return GetStageFlagsFromIndex(GetIndexFromBinding(binding)); 125 } 126 uint32_t GetIndexFromGlobalIndex(const uint32_t global_index) const; 127 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t global_index) const { 128 return GetTypeFromIndex(GetIndexFromGlobalIndex(global_index)); 129 } 130 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t) const; 131 VkSampler const *GetImmutableSamplerPtrFromIndex(const uint32_t) const; 132 // For a given binding and array index, return the corresponding index into the dynamic offset array 133 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const { 134 auto dyn_off = binding_to_dynamic_array_idx_map_.find(binding); 135 if (dyn_off == binding_to_dynamic_array_idx_map_.end()) { 136 assert(0); // Requesting dyn offset for invalid binding/array idx pair 137 return -1; 138 } 139 return dyn_off->second; 140 } 141 // For a particular binding, get the global index range 142 // This call should be guarded by a call to "HasBinding(binding)" to verify that the given binding exists 143 const IndexRange &GetGlobalIndexRangeFromBinding(const uint32_t) const; 144 145 // Helper function to get the next valid binding for a descriptor 146 uint32_t GetNextValidBinding(const uint32_t) const; 147 // For a particular binding starting at offset and having update_count descriptors 148 // updated, verify that for any binding boundaries crossed, the update is consistent 149 bool VerifyUpdateConsistency(uint32_t, uint32_t, uint32_t, const char *, const VkDescriptorSet, std::string *) const; 150 bool IsPushDescriptor() const { return GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; }; 151 152 struct BindingTypeStats { 153 uint32_t dynamic_buffer_count; 154 uint32_t non_dynamic_buffer_count; 155 uint32_t image_sampler_count; 156 }; 157 const BindingTypeStats &GetBindingTypeStats() const { return binding_type_stats_; } 158 159 private: 160 VkDescriptorSetLayout layout_; 161 bool layout_destroyed_; 162 std::set<uint32_t> non_empty_bindings_; // Containing non-emtpy bindings in numerical order 163 std::unordered_map<uint32_t, uint32_t> binding_to_index_map_; 164 // The following map allows an non-iterative lookup of a binding from a global index... 165 std::map<uint32_t, uint32_t> global_start_to_index_map_; // The index corresponding for a starting global (descriptor) index 166 std::unordered_map<uint32_t, IndexRange> binding_to_global_index_range_map_; // range is exclusive of .end 167 // For a given binding map to associated index in the dynamic offset array 168 std::unordered_map<uint32_t, uint32_t> binding_to_dynamic_array_idx_map_; 169 VkDescriptorSetLayoutCreateFlags flags_; 170 uint32_t binding_count_; // # of bindings in this layout 171 std::vector<safe_VkDescriptorSetLayoutBinding> bindings_; 172 uint32_t descriptor_count_; // total # descriptors in this layout 173 uint32_t dynamic_descriptor_count_; 174 BindingTypeStats binding_type_stats_; 175}; 176 177/* 178 * Descriptor classes 179 * Descriptor is an abstract base class from which 5 separate descriptor types are derived. 180 * This allows the WriteUpdate() and CopyUpdate() operations to be specialized per 181 * descriptor type, but all descriptors in a set can be accessed via the common Descriptor*. 182 */ 183 184// Slightly broader than type, each c++ "class" will has a corresponding "DescriptorClass" 185enum DescriptorClass { PlainSampler, ImageSampler, Image, TexelBuffer, GeneralBuffer }; 186 187class Descriptor { 188 public: 189 virtual ~Descriptor(){}; 190 virtual void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) = 0; 191 virtual void CopyUpdate(const Descriptor *) = 0; 192 // Create binding between resources of this descriptor and given cb_node 193 virtual void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) = 0; 194 virtual DescriptorClass GetClass() const { return descriptor_class; }; 195 // Special fast-path check for SamplerDescriptors that are immutable 196 virtual bool IsImmutableSampler() const { return false; }; 197 // Check for dynamic descriptor type 198 virtual bool IsDynamic() const { return false; }; 199 // Check for storage descriptor type 200 virtual bool IsStorage() const { return false; }; 201 bool updated; // Has descriptor been updated? 202 DescriptorClass descriptor_class; 203}; 204// Shared helper functions - These are useful because the shared sampler image descriptor type 205// performs common functions with both sampler and image descriptors so they can share their common functions 206bool ValidateSampler(const VkSampler, const core_validation::layer_data *); 207bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *, 208 UNIQUE_VALIDATION_ERROR_CODE *, std::string *); 209 210class SamplerDescriptor : public Descriptor { 211 public: 212 SamplerDescriptor(const VkSampler *); 213 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; 214 void CopyUpdate(const Descriptor *) override; 215 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; 216 virtual bool IsImmutableSampler() const override { return immutable_; }; 217 VkSampler GetSampler() const { return sampler_; } 218 219 private: 220 // bool ValidateSampler(const VkSampler) const; 221 VkSampler sampler_; 222 bool immutable_; 223}; 224 225class ImageSamplerDescriptor : public Descriptor { 226 public: 227 ImageSamplerDescriptor(const VkSampler *); 228 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; 229 void CopyUpdate(const Descriptor *) override; 230 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; 231 virtual bool IsImmutableSampler() const override { return immutable_; }; 232 VkSampler GetSampler() const { return sampler_; } 233 VkImageView GetImageView() const { return image_view_; } 234 VkImageLayout GetImageLayout() const { return image_layout_; } 235 236 private: 237 VkSampler sampler_; 238 bool immutable_; 239 VkImageView image_view_; 240 VkImageLayout image_layout_; 241}; 242 243class ImageDescriptor : public Descriptor { 244 public: 245 ImageDescriptor(const VkDescriptorType); 246 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; 247 void CopyUpdate(const Descriptor *) override; 248 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; 249 virtual bool IsStorage() const override { return storage_; } 250 VkImageView GetImageView() const { return image_view_; } 251 VkImageLayout GetImageLayout() const { return image_layout_; } 252 253 private: 254 bool storage_; 255 VkImageView image_view_; 256 VkImageLayout image_layout_; 257}; 258 259class TexelDescriptor : public Descriptor { 260 public: 261 TexelDescriptor(const VkDescriptorType); 262 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; 263 void CopyUpdate(const Descriptor *) override; 264 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; 265 virtual bool IsStorage() const override { return storage_; } 266 VkBufferView GetBufferView() const { return buffer_view_; } 267 268 private: 269 VkBufferView buffer_view_; 270 bool storage_; 271}; 272 273class BufferDescriptor : public Descriptor { 274 public: 275 BufferDescriptor(const VkDescriptorType); 276 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; 277 void CopyUpdate(const Descriptor *) override; 278 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; 279 virtual bool IsDynamic() const override { return dynamic_; } 280 virtual bool IsStorage() const override { return storage_; } 281 VkBuffer GetBuffer() const { return buffer_; } 282 VkDeviceSize GetOffset() const { return offset_; } 283 VkDeviceSize GetRange() const { return range_; } 284 285 private: 286 bool storage_; 287 bool dynamic_; 288 VkBuffer buffer_; 289 VkDeviceSize offset_; 290 VkDeviceSize range_; 291}; 292// Structs to contain common elements that need to be shared between Validate* and Perform* calls below 293struct AllocateDescriptorSetsData { 294 uint32_t required_descriptors_by_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; 295 std::vector<std::shared_ptr<DescriptorSetLayout const>> layout_nodes; 296 AllocateDescriptorSetsData(uint32_t); 297}; 298// Helper functions for descriptor set functions that cross multiple sets 299// "Validate" will make sure an update is ok without actually performing it 300bool ValidateUpdateDescriptorSets(const debug_report_data *, const core_validation::layer_data *, uint32_t, 301 const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *); 302// "Perform" does the update with the assumption that ValidateUpdateDescriptorSets() has passed for the given update 303void PerformUpdateDescriptorSets(const core_validation::layer_data *, uint32_t, const VkWriteDescriptorSet *, uint32_t, 304 const VkCopyDescriptorSet *); 305// Similar to PerformUpdateDescriptorSets, this function will do the same for updating via templates 306void PerformUpdateDescriptorSetsWithTemplateKHR(layer_data *, VkDescriptorSet, std::unique_ptr<TEMPLATE_STATE> const &, 307 const void *); 308// Update the common AllocateDescriptorSetsData struct which can then be shared between Validate* and Perform* funcs below 309void UpdateAllocateDescriptorSetsData(const layer_data *dev_data, const VkDescriptorSetAllocateInfo *, 310 AllocateDescriptorSetsData *); 311// Validate that Allocation state is ok 312bool ValidateAllocateDescriptorSets(const core_validation::layer_data *, const VkDescriptorSetAllocateInfo *, 313 const AllocateDescriptorSetsData *); 314// Update state based on allocating new descriptorsets 315void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const VkDescriptorSet *, const AllocateDescriptorSetsData *, 316 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *, 317 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *, 318 core_validation::layer_data *); 319 320/* 321 * DescriptorSet class 322 * 323 * Overview - This class encapsulates the Vulkan VkDescriptorSet data (set). 324 * A set has an underlying layout which defines the bindings in the set and the 325 * types and numbers of descriptors in each descriptor slot. Most of the layout 326 * interfaces are exposed through identically-named functions in the set class. 327 * Please refer to the DescriptorSetLayout comment above for a description of 328 * index, binding, and global index. 329 * 330 * At construction a vector of Descriptor* is created with types corresponding to the 331 * layout. The primary operation performed on the descriptors is to update them 332 * via write or copy updates, and validate that the update contents are correct. 333 * In order to validate update contents, the DescriptorSet stores a bunch of ptrs 334 * to data maps where various Vulkan objects can be looked up. The management of 335 * those maps is performed externally. The set class relies on their contents to 336 * be correct at the time of update. 337 */ 338class DescriptorSet : public BASE_NODE { 339 public: 340 DescriptorSet(const VkDescriptorSet, const VkDescriptorPool, const std::shared_ptr<DescriptorSetLayout const> &, 341 core_validation::layer_data *); 342 ~DescriptorSet(); 343 // A number of common Get* functions that return data based on layout from which this set was created 344 uint32_t GetTotalDescriptorCount() const { return p_layout_->GetTotalDescriptorCount(); }; 345 uint32_t GetDynamicDescriptorCount() const { return p_layout_->GetDynamicDescriptorCount(); }; 346 uint32_t GetBindingCount() const { return p_layout_->GetBindingCount(); }; 347 VkDescriptorType GetTypeFromIndex(const uint32_t index) const { return p_layout_->GetTypeFromIndex(index); }; 348 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t index) const { return p_layout_->GetTypeFromGlobalIndex(index); }; 349 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { return p_layout_->GetTypeFromBinding(binding); }; 350 uint32_t GetDescriptorCountFromIndex(const uint32_t index) const { return p_layout_->GetDescriptorCountFromIndex(index); }; 351 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const { 352 return p_layout_->GetDescriptorCountFromBinding(binding); 353 }; 354 // Return index into dynamic offset array for given binding 355 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const { 356 return p_layout_->GetDynamicOffsetIndexFromBinding(binding); 357 } 358 // Return true if given binding is present in this set 359 bool HasBinding(const uint32_t binding) const { return p_layout_->HasBinding(binding); }; 360 // Is this set compatible with the given layout? 361 bool IsCompatible(DescriptorSetLayout const *const, std::string *) const; 362 // For given bindings validate state at time of draw is correct, returning false on error and writing error details into string* 363 bool ValidateDrawState(const std::map<uint32_t, descriptor_req> &, const std::vector<uint32_t> &, GLOBAL_CB_NODE *, 364 const char *caller, std::string *) const; 365 // For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number 366 // of objects inserted 367 uint32_t GetStorageUpdates(const std::map<uint32_t, descriptor_req> &, std::unordered_set<VkBuffer> *, 368 std::unordered_set<VkImageView> *) const; 369 370 // Descriptor Update functions. These functions validate state and perform update separately 371 // Validate contents of a WriteUpdate 372 bool ValidateWriteUpdate(const debug_report_data *, const VkWriteDescriptorSet *, UNIQUE_VALIDATION_ERROR_CODE *, 373 std::string *); 374 // Perform a WriteUpdate whose contents were just validated using ValidateWriteUpdate 375 void PerformWriteUpdate(const VkWriteDescriptorSet *); 376 // Validate contents of a CopyUpdate 377 bool ValidateCopyUpdate(const debug_report_data *, const VkCopyDescriptorSet *, const DescriptorSet *, 378 UNIQUE_VALIDATION_ERROR_CODE *, std::string *); 379 // Perform a CopyUpdate whose contents were just validated using ValidateCopyUpdate 380 void PerformCopyUpdate(const VkCopyDescriptorSet *, const DescriptorSet *); 381 382 std::shared_ptr<DescriptorSetLayout const> const GetLayout() const { return p_layout_; }; 383 VkDescriptorSet GetSet() const { return set_; }; 384 // Return unordered_set of all command buffers that this set is bound to 385 std::unordered_set<GLOBAL_CB_NODE *> GetBoundCmdBuffers() const { return cb_bindings; } 386 // Bind given cmd_buffer to this descriptor set 387 void BindCommandBuffer(GLOBAL_CB_NODE *, const std::map<uint32_t, descriptor_req> &); 388 389 // Track work that has been bound or validated to avoid duplicate work, important when large descriptor arrays 390 // are present 391 typedef std::unordered_set<uint32_t> TrackedBindings; 392 static void FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, const BindingReqMap &in_req, 393 BindingReqMap *out_req, TrackedBindings *set); 394 static void FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, const BindingReqMap &in_req, 395 BindingReqMap *out_req, TrackedBindings *set, uint32_t limit); 396 void FilterAndTrackBindingReqs(GLOBAL_CB_NODE *, const BindingReqMap &in_req, BindingReqMap *out_req); 397 void FilterAndTrackBindingReqs(GLOBAL_CB_NODE *, PIPELINE_STATE *, const BindingReqMap &in_req, BindingReqMap *out_req); 398 void ClearCachedDynamicDescriptorValidation(GLOBAL_CB_NODE *cb_state) { cached_validation_[cb_state].dynamic_buffers.clear(); } 399 void ClearCachedValidation(GLOBAL_CB_NODE *cb_state) { cached_validation_.erase(cb_state); } 400 // If given cmd_buffer is in the cb_bindings set, remove it 401 void RemoveBoundCommandBuffer(GLOBAL_CB_NODE *cb_node) { 402 cb_bindings.erase(cb_node); 403 ClearCachedValidation(cb_node); 404 } 405 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t index) const { 406 return p_layout_->GetImmutableSamplerPtrFromBinding(index); 407 }; 408 // For a particular binding, get the global index 409 const IndexRange &GetGlobalIndexRangeFromBinding(const uint32_t binding) const { 410 return p_layout_->GetGlobalIndexRangeFromBinding(binding); 411 }; 412 // Return true if any part of set has ever been updated 413 bool IsUpdated() const { return some_update_; }; 414 bool IsPushDescriptor() const { return p_layout_->IsPushDescriptor(); }; 415 416 private: 417 bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, UNIQUE_VALIDATION_ERROR_CODE *, 418 std::string *) const; 419 bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, VkDescriptorType, uint32_t, 420 UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const; 421 bool ValidateBufferUsage(BUFFER_STATE const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const; 422 bool ValidateBufferUpdate(VkDescriptorBufferInfo const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *, 423 std::string *) const; 424 // Private helper to set all bound cmd buffers to INVALID state 425 void InvalidateBoundCmdBuffers(); 426 bool some_update_; // has any part of the set ever been updated? 427 VkDescriptorSet set_; 428 DESCRIPTOR_POOL_STATE *pool_state_; 429 const std::shared_ptr<DescriptorSetLayout const> p_layout_; 430 std::vector<std::unique_ptr<Descriptor>> descriptors_; 431 // Ptr to device data used for various data look-ups 432 core_validation::layer_data *const device_data_; 433 const VkPhysicalDeviceLimits limits_; 434 435 // Cached binding and validation support: 436 // 437 // For the lifespan of a given command buffer recording, do lazy evaluation, caching, and dirtying of 438 // expensive validation operation (typically per-draw) 439 typedef std::unordered_map<GLOBAL_CB_NODE *, TrackedBindings> TrackedBindingMap; 440 typedef std::unordered_map<PIPELINE_STATE *, TrackedBindingMap> ValidatedBindings; 441 // Track the validation caching of bindings vs. the command buffer and draw state 442 typedef std::unordered_map<uint32_t, GLOBAL_CB_NODE::ImageLayoutUpdateCount> VersionedBindings; 443 struct CachedValidation { 444 TrackedBindings command_binding_and_usage; // Persistent for the life of the recording 445 TrackedBindings non_dynamic_buffers; // Persistent for the life of the recording 446 TrackedBindings dynamic_buffers; // Dirtied (flushed) each BindDescriptorSet 447 std::unordered_map<PIPELINE_STATE *, VersionedBindings> image_samplers; // Tested vs. changes to CB's ImageLayout 448 }; 449 typedef std::unordered_map<GLOBAL_CB_NODE *, CachedValidation> CachedValidationMap; 450 // Image and ImageView bindings are validated per pipeline and not invalidate by repeated binding 451 CachedValidationMap cached_validation_; 452}; 453// For the "bindless" style resource usage with many descriptors, need to optimize binding and validation 454class PrefilterBindRequestMap { 455 public: 456 static const uint32_t kManyDescriptors_ = 64; // TODO base this number on measured data 457 std::unique_ptr<BindingReqMap> filtered_map_; 458 const BindingReqMap &orig_map_; 459 460 PrefilterBindRequestMap(DescriptorSet &ds, const BindingReqMap &in_map, GLOBAL_CB_NODE *cb_state); 461 PrefilterBindRequestMap(DescriptorSet &ds, const BindingReqMap &in_map, GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *); 462 const BindingReqMap &Map() const { return (filtered_map_) ? *filtered_map_ : orig_map_; } 463}; 464} // namespace cvdescriptorset 465#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_ 466