Merge vk-gl-cts/opengl-es-cts-3.2.4 into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / vktDrawUtil.hpp
1 #ifndef _VKTDRAWUTIL_HPP
2 #define _VKTDRAWUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  * Copyright (c) 2016 Google 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 Utility for generating simple work
25  *//*--------------------------------------------------------------------*/
26
27 #include "vkDefs.hpp"
28
29 #include "deUniquePtr.hpp"
30 #include "vkBufferWithMemory.hpp"
31 #include "vkImageWithMemory.hpp"
32 #include "vkImageUtil.hpp"
33 #include "vkPrograms.hpp"
34 #include "vktTestCase.hpp"
35 #include "vkTypeUtil.hpp"
36 #include "rrRenderer.hpp"
37
38 namespace vkt
39 {
40 namespace drawutil
41 {
42
43 struct DrawState
44 {
45         vk::VkPrimitiveTopology                 topology;
46         vk::VkFormat                                    colorFormat;
47         vk::VkFormat                                    depthFormat;
48         tcu::UVec2                                              renderSize;
49         bool                                                    depthClampEnable;
50         bool                                                    depthTestEnable;
51         bool                                                    depthWriteEnable;
52         rr::TestFunc                                    compareOp;
53         bool                                                    blendEnable;
54         float                                                   lineWidth;
55         deUint32                                                numPatchControlPoints;
56         deUint32                                                numSamples;
57         bool                                                    sampleShadingEnable;
58
59         DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
60 };
61
62 struct DrawCallData
63 {
64         const std::vector<tcu::Vec4>&   vertices;
65
66         DrawCallData            (const std::vector<tcu::Vec4>&  vertices_)
67                 : vertices              (vertices_)
68         {
69         }
70 };
71
72 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
73 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
74 //! Clip coords (-1,-1) map to viewport coords (0, 0).
75 class DrawContext
76 {
77 public:
78                                                                                         DrawContext                             (const DrawState&               drawState,
79                                                                                                                                          const DrawCallData&    drawCallData)
80                 : m_drawState                                           (drawState)
81                 , m_drawCallData                                        (drawCallData)
82         {
83         }
84         virtual                                                                 ~DrawContext                    (void)
85         {
86         }
87
88         virtual void                                                    draw                                    (void) = 0;
89         virtual tcu::ConstPixelBufferAccess             getColorPixels                  (void) const = 0;
90 protected:
91         const DrawState&                                                m_drawState;
92         const DrawCallData&                                             m_drawCallData;
93 };
94
95 class ReferenceDrawContext : public DrawContext
96 {
97 public:
98                                                                                         ReferenceDrawContext    (const DrawState&                       drawState,
99                                                                                                                                          const DrawCallData&            drawCallData,
100                                                                                                                                          const rr::VertexShader&        vertexShader,
101                                                                                                                                          const rr::FragmentShader&      fragmentShader)
102                 : DrawContext                                           (drawState, drawCallData)
103                 , m_vertexShader                                        (vertexShader)
104                 , m_fragmentShader                                      (fragmentShader)
105         {
106         }
107         virtual                                                                 ~ReferenceDrawContext   (void);
108         virtual void                                                    draw                                    (void);
109         virtual tcu::ConstPixelBufferAccess             getColorPixels                  (void) const;
110 private:
111         const rr::VertexShader&                                 m_vertexShader;
112         const rr::FragmentShader&                               m_fragmentShader;
113         tcu::TextureLevel                                               m_refImage;
114 };
115
116 struct VulkanShader
117 {
118         vk::VkShaderStageFlagBits       stage;
119         const vk::ProgramBinary*        binary;
120
121         VulkanShader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_)
122                 : stage         (stage_)
123                 , binary        (&binary_)
124         {
125         }
126 };
127
128 struct VulkanProgram
129 {
130         std::vector<VulkanShader>       shaders;
131         vk::VkImageView                         depthImageView;         // \todo [2017-06-06 pyry] This shouldn't be here? Doesn't logically belong to program
132         vk::VkDescriptorSetLayout       descriptorSetLayout;
133         vk::VkDescriptorSet                     descriptorSet;
134
135         VulkanProgram (const std::vector<VulkanShader>& shaders_)
136                 : shaders                               (shaders_)
137                 , depthImageView                (0)
138                 , descriptorSetLayout   (0)
139                 , descriptorSet                 (0)
140         {}
141
142         VulkanProgram (void)
143                 : depthImageView                (0)
144                 , descriptorSetLayout   (0)
145                 , descriptorSet                 (0)
146         {}
147 };
148
149 class VulkanDrawContext : public DrawContext
150 {
151 public:
152                                                                                         VulkanDrawContext       (Context&                               context,
153                                                                                                                                  const DrawState&               drawState,
154                                                                                                                                  const DrawCallData&    drawCallData,
155                                                                                                                                  const VulkanProgram&   vulkanProgram);
156         virtual                                                                 ~VulkanDrawContext      (void);
157         virtual void                                                    draw                            (void);
158         virtual tcu::ConstPixelBufferAccess             getColorPixels          (void) const;
159 private:
160         enum VulkanContants
161         {
162                 MAX_NUM_SHADER_MODULES                                  = 5,
163         };
164         Context&                                                                        m_context;
165         const VulkanProgram&                                            m_program;
166         de::MovePtr<vk::ImageWithMemory>                        m_colorImage;
167         de::MovePtr<vk::ImageWithMemory>                        m_resolveImage;
168         de::MovePtr<vk::BufferWithMemory>                       m_colorAttachmentBuffer;
169         vk::refdetails::Move<vk::VkImageView>           m_colorImageView;
170         vk::refdetails::Move<vk::VkRenderPass>          m_renderPass;
171         vk::refdetails::Move<vk::VkFramebuffer>         m_framebuffer;
172         vk::refdetails::Move<vk::VkPipelineLayout>      m_pipelineLayout;
173         vk::refdetails::Move<vk::VkPipeline>            m_pipeline;
174         vk::refdetails::Move<vk::VkCommandPool>         m_cmdPool;
175         vk::refdetails::Move<vk::VkCommandBuffer>       m_cmdBuffer;
176         vk::refdetails::Move<vk::VkShaderModule>        m_shaderModules[MAX_NUM_SHADER_MODULES];
177         de::MovePtr<vk::BufferWithMemory>                       m_vertexBuffer;
178 };
179
180 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
181
182 } // drwwutil
183 } // vkt
184
185 #endif // _VKTDRAWUTIL_HPP