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