dEQP-VK.renderpass: Set IMAGE_USAGE_TRANSFER_SRC_BIT when needed
[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
93 class DescriptorPoolBuilder
94 {
95 public:
96                                                                                 DescriptorPoolBuilder   (void);
97
98         DescriptorPoolBuilder&                          addType                                 (VkDescriptorType type, deUint32 numDescriptors = 1u);
99         Move<VkDescriptorPool>                          build                                   (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets) const;
100
101 private:
102                                                                                 DescriptorPoolBuilder   (const DescriptorPoolBuilder&); // delete
103         DescriptorPoolBuilder&                          operator=                               (const DescriptorPoolBuilder&); // delete
104
105         std::vector<VkDescriptorPoolSize>       m_counts;
106 };
107
108 class DescriptorSetUpdateBuilder
109 {
110 public:
111         class Location
112         {
113         public:
114                 static inline Location  binding                         (deUint32 binding_)
115                 {
116                         return Location(binding_, 0u);
117                 }
118                 static inline Location  bindingArrayElement     (deUint32 binding_, deUint32 arrayElement)
119                 {
120                         return Location(binding_, arrayElement);
121                 }
122
123         private:
124                 // \note private to force use of factory methods that have more descriptive names
125                 inline                                  Location                        (deUint32 binding_, deUint32 arrayElement)
126                         : m_binding                     (binding_)
127                         , m_arrayElement        (arrayElement)
128                 {
129                 }
130
131                 friend class DescriptorSetUpdateBuilder;
132
133                 const deUint32                  m_binding;
134                 const deUint32                  m_arrayElement;
135         };
136
137                                                                                 DescriptorSetUpdateBuilder      (void);
138
139         DescriptorSetUpdateBuilder&                     write                                           (VkDescriptorSet                                destSet,
140                                                                                                                                          deUint32                                               destBinding,
141                                                                                                                                          deUint32                                               destArrayElement,
142                                                                                                                                          deUint32                                               count,
143                                                                                                                                          VkDescriptorType                               descriptorType,
144                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo,
145                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo,
146                                                                                                                                          const VkBufferView*                    pTexelBufferView);
147
148         DescriptorSetUpdateBuilder&                     copy                                            (VkDescriptorSet        srcSet,
149                                                                                                                                          deUint32                       srcBinding,
150                                                                                                                                          deUint32                       srcArrayElement,
151                                                                                                                                          VkDescriptorSet        destSet,
152                                                                                                                                          deUint32                       destBinding,
153                                                                                                                                          deUint32                       destArrayElement,
154                                                                                                                                          deUint32                       count);
155
156         void                                                            update                                          (const DeviceInterface& vk, VkDevice device) const;
157
158         // helpers
159
160         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
161                                                                                                                                          const Location&                                destLocation,
162                                                                                                                                          VkDescriptorType                               descriptorType,
163                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo)
164         {
165                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, pImageInfo, DE_NULL, DE_NULL);
166         }
167
168         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
169                                                                                                                                          const Location&                                destLocation,
170                                                                                                                                          VkDescriptorType                               descriptorType,
171                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo)
172         {
173                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
174         }
175
176         inline DescriptorSetUpdateBuilder&      writeSingle                                     (VkDescriptorSet                                destSet,
177                                                                                                                                          const Location&                                destLocation,
178                                                                                                                                          VkDescriptorType                               descriptorType,
179                                                                                                                                          const VkBufferView*                    pTexelBufferView)
180         {
181                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
182         }
183
184         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
185                                                                                                                                          const Location&                                destLocation,
186                                                                                                                                          VkDescriptorType                               descriptorType,
187                                                                                                                                          deUint32                                               numDescriptors,
188                                                                                                                                          const VkDescriptorImageInfo*   pImageInfo)
189         {
190                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, pImageInfo, DE_NULL, DE_NULL);
191         }
192
193         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
194                                                                                                                                          const Location&                                destLocation,
195                                                                                                                                          VkDescriptorType                               descriptorType,
196                                                                                                                                          deUint32                                               numDescriptors,
197                                                                                                                                          const VkDescriptorBufferInfo*  pBufferInfo)
198         {
199                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, pBufferInfo, DE_NULL);
200         }
201
202         inline DescriptorSetUpdateBuilder&      writeArray                                      (VkDescriptorSet                                destSet,
203                                                                                                                                          const Location&                                destLocation,
204                                                                                                                                          VkDescriptorType                               descriptorType,
205                                                                                                                                          deUint32                                               numDescriptors,
206                                                                                                                                          const VkBufferView*                    pTexelBufferView)
207         {
208                 return write(destSet, destLocation.m_binding, destLocation.m_arrayElement, numDescriptors, descriptorType, DE_NULL, DE_NULL, pTexelBufferView);
209         }
210
211         inline DescriptorSetUpdateBuilder&      copySingle                                      (VkDescriptorSet        srcSet,
212                                                                                                                                          const Location&        srcLocation,
213                                                                                                                                          VkDescriptorSet        destSet,
214                                                                                                                                          const Location&        destLocation)
215         {
216                 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, 1u);
217         }
218
219         inline DescriptorSetUpdateBuilder&      copyArray                                       (VkDescriptorSet        srcSet,
220                                                                                                                                          const Location&        srcLocation,
221                                                                                                                                          VkDescriptorSet        destSet,
222                                                                                                                                          const Location&        destLocation,
223                                                                                                                                          deUint32                       count)
224         {
225                 return copy(srcSet, srcLocation.m_binding, srcLocation.m_arrayElement, destSet, destLocation.m_binding, destLocation.m_arrayElement, count);
226         }
227
228 private:
229                                                                                 DescriptorSetUpdateBuilder      (const DescriptorSetUpdateBuilder&); // delete
230         DescriptorSetUpdateBuilder&                     operator=                                       (const DescriptorSetUpdateBuilder&); // delete
231
232         std::vector<VkDescriptorImageInfo>      m_imageInfos;
233         std::vector<VkDescriptorBufferInfo>     m_bufferInfos;
234         std::vector<VkBufferView>                       m_texelBufferViews;
235
236         std::vector<VkWriteDescriptorSet>       m_writes;
237         std::vector<VkCopyDescriptorSet>        m_copies;
238 };
239
240 } // vk
241
242 #endif // _VKBUILDERUTIL_HPP