Test component qualifier in shaders
[platform/upstream/VK-GL-CTS.git] / framework / opengl / gluShaderLibrary.hpp
1 #ifndef _GLUSHADERLIBRARY_HPP
2 #define _GLUSHADERLIBRARY_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES Utilities
5  * ------------------------------------------------
6  *
7  * Copyright 2015 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Shader .test file utilities.
24  *//*--------------------------------------------------------------------*/
25
26 #include "gluDefs.hpp"
27 #include "gluVarType.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "tcuTestCase.hpp"
30
31 #include <string>
32 #include <vector>
33
34 namespace glu
35 {
36 namespace sl
37 {
38
39 enum CaseType
40 {
41         CASETYPE_COMPLETE = 0,          //!< Has all shaders specified separately.
42         CASETYPE_VERTEX_ONLY,           //!< "Both" case, vertex shader sub case.
43         CASETYPE_FRAGMENT_ONLY,         //!< "Both" case, fragment shader sub case.
44
45         CASETYPE_LAST
46 };
47
48 enum ExpectResult
49 {
50         EXPECT_PASS = 0,
51         EXPECT_COMPILE_FAIL,
52         EXPECT_LINK_FAIL,
53         EXPECT_COMPILE_LINK_FAIL,
54         EXPECT_VALIDATION_FAIL,
55         EXPECT_BUILD_SUCCESSFUL,
56
57         EXPECT_LAST
58 };
59
60 enum OutputType
61 {
62         OUTPUT_RESULT = 0,
63         OUTPUT_COLOR,
64
65         OUTPUT_LAST
66 };
67
68 struct Value
69 {
70         union Element
71         {
72                 float           float32;
73                 deInt32         int32;
74                 deInt32         bool32;
75         };
76
77         VarType                                 type;
78         std::string                             name;
79         std::vector<Element>    elements;               // Scalar values (variable.varType.getScalarSize() * #values).
80 };
81
82 struct ValueBlock
83 {
84         std::vector<Value>              inputs;
85         std::vector<Value>              outputs;
86         std::vector<Value>              uniforms;
87 };
88
89 struct RequiredCapability
90 {
91         deUint32                                enumName;
92         int                                             referenceValue;
93
94         RequiredCapability (void)
95                 : enumName                      (0u)
96                 , referenceValue        (0)
97         {
98         }
99
100         RequiredCapability (deUint32 enumName_, int referenceValue_)
101                 : enumName                      (enumName_)
102                 , referenceValue        (referenceValue_)
103         {
104         }
105 };
106
107 struct RequiredExtension
108 {
109         std::vector<std::string>        alternatives;           // One or more extensions, at least one (but not all) must be supported
110         deUint32                                        effectiveStages;        // Bitfield of shader stages requiring this extension
111
112         RequiredExtension (const std::vector<std::string>&      alternatives_,
113                                            deUint32                                                     effectiveStages_)
114                 : alternatives          (alternatives_)
115                 , effectiveStages       (effectiveStages_)
116         {
117         }
118
119                 RequiredExtension (const std::string&   extension,
120                                                    deUint32                             effectiveStages_)
121                 : effectiveStages       (effectiveStages_)
122         {
123                 alternatives.push_back(extension);
124         }
125
126         RequiredExtension (void)
127                 : effectiveStages       (0u)
128         {
129         }
130 };
131
132 struct ProgramSpecification
133 {
134         glu::ProgramSources                             sources;
135         std::vector<RequiredExtension>  requiredExtensions;
136         deUint32                                                activeStages;   // Has an effect only if sources.separable == true, must be 0 otherwise
137
138         ProgramSpecification (void)
139                 : activeStages(0u)
140         {
141         }
142 };
143
144 struct ShaderCaseSpecification
145 {
146         CaseType                                                        caseType;
147         ExpectResult                                            expectResult;
148         OutputType                                                      outputType;
149         DataType                                                        outputFormat;
150         glu::GLSLVersion                                        targetVersion;
151
152         // \todo [pyry] Clean this up
153         std::vector<RequiredCapability>         requiredCaps;
154         bool                                                            fullGLSLES100Required;
155
156         ValueBlock                                                      values;
157         std::vector<ProgramSpecification>       programs;
158
159         ShaderCaseSpecification (void)
160                 : caseType                              (CASETYPE_LAST)
161                 , expectResult                  (EXPECT_LAST)
162                 , outputType                    (OUTPUT_RESULT)
163                 , outputFormat                  (TYPE_LAST)
164                 , targetVersion                 (glu::GLSL_VERSION_LAST)
165                 , fullGLSLES100Required (false)
166         {
167         }
168 };
169
170 bool    isValid         (const ValueBlock& block);
171 bool    isValid         (const ShaderCaseSpecification& spec);
172
173 class ShaderCaseFactory
174 {
175 public:
176         virtual tcu::TestCaseGroup*     createGroup     (const std::string& name, const std::string& description, const std::vector<tcu::TestNode*>& children) = 0;
177         virtual tcu::TestCase*          createCase      (const std::string& name, const std::string& description, const ShaderCaseSpecification& spec) = 0;
178 };
179
180 std::vector<tcu::TestNode*>             parseFile       (const tcu::Archive& archive, const std::string& filename, ShaderCaseFactory* caseFactory);
181
182 // Specialization utilties
183
184 struct ProgramSpecializationParams
185 {
186         const ShaderCaseSpecification&                  caseSpec;
187         const std::vector<RequiredExtension>    requiredExtensions;     // Extensions, must be resolved to single ext per entry
188         const int                                                               maxPatchVertices;       // Used by tess shaders only
189
190         ProgramSpecializationParams (const ShaderCaseSpecification&                     caseSpec_,
191                                                                  const std::vector<RequiredExtension>&  requiredExtensions_,
192                                                                  int                                                                    maxPatchVertices_)
193                 : caseSpec                              (caseSpec_)
194                 , requiredExtensions    (requiredExtensions_)
195                 , maxPatchVertices              (maxPatchVertices_)
196         {
197         }
198 };
199
200 void                    genCompareFunctions                     (std::ostringstream& stream, const ValueBlock& valueBlock, bool useFloatTypes);
201 std::string             injectExtensionRequirements     (const std::string& baseCode, const std::vector<RequiredExtension>& extensions, ShaderType shaderType);
202
203 // Other utilities
204
205 void                    dumpValues                                      (tcu::TestLog& log, const ValueBlock& values, int arrayNdx);
206
207 } // sl
208 } // glu
209
210 #endif // _GLUSHADERLIBRARY_HPP