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 Move<VkDescriptorSetLayout> build (const DeviceInterface& vk, VkDevice device) const;
48 inline DescriptorSetLayoutBuilder& addSingleBinding (VkDescriptorType descriptorType,
49 VkShaderStageFlags stageFlags)
51 return addBinding(descriptorType, 1u, stageFlags, (VkSampler*)DE_NULL);
53 inline DescriptorSetLayoutBuilder& addArrayBinding (VkDescriptorType descriptorType,
54 deUint32 descriptorCount,
55 VkShaderStageFlags stageFlags)
57 return addBinding(descriptorType, descriptorCount, stageFlags, (VkSampler*)DE_NULL);
59 inline DescriptorSetLayoutBuilder& addSingleSamplerBinding (VkDescriptorType descriptorType,
60 VkShaderStageFlags stageFlags,
61 const VkSampler* immutableSampler) //!< \note: Using pointer to sampler to clarify that handle is not
62 //!< copied and argument lifetime is expected to cover build()
65 return addBinding(descriptorType, 1u, stageFlags, immutableSampler);
67 inline DescriptorSetLayoutBuilder& addArraySamplerBinding (VkDescriptorType descriptorType,
68 deUint32 descriptorCount,
69 VkShaderStageFlags stageFlags,
70 const VkSampler* pImmutableSamplers)
72 return addBinding(descriptorType, descriptorCount, stageFlags, pImmutableSamplers);
76 DescriptorSetLayoutBuilder (const DescriptorSetLayoutBuilder&); // delete
77 DescriptorSetLayoutBuilder& operator= (const DescriptorSetLayoutBuilder&); // delete
79 std::vector<VkDescriptorSetLayoutBinding> m_bindings;
81 struct ImmutableSamplerInfo
83 deUint32 bindingIndex;
84 deUint32 samplerBaseIndex;
87 std::vector<ImmutableSamplerInfo> m_immutableSamplerInfos;
88 std::vector<VkSampler> m_immutableSamplers;
91 class DescriptorPoolBuilder
94 DescriptorPoolBuilder (void);
96 DescriptorPoolBuilder& addType (VkDescriptorType type, deUint32 numDescriptors = 1u);
97 Move<VkDescriptorPool> build (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets) const;
100 DescriptorPoolBuilder (const DescriptorPoolBuilder&); // delete
101 DescriptorPoolBuilder& operator= (const DescriptorPoolBuilder&); // delete
103 std::vector<VkDescriptorPoolSize> m_counts;
106 class DescriptorSetUpdateBuilder
112 static inline Location binding (deUint32 binding_)
114 return Location(binding_, 0u);
116 static inline Location bindingArrayElement (deUint32 binding_, deUint32 arrayElement)
118 return Location(binding_, arrayElement);
122 // \note private to force use of factory methods that have more descriptive names
123 inline Location (deUint32 binding_, deUint32 arrayElement)
124 : m_binding (binding_)
125 , m_arrayElement (arrayElement)
129 friend class DescriptorSetUpdateBuilder;
131 const deUint32 m_binding;
132 const deUint32 m_arrayElement;
135 DescriptorSetUpdateBuilder (void);
137 DescriptorSetUpdateBuilder& write (VkDescriptorSet destSet,
138 deUint32 destBinding,
139 deUint32 destArrayElement,
141 VkDescriptorType descriptorType,
142 const VkDescriptorImageInfo* pImageInfo,
143 const VkDescriptorBufferInfo* pBufferInfo,
144 const VkBufferView* pTexelBufferView);
146 DescriptorSetUpdateBuilder& copy (VkDescriptorSet srcSet,
148 deUint32 srcArrayElement,
149 VkDescriptorSet destSet,
150 deUint32 destBinding,
151 deUint32 destArrayElement,
154 void update (const DeviceInterface& vk, VkDevice device) const;
158 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
159 const Location& destLocation,
160 VkDescriptorType descriptorType,
161 const VkDescriptorImageInfo* pImageInfo)
163 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, pImageInfo, DE_NULL, DE_NULL);
166 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
167 const Location& destLocation,
168 VkDescriptorType descriptorType,
169 const VkDescriptorBufferInfo* pBufferInfo)
171 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
174 inline DescriptorSetUpdateBuilder& writeSingle (VkDescriptorSet destSet,
175 const Location& destLocation,
176 VkDescriptorType descriptorType,
177 const VkBufferView* pTexelBufferView)
179 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
182 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
183 const Location& destLocation,
184 VkDescriptorType descriptorType,
185 deUint32 numDescriptors,
186 const VkDescriptorImageInfo* pImageInfo)
188 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, pImageInfo, DE_NULL, DE_NULL);
191 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
192 const Location& destLocation,
193 VkDescriptorType descriptorType,
194 deUint32 numDescriptors,
195 const VkDescriptorBufferInfo* pBufferInfo)
197 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
200 inline DescriptorSetUpdateBuilder& writeArray (VkDescriptorSet destSet,
201 const Location& destLocation,
202 VkDescriptorType descriptorType,
203 deUint32 numDescriptors,
204 const VkBufferView* pTexelBufferView)
206 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
209 inline DescriptorSetUpdateBuilder& copySingle (VkDescriptorSet srcSet,
210 const Location& srcLocation,
211 VkDescriptorSet destSet,
212 const Location& destLocation)
214 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
217 inline DescriptorSetUpdateBuilder& copyArray (VkDescriptorSet srcSet,
218 const Location& srcLocation,
219 VkDescriptorSet destSet,
220 const Location& destLocation,
223 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
227 DescriptorSetUpdateBuilder (const DescriptorSetUpdateBuilder&); // delete
228 DescriptorSetUpdateBuilder& operator= (const DescriptorSetUpdateBuilder&); // delete
230 struct WriteDescriptorInfo
232 std::vector<VkDescriptorImageInfo> imageInfos;
233 std::vector<VkDescriptorBufferInfo> bufferInfos;
234 std::vector<VkBufferView> texelBufferViews;
237 std::vector<WriteDescriptorInfo> m_writeDescriptorInfos;
239 std::vector<VkWriteDescriptorSet> m_writes;
240 std::vector<VkCopyDescriptorSet> m_copies;
245 #endif // _VKBUILDERUTIL_HPP