0daf768e1155e8fd71b59d75a078b174ba15e603
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / shaderrendercase / vktShaderRenderCase.hpp
1 /*------------------------------------------------------------------------
2  * Copyright (c) 2015 The Khronos Group Inc.
3  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and/or associated documentation files (the
7  * "Materials"), to deal in the Materials without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Materials, and to
10  * permit persons to whom the Materials are furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice(s) and this permission notice shall be included
14  * in all copies or substantial portions of the Materials.
15  *
16  * The Materials are Confidential Information as defined by the
17  * Khronos Membership Agreement until designated non-confidential by Khronos,
18  * at which point this condition clause shall be removed.
19  *
20  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  *
28  *//*!
29  * \file
30  * \brief Vulkan ShaderRenderCase
31  *//*--------------------------------------------------------------------*/
32
33 #ifndef _VKTSHADERRENDERCASE_HPP
34
35 #include "tcuTexture.hpp"
36
37 #include "vktTestCase.hpp"
38 #include "vkPrograms.hpp"
39
40 namespace vkt
41 {
42 namespace shaderrendercase
43 {
44
45 class QuadGrid;
46
47 class TextureBinding
48 {
49 };
50
51 // ShaderEvalContext.
52
53 class ShaderEvalContext
54 {
55 public:
56     // Limits.
57     enum
58     {
59         MAX_USER_ATTRIBS    = 4,
60         MAX_TEXTURES        = 4,
61     };
62
63     struct ShaderSampler
64     {
65         tcu::Sampler                sampler;
66         const tcu::Texture2D*       tex2D;
67         const tcu::TextureCube*     texCube;
68         const tcu::Texture2DArray*  tex2DArray;
69         const tcu::Texture3D*       tex3D;
70
71         inline ShaderSampler (void)
72             : tex2D     (DE_NULL)
73             , texCube   (DE_NULL)
74             , tex2DArray(DE_NULL)
75             , tex3D     (DE_NULL)
76         {
77         }
78     };
79
80                             ShaderEvalContext       (const QuadGrid& quadGrid);
81                             ~ShaderEvalContext      (void);
82
83     void                    reset                   (float sx, float sy);
84
85     // Inputs.
86     tcu::Vec4               coords;
87     tcu::Vec4               unitCoords;
88     tcu::Vec4               constCoords;
89
90     tcu::Vec4               in[MAX_USER_ATTRIBS];
91     ShaderSampler           textures[MAX_TEXTURES];
92
93     // Output.
94     tcu::Vec4               color;
95     bool                    isDiscarded;
96
97     // Functions.
98     inline void             discard                 (void)  { isDiscarded = true; }
99     tcu::Vec4               texture2D               (int unitNdx, const tcu::Vec2& coords);
100
101 private:
102     const QuadGrid&         quadGrid;
103 };
104
105
106 typedef void (*ShaderEvalFunc) (ShaderEvalContext& c);
107
108 inline void evalCoordsPassthroughX      (ShaderEvalContext& c) { c.color.x() = c.coords.x(); }
109 inline void evalCoordsPassthroughXY     (ShaderEvalContext& c) { c.color.xy() = c.coords.swizzle(0,1); }
110 inline void evalCoordsPassthroughXYZ    (ShaderEvalContext& c) { c.color.xyz() = c.coords.swizzle(0,1,2); }
111 inline void evalCoordsPassthrough       (ShaderEvalContext& c) { c.color = c.coords; }
112 inline void evalCoordsSwizzleWZYX       (ShaderEvalContext& c) { c.color = c.coords.swizzle(3,2,1,0); }
113
114 // ShaderEvaluator
115 // Either inherit a class with overridden evaluate() or just pass in an evalFunc.
116
117 class ShaderEvaluator
118 {
119 public:
120                         ShaderEvaluator         (void);
121                         ShaderEvaluator         (ShaderEvalFunc evalFunc);
122     virtual             ~ShaderEvaluator        (void);
123
124     virtual void        evaluate                (ShaderEvalContext& ctx);
125
126 private:
127                         ShaderEvaluator         (const ShaderEvaluator&);   // not allowed!
128     ShaderEvaluator&    operator=               (const ShaderEvaluator&);   // not allowed!
129
130     ShaderEvalFunc      m_evalFunc;
131 };
132
133
134 class ShaderRenderCase : public vkt::TestCase
135 {
136 public:
137                                                         ShaderRenderCase        (tcu::TestContext& testCtx,
138                                                                                                 const std::string& name,
139                                                                                                 const std::string& description,
140                                                                                                 bool isVertexCase,
141                                                                                                 ShaderEvalFunc evalFunc);
142                                                         ShaderRenderCase        (tcu::TestContext& testCtx,
143                                                                                                 const std::string& name,
144                                                                                                 const std::string& description,
145                                                                                                 bool isVertexCase,
146                                                                                                 ShaderEvaluator* evaulator);
147
148         virtual                                 ~ShaderRenderCase       (void);
149         virtual void                    initPrograms            (vk::ProgramCollection<glu::ProgramSources>& programCollection) const;
150         virtual TestInstance*   createInstance          (Context& context) const;
151
152 private:
153         bool                                    m_isVertexCase;
154         ShaderEvaluator*                m_evaluator;
155 };
156
157 // ShaderRenderCaseInstance.
158
159 class ShaderRenderCaseInstance : public vkt::TestInstance
160 {
161 public:
162                                                         ShaderRenderCaseInstance        (Context& context, bool isVertexCase, ShaderEvaluator& evaluator);
163         virtual                                 ~ShaderRenderCaseInstance       (void);
164         virtual tcu::TestStatus iterate                                         (void);
165
166 private:
167         bool                            m_isVertexCase;
168         ShaderEvaluator&        m_evaluator;
169 };
170
171
172 } // shaderrendercase
173 } // vkt
174
175 #endif // _VKTSHADERRENDERCASE_HPP