• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
36     Move<VkCommandPool> cmdPool;
37     Move<VkCommandBuffer> cmdBuffer;
38 
39     CommandPoolWithBuffer(const DeviceInterface &vkd, const VkDevice device, const uint32_t queueFamilyIndex);
40 };
41 
42 Move<VkPipeline> makeComputePipeline(const DeviceInterface &vk, const VkDevice device,
43                                      const VkPipelineLayout pipelineLayout, const VkPipelineCreateFlags pipelineFlags,
44                                      const void *pipelinePNext, const VkShaderModule shaderModule,
45                                      const VkPipelineShaderStageCreateFlags shaderFlags,
46                                      const VkSpecializationInfo *specializationInfo = nullptr,
47                                      const VkPipelineCache pipelineCache            = VK_NULL_HANDLE,
48                                      const uint32_t subgroupSize                    = 0);
49 
50 Move<VkPipeline> makeComputePipeline(const DeviceInterface &vk, VkDevice device, VkPipelineLayout pipelineLayout,
51                                      VkShaderModule shaderModule);
52 
53 Move<VkPipeline> makeGraphicsPipeline(
54     const DeviceInterface &vk, const VkDevice device, const VkPipelineLayout pipelineLayout,
55     const VkShaderModule vertexShaderModule, const VkShaderModule tessellationControlShaderModule,
56     const VkShaderModule tessellationEvalShaderModule, const VkShaderModule geometryShaderModule,
57     const VkShaderModule fragmentShaderModule, const VkRenderPass renderPass, const std::vector<VkViewport> &viewports,
58     const std::vector<VkRect2D> &scissors, const VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
59     const uint32_t subpass = 0u, const uint32_t patchControlPoints = 0u,
60     const VkPipelineVertexInputStateCreateInfo *vertexInputStateCreateInfo     = nullptr,
61     const VkPipelineRasterizationStateCreateInfo *rasterizationStateCreateInfo = nullptr,
62     const VkPipelineMultisampleStateCreateInfo *multisampleStateCreateInfo     = nullptr,
63     const VkPipelineDepthStencilStateCreateInfo *depthStencilStateCreateInfo   = nullptr,
64     const VkPipelineColorBlendStateCreateInfo *colorBlendStateCreateInfo       = nullptr,
65     const VkPipelineDynamicStateCreateInfo *dynamicStateCreateInfo = nullptr, const void *pNext = nullptr,
66     const VkPipelineCreateFlags pipelineCreateFlags = 0u);
67 
68 Move<VkPipeline> makeGraphicsPipeline(
69     const DeviceInterface &vk, const VkDevice device, const VkPipelineLayout pipelineLayout,
70     const VkShaderModule vertexShaderModule, const VkShaderModule tessellationControlShaderModule,
71     const VkShaderModule tessellationEvalShaderModule, const VkShaderModule geometryShaderModule,
72     const VkShaderModule fragmentShaderModule, const VkRenderPass renderPass, const uint32_t subpass = 0u,
73     const VkPipelineVertexInputStateCreateInfo *vertexInputStateCreateInfo     = nullptr,
74     const VkPipelineInputAssemblyStateCreateInfo *inputAssemblyStateCreateInfo = nullptr,
75     const VkPipelineTessellationStateCreateInfo *tessStateCreateInfo           = nullptr,
76     const VkPipelineViewportStateCreateInfo *viewportStateCreateInfo           = nullptr,
77     const VkPipelineRasterizationStateCreateInfo *rasterizationStateCreateInfo = nullptr,
78     const VkPipelineMultisampleStateCreateInfo *multisampleStateCreateInfo     = nullptr,
79     const VkPipelineDepthStencilStateCreateInfo *depthStencilStateCreateInfo   = nullptr,
80     const VkPipelineColorBlendStateCreateInfo *colorBlendStateCreateInfo       = nullptr,
81     const VkPipelineDynamicStateCreateInfo *dynamicStateCreateInfo = nullptr, const void *pNext = nullptr,
82     const VkPipelineCreateFlags pipelineCreateFlags = 0u);
83 
84 #ifndef CTS_USES_VULKANSC
85 Move<VkPipeline> makeGraphicsPipeline(
86     const DeviceInterface &vk, const VkDevice device, const VkPipelineLayout pipelineLayout,
87     const VkShaderModule taskShaderModule, const VkShaderModule meshShaderModule,
88     const VkShaderModule fragmentShaderModule, const VkRenderPass renderPass, const std::vector<VkViewport> &viewports,
89     const std::vector<VkRect2D> &scissors, const uint32_t subpass = 0u,
90     const VkPipelineRasterizationStateCreateInfo *rasterizationStateCreateInfo = nullptr,
91     const VkPipelineMultisampleStateCreateInfo *multisampleStateCreateInfo     = nullptr,
92     const VkPipelineDepthStencilStateCreateInfo *depthStencilStateCreateInfo   = nullptr,
93     const VkPipelineColorBlendStateCreateInfo *colorBlendStateCreateInfo       = nullptr,
94     const VkPipelineDynamicStateCreateInfo *dynamicStateCreateInfo             = nullptr,
95     const VkPipelineCreateFlags pipelineCreateFlags = 0u, const void *pNext = nullptr);
96 #endif // CTS_USES_VULKANSC
97 
98 Move<VkPipeline> makeGraphicsPipeline(
99     const DeviceInterface &vk, const VkDevice device, const VkPipeline basePipelineHandle,
100     const VkPipelineLayout pipelineLayout, const VkPipelineCreateFlags pipelineCreateFlags,
101     const std::vector<VkPipelineShaderStageCreateInfo> &shaderCreateInfos, const VkRenderPass renderPass,
102     const std::vector<VkViewport> &viewports, const std::vector<VkRect2D> &scissors, const uint32_t subpass = 0u,
103     const VkPipelineRasterizationStateCreateInfo *rasterizationStateCreateInfo = nullptr,
104     const VkPipelineMultisampleStateCreateInfo *multisampleStateCreateInfo     = nullptr,
105     const VkPipelineDepthStencilStateCreateInfo *depthStencilStateCreateInfo   = nullptr,
106     const VkPipelineColorBlendStateCreateInfo *colorBlendStateCreateInfo       = nullptr,
107     const VkPipelineDynamicStateCreateInfo *dynamicStateCreateInfo = nullptr, const void *pNext = nullptr);
108 
109 Move<VkRenderPass> makeRenderPass(
110     const DeviceInterface &vk, const VkDevice device, const VkFormat colorFormat = VK_FORMAT_UNDEFINED,
111     const VkFormat depthStencilFormat                      = VK_FORMAT_UNDEFINED,
112     const VkAttachmentLoadOp loadOperation                 = VK_ATTACHMENT_LOAD_OP_CLEAR,
113     const VkImageLayout finalLayoutColor                   = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
114     const VkImageLayout finalLayoutDepthStencil            = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
115     const VkImageLayout subpassLayoutColor                 = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
116     const VkImageLayout subpassLayoutDepthStencil          = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
117     const VkAllocationCallbacks *const allocationCallbacks = nullptr, const void *pNext = nullptr);
118 
119 Move<VkImageView> makeImageView(const DeviceInterface &vk, const VkDevice vkDevice, const VkImage image,
120                                 const VkImageViewType imageViewType, const VkFormat format,
121                                 const VkImageSubresourceRange subresourceRange,
122                                 const vk::VkImageViewUsageCreateInfo *imageUsageCreateInfo = nullptr);
123 
124 Move<VkBufferView> makeBufferView(const DeviceInterface &vk, const VkDevice vkDevice, const VkBuffer buffer,
125                                   const VkFormat format, const VkDeviceSize offset, const VkDeviceSize size);
126 
127 Move<VkDescriptorSet> makeDescriptorSet(const DeviceInterface &vk, const VkDevice device,
128                                         const VkDescriptorPool descriptorPool, const VkDescriptorSetLayout setLayout,
129                                         const void *pNext = nullptr);
130 
131 VkBufferCreateInfo makeBufferCreateInfo(const VkDeviceSize size, const VkBufferUsageFlags usage);
132 
133 VkBufferCreateInfo makeBufferCreateInfo(const VkDeviceSize size, const VkBufferUsageFlags usage,
134                                         const std::vector<uint32_t> &queueFamilyIndices,
135                                         const VkBufferCreateFlags createFlags = 0, const void *pNext = nullptr);
136 
137 Move<VkPipelineLayout> makePipelineLayout(const DeviceInterface &vk, const VkDevice device,
138                                           const VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE,
139                                           const VkPushConstantRange *pushConstantRange    = nullptr);
140 
141 Move<VkPipelineLayout> makePipelineLayout(const DeviceInterface &vk, const VkDevice device,
142                                           const std::vector<VkDescriptorSetLayout> &descriptorSetLayouts);
143 
144 Move<VkPipelineLayout> makePipelineLayout(const DeviceInterface &vk, const VkDevice device,
145                                           const std::vector<vk::Move<VkDescriptorSetLayout>> &descriptorSetLayouts);
146 
147 Move<VkPipelineLayout> makePipelineLayout(const DeviceInterface &vk, const VkDevice device,
148                                           const uint32_t setLayoutCount,
149                                           const VkDescriptorSetLayout *descriptorSetLayout,
150                                           const VkPipelineLayoutCreateFlags flags = 0u);
151 
152 Move<VkPipelineLayout> makePipelineLayout(const DeviceInterface &vk, const VkDevice device,
153                                           const uint32_t setLayoutCount,
154                                           const VkDescriptorSetLayout *descriptorSetLayout,
155                                           const uint32_t pushConstantRangeCount,
156                                           const VkPushConstantRange *pPushConstantRanges,
157                                           const VkPipelineLayoutCreateFlags flags = 0u);
158 
159 Move<VkFramebuffer> makeFramebuffer(const DeviceInterface &vk, const VkDevice device, const VkRenderPass renderPass,
160                                     const VkImageView colorAttachment, const uint32_t width, const uint32_t height,
161                                     const uint32_t layers = 1u);
162 
163 Move<VkFramebuffer> makeFramebuffer(const DeviceInterface &vk, const VkDevice device, const VkRenderPass renderPass,
164                                     const uint32_t attachmentCount, const VkImageView *attachmentsArray,
165                                     const uint32_t width, const uint32_t height, const uint32_t layers = 1u);
166 
167 Move<VkCommandPool> makeCommandPool(const DeviceInterface &vk, const VkDevice device, const uint32_t queueFamilyIndex);
168 
makeBuffer(const DeviceInterface & vk,const VkDevice device,const VkDeviceSize bufferSize,const VkBufferUsageFlags usage)169 inline Move<VkBuffer> makeBuffer(const DeviceInterface &vk, const VkDevice device, const VkDeviceSize bufferSize,
170                                  const VkBufferUsageFlags usage)
171 {
172     const VkBufferCreateInfo bufferCreateInfo = makeBufferCreateInfo(bufferSize, usage);
173     return createBuffer(vk, device, &bufferCreateInfo);
174 }
175 
makeBuffer(const vk::DeviceInterface & vk,const vk::VkDevice device,const vk::VkBufferCreateInfo & createInfo)176 inline Move<VkBuffer> makeBuffer(const vk::DeviceInterface &vk, const vk::VkDevice device,
177                                  const vk::VkBufferCreateInfo &createInfo)
178 {
179     return createBuffer(vk, device, &createInfo);
180 }
181 
makeImage(const DeviceInterface & vk,const VkDevice device,const VkImageCreateInfo & createInfo)182 inline Move<VkImage> makeImage(const DeviceInterface &vk, const VkDevice device, const VkImageCreateInfo &createInfo)
183 {
184     return createImage(vk, device, &createInfo);
185 }
186 
187 VkBufferImageCopy makeBufferImageCopy(const VkExtent3D extent, const VkImageSubresourceLayers subresourceLayers);
188 
189 } // namespace vk
190 
191 #endif // _VKOBJUTIL_HPP
192