4cb00c24123c1aa49b402d677ac83a4c9c2ad0ba
[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 Shader
44 {
45         vk::VkShaderStageFlagBits       stage;
46         const vk::ProgramBinary*        binary;
47
48         Shader (const vk::VkShaderStageFlagBits stage_, const vk::ProgramBinary& binary_)
49                 : stage         (stage_)
50                 , binary        (&binary_)
51         {
52         }
53 };
54
55 struct DrawState
56 {
57         const vk::VkPrimitiveTopology   topology;
58         const vk::VkFormat                              colorFormat;
59         const vk::VkFormat                              depthFormat;
60         tcu::UVec2                                              renderSize;
61         bool                                                    depthClampEnable;
62         bool                                                    blendEnable;
63         float                                                   lineWidth;
64         deUint32                                                numPatchControlPoints;
65
66         DrawState (const vk::VkPrimitiveTopology topology_, deUint32 renderWidth_, deUint32 renderHeight_);
67 };
68
69 struct DrawCallData
70 {
71         const std::vector<tcu::Vec4>&   vertices;
72
73         DrawCallData            (const std::vector<tcu::Vec4>&  vertices_)
74                 : vertices              (vertices_)
75         {
76         }
77 };
78
79 //! Sets up a graphics pipeline and enables simple draw calls to predefined attachments.
80 //! Clip volume uses wc = 1.0, which gives clip coord ranges: x = [-1, 1], y = [-1, 1], z = [0, 1]
81 //! Clip coords (-1,-1) map to viewport coords (0, 0).
82 class DrawContext
83 {
84 public:
85                                                                                         DrawContext                             (const DrawState&               drawState,
86                                                                                                                                          const DrawCallData&    drawCallData)
87                 : m_drawState                                           (drawState)
88                 , m_drawCallData                                        (drawCallData)
89         {
90         }
91         virtual                                                                 ~DrawContext                    (void)
92         {
93         }
94
95         virtual void                                                    draw                                    (void) = 0;
96         virtual tcu::ConstPixelBufferAccess             getColorPixels                  (void) const = 0;
97 protected:
98                 const DrawState                                         m_drawState;
99                 const DrawCallData                                      m_drawCallData;
100 };
101
102 class ReferenceDrawContext : public DrawContext
103 {
104 public:
105                                                                                         ReferenceDrawContext    (const DrawState&                       drawState,
106                                                                                                                                          const DrawCallData&            drawCallData,
107                                                                                                                                          const rr::VertexShader&        vertexShader,
108                                                                                                                                          const rr::FragmentShader&      fragmentShader)
109                 : DrawContext                                           (drawState, drawCallData)
110                 , m_vertexShader                                        (vertexShader)
111                 , m_fragmentShader                                      (fragmentShader)
112         {
113         }
114         virtual                                                                 ~ReferenceDrawContext   (void);
115         virtual void                                                    draw                                    (void);
116         virtual tcu::ConstPixelBufferAccess             getColorPixels                  (void) const;
117 private:
118         const rr::VertexShader&                                 m_vertexShader;
119         const rr::FragmentShader&                               m_fragmentShader;
120         tcu::TextureLevel                                               m_refImage;
121 };
122
123 struct VulkanProgram
124 {
125         const std::vector<Shader>&                              shaders;
126
127         VulkanProgram           (const std::vector<Shader>&                     shaders_)
128                 : shaders               (shaders_)
129         {
130         }
131 };
132
133 class VulkanDrawContext : public DrawContext
134 {
135 public:
136                                                                                         VulkanDrawContext       (Context&                               context,
137                                                                                                                                  const DrawState&               drawState,
138                                                                                                                                  const DrawCallData&    drawCallData,
139                                                                                                                                  const VulkanProgram&   vulkanProgram);
140         virtual                                                                 ~VulkanDrawContext      (void);
141         virtual void                                                    draw                            (void);
142         virtual tcu::ConstPixelBufferAccess             getColorPixels          (void) const;
143 private:
144         enum Contants
145         {
146                 MAX_NUM_SHADER_MODULES                                  = 5,
147         };
148         Context&                                                                        m_context;
149         VulkanProgram                                                           m_program;
150         de::MovePtr<vk::ImageWithMemory>                        m_colorImage;
151         de::MovePtr<vk::ImageWithMemory>                        m_depthImage;
152         de::MovePtr<vk::BufferWithMemory>                       m_colorAttachmentBuffer;
153         vk::refdetails::Move<vk::VkImageView>           m_colorImageView;
154         vk::refdetails::Move<vk::VkImageView>           m_depthImageView;
155         vk::refdetails::Move<vk::VkRenderPass>          m_renderPass;
156         vk::refdetails::Move<vk::VkFramebuffer>         m_framebuffer;
157         vk::refdetails::Move<vk::VkPipelineLayout>      m_pipelineLayout;
158         vk::refdetails::Move<vk::VkPipeline>            m_pipeline;
159         vk::refdetails::Move<vk::VkCommandPool>         m_cmdPool;
160         vk::refdetails::Move<vk::VkCommandBuffer>       m_cmdBuffer;
161         vk::refdetails::Move<vk::VkShaderModule>        m_shaderModules[MAX_NUM_SHADER_MODULES];
162         de::MovePtr<vk::BufferWithMemory>                       m_vertexBuffer;
163 };
164
165 std::string getPrimitiveTopologyShortName (const vk::VkPrimitiveTopology topology);
166
167 } // drwwutil
168 } // vkt
169
170 #endif // _VKTDRAWUTIL_HPP