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