1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Shader utilities.
22 *//*--------------------------------------------------------------------*/
23
24 #include "gluShaderUtil.hpp"
25 #include "glwEnums.hpp"
26 #include "deArrayUtil.hpp"
27
28 namespace glu
29 {
30
31 // ShadingLanguageVersion
32
getGLSLVersionName(GLSLVersion version)33 const char* getGLSLVersionName (GLSLVersion version)
34 {
35 static const char* s_names[] =
36 {
37 "GLSL ES 1.0",
38 "GLSL ES 3.0",
39 "GLSL ES 3.1",
40 "GLSL ES 3.2",
41 "GLSL 1.3",
42 "GLSL 1.4",
43 "GLSL 1.5",
44 "GLSL 3.3",
45 "GLSL 4.0",
46 "GLSL 4.1",
47 "GLSL 4.2",
48 "GLSL 4.3",
49 "GLSL 4.4",
50 "GLSL 4.5",
51 "GLSL 4.6",
52 };
53
54 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_names, version);
55 }
56
getGLSLVersionDeclaration(GLSLVersion version)57 const char* getGLSLVersionDeclaration (GLSLVersion version)
58 {
59 static const char* s_decl[] =
60 {
61 "#version 100",
62 "#version 300 es",
63 "#version 310 es",
64 "#version 320 es",
65 "#version 130",
66 "#version 140",
67 "#version 150",
68 "#version 330",
69 "#version 400",
70 "#version 410",
71 "#version 420",
72 "#version 430",
73 "#version 440",
74 "#version 450",
75 "#version 460",
76 };
77
78 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_decl, version);
79 }
80
glslVersionUsesInOutQualifiers(GLSLVersion version)81 bool glslVersionUsesInOutQualifiers (GLSLVersion version)
82 {
83 return de::inRange<int>(version, GLSL_VERSION_300_ES, GLSL_VERSION_320_ES) || de::inRange<int>(version, GLSL_VERSION_330, GLSL_VERSION_460);
84 }
85
glslVersionIsES(GLSLVersion version)86 bool glslVersionIsES (GLSLVersion version)
87 {
88 DE_STATIC_ASSERT(GLSL_VERSION_LAST == 15);
89 DE_ASSERT(version != GLSL_VERSION_LAST);
90
91 if (version == GLSL_VERSION_100_ES ||
92 version == GLSL_VERSION_300_ES ||
93 version == GLSL_VERSION_310_ES ||
94 version == GLSL_VERSION_320_ES)
95 return true;
96 else
97 return false;
98 }
99
100 // \todo [2014-10-06 pyry] Export this.
getMinAPIForGLSLVersion(GLSLVersion version)101 static ApiType getMinAPIForGLSLVersion (GLSLVersion version)
102 {
103 static const ApiType s_minApi[] =
104 {
105 ApiType::es(2,0),
106 ApiType::es(3,0),
107 ApiType::es(3,1),
108 ApiType::es(3,2),
109 ApiType::core(3,0),
110 ApiType::core(3,1),
111 ApiType::core(3,2),
112 ApiType::core(3,3),
113 ApiType::core(4,0),
114 ApiType::core(4,1),
115 ApiType::core(4,2),
116 ApiType::core(4,3),
117 ApiType::core(4,4),
118 ApiType::core(4,5),
119 ApiType::core(4,6),
120 };
121
122 return de::getSizedArrayElement<GLSL_VERSION_LAST>(s_minApi, version);
123 }
124
isGLSLVersionSupported(ContextType type,GLSLVersion version)125 bool isGLSLVersionSupported (ContextType type, GLSLVersion version)
126 {
127 return contextSupports(type, getMinAPIForGLSLVersion(version));
128 }
129
getContextTypeGLSLVersion(ContextType type)130 GLSLVersion getContextTypeGLSLVersion (ContextType type)
131 {
132 // \note From newer to older
133 for (int version = GLSL_VERSION_LAST-1; version >= 0; version--)
134 {
135 if (isGLSLVersionSupported(type, GLSLVersion(version)))
136 return GLSLVersion(version);
137 }
138
139 DE_ASSERT(false);
140 return GLSL_VERSION_LAST;
141 }
142
143 // ShaderType
144
getShaderTypeName(ShaderType shaderType)145 const char* getShaderTypeName (ShaderType shaderType)
146 {
147 static const char* s_names[] =
148 {
149 "vertex",
150 "fragment",
151 "geometry",
152 "tess_control",
153 "tess_eval",
154 "compute",
155 "unused for GL",
156 "unused for GL",
157 "unused for GL",
158 "unused for GL",
159 "unused for GL",
160 "unused for GL",
161 };
162
163 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == SHADERTYPE_LAST);
164 DE_ASSERT(deInBounds32((int)shaderType, 0, SHADERTYPE_LAST));
165 return s_names[(int)shaderType];
166 }
167
getShaderTypePostfix(ShaderType shaderType)168 std::string getShaderTypePostfix (ShaderType shaderType)
169 {
170 return "_" + std::string(getShaderTypeName(shaderType));
171 }
172
173 // Precision
174
getPrecisionName(Precision precision)175 const char* getPrecisionName (Precision precision)
176 {
177 static const char* s_names[] =
178 {
179 "lowp",
180 "mediump",
181 "highp"
182 };
183
184 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == PRECISION_LAST);
185 DE_ASSERT(deInBounds32((int)precision, 0, PRECISION_LAST));
186 return s_names[(int)precision];
187 }
188
getPrecisionPostfix(Precision precision)189 std::string getPrecisionPostfix (Precision precision)
190 {
191 return "_" + std::string(getPrecisionName(precision));
192 }
193
194 // DataType
195
getDataTypeName(DataType dataType)196 const char* getDataTypeName (DataType dataType)
197 {
198 static const char* s_names[] =
199 {
200 "invalid",
201 "float",
202 "vec2",
203 "vec3",
204 "vec4",
205 "mat2",
206 "mat2x3",
207 "mat2x4",
208 "mat3x2",
209 "mat3",
210 "mat3x4",
211 "mat4x2",
212 "mat4x3",
213 "mat4",
214 "double",
215 "dvec2",
216 "dvec3",
217 "dvec4",
218 "dmat2",
219 "dmat2x3",
220 "dmat2x4",
221 "dmat3x2",
222 "dmat3",
223 "dmat3x4",
224 "dmat4x2",
225 "dmat4x3",
226 "dmat4",
227 "int",
228 "ivec2",
229 "ivec3",
230 "ivec4",
231 "uint",
232 "uvec2",
233 "uvec3",
234 "uvec4",
235 "bool",
236 "bvec2",
237 "bvec3",
238 "bvec4",
239 "sampler1D",
240 "sampler2D",
241 "samplerCube",
242 "sampler1DArray",
243 "sampler2DArray",
244 "sampler3D",
245 "samplerCubeArray",
246 "sampler1DShadow",
247 "sampler2DShadow",
248 "samplerCubeShadow",
249 "sampler1DArrayShadow",
250 "sampler2DArrayShadow",
251 "samplerCubeArrayShadow",
252 "isampler1D",
253 "isampler2D",
254 "isamplerCube",
255 "isampler1DArray",
256 "isampler2DArray",
257 "isampler3D",
258 "isamplerCubeArray",
259 "usampler1D",
260 "usampler2D",
261 "usamplerCube",
262 "usampler1DArray",
263 "usampler2DArray",
264 "usampler3D",
265 "usamplerCubeArray",
266 "sampler2DMS",
267 "isampler2DMS",
268 "usampler2DMS",
269 "image2D",
270 "imageCube",
271 "image2DArray",
272 "image3D",
273 "imageCubeArray",
274 "iimage2D",
275 "iimageCube",
276 "iimage2DArray",
277 "iimage3D",
278 "iimageCubeArray",
279 "uimage2D",
280 "uimageCube",
281 "uimage2DArray",
282 "uimage3D",
283 "uimageCubeArray",
284 "atomic_uint",
285 "samplerBuffer",
286 "isamplerBuffer",
287 "usamplerBuffer",
288 "sampler2DMSArray",
289 "isampler2DMSArray",
290 "usampler2DMSArray",
291 "imageBuffer",
292 "iimageBuffer",
293 "uimageBuffer",
294 "uint8_t",
295 "u8vec2",
296 "u8vec3",
297 "u8vec4",
298 "int8_t",
299 "i8vec2",
300 "i8vec3",
301 "i8vec4",
302 "uint16_t",
303 "u16vec2",
304 "u16vec3",
305 "u16vec4",
306 "int16_t",
307 "i16vec2",
308 "i16vec3",
309 "i16vec4",
310 "float16_t",
311 "f16vec2",
312 "f16vec3",
313 "f16vec4",
314 "f16mat2",
315 "f16mat2x3",
316 "f16mat2x4",
317 "f16mat3x2",
318 "f16mat3",
319 "f16mat3x4",
320 "f16mat4x2",
321 "f16mat4x3",
322 "f16mat4",
323 };
324
325 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_names) == TYPE_LAST);
326 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_names)));
327 return s_names[(int)dataType];
328 }
329
getDataTypeScalarSize(DataType dataType)330 int getDataTypeScalarSize (DataType dataType)
331 {
332 static const int s_sizes[] =
333 {
334 -1, // invalid
335 1, // float
336 2, // vec2
337 3, // vec3
338 4, // vec4
339 4, // mat2
340 6, // mat2x3
341 8, // mat2x4
342 6, // mat3x2
343 9, // mat3
344 12, // mat3x4
345 8, // mat4x2
346 12, // mat4x3
347 16, // mat4
348 1, // double
349 2, // dvec2
350 3, // dvec3
351 4, // dvec4
352 4, // dmat2
353 6, // dmat2x3
354 8, // dmat2x4
355 6, // dmat3x2
356 9, // dmat3
357 12, // dmat3x4
358 8, // dmat4x2
359 12, // dmat4x3
360 16, // dmat4
361 1, // int
362 2, // ivec2
363 3, // ivec3
364 4, // ivec4
365 1, // uint
366 2, // uvec2
367 3, // uvec3
368 4, // uvec4
369 1, // bool
370 2, // bvec2
371 3, // bvec3
372 4, // bvec4
373 1, // sampler1D
374 1, // sampler2D
375 1, // samplerCube
376 1, // sampler1DArray
377 1, // sampler2DArray
378 1, // sampler3D
379 1, // samplerCubeArray
380 1, // sampler1DShadow
381 1, // sampler2DShadow
382 1, // samplerCubeShadow
383 1, // sampler1DArrayShadow
384 1, // sampler2DArrayShadow
385 1, // samplerCubeArrayShadow
386 1, // isampler1D
387 1, // isampler2D
388 1, // isamplerCube
389 1, // isampler1DArray
390 1, // isampler2DArray
391 1, // isampler3D
392 1, // isamplerCubeArray
393 1, // usampler1D
394 1, // usampler2D
395 1, // usamplerCube
396 1, // usampler1DArray
397 1, // usampler2DArray
398 1, // usampler3D
399 1, // usamplerCubeArray
400 1, // sampler2DMS
401 1, // isampler2DMS
402 1, // usampler2DMS
403 1, // image2D
404 1, // imageCube
405 1, // image2DArray
406 1, // image3D
407 1, // imageCubeArray
408 1, // iimage2D
409 1, // iimageCube
410 1, // iimage2DArray
411 1, // iimage3D
412 1, // iimageCubeArray
413 1, // uimage2D
414 1, // uimageCube
415 1, // uimage2DArray
416 1, // uimage3D
417 1, // uimageCubeArray
418 1, // atomic_uint
419 1, // samplerBuffer
420 1, // isamplerBuffer
421 1, // usamplerBuffer
422 1, // sampler2DMSArray
423 1, // isampler2DMSArray
424 1, // usampler2DMSArray
425 1, // imageBuffer
426 1, // iimageBuffer
427 1, // uimageBuffer
428 1, // uint8_t
429 2, // u8vec2
430 3, // u8vec3
431 4, // u8vec4
432 1, // int8_t
433 2, // i8vec2
434 3, // i8vec3
435 4, // i8vec4
436 1, // uint16_t
437 2, // u16vec2
438 3, // u16vec3
439 4, // u16vec4
440 1, // int16_t
441 2, // i16vec2
442 3, // i16vec3
443 4, // i16vec4
444 1, // float16_t
445 2, // f16vec2
446 3, // f16vec3
447 4, // f16vec4
448 4, // f16mat2
449 6, // f16mat2x3
450 8, // f16mat2x4
451 6, // f16mat3x2
452 9, // f16mat3
453 12, // f16mat3x4
454 8, // f16mat4x2
455 12, // f16mat4x3
456 16, // f16mat4
457 };
458
459 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_sizes) == TYPE_LAST);
460 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_sizes)));
461 return s_sizes[(int)dataType];
462 }
463
getDataTypeScalarType(DataType dataType)464 DataType getDataTypeScalarType (DataType dataType)
465 {
466 static const DataType s_scalarTypes[] =
467 {
468 TYPE_INVALID, // invalid
469 TYPE_FLOAT, // float
470 TYPE_FLOAT, // vec2
471 TYPE_FLOAT, // vec3
472 TYPE_FLOAT, // vec4
473 TYPE_FLOAT, // mat2
474 TYPE_FLOAT, // mat2x3
475 TYPE_FLOAT, // mat2x4
476 TYPE_FLOAT, // mat3x2
477 TYPE_FLOAT, // mat3
478 TYPE_FLOAT, // mat3x4
479 TYPE_FLOAT, // mat4x2
480 TYPE_FLOAT, // mat4x3
481 TYPE_FLOAT, // mat4
482 TYPE_DOUBLE, // double
483 TYPE_DOUBLE, // dvec2
484 TYPE_DOUBLE, // dvec3
485 TYPE_DOUBLE, // dvec4
486 TYPE_DOUBLE, // dmat2
487 TYPE_DOUBLE, // dmat2x3
488 TYPE_DOUBLE, // dmat2x4
489 TYPE_DOUBLE, // dmat3x2
490 TYPE_DOUBLE, // dmat3
491 TYPE_DOUBLE, // dmat3x4
492 TYPE_DOUBLE, // dmat4x2
493 TYPE_DOUBLE, // dmat4x3
494 TYPE_DOUBLE, // dmat4
495 TYPE_INT, // int
496 TYPE_INT, // ivec2
497 TYPE_INT, // ivec3
498 TYPE_INT, // ivec4
499 TYPE_UINT, // uint
500 TYPE_UINT, // uvec2
501 TYPE_UINT, // uvec3
502 TYPE_UINT, // uvec4
503 TYPE_BOOL, // bool
504 TYPE_BOOL, // bvec2
505 TYPE_BOOL, // bvec3
506 TYPE_BOOL, // bvec4
507 TYPE_SAMPLER_1D, // sampler1D
508 TYPE_SAMPLER_2D, // sampler2D
509 TYPE_SAMPLER_CUBE, // samplerCube
510 TYPE_SAMPLER_1D_ARRAY, // sampler1DArray
511 TYPE_SAMPLER_2D_ARRAY, // sampler2DArray
512 TYPE_SAMPLER_3D, // sampler3D
513 TYPE_SAMPLER_CUBE_ARRAY, // samplerCubeArray
514 TYPE_SAMPLER_1D_SHADOW, // sampler1DShadow
515 TYPE_SAMPLER_2D_SHADOW, // sampler2DShadow
516 TYPE_SAMPLER_CUBE_SHADOW, // samplerCubeShadow
517 TYPE_SAMPLER_1D_ARRAY_SHADOW, // sampler1DArrayShadow
518 TYPE_SAMPLER_2D_ARRAY_SHADOW, // sampler2DArrayShadow
519 TYPE_SAMPLER_CUBE_ARRAY_SHADOW, // samplerCubeArrayShadow
520 TYPE_INT_SAMPLER_1D, // isampler1D
521 TYPE_INT_SAMPLER_2D, // isampler2D
522 TYPE_INT_SAMPLER_CUBE, // isamplerCube
523 TYPE_INT_SAMPLER_1D_ARRAY, // isampler1DArray
524 TYPE_INT_SAMPLER_2D_ARRAY, // isampler2DArray
525 TYPE_INT_SAMPLER_3D, // isampler3D
526 TYPE_INT_SAMPLER_CUBE_ARRAY, // isamplerCubeArray
527 TYPE_UINT_SAMPLER_1D, // usampler1D
528 TYPE_UINT_SAMPLER_2D, // usampler2D
529 TYPE_UINT_SAMPLER_CUBE, // usamplerCube
530 TYPE_UINT_SAMPLER_1D_ARRAY, // usampler1DArray
531 TYPE_UINT_SAMPLER_2D_ARRAY, // usampler2DArray
532 TYPE_UINT_SAMPLER_3D, // usampler3D
533 TYPE_UINT_SAMPLER_CUBE_ARRAY, // usamplerCubeArray
534 TYPE_SAMPLER_2D_MULTISAMPLE, // sampler2DMS
535 TYPE_INT_SAMPLER_2D_MULTISAMPLE, // isampler2DMS
536 TYPE_UINT_SAMPLER_2D_MULTISAMPLE, // usampler2DMS
537 TYPE_IMAGE_2D, // image2D
538 TYPE_IMAGE_CUBE, // imageCube
539 TYPE_IMAGE_2D_ARRAY, // image2DArray
540 TYPE_IMAGE_3D, // image3D
541 TYPE_IMAGE_CUBE_ARRAY, // imageCubeArray
542 TYPE_INT_IMAGE_2D, // iimage2D
543 TYPE_INT_IMAGE_CUBE, // iimageCube
544 TYPE_INT_IMAGE_2D_ARRAY, // iimage2DArray
545 TYPE_INT_IMAGE_3D, // iimage3D
546 TYPE_INT_IMAGE_CUBE_ARRAY, // iimageCubeArray
547 TYPE_UINT_IMAGE_2D, // uimage2D
548 TYPE_UINT_IMAGE_CUBE, // uimageCube
549 TYPE_UINT_IMAGE_2D_ARRAY, // uimage2DArray
550 TYPE_UINT_IMAGE_3D, // uimage3D
551 TYPE_UINT_IMAGE_CUBE_ARRAY, // uimageCubeArray
552 TYPE_UINT_ATOMIC_COUNTER, // atomic_uint
553 TYPE_SAMPLER_BUFFER, // samplerBuffer
554 TYPE_INT_SAMPLER_BUFFER, // isamplerBuffer
555 TYPE_UINT_SAMPLER_BUFFER, // usamplerBuffer
556 TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY, // sampler2DMSArray
557 TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY, // isampler2DMSArray
558 TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY, // usampler2DMSArray
559 TYPE_IMAGE_BUFFER, // imageBuffer
560 TYPE_INT_IMAGE_BUFFER, // iimageBuffer
561 TYPE_UINT_IMAGE_BUFFER, // uimageBuffer
562 TYPE_UINT8, // uint8_t
563 TYPE_UINT8, // u8vec2
564 TYPE_UINT8, // u8vec3
565 TYPE_UINT8, // u8vec4
566 TYPE_INT8, // int8_t
567 TYPE_INT8, // i8vec2
568 TYPE_INT8, // i8vec3
569 TYPE_INT8, // i8vec4
570 TYPE_UINT16, // uint16_t
571 TYPE_UINT16, // u16vec2
572 TYPE_UINT16, // u16vec3
573 TYPE_UINT16, // u16vec4
574 TYPE_INT16, // int16_t
575 TYPE_INT16, // i16vec2
576 TYPE_INT16, // i16vec3
577 TYPE_INT16, // i16vec4
578 TYPE_FLOAT16, // float16_t
579 TYPE_FLOAT16, // f16vec2
580 TYPE_FLOAT16, // f16vec3
581 TYPE_FLOAT16, // f16vec4
582 TYPE_FLOAT16, // f16mat2
583 TYPE_FLOAT16, // f16mat2x3
584 TYPE_FLOAT16, // f16mat2x4
585 TYPE_FLOAT16, // f16mat3x2
586 TYPE_FLOAT16, // f16mat3
587 TYPE_FLOAT16, // f16mat3x4
588 TYPE_FLOAT16, // f16mat4x2
589 TYPE_FLOAT16, // f16mat4x3
590 TYPE_FLOAT16, // f16mat4
591 };
592
593 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_scalarTypes) == TYPE_LAST);
594 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_scalarTypes)));
595 return s_scalarTypes[(int)dataType];
596 }
597
getDataTypeFloat16Scalars(DataType dataType)598 DataType getDataTypeFloat16Scalars (DataType dataType)
599 {
600 static const DataType s_floatTypes[] =
601 {
602 TYPE_INVALID, // invalid
603 TYPE_FLOAT16, // float
604 TYPE_FLOAT16_VEC2, // vec2
605 TYPE_FLOAT16_VEC3, // vec3
606 TYPE_FLOAT16_VEC4, // vec4
607 TYPE_FLOAT16_MAT2, // mat2
608 TYPE_FLOAT16_MAT2X3, // mat2x3
609 TYPE_FLOAT16_MAT2X4, // mat2x4
610 TYPE_FLOAT16_MAT3X2, // mat3x2
611 TYPE_FLOAT16_MAT3, // mat3
612 TYPE_FLOAT16_MAT3X4, // mat3x4
613 TYPE_FLOAT16_MAT4X2, // mat4x2
614 TYPE_FLOAT16_MAT4X3, // mat4x3
615 TYPE_FLOAT16_MAT4, // mat4
616 TYPE_FLOAT16, // double
617 TYPE_FLOAT16_VEC2, // dvec2
618 TYPE_FLOAT16_VEC3, // dvec3
619 TYPE_FLOAT16_VEC4, // dvec4
620 TYPE_FLOAT16_MAT2, // dmat2
621 TYPE_FLOAT16_MAT2X3, // dmat2x3
622 TYPE_FLOAT16_MAT2X4, // dmat2x4
623 TYPE_FLOAT16_MAT3X2, // dmat3x2
624 TYPE_FLOAT16_MAT3, // dmat3
625 TYPE_FLOAT16_MAT3X4, // dmat3x4
626 TYPE_FLOAT16_MAT4X2, // dmat4x2
627 TYPE_FLOAT16_MAT4X3, // dmat4x3
628 TYPE_FLOAT16_MAT4, // dmat4
629 TYPE_FLOAT16, // int
630 TYPE_FLOAT16_VEC2, // ivec2
631 TYPE_FLOAT16_VEC3, // ivec3
632 TYPE_FLOAT16_VEC4, // ivec4
633 TYPE_FLOAT16, // uint
634 TYPE_FLOAT16_VEC2, // uvec2
635 TYPE_FLOAT16_VEC3, // uvec3
636 TYPE_FLOAT16_VEC4, // uvec4
637 TYPE_FLOAT16, // bool
638 TYPE_FLOAT16_VEC2, // bvec2
639 TYPE_FLOAT16_VEC3, // bvec3
640 TYPE_FLOAT16_VEC4, // bvec4
641 TYPE_INVALID, // sampler1D
642 TYPE_INVALID, // sampler2D
643 TYPE_INVALID, // samplerCube
644 TYPE_INVALID, // sampler1DArray
645 TYPE_INVALID, // sampler2DArray
646 TYPE_INVALID, // sampler3D
647 TYPE_INVALID, // samplerCubeArray
648 TYPE_INVALID, // sampler1DShadow
649 TYPE_INVALID, // sampler2DShadow
650 TYPE_INVALID, // samplerCubeShadow
651 TYPE_INVALID, // sampler1DArrayShadow
652 TYPE_INVALID, // sampler2DArrayShadow
653 TYPE_INVALID, // samplerCubeArrayShadow
654 TYPE_INVALID, // isampler1D
655 TYPE_INVALID, // isampler2D
656 TYPE_INVALID, // isamplerCube
657 TYPE_INVALID, // isampler1DArray
658 TYPE_INVALID, // isampler2DArray
659 TYPE_INVALID, // isampler3D
660 TYPE_INVALID, // isamplerCubeArray
661 TYPE_INVALID, // usampler1D
662 TYPE_INVALID, // usampler2D
663 TYPE_INVALID, // usamplerCube
664 TYPE_INVALID, // usampler1DArray
665 TYPE_INVALID, // usampler2DArray
666 TYPE_INVALID, // usampler3D
667 TYPE_INVALID, // usamplerCubeArray
668 TYPE_INVALID, // sampler2DMS
669 TYPE_INVALID, // isampler2DMS
670 TYPE_INVALID, // usampler2DMS
671 TYPE_INVALID, // image2D
672 TYPE_INVALID, // imageCube
673 TYPE_INVALID, // image2DArray
674 TYPE_INVALID, // image3D
675 TYPE_INVALID, // imageCubeArray
676 TYPE_INVALID, // iimage2D
677 TYPE_INVALID, // iimageCube
678 TYPE_INVALID, // iimage2DArray
679 TYPE_INVALID, // iimage3D
680 TYPE_INVALID, // iimageCubeArray
681 TYPE_INVALID, // uimage2D
682 TYPE_INVALID, // uimageCube
683 TYPE_INVALID, // uimage2DArray
684 TYPE_INVALID, // uimage3D
685 TYPE_INVALID, // uimageCubeArray
686 TYPE_INVALID, // atomic_uint
687 TYPE_INVALID, // samplerBuffer
688 TYPE_INVALID, // isamplerBuffer
689 TYPE_INVALID, // usamplerBuffer
690 TYPE_INVALID, // sampler2DMSArray
691 TYPE_INVALID, // isampler2DMSArray
692 TYPE_INVALID, // usampler2DMSArray
693 TYPE_INVALID, // imageBuffer
694 TYPE_INVALID, // iimageBuffer
695 TYPE_INVALID, // uimageBuffer
696 TYPE_FLOAT16, // uint8_t
697 TYPE_FLOAT16_VEC2, // u8vec2
698 TYPE_FLOAT16_VEC3, // u8vec3
699 TYPE_FLOAT16_VEC4, // u8vec4
700 TYPE_FLOAT16, // int8_t
701 TYPE_FLOAT16_VEC2, // i8vec2
702 TYPE_FLOAT16_VEC3, // i8vec3
703 TYPE_FLOAT16_VEC4, // i8vec4
704 TYPE_FLOAT16, // uint16_t
705 TYPE_FLOAT16_VEC2, // u16vec2
706 TYPE_FLOAT16_VEC3, // u16vec3
707 TYPE_FLOAT16_VEC4, // u16vec4
708 TYPE_FLOAT16, // int16_t
709 TYPE_FLOAT16_VEC2, // i16vec2
710 TYPE_FLOAT16_VEC3, // i16vec3
711 TYPE_FLOAT16_VEC4, // i16vec4
712 TYPE_FLOAT16, // float16_t
713 TYPE_FLOAT16_VEC2, // f16vec2
714 TYPE_FLOAT16_VEC3, // f16vec3
715 TYPE_FLOAT16_VEC4, // f16vec4
716 TYPE_FLOAT16_MAT2, // f16mat2
717 TYPE_FLOAT16_MAT2X3, // f16mat2x3
718 TYPE_FLOAT16_MAT2X4, // f16mat2x4
719 TYPE_FLOAT16_MAT3X2, // f16mat3x2
720 TYPE_FLOAT16_MAT3, // f16mat3
721 TYPE_FLOAT16_MAT3X4, // f16mat3x4
722 TYPE_FLOAT16_MAT4X2, // f16mat4x2
723 TYPE_FLOAT16_MAT4X3, // f16mat4x3
724 TYPE_FLOAT16_MAT4, // f16mat4
725 };
726
727 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
728 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
729 return s_floatTypes[(int)dataType];
730 }
731
getDataTypeFloatScalars(DataType dataType)732 DataType getDataTypeFloatScalars (DataType dataType)
733 {
734 static const DataType s_floatTypes[] =
735 {
736 TYPE_INVALID, // invalid
737 TYPE_FLOAT, // float
738 TYPE_FLOAT_VEC2, // vec2
739 TYPE_FLOAT_VEC3, // vec3
740 TYPE_FLOAT_VEC4, // vec4
741 TYPE_FLOAT_MAT2, // mat2
742 TYPE_FLOAT_MAT2X3, // mat2x3
743 TYPE_FLOAT_MAT2X4, // mat2x4
744 TYPE_FLOAT_MAT3X2, // mat3x2
745 TYPE_FLOAT_MAT3, // mat3
746 TYPE_FLOAT_MAT3X4, // mat3x4
747 TYPE_FLOAT_MAT4X2, // mat4x2
748 TYPE_FLOAT_MAT4X3, // mat4x3
749 TYPE_FLOAT_MAT4, // mat4
750 TYPE_FLOAT, // double
751 TYPE_FLOAT_VEC2, // dvec2
752 TYPE_FLOAT_VEC3, // dvec3
753 TYPE_FLOAT_VEC4, // dvec4
754 TYPE_FLOAT_MAT2, // dmat2
755 TYPE_FLOAT_MAT2X3, // dmat2x3
756 TYPE_FLOAT_MAT2X4, // dmat2x4
757 TYPE_FLOAT_MAT3X2, // dmat3x2
758 TYPE_FLOAT_MAT3, // dmat3
759 TYPE_FLOAT_MAT3X4, // dmat3x4
760 TYPE_FLOAT_MAT4X2, // dmat4x2
761 TYPE_FLOAT_MAT4X3, // dmat4x3
762 TYPE_FLOAT_MAT4, // dmat4
763 TYPE_FLOAT, // int
764 TYPE_FLOAT_VEC2, // ivec2
765 TYPE_FLOAT_VEC3, // ivec3
766 TYPE_FLOAT_VEC4, // ivec4
767 TYPE_FLOAT, // uint
768 TYPE_FLOAT_VEC2, // uvec2
769 TYPE_FLOAT_VEC3, // uvec3
770 TYPE_FLOAT_VEC4, // uvec4
771 TYPE_FLOAT, // bool
772 TYPE_FLOAT_VEC2, // bvec2
773 TYPE_FLOAT_VEC3, // bvec3
774 TYPE_FLOAT_VEC4, // bvec4
775 TYPE_INVALID, // sampler1D
776 TYPE_INVALID, // sampler2D
777 TYPE_INVALID, // samplerCube
778 TYPE_INVALID, // sampler1DArray
779 TYPE_INVALID, // sampler2DArray
780 TYPE_INVALID, // sampler3D
781 TYPE_INVALID, // samplerCubeArray
782 TYPE_INVALID, // sampler1DShadow
783 TYPE_INVALID, // sampler2DShadow
784 TYPE_INVALID, // samplerCubeShadow
785 TYPE_INVALID, // sampler1DArrayShadow
786 TYPE_INVALID, // sampler2DArrayShadow
787 TYPE_INVALID, // samplerCubeArrayShadow
788 TYPE_INVALID, // isampler1D
789 TYPE_INVALID, // isampler2D
790 TYPE_INVALID, // isamplerCube
791 TYPE_INVALID, // isampler1DArray
792 TYPE_INVALID, // isampler2DArray
793 TYPE_INVALID, // isampler3D
794 TYPE_INVALID, // isamplerCubeArray
795 TYPE_INVALID, // usampler1D
796 TYPE_INVALID, // usampler2D
797 TYPE_INVALID, // usamplerCube
798 TYPE_INVALID, // usampler1DArray
799 TYPE_INVALID, // usampler2DArray
800 TYPE_INVALID, // usampler3D
801 TYPE_INVALID, // usamplerCubeArray
802 TYPE_INVALID, // sampler2DMS
803 TYPE_INVALID, // isampler2DMS
804 TYPE_INVALID, // usampler2DMS
805 TYPE_INVALID, // image2D
806 TYPE_INVALID, // imageCube
807 TYPE_INVALID, // image2DArray
808 TYPE_INVALID, // image3D
809 TYPE_INVALID, // imageCubeArray
810 TYPE_INVALID, // iimage2D
811 TYPE_INVALID, // iimageCube
812 TYPE_INVALID, // iimage2DArray
813 TYPE_INVALID, // iimage3D
814 TYPE_INVALID, // iimageCubeArray
815 TYPE_INVALID, // uimage2D
816 TYPE_INVALID, // uimageCube
817 TYPE_INVALID, // uimage2DArray
818 TYPE_INVALID, // uimage3D
819 TYPE_INVALID, // uimageCubeArray
820 TYPE_INVALID, // atomic_uint
821 TYPE_INVALID, // samplerBuffer
822 TYPE_INVALID, // isamplerBuffer
823 TYPE_INVALID, // usamplerBuffer
824 TYPE_INVALID, // sampler2DMSArray
825 TYPE_INVALID, // isampler2DMSArray
826 TYPE_INVALID, // usampler2DMSArray
827 TYPE_INVALID, // imageBuffer
828 TYPE_INVALID, // iimageBuffer
829 TYPE_INVALID, // uimageBuffer
830 TYPE_FLOAT, // uint8_t
831 TYPE_FLOAT_VEC2, // u8vec2
832 TYPE_FLOAT_VEC3, // u8vec3
833 TYPE_FLOAT_VEC4, // u8vec4
834 TYPE_FLOAT, // int8_t
835 TYPE_FLOAT_VEC2, // i8vec2
836 TYPE_FLOAT_VEC3, // i8vec3
837 TYPE_FLOAT_VEC4, // i8vec4
838 TYPE_FLOAT, // uint16_t
839 TYPE_FLOAT_VEC2, // u16vec2
840 TYPE_FLOAT_VEC3, // u16vec3
841 TYPE_FLOAT_VEC4, // u16vec4
842 TYPE_FLOAT, // int16_t
843 TYPE_FLOAT_VEC2, // i16vec2
844 TYPE_FLOAT_VEC3, // i16vec3
845 TYPE_FLOAT_VEC4, // i16vec4
846 TYPE_FLOAT, // float16_t
847 TYPE_FLOAT_VEC2, // f16vec2
848 TYPE_FLOAT_VEC3, // f16vec3
849 TYPE_FLOAT_VEC4, // f16vec4
850 TYPE_FLOAT_MAT2, // f16mat2
851 TYPE_FLOAT_MAT2X3, // f16mat2x3
852 TYPE_FLOAT_MAT2X4, // f16mat2x4
853 TYPE_FLOAT_MAT3X2, // f16mat3x2
854 TYPE_FLOAT_MAT3, // f16mat3
855 TYPE_FLOAT_MAT3X4, // f16mat3x4
856 TYPE_FLOAT_MAT4X2, // f16mat4x2
857 TYPE_FLOAT_MAT4X3, // f16mat4x3
858 TYPE_FLOAT_MAT4, // f16mat4
859 };
860
861 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_floatTypes) == TYPE_LAST);
862 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_floatTypes)));
863 return s_floatTypes[(int)dataType];
864 }
865
getDataTypeDoubleScalars(DataType dataType)866 DataType getDataTypeDoubleScalars (DataType dataType)
867 {
868 static const DataType s_doubleTypes[] =
869 {
870 TYPE_INVALID, // invalid
871 TYPE_DOUBLE, // float
872 TYPE_DOUBLE_VEC2, // vec2
873 TYPE_DOUBLE_VEC3, // vec3
874 TYPE_DOUBLE_VEC4, // vec4
875 TYPE_DOUBLE_MAT2, // mat2
876 TYPE_DOUBLE_MAT2X3, // mat2x3
877 TYPE_DOUBLE_MAT2X4, // mat2x4
878 TYPE_DOUBLE_MAT3X2, // mat3x2
879 TYPE_DOUBLE_MAT3, // mat3
880 TYPE_DOUBLE_MAT3X4, // mat3x4
881 TYPE_DOUBLE_MAT4X2, // mat4x2
882 TYPE_DOUBLE_MAT4X3, // mat4x3
883 TYPE_DOUBLE_MAT4, // mat4
884 TYPE_DOUBLE, // double
885 TYPE_DOUBLE_VEC2, // dvec2
886 TYPE_DOUBLE_VEC3, // dvec3
887 TYPE_DOUBLE_VEC4, // dvec4
888 TYPE_DOUBLE_MAT2, // dmat2
889 TYPE_DOUBLE_MAT2X3, // dmat2x3
890 TYPE_DOUBLE_MAT2X4, // dmat2x4
891 TYPE_DOUBLE_MAT3X2, // dmat3x2
892 TYPE_DOUBLE_MAT3, // dmat3
893 TYPE_DOUBLE_MAT3X4, // dmat3x4
894 TYPE_DOUBLE_MAT4X2, // dmat4x2
895 TYPE_DOUBLE_MAT4X3, // dmat4x3
896 TYPE_DOUBLE_MAT4, // dmat4
897 TYPE_DOUBLE, // int
898 TYPE_DOUBLE_VEC2, // ivec2
899 TYPE_DOUBLE_VEC3, // ivec3
900 TYPE_DOUBLE_VEC4, // ivec4
901 TYPE_DOUBLE, // uint
902 TYPE_DOUBLE_VEC2, // uvec2
903 TYPE_DOUBLE_VEC3, // uvec3
904 TYPE_DOUBLE_VEC4, // uvec4
905 TYPE_DOUBLE, // bool
906 TYPE_DOUBLE_VEC2, // bvec2
907 TYPE_DOUBLE_VEC3, // bvec3
908 TYPE_DOUBLE_VEC4, // bvec4
909 TYPE_INVALID, // sampler1D
910 TYPE_INVALID, // sampler2D
911 TYPE_INVALID, // samplerCube
912 TYPE_INVALID, // sampler1DArray
913 TYPE_INVALID, // sampler2DArray
914 TYPE_INVALID, // sampler3D
915 TYPE_INVALID, // samplerCubeArray
916 TYPE_INVALID, // sampler1DShadow
917 TYPE_INVALID, // sampler2DShadow
918 TYPE_INVALID, // samplerCubeShadow
919 TYPE_INVALID, // sampler1DArrayShadow
920 TYPE_INVALID, // sampler2DArrayShadow
921 TYPE_INVALID, // samplerCubeArrayShadow
922 TYPE_INVALID, // isampler1D
923 TYPE_INVALID, // isampler2D
924 TYPE_INVALID, // isamplerCube
925 TYPE_INVALID, // isampler1DArray
926 TYPE_INVALID, // isampler2DArray
927 TYPE_INVALID, // isampler3D
928 TYPE_INVALID, // isamplerCubeArray
929 TYPE_INVALID, // usampler1D
930 TYPE_INVALID, // usampler2D
931 TYPE_INVALID, // usamplerCube
932 TYPE_INVALID, // usampler1DArray
933 TYPE_INVALID, // usampler2DArray
934 TYPE_INVALID, // usampler3D
935 TYPE_INVALID, // usamplerCubeArray
936 TYPE_INVALID, // sampler2DMS
937 TYPE_INVALID, // isampler2DMS
938 TYPE_INVALID, // usampler2DMS
939 TYPE_INVALID, // image2D
940 TYPE_INVALID, // imageCube
941 TYPE_INVALID, // image2DArray
942 TYPE_INVALID, // image3D
943 TYPE_INVALID, // imageCubeArray
944 TYPE_INVALID, // iimage2D
945 TYPE_INVALID, // iimageCube
946 TYPE_INVALID, // iimage2DArray
947 TYPE_INVALID, // iimage3D
948 TYPE_INVALID, // iimageCubeArray
949 TYPE_INVALID, // uimage2D
950 TYPE_INVALID, // uimageCube
951 TYPE_INVALID, // uimage2DArray
952 TYPE_INVALID, // uimage3D
953 TYPE_INVALID, // uimageCubeArray
954 TYPE_INVALID, // atomic_uint
955 TYPE_INVALID, // samplerBuffer
956 TYPE_INVALID, // isamplerBuffer
957 TYPE_INVALID, // usamplerBuffer
958 TYPE_INVALID, // sampler2DMSArray
959 TYPE_INVALID, // isampler2DMSArray
960 TYPE_INVALID, // usampler2DMSArray
961 TYPE_INVALID, // imageBuffer
962 TYPE_INVALID, // iimageBuffer
963 TYPE_INVALID, // uimageBuffer
964 TYPE_DOUBLE, // uint18_t
965 TYPE_DOUBLE_VEC2, // u8vec2
966 TYPE_DOUBLE_VEC3, // u8vec3
967 TYPE_DOUBLE_VEC4, // u8vec4
968 TYPE_DOUBLE, // int8_t
969 TYPE_DOUBLE_VEC2, // i8vec2
970 TYPE_DOUBLE_VEC3, // i8vec3
971 TYPE_DOUBLE_VEC4, // i8vec4
972 TYPE_DOUBLE, // uint16_t
973 TYPE_DOUBLE_VEC2, // u16vec2
974 TYPE_DOUBLE_VEC3, // u16vec3
975 TYPE_DOUBLE_VEC4, // u16vec4
976 TYPE_DOUBLE, // int16_t
977 TYPE_DOUBLE_VEC2, // i16vec2
978 TYPE_DOUBLE_VEC3, // i16vec3
979 TYPE_DOUBLE_VEC4, // i16vec4
980 TYPE_DOUBLE, // float16_t
981 TYPE_DOUBLE_VEC2, // f16vec2
982 TYPE_DOUBLE_VEC3, // f16vec3
983 TYPE_DOUBLE_VEC4, // f16vec4
984 TYPE_DOUBLE_MAT2, // f16mat2
985 TYPE_DOUBLE_MAT2X3, // f16mat2x3
986 TYPE_DOUBLE_MAT2X4, // f16mat2x4
987 TYPE_DOUBLE_MAT3X2, // f16mat3x2
988 TYPE_DOUBLE_MAT3, // f16mat3
989 TYPE_DOUBLE_MAT3X4, // f16mat3x4
990 TYPE_DOUBLE_MAT4X2, // f16mat4x2
991 TYPE_DOUBLE_MAT4X3, // f16mat4x3
992 TYPE_DOUBLE_MAT4, // f16mat4
993 };
994
995 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_doubleTypes) == TYPE_LAST);
996 DE_ASSERT(deInBounds32((int)dataType, 0, DE_LENGTH_OF_ARRAY(s_doubleTypes)));
997 return s_doubleTypes[(int)dataType];
998 }
999
getDataTypeVector(DataType scalarType,int size)1000 DataType getDataTypeVector (DataType scalarType, int size)
1001 {
1002 DE_ASSERT(deInRange32(size, 1, 4));
1003 switch (scalarType)
1004 {
1005 case TYPE_FLOAT:
1006 case TYPE_DOUBLE:
1007 case TYPE_INT:
1008 case TYPE_UINT:
1009 case TYPE_BOOL:
1010 case TYPE_UINT8:
1011 case TYPE_INT8:
1012 case TYPE_UINT16:
1013 case TYPE_INT16:
1014 case TYPE_FLOAT16:
1015 return (DataType)((int)scalarType + size - 1);
1016 default:
1017 return TYPE_INVALID;
1018 }
1019 }
1020
getDataTypeFloatVec(int vecSize)1021 DataType getDataTypeFloatVec (int vecSize)
1022 {
1023 return getDataTypeVector(TYPE_FLOAT, vecSize);
1024 }
1025
getDataTypeIntVec(int vecSize)1026 DataType getDataTypeIntVec (int vecSize)
1027 {
1028 return getDataTypeVector(TYPE_INT, vecSize);
1029 }
1030
getDataTypeUintVec(int vecSize)1031 DataType getDataTypeUintVec (int vecSize)
1032 {
1033 return getDataTypeVector(TYPE_UINT, vecSize);
1034 }
1035
getDataTypeBoolVec(int vecSize)1036 DataType getDataTypeBoolVec (int vecSize)
1037 {
1038 return getDataTypeVector(TYPE_BOOL, vecSize);
1039 }
1040
getDataTypeMatrix(int numCols,int numRows)1041 DataType getDataTypeMatrix (int numCols, int numRows)
1042 {
1043 DE_ASSERT(de::inRange(numCols, 2, 4) && de::inRange(numRows, 2, 4));
1044 return (DataType)((int)TYPE_FLOAT_MAT2 + (numCols-2)*3 + (numRows-2));
1045 }
1046
getDataTypeMatrixNumRows(DataType dataType)1047 int getDataTypeMatrixNumRows (DataType dataType)
1048 {
1049 switch (dataType)
1050 {
1051 case TYPE_FLOAT_MAT2: return 2;
1052 case TYPE_FLOAT_MAT2X3: return 3;
1053 case TYPE_FLOAT_MAT2X4: return 4;
1054 case TYPE_FLOAT_MAT3X2: return 2;
1055 case TYPE_FLOAT_MAT3: return 3;
1056 case TYPE_FLOAT_MAT3X4: return 4;
1057 case TYPE_FLOAT_MAT4X2: return 2;
1058 case TYPE_FLOAT_MAT4X3: return 3;
1059 case TYPE_FLOAT_MAT4: return 4;
1060 case TYPE_DOUBLE_MAT2: return 2;
1061 case TYPE_DOUBLE_MAT2X3: return 3;
1062 case TYPE_DOUBLE_MAT2X4: return 4;
1063 case TYPE_DOUBLE_MAT3X2: return 2;
1064 case TYPE_DOUBLE_MAT3: return 3;
1065 case TYPE_DOUBLE_MAT3X4: return 4;
1066 case TYPE_DOUBLE_MAT4X2: return 2;
1067 case TYPE_DOUBLE_MAT4X3: return 3;
1068 case TYPE_DOUBLE_MAT4: return 4;
1069 case TYPE_FLOAT16_MAT2: return 2;
1070 case TYPE_FLOAT16_MAT2X3: return 3;
1071 case TYPE_FLOAT16_MAT2X4: return 4;
1072 case TYPE_FLOAT16_MAT3X2: return 2;
1073 case TYPE_FLOAT16_MAT3: return 3;
1074 case TYPE_FLOAT16_MAT3X4: return 4;
1075 case TYPE_FLOAT16_MAT4X2: return 2;
1076 case TYPE_FLOAT16_MAT4X3: return 3;
1077 case TYPE_FLOAT16_MAT4: return 4;
1078 default:
1079 DE_ASSERT(false);
1080 return 0;
1081 }
1082 }
1083
getDataTypeMatrixNumColumns(DataType dataType)1084 int getDataTypeMatrixNumColumns (DataType dataType)
1085 {
1086 switch (dataType)
1087 {
1088 case TYPE_FLOAT_MAT2: return 2;
1089 case TYPE_FLOAT_MAT2X3: return 2;
1090 case TYPE_FLOAT_MAT2X4: return 2;
1091 case TYPE_FLOAT_MAT3X2: return 3;
1092 case TYPE_FLOAT_MAT3: return 3;
1093 case TYPE_FLOAT_MAT3X4: return 3;
1094 case TYPE_FLOAT_MAT4X2: return 4;
1095 case TYPE_FLOAT_MAT4X3: return 4;
1096 case TYPE_FLOAT_MAT4: return 4;
1097 case TYPE_DOUBLE_MAT2: return 2;
1098 case TYPE_DOUBLE_MAT2X3: return 2;
1099 case TYPE_DOUBLE_MAT2X4: return 2;
1100 case TYPE_DOUBLE_MAT3X2: return 3;
1101 case TYPE_DOUBLE_MAT3: return 3;
1102 case TYPE_DOUBLE_MAT3X4: return 3;
1103 case TYPE_DOUBLE_MAT4X2: return 4;
1104 case TYPE_DOUBLE_MAT4X3: return 4;
1105 case TYPE_DOUBLE_MAT4: return 4;
1106 case TYPE_FLOAT16_MAT2: return 2;
1107 case TYPE_FLOAT16_MAT2X3: return 2;
1108 case TYPE_FLOAT16_MAT2X4: return 2;
1109 case TYPE_FLOAT16_MAT3X2: return 3;
1110 case TYPE_FLOAT16_MAT3: return 3;
1111 case TYPE_FLOAT16_MAT3X4: return 3;
1112 case TYPE_FLOAT16_MAT4X2: return 4;
1113 case TYPE_FLOAT16_MAT4X3: return 4;
1114 case TYPE_FLOAT16_MAT4: return 4;
1115 default:
1116 DE_ASSERT(false);
1117 return 0;
1118 }
1119 }
1120
getDataTypeNumLocations(DataType dataType)1121 int getDataTypeNumLocations (DataType dataType)
1122 {
1123 if (isDataTypeScalarOrVector(dataType))
1124 return 1;
1125 else if (isDataTypeMatrix(dataType))
1126 return getDataTypeMatrixNumColumns(dataType);
1127
1128 DE_FATAL("Illegal datatype.");
1129 return 0;
1130 }
1131
getDataTypeNumComponents(DataType dataType)1132 int getDataTypeNumComponents (DataType dataType)
1133 {
1134 if (isDataTypeScalarOrVector(dataType))
1135 return getDataTypeScalarSize(dataType);
1136 else if (isDataTypeMatrix(dataType))
1137 return getDataTypeMatrixNumRows(dataType);
1138
1139 DE_FATAL("Illegal datatype.");
1140 return 0;
1141 }
1142
getDataTypeFromGLType(deUint32 glType)1143 DataType getDataTypeFromGLType (deUint32 glType)
1144 {
1145 switch (glType)
1146 {
1147 case GL_FLOAT: return TYPE_FLOAT;
1148 case GL_FLOAT_VEC2: return TYPE_FLOAT_VEC2;
1149 case GL_FLOAT_VEC3: return TYPE_FLOAT_VEC3;
1150 case GL_FLOAT_VEC4: return TYPE_FLOAT_VEC4;
1151
1152 case GL_FLOAT_MAT2: return TYPE_FLOAT_MAT2;
1153 case GL_FLOAT_MAT2x3: return TYPE_FLOAT_MAT2X3;
1154 case GL_FLOAT_MAT2x4: return TYPE_FLOAT_MAT2X4;
1155
1156 case GL_FLOAT_MAT3x2: return TYPE_FLOAT_MAT3X2;
1157 case GL_FLOAT_MAT3: return TYPE_FLOAT_MAT3;
1158 case GL_FLOAT_MAT3x4: return TYPE_FLOAT_MAT3X4;
1159
1160 case GL_FLOAT_MAT4x2: return TYPE_FLOAT_MAT4X2;
1161 case GL_FLOAT_MAT4x3: return TYPE_FLOAT_MAT4X3;
1162 case GL_FLOAT_MAT4: return TYPE_FLOAT_MAT4;
1163
1164 case GL_DOUBLE: return TYPE_DOUBLE;
1165 case GL_DOUBLE_VEC2: return TYPE_DOUBLE_VEC2;
1166 case GL_DOUBLE_VEC3: return TYPE_DOUBLE_VEC3;
1167 case GL_DOUBLE_VEC4: return TYPE_DOUBLE_VEC4;
1168
1169 case GL_DOUBLE_MAT2: return TYPE_DOUBLE_MAT2;
1170 case GL_DOUBLE_MAT2x3: return TYPE_DOUBLE_MAT2X3;
1171 case GL_DOUBLE_MAT2x4: return TYPE_DOUBLE_MAT2X4;
1172
1173 case GL_DOUBLE_MAT3x2: return TYPE_DOUBLE_MAT3X2;
1174 case GL_DOUBLE_MAT3: return TYPE_DOUBLE_MAT3;
1175 case GL_DOUBLE_MAT3x4: return TYPE_DOUBLE_MAT3X4;
1176
1177 case GL_DOUBLE_MAT4x2: return TYPE_DOUBLE_MAT4X2;
1178 case GL_DOUBLE_MAT4x3: return TYPE_DOUBLE_MAT4X3;
1179 case GL_DOUBLE_MAT4: return TYPE_DOUBLE_MAT4;
1180
1181 case GL_INT: return TYPE_INT;
1182 case GL_INT_VEC2: return TYPE_INT_VEC2;
1183 case GL_INT_VEC3: return TYPE_INT_VEC3;
1184 case GL_INT_VEC4: return TYPE_INT_VEC4;
1185
1186 case GL_UNSIGNED_INT: return TYPE_UINT;
1187 case GL_UNSIGNED_INT_VEC2: return TYPE_UINT_VEC2;
1188 case GL_UNSIGNED_INT_VEC3: return TYPE_UINT_VEC3;
1189 case GL_UNSIGNED_INT_VEC4: return TYPE_UINT_VEC4;
1190
1191 case GL_BOOL: return TYPE_BOOL;
1192 case GL_BOOL_VEC2: return TYPE_BOOL_VEC2;
1193 case GL_BOOL_VEC3: return TYPE_BOOL_VEC3;
1194 case GL_BOOL_VEC4: return TYPE_BOOL_VEC4;
1195
1196 case GL_SAMPLER_1D: return TYPE_SAMPLER_1D;
1197 case GL_SAMPLER_2D: return TYPE_SAMPLER_2D;
1198 case GL_SAMPLER_CUBE: return TYPE_SAMPLER_CUBE;
1199 case GL_SAMPLER_1D_ARRAY: return TYPE_SAMPLER_1D_ARRAY;
1200 case GL_SAMPLER_2D_ARRAY: return TYPE_SAMPLER_2D_ARRAY;
1201 case GL_SAMPLER_3D: return TYPE_SAMPLER_3D;
1202 case GL_SAMPLER_CUBE_MAP_ARRAY: return TYPE_SAMPLER_CUBE_ARRAY;
1203
1204 case GL_SAMPLER_1D_SHADOW: return TYPE_SAMPLER_1D_SHADOW;
1205 case GL_SAMPLER_2D_SHADOW: return TYPE_SAMPLER_2D_SHADOW;
1206 case GL_SAMPLER_CUBE_SHADOW: return TYPE_SAMPLER_CUBE_SHADOW;
1207 case GL_SAMPLER_1D_ARRAY_SHADOW: return TYPE_SAMPLER_1D_ARRAY_SHADOW;
1208 case GL_SAMPLER_2D_ARRAY_SHADOW: return TYPE_SAMPLER_2D_ARRAY_SHADOW;
1209 case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW: return TYPE_SAMPLER_CUBE_ARRAY_SHADOW;
1210
1211 case GL_INT_SAMPLER_1D: return TYPE_INT_SAMPLER_1D;
1212 case GL_INT_SAMPLER_2D: return TYPE_INT_SAMPLER_2D;
1213 case GL_INT_SAMPLER_CUBE: return TYPE_INT_SAMPLER_CUBE;
1214 case GL_INT_SAMPLER_1D_ARRAY: return TYPE_INT_SAMPLER_1D_ARRAY;
1215 case GL_INT_SAMPLER_2D_ARRAY: return TYPE_INT_SAMPLER_2D_ARRAY;
1216 case GL_INT_SAMPLER_3D: return TYPE_INT_SAMPLER_3D;
1217 case GL_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_INT_SAMPLER_CUBE_ARRAY;
1218
1219 case GL_UNSIGNED_INT_SAMPLER_1D: return TYPE_UINT_SAMPLER_1D;
1220 case GL_UNSIGNED_INT_SAMPLER_2D: return TYPE_UINT_SAMPLER_2D;
1221 case GL_UNSIGNED_INT_SAMPLER_CUBE: return TYPE_UINT_SAMPLER_CUBE;
1222 case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: return TYPE_UINT_SAMPLER_1D_ARRAY;
1223 case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: return TYPE_UINT_SAMPLER_2D_ARRAY;
1224 case GL_UNSIGNED_INT_SAMPLER_3D: return TYPE_UINT_SAMPLER_3D;
1225 case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: return TYPE_UINT_SAMPLER_CUBE_ARRAY;
1226
1227 case GL_SAMPLER_2D_MULTISAMPLE: return TYPE_SAMPLER_2D_MULTISAMPLE;
1228 case GL_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_INT_SAMPLER_2D_MULTISAMPLE;
1229 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE;
1230
1231 case GL_IMAGE_2D: return TYPE_IMAGE_2D;
1232 case GL_IMAGE_CUBE: return TYPE_IMAGE_CUBE;
1233 case GL_IMAGE_2D_ARRAY: return TYPE_IMAGE_2D_ARRAY;
1234 case GL_IMAGE_3D: return TYPE_IMAGE_3D;
1235 case GL_INT_IMAGE_2D: return TYPE_INT_IMAGE_2D;
1236 case GL_INT_IMAGE_CUBE: return TYPE_INT_IMAGE_CUBE;
1237 case GL_INT_IMAGE_2D_ARRAY: return TYPE_INT_IMAGE_2D_ARRAY;
1238 case GL_INT_IMAGE_3D: return TYPE_INT_IMAGE_3D;
1239 case GL_UNSIGNED_INT_IMAGE_2D: return TYPE_UINT_IMAGE_2D;
1240 case GL_UNSIGNED_INT_IMAGE_CUBE: return TYPE_UINT_IMAGE_CUBE;
1241 case GL_UNSIGNED_INT_IMAGE_2D_ARRAY: return TYPE_UINT_IMAGE_2D_ARRAY;
1242 case GL_UNSIGNED_INT_IMAGE_3D: return TYPE_UINT_IMAGE_3D;
1243
1244 case GL_UNSIGNED_INT_ATOMIC_COUNTER: return TYPE_UINT_ATOMIC_COUNTER;
1245
1246 case GL_SAMPLER_BUFFER: return TYPE_SAMPLER_BUFFER;
1247 case GL_INT_SAMPLER_BUFFER: return TYPE_INT_SAMPLER_BUFFER;
1248 case GL_UNSIGNED_INT_SAMPLER_BUFFER: return TYPE_UINT_SAMPLER_BUFFER;
1249
1250 case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_SAMPLER_2D_MULTISAMPLE_ARRAY;
1251 case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_INT_SAMPLER_2D_MULTISAMPLE_ARRAY;
1252 case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: return TYPE_UINT_SAMPLER_2D_MULTISAMPLE_ARRAY;
1253
1254 case GL_IMAGE_BUFFER: return TYPE_IMAGE_BUFFER;
1255 case GL_INT_IMAGE_BUFFER: return TYPE_INT_IMAGE_BUFFER;
1256 case GL_UNSIGNED_INT_IMAGE_BUFFER: return TYPE_UINT_IMAGE_BUFFER;
1257
1258 default:
1259 return TYPE_LAST;
1260 }
1261 }
1262
1263 } // glu
1264