1 #ifndef _VKBUILDERUTIL_HPP
2 #define _VKBUILDERUTIL_HPP
3 /*-------------------------------------------------------------------------
7 * Copyright (c) 2015 Google Inc.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and/or associated documentation files (the
11 * "Materials"), to deal in the Materials without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Materials, and to
14 * permit persons to whom the Materials are furnished to do so, subject to
15 * the following conditions:
17 * The above copyright notice(s) and this permission notice shall be
18 * included in all copies or substantial portions of the Materials.
20 * The Materials are Confidential Information as defined by the
21 * Khronos Membership Agreement until designated non-confidential by
22 * Khronos, at which point this condition clause shall be removed.
24 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
34 * \brief Vulkan object builder utilities.
35 *//*--------------------------------------------------------------------*/
45 class DescriptorSetLayoutBuilder
48 DescriptorSetLayoutBuilder (void);
50 DescriptorSetLayoutBuilder& addBinding (VkDescriptorType descriptorType,
51 deUint32 descriptorCount,
52 VkShaderStageFlags stageFlags,
53 const VkSampler* pImmutableSamplers);
55 Move<VkDescriptorSetLayout> build (const DeviceInterface& vk, VkDevice device) const;
59 inline DescriptorSetLayoutBuilder& addSingleBinding (VkDescriptorType descriptorType,
60 VkShaderStageFlags stageFlags)
62 return addBinding(descriptorType, 1u, stageFlags, (VkSampler*)DE_NULL);
64 inline DescriptorSetLayoutBuilder& addArrayBinding (VkDescriptorType descriptorType,
65 deUint32 descriptorCount,
66 VkShaderStageFlags stageFlags)
68 return addBinding(descriptorType, descriptorCount, stageFlags, (VkSampler*)DE_NULL);
70 inline DescriptorSetLayoutBuilder& addSingleSamplerBinding (VkDescriptorType descriptorType,
71 VkShaderStageFlags stageFlags,
72 const VkSampler* immutableSampler) //!< \note: Using pointer to sampler to clarify that handle is not
73 //!< copied and argument lifetime is expected to cover build()
76 return addBinding(descriptorType, 1u, stageFlags, immutableSampler);
78 inline DescriptorSetLayoutBuilder& addArraySamplerBinding (VkDescriptorType descriptorType,
79 deUint32 descriptorCount,
80 VkShaderStageFlags stageFlags,
81 const VkSampler* pImmutableSamplers)
83 return addBinding(descriptorType, descriptorCount, stageFlags, pImmutableSamplers);
87 DescriptorSetLayoutBuilder (const DescriptorSetLayoutBuilder&); // delete
88 DescriptorSetLayoutBuilder& operator= (const DescriptorSetLayoutBuilder&); // delete
90 std::vector<VkDescriptorSetLayoutBinding> m_bindings;
92 struct ImmutableSamplerInfo
94 deUint32 bindingIndex;
95 deUint32 samplerBaseIndex;
98 std::vector<ImmutableSamplerInfo> m_immutableSamplerInfos;
99 std::vector<VkSampler> m_immutableSamplers;
102 class DescriptorPoolBuilder
105 DescriptorPoolBuilder (void);
107 DescriptorPoolBuilder& addType (VkDescriptorType type, deUint32 numDescriptors = 1u);
108 Move<VkDescriptorPool> build (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets) const;
111 DescriptorPoolBuilder (const DescriptorPoolBuilder&); // delete
112 DescriptorPoolBuilder& operator= (const DescriptorPoolBuilder&); // delete
114 std::vector<VkDescriptorPoolSize> m_counts;
117 class DescriptorSetUpdateBuilder
123 static inline Location binding (deUint32 binding_)
125 return Location(binding_, 0u);
127 static inline Location bindingArrayElement (deUint32 binding_, deUint32 arrayElement)
129 return Location(binding_, arrayElement);
133 // \note private to force use of factory methods that have more descriptive names
134 inline Location (deUint32 binding_, deUint32 arrayElement)
135 : m_binding (binding_)
136 , m_arrayElement (arrayElement)
140 friend class DescriptorSetUpdateBuilder;
142 const deUint32 m_binding;
143 const deUint32 m_arrayElement;
146 DescriptorSetUpdateBuilder (void);
148 DescriptorSetUpdateBuilder& write (VkDescriptorSet destSet,
149 deUint32 destBinding,
150 deUint32 destArrayElement,
152 VkDescriptorType descriptorType,
153 const VkDescriptorImageInfo* pImageInfo,
154 const VkDescriptorBufferInfo* pBufferInfo,
155 const VkBufferView* pTexelBufferView);
157 DescriptorSetUpdateBuilder& copy (VkDescriptorSet srcSet,
159 deUint32 srcArrayElement,
160 VkDescriptorSet destSet,
161 deUint32 destBinding,
162 deUint32 destArrayElement,
165 void update (const DeviceInterface& vk, VkDevice device) const;
169 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
170 const Location& destLocation,
171 VkDescriptorType descriptorType,
172 const VkDescriptorImageInfo* pImageInfo)
174 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, pImageInfo, DE_NULL, DE_NULL);
177 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
178 const Location& destLocation,
179 VkDescriptorType descriptorType,
180 const VkDescriptorBufferInfo* pBufferInfo)
182 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
185 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
186 const Location& destLocation,
187 VkDescriptorType descriptorType,
188 const VkBufferView* pTexelBufferView)
190 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
193 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
194 const Location& destLocation,
195 VkDescriptorType descriptorType,
196 deUint32 numDescriptors,
197 const VkDescriptorImageInfo* pImageInfo)
199 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, pImageInfo, DE_NULL, DE_NULL);
202 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
203 const Location& destLocation,
204 VkDescriptorType descriptorType,
205 deUint32 numDescriptors,
206 const VkDescriptorBufferInfo* pBufferInfo)
208 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
211 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
212 const Location& destLocation,
213 VkDescriptorType descriptorType,
214 deUint32 numDescriptors,
215 const VkBufferView* pTexelBufferView)
217 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
220 inline DescriptorSetUpdateBuilder& copySingle (VkDescriptorSet srcSet,
221 const Location& srcLocation,
222 VkDescriptorSet destSet,
223 const Location& destLocation)
225 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
228 inline DescriptorSetUpdateBuilder& copyArray (VkDescriptorSet srcSet,
229 const Location& srcLocation,
230 VkDescriptorSet destSet,
231 const Location& destLocation,
234 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
238 DescriptorSetUpdateBuilder (const DescriptorSetUpdateBuilder&); // delete
239 DescriptorSetUpdateBuilder& operator= (const DescriptorSetUpdateBuilder&); // delete
241 struct WriteDescriptorInfo
243 std::vector<VkDescriptorImageInfo> imageInfos;
244 std::vector<VkDescriptorBufferInfo> bufferInfos;
245 std::vector<VkBufferView> texelBufferViews;
248 std::vector<WriteDescriptorInfo> m_writeDescriptorInfos;
250 std::vector<VkWriteDescriptorSet> m_writes;
251 std::vector<VkCopyDescriptorSet> m_copies;
256 #endif // _VKBUILDERUTIL_HPP