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