xref: /aosp_15_r20/external/deqp/external/vulkancts/modules/vulkan/geometry/vktGeometryTestsUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _VKTGEOMETRYTESTSUTIL_HPP
2 #define _VKTGEOMETRYTESTSUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2014 The Android Open Source Project
8  * Copyright (c) 2016 The Khronos Group Inc.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  *//*!
23  * \file
24  * \brief Geometry Utilities
25  *//*--------------------------------------------------------------------*/
26 
27 #include "vkDefs.hpp"
28 #include "vkObjUtil.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkRef.hpp"
31 #include "vkPrograms.hpp"
32 #include "vkRefUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vktTestCase.hpp"
35 
36 #include "tcuVector.hpp"
37 #include "tcuTexture.hpp"
38 
39 #include "deStringUtil.hpp"
40 #include "deUniquePtr.hpp"
41 
42 namespace vkt
43 {
44 namespace geometry
45 {
46 
47 struct PrimitiveTestSpec
48 {
49     vk::VkPrimitiveTopology primitiveType;
50     const char *name;
51     vk::VkPrimitiveTopology outputType;
52 };
53 
54 class GraphicsPipelineBuilder
55 {
56 public:
GraphicsPipelineBuilder(void)57     GraphicsPipelineBuilder(void)
58         : m_renderSize(0, 0)
59         , m_shaderStageFlags(0u)
60         , m_cullModeFlags(vk::VK_CULL_MODE_NONE)
61         , m_frontFace(vk::VK_FRONT_FACE_COUNTER_CLOCKWISE)
62         , m_patchControlPoints(1u)
63         , m_blendEnable(false)
64         , m_primitiveTopology(vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
65     {
66     }
67 
setRenderSize(const tcu::IVec2 & size)68     GraphicsPipelineBuilder &setRenderSize(const tcu::IVec2 &size)
69     {
70         m_renderSize = size;
71         return *this;
72     }
73     GraphicsPipelineBuilder &setShader(const vk::DeviceInterface &vk, const vk::VkDevice device,
74                                        const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary &binary,
75                                        const vk::VkSpecializationInfo *specInfo);
setPatchControlPoints(const uint32_t controlPoints)76     GraphicsPipelineBuilder &setPatchControlPoints(const uint32_t controlPoints)
77     {
78         m_patchControlPoints = controlPoints;
79         return *this;
80     }
setCullModeFlags(const vk::VkCullModeFlags cullModeFlags)81     GraphicsPipelineBuilder &setCullModeFlags(const vk::VkCullModeFlags cullModeFlags)
82     {
83         m_cullModeFlags = cullModeFlags;
84         return *this;
85     }
setFrontFace(const vk::VkFrontFace frontFace)86     GraphicsPipelineBuilder &setFrontFace(const vk::VkFrontFace frontFace)
87     {
88         m_frontFace = frontFace;
89         return *this;
90     }
setBlend(const bool enable)91     GraphicsPipelineBuilder &setBlend(const bool enable)
92     {
93         m_blendEnable = enable;
94         return *this;
95     }
96 
97     //! Applies only to pipelines without tessellation shaders.
setPrimitiveTopology(const vk::VkPrimitiveTopology topology)98     GraphicsPipelineBuilder &setPrimitiveTopology(const vk::VkPrimitiveTopology topology)
99     {
100         m_primitiveTopology = topology;
101         return *this;
102     }
103 
addVertexBinding(const vk::VkVertexInputBindingDescription vertexBinding)104     GraphicsPipelineBuilder &addVertexBinding(const vk::VkVertexInputBindingDescription vertexBinding)
105     {
106         m_vertexInputBindings.push_back(vertexBinding);
107         return *this;
108     }
addVertexAttribute(const vk::VkVertexInputAttributeDescription vertexAttribute)109     GraphicsPipelineBuilder &addVertexAttribute(const vk::VkVertexInputAttributeDescription vertexAttribute)
110     {
111         m_vertexInputAttributes.push_back(vertexAttribute);
112         return *this;
113     }
114 
115     //! Basic vertex input configuration (uses biding 0, location 0, etc.)
116     GraphicsPipelineBuilder &setVertexInputSingleAttribute(const vk::VkFormat vertexFormat, const uint32_t stride);
117 
118     vk::Move<vk::VkPipeline> build(const vk::DeviceInterface &vk, const vk::VkDevice device,
119                                    const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
120 
121 private:
122     tcu::IVec2 m_renderSize;
123     vk::Move<vk::VkShaderModule> m_vertexShaderModule;
124     vk::Move<vk::VkShaderModule> m_fragmentShaderModule;
125     vk::Move<vk::VkShaderModule> m_geometryShaderModule;
126     vk::Move<vk::VkShaderModule> m_tessControlShaderModule;
127     vk::Move<vk::VkShaderModule> m_tessEvaluationShaderModule;
128     std::vector<vk::VkPipelineShaderStageCreateInfo> m_shaderStages;
129     std::vector<vk::VkVertexInputBindingDescription> m_vertexInputBindings;
130     std::vector<vk::VkVertexInputAttributeDescription> m_vertexInputAttributes;
131     vk::VkShaderStageFlags m_shaderStageFlags;
132     vk::VkCullModeFlags m_cullModeFlags;
133     vk::VkFrontFace m_frontFace;
134     uint32_t m_patchControlPoints;
135     bool m_blendEnable;
136     vk::VkPrimitiveTopology m_primitiveTopology;
137 
138     GraphicsPipelineBuilder(const GraphicsPipelineBuilder &); // "deleted"
139     GraphicsPipelineBuilder &operator=(const GraphicsPipelineBuilder &);
140 };
141 
142 template <typename T>
sizeInBytes(const std::vector<T> & vec)143 inline std::size_t sizeInBytes(const std::vector<T> &vec)
144 {
145     return vec.size() * sizeof(vec[0]);
146 }
147 
148 std::string inputTypeToGLString(const vk::VkPrimitiveTopology &inputType);
149 std::string outputTypeToGLString(const vk::VkPrimitiveTopology &outputType);
150 std::size_t calcOutputVertices(const vk::VkPrimitiveTopology &inputType);
151 
152 vk::VkImageCreateInfo makeImageCreateInfo(const tcu::IVec2 &size, const vk::VkFormat format,
153                                           const vk::VkImageUsageFlags usage, const uint32_t numArrayLayers = 1u);
154 vk::VkBufferImageCopy makeBufferImageCopy(const vk::VkDeviceSize &bufferOffset,
155                                           const vk::VkImageSubresourceLayers &imageSubresource,
156                                           const vk::VkOffset3D &imageOffset, const vk::VkExtent3D &imageExtent);
157 
158 bool compareWithFileImage(Context &context, const tcu::ConstPixelBufferAccess &resultImage, std::string name);
159 
160 void fillBuffer(const vk::DeviceInterface &vk, const vk::VkDevice device, const vk::Allocation &alloc,
161                 const vk::VkDeviceSize size, const vk::VkDeviceSize offset, const vk::VkFormat format,
162                 const tcu::Vec4 &color);
163 void fillBuffer(const vk::DeviceInterface &vk, const vk::VkDevice device, const vk::Allocation &alloc,
164                 const vk::VkDeviceSize size, const vk::VkDeviceSize offset, const vk::VkFormat format,
165                 const float depth);
166 vk::VkBool32 checkPointSize(const vk::InstanceInterface &vki, const vk::VkPhysicalDevice physDevice);
167 
168 } // namespace geometry
169 } // namespace vkt
170 
171 #endif // _VKTGEOMETRYTESTSUTIL_HPP
172