Merge branch 'jekstrand_renderpass_transfer_bit_fix' into 'master'
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkBuilderUtil.hpp
1 #ifndef _VKBUILDERUTIL_HPP
2 #define _VKBUILDERUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2015 Google Inc.
8  *
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:
16  *
17  * The above copyright notice(s) and this permission notice shall be
18  * included in all copies or substantial portions of the Materials.
19  *
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.
23  *
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.
31  *
32  *//*!
33  * \file
34  * \brief Vulkan object builder utilities.
35  *//*--------------------------------------------------------------------*/
36
37 #include "vkDefs.hpp"
38 #include "vkRef.hpp"
39
40 #include <vector>
41
42 namespace vk
43 {
44
45 class DescriptorSetLayoutBuilder
46 {
47 public:
48                                                                                                 DescriptorSetLayoutBuilder      (void);
49
50         DescriptorSetLayoutBuilder&                                     addBinding                                      (VkDescriptorType       descriptorType,
51                                                                                                                                                          deUint32                       descriptorCount,
52                                                                                                                                                          VkShaderStageFlags     stageFlags,
53                                                                                                                                                          const VkSampler*       pImmutableSamplers);
54
55         Move<VkDescriptorSetLayout>                                     build                                           (const DeviceInterface& vk, VkDevice device) const;
56
57         // helpers
58
59         inline DescriptorSetLayoutBuilder&                      addSingleBinding                        (VkDescriptorType       descriptorType,
60                                                                                                                                                          VkShaderStageFlags     stageFlags)
61         {
62                 return addBinding(descriptorType, 1u, stageFlags, (VkSampler*)DE_NULL);
63         }
64         inline DescriptorSetLayoutBuilder&                      addArrayBinding                         (VkDescriptorType       descriptorType,
65                                                                                                                                                          deUint32                       descriptorCount,
66                                                                                                                                                          VkShaderStageFlags     stageFlags)
67         {
68                 return addBinding(descriptorType, descriptorCount, stageFlags, (VkSampler*)DE_NULL);
69         }
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()
74                                                                                                                                                                                                                                         //!<        call.
75         {
76                 return addBinding(descriptorType, 1u, stageFlags, immutableSampler);
77         }
78         inline DescriptorSetLayoutBuilder&                      addArraySamplerBinding          (VkDescriptorType       descriptorType,
79                                                                                                                                                          deUint32                       descriptorCount,
80                                                                                                                                                          VkShaderStageFlags     stageFlags,
81                                                                                                                                                          const VkSampler*       pImmutableSamplers)
82         {
83                 return addBinding(descriptorType, descriptorCount, stageFlags, pImmutableSamplers);
84         }
85
86 private:
87                                                                                                 DescriptorSetLayoutBuilder      (const DescriptorSetLayoutBuilder&); // delete
88         DescriptorSetLayoutBuilder&                                     operator=                                       (const DescriptorSetLayoutBuilder&); // delete
89
90         std::vector<VkDescriptorSetLayoutBinding>       m_bindings;
91
92         struct ImmutableSamplerInfo
93         {
94                 deUint32 bindingIndex;
95                 deUint32 samplerBaseIndex;
96         };
97
98         std::vector<ImmutableSamplerInfo>                       m_immutableSamplerInfos;
99         std::vector<VkSampler>                                          m_immutableSamplers;
100 };
101
102 class DescriptorPoolBuilder
103 {
104 public:
105                                                                                 DescriptorPoolBuilder   (void);
106
107         DescriptorPoolBuilder&                          addType                                 (VkDescriptorType type, deUint32 numDescriptors = 1u);
108         Move<VkDescriptorPool>                          build                                   (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets) const;
109
110 private:
111                                                                                 DescriptorPoolBuilder   (const DescriptorPoolBuilder&); // delete
112         DescriptorPoolBuilder&                          operator=                               (const DescriptorPoolBuilder&); // delete
113
114         std::vector<VkDescriptorPoolSize>       m_counts;
115 };
116
117 class DescriptorSetUpdateBuilder
118 {
119 public:
120         class Location
121         {
122         public:
123                 static inline Location  binding                         (deUint32 binding_)
124                 {
125                         return Location(binding_, 0u);
126                 }
127                 static inline Location  bindingArrayElement     (deUint32 binding_, deUint32 arrayElement)
128                 {
129                         return Location(binding_, arrayElement);
130                 }
131
132         private:
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)
137                 {
138                 }
139
140                 friend class DescriptorSetUpdateBuilder;
141
142                 const deUint32                  m_binding;
143                 const deUint32                  m_arrayElement;
144         };
145
146                                                                                 DescriptorSetUpdateBuilder      (void);
147
148         DescriptorSetUpdateBuilder&                     write                                           (VkDescriptorSet                                destSet,
149                                                                                                                                          deUint32                                               destBinding,
150                                                                                                                                          deUint32                                               destArrayElement,
151                                                                                                                                          deUint32                                               count,
152                                                                                                                                          VkDescriptorType                               descriptorType,
153                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo,
154                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo,
155                                                                                                                                          const VkBufferView*                    pTexelBufferView);
156
157         DescriptorSetUpdateBuilder&                     copy                                            (VkDescriptorSet        srcSet,
158                                                                                                                                          deUint32                       srcBinding,
159                                                                                                                                          deUint32                       srcArrayElement,
160                                                                                                                                          VkDescriptorSet        destSet,
161                                                                                                                                          deUint32                       destBinding,
162                                                                                                                                          deUint32                       destArrayElement,
163                                                                                                                                          deUint32                       count);
164
165         void                                                            update                                          (const DeviceInterface& vk, VkDevice device) const;
166
167         // helpers
168
169         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
170                                                                                                                                          const Location&                                destLocation,
171                                                                                                                                          VkDescriptorType                               descriptorType,
172                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo)
173         {
174                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, pImageInfo, DE_NULL, DE_NULL);
175         }
176
177         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
178                                                                                                                                          const Location&                                destLocation,
179                                                                                                                                          VkDescriptorType                               descriptorType,
180                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo)
181         {
182                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
183         }
184
185         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
186                                                                                                                                          const Location&                                destLocation,
187                                                                                                                                          VkDescriptorType                               descriptorType,
188                                                                                                                                          const VkBufferView*                    pTexelBufferView)
189         {
190                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
191         }
192
193         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
194                                                                                                                                          const Location&                                destLocation,
195                                                                                                                                          VkDescriptorType                               descriptorType,
196                                                                                                                                          deUint32                                               numDescriptors,
197                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo)
198         {
199                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, pImageInfo, DE_NULL, DE_NULL);
200         }
201
202         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
203                                                                                                                                          const Location&                                destLocation,
204                                                                                                                                          VkDescriptorType                               descriptorType,
205                                                                                                                                          deUint32                                               numDescriptors,
206                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo)
207         {
208                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
209         }
210
211         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
212                                                                                                                                          const Location&                                destLocation,
213                                                                                                                                          VkDescriptorType                               descriptorType,
214                                                                                                                                          deUint32                                               numDescriptors,
215                                                                                                                                          const VkBufferView*                    pTexelBufferView)
216         {
217                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
218         }
219
220         inline DescriptorSetUpdateBuilder&      copySingle                                      (VkDescriptorSet        srcSet,
221                                                                                                                                          const Location&        srcLocation,
222                                                                                                                                          VkDescriptorSet        destSet,
223                                                                                                                                          const Location&        destLocation)
224         {
225                 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
226         }
227
228         inline DescriptorSetUpdateBuilder&      copyArray                                       (VkDescriptorSet        srcSet,
229                                                                                                                                          const Location&        srcLocation,
230                                                                                                                                          VkDescriptorSet        destSet,
231                                                                                                                                          const Location&        destLocation,
232                                                                                                                                          deUint32                       count)
233         {
234                 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
235         }
236
237 private:
238                                                                                 DescriptorSetUpdateBuilder      (const DescriptorSetUpdateBuilder&); // delete
239         DescriptorSetUpdateBuilder&                     operator=                                       (const DescriptorSetUpdateBuilder&); // delete
240
241         struct WriteDescriptorInfo
242         {
243                 std::vector<VkDescriptorImageInfo>      imageInfos;
244                 std::vector<VkDescriptorBufferInfo>     bufferInfos;
245                 std::vector<VkBufferView>                       texelBufferViews;
246         };
247
248         std::vector<WriteDescriptorInfo>        m_writeDescriptorInfos;
249
250         std::vector<VkWriteDescriptorSet>       m_writes;
251         std::vector<VkCopyDescriptorSet>        m_copies;
252 };
253
254 } // vk
255
256 #endif // _VKBUILDERUTIL_HPP