Remove unused function from es31fSRGBDecodeTests.cpp am: 1ee59ff986 am: 2e80d40a0b...
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / geometry / vktGeometryTestsUtil.hpp
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 "vkMemUtil.hpp"
29 #include "vkRef.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkQueryUtil.hpp"
33 #include "vktTestCase.hpp"
34
35 #include "tcuVector.hpp"
36 #include "tcuTexture.hpp"
37
38 #include "deStringUtil.hpp"
39 #include "deUniquePtr.hpp"
40
41 namespace vkt
42 {
43 namespace geometry
44 {
45
46 struct PrimitiveTestSpec
47 {
48         vk::VkPrimitiveTopology         primitiveType;
49         const char*                                     name;
50         vk::VkPrimitiveTopology         outputType;
51 };
52
53 class Buffer
54 {
55 public:
56                                                                                 Buffer                  (const vk::DeviceInterface&             vk,
57                                                                                                                  const vk::VkDevice                             device,
58                                                                                                                  vk::Allocator&                                 allocator,
59                                                                                                                  const vk::VkBufferCreateInfo&  bufferCreateInfo,
60                                                                                                                  const vk::MemoryRequirement    memoryRequirement)
61
62                                                                                         : m_buffer              (createBuffer(vk, device, &bufferCreateInfo))
63                                                                                         , m_allocation  (allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement))
64                                                                                 {
65                                                                                         VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
66                                                                                 }
67
68         const vk::VkBuffer&                                     get                             (void) const { return *m_buffer; }
69         const vk::VkBuffer&                                     operator*               (void) const { return get(); }
70         vk::Allocation&                                         getAllocation   (void) const { return *m_allocation; }
71
72 private:
73         const vk::Unique<vk::VkBuffer>          m_buffer;
74         const de::UniquePtr<vk::Allocation>     m_allocation;
75
76         // "deleted"
77                                                                                 Buffer                  (const Buffer&);
78         Buffer&                                                         operator=               (const Buffer&);
79 };
80
81 class Image
82 {
83 public:
84                                                                                 Image                   (const vk::DeviceInterface&             vk,
85                                                                                                                  const vk::VkDevice                             device,
86                                                                                                                  vk::Allocator&                                 allocator,
87                                                                                                                  const vk::VkImageCreateInfo&   imageCreateInfo,
88                                                                                                                  const vk::MemoryRequirement    memoryRequirement)
89
90                                                                                         : m_image               (createImage(vk, device, &imageCreateInfo))
91                                                                                         , m_allocation  (allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement))
92                                                                                 {
93                                                                                         VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
94                                                                                 }
95
96         const vk::VkImage&                                      get                             (void) const { return *m_image; }
97         const vk::VkImage&                                      operator*               (void) const { return get(); }
98         vk::Allocation&                                         getAllocation   (void) const { return *m_allocation; }
99
100 private:
101         const vk::Unique<vk::VkImage>           m_image;
102         const de::UniquePtr<vk::Allocation>     m_allocation;
103
104         // "deleted"
105                                                                                 Image                   (const Image&);
106         Image&                                                          operator=               (const Image&);
107 };
108
109 class GraphicsPipelineBuilder
110 {
111 public:
112                                                                 GraphicsPipelineBuilder (void) : m_renderSize                   (0, 0)
113                                                                                                                            , m_shaderStageFlags         (0u)
114                                                                                                                            , m_cullModeFlags            (vk::VK_CULL_MODE_NONE)
115                                                                                                                            , m_frontFace                        (vk::VK_FRONT_FACE_COUNTER_CLOCKWISE)
116                                                                                                                            , m_patchControlPoints       (1u)
117                                                                                                                            , m_blendEnable                      (false)
118                                                                                                                            , m_primitiveTopology        (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) {}
119
120         GraphicsPipelineBuilder&        setRenderSize                                   (const tcu::IVec2& size) { m_renderSize = size; return *this; }
121         GraphicsPipelineBuilder&        setShader                                               (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo);
122         GraphicsPipelineBuilder&        setPatchControlPoints                   (const deUint32 controlPoints) { m_patchControlPoints = controlPoints; return *this; }
123         GraphicsPipelineBuilder&        setCullModeFlags                                (const vk::VkCullModeFlags cullModeFlags) { m_cullModeFlags = cullModeFlags; return *this; }
124         GraphicsPipelineBuilder&        setFrontFace                                    (const vk::VkFrontFace frontFace) { m_frontFace = frontFace; return *this; }
125         GraphicsPipelineBuilder&        setBlend                                                (const bool enable) { m_blendEnable = enable; return *this; }
126
127         //! Applies only to pipelines without tessellation shaders.
128         GraphicsPipelineBuilder&        setPrimitiveTopology                    (const vk::VkPrimitiveTopology topology) { m_primitiveTopology = topology; return *this; }
129
130         GraphicsPipelineBuilder&        addVertexBinding                                (const vk::VkVertexInputBindingDescription vertexBinding) { m_vertexInputBindings.push_back(vertexBinding); return *this; }
131         GraphicsPipelineBuilder&        addVertexAttribute                              (const vk::VkVertexInputAttributeDescription vertexAttribute) { m_vertexInputAttributes.push_back(vertexAttribute); return *this; }
132
133         //! Basic vertex input configuration (uses biding 0, location 0, etc.)
134         GraphicsPipelineBuilder&        setVertexInputSingleAttribute   (const vk::VkFormat vertexFormat, const deUint32 stride);
135
136         vk::Move<vk::VkPipeline>        build                                                   (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
137
138 private:
139         tcu::IVec2                                                                                      m_renderSize;
140         vk::Move<vk::VkShaderModule>                                            m_vertexShaderModule;
141         vk::Move<vk::VkShaderModule>                                            m_fragmentShaderModule;
142         vk::Move<vk::VkShaderModule>                                            m_geometryShaderModule;
143         vk::Move<vk::VkShaderModule>                                            m_tessControlShaderModule;
144         vk::Move<vk::VkShaderModule>                                            m_tessEvaluationShaderModule;
145         std::vector<vk::VkPipelineShaderStageCreateInfo>        m_shaderStages;
146         std::vector<vk::VkVertexInputBindingDescription>        m_vertexInputBindings;
147         std::vector<vk::VkVertexInputAttributeDescription>      m_vertexInputAttributes;
148         vk::VkShaderStageFlags                                                          m_shaderStageFlags;
149         vk::VkCullModeFlags                                                                     m_cullModeFlags;
150         vk::VkFrontFace                                                                         m_frontFace;
151         deUint32                                                                                        m_patchControlPoints;
152         bool                                                                                            m_blendEnable;
153         vk::VkPrimitiveTopology                                                         m_primitiveTopology;
154
155         GraphicsPipelineBuilder (const GraphicsPipelineBuilder&); // "deleted"
156         GraphicsPipelineBuilder& operator= (const GraphicsPipelineBuilder&);
157 };
158
159 template<typename T>
160 inline std::size_t sizeInBytes (const std::vector<T>& vec)
161 {
162         return vec.size() * sizeof(vec[0]);
163 }
164
165 std::string                                             inputTypeToGLString                     (const vk::VkPrimitiveTopology& inputType);
166 std::string                                             outputTypeToGLString            (const vk::VkPrimitiveTopology& outputType);
167 std::size_t                                             calcOutputVertices                      (const vk::VkPrimitiveTopology& inputType);
168
169 vk::VkBufferCreateInfo                  makeBufferCreateInfo            (const vk::VkDeviceSize bufferSize, const vk::VkBufferUsageFlags usage);
170 vk::VkImageCreateInfo                   makeImageCreateInfo                     (const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage, const deUint32 numArrayLayers = 1u);
171 vk::Move<vk::VkDescriptorSet>   makeDescriptorSet                       (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout);
172 vk::Move<vk::VkRenderPass>              makeRenderPass                          (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkFormat colorFormat);
173 vk::Move<vk::VkImageView>               makeImageView                           (const vk::DeviceInterface& vk, const vk::VkDevice vkDevice, const vk::VkImage image, const vk::VkImageViewType viewType, const vk::VkFormat format, const vk::VkImageSubresourceRange subresourceRange);
174 vk::VkBufferImageCopy                   makeBufferImageCopy                     (const vk::VkExtent3D extent, const vk::VkImageSubresourceLayers subresourceLayers);
175 vk::Move<vk::VkPipelineLayout>  makePipelineLayout                      (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorSetLayout descriptorSetLayout = DE_NULL);
176 vk::Move<vk::VkFramebuffer>             makeFramebuffer                         (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkRenderPass renderPass, const vk::VkImageView colorAttachment, const deUint32 width, const deUint32 height, const deUint32 layers);
177 vk::VkImageMemoryBarrier                makeImageMemoryBarrier          (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkImageLayout oldLayout, const vk::VkImageLayout newLayout, const vk::VkImage image, const vk::VkImageSubresourceRange subresourceRange);
178 vk::VkBufferMemoryBarrier               makeBufferMemoryBarrier         (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkBuffer buffer, const vk::VkDeviceSize offset, const vk::VkDeviceSize bufferSizeBytes);
179 de::MovePtr<vk::Allocation>             bindImage                                       (const vk::DeviceInterface& vk, const vk::VkDevice device, vk::Allocator& allocator, const vk::VkImage image, const vk::MemoryRequirement requirement);
180 de::MovePtr<vk::Allocation>             bindBuffer                                      (const vk::DeviceInterface& vk, const vk::VkDevice device, vk::Allocator& allocator, const vk::VkBuffer buffer, const vk::MemoryRequirement requirement);
181
182 void                                                    beginRenderPass                         (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer, const vk::VkRenderPass renderPass, const vk::VkFramebuffer framebuffer, const vk::VkRect2D& renderArea, const tcu::Vec4& clearColor);
183 void                                                    endRenderPass                           (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
184 void                                                    beginCommandBuffer                      (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
185 void                                                    endCommandBuffer                        (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
186 void                                                    submitCommandsAndWait           (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkQueue queue, const vk::VkCommandBuffer commandBuffer);
187
188 bool                                                    compareWithFileImage            (Context& context, const tcu::ConstPixelBufferAccess& resultImage, std::string name);
189
190 void                                                    zeroBuffer                                      (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::Allocation& alloc, const vk::VkDeviceSize size);
191
192 void                                                    checkGeometryShaderSupport      (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice, const int numGeometryShaderInvocations = 0);
193 vk::VkBool32                                    checkPointSize                          (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice);
194
195 inline vk::Move<vk::VkBuffer> makeBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkBufferCreateInfo& createInfo)
196 {
197         return createBuffer(vk, device, &createInfo);
198 }
199
200 inline vk::Move<vk::VkImage> makeImage (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkImageCreateInfo& createInfo)
201 {
202         return createImage(vk, device, &createInfo);
203 }
204
205 } //vkt
206 } //geometry
207
208 #endif // _VKTGEOMETRYTESTSUTIL_HPP