1 #ifndef _VKOBJUTIL_HPP
2 #define _VKOBJUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan CTS Framework
5 * --------------------
6 *
7 * Copyright (c) 2015 Google Inc.
8 *
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
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
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.
20 *
21 *//*!
22 * \file
23 * \brief Utilities for creating commonly used Vulkan objects
24 *//*--------------------------------------------------------------------*/
25
26 #include <vector>
27 #include <memory>
28 #include "vkRef.hpp"
29 #include "vkRefUtil.hpp"
30
31 namespace vk
32 {
33
34 struct CommandPoolWithBuffer {
35 Move<VkCommandPool> cmdPool;
36 Move<VkCommandBuffer> cmdBuffer;
37
38 CommandPoolWithBuffer(const DeviceInterface& vkd, const VkDevice device, const deUint32 queueFamilyIndex);
39 };
40
41 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
42 const VkDevice device,
43 const VkPipelineLayout pipelineLayout,
44 const VkPipelineCreateFlags pipelineFlags,
45 const VkShaderModule shaderModule,
46 const VkPipelineShaderStageCreateFlags shaderFlags,
47 const VkSpecializationInfo* specializationInfo = DE_NULL,
48 const VkPipelineCache pipelineCache = DE_NULL);
49
50 Move<VkPipeline> makeComputePipeline (const DeviceInterface& vk,
51 VkDevice device,
52 VkPipelineLayout pipelineLayout,
53 VkShaderModule shaderModule);
54
55 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
56 const VkDevice device,
57 const VkPipelineLayout pipelineLayout,
58 const VkShaderModule vertexShaderModule,
59 const VkShaderModule tessellationControlShaderModule,
60 const VkShaderModule tessellationEvalShaderModule,
61 const VkShaderModule geometryShaderModule,
62 const VkShaderModule fragmentShaderModule,
63 const VkRenderPass renderPass,
64 const std::vector<VkViewport>& viewports,
65 const std::vector<VkRect2D>& scissors,
66 const VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
67 const deUint32 subpass = 0u,
68 const deUint32 patchControlPoints = 0u,
69 const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo = DE_NULL,
70 const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo = DE_NULL,
71 const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo = DE_NULL,
72 const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo = DE_NULL,
73 const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo = DE_NULL,
74 const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo = DE_NULL,
75 const void* pNext = DE_NULL,
76 const VkPipelineCreateFlags pipelineCreateFlags = 0u);
77
78 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
79 const VkDevice device,
80 const VkPipelineLayout pipelineLayout,
81 const VkShaderModule vertexShaderModule,
82 const VkShaderModule tessellationControlShaderModule,
83 const VkShaderModule tessellationEvalShaderModule,
84 const VkShaderModule geometryShaderModule,
85 const VkShaderModule fragmentShaderModule,
86 const VkRenderPass renderPass,
87 const deUint32 subpass = 0u,
88 const VkPipelineVertexInputStateCreateInfo* vertexInputStateCreateInfo = DE_NULL,
89 const VkPipelineInputAssemblyStateCreateInfo* inputAssemblyStateCreateInfo = DE_NULL,
90 const VkPipelineTessellationStateCreateInfo* tessStateCreateInfo = DE_NULL,
91 const VkPipelineViewportStateCreateInfo* viewportStateCreateInfo = DE_NULL,
92 const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo = DE_NULL,
93 const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo = DE_NULL,
94 const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo = DE_NULL,
95 const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo = DE_NULL,
96 const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo = DE_NULL,
97 const void* pNext = DE_NULL,
98 const VkPipelineCreateFlags pipelineCreateFlags = 0u);
99
100 #ifndef CTS_USES_VULKANSC
101 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
102 const VkDevice device,
103 const VkPipelineLayout pipelineLayout,
104 const VkShaderModule taskShaderModule,
105 const VkShaderModule meshShaderModule,
106 const VkShaderModule fragmentShaderModule,
107 const VkRenderPass renderPass,
108 const std::vector<VkViewport>& viewports,
109 const std::vector<VkRect2D>& scissors,
110 const deUint32 subpass = 0u,
111 const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo = nullptr,
112 const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo = nullptr,
113 const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo = nullptr,
114 const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo = nullptr,
115 const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo = nullptr,
116 const VkPipelineCreateFlags pipelineCreateFlags = 0u,
117 const void* pNext = nullptr);
118 #endif // CTS_USES_VULKANSC
119
120 Move<VkPipeline> makeGraphicsPipeline (const DeviceInterface& vk,
121 const VkDevice device,
122 const VkPipeline basePipelineHandle,
123 const VkPipelineLayout pipelineLayout,
124 const VkPipelineCreateFlags pipelineCreateFlags,
125 const std::vector<VkPipelineShaderStageCreateInfo>& shaderCreateInfos,
126 const VkRenderPass renderPass,
127 const std::vector<VkViewport>& viewports,
128 const std::vector<VkRect2D>& scissors,
129 const deUint32 subpass = 0u,
130 const VkPipelineRasterizationStateCreateInfo* rasterizationStateCreateInfo = nullptr,
131 const VkPipelineMultisampleStateCreateInfo* multisampleStateCreateInfo = nullptr,
132 const VkPipelineDepthStencilStateCreateInfo* depthStencilStateCreateInfo = nullptr,
133 const VkPipelineColorBlendStateCreateInfo* colorBlendStateCreateInfo = nullptr,
134 const VkPipelineDynamicStateCreateInfo* dynamicStateCreateInfo = nullptr,
135 const void* pNext = nullptr);
136
137 Move<VkRenderPass> makeRenderPass (const DeviceInterface& vk,
138 const VkDevice device,
139 const VkFormat colorFormat = VK_FORMAT_UNDEFINED,
140 const VkFormat depthStencilFormat = VK_FORMAT_UNDEFINED,
141 const VkAttachmentLoadOp loadOperation = VK_ATTACHMENT_LOAD_OP_CLEAR,
142 const VkImageLayout finalLayoutColor = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
143 const VkImageLayout finalLayoutDepthStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
144 const VkImageLayout subpassLayoutColor = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
145 const VkImageLayout subpassLayoutDepthStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
146 const VkAllocationCallbacks* const allocationCallbacks = DE_NULL);
147
148 Move<VkImageView> makeImageView (const DeviceInterface& vk,
149 const VkDevice vkDevice,
150 const VkImage image,
151 const VkImageViewType imageViewType,
152 const VkFormat format,
153 const VkImageSubresourceRange subresourceRange,
154 const vk::VkImageViewUsageCreateInfo* imageUsageCreateInfo = DE_NULL);
155
156 Move<VkBufferView> makeBufferView (const DeviceInterface& vk,
157 const VkDevice vkDevice,
158 const VkBuffer buffer,
159 const VkFormat format,
160 const VkDeviceSize offset,
161 const VkDeviceSize size);
162
163 Move<VkDescriptorSet> makeDescriptorSet (const DeviceInterface& vk,
164 const VkDevice device,
165 const VkDescriptorPool descriptorPool,
166 const VkDescriptorSetLayout setLayout,
167 const void* pNext = DE_NULL);
168
169 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize size,
170 const VkBufferUsageFlags usage);
171
172 VkBufferCreateInfo makeBufferCreateInfo (const VkDeviceSize size,
173 const VkBufferUsageFlags usage,
174 const std::vector<deUint32>& queueFamilyIndices,
175 const VkBufferCreateFlags createFlags = 0);
176
177 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
178 const VkDevice device,
179 const VkDescriptorSetLayout descriptorSetLayout = DE_NULL,
180 const VkPushConstantRange* pushConstantRange = nullptr);
181
182 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
183 const VkDevice device,
184 const std::vector<VkDescriptorSetLayout> &descriptorSetLayouts);
185
186 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
187 const VkDevice device,
188 const std::vector<vk::Move<VkDescriptorSetLayout>> &descriptorSetLayouts);
189
190 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
191 const VkDevice device,
192 const deUint32 setLayoutCount,
193 const VkDescriptorSetLayout* descriptorSetLayout,
194 const VkPipelineLayoutCreateFlags flags = 0u);
195
196 Move<VkPipelineLayout> makePipelineLayout (const DeviceInterface& vk,
197 const VkDevice device,
198 const deUint32 setLayoutCount,
199 const VkDescriptorSetLayout* descriptorSetLayout,
200 const deUint32 pushConstantRangeCount,
201 const VkPushConstantRange* pPushConstantRanges,
202 const VkPipelineLayoutCreateFlags flags = 0u);
203
204 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
205 const VkDevice device,
206 const VkRenderPass renderPass,
207 const VkImageView colorAttachment,
208 const deUint32 width,
209 const deUint32 height,
210 const deUint32 layers = 1u);
211
212 Move<VkFramebuffer> makeFramebuffer (const DeviceInterface& vk,
213 const VkDevice device,
214 const VkRenderPass renderPass,
215 const deUint32 attachmentCount,
216 const VkImageView* attachmentsArray,
217 const deUint32 width,
218 const deUint32 height,
219 const deUint32 layers = 1u);
220
221 Move<VkCommandPool> makeCommandPool (const DeviceInterface& vk,
222 const VkDevice device,
223 const deUint32 queueFamilyIndex);
224
makeBuffer(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)225 inline Move<VkBuffer> makeBuffer (const DeviceInterface& vk,
226 const VkDevice device,
227 const VkDeviceSize bufferSize,
228 const VkBufferUsageFlags usage)
229 {
230 const VkBufferCreateInfo bufferCreateInfo = makeBufferCreateInfo(bufferSize, usage);
231 return createBuffer(vk, device, &bufferCreateInfo);
232 }
233
makeBuffer(const vk::DeviceInterface & vk,const vk::VkDevice device,const vk::VkBufferCreateInfo & createInfo)234 inline Move<VkBuffer> makeBuffer (const vk::DeviceInterface& vk,
235 const vk::VkDevice device,
236 const vk::VkBufferCreateInfo& createInfo)
237 {
238 return createBuffer(vk, device, &createInfo);
239 }
240
makeImage(const DeviceInterface & vk,const VkDevice device,const VkImageCreateInfo & createInfo)241 inline Move<VkImage> makeImage (const DeviceInterface& vk,
242 const VkDevice device,
243 const VkImageCreateInfo& createInfo)
244 {
245 return createImage(vk, device, &createInfo);
246 }
247
248 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
249 const VkImageSubresourceLayers subresourceLayers);
250
251 } // vk
252
253 #endif // _VKOBJUTIL_HPP
254