blob: b9103ec7c866051c85f808ce0c5b8f8ec8eaebb2 [file] [log] [blame]
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06001/* 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 Lobodzinskia5efa732016-10-10 14:05:59 -060024#ifndef NOEXCEPT
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060025#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 Lobodzinskia5efa732016-10-10 14:05:59 -060044#endif
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060045
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060046#include "core_validation_error_enums.h"
Tobin Ehlisbf98b692016-10-06 12:58:06 -060047#include "vk_validation_error_messages.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060048#include "core_validation_types.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060049#include "vk_layer_logging.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060050#include "vk_layer_utils.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060051#include "vk_safe_struct.h"
52#include "vulkan/vk_layer.h"
Tobin Ehliscebc4c02016-08-22 10:10:43 -060053#include <map>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060054#include <memory>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060055#include <unordered_map>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060056#include <unordered_set>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060057#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 Ehlis0a43bde2016-05-03 08:31:08 -060088namespace cvdescriptorset {
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060089class DescriptorSetLayout {
90 public:
91 // Constructors and destructor
Tobin Ehlis154c2692016-10-25 09:36:53 -060092 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 Ehlis2d9deec2016-04-21 14:19:26 -060095 // Straightforward Get functions
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060096 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 Ehlis2d9deec2016-04-21 14:19:26 -0600102 // Return true if given binding is present in this layout
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600103 bool HasBinding(const uint32_t binding) const { return binding_to_index_map_.count(binding) > 0; };
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600104 // Return true if this layout is compatible with passed in layout,
105 // else return false and update error_msg with description of incompatibility
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600106 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 Ehlis2d9deec2016-04-21 14:19:26 -0600109 // 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 Ehlis0a43bde2016-05-03 08:31:08 -0600112 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 Ehlisa3525e02016-11-17 10:50:52 -0700122 // For a given binding and array index, return the corresponding index into the dynamic offset array
123 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const {
124 auto dyn_off = binding_to_dynamic_array_idx_map_.find(binding);
125 if (dyn_off == binding_to_dynamic_array_idx_map_.end()) {
126 assert(0); // Requesting dyn offset for invalid binding/array idx pair
127 return -1;
128 }
129 return dyn_off->second;
130 }
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600131 // For a particular binding, get the global index
Tobin Ehlis58c59582016-06-21 12:34:33 -0600132 // These calls should be guarded by a call to "HasBinding(binding)" to verify that the given binding exists
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600133 uint32_t GetGlobalStartIndexFromBinding(const uint32_t) const;
134 uint32_t GetGlobalEndIndexFromBinding(const uint32_t) const;
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600135 // For a particular binding starting at offset and having update_count descriptors
136 // updated, verify that for any binding boundaries crossed, the update is consistent
137 bool VerifyUpdateConsistency(uint32_t, uint32_t, uint32_t, const char *, const VkDescriptorSet, std::string *) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600138
139 private:
140 VkDescriptorSetLayout layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600141 std::unordered_map<uint32_t, uint32_t> binding_to_index_map_;
142 std::unordered_map<uint32_t, uint32_t> binding_to_global_start_index_map_;
143 std::unordered_map<uint32_t, uint32_t> binding_to_global_end_index_map_;
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700144 // For a given binding map to associated index in the dynamic offset array
145 std::unordered_map<uint32_t, uint32_t> binding_to_dynamic_array_idx_map_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600146 // VkDescriptorSetLayoutCreateFlags flags_;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600147 uint32_t binding_count_; // # of bindings in this layout
Tobin Ehlis664e6012016-05-05 11:04:44 -0600148 std::vector<safe_VkDescriptorSetLayoutBinding> bindings_;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600149 uint32_t descriptor_count_; // total # descriptors in this layout
150 uint32_t dynamic_descriptor_count_;
151};
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600152
153/*
154 * Descriptor classes
155 * Descriptor is an abstract base class from which 5 separate descriptor types are derived.
156 * This allows the WriteUpdate() and CopyUpdate() operations to be specialized per
157 * descriptor type, but all descriptors in a set can be accessed via the common Descriptor*.
158 */
159
160// Slightly broader than type, each c++ "class" will has a corresponding "DescriptorClass"
Mark Lobodzinski0978f5f2016-05-19 17:23:38 -0600161enum DescriptorClass { PlainSampler, ImageSampler, Image, TexelBuffer, GeneralBuffer };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600162
163class Descriptor {
164 public:
165 virtual ~Descriptor(){};
Tobin Ehlis300888c2016-05-18 13:43:26 -0600166 virtual void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) = 0;
167 virtual void CopyUpdate(const Descriptor *) = 0;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600168 // Create binding between resources of this descriptor and given cb_node
169 virtual void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) = 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600170 virtual DescriptorClass GetClass() const { return descriptor_class; };
171 // Special fast-path check for SamplerDescriptors that are immutable
172 virtual bool IsImmutableSampler() const { return false; };
173 // Check for dynamic descriptor type
174 virtual bool IsDynamic() const { return false; };
175 // Check for storage descriptor type
176 virtual bool IsStorage() const { return false; };
177 bool updated; // Has descriptor been updated?
178 DescriptorClass descriptor_class;
179};
180// Shared helper functions - These are useful because the shared sampler image descriptor type
181// performs common functions with both sampler and image descriptors so they can share their common functions
Tobin Ehlise2f80292016-06-02 10:08:53 -0600182bool ValidateSampler(const VkSampler, const core_validation::layer_data *);
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600183bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *,
184 UNIQUE_VALIDATION_ERROR_CODE *, std::string *);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600185
186class SamplerDescriptor : public Descriptor {
187 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600188 SamplerDescriptor();
189 SamplerDescriptor(const VkSampler *);
190 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
191 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600192 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600193 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600194 VkSampler GetSampler() const { return sampler_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600195
196 private:
197 // bool ValidateSampler(const VkSampler) const;
198 VkSampler sampler_;
199 bool immutable_;
Tobin Ehlis546326f2016-04-26 11:06:05 -0600200};
201
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600202class ImageSamplerDescriptor : public Descriptor {
203 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600204 ImageSamplerDescriptor();
205 ImageSamplerDescriptor(const VkSampler *);
206 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
207 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600208 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlisc9625152016-05-24 16:47:36 -0600209 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600210 VkSampler GetSampler() const { return sampler_; }
211 VkImageView GetImageView() const { return image_view_; }
212 VkImageLayout GetImageLayout() const { return image_layout_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600213
214 private:
215 VkSampler sampler_;
216 bool immutable_;
217 VkImageView image_view_;
218 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600219};
220
221class ImageDescriptor : public Descriptor {
222 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600223 ImageDescriptor(const VkDescriptorType);
224 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
225 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600226 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Norbert Nopper419a1092016-05-15 19:19:41 +0200227 virtual bool IsStorage() const override { return storage_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600228 VkImageView GetImageView() const { return image_view_; }
229 VkImageLayout GetImageLayout() const { return image_layout_; }
230
231 private:
232 bool storage_;
233 VkImageView image_view_;
234 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600235};
236
237class TexelDescriptor : public Descriptor {
238 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600239 TexelDescriptor(const VkDescriptorType);
240 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
241 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600242 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlisf490f2e2016-05-17 06:43:48 -0600243 virtual bool IsStorage() const override { return storage_; }
244 VkBufferView GetBufferView() const { return buffer_view_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600245
246 private:
247 VkBufferView buffer_view_;
248 bool storage_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600249};
250
251class BufferDescriptor : public Descriptor {
252 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600253 BufferDescriptor(const VkDescriptorType);
254 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
255 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600256 void BindCommandBuffer(const core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600257 virtual bool IsDynamic() const override { return dynamic_; }
258 virtual bool IsStorage() const override { return storage_; }
259 VkBuffer GetBuffer() const { return buffer_; }
260 VkDeviceSize GetOffset() const { return offset_; }
261 VkDeviceSize GetRange() const { return range_; }
262
263 private:
264 bool storage_;
265 bool dynamic_;
266 VkBuffer buffer_;
267 VkDeviceSize offset_;
268 VkDeviceSize range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600269};
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600270// Structs to contain common elements that need to be shared between Validate* and Perform* calls below
271struct AllocateDescriptorSetsData {
272 uint32_t required_descriptors_by_type[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
273 std::vector<cvdescriptorset::DescriptorSetLayout const *> layout_nodes;
274 AllocateDescriptorSetsData(uint32_t);
275};
Tobin Ehlisee471462016-05-26 11:21:59 -0600276// Helper functions for descriptor set functions that cross multiple sets
277// "Validate" will make sure an update is ok without actually performing it
Tobin Ehlis6a72dc72016-06-01 16:41:17 -0600278bool ValidateUpdateDescriptorSets(const debug_report_data *, const core_validation::layer_data *, uint32_t,
Tobin Ehlis56a30942016-05-19 08:00:00 -0600279 const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600280// "Perform" does the update with the assumption that ValidateUpdateDescriptorSets() has passed for the given update
Tobin Ehlis6a72dc72016-06-01 16:41:17 -0600281void PerformUpdateDescriptorSets(const core_validation::layer_data *, uint32_t, const VkWriteDescriptorSet *, uint32_t,
282 const VkCopyDescriptorSet *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600283// Validate that Allocation state is ok
284bool ValidateAllocateDescriptorSets(const debug_report_data *, const VkDescriptorSetAllocateInfo *,
Tobin Ehlis815e8132016-06-02 13:02:17 -0600285 const core_validation::layer_data *, AllocateDescriptorSetsData *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600286// Update state based on allocating new descriptorsets
Tobin Ehlis997b2582016-06-02 08:43:37 -0600287void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const VkDescriptorSet *, const AllocateDescriptorSetsData *,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -0600288 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *,
Tobin Ehlis997b2582016-06-02 08:43:37 -0600289 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *,
Tobin Ehlis4e380592016-06-02 12:41:47 -0600290 const core_validation::layer_data *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600291
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600292/*
293 * DescriptorSet class
294 *
295 * Overview - This class encapsulates the Vulkan VkDescriptorSet data (set).
296 * A set has an underlying layout which defines the bindings in the set and the
297 * types and numbers of descriptors in each descriptor slot. Most of the layout
298 * interfaces are exposed through identically-named functions in the set class.
299 * Please refer to the DescriptorSetLayout comment above for a description of
300 * index, binding, and global index.
301 *
302 * At construction a vector of Descriptor* is created with types corresponding to the
303 * layout. The primary operation performed on the descriptors is to update them
304 * via write or copy updates, and validate that the update contents are correct.
305 * In order to validate update contents, the DescriptorSet stores a bunch of ptrs
306 * to data maps where various Vulkan objects can be looked up. The management of
307 * those maps is performed externally. The set class relies on their contents to
308 * be correct at the time of update.
309 */
Tobin Ehlis05be5df2016-05-05 08:25:02 -0600310class DescriptorSet : public BASE_NODE {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600311 public:
Tobin Ehlis93f22372016-10-12 14:34:12 -0600312 DescriptorSet(const VkDescriptorSet, const VkDescriptorPool, const DescriptorSetLayout *, const core_validation::layer_data *);
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600313 ~DescriptorSet();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600314 // A number of common Get* functions that return data based on layout from which this set was created
315 uint32_t GetTotalDescriptorCount() const { return p_layout_ ? p_layout_->GetTotalDescriptorCount() : 0; };
316 uint32_t GetDynamicDescriptorCount() const { return p_layout_ ? p_layout_->GetDynamicDescriptorCount() : 0; };
317 uint32_t GetBindingCount() const { return p_layout_ ? p_layout_->GetBindingCount() : 0; };
318 VkDescriptorType GetTypeFromIndex(const uint32_t index) const {
319 return p_layout_ ? p_layout_->GetTypeFromIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
320 };
321 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t index) const {
322 return p_layout_ ? p_layout_->GetTypeFromGlobalIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
323 };
324 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const {
325 return p_layout_ ? p_layout_->GetTypeFromBinding(binding) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
326 };
327 uint32_t GetDescriptorCountFromIndex(const uint32_t index) const {
328 return p_layout_ ? p_layout_->GetDescriptorCountFromIndex(index) : 0;
329 };
330 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const {
331 return p_layout_ ? p_layout_->GetDescriptorCountFromBinding(binding) : 0;
332 };
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700333 // Return index into dynamic offset array for given binding
334 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const {
335 return p_layout_ ? p_layout_->GetDynamicOffsetIndexFromBinding(binding) : -1;
336 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600337 // Return true if given binding is present in this set
338 bool HasBinding(const uint32_t binding) const { return p_layout_->HasBinding(binding); };
339 // Is this set compatible with the given layout?
340 bool IsCompatible(const DescriptorSetLayout *, std::string *) const;
341 // For given bindings validate state at time of draw is correct, returning false on error and writing error details into string*
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600342 bool ValidateDrawState(const std::map<uint32_t, descriptor_req> &, const std::vector<uint32_t> &, std::string *) const;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600343 // For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number
344 // of objects inserted
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600345 uint32_t GetStorageUpdates(const std::map<uint32_t, descriptor_req> &, std::unordered_set<VkBuffer> *,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600346 std::unordered_set<VkImageView> *) const;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600347
348 // Descriptor Update functions. These functions validate state and perform update separately
349 // Validate contents of a WriteUpdate
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600350 bool ValidateWriteUpdate(const debug_report_data *, const VkWriteDescriptorSet *, UNIQUE_VALIDATION_ERROR_CODE *,
351 std::string *);
Tobin Ehlis300888c2016-05-18 13:43:26 -0600352 // Perform a WriteUpdate whose contents were just validated using ValidateWriteUpdate
353 void PerformWriteUpdate(const VkWriteDescriptorSet *);
354 // Validate contents of a CopyUpdate
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600355 bool ValidateCopyUpdate(const debug_report_data *, const VkCopyDescriptorSet *, const DescriptorSet *,
356 UNIQUE_VALIDATION_ERROR_CODE *, std::string *);
Tobin Ehlis300888c2016-05-18 13:43:26 -0600357 // Perform a CopyUpdate whose contents were just validated using ValidateCopyUpdate
358 void PerformCopyUpdate(const VkCopyDescriptorSet *, const DescriptorSet *);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600359
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600360 const DescriptorSetLayout *GetLayout() const { return p_layout_; };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600361 VkDescriptorSet GetSet() const { return set_; };
362 // Return unordered_set of all command buffers that this set is bound to
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600363 std::unordered_set<GLOBAL_CB_NODE *> GetBoundCmdBuffers() const { return cb_bindings; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600364 // Bind given cmd_buffer to this descriptor set
Tobin Ehlisf9519102016-08-17 09:49:13 -0600365 void BindCommandBuffer(GLOBAL_CB_NODE *, const std::unordered_set<uint32_t> &);
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600366 // If given cmd_buffer is in the cb_bindings set, remove it
367 void RemoveBoundCommandBuffer(GLOBAL_CB_NODE *cb_node) { cb_bindings.erase(cb_node); }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600368 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t index) const {
369 return p_layout_->GetImmutableSamplerPtrFromBinding(index);
370 };
371 // For a particular binding, get the global index
372 uint32_t GetGlobalStartIndexFromBinding(const uint32_t binding) const {
373 return p_layout_->GetGlobalStartIndexFromBinding(binding);
374 };
375 uint32_t GetGlobalEndIndexFromBinding(const uint32_t binding) const {
376 return p_layout_->GetGlobalEndIndexFromBinding(binding);
377 };
378 // Return true if any part of set has ever been updated
379 bool IsUpdated() const { return some_update_; };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600380
381 private:
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600382 bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, UNIQUE_VALIDATION_ERROR_CODE *,
383 std::string *) const;
Tobin Ehliscbcf2342016-05-24 13:07:12 -0600384 bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, VkDescriptorType, uint32_t,
Tobin Ehlis75f04ec2016-10-06 17:43:11 -0600385 UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const;
386 bool ValidateBufferUsage(BUFFER_NODE const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *, std::string *) const;
387 bool ValidateBufferUpdate(VkDescriptorBufferInfo const *, VkDescriptorType, UNIQUE_VALIDATION_ERROR_CODE *,
388 std::string *) const;
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600389 // Private helper to set all bound cmd buffers to INVALID state
390 void InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600391 bool some_update_; // has any part of the set ever been updated?
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600392 VkDescriptorSet set_;
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600393 DESCRIPTOR_POOL_STATE *pool_state_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600394 const DescriptorSetLayout *p_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600395 std::vector<std::unique_ptr<Descriptor>> descriptors_;
Tobin Ehlis3d15c4a2016-06-02 13:04:47 -0600396 // Ptr to device data used for various data look-ups
Tobin Ehlis94bc5d22016-06-02 07:46:52 -0600397 const core_validation::layer_data *device_data_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600398};
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600399}
Chris Forbes6f6844a2016-04-27 14:00:44 +1200400#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_