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