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