blob: af062dd753999d163d7eb7c469393b5f09ce6f0b [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
24#if defined(__clang__)
25#if __has_feature(cxx_noexcept)
26#define HAS_NOEXCEPT
27#endif
28#else
29#if defined(__GXX_EXPERIMENTAL_CXX0X__) && __GNUC__ * 10 + __GNUC_MINOR__ >= 46
30#define HAS_NOEXCEPT
31#else
32#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026 && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS
33#define HAS_NOEXCEPT
34#endif
35#endif
36#endif
37
38#ifdef HAS_NOEXCEPT
39#define NOEXCEPT noexcept
40#else
41#define NOEXCEPT
42#endif
43
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060044#include "core_validation_error_enums.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060045#include "core_validation_types.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060046#include "vk_layer_logging.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060047#include "vk_layer_utils.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060048#include "vk_safe_struct.h"
49#include "vulkan/vk_layer.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060050#include <memory>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060051#include <unordered_map>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060052#include <unordered_set>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060053#include <vector>
54
55// Descriptor Data structures
56
57/*
58 * DescriptorSetLayout class
59 *
60 * Overview - This class encapsulates the Vulkan VkDescriptorSetLayout data (layout).
61 * A layout consists of some number of bindings, each of which has a binding#, a
62 * type, descriptor count, stage flags, and pImmutableSamplers.
63 *
64 * Index vs Binding - A layout is created with an array of VkDescriptorSetLayoutBinding
65 * where each array index will have a corresponding binding# that is defined in that struct.
66 * This class, therefore, provides utility functions where you can retrieve data for
67 * layout bindings based on either the original index into the pBindings array, or based
68 * on the binding#.
69 * Typically if you want to cover all of the bindings in a layout, you can do that by
70 * iterating over GetBindingCount() bindings and using the Get*FromIndex() functions.
71 * Otherwise, you can use the Get*FromBinding() functions to just grab binding info
72 * for a particular binding#.
73 *
74 * Global Index - The "Index" referenced above is the index into the original pBindings
75 * array. So there are 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 pBinding[0] is index 0 and each descriptor in the layout increments
80 * from there. So if pBinding[0] in this example had descriptorCount of 10, then
81 * the GlobalStartIndex of pBinding[1] will be 10 where 0-9 are the global indices
82 * for pBinding[0].
83 */
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060084namespace cvdescriptorset {
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060085class DescriptorSetLayout {
86 public:
87 // Constructors and destructor
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060088 DescriptorSetLayout(debug_report_data *report_data, const VkDescriptorSetLayoutCreateInfo *p_create_info,
89 const VkDescriptorSetLayout layout);
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060090 // Straightforward Get functions
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060091 VkDescriptorSetLayout GetDescriptorSetLayout() const { return layout_; };
92 uint32_t GetTotalDescriptorCount() const { return descriptor_count_; };
93 uint32_t GetDynamicDescriptorCount() const { return dynamic_descriptor_count_; };
94 uint32_t GetBindingCount() const { return binding_count_; };
95 // Fill passed-in set with bindings
96 void FillBindingSet(std::unordered_set<uint32_t> *) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060097 // Return true if given binding is present in this layout
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060098 bool HasBinding(const uint32_t binding) const { return binding_to_index_map_.count(binding) > 0; };
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060099 // Return true if this layout is compatible with passed in layout,
100 // else return false and update error_msg with description of incompatibility
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600101 bool IsCompatible(const DescriptorSetLayout *, std::string *) const;
102 // Return true if binding 1 beyond given exists and has same type, stageFlags & immutable sampler use
103 bool IsNextBindingConsistent(const uint32_t) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600104 // Various Get functions that can either be passed a binding#, which will
105 // be automatically translated into the appropriate index from the original
106 // pBindings array, or the index# can be passed in directly
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600107 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t) const;
108 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t) const;
109 uint32_t GetDescriptorCountFromBinding(const uint32_t) const;
110 uint32_t GetDescriptorCountFromIndex(const uint32_t) const;
111 VkDescriptorType GetTypeFromBinding(const uint32_t) const;
112 VkDescriptorType GetTypeFromIndex(const uint32_t) const;
113 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t) const;
114 VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t) const;
115 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t) const;
116 VkSampler const *GetImmutableSamplerPtrFromIndex(const uint32_t) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600117 // For a particular binding, get the global index
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600118 uint32_t GetGlobalStartIndexFromBinding(const uint32_t) const;
119 uint32_t GetGlobalEndIndexFromBinding(const uint32_t) const;
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600120 // For a particular binding starting at offset and having update_count descriptors
121 // updated, verify that for any binding boundaries crossed, the update is consistent
122 bool VerifyUpdateConsistency(uint32_t, uint32_t, uint32_t, const char *, const VkDescriptorSet, std::string *) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600123
124 private:
125 VkDescriptorSetLayout layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600126 std::unordered_map<uint32_t, uint32_t> binding_to_index_map_;
127 std::unordered_map<uint32_t, uint32_t> binding_to_global_start_index_map_;
128 std::unordered_map<uint32_t, uint32_t> binding_to_global_end_index_map_;
129 // VkDescriptorSetLayoutCreateFlags flags_;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600130 uint32_t binding_count_; // # of bindings in this layout
Tobin Ehlis664e6012016-05-05 11:04:44 -0600131 std::vector<safe_VkDescriptorSetLayoutBinding> bindings_;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600132 uint32_t descriptor_count_; // total # descriptors in this layout
133 uint32_t dynamic_descriptor_count_;
134};
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600135
136/*
137 * Descriptor classes
138 * Descriptor is an abstract base class from which 5 separate descriptor types are derived.
139 * This allows the WriteUpdate() and CopyUpdate() operations to be specialized per
140 * descriptor type, but all descriptors in a set can be accessed via the common Descriptor*.
141 */
142
143// Slightly broader than type, each c++ "class" will has a corresponding "DescriptorClass"
Mark Lobodzinski0978f5f2016-05-19 17:23:38 -0600144enum DescriptorClass { PlainSampler, ImageSampler, Image, TexelBuffer, GeneralBuffer };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600145
146class Descriptor {
147 public:
148 virtual ~Descriptor(){};
Tobin Ehlis300888c2016-05-18 13:43:26 -0600149 virtual void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) = 0;
150 virtual void CopyUpdate(const Descriptor *) = 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600151 virtual DescriptorClass GetClass() const { return descriptor_class; };
152 // Special fast-path check for SamplerDescriptors that are immutable
153 virtual bool IsImmutableSampler() const { return false; };
154 // Check for dynamic descriptor type
155 virtual bool IsDynamic() const { return false; };
156 // Check for storage descriptor type
157 virtual bool IsStorage() const { return false; };
158 bool updated; // Has descriptor been updated?
159 DescriptorClass descriptor_class;
160};
161// Shared helper functions - These are useful because the shared sampler image descriptor type
162// performs common functions with both sampler and image descriptors so they can share their common functions
163bool ValidateSampler(const VkSampler, const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *);
Tobin Ehlis554bf382016-05-24 11:14:43 -0600164bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType,
165 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600166 const std::unordered_map<VkImage, IMAGE_NODE> *, const std::unordered_map<VkImage, VkSwapchainKHR> *,
167 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *, std::string *);
168
169class SamplerDescriptor : public Descriptor {
170 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600171 SamplerDescriptor();
172 SamplerDescriptor(const VkSampler *);
173 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
174 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600175 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600176 VkSampler GetSampler() const { return sampler_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600177
178 private:
179 // bool ValidateSampler(const VkSampler) const;
180 VkSampler sampler_;
181 bool immutable_;
Tobin Ehlis546326f2016-04-26 11:06:05 -0600182};
183
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600184class ImageSamplerDescriptor : public Descriptor {
185 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600186 ImageSamplerDescriptor();
187 ImageSamplerDescriptor(const VkSampler *);
188 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
189 void CopyUpdate(const Descriptor *) override;
Tobin Ehlisc9625152016-05-24 16:47:36 -0600190 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600191 VkSampler GetSampler() const { return sampler_; }
192 VkImageView GetImageView() const { return image_view_; }
193 VkImageLayout GetImageLayout() const { return image_layout_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600194
195 private:
196 VkSampler sampler_;
197 bool immutable_;
198 VkImageView image_view_;
199 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600200};
201
202class ImageDescriptor : public Descriptor {
203 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600204 ImageDescriptor(const VkDescriptorType);
205 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
206 void CopyUpdate(const Descriptor *) override;
Norbert Nopper419a1092016-05-15 19:19:41 +0200207 virtual bool IsStorage() const override { return storage_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600208 VkImageView GetImageView() const { return image_view_; }
209 VkImageLayout GetImageLayout() const { return image_layout_; }
210
211 private:
212 bool storage_;
213 VkImageView image_view_;
214 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600215};
216
217class TexelDescriptor : public Descriptor {
218 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600219 TexelDescriptor(const VkDescriptorType);
220 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
221 void CopyUpdate(const Descriptor *) override;
Tobin Ehlisf490f2e2016-05-17 06:43:48 -0600222 virtual bool IsStorage() const override { return storage_; }
223 VkBufferView GetBufferView() const { return buffer_view_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600224
225 private:
226 VkBufferView buffer_view_;
227 bool storage_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600228};
229
230class BufferDescriptor : public Descriptor {
231 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600232 BufferDescriptor(const VkDescriptorType);
233 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
234 void CopyUpdate(const Descriptor *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600235 virtual bool IsDynamic() const override { return dynamic_; }
236 virtual bool IsStorage() const override { return storage_; }
237 VkBuffer GetBuffer() const { return buffer_; }
238 VkDeviceSize GetOffset() const { return offset_; }
239 VkDeviceSize GetRange() const { return range_; }
240
241 private:
242 bool storage_;
243 bool dynamic_;
244 VkBuffer buffer_;
245 VkDeviceSize offset_;
246 VkDeviceSize range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600247};
Tobin Ehlisee471462016-05-26 11:21:59 -0600248// Helper functions for descriptor set functions that cross multiple sets
249// "Validate" will make sure an update is ok without actually performing it
Tobin Ehlis300888c2016-05-18 13:43:26 -0600250bool ValidateUpdateDescriptorSets(const debug_report_data *,
Tobin Ehlis56a30942016-05-19 08:00:00 -0600251 const std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> &, uint32_t,
252 const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600253// "Perform" does the update with the assumption that ValidateUpdateDescriptorSets() has passed for the given update
Tobin Ehlis56a30942016-05-19 08:00:00 -0600254void PerformUpdateDescriptorSets(const std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> &, uint32_t,
255 const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600256// Validate that Allocation state is ok
257bool ValidateAllocateDescriptorSets(const debug_report_data *, const VkDescriptorSetAllocateInfo *,
258 const std::unordered_map<VkDescriptorSetLayout, cvdescriptorset::DescriptorSetLayout *> &,
259 const std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE *> &);
260// Update state based on allocating new descriptorsets
261void PerformAllocateDescriptorSets(
262 const VkDescriptorSetAllocateInfo *, const VkDescriptorSet *, std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE *> *,
263 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *,
264 const std::unordered_map<VkDescriptorSetLayout, cvdescriptorset::DescriptorSetLayout *> &,
265 const std::unordered_map<VkBuffer, BUFFER_NODE> &, const std::unordered_map<VkDeviceMemory, DEVICE_MEM_INFO> &,
266 const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> &,
267 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> &,
268 const std::unordered_map<VkImageView, VkImageViewCreateInfo> &, const std::unordered_map<VkImage, IMAGE_NODE> &,
269 const std::unordered_map<VkImage, VkSwapchainKHR> &, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> &);
270
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600271/*
272 * DescriptorSet class
273 *
274 * Overview - This class encapsulates the Vulkan VkDescriptorSet data (set).
275 * A set has an underlying layout which defines the bindings in the set and the
276 * types and numbers of descriptors in each descriptor slot. Most of the layout
277 * interfaces are exposed through identically-named functions in the set class.
278 * Please refer to the DescriptorSetLayout comment above for a description of
279 * index, binding, and global index.
280 *
281 * At construction a vector of Descriptor* is created with types corresponding to the
282 * layout. The primary operation performed on the descriptors is to update them
283 * via write or copy updates, and validate that the update contents are correct.
284 * In order to validate update contents, the DescriptorSet stores a bunch of ptrs
285 * to data maps where various Vulkan objects can be looked up. The management of
286 * those maps is performed externally. The set class relies on their contents to
287 * be correct at the time of update.
288 */
Tobin Ehlis05be5df2016-05-05 08:25:02 -0600289class DescriptorSet : public BASE_NODE {
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600290 public:
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600291 using BASE_NODE::in_use;
Tobin Ehlis56a30942016-05-19 08:00:00 -0600292 DescriptorSet(const VkDescriptorSet, const DescriptorSetLayout *, const std::unordered_map<VkBuffer, BUFFER_NODE> *,
293 const std::unordered_map<VkDeviceMemory, DEVICE_MEM_INFO> *,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600294 const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> *,
295 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *,
296 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *, const std::unordered_map<VkImage, IMAGE_NODE> *,
297 const std::unordered_map<VkImage, VkSwapchainKHR> *,
298 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *);
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600299 ~DescriptorSet();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600300 // A number of common Get* functions that return data based on layout from which this set was created
301 uint32_t GetTotalDescriptorCount() const { return p_layout_ ? p_layout_->GetTotalDescriptorCount() : 0; };
302 uint32_t GetDynamicDescriptorCount() const { return p_layout_ ? p_layout_->GetDynamicDescriptorCount() : 0; };
303 uint32_t GetBindingCount() const { return p_layout_ ? p_layout_->GetBindingCount() : 0; };
304 VkDescriptorType GetTypeFromIndex(const uint32_t index) const {
305 return p_layout_ ? p_layout_->GetTypeFromIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
306 };
307 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t index) const {
308 return p_layout_ ? p_layout_->GetTypeFromGlobalIndex(index) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
309 };
310 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const {
311 return p_layout_ ? p_layout_->GetTypeFromBinding(binding) : VK_DESCRIPTOR_TYPE_MAX_ENUM;
312 };
313 uint32_t GetDescriptorCountFromIndex(const uint32_t index) const {
314 return p_layout_ ? p_layout_->GetDescriptorCountFromIndex(index) : 0;
315 };
316 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const {
317 return p_layout_ ? p_layout_->GetDescriptorCountFromBinding(binding) : 0;
318 };
319 // Return true if given binding is present in this set
320 bool HasBinding(const uint32_t binding) const { return p_layout_->HasBinding(binding); };
321 // Is this set compatible with the given layout?
322 bool IsCompatible(const DescriptorSetLayout *, std::string *) const;
323 // For given bindings validate state at time of draw is correct, returning false on error and writing error details into string*
324 bool ValidateDrawState(const std::unordered_set<uint32_t> &, const std::vector<uint32_t> &, std::string *) const;
325 // For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number
326 // of objects inserted
327 uint32_t GetStorageUpdates(const std::unordered_set<uint32_t> &, std::unordered_set<VkBuffer> *,
328 std::unordered_set<VkImageView> *) const;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600329
330 // Descriptor Update functions. These functions validate state and perform update separately
331 // Validate contents of a WriteUpdate
332 bool ValidateWriteUpdate(const debug_report_data *, const VkWriteDescriptorSet *, std::string *);
333 // Perform a WriteUpdate whose contents were just validated using ValidateWriteUpdate
334 void PerformWriteUpdate(const VkWriteDescriptorSet *);
335 // Validate contents of a CopyUpdate
336 bool ValidateCopyUpdate(const debug_report_data *, const VkCopyDescriptorSet *, const DescriptorSet *, std::string *);
337 // Perform a CopyUpdate whose contents were just validated using ValidateCopyUpdate
338 void PerformCopyUpdate(const VkCopyDescriptorSet *, const DescriptorSet *);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600339
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600340 const DescriptorSetLayout *GetLayout() const { return p_layout_; };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600341 VkDescriptorSet GetSet() const { return set_; };
342 // Return unordered_set of all command buffers that this set is bound to
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600343 std::unordered_set<GLOBAL_CB_NODE *> GetBoundCmdBuffers() const { return bound_cmd_buffers_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600344 // Bind given cmd_buffer to this descriptor set
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600345 void BindCommandBuffer(GLOBAL_CB_NODE *cb_node) { bound_cmd_buffers_.insert(cb_node); }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600346 // If given cmd_buffer is in the bound_cmd_buffers_ set, remove it
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600347 void RemoveBoundCommandBuffer(GLOBAL_CB_NODE *cb_node) { bound_cmd_buffers_.erase(cb_node); }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600348 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t index) const {
349 return p_layout_->GetImmutableSamplerPtrFromBinding(index);
350 };
351 // For a particular binding, get the global index
352 uint32_t GetGlobalStartIndexFromBinding(const uint32_t binding) const {
353 return p_layout_->GetGlobalStartIndexFromBinding(binding);
354 };
355 uint32_t GetGlobalEndIndexFromBinding(const uint32_t binding) const {
356 return p_layout_->GetGlobalEndIndexFromBinding(binding);
357 };
358 // Return true if any part of set has ever been updated
359 bool IsUpdated() const { return some_update_; };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600360
361 private:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600362 bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, std::string *) const;
Tobin Ehliscbcf2342016-05-24 13:07:12 -0600363 bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, VkDescriptorType, uint32_t,
364 std::string *) const;
Tobin Ehlis6bd2b982016-05-24 12:33:42 -0600365 bool ValidateBufferUpdate(VkBuffer, VkDescriptorType, std::string *) const;
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600366 // Private helper to set all bound cmd buffers to INVALID state
367 void InvalidateBoundCmdBuffers();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600368 bool some_update_; // has any part of the set ever been updated?
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600369 VkDescriptorSet set_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600370 const DescriptorSetLayout *p_layout_;
Tobin Ehlis03d61de2016-05-17 08:31:46 -0600371 std::unordered_set<GLOBAL_CB_NODE *> bound_cmd_buffers_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600372 std::vector<std::unique_ptr<Descriptor>> descriptors_;
373 // Ptrs to object containers to verify bound data
374 const std::unordered_map<VkBuffer, BUFFER_NODE> *buffer_map_;
375 const std::unordered_map<VkDeviceMemory, DEVICE_MEM_INFO> *memory_map_;
376 const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> *buffer_view_map_;
377 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map_;
378 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map_;
379 // TODO : For next 3 maps all we really need (currently) is an image to format mapping
380 const std::unordered_map<VkImage, IMAGE_NODE> *image_map_;
381 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map_;
382 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map_;
383};
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600384}
Chris Forbes6f6844a2016-04-27 14:00:44 +1200385#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_