1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and/or associated documentation files (the
9 * "Materials"), to deal in the Materials without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Materials, and to
12 * permit persons to whom the Materials are furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice(s) and this permission notice shall be
16 * included in all copies or substantial portions of the Materials.
18 * The Materials are Confidential Information as defined by the
19 * Khronos Membership Agreement until designated non-confidential by
20 * Khronos, at which point this condition clause shall be removed.
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 * \brief Vulkan object builder utilities.
33 *//*--------------------------------------------------------------------*/
35 #include "vkBuilderUtil.hpp"
37 #include "vkRefUtil.hpp"
42 // DescriptorSetLayoutBuilder
44 DescriptorSetLayoutBuilder::DescriptorSetLayoutBuilder (void)
48 DescriptorSetLayoutBuilder& DescriptorSetLayoutBuilder::addBinding (VkDescriptorType descriptorType,
49 deUint32 descriptorCount,
50 VkShaderStageFlags stageFlags,
51 const VkSampler* pImmutableSamplers)
53 const VkDescriptorSetLayoutBinding binding =
55 (deUint32)m_bindings.size(), // binding
56 descriptorType, // descriptorType
57 descriptorCount, // descriptorCount
58 stageFlags, // stageFlags
59 pImmutableSamplers, // pImmutableSamplers
61 m_bindings.push_back(binding);
65 Move<VkDescriptorSetLayout> DescriptorSetLayoutBuilder::build (const DeviceInterface& vk, VkDevice device) const
67 const VkDescriptorSetLayoutBinding* const bindingPtr = (m_bindings.empty()) ? (DE_NULL) : (&m_bindings[0]);
68 const VkDescriptorSetLayoutCreateInfo createInfo =
70 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
72 (VkDescriptorSetLayoutCreateFlags)0, // flags
73 (deUint32)m_bindings.size(), // bindingCount
74 bindingPtr, // pBinding
77 return createDescriptorSetLayout(vk, device, &createInfo);
80 // DescriptorPoolBuilder
82 DescriptorPoolBuilder::DescriptorPoolBuilder (void)
86 DescriptorPoolBuilder& DescriptorPoolBuilder::addType (VkDescriptorType type, deUint32 numDescriptors)
88 if (numDescriptors == 0u)
95 for (size_t ndx = 0; ndx < m_counts.size(); ++ndx)
97 if (m_counts[ndx].type == type)
99 // augment existing requirement
100 m_counts[ndx].descriptorCount += numDescriptors;
107 const VkDescriptorPoolSize typeCount =
110 numDescriptors, // numDescriptors
113 m_counts.push_back(typeCount);
119 Move<VkDescriptorPool> DescriptorPoolBuilder::build (const DeviceInterface& vk, VkDevice device, VkDescriptorPoolCreateFlags flags, deUint32 maxSets) const
121 const VkDescriptorPoolSize* const typeCountPtr = (m_counts.empty()) ? (DE_NULL) : (&m_counts[0]);
122 const VkDescriptorPoolCreateInfo createInfo =
124 VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
128 (deUint32)m_counts.size(), // poolSizeCount
129 typeCountPtr, // pPoolSizes
132 return createDescriptorPool(vk, device, &createInfo);
135 // DescriptorSetUpdateBuilder
137 DescriptorSetUpdateBuilder::DescriptorSetUpdateBuilder (void)
141 DescriptorSetUpdateBuilder& DescriptorSetUpdateBuilder::write (VkDescriptorSet destSet,
142 deUint32 destBinding,
143 deUint32 destArrayElement,
145 VkDescriptorType descriptorType,
146 const VkDescriptorImageInfo* pImageInfo,
147 const VkDescriptorBufferInfo* pBufferInfo,
148 const VkBufferView* pTexelBufferView)
150 const VkWriteDescriptorSet writeParams =
152 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
154 destSet, //!< destSet
155 destBinding, //!< destBinding
156 destArrayElement, //!< destArrayElement
158 descriptorType, //!< descriptorType
163 m_writes.push_back(writeParams);
167 DescriptorSetUpdateBuilder& DescriptorSetUpdateBuilder::copy (VkDescriptorSet srcSet,
169 deUint32 srcArrayElement,
170 VkDescriptorSet destSet,
171 deUint32 destBinding,
172 deUint32 destArrayElement,
175 const VkCopyDescriptorSet copyParams =
177 VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET,
180 srcBinding, //!< srcBinding
181 srcArrayElement, //!< srcArrayElement
182 destSet, //!< destSet
183 destBinding, //!< destBinding
184 destArrayElement, //!< destArrayElement
187 m_copies.push_back(copyParams);
191 void DescriptorSetUpdateBuilder::update (const DeviceInterface& vk, VkDevice device) const
193 const VkWriteDescriptorSet* const writePtr = (m_writes.empty()) ? (DE_NULL) : (&m_writes[0]);
194 const VkCopyDescriptorSet* const copyPtr = (m_copies.empty()) ? (DE_NULL) : (&m_copies[0]);
196 vk.updateDescriptorSets(device, (deUint32)m_writes.size(), writePtr, (deUint32)m_copies.size(), copyPtr);