blob: 74a3bdec523df9872bf638b9c6e5d37d0cc006bc [file] [log] [blame]
Dave Houlton4d9b2f82018-10-24 18:21:06 -06001/* Copyright (c) 2015-2018 The Khronos Group Inc.
2 * Copyright (c) 2015-2018 Valve Corporation
3 * Copyright (c) 2015-2018 LunarG, Inc.
4 * Copyright (C) 2015-2018 Google Inc.
Tobin Ehlis2d9deec2016-04-21 14:19:26 -06005 *
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>
John Zulaufc483f442017-12-15 14:02:06 -070019 * John Zulauf <jzulauf@lunarg.com>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060020 */
21#ifndef CORE_VALIDATION_DESCRIPTOR_SETS_H_
22#define CORE_VALIDATION_DESCRIPTOR_SETS_H_
23
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060024#include "core_validation_error_enums.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060025#include "core_validation_types.h"
John Zulaufd47d0612018-02-16 13:00:34 -070026#include "hash_vk_types.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060027#include "vk_layer_logging.h"
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060028#include "vk_layer_utils.h"
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060029#include "vk_safe_struct.h"
30#include "vulkan/vk_layer.h"
Mark Lobodzinski33826372017-04-13 11:10:11 -060031#include "vk_object_types.h"
Tobin Ehliscebc4c02016-08-22 10:10:43 -060032#include <map>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060033#include <memory>
John Zulaufb6d71202017-12-22 16:47:09 -070034#include <set>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060035#include <unordered_map>
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060036#include <unordered_set>
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060037#include <vector>
38
Tobin Ehlis58c884f2017-02-08 12:15:27 -070039using core_validation::layer_data;
40
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060041// Descriptor Data structures
John Zulaufc483f442017-12-15 14:02:06 -070042namespace cvdescriptorset {
43
John Zulauf48a6a702017-12-22 17:14:54 -070044// Utility structs/classes/types
John Zulaufc483f442017-12-15 14:02:06 -070045// 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};
John Zulauf48a6a702017-12-22 17:14:54 -070052typedef std::map<uint32_t, descriptor_req> BindingReqMap;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060053
54/*
John Zulauf34ebf272018-02-16 13:08:47 -070055 * DescriptorSetLayoutDef/DescriptorSetLayout classes
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060056 *
John Zulauf34ebf272018-02-16 13:08:47 -070057 * Overview - These two classes encapsulate the Vulkan VkDescriptorSetLayout data (layout).
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060058 * A layout consists of some number of bindings, each of which has a binding#, a
59 * type, descriptor count, stage flags, and pImmutableSamplers.
John Zulauf34ebf272018-02-16 13:08:47 -070060
61 * The DescriptorSetLayoutDef represents a canonicalization of the input data and contains
62 * neither per handle or per device state. It is possible for different handles on
63 * different devices to share a common def. This is used and useful for quick compatibiltiy
64 * validation. The DescriptorSetLayout refers to a DescriptorSetLayoutDef and contains
65 * all per handle state.
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060066 *
67 * Index vs Binding - A layout is created with an array of VkDescriptorSetLayoutBinding
68 * where each array index will have a corresponding binding# that is defined in that struct.
Tobin Ehlis9637fb22016-12-12 15:59:34 -070069 * The binding#, then, is decoupled from VkDescriptorSetLayoutBinding index, which allows
70 * bindings to be defined out-of-order. This DescriptorSetLayout class, however, stores
71 * the bindings internally in-order. This is useful for operations which may "roll over"
72 * from a single binding to the next consecutive binding.
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060073 *
Tobin Ehlis9637fb22016-12-12 15:59:34 -070074 * Note that although the bindings are stored in-order, there still may be "gaps" in the
75 * binding#. For example, if the binding creation order is 8, 7, 10, 3, 4, then the
76 * internal binding array will have five entries stored in binding order 3, 4, 7, 8, 10.
77 * To process all of the bindings in a layout you can iterate from 0 to GetBindingCount()
78 * and use the Get*FromIndex() functions for each index. To just process a single binding,
79 * use the Get*FromBinding() functions.
80 *
81 * Global Index - The binding vector index has as many indices as there are bindings.
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060082 * This class also has the concept of a Global Index. For the global index functions,
83 * there are as many global indices as there are descriptors in the layout.
84 * For the global index, consider all of the bindings to be a flat array where
Tobin Ehlis9637fb22016-12-12 15:59:34 -070085 * descriptor 0 of of the lowest binding# is index 0 and each descriptor in the layout
86 * increments from there. So if the lowest binding# in this example had descriptorCount of
87 * 10, then the GlobalStartIndex of the 2nd lowest binding# will be 10 where 0-9 are the
88 * global indices for the lowest binding#.
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060089 */
John Zulauf1f8174b2018-02-16 12:58:37 -070090class DescriptorSetLayoutDef {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070091 public:
Tobin Ehlis2d9deec2016-04-21 14:19:26 -060092 // Constructors and destructor
John Zulauf1f8174b2018-02-16 12:58:37 -070093 DescriptorSetLayoutDef(const VkDescriptorSetLayoutCreateInfo *p_create_info);
94 size_t hash() const;
95
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060096 uint32_t GetTotalDescriptorCount() const { return descriptor_count_; };
97 uint32_t GetDynamicDescriptorCount() const { return dynamic_descriptor_count_; };
Józef Kucia1bb00972017-09-10 11:24:08 +020098 VkDescriptorSetLayoutCreateFlags GetCreateFlags() const { return flags_; }
Tobin Ehlisf922ef82016-11-30 10:19:14 -070099 // For a given binding, return the number of descriptors in that binding and all successive bindings
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600100 uint32_t GetBindingCount() const { return binding_count_; };
John Zulaufb6d71202017-12-22 16:47:09 -0700101 // Non-empty binding numbers in order
102 const std::set<uint32_t> &GetSortedBindingSet() const { return non_empty_bindings_; }
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600103 // Return true if given binding is present in this layout
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600104 bool HasBinding(const uint32_t binding) const { return binding_to_index_map_.count(binding) > 0; };
John Zulaufdf3c5c12018-03-06 16:44:43 -0700105 // Return true if this DSL Def (referenced by the 1st layout) is compatible with another DSL Def (ref'd from the 2nd layout)
106 // else return false and update error_msg with description of incompatibility
John Zulauf1f8174b2018-02-16 12:58:37 -0700107 bool IsCompatible(VkDescriptorSetLayout, VkDescriptorSetLayout, DescriptorSetLayoutDef const *const, std::string *) const;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600108 // Return true if binding 1 beyond given exists and has same type, stageFlags & immutable sampler use
109 bool IsNextBindingConsistent(const uint32_t) const;
John Zulaufb6d71202017-12-22 16:47:09 -0700110 uint32_t GetIndexFromBinding(uint32_t binding) const;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600111 // Various Get functions that can either be passed a binding#, which will
Tobin Ehlis9637fb22016-12-12 15:59:34 -0700112 // be automatically translated into the appropriate index, or the index# can be passed in directly
John Zulaufb6d71202017-12-22 16:47:09 -0700113 uint32_t GetMaxBinding() const { return bindings_[bindings_.size() - 1].binding; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600114 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t) const;
John Zulaufb6d71202017-12-22 16:47:09 -0700115 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromBinding(uint32_t binding) const {
116 return GetDescriptorSetLayoutBindingPtrFromIndex(GetIndexFromBinding(binding));
117 }
John Zulauf1f8174b2018-02-16 12:58:37 -0700118 const std::vector<safe_VkDescriptorSetLayoutBinding> &GetBindings() const { return bindings_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600119 uint32_t GetDescriptorCountFromIndex(const uint32_t) const;
John Zulaufb6d71202017-12-22 16:47:09 -0700120 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const {
121 return GetDescriptorCountFromIndex(GetIndexFromBinding(binding));
122 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600123 VkDescriptorType GetTypeFromIndex(const uint32_t) const;
John Zulaufb6d71202017-12-22 16:47:09 -0700124 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { return GetTypeFromIndex(GetIndexFromBinding(binding)); }
125 VkShaderStageFlags GetStageFlagsFromIndex(const uint32_t) const;
126 VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t binding) const {
127 return GetStageFlagsFromIndex(GetIndexFromBinding(binding));
128 }
Jeff Bolzfdf96072018-04-10 14:32:18 -0500129 VkDescriptorBindingFlagsEXT GetDescriptorBindingFlagsFromIndex(const uint32_t) const;
130 VkDescriptorBindingFlagsEXT GetDescriptorBindingFlagsFromBinding(const uint32_t binding) const {
131 return GetDescriptorBindingFlagsFromIndex(GetIndexFromBinding(binding));
132 }
John Zulaufb6d71202017-12-22 16:47:09 -0700133 uint32_t GetIndexFromGlobalIndex(const uint32_t global_index) const;
134 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t global_index) const {
135 return GetTypeFromIndex(GetIndexFromGlobalIndex(global_index));
136 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600137 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t) const;
138 VkSampler const *GetImmutableSamplerPtrFromIndex(const uint32_t) const;
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700139 // For a given binding and array index, return the corresponding index into the dynamic offset array
140 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const {
141 auto dyn_off = binding_to_dynamic_array_idx_map_.find(binding);
142 if (dyn_off == binding_to_dynamic_array_idx_map_.end()) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700143 assert(0); // Requesting dyn offset for invalid binding/array idx pair
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700144 return -1;
145 }
146 return dyn_off->second;
147 }
John Zulaufc483f442017-12-15 14:02:06 -0700148 // For a particular binding, get the global index range
149 // This call should be guarded by a call to "HasBinding(binding)" to verify that the given binding exists
150 const IndexRange &GetGlobalIndexRangeFromBinding(const uint32_t) const;
151
Mark Lobodzinski4aa479d2017-03-10 09:14:00 -0700152 // Helper function to get the next valid binding for a descriptor
153 uint32_t GetNextValidBinding(const uint32_t) const;
Tobin Ehlis1f946f82016-05-05 12:03:44 -0600154 // For a particular binding starting at offset and having update_count descriptors
155 // updated, verify that for any binding boundaries crossed, the update is consistent
156 bool VerifyUpdateConsistency(uint32_t, uint32_t, uint32_t, const char *, const VkDescriptorSet, std::string *) const;
Józef Kuciaf0c94d42017-10-25 22:15:22 +0200157 bool IsPushDescriptor() const { return GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; };
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600158
John Zulauf48a6a702017-12-22 17:14:54 -0700159 struct BindingTypeStats {
160 uint32_t dynamic_buffer_count;
161 uint32_t non_dynamic_buffer_count;
162 uint32_t image_sampler_count;
163 };
164 const BindingTypeStats &GetBindingTypeStats() const { return binding_type_stats_; }
165
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700166 private:
John Zulaufdf3c5c12018-03-06 16:44:43 -0700167 // Only the first two data members are used for hash and equality checks, the other members are derived from them, and are used
168 // to speed up the various lookups/queries/validations
John Zulauf1f8174b2018-02-16 12:58:37 -0700169 VkDescriptorSetLayoutCreateFlags flags_;
170 std::vector<safe_VkDescriptorSetLayoutBinding> bindings_;
Jeff Bolzfdf96072018-04-10 14:32:18 -0500171 std::vector<VkDescriptorBindingFlagsEXT> binding_flags_;
John Zulauf1f8174b2018-02-16 12:58:37 -0700172
173 // Convenience data structures for rapid lookup of various descriptor set layout properties
John Zulaufb6d71202017-12-22 16:47:09 -0700174 std::set<uint32_t> non_empty_bindings_; // Containing non-emtpy bindings in numerical order
175 std::unordered_map<uint32_t, uint32_t> binding_to_index_map_;
176 // The following map allows an non-iterative lookup of a binding from a global index...
177 std::map<uint32_t, uint32_t> global_start_to_index_map_; // The index corresponding for a starting global (descriptor) index
John Zulaufc483f442017-12-15 14:02:06 -0700178 std::unordered_map<uint32_t, IndexRange> binding_to_global_index_range_map_; // range is exclusive of .end
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700179 // For a given binding map to associated index in the dynamic offset array
180 std::unordered_map<uint32_t, uint32_t> binding_to_dynamic_array_idx_map_;
John Zulauf1f8174b2018-02-16 12:58:37 -0700181
Jeff Bolzfdf96072018-04-10 14:32:18 -0500182 uint32_t binding_count_; // # of bindings in this layout
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700183 uint32_t descriptor_count_; // total # descriptors in this layout
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600184 uint32_t dynamic_descriptor_count_;
John Zulauf48a6a702017-12-22 17:14:54 -0700185 BindingTypeStats binding_type_stats_;
Tobin Ehlis2d9deec2016-04-21 14:19:26 -0600186};
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600187
John Zulaufd47d0612018-02-16 13:00:34 -0700188static bool operator==(const DescriptorSetLayoutDef &lhs, const DescriptorSetLayoutDef &rhs) {
189 return (lhs.GetCreateFlags() == rhs.GetCreateFlags()) && (lhs.GetBindings() == rhs.GetBindings());
190}
191
John Zulauf34ebf272018-02-16 13:08:47 -0700192// Canonical dictionary of DSL definitions -- independent of device or handle
193using DescriptorSetLayoutDict = hash_util::Dictionary<DescriptorSetLayoutDef, hash_util::HasHashMember<DescriptorSetLayoutDef>>;
194using DescriptorSetLayoutId = DescriptorSetLayoutDict::Id;
John Zulauf1f8174b2018-02-16 12:58:37 -0700195
196class DescriptorSetLayout {
197 public:
198 // Constructors and destructor
199 DescriptorSetLayout(const VkDescriptorSetLayoutCreateInfo *p_create_info, const VkDescriptorSetLayout layout);
200 // Validate create info - should be called prior to creation
Jeff Bolzfdf96072018-04-10 14:32:18 -0500201 static bool ValidateCreateInfo(const debug_report_data *, const VkDescriptorSetLayoutCreateInfo *, const bool, const uint32_t,
Jeff Bolze54ae892018-09-08 12:16:29 -0500202 const bool, const VkPhysicalDeviceDescriptorIndexingFeaturesEXT *descriptor_indexing_features,
203 const VkPhysicalDeviceInlineUniformBlockFeaturesEXT *inline_uniform_block_features,
204 const VkPhysicalDeviceInlineUniformBlockPropertiesEXT *inline_uniform_block_props);
John Zulauf1f8174b2018-02-16 12:58:37 -0700205 bool HasBinding(const uint32_t binding) const { return layout_id_->HasBinding(binding); }
206 // Return true if this layout is compatible with passed in layout from a pipelineLayout,
207 // else return false and update error_msg with description of incompatibility
208 bool IsCompatible(DescriptorSetLayout const *const, std::string *) const;
209 // Straightforward Get functions
210 VkDescriptorSetLayout GetDescriptorSetLayout() const { return layout_; };
211 bool IsDestroyed() const { return layout_destroyed_; }
212 void MarkDestroyed() { layout_destroyed_ = true; }
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600213 const DescriptorSetLayoutDef *GetLayoutDef() const { return layout_id_.get(); }
214 DescriptorSetLayoutId GetLayoutId() const { return layout_id_; }
John Zulauf1f8174b2018-02-16 12:58:37 -0700215 uint32_t GetTotalDescriptorCount() const { return layout_id_->GetTotalDescriptorCount(); };
216 uint32_t GetDynamicDescriptorCount() const { return layout_id_->GetDynamicDescriptorCount(); };
217 uint32_t GetBindingCount() const { return layout_id_->GetBindingCount(); };
218 VkDescriptorSetLayoutCreateFlags GetCreateFlags() const { return layout_id_->GetCreateFlags(); }
219 bool IsNextBindingConsistent(const uint32_t) const;
220 uint32_t GetIndexFromBinding(uint32_t binding) const { return layout_id_->GetIndexFromBinding(binding); }
221 // Various Get functions that can either be passed a binding#, which will
222 // be automatically translated into the appropriate index, or the index# can be passed in directly
223 uint32_t GetMaxBinding() const { return layout_id_->GetMaxBinding(); }
224 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
225 return layout_id_->GetDescriptorSetLayoutBindingPtrFromIndex(index);
226 }
227 VkDescriptorSetLayoutBinding const *GetDescriptorSetLayoutBindingPtrFromBinding(uint32_t binding) const {
228 return layout_id_->GetDescriptorSetLayoutBindingPtrFromBinding(binding);
229 }
230 const std::vector<safe_VkDescriptorSetLayoutBinding> &GetBindings() const { return layout_id_->GetBindings(); }
231 uint32_t GetDescriptorCountFromIndex(const uint32_t index) const { return layout_id_->GetDescriptorCountFromIndex(index); }
232 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const {
233 return layout_id_->GetDescriptorCountFromBinding(binding);
234 }
235 VkDescriptorType GetTypeFromIndex(const uint32_t index) const { return layout_id_->GetTypeFromIndex(index); }
236 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { return layout_id_->GetTypeFromBinding(binding); }
237 VkShaderStageFlags GetStageFlagsFromIndex(const uint32_t index) const { return layout_id_->GetStageFlagsFromIndex(index); }
238 VkShaderStageFlags GetStageFlagsFromBinding(const uint32_t binding) const {
239 return layout_id_->GetStageFlagsFromBinding(binding);
240 }
Jeff Bolzfdf96072018-04-10 14:32:18 -0500241 VkDescriptorBindingFlagsEXT GetDescriptorBindingFlagsFromIndex(const uint32_t index) const {
242 return layout_id_->GetDescriptorBindingFlagsFromIndex(index);
243 }
244 VkDescriptorBindingFlagsEXT GetDescriptorBindingFlagsFromBinding(const uint32_t binding) const {
245 return layout_id_->GetDescriptorBindingFlagsFromBinding(binding);
246 }
John Zulauf1f8174b2018-02-16 12:58:37 -0700247 uint32_t GetIndexFromGlobalIndex(const uint32_t global_index) const {
248 return layout_id_->GetIndexFromGlobalIndex(global_index);
249 }
250 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t global_index) const {
251 return GetTypeFromIndex(GetIndexFromGlobalIndex(global_index));
252 }
253 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
254 return layout_id_->GetImmutableSamplerPtrFromBinding(binding);
255 }
256 VkSampler const *GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
257 return layout_id_->GetImmutableSamplerPtrFromIndex(index);
258 }
259 // For a given binding and array index, return the corresponding index into the dynamic offset array
260 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const {
261 return layout_id_->GetDynamicOffsetIndexFromBinding(binding);
262 }
263 // For a particular binding, get the global index range
264 // This call should be guarded by a call to "HasBinding(binding)" to verify that the given binding exists
265 const IndexRange &GetGlobalIndexRangeFromBinding(const uint32_t binding) const {
266 return layout_id_->GetGlobalIndexRangeFromBinding(binding);
267 }
268 // Helper function to get the next valid binding for a descriptor
269 uint32_t GetNextValidBinding(const uint32_t binding) const { return layout_id_->GetNextValidBinding(binding); }
270 // For a particular binding starting at offset and having update_count descriptors
271 // updated, verify that for any binding boundaries crossed, the update is consistent
272 bool VerifyUpdateConsistency(uint32_t current_binding, uint32_t offset, uint32_t update_count, const char *type,
273 const VkDescriptorSet set, std::string *error_msg) const {
274 return layout_id_->VerifyUpdateConsistency(current_binding, offset, update_count, type, set, error_msg);
275 }
276 bool IsPushDescriptor() const { return layout_id_->IsPushDescriptor(); }
277
278 using BindingTypeStats = DescriptorSetLayoutDef::BindingTypeStats;
279 const BindingTypeStats &GetBindingTypeStats() const { return layout_id_->GetBindingTypeStats(); }
280
281 private:
282 VkDescriptorSetLayout layout_;
283 bool layout_destroyed_;
284 DescriptorSetLayoutId layout_id_;
285};
286
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600287/*
288 * Descriptor classes
289 * Descriptor is an abstract base class from which 5 separate descriptor types are derived.
290 * This allows the WriteUpdate() and CopyUpdate() operations to be specialized per
291 * descriptor type, but all descriptors in a set can be accessed via the common Descriptor*.
292 */
293
294// Slightly broader than type, each c++ "class" will has a corresponding "DescriptorClass"
Jeff Bolzfbe51582018-09-13 10:01:35 -0500295enum DescriptorClass { PlainSampler, ImageSampler, Image, TexelBuffer, GeneralBuffer, InlineUniform, AccelerationStructure };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600296
297class Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700298 public:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600299 virtual ~Descriptor(){};
Tobin Ehlis300888c2016-05-18 13:43:26 -0600300 virtual void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) = 0;
301 virtual void CopyUpdate(const Descriptor *) = 0;
Tobin Ehlis8020eea2016-08-17 11:10:41 -0600302 // Create binding between resources of this descriptor and given cb_node
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600303 virtual void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) = 0;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600304 virtual DescriptorClass GetClass() const { return descriptor_class; };
305 // Special fast-path check for SamplerDescriptors that are immutable
306 virtual bool IsImmutableSampler() const { return false; };
307 // Check for dynamic descriptor type
308 virtual bool IsDynamic() const { return false; };
309 // Check for storage descriptor type
310 virtual bool IsStorage() const { return false; };
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700311 bool updated; // Has descriptor been updated?
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600312 DescriptorClass descriptor_class;
313};
314// Shared helper functions - These are useful because the shared sampler image descriptor type
315// performs common functions with both sampler and image descriptors so they can share their common functions
Tobin Ehlise2f80292016-06-02 10:08:53 -0600316bool ValidateSampler(const VkSampler, const core_validation::layer_data *);
Dave Houlton00c154e2018-05-24 13:20:50 -0600317bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *, std::string *,
Dave Houltond8ed0212018-05-16 17:18:24 -0600318 std::string *);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600319
320class SamplerDescriptor : public Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700321 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600322 SamplerDescriptor(const VkSampler *);
323 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
324 void CopyUpdate(const Descriptor *) override;
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600325 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600326 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600327 VkSampler GetSampler() const { return sampler_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600328
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700329 private:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600330 // bool ValidateSampler(const VkSampler) const;
331 VkSampler sampler_;
332 bool immutable_;
Tobin Ehlis546326f2016-04-26 11:06:05 -0600333};
334
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600335class ImageSamplerDescriptor : public Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700336 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600337 ImageSamplerDescriptor(const VkSampler *);
338 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
339 void CopyUpdate(const Descriptor *) override;
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600340 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlisc9625152016-05-24 16:47:36 -0600341 virtual bool IsImmutableSampler() const override { return immutable_; };
Tobin Ehlis300888c2016-05-18 13:43:26 -0600342 VkSampler GetSampler() const { return sampler_; }
343 VkImageView GetImageView() const { return image_view_; }
344 VkImageLayout GetImageLayout() const { return image_layout_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700346 private:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600347 VkSampler sampler_;
348 bool immutable_;
349 VkImageView image_view_;
350 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600351};
352
353class ImageDescriptor : public Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700354 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600355 ImageDescriptor(const VkDescriptorType);
356 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
357 void CopyUpdate(const Descriptor *) override;
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600358 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Norbert Nopper419a1092016-05-15 19:19:41 +0200359 virtual bool IsStorage() const override { return storage_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600360 VkImageView GetImageView() const { return image_view_; }
361 VkImageLayout GetImageLayout() const { return image_layout_; }
362
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700363 private:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600364 bool storage_;
365 VkImageView image_view_;
366 VkImageLayout image_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600367};
368
369class TexelDescriptor : public Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700370 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600371 TexelDescriptor(const VkDescriptorType);
372 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
373 void CopyUpdate(const Descriptor *) override;
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600374 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlisf490f2e2016-05-17 06:43:48 -0600375 virtual bool IsStorage() const override { return storage_; }
376 VkBufferView GetBufferView() const { return buffer_view_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600377
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700378 private:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600379 VkBufferView buffer_view_;
380 bool storage_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600381};
382
383class BufferDescriptor : public Descriptor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700384 public:
Tobin Ehlis300888c2016-05-18 13:43:26 -0600385 BufferDescriptor(const VkDescriptorType);
386 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override;
387 void CopyUpdate(const Descriptor *) override;
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600388 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600389 virtual bool IsDynamic() const override { return dynamic_; }
390 virtual bool IsStorage() const override { return storage_; }
391 VkBuffer GetBuffer() const { return buffer_; }
392 VkDeviceSize GetOffset() const { return offset_; }
393 VkDeviceSize GetRange() const { return range_; }
394
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395 private:
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600396 bool storage_;
397 bool dynamic_;
398 VkBuffer buffer_;
399 VkDeviceSize offset_;
400 VkDeviceSize range_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600401};
Jeff Bolze54ae892018-09-08 12:16:29 -0500402
403class InlineUniformDescriptor : public Descriptor {
404 public:
Dave Houlton142c4cb2018-10-17 15:04:41 -0600405 InlineUniformDescriptor(const VkDescriptorType) {
406 updated = false;
407 descriptor_class = InlineUniform;
408 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500409 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override { updated = true; }
Dave Houlton142c4cb2018-10-17 15:04:41 -0600410 void CopyUpdate(const Descriptor *) override { updated = true; }
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600411 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override {}
Jeff Bolze54ae892018-09-08 12:16:29 -0500412};
413
Jeff Bolzfbe51582018-09-13 10:01:35 -0500414class AccelerationStructureDescriptor : public Descriptor {
415 public:
Dave Houlton142c4cb2018-10-17 15:04:41 -0600416 AccelerationStructureDescriptor(const VkDescriptorType) {
417 updated = false;
418 descriptor_class = AccelerationStructure;
419 }
Jeff Bolzfbe51582018-09-13 10:01:35 -0500420 void WriteUpdate(const VkWriteDescriptorSet *, const uint32_t) override { updated = true; }
Dave Houlton142c4cb2018-10-17 15:04:41 -0600421 void CopyUpdate(const Descriptor *) override { updated = true; }
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600422 void UpdateDrawState(core_validation::layer_data *, GLOBAL_CB_NODE *) override {}
Jeff Bolzfbe51582018-09-13 10:01:35 -0500423};
424
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600425// Structs to contain common elements that need to be shared between Validate* and Perform* calls below
426struct AllocateDescriptorSetsData {
Jeff Bolze54ae892018-09-08 12:16:29 -0500427 std::map<uint32_t, uint32_t> required_descriptors_by_type;
Tobin Ehlisa8e46e72017-06-21 10:16:10 -0600428 std::vector<std::shared_ptr<DescriptorSetLayout const>> layout_nodes;
Tobin Ehlis68d0adf2016-06-01 11:33:50 -0600429 AllocateDescriptorSetsData(uint32_t);
430};
Tobin Ehlisee471462016-05-26 11:21:59 -0600431// Helper functions for descriptor set functions that cross multiple sets
432// "Validate" will make sure an update is ok without actually performing it
Tobin Ehlis6a72dc72016-06-01 16:41:17 -0600433bool ValidateUpdateDescriptorSets(const debug_report_data *, const core_validation::layer_data *, uint32_t,
Tobin Ehlis56a30942016-05-19 08:00:00 -0600434 const VkWriteDescriptorSet *, uint32_t, const VkCopyDescriptorSet *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600435// "Perform" does the update with the assumption that ValidateUpdateDescriptorSets() has passed for the given update
Tobin Ehlis6a72dc72016-06-01 16:41:17 -0600436void PerformUpdateDescriptorSets(const core_validation::layer_data *, uint32_t, const VkWriteDescriptorSet *, uint32_t,
437 const VkCopyDescriptorSet *);
Mark Lobodzinski3d63a042017-03-09 16:24:13 -0700438// Similar to PerformUpdateDescriptorSets, this function will do the same for updating via templates
439void PerformUpdateDescriptorSetsWithTemplateKHR(layer_data *, VkDescriptorSet, std::unique_ptr<TEMPLATE_STATE> const &,
440 const void *);
Tobin Ehlisf320b192017-03-14 11:22:50 -0600441// Update the common AllocateDescriptorSetsData struct which can then be shared between Validate* and Perform* funcs below
442void UpdateAllocateDescriptorSetsData(const layer_data *dev_data, const VkDescriptorSetAllocateInfo *,
443 AllocateDescriptorSetsData *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600444// Validate that Allocation state is ok
Tobin Ehlisf320b192017-03-14 11:22:50 -0600445bool ValidateAllocateDescriptorSets(const core_validation::layer_data *, const VkDescriptorSetAllocateInfo *,
446 const AllocateDescriptorSetsData *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600447// Update state based on allocating new descriptorsets
Tobin Ehlis997b2582016-06-02 08:43:37 -0600448void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const VkDescriptorSet *, const AllocateDescriptorSetsData *,
Tobin Ehlisbd711bd2016-10-12 14:27:30 -0600449 std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_STATE *> *,
Tobin Ehlis997b2582016-06-02 08:43:37 -0600450 std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *,
John Zulauf48a6a702017-12-22 17:14:54 -0700451 core_validation::layer_data *);
Tobin Ehlisee471462016-05-26 11:21:59 -0600452
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600453/*
454 * DescriptorSet class
455 *
456 * Overview - This class encapsulates the Vulkan VkDescriptorSet data (set).
457 * A set has an underlying layout which defines the bindings in the set and the
458 * types and numbers of descriptors in each descriptor slot. Most of the layout
459 * interfaces are exposed through identically-named functions in the set class.
460 * Please refer to the DescriptorSetLayout comment above for a description of
461 * index, binding, and global index.
462 *
463 * At construction a vector of Descriptor* is created with types corresponding to the
464 * layout. The primary operation performed on the descriptors is to update them
465 * via write or copy updates, and validate that the update contents are correct.
466 * In order to validate update contents, the DescriptorSet stores a bunch of ptrs
467 * to data maps where various Vulkan objects can be looked up. The management of
468 * those maps is performed externally. The set class relies on their contents to
469 * be correct at the time of update.
470 */
Tobin Ehlis05be5df2016-05-05 08:25:02 -0600471class DescriptorSet : public BASE_NODE {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700472 public:
Tobin Ehlis452b4532017-06-21 09:56:13 -0600473 DescriptorSet(const VkDescriptorSet, const VkDescriptorPool, const std::shared_ptr<DescriptorSetLayout const> &,
Jeff Bolzfdf96072018-04-10 14:32:18 -0500474 uint32_t variable_count, core_validation::layer_data *);
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600475 ~DescriptorSet();
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600476 // A number of common Get* functions that return data based on layout from which this set was created
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600477 uint32_t GetTotalDescriptorCount() const { return p_layout_->GetTotalDescriptorCount(); };
478 uint32_t GetDynamicDescriptorCount() const { return p_layout_->GetDynamicDescriptorCount(); };
479 uint32_t GetBindingCount() const { return p_layout_->GetBindingCount(); };
480 VkDescriptorType GetTypeFromIndex(const uint32_t index) const { return p_layout_->GetTypeFromIndex(index); };
481 VkDescriptorType GetTypeFromGlobalIndex(const uint32_t index) const { return p_layout_->GetTypeFromGlobalIndex(index); };
482 VkDescriptorType GetTypeFromBinding(const uint32_t binding) const { return p_layout_->GetTypeFromBinding(binding); };
483 uint32_t GetDescriptorCountFromIndex(const uint32_t index) const { return p_layout_->GetDescriptorCountFromIndex(index); };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600484 uint32_t GetDescriptorCountFromBinding(const uint32_t binding) const {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600485 return p_layout_->GetDescriptorCountFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600486 };
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700487 // Return index into dynamic offset array for given binding
488 int32_t GetDynamicOffsetIndexFromBinding(uint32_t binding) const {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600489 return p_layout_->GetDynamicOffsetIndexFromBinding(binding);
Tobin Ehlisa3525e02016-11-17 10:50:52 -0700490 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600491 // Return true if given binding is present in this set
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600492 bool HasBinding(const uint32_t binding) const { return p_layout_->HasBinding(binding); };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600493 // Is this set compatible with the given layout?
Tobin Ehlis6dc57dd2017-06-21 10:08:52 -0600494 bool IsCompatible(DescriptorSetLayout const *const, std::string *) const;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600495 // For given bindings validate state at time of draw is correct, returning false on error and writing error details into string*
John Zulauf48a6a702017-12-22 17:14:54 -0700496 bool ValidateDrawState(const std::map<uint32_t, descriptor_req> &, const std::vector<uint32_t> &, GLOBAL_CB_NODE *,
Tobin Ehlisc8266452017-04-07 12:20:30 -0600497 const char *caller, std::string *) const;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600498 // For given set of bindings, add any buffers and images that will be updated to their respective unordered_sets & return number
499 // of objects inserted
Tobin Ehliscebc4c02016-08-22 10:10:43 -0600500 uint32_t GetStorageUpdates(const std::map<uint32_t, descriptor_req> &, std::unordered_set<VkBuffer> *,
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600501 std::unordered_set<VkImageView> *) const;
Tobin Ehlis300888c2016-05-18 13:43:26 -0600502
503 // Descriptor Update functions. These functions validate state and perform update separately
504 // Validate contents of a WriteUpdate
Dave Houlton00c154e2018-05-24 13:20:50 -0600505 bool ValidateWriteUpdate(const debug_report_data *, const VkWriteDescriptorSet *, std::string *, std::string *);
Tobin Ehlis300888c2016-05-18 13:43:26 -0600506 // Perform a WriteUpdate whose contents were just validated using ValidateWriteUpdate
507 void PerformWriteUpdate(const VkWriteDescriptorSet *);
508 // Validate contents of a CopyUpdate
Dave Houlton00c154e2018-05-24 13:20:50 -0600509 bool ValidateCopyUpdate(const debug_report_data *, const VkCopyDescriptorSet *, const DescriptorSet *, std::string *,
Dave Houltond8ed0212018-05-16 17:18:24 -0600510 std::string *);
Tobin Ehlis300888c2016-05-18 13:43:26 -0600511 // Perform a CopyUpdate whose contents were just validated using ValidateCopyUpdate
512 void PerformCopyUpdate(const VkCopyDescriptorSet *, const DescriptorSet *);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600513
John Zulauf1f8174b2018-02-16 12:58:37 -0700514 const std::shared_ptr<DescriptorSetLayout const> GetLayout() const { return p_layout_; };
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600515 VkDescriptorSet GetSet() const { return set_; };
516 // Return unordered_set of all command buffers that this set is bound to
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600517 std::unordered_set<GLOBAL_CB_NODE *> GetBoundCmdBuffers() const { return cb_bindings; }
John Zulauf6f3d2bd2018-10-29 17:08:42 -0600518 // Bind given cmd_buffer to this descriptor set and
519 // update CB image layout map with image/imagesampler descriptor image layouts
520 void UpdateDrawState(GLOBAL_CB_NODE *, const std::map<uint32_t, descriptor_req> &);
John Zulauf48a6a702017-12-22 17:14:54 -0700521
522 // Track work that has been bound or validated to avoid duplicate work, important when large descriptor arrays
523 // are present
524 typedef std::unordered_set<uint32_t> TrackedBindings;
525 static void FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, const BindingReqMap &in_req,
526 BindingReqMap *out_req, TrackedBindings *set);
527 static void FilterAndTrackOneBindingReq(const BindingReqMap::value_type &binding_req_pair, const BindingReqMap &in_req,
528 BindingReqMap *out_req, TrackedBindings *set, uint32_t limit);
529 void FilterAndTrackBindingReqs(GLOBAL_CB_NODE *, const BindingReqMap &in_req, BindingReqMap *out_req);
530 void FilterAndTrackBindingReqs(GLOBAL_CB_NODE *, PIPELINE_STATE *, const BindingReqMap &in_req, BindingReqMap *out_req);
531 void ClearCachedDynamicDescriptorValidation(GLOBAL_CB_NODE *cb_state) { cached_validation_[cb_state].dynamic_buffers.clear(); }
532 void ClearCachedValidation(GLOBAL_CB_NODE *cb_state) { cached_validation_.erase(cb_state); }
Tobin Ehlis2556f5b2016-06-24 17:22:16 -0600533 // If given cmd_buffer is in the cb_bindings set, remove it
John Zulauf48a6a702017-12-22 17:14:54 -0700534 void RemoveBoundCommandBuffer(GLOBAL_CB_NODE *cb_node) {
535 cb_bindings.erase(cb_node);
536 ClearCachedValidation(cb_node);
537 }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600538 VkSampler const *GetImmutableSamplerPtrFromBinding(const uint32_t index) const {
Tobin Ehlis7cd8c792017-06-20 08:30:39 -0600539 return p_layout_->GetImmutableSamplerPtrFromBinding(index);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600540 };
541 // For a particular binding, get the global index
John Zulaufc483f442017-12-15 14:02:06 -0700542 const IndexRange &GetGlobalIndexRangeFromBinding(const uint32_t binding) const {
543 return p_layout_->GetGlobalIndexRangeFromBinding(binding);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600544 };
545 // Return true if any part of set has ever been updated
546 bool IsUpdated() const { return some_update_; };
Józef Kuciaf0c94d42017-10-25 22:15:22 +0200547 bool IsPushDescriptor() const { return p_layout_->IsPushDescriptor(); };
Jeff Bolzfdf96072018-04-10 14:32:18 -0500548 bool IsVariableDescriptorCount(uint32_t binding) const {
549 return !!(p_layout_->GetDescriptorBindingFlagsFromBinding(binding) &
550 VK_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT_EXT);
551 }
552 uint32_t GetVariableDescriptorCount() const { return variable_count_; }
553 DESCRIPTOR_POOL_STATE *GetPoolState() const { return pool_state_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600554
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700555 private:
Dave Houlton00c154e2018-05-24 13:20:50 -0600556 bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, std::string *, std::string *) const;
557 bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, VkDescriptorType, uint32_t, std::string *,
Dave Houltond8ed0212018-05-16 17:18:24 -0600558 std::string *) const;
Dave Houlton00c154e2018-05-24 13:20:50 -0600559 bool ValidateBufferUsage(BUFFER_STATE const *, VkDescriptorType, std::string *, std::string *) const;
560 bool ValidateBufferUpdate(VkDescriptorBufferInfo const *, VkDescriptorType, std::string *, std::string *) const;
Tobin Ehlis9906d9d2016-05-17 14:23:46 -0600561 // Private helper to set all bound cmd buffers to INVALID state
562 void InvalidateBoundCmdBuffers();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700563 bool some_update_; // has any part of the set ever been updated?
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600564 VkDescriptorSet set_;
Tobin Ehlis7ca20be2016-10-12 15:09:16 -0600565 DESCRIPTOR_POOL_STATE *pool_state_;
Tobin Ehlis452b4532017-06-21 09:56:13 -0600566 const std::shared_ptr<DescriptorSetLayout const> p_layout_;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600567 std::vector<std::unique_ptr<Descriptor>> descriptors_;
Tobin Ehlis3d15c4a2016-06-02 13:04:47 -0600568 // Ptr to device data used for various data look-ups
John Zulauf48a6a702017-12-22 17:14:54 -0700569 core_validation::layer_data *const device_data_;
Tobin Ehlisc3b6c4c2017-02-02 17:26:40 -0700570 const VkPhysicalDeviceLimits limits_;
Jeff Bolzfdf96072018-04-10 14:32:18 -0500571 uint32_t variable_count_;
John Zulauf48a6a702017-12-22 17:14:54 -0700572
573 // Cached binding and validation support:
574 //
575 // For the lifespan of a given command buffer recording, do lazy evaluation, caching, and dirtying of
576 // expensive validation operation (typically per-draw)
577 typedef std::unordered_map<GLOBAL_CB_NODE *, TrackedBindings> TrackedBindingMap;
578 typedef std::unordered_map<PIPELINE_STATE *, TrackedBindingMap> ValidatedBindings;
579 // Track the validation caching of bindings vs. the command buffer and draw state
580 typedef std::unordered_map<uint32_t, GLOBAL_CB_NODE::ImageLayoutUpdateCount> VersionedBindings;
581 struct CachedValidation {
582 TrackedBindings command_binding_and_usage; // Persistent for the life of the recording
583 TrackedBindings non_dynamic_buffers; // Persistent for the life of the recording
584 TrackedBindings dynamic_buffers; // Dirtied (flushed) each BindDescriptorSet
585 std::unordered_map<PIPELINE_STATE *, VersionedBindings> image_samplers; // Tested vs. changes to CB's ImageLayout
586 };
587 typedef std::unordered_map<GLOBAL_CB_NODE *, CachedValidation> CachedValidationMap;
588 // Image and ImageView bindings are validated per pipeline and not invalidate by repeated binding
589 CachedValidationMap cached_validation_;
590};
591// For the "bindless" style resource usage with many descriptors, need to optimize binding and validation
592class PrefilterBindRequestMap {
593 public:
594 static const uint32_t kManyDescriptors_ = 64; // TODO base this number on measured data
595 std::unique_ptr<BindingReqMap> filtered_map_;
596 const BindingReqMap &orig_map_;
597
598 PrefilterBindRequestMap(DescriptorSet &ds, const BindingReqMap &in_map, GLOBAL_CB_NODE *cb_state);
599 PrefilterBindRequestMap(DescriptorSet &ds, const BindingReqMap &in_map, GLOBAL_CB_NODE *cb_state, PIPELINE_STATE *);
600 const BindingReqMap &Map() const { return (filtered_map_) ? *filtered_map_ : orig_map_; }
Tobin Ehlis0a43bde2016-05-03 08:31:08 -0600601};
Dave Houltona9df0ce2018-02-07 10:51:23 -0700602} // namespace cvdescriptorset
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700603#endif // CORE_VALIDATION_DESCRIPTOR_SETS_H_