1 #ifndef _GLUSHADERUTIL_HPP
2 #define _GLUSHADERUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
5 * ------------------------------------------------
6 *
7 * Copyright 2014 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 utilities.
24 *//*--------------------------------------------------------------------*/
25
26 #include "tcuDefs.hpp"
27 #include "deInt32.h"
28 #include "gluRenderContext.hpp"
29 #include "tcuVector.hpp"
30 #include "tcuVector.hpp"
31 #include "tcuMatrix.hpp"
32
33 namespace glu
34 {
35
36 // ShadingLanguageVersion
37
38 enum GLSLVersion
39 {
40 GLSL_VERSION_100_ES = 0, //!< GLSL ES 1.0
41 GLSL_VERSION_300_ES, //!< GLSL ES 3.0
42 GLSL_VERSION_310_ES, //!< GLSL ES 3.1
43 GLSL_VERSION_320_ES, //!< GLSL ES 3.2
44
45 GLSL_VERSION_130, //!< GLSL 1.3
46 GLSL_VERSION_140, //!< GLSL 1.4
47 GLSL_VERSION_150, //!< GLSL 1.5
48 GLSL_VERSION_330, //!< GLSL 3.0
49 GLSL_VERSION_400, //!< GLSL 4.0
50 GLSL_VERSION_410, //!< GLSL 4.1
51 GLSL_VERSION_420, //!< GLSL 4.2
52 GLSL_VERSION_430, //!< GLSL 4.3
53 GLSL_VERSION_440, //!< GLSL 4.4
54 GLSL_VERSION_450, //!< GLSL 4.5
55 GLSL_VERSION_460, //!< GLSL 4.6
56
57 GLSL_VERSION_LAST
58 };
59
60 const char* getGLSLVersionName (GLSLVersion version);
61 const char* getGLSLVersionDeclaration (GLSLVersion version);
62 bool glslVersionUsesInOutQualifiers (GLSLVersion version);
63 bool glslVersionIsES (GLSLVersion version);
64 bool isGLSLVersionSupported (ContextType type, GLSLVersion version);
65 GLSLVersion getContextTypeGLSLVersion (ContextType type);
66
67 // ShaderType
68
69 enum ShaderType
70 {
71 SHADERTYPE_VERTEX = 0,
72 SHADERTYPE_FRAGMENT,
73 SHADERTYPE_GEOMETRY,
74 SHADERTYPE_TESSELLATION_CONTROL,
75 SHADERTYPE_TESSELLATION_EVALUATION,
76 SHADERTYPE_COMPUTE,
77
78 SHADERTYPE_LAST
79 };
80
81 const char* getShaderTypeName (ShaderType shaderType);
82
83 // Precision
84
85 enum Precision
86 {
87 PRECISION_LOWP = 0,
88 PRECISION_MEDIUMP,
89 PRECISION_HIGHP,
90
91 PRECISION_LAST
92 };
93
94 const char* getPrecisionName (Precision precision);
95
96 // DataType
97
98 enum DataType
99 {
100 TYPE_INVALID = 0,
101
102 TYPE_FLOAT,
103 TYPE_FLOAT_VEC2,
104 TYPE_FLOAT_VEC3,
105 TYPE_FLOAT_VEC4,
106 TYPE_FLOAT_MAT2,
107 TYPE_FLOAT_MAT2X3,
108 TYPE_FLOAT_MAT2X4,
109 TYPE_FLOAT_MAT3X2,
110 TYPE_FLOAT_MAT3,
111 TYPE_FLOAT_MAT3X4,
112 TYPE_FLOAT_MAT4X2,
113 TYPE_FLOAT_MAT4X3,
114 TYPE_FLOAT_MAT4,
115
116 TYPE_DOUBLE,
117 TYPE_DOUBLE_VEC2,
118 TYPE_DOUBLE_VEC3,
119 TYPE_DOUBLE_VEC4,
120 TYPE_DOUBLE_MAT2,
121 TYPE_DOUBLE_MAT2X3,
122 TYPE_DOUBLE_MAT2X4,
123 TYPE_DOUBLE_MAT3X2,
124 TYPE_DOUBLE_MAT3,
125 TYPE_DOUBLE_MAT3X4,
126 TYPE_DOUBLE_MAT4X2,
127 TYPE_DOUBLE_MAT4X3,
128 TYPE_DOUBLE_MAT4,
129
130 TYPE_INT,
131 TYPE_INT_VEC2,
132 TYPE_INT_VEC3,
133 TYPE_INT_VEC4,
134
135 TYPE_UINT,
136 TYPE_UINT_VEC2,
137 TYPE_UINT_VEC3,
138 TYPE_UINT_VEC4,
139
140 TYPE_BOOL,
141 TYPE_BOOL_VEC2,
142 TYPE_BOOL_VEC3,
143 TYPE_BOOL_VEC4,
144
145 TYPE_SAMPLER_1D,
146 TYPE_SAMPLER_2D,
147 TYPE_SAMPLER_CUBE,
148 TYPE_SAMPLER_1D_ARRAY,
149 TYPE_SAMPLER_2D_ARRAY,
150 TYPE_SAMPLER_3D,
151 TYPE_SAMPLER_CUBE_ARRAY,
152
153 TYPE_SAMPLER_1D_SHADOW,
154 TYPE_SAMPLER_2D_SHADOW,
155 TYPE_SAMPLER_CUBE_SHADOW,
156 TYPE_SAMPLER_1D_ARRAY_SHADOW,
157 TYPE_SAMPLER_2D_ARRAY_SHADOW,
158 TYPE_SAMPLER_CUBE_ARRAY_SHADOW,
159
160 TYPE_INT_SAMPLER_1D,
161 TYPE_INT_SAMPLER_2D,
162 TYPE_INT_SAMPLER_CUBE,
163 TYPE_INT_SAMPLER_1D_ARRAY,
164 TYPE_INT_SAMPLER_2D_ARRAY,
165 TYPE_INT_SAMPLER_3D,
166 TYPE_INT_SAMPLER_CUBE_ARRAY,
167
168 TYPE_UINT_SAMPLER_1D,
169 TYPE_UINT_SAMPLER_2D,
170 TYPE_UINT_SAMPLER_CUBE,
171 TYPE_UINT_SAMPLER_1D_ARRAY,
172 TYPE_UINT_SAMPLER_2D_ARRAY,
173 TYPE_UINT_SAMPLER_3D,
174 TYPE_UINT_SAMPLER_CUBE_ARRAY,
175
176 TYPE_SAMPLER_2D_MULTISAMPLE,
177 TYPE_INT_SAMPLER_2D_MULTISAMPLE,
178 TYPE_UINT_SAMPLER_2D_MULTISAMPLE,
179
180 TYPE_IMAGE_2D,
181 TYPE_IMAGE_CUBE,
182 TYPE_IMAGE_2D_ARRAY,
183 TYPE_IMAGE_3D,
184 TYPE_IMAGE_CUBE_ARRAY,
185
186 TYPE_INT_IMAGE_2D,
187 TYPE_INT_IMAGE_CUBE,
188 TYPE_INT_IMAGE_2D_ARRAY,
189 TYPE_INT_IMAGE_3D,
190 TYPE_INT_IMAGE_CUBE_ARRAY,
191
192 TYPE_UINT_IMAGE_2D,
193 TYPE_UINT_IMAGE_CUBE,
194 TYPE_UINT_IMAGE_2D_ARRAY,
195 TYPE_UINT_IMAGE_3D,
196 TYPE_UINT_IMAGE_CUBE_ARRAY,
197
198 TYPE_UINT_ATOMIC_COUNTER,
199
200 TYPE_SAMPLER_BUFFER,
201 TYPE_INT_SAMPLER_BUFFER,
202 TYPE_UINT_SAMPLER_BUFFER,
203
204 TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY,
205 TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY,
206 TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY,
207
208 TYPE_IMAGE_BUFFER,
209 TYPE_INT_IMAGE_BUFFER,
210 TYPE_UINT_IMAGE_BUFFER,
211
212 TYPE_LAST
213 };
214
215 const char* getDataTypeName (DataType dataType);
216 int getDataTypeScalarSize (DataType dataType);
217 DataType getDataTypeScalarType (DataType dataType);
218 DataType getDataTypeFloatScalars (DataType dataType);
219 DataType getDataTypeDoubleScalars (DataType dataType);
220 DataType getDataTypeVector (DataType scalarType, int size);
221 DataType getDataTypeFloatVec (int vecSize);
222 DataType getDataTypeIntVec (int vecSize);
223 DataType getDataTypeUintVec (int vecSize);
224 DataType getDataTypeBoolVec (int vecSize);
225 DataType getDataTypeMatrix (int numCols, int numRows);
226 DataType getDataTypeFromGLType (deUint32 glType);
227
isDataTypeFloatOrVec(DataType dataType)228 inline bool isDataTypeFloatOrVec (DataType dataType) { return (dataType >= TYPE_FLOAT) && (dataType <= TYPE_FLOAT_VEC4); }
isDataTypeDoubleOrDVec(DataType dataType)229 inline bool isDataTypeDoubleOrDVec (DataType dataType) { return (dataType >= TYPE_DOUBLE) && (dataType <= TYPE_DOUBLE_VEC4); }
isDataTypeMatrix(DataType dataType)230 inline bool isDataTypeMatrix (DataType dataType) { return ((dataType >= TYPE_FLOAT_MAT2) && (dataType <= TYPE_FLOAT_MAT4)) || ((dataType >= TYPE_DOUBLE_MAT2) && (dataType <= TYPE_DOUBLE_MAT4)); }
isDataTypeIntOrIVec(DataType dataType)231 inline bool isDataTypeIntOrIVec (DataType dataType) { return (dataType >= TYPE_INT) && (dataType <= TYPE_INT_VEC4); }
isDataTypeUintOrUVec(DataType dataType)232 inline bool isDataTypeUintOrUVec (DataType dataType) { return (dataType >= TYPE_UINT) && (dataType <= TYPE_UINT_VEC4); }
isDataTypeBoolOrBVec(DataType dataType)233 inline bool isDataTypeBoolOrBVec (DataType dataType) { return (dataType >= TYPE_BOOL) && (dataType <= TYPE_BOOL_VEC4); }
isDataTypeScalar(DataType dataType)234 inline bool isDataTypeScalar (DataType dataType) { return (dataType == TYPE_FLOAT) || (dataType == TYPE_DOUBLE) ||(dataType == TYPE_INT) || (dataType == TYPE_UINT) || (dataType == TYPE_BOOL); }
isDataTypeVector(DataType dataType)235 inline bool isDataTypeVector (DataType dataType) { return deInRange32(dataType, TYPE_FLOAT_VEC2, TYPE_FLOAT_VEC4) || deInRange32(dataType, TYPE_DOUBLE_VEC2, TYPE_DOUBLE_VEC4) || deInRange32(dataType, TYPE_INT_VEC2, TYPE_INT_VEC4) || deInRange32(dataType, TYPE_UINT_VEC2, TYPE_UINT_VEC4) || deInRange32(dataType, TYPE_BOOL_VEC2, TYPE_BOOL_VEC4); }
isDataTypeScalarOrVector(DataType dataType)236 inline bool isDataTypeScalarOrVector (DataType dataType) { return deInRange32(dataType, TYPE_FLOAT, TYPE_FLOAT_VEC4) || deInRange32(dataType, TYPE_DOUBLE, TYPE_DOUBLE_VEC4) || deInRange32(dataType, TYPE_INT, TYPE_INT_VEC4) || deInRange32(dataType, TYPE_UINT, TYPE_UINT_VEC4) || deInRange32(dataType, TYPE_BOOL, TYPE_BOOL_VEC4); }
isDataTypeSampler(DataType dataType)237 inline bool isDataTypeSampler (DataType dataType) { return (dataType >= TYPE_SAMPLER_1D) && (dataType <= TYPE_UINT_SAMPLER_2D_MULTISAMPLE); }
isDataTypeImage(DataType dataType)238 inline bool isDataTypeImage (DataType dataType) { return (dataType >= TYPE_IMAGE_2D) && (dataType <= TYPE_UINT_IMAGE_3D); }
isDataTypeSamplerMultisample(DataType dataType)239 inline bool isDataTypeSamplerMultisample(DataType dataType) { return (dataType >= TYPE_SAMPLER_2D_MULTISAMPLE) && (dataType <= TYPE_UINT_SAMPLER_2D_MULTISAMPLE); }
isDataTypeAtomicCounter(DataType dataType)240 inline bool isDataTypeAtomicCounter (DataType dataType) { return dataType == TYPE_UINT_ATOMIC_COUNTER; }
isDataTypeSamplerBuffer(DataType dataType)241 inline bool isDataTypeSamplerBuffer (DataType dataType) { return (dataType >= TYPE_SAMPLER_BUFFER) && (dataType <= TYPE_UINT_SAMPLER_BUFFER); }
isDataTypeSamplerMSArray(DataType dataType)242 inline bool isDataTypeSamplerMSArray (DataType dataType) { return (dataType >= TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY) && (dataType <= TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY); }
isDataTypeImageBuffer(DataType dataType)243 inline bool isDataTypeImageBuffer (DataType dataType) { return (dataType >= TYPE_IMAGE_BUFFER) && (dataType <= TYPE_UINT_IMAGE_BUFFER); }
244
245 int getDataTypeMatrixNumRows (DataType dataType);
246 int getDataTypeMatrixNumColumns (DataType dataType);
247
248 int getDataTypeNumLocations (DataType dataType);
249 int getDataTypeNumComponents (DataType dataType);
250
251 template <typename T>
252 struct DataTypeTraits;
253
254 template <> struct DataTypeTraits<float> { enum { DATATYPE = TYPE_FLOAT }; };
255 template <> struct DataTypeTraits<bool> { enum { DATATYPE = TYPE_BOOL }; };
256 template <> struct DataTypeTraits<int> { enum { DATATYPE = TYPE_INT }; };
257 template <> struct DataTypeTraits<deUint32> { enum { DATATYPE = TYPE_UINT }; };
258 template <> struct DataTypeTraits<tcu::Mat2> { enum { DATATYPE = TYPE_FLOAT_MAT2 }; };
259 template <> struct DataTypeTraits<tcu::Mat2x3> { enum { DATATYPE = TYPE_FLOAT_MAT2X3 }; };
260 template <> struct DataTypeTraits<tcu::Mat2x4> { enum { DATATYPE = TYPE_FLOAT_MAT2X4 }; };
261 template <> struct DataTypeTraits<tcu::Mat3x2> { enum { DATATYPE = TYPE_FLOAT_MAT3X2 }; };
262 template <> struct DataTypeTraits<tcu::Mat3> { enum { DATATYPE = TYPE_FLOAT_MAT3 }; };
263 template <> struct DataTypeTraits<tcu::Mat3x4> { enum { DATATYPE = TYPE_FLOAT_MAT3X4 }; };
264 template <> struct DataTypeTraits<tcu::Mat4x2> { enum { DATATYPE = TYPE_FLOAT_MAT4X2 }; };
265 template <> struct DataTypeTraits<tcu::Mat4x3> { enum { DATATYPE = TYPE_FLOAT_MAT4X3 }; };
266 template <> struct DataTypeTraits<tcu::Mat4> { enum { DATATYPE = TYPE_FLOAT_MAT4 }; };
267
268 template <typename T, int Size>
269 struct DataTypeTraits<tcu::Vector<T, Size> >
270 {
271 DE_STATIC_ASSERT(TYPE_FLOAT_VEC4 == TYPE_FLOAT + 3);
272 DE_STATIC_ASSERT(TYPE_INT_VEC4 == TYPE_INT + 3);
273 DE_STATIC_ASSERT(TYPE_UINT_VEC4 == TYPE_UINT + 3);
274 DE_STATIC_ASSERT(TYPE_BOOL_VEC4 == TYPE_BOOL + 3);
275 enum { DATATYPE = DataTypeTraits<T>::DATATYPE + Size - 1 };
276 };
277
278 template <typename T>
dataTypeOf(void)279 inline DataType dataTypeOf (void) { return DataType(DataTypeTraits<T>::DATATYPE); }
280
281 } // glu
282
283 #endif // _GLUSHADERUTIL_HPP
284