1 #ifndef _VKBUILDERUTIL_HPP
2 #define _VKBUILDERUTIL_HPP
3 /*-------------------------------------------------------------------------
7 * Copyright (c) 2015 Google Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Vulkan object builder utilities.
24 *//*--------------------------------------------------------------------*/
34 class DescriptorSetLayoutBuilder
37 DescriptorSetLayoutBuilder (void);
39 DescriptorSetLayoutBuilder& addBinding (VkDescriptorType descriptorType,
40 deUint32 descriptorCount,
41 VkShaderStageFlags stageFlags,
42 const VkSampler* pImmutableSamplers);
44 DescriptorSetLayoutBuilder& addIndexedBinding (VkDescriptorType descriptorType,
45 deUint32 descriptorCount,
46 VkShaderStageFlags stageFlags,
48 const VkSampler* pImmutableSamplers);
50 Move<VkDescriptorSetLayout> build (const DeviceInterface& vk, VkDevice device, VkDescriptorSetLayoutCreateFlags extraFlags = 0) const;
54 inline DescriptorSetLayoutBuilder& addSingleBinding (VkDescriptorType descriptorType,
55 VkShaderStageFlags stageFlags)
57 return addBinding(descriptorType, 1u, stageFlags, (VkSampler*)DE_NULL);
59 inline DescriptorSetLayoutBuilder& addSingleIndexedBinding (VkDescriptorType descriptorType,
60 VkShaderStageFlags stageFlags,
63 return addIndexedBinding(descriptorType, 1u, stageFlags, dstBinding, (VkSampler*)DE_NULL);
65 inline DescriptorSetLayoutBuilder& addArrayBinding (VkDescriptorType descriptorType,
66 deUint32 descriptorCount,
67 VkShaderStageFlags stageFlags)
69 return addBinding(descriptorType, descriptorCount, stageFlags, (VkSampler*)DE_NULL);
71 inline DescriptorSetLayoutBuilder& addSingleSamplerBinding (VkDescriptorType descriptorType,
72 VkShaderStageFlags stageFlags,
73 const VkSampler* immutableSampler) //!< \note: Using pointer to sampler to clarify that handle is not
74 //!< copied and argument lifetime is expected to cover build()
77 return addBinding(descriptorType, 1u, stageFlags, immutableSampler);
79 inline DescriptorSetLayoutBuilder& addSingleIndexedSamplerBinding (VkDescriptorType descriptorType,
80 VkShaderStageFlags stageFlags,
82 const VkSampler* immutableSampler) //!< \note: Using pointer to sampler to clarify that handle is not
83 //!< copied and argument lifetime is expected to cover build()
86 return addIndexedBinding(descriptorType, 1u, stageFlags, dstBinding, immutableSampler);
88 inline DescriptorSetLayoutBuilder& addArraySamplerBinding (VkDescriptorType descriptorType,
89 deUint32 descriptorCount,
90 VkShaderStageFlags stageFlags,
91 const VkSampler* pImmutableSamplers)
93 return addBinding(descriptorType, descriptorCount, stageFlags, pImmutableSamplers);
97 DescriptorSetLayoutBuilder (const DescriptorSetLayoutBuilder&); // delete
98 DescriptorSetLayoutBuilder& operator= (const DescriptorSetLayoutBuilder&); // delete
100 std::vector<VkDescriptorSetLayoutBinding> m_bindings;
102 struct ImmutableSamplerInfo
104 deUint32 bindingIndex;
105 deUint32 samplerBaseIndex;
108 std::vector<ImmutableSamplerInfo> m_immutableSamplerInfos;
109 std::vector<VkSampler> m_immutableSamplers;
112 class DescriptorPoolBuilder
115 DescriptorPoolBuilder (void);
117 DescriptorPoolBuilder& addType (VkDescriptorType type, deUint32 numDescriptors = 1u);
118 Move<VkDescriptorPool> build (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets, const void *pNext = DE_NULL) const;
121 DescriptorPoolBuilder (const DescriptorPoolBuilder&); // delete
122 DescriptorPoolBuilder& operator= (const DescriptorPoolBuilder&); // delete
124 std::vector<VkDescriptorPoolSize> m_counts;
127 class DescriptorSetUpdateBuilder
133 static inline Location binding (deUint32 binding_)
135 return Location(binding_, 0u);
137 static inline Location bindingArrayElement (deUint32 binding_, deUint32 arrayElement)
139 return Location(binding_, arrayElement);
143 // \note private to force use of factory methods that have more descriptive names
144 inline Location (deUint32 binding_, deUint32 arrayElement)
145 : m_binding (binding_)
146 , m_arrayElement (arrayElement)
150 friend class DescriptorSetUpdateBuilder;
152 const deUint32 m_binding;
153 const deUint32 m_arrayElement;
156 DescriptorSetUpdateBuilder (void);
157 /* DescriptorSetUpdateBuilder (const DescriptorSetUpdateBuilder&); // do not delete */
159 DescriptorSetUpdateBuilder& write (VkDescriptorSet destSet,
160 deUint32 destBinding,
161 deUint32 destArrayElement,
163 VkDescriptorType descriptorType,
164 const VkDescriptorImageInfo* pImageInfo,
165 const VkDescriptorBufferInfo* pBufferInfo,
166 const VkBufferView* pTexelBufferView,
167 const void* pNext = DE_NULL);
169 DescriptorSetUpdateBuilder& copy (VkDescriptorSet srcSet,
171 deUint32 srcArrayElement,
172 VkDescriptorSet destSet,
173 deUint32 destBinding,
174 deUint32 destArrayElement,
177 void update (const DeviceInterface& vk, VkDevice device) const;
178 void updateWithPush (const DeviceInterface& vk, VkCommandBuffer cmd, VkPipelineBindPoint bindPoint, VkPipelineLayout pipelineLayout, deUint32 setIdx, deUint32 descriptorIdx = 0, deUint32 numDescriptors = 0) const;
183 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
184 const Location& destLocation,
185 VkDescriptorType descriptorType,
186 const VkDescriptorImageInfo* pImageInfo)
188 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, pImageInfo, DE_NULL, DE_NULL);
191 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
192 const Location& destLocation,
193 VkDescriptorType descriptorType,
194 const VkDescriptorBufferInfo* pBufferInfo)
196 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
199 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
200 const Location& destLocation,
201 VkDescriptorType descriptorType,
202 const VkBufferView* pTexelBufferView)
204 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
207 #ifndef CTS_USES_VULKANSC
208 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
209 const Location& destLocation,
210 VkDescriptorType descriptorType,
211 const VkWriteDescriptorSetAccelerationStructureKHR* pAccelerationStructure)
213 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, DE_NULL, pAccelerationStructure);
215 #endif // CTS_USES_VULKANSC
217 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
218 const Location& destLocation,
219 VkDescriptorType descriptorType,
220 deUint32 numDescriptors,
221 const VkDescriptorImageInfo* pImageInfo)
223 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, pImageInfo, DE_NULL, DE_NULL);
226 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
227 const Location& destLocation,
228 VkDescriptorType descriptorType,
229 deUint32 numDescriptors,
230 const VkDescriptorBufferInfo* pBufferInfo)
232 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
235 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
236 const Location& destLocation,
237 VkDescriptorType descriptorType,
238 deUint32 numDescriptors,
239 const VkBufferView* pTexelBufferView)
241 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
244 #ifndef CTS_USES_VULKANSC
245 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
246 const Location& destLocation,
247 VkDescriptorType descriptorType,
248 deUint32 numDescriptors,
249 const VkWriteDescriptorSetAccelerationStructureKHR* pAccelerationStructure)
251 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, DE_NULL, pAccelerationStructure);
253 #endif // CTS_USES_VULKANSC
255 inline DescriptorSetUpdateBuilder& copySingle (VkDescriptorSet srcSet,
256 const Location& srcLocation,
257 VkDescriptorSet destSet,
258 const Location& destLocation)
260 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
263 inline DescriptorSetUpdateBuilder& copyArray (VkDescriptorSet srcSet,
264 const Location& srcLocation,
265 VkDescriptorSet destSet,
266 const Location& destLocation,
269 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
273 DescriptorSetUpdateBuilder& operator= (const DescriptorSetUpdateBuilder&); // delete
275 struct WriteDescriptorInfo
277 std::vector<VkDescriptorImageInfo> imageInfos;
278 std::vector<VkDescriptorBufferInfo> bufferInfos;
279 std::vector<VkBufferView> texelBufferViews;
282 std::vector<WriteDescriptorInfo> m_writeDescriptorInfos;
284 std::vector<VkWriteDescriptorSet> m_writes;
285 std::vector<VkCopyDescriptorSet> m_copies;
290 #endif // _VKBUILDERUTIL_HPP