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