• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
44 	GLSL_VERSION_130,			//!< GLSL 1.3
45 	GLSL_VERSION_140,			//!< GLSL 1.4
46 	GLSL_VERSION_150,			//!< GLSL 1.5
47 	GLSL_VERSION_330,			//!< GLSL 3.0
48 	GLSL_VERSION_400,			//!< GLSL 4.0
49 	GLSL_VERSION_410,			//!< GLSL 4.1
50 	GLSL_VERSION_420,			//!< GLSL 4.2
51 	GLSL_VERSION_430,			//!< GLSL 4.3
52 	GLSL_VERSION_440,			//!< GLSL 4.4
53 
54 	GLSL_VERSION_LAST
55 };
56 
57 const char*		getGLSLVersionName				(GLSLVersion version);
58 const char*		getGLSLVersionDeclaration		(GLSLVersion version);
59 bool			glslVersionUsesInOutQualifiers	(GLSLVersion version);
60 bool			glslVersionIsES					(GLSLVersion version);
61 bool			isGLSLVersionSupported			(ContextType type, GLSLVersion version);
62 GLSLVersion		getContextTypeGLSLVersion		(ContextType type);
63 
64 // ShaderType
65 
66 enum ShaderType
67 {
68 	SHADERTYPE_VERTEX = 0,
69 	SHADERTYPE_FRAGMENT,
70 	SHADERTYPE_GEOMETRY,
71 	SHADERTYPE_TESSELLATION_CONTROL,
72 	SHADERTYPE_TESSELLATION_EVALUATION,
73 	SHADERTYPE_COMPUTE,
74 
75 	SHADERTYPE_LAST
76 };
77 
78 const char*	getShaderTypeName (ShaderType shaderType);
79 
80 // Precision
81 
82 enum Precision
83 {
84 	PRECISION_LOWP = 0,
85 	PRECISION_MEDIUMP,
86 	PRECISION_HIGHP,
87 
88 	PRECISION_LAST
89 };
90 
91 const char* getPrecisionName (Precision precision);
92 
93 // DataType
94 
95 enum DataType
96 {
97 	TYPE_INVALID	= 0,
98 
99 	TYPE_FLOAT,
100 	TYPE_FLOAT_VEC2,
101 	TYPE_FLOAT_VEC3,
102 	TYPE_FLOAT_VEC4,
103 	TYPE_FLOAT_MAT2,
104 	TYPE_FLOAT_MAT2X3,
105 	TYPE_FLOAT_MAT2X4,
106 	TYPE_FLOAT_MAT3X2,
107 	TYPE_FLOAT_MAT3,
108 	TYPE_FLOAT_MAT3X4,
109 	TYPE_FLOAT_MAT4X2,
110 	TYPE_FLOAT_MAT4X3,
111 	TYPE_FLOAT_MAT4,
112 
113 	TYPE_INT,
114 	TYPE_INT_VEC2,
115 	TYPE_INT_VEC3,
116 	TYPE_INT_VEC4,
117 
118 	TYPE_UINT,
119 	TYPE_UINT_VEC2,
120 	TYPE_UINT_VEC3,
121 	TYPE_UINT_VEC4,
122 
123 	TYPE_BOOL,
124 	TYPE_BOOL_VEC2,
125 	TYPE_BOOL_VEC3,
126 	TYPE_BOOL_VEC4,
127 
128 	TYPE_SAMPLER_1D,
129 	TYPE_SAMPLER_2D,
130 	TYPE_SAMPLER_CUBE,
131 	TYPE_SAMPLER_2D_ARRAY,
132 	TYPE_SAMPLER_3D,
133 	TYPE_SAMPLER_CUBE_ARRAY,
134 
135 	TYPE_SAMPLER_1D_SHADOW,
136 	TYPE_SAMPLER_2D_SHADOW,
137 	TYPE_SAMPLER_CUBE_SHADOW,
138 	TYPE_SAMPLER_2D_ARRAY_SHADOW,
139 	TYPE_SAMPLER_CUBE_ARRAY_SHADOW,
140 
141 	TYPE_INT_SAMPLER_1D,
142 	TYPE_INT_SAMPLER_2D,
143 	TYPE_INT_SAMPLER_CUBE,
144 	TYPE_INT_SAMPLER_2D_ARRAY,
145 	TYPE_INT_SAMPLER_3D,
146 	TYPE_INT_SAMPLER_CUBE_ARRAY,
147 
148 	TYPE_UINT_SAMPLER_1D,
149 	TYPE_UINT_SAMPLER_2D,
150 	TYPE_UINT_SAMPLER_CUBE,
151 	TYPE_UINT_SAMPLER_2D_ARRAY,
152 	TYPE_UINT_SAMPLER_3D,
153 	TYPE_UINT_SAMPLER_CUBE_ARRAY,
154 
155 	TYPE_SAMPLER_2D_MULTISAMPLE,
156 	TYPE_INT_SAMPLER_2D_MULTISAMPLE,
157 	TYPE_UINT_SAMPLER_2D_MULTISAMPLE,
158 
159 	TYPE_IMAGE_2D,
160 	TYPE_IMAGE_CUBE,
161 	TYPE_IMAGE_2D_ARRAY,
162 	TYPE_IMAGE_3D,
163 	TYPE_IMAGE_CUBE_ARRAY,
164 
165 	TYPE_INT_IMAGE_2D,
166 	TYPE_INT_IMAGE_CUBE,
167 	TYPE_INT_IMAGE_2D_ARRAY,
168 	TYPE_INT_IMAGE_3D,
169 	TYPE_INT_IMAGE_CUBE_ARRAY,
170 
171 	TYPE_UINT_IMAGE_2D,
172 	TYPE_UINT_IMAGE_CUBE,
173 	TYPE_UINT_IMAGE_2D_ARRAY,
174 	TYPE_UINT_IMAGE_3D,
175 	TYPE_UINT_IMAGE_CUBE_ARRAY,
176 
177 	TYPE_UINT_ATOMIC_COUNTER,
178 
179 	TYPE_LAST
180 };
181 
182 const char*		getDataTypeName				(DataType dataType);
183 int				getDataTypeScalarSize		(DataType dataType);
184 DataType		getDataTypeScalarType		(DataType dataType);
185 DataType		getDataTypeFloatScalars		(DataType dataType);
186 DataType		getDataTypeVector			(DataType scalarType, int size);
187 DataType		getDataTypeFloatVec			(int vecSize);
188 DataType		getDataTypeIntVec			(int vecSize);
189 DataType		getDataTypeUintVec			(int vecSize);
190 DataType		getDataTypeBoolVec			(int vecSize);
191 DataType		getDataTypeMatrix			(int numCols, int numRows);
192 DataType		getDataTypeFromGLType		(deUint32 glType);
193 
isDataTypeFloatOrVec(DataType dataType)194 inline bool		isDataTypeFloatOrVec		(DataType dataType)	{ return (dataType >= TYPE_FLOAT)      && (dataType <= TYPE_FLOAT_VEC4);   }
isDataTypeMatrix(DataType dataType)195 inline bool		isDataTypeMatrix			(DataType dataType)	{ return (dataType >= TYPE_FLOAT_MAT2) && (dataType <= TYPE_FLOAT_MAT4);   }
isDataTypeIntOrIVec(DataType dataType)196 inline bool		isDataTypeIntOrIVec			(DataType dataType)	{ return (dataType >= TYPE_INT)        && (dataType <= TYPE_INT_VEC4);     }
isDataTypeUintOrUVec(DataType dataType)197 inline bool		isDataTypeUintOrUVec		(DataType dataType)	{ return (dataType >= TYPE_UINT)       && (dataType <= TYPE_UINT_VEC4);     }
isDataTypeBoolOrBVec(DataType dataType)198 inline bool		isDataTypeBoolOrBVec		(DataType dataType)	{ return (dataType >= TYPE_BOOL)       && (dataType <= TYPE_BOOL_VEC4);    }
isDataTypeScalar(DataType dataType)199 inline bool		isDataTypeScalar			(DataType dataType) { return (dataType == TYPE_FLOAT) || (dataType == TYPE_INT) || (dataType == TYPE_UINT) || (dataType == TYPE_BOOL); }
isDataTypeVector(DataType dataType)200 inline bool		isDataTypeVector			(DataType dataType) { return deInRange32(dataType, TYPE_FLOAT_VEC2, TYPE_FLOAT_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)201 inline bool		isDataTypeScalarOrVector	(DataType dataType) { return deInRange32(dataType, TYPE_FLOAT, TYPE_FLOAT_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)202 inline bool		isDataTypeSampler			(DataType dataType)	{ return (dataType >= TYPE_SAMPLER_1D) && (dataType <= TYPE_UINT_SAMPLER_2D_MULTISAMPLE); }
isDataTypeImage(DataType dataType)203 inline bool		isDataTypeImage				(DataType dataType)	{ return (dataType >= TYPE_IMAGE_2D) && (dataType <= TYPE_UINT_IMAGE_3D); }
isDataTypeSamplerMultisample(DataType dataType)204 inline bool		isDataTypeSamplerMultisample(DataType dataType)	{ return (dataType >= TYPE_SAMPLER_2D_MULTISAMPLE) && (dataType <= TYPE_UINT_SAMPLER_2D_MULTISAMPLE); }
isDataTypeAtomicCounter(DataType dataType)205 inline bool		isDataTypeAtomicCounter		(DataType dataType)	{ return dataType == TYPE_UINT_ATOMIC_COUNTER; }
206 
207 int				getDataTypeMatrixNumRows	(DataType dataType);
208 int				getDataTypeMatrixNumColumns	(DataType dataType);
209 
210 int				getDataTypeNumLocations		(DataType dataType);
211 int				getDataTypeNumComponents	(DataType dataType);
212 
213 template <typename T>
214 struct DataTypeTraits;
215 
216 template <> struct DataTypeTraits<float>		{ enum { DATATYPE = TYPE_FLOAT			}; };
217 template <> struct DataTypeTraits<bool>			{ enum { DATATYPE = TYPE_BOOL			}; };
218 template <> struct DataTypeTraits<int>			{ enum { DATATYPE = TYPE_INT			}; };
219 template <> struct DataTypeTraits<deUint32>		{ enum { DATATYPE = TYPE_UINT			}; };
220 template <> struct DataTypeTraits<tcu::Mat2>	{ enum { DATATYPE = TYPE_FLOAT_MAT2		}; };
221 template <> struct DataTypeTraits<tcu::Mat2x3>	{ enum { DATATYPE = TYPE_FLOAT_MAT2X3	}; };
222 template <> struct DataTypeTraits<tcu::Mat2x4>	{ enum { DATATYPE = TYPE_FLOAT_MAT2X4	}; };
223 template <> struct DataTypeTraits<tcu::Mat3x2>	{ enum { DATATYPE = TYPE_FLOAT_MAT3X2	}; };
224 template <> struct DataTypeTraits<tcu::Mat3>	{ enum { DATATYPE = TYPE_FLOAT_MAT3		}; };
225 template <> struct DataTypeTraits<tcu::Mat3x4>	{ enum { DATATYPE = TYPE_FLOAT_MAT3X4	}; };
226 template <> struct DataTypeTraits<tcu::Mat4x2>	{ enum { DATATYPE = TYPE_FLOAT_MAT4X2	}; };
227 template <> struct DataTypeTraits<tcu::Mat4x3>	{ enum { DATATYPE = TYPE_FLOAT_MAT4X3	}; };
228 template <> struct DataTypeTraits<tcu::Mat4>	{ enum { DATATYPE = TYPE_FLOAT_MAT4		}; };
229 
230 template <typename T, int Size>
231 struct DataTypeTraits<tcu::Vector<T, Size> >
232 {
233 	DE_STATIC_ASSERT(TYPE_FLOAT_VEC4 == TYPE_FLOAT + 3);
234 	DE_STATIC_ASSERT(TYPE_INT_VEC4 == TYPE_INT + 3);
235 	DE_STATIC_ASSERT(TYPE_UINT_VEC4 == TYPE_UINT + 3);
236 	DE_STATIC_ASSERT(TYPE_BOOL_VEC4 == TYPE_BOOL + 3);
237 	enum { DATATYPE = DataTypeTraits<T>::DATATYPE + Size - 1 };
238 };
239 
240 template <typename T>
dataTypeOf(void)241 inline DataType	dataTypeOf (void) { return DataType(DataTypeTraits<T>::DATATYPE); }
242 
243 } // glu
244 
245 #endif // _GLUSHADERUTIL_HPP
246