Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Tobin Ehlis <tobine@google.com> |
| 19 | */ |
| 20 | #ifndef CORE_VALIDATION_DESCRIPTOR_SETS_H_ |
| 21 | #define CORE_VALIDATION_DESCRIPTOR_SETS_H_ |
| 22 | |
| 23 | // Check for noexcept support |
Mark Lobodzinski | a5efa73 | 2016-10-10 14:05:59 -0600 | [diff] [blame] | 24 | #ifndef NOEXCEPT |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 25 | #if defined(__clang__) |
| 26 | #if __has_feature(cxx_noexcept) |
| 27 | #define HAS_NOEXCEPT |
| 28 | #endif |
| 29 | #else |
| 30 | #if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46 |
| 31 | #define HAS_NOEXCEPT |
| 32 | #else |
| 33 | #if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS |
| 34 | #define HAS_NOEXCEPT |
| 35 | #endif |
| 36 | #endif |
| 37 | #endif |
| 38 | |
| 39 | #ifdef HAS_NOEXCEPT |
| 40 | #define NOEXCEPT noexcept |
| 41 | #else |
| 42 | #define NOEXCEPT |
| 43 | #endif |
Mark Lobodzinski | a5efa73 | 2016-10-10 14:05:59 -0600 | [diff] [blame] | 44 | #endif |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 45 | |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 46 | #include "core_validation_error_enums.h" |
Tobin Ehlis | bf98b69 | 2016-10-06 12:58:06 -0600 | [diff] [blame] | 47 | #include "vk_validation_error_messages.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 48 | #include "core_validation_types.h" |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 49 | #include "vk_layer_logging.h" |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 50 | #include "vk_layer_utils.h" |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 51 | #include "vk_safe_struct.h" |
| 52 | #include "vulkan/vk_layer.h" |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 53 | #include <map> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 54 | #include <memory> |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 55 | #include <unordered_map> |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 56 | #include <unordered_set> |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 57 | #include <vector> |
| 58 | |
| 59 | // Descriptor Data structures |
| 60 | |
| 61 | /* |
| 62 | * DescriptorSetLayout class |
| 63 | * |
| 64 | * Overview - This class encapsulates the Vulkan VkDescriptorSetLayout data (layout). |
| 65 | * A layout consists of some number of bindings, each of which has a binding#, a |
| 66 | * type, descriptor count, stage flags, and pImmutableSamplers. |
| 67 | * |
| 68 | * Index vs Binding - A layout is created with an array of VkDescriptorSetLayoutBinding |
| 69 | * where each array index will have a corresponding binding# that is defined in that struct. |
| 70 | * This class, therefore, provides utility functions where you can retrieve data for |
| 71 | * layout bindings based on either the original index into the pBindings array, or based |
| 72 | * on the binding#. |
| 73 | * Typically if you want to cover all of the bindings in a layout, you can do that by |
| 74 | * iterating over GetBindingCount() bindings and using the Get*FromIndex() functions. |
| 75 | * Otherwise, you can use the Get*FromBinding() functions to just grab binding info |
| 76 | * for a particular binding#. |
| 77 | * |
| 78 | * Global Index - The "Index" referenced above is the index into the original pBindings |
| 79 | * array. So there are as many indices as there are bindings. |
| 80 | * This class also has the concept of a Global Index. For the global index functions, |
| 81 | * there are as many global indices as there are descriptors in the layout. |
| 82 | * For the global index, consider all of the bindings to be a flat array where |
| 83 | * descriptor 0 of pBinding[0] is index 0 and each descriptor in the layout increments |
| 84 | * from there. So if pBinding[0] in this example had descriptorCount of 10, then |
| 85 | * the GlobalStartIndex of pBinding[1] will be 10 where 0-9 are the global indices |
| 86 | * for pBinding[0]. |
| 87 | */ |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 88 | namespace cvdescriptorset { |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 89 | class DescriptorSetLayout { |
| 90 | public: |
| 91 | // Constructors and destructor |
Tobin Ehlis | 154c269 | 2016-10-25 09:36:53 -0600 | [diff] [blame^] | 92 | DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, const VkDescriptorSetLayout layout); |
| 93 | // Validate create info - should be called prior to creation |
| 94 | static bool ValidateCreateInfo(debug_report_data *, const VkDescriptorSetLayoutCreateInfo *); |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 95 | // Straightforward Get functions |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 96 | VkDescriptorSetLayout GetDescriptorSetLayout() const { return layout_; }; |
| 97 | uint32_t GetTotalDescriptorCount() const { return descriptor_count_; }; |
| 98 | uint32_t GetDynamicDescriptorCount() const { return dynamic_descriptor_count_; }; |
| 99 | uint32_t GetBindingCount() const { return binding_count_; }; |
| 100 | // Fill passed-in set with bindings |
| 101 | void FillBindingSet(std::unordered_set<uint32_t> *) const; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 102 | // Return true if given binding is present in this layout |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 103 | bool HasBinding(const uint32_t binding) const { return binding_to_index_map_.count(binding) > 0; }; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 104 | // Return true if this layout is compatible with passed in layout, |
| 105 | // else return false and update error_msg with description of incompatibility |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 106 | bool IsCompatible(const DescriptorSetLayout *, std::string *) const; |
| 107 | // Return true if binding 1 beyond given exists and has same type, stageFlags & immutable sampler use |
| 108 | bool IsNextBindingConsistent(const uint32_t) const; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 109 | // Various Get functions that can either be passed a binding#, which will |
| 110 | // be automatically translated into the appropriate index from the original |
| 111 | // pBindings array, or the index# can be passed in directly |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 112 | VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t) const; |
| 113 | VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t) const; |
| 114 | uint32_t GetDescriptorCountFromBinding(const uint32_t) const; |
| 115 | uint32_t GetDescriptorCountFromIndex(const uint32_t) const; |
| 116 | VkDescriptorType GetTypeFromBinding(const uint32_t) const; |
| 117 | VkDescriptorType GetTypeFromIndex(const uint32_t) const; |
| 118 | VkDescriptorType GetTypeFromGlobalIndex(const uint32_t) const; |
| 119 | VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t) const; |
| 120 | VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t) const; |
| 121 | VkSampler const *GetImmutableSamplerPtrFromIndex(const uint32_t) const; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 122 | // For a particular binding, get the global index |
Tobin Ehlis | 58c5958 | 2016-06-21 12:34:33 -0600 | [diff] [blame] | 123 | // These calls should be guarded by a call to "HasBinding(binding)" to verify that the given binding exists |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 124 | uint32_t GetGlobalStartIndexFromBinding(const uint32_t) const; |
| 125 | uint32_t GetGlobalEndIndexFromBinding(const uint32_t) const; |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 126 | // For a particular binding starting at offset and having update_count descriptors |
| 127 | // updated, verify that for any binding boundaries crossed, the update is consistent |
| 128 | bool VerifyUpdateConsistency(uint32_t, uint32_t, uint32_t, const char *, const VkDescriptorSet, std::string *) const; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 129 | |
| 130 | private: |
| 131 | VkDescriptorSetLayout layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 132 | std::unordered_map<uint32_t, uint32_t> binding_to_index_map_; |
| 133 | std::unordered_map<uint32_t, uint32_t> binding_to_global_start_index_map_; |
| 134 | std::unordered_map<uint32_t, uint32_t> binding_to_global_end_index_map_; |
| 135 | // VkDescriptorSetLayoutCreateFlags flags_; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 136 | uint32_t binding_count_; // # of bindings in this layout |
Tobin Ehlis | 664e601 | 2016-05-05 11:04:44 -0600 | [diff] [blame] | 137 | std::vector<safe_VkDescriptorSetLayoutBinding> bindings_; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 138 | uint32_t descriptor_count_; // total # descriptors in this layout |
| 139 | uint32_t dynamic_descriptor_count_; |
| 140 | }; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Descriptor classes |
| 144 | * Descriptor is an abstract base class from which 5 separate descriptor types are derived. |
| 145 | * This allows the WriteUpdate() and CopyUpdate() operations to be specialized per |
| 146 | * descriptor type, but all descriptors in a set can be accessed via the common Descriptor*. |
| 147 | */ |
| 148 | |
| 149 | // Slightly broader than type, each c++ "class" will has a corresponding "DescriptorClass" |
Mark Lobodzinski | 0978f5f | 2016-05-19 17:23:38 -0600 | [diff] [blame] | 150 | enum DescriptorClass { PlainSampler, ImageSampler, Image, TexelBuffer, GeneralBuffer }; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 151 | |
| 152 | class Descriptor { |
| 153 | public: |
| 154 | virtual ~Descriptor(){}; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 155 | virtual void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) = 0; |
| 156 | virtual void CopyUpdate(const Descriptor *) = 0; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 157 | // Create binding between resources of this descriptor and given cb_node |
| 158 | virtual void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) = 0; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 159 | virtual DescriptorClass GetClass() const { return descriptor_class; }; |
| 160 | // Special fast-path check for SamplerDescriptors that are immutable |
| 161 | virtual bool IsImmutableSampler() const { return false; }; |
| 162 | // Check for dynamic descriptor type |
| 163 | virtual bool IsDynamic() const { return false; }; |
| 164 | // Check for storage descriptor type |
| 165 | virtual bool IsStorage() const { return false; }; |
| 166 | bool updated; // Has descriptor been updated? |
| 167 | DescriptorClass descriptor_class; |
| 168 | }; |
| 169 | // Shared helper functions - These are useful because the shared sampler image descriptor type |
| 170 | // performs common functions with both sampler and image descriptors so they can share their common functions |
Tobin Ehlis | e2f8029 | 2016-06-02 10:08:53 -0600 | [diff] [blame] | 171 | bool ValidateSampler(const VkSampler, const core_validation::layer_data *); |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 172 | bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *, |
| 173 | UNIQUE_VALIDATION_ERROR_CODE *, std::string *); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 174 | |
| 175 | class SamplerDescriptor : public Descriptor { |
| 176 | public: |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 177 | SamplerDescriptor(); |
| 178 | SamplerDescriptor(const VkSampler *); |
| 179 | void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; |
| 180 | void CopyUpdate(const Descriptor *) override; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 181 | void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 182 | virtual bool IsImmutableSampler() const override { return immutable_; }; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 183 | VkSampler GetSampler() const { return sampler_; } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 184 | |
| 185 | private: |
| 186 | // bool ValidateSampler(const VkSampler) const; |
| 187 | VkSampler sampler_; |
| 188 | bool immutable_; |
Tobin Ehlis | 546326f | 2016-04-26 11:06:05 -0600 | [diff] [blame] | 189 | }; |
| 190 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 191 | class ImageSamplerDescriptor : public Descriptor { |
| 192 | public: |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 193 | ImageSamplerDescriptor(); |
| 194 | ImageSamplerDescriptor(const VkSampler *); |
| 195 | void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; |
| 196 | void CopyUpdate(const Descriptor *) override; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 197 | void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; |
Tobin Ehlis | c962515 | 2016-05-24 16:47:36 -0600 | [diff] [blame] | 198 | virtual bool IsImmutableSampler() const override { return immutable_; }; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 199 | VkSampler GetSampler() const { return sampler_; } |
| 200 | VkImageView GetImageView() const { return image_view_; } |
| 201 | VkImageLayout GetImageLayout() const { return image_layout_; } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 202 | |
| 203 | private: |
| 204 | VkSampler sampler_; |
| 205 | bool immutable_; |
| 206 | VkImageView image_view_; |
| 207 | VkImageLayout image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | class ImageDescriptor : public Descriptor { |
| 211 | public: |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 212 | ImageDescriptor(const VkDescriptorType); |
| 213 | void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; |
| 214 | void CopyUpdate(const Descriptor *) override; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 215 | void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; |
Norbert Nopper | 419a109 | 2016-05-15 19:19:41 +0200 | [diff] [blame] | 216 | virtual bool IsStorage() const override { return storage_; } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 217 | VkImageView GetImageView() const { return image_view_; } |
| 218 | VkImageLayout GetImageLayout() const { return image_layout_; } |
| 219 | |
| 220 | private: |
| 221 | bool storage_; |
| 222 | VkImageView image_view_; |
| 223 | VkImageLayout image_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | class TexelDescriptor : public Descriptor { |
| 227 | public: |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 228 | TexelDescriptor(const VkDescriptorType); |
| 229 | void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; |
| 230 | void CopyUpdate(const Descriptor *) override; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 231 | void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; |
Tobin Ehlis | f490f2e | 2016-05-17 06:43:48 -0600 | [diff] [blame] | 232 | virtual bool IsStorage() const override { return storage_; } |
| 233 | VkBufferView GetBufferView() const { return buffer_view_; } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 234 | |
| 235 | private: |
| 236 | VkBufferView buffer_view_; |
| 237 | bool storage_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | class BufferDescriptor : public Descriptor { |
| 241 | public: |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 242 | BufferDescriptor(const VkDescriptorType); |
| 243 | void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override; |
| 244 | void CopyUpdate(const Descriptor *) override; |
Tobin Ehlis | 8020eea | 2016-08-17 11:10:41 -0600 | [diff] [blame] | 245 | void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 246 | virtual bool IsDynamic() const override { return dynamic_; } |
| 247 | virtual bool IsStorage() const override { return storage_; } |
| 248 | VkBuffer GetBuffer() const { return buffer_; } |
| 249 | VkDeviceSize GetOffset() const { return offset_; } |
| 250 | VkDeviceSize GetRange() const { return range_; } |
| 251 | |
| 252 | private: |
| 253 | bool storage_; |
| 254 | bool dynamic_; |
| 255 | VkBuffer buffer_; |
| 256 | VkDeviceSize offset_; |
| 257 | VkDeviceSize range_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 258 | }; |
Tobin Ehlis | 68d0adf | 2016-06-01 11:33:50 -0600 | [diff] [blame] | 259 | // Structs to contain common elements that need to be shared between Validate* and Perform* calls below |
| 260 | struct AllocateDescriptorSetsData { |
| 261 | uint32_t required_descriptors_by_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE]; |
| 262 | std::vector<cvdescriptorset::DescriptorSetLayout const *> layout_nodes; |
| 263 | AllocateDescriptorSetsData(uint32_t); |
| 264 | }; |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 265 | // Helper functions for descriptor set functions that cross multiple sets |
| 266 | // "Validate" will make sure an update is ok without actually performing it |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 267 | bool ValidateUpdateDescriptorSets(const debug_report_data *, const core_validation::layer_data *, uint32_t, |
Tobin Ehlis | 56a3094 | 2016-05-19 08:00:00 -0600 | [diff] [blame] | 268 | const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 269 | // "Perform" does the update with the assumption that ValidateUpdateDescriptorSets() has passed for the given update |
Tobin Ehlis | 6a72dc7 | 2016-06-01 16:41:17 -0600 | [diff] [blame] | 270 | void PerformUpdateDescriptorSets(const core_validation::layer_data *, uint32_t, const VkWriteDescriptorSet *, uint32_t, |
| 271 | const VkCopyDescriptorSet *); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 272 | // Validate that Allocation state is ok |
| 273 | bool ValidateAllocateDescriptorSets(const debug_report_data *, const VkDescriptorSetAllocateInfo *, |
Tobin Ehlis | 815e813 | 2016-06-02 13:02:17 -0600 | [diff] [blame] | 274 | const core_validation::layer_data *, AllocateDescriptorSetsData *); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 275 | // Update state based on allocating new descriptorsets |
Tobin Ehlis | 997b258 | 2016-06-02 08:43:37 -0600 | [diff] [blame] | 276 | void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const VkDescriptorSet *, const AllocateDescriptorSetsData *, |
Tobin Ehlis | bd711bd | 2016-10-12 14:27:30 -0600 | [diff] [blame] | 277 | std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *, |
Tobin Ehlis | 997b258 | 2016-06-02 08:43:37 -0600 | [diff] [blame] | 278 | std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *, |
Tobin Ehlis | 4e38059 | 2016-06-02 12:41:47 -0600 | [diff] [blame] | 279 | const core_validation::layer_data *); |
Tobin Ehlis | ee47146 | 2016-05-26 11:21:59 -0600 | [diff] [blame] | 280 | |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 281 | /* |
| 282 | * DescriptorSet class |
| 283 | * |
| 284 | * Overview - This class encapsulates the Vulkan VkDescriptorSet data (set). |
| 285 | * A set has an underlying layout which defines the bindings in the set and the |
| 286 | * types and numbers of descriptors in each descriptor slot. Most of the layout |
| 287 | * interfaces are exposed through identically-named functions in the set class. |
| 288 | * Please refer to the DescriptorSetLayout comment above for a description of |
| 289 | * index, binding, and global index. |
| 290 | * |
| 291 | * At construction a vector of Descriptor* is created with types corresponding to the |
| 292 | * layout. The primary operation performed on the descriptors is to update them |
| 293 | * via write or copy updates, and validate that the update contents are correct. |
| 294 | * In order to validate update contents, the DescriptorSet stores a bunch of ptrs |
| 295 | * to data maps where various Vulkan objects can be looked up. The management of |
| 296 | * those maps is performed externally. The set class relies on their contents to |
| 297 | * be correct at the time of update. |
| 298 | */ |
Tobin Ehlis | 05be5df | 2016-05-05 08:25:02 -0600 | [diff] [blame] | 299 | class DescriptorSet : public BASE_NODE { |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 300 | public: |
Tobin Ehlis | 93f2237 | 2016-10-12 14:34:12 -0600 | [diff] [blame] | 301 | DescriptorSet(const VkDescriptorSet, const VkDescriptorPool, const DescriptorSetLayout *, const core_validation::layer_data *); |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 302 | ~DescriptorSet(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 303 | // A number of common Get* functions that return data based on layout from which this set was created |
| 304 | uint32_t GetTotalDescriptorCount() const { return p_layout_ ? p_layout_->GetTotalDescriptorCount() : 0; }; |
| 305 | uint32_t GetDynamicDescriptorCount() const { return p_layout_ ? p_layout_->GetDynamicDescriptorCount() : 0; }; |
| 306 | uint32_t GetBindingCount() const { return p_layout_ ? p_layout_->GetBindingCount() : 0; }; |
| 307 | VkDescriptorType GetTypeFromIndex(const uint32_t index) const { |
| 308 | return p_layout_ ? p_layout_->GetTypeFromIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 309 | }; |
| 310 | VkDescriptorType GetTypeFromGlobalIndex(const uint32_t index) const { |
| 311 | return p_layout_ ? p_layout_->GetTypeFromGlobalIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 312 | }; |
| 313 | VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { |
| 314 | return p_layout_ ? p_layout_->GetTypeFromBinding(binding) : VK_DESCRIPTOR_TYPE_MAX_ENUM; |
| 315 | }; |
| 316 | uint32_t GetDescriptorCountFromIndex(const uint32_t index) const { |
| 317 | return p_layout_ ? p_layout_->GetDescriptorCountFromIndex(index) : 0; |
| 318 | }; |
| 319 | uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const { |
| 320 | return p_layout_ ? p_layout_->GetDescriptorCountFromBinding(binding) : 0; |
| 321 | }; |
| 322 | // Return true if given binding is present in this set |
| 323 | bool HasBinding(const uint32_t binding) const { return p_layout_->HasBinding(binding); }; |
| 324 | // Is this set compatible with the given layout? |
| 325 | bool IsCompatible(const DescriptorSetLayout *, std::string *) const; |
| 326 | // For given bindings validate state at time of draw is correct, returning false on error and writing error details into string* |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 327 | bool ValidateDrawState(const std::map<uint32_t, descriptor_req> &, const std::vector<uint32_t> &, std::string *) const; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 328 | // For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number |
| 329 | // of objects inserted |
Tobin Ehlis | cebc4c0 | 2016-08-22 10:10:43 -0600 | [diff] [blame] | 330 | uint32_t GetStorageUpdates(const std::map<uint32_t, descriptor_req> &, std::unordered_set<VkBuffer> *, |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 331 | std::unordered_set<VkImageView> *) const; |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 332 | |
| 333 | // Descriptor Update functions. These functions validate state and perform update separately |
| 334 | // Validate contents of a WriteUpdate |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 335 | bool ValidateWriteUpdate(const debug_report_data *, const VkWriteDescriptorSet *, UNIQUE_VALIDATION_ERROR_CODE *, |
| 336 | std::string *); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 337 | // Perform a WriteUpdate whose contents were just validated using ValidateWriteUpdate |
| 338 | void PerformWriteUpdate(const VkWriteDescriptorSet *); |
| 339 | // Validate contents of a CopyUpdate |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 340 | bool ValidateCopyUpdate(const debug_report_data *, const VkCopyDescriptorSet *, const DescriptorSet *, |
| 341 | UNIQUE_VALIDATION_ERROR_CODE *, std::string *); |
Tobin Ehlis | 300888c | 2016-05-18 13:43:26 -0600 | [diff] [blame] | 342 | // Perform a CopyUpdate whose contents were just validated using ValidateCopyUpdate |
| 343 | void PerformCopyUpdate(const VkCopyDescriptorSet *, const DescriptorSet *); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 344 | |
Tobin Ehlis | 1f946f8 | 2016-05-05 12:03:44 -0600 | [diff] [blame] | 345 | const DescriptorSetLayout *GetLayout() const { return p_layout_; }; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 346 | VkDescriptorSet GetSet() const { return set_; }; |
| 347 | // Return unordered_set of all command buffers that this set is bound to |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 348 | std::unordered_set<GLOBAL_CB_NODE *> GetBoundCmdBuffers() const { return cb_bindings; } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 349 | // Bind given cmd_buffer to this descriptor set |
Tobin Ehlis | f951910 | 2016-08-17 09:49:13 -0600 | [diff] [blame] | 350 | void BindCommandBuffer(GLOBAL_CB_NODE *, const std::unordered_set<uint32_t> &); |
Tobin Ehlis | 2556f5b | 2016-06-24 17:22:16 -0600 | [diff] [blame] | 351 | // If given cmd_buffer is in the cb_bindings set, remove it |
| 352 | void RemoveBoundCommandBuffer(GLOBAL_CB_NODE *cb_node) { cb_bindings.erase(cb_node); } |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 353 | VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t index) const { |
| 354 | return p_layout_->GetImmutableSamplerPtrFromBinding(index); |
| 355 | }; |
| 356 | // For a particular binding, get the global index |
| 357 | uint32_t GetGlobalStartIndexFromBinding(const uint32_t binding) const { |
| 358 | return p_layout_->GetGlobalStartIndexFromBinding(binding); |
| 359 | }; |
| 360 | uint32_t GetGlobalEndIndexFromBinding(const uint32_t binding) const { |
| 361 | return p_layout_->GetGlobalEndIndexFromBinding(binding); |
| 362 | }; |
| 363 | // Return true if any part of set has ever been updated |
| 364 | bool IsUpdated() const { return some_update_; }; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 365 | |
| 366 | private: |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 367 | bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, UNIQUE_VALIDATION_ERROR_CODE *, |
| 368 | std::string *) const; |
Tobin Ehlis | cbcf234 | 2016-05-24 13:07:12 -0600 | [diff] [blame] | 369 | bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, VkDescriptorType, uint32_t, |
Tobin Ehlis | 75f04ec | 2016-10-06 17:43:11 -0600 | [diff] [blame] | 370 | UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const; |
| 371 | bool ValidateBufferUsage(BUFFER_NODE const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const; |
| 372 | bool ValidateBufferUpdate(VkDescriptorBufferInfo const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *, |
| 373 | std::string *) const; |
Tobin Ehlis | 9906d9d | 2016-05-17 14:23:46 -0600 | [diff] [blame] | 374 | // Private helper to set all bound cmd buffers to INVALID state |
| 375 | void InvalidateBoundCmdBuffers(); |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 376 | bool some_update_; // has any part of the set ever been updated? |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 377 | VkDescriptorSet set_; |
Tobin Ehlis | 7ca20be | 2016-10-12 15:09:16 -0600 | [diff] [blame] | 378 | DESCRIPTOR_POOL_STATE *pool_state_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 379 | const DescriptorSetLayout *p_layout_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 380 | std::vector<std::unique_ptr<Descriptor>> descriptors_; |
Tobin Ehlis | 3d15c4a | 2016-06-02 13:04:47 -0600 | [diff] [blame] | 381 | // Ptr to device data used for various data look-ups |
Tobin Ehlis | 94bc5d2 | 2016-06-02 07:46:52 -0600 | [diff] [blame] | 382 | const core_validation::layer_data *device_data_; |
Tobin Ehlis | 0a43bde | 2016-05-03 08:31:08 -0600 | [diff] [blame] | 383 | }; |
Tobin Ehlis | 2d9deec | 2016-04-21 14:19:26 -0600 | [diff] [blame] | 384 | } |
Chris Forbes | 6f6844a | 2016-04-27 14:00:44 +1200 | [diff] [blame] | 385 | #endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_ |