2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * \file slang_assemble_typeinfo.c
31 #include "main/imports.h"
32 #include "shader/prog_instruction.h"
33 #include "slang_typeinfo.h"
34 #include "slang_compile.h"
35 #include "slang_log.h"
36 #include "slang_mem.h"
40 * Checks if a field selector is a general swizzle (an r-value swizzle
41 * with replicated components or an l-value swizzle mask) for a
42 * vector. Returns GL_TRUE if this is the case, <swz> is filled with
43 * swizzle information. Returns GL_FALSE otherwise.
46 _slang_is_swizzle(const char *field
, GLuint rows
, slang_swizzle
* swz
)
49 GLboolean xyzw
= GL_FALSE
, rgba
= GL_FALSE
, stpq
= GL_FALSE
;
52 * We rely on undefined/nil values to distinguish between
53 * regular swizzles and writemasks.
54 * For example, the swizzle ".xNNN" is the writemask ".x".
55 * That's different than the swizzle ".xxxx".
57 for (i
= 0; i
< 4; i
++)
58 swz
->swizzle
[i
] = SWIZZLE_NIL
;
60 /* the swizzle can be at most 4-component long */
61 swz
->num_components
= slang_string_length(field
);
62 if (swz
->num_components
> 4)
65 for (i
= 0; i
< swz
->num_components
; i
++) {
66 /* mark which swizzle group is used */
90 /* collect swizzle component */
114 /* check if the component is valid for given vector's row count */
115 if (rows
<= swz
->swizzle
[i
])
119 /* only one swizzle group can be used */
120 if ((xyzw
&& rgba
) || (xyzw
&& stpq
) || (rgba
&& stpq
))
129 * Checks if a general swizzle is an l-value swizzle - these swizzles
130 * do not have duplicated fields. Returns GL_TRUE if this is a
131 * swizzle mask. Returns GL_FALSE otherwise
134 _slang_is_swizzle_mask(const slang_swizzle
* swz
, GLuint rows
)
138 /* the swizzle may not be longer than the vector dim */
139 if (swz
->num_components
> rows
)
142 /* the swizzle components cannot be duplicated */
143 for (i
= 0; i
< swz
->num_components
; i
++) {
144 if ((c
& (1 << swz
->swizzle
[i
])) != 0)
146 c
|= 1 << swz
->swizzle
[i
];
154 * Combines (multiplies) two swizzles to form single swizzle.
155 * Example: "vec.wzyx.yx" --> "vec.zw".
158 _slang_multiply_swizzles(slang_swizzle
* dst
, const slang_swizzle
* left
,
159 const slang_swizzle
* right
)
163 dst
->num_components
= right
->num_components
;
164 for (i
= 0; i
< right
->num_components
; i
++)
165 dst
->swizzle
[i
] = left
->swizzle
[right
->swizzle
[i
]];
170 slang_type_specifier_ctr(slang_type_specifier
* self
)
172 self
->type
= SLANG_SPEC_VOID
;
173 self
->_struct
= NULL
;
178 slang_type_specifier_dtr(slang_type_specifier
* self
)
180 if (self
->_struct
!= NULL
) {
181 slang_struct_destruct(self
->_struct
);
182 _slang_free(self
->_struct
);
184 if (self
->_array
!= NULL
) {
185 slang_type_specifier_dtr(self
->_array
);
186 _slang_free(self
->_array
);
191 slang_type_specifier_copy(slang_type_specifier
* x
,
192 const slang_type_specifier
* y
)
194 slang_type_specifier z
;
196 slang_type_specifier_ctr(&z
);
198 if (z
.type
== SLANG_SPEC_STRUCT
) {
199 z
._struct
= (slang_struct
*) _slang_alloc(sizeof(slang_struct
));
200 if (z
._struct
== NULL
) {
201 slang_type_specifier_dtr(&z
);
204 if (!slang_struct_construct(z
._struct
)) {
205 _slang_free(z
._struct
);
206 slang_type_specifier_dtr(&z
);
209 if (!slang_struct_copy(z
._struct
, y
->_struct
)) {
210 slang_type_specifier_dtr(&z
);
214 else if (z
.type
== SLANG_SPEC_ARRAY
) {
215 z
._array
= (slang_type_specifier
*)
216 _slang_alloc(sizeof(slang_type_specifier
));
217 if (z
._array
== NULL
) {
218 slang_type_specifier_dtr(&z
);
221 slang_type_specifier_ctr(z
._array
);
222 if (!slang_type_specifier_copy(z
._array
, y
->_array
)) {
223 slang_type_specifier_dtr(&z
);
227 slang_type_specifier_dtr(x
);
234 * Test if two types are equal.
237 slang_type_specifier_equal(const slang_type_specifier
* x
,
238 const slang_type_specifier
* y
)
240 if (x
->type
!= y
->type
)
242 if (x
->type
== SLANG_SPEC_STRUCT
)
243 return slang_struct_equal(x
->_struct
, y
->_struct
);
244 if (x
->type
== SLANG_SPEC_ARRAY
)
245 return slang_type_specifier_equal(x
->_array
, y
->_array
);
251 * As above, but allow float/int casting.
254 slang_type_specifier_compatible(const slang_type_specifier
* x
,
255 const slang_type_specifier
* y
)
257 /* special case: float == int */
258 if (x
->type
== SLANG_SPEC_INT
&& y
->type
== SLANG_SPEC_FLOAT
) {
261 /* XXX may need to add bool/int compatibility, etc */
263 if (x
->type
!= y
->type
)
265 if (x
->type
== SLANG_SPEC_STRUCT
)
266 return slang_struct_equal(x
->_struct
, y
->_struct
);
267 if (x
->type
== SLANG_SPEC_ARRAY
)
268 return slang_type_specifier_compatible(x
->_array
, y
->_array
);
274 slang_typeinfo_construct(slang_typeinfo
* ti
)
276 slang_type_specifier_ctr(&ti
->spec
);
282 slang_typeinfo_destruct(slang_typeinfo
* ti
)
284 slang_type_specifier_dtr(&ti
->spec
);
290 * Determine the return type of a function.
291 * \param a_name the function name
292 * \param param function parameters (overloading)
293 * \param num_params number of parameters to function
294 * \param space namespace to search
295 * \param spec returns the type
296 * \param funFound returns pointer to the function, or NULL if not found.
297 * \return GL_TRUE for success, GL_FALSE if failure (bad function name)
300 _slang_typeof_function(slang_atom a_name
,
301 slang_operation
* params
, GLuint num_params
,
302 const slang_name_space
* space
,
303 slang_type_specifier
* spec
,
304 slang_function
**funFound
,
305 slang_atom_pool
*atoms
, slang_info_log
*log
)
307 *funFound
= _slang_locate_function(space
->funcs
, a_name
, params
,
308 num_params
, space
, atoms
, log
);
310 return GL_TRUE
; /* yes, not false */
311 return slang_type_specifier_copy(spec
, &(*funFound
)->header
.type
.specifier
);
316 * Determine the type of a math function.
317 * \param name name of the operator, one of +,-,*,/ or unary -
318 * \param params array of function parameters
319 * \param num_params number of parameters
320 * \param space namespace to use
321 * \param spec returns the function's type
322 * \param atoms atom pool
323 * \return GL_TRUE for success, GL_FALSE if failure
326 typeof_math_call(const char *name
, slang_operation
*call
,
327 const slang_name_space
* space
,
328 slang_type_specifier
* spec
,
329 slang_atom_pool
* atoms
,
333 /* we've previously resolved this function call */
334 slang_type_specifier_copy(spec
, &call
->fun
->header
.type
.specifier
);
341 /* number of params: */
342 assert(call
->num_children
== 1 || call
->num_children
== 2);
344 atom
= slang_atom_pool_atom(atoms
, name
);
345 if (!_slang_typeof_function(atom
, call
->children
, call
->num_children
,
346 space
, spec
, &fun
, atoms
, log
))
350 /* Save pointer to save time in future */
359 _slang_typeof_operation(const slang_assemble_ctx
* A
,
360 slang_operation
* op
,
363 return _slang_typeof_operation_(op
, &A
->space
, ti
, A
->atoms
, A
->log
);
368 * Determine the return type of an operation.
369 * \param op the operation node
370 * \param space the namespace to use
371 * \param ti the returned type
372 * \param atoms atom pool
373 * \return GL_TRUE for success, GL_FALSE if failure
376 _slang_typeof_operation_(slang_operation
* op
,
377 const slang_name_space
* space
,
379 slang_atom_pool
* atoms
,
382 ti
->can_be_referenced
= GL_FALSE
;
383 ti
->is_swizzled
= GL_FALSE
;
386 case SLANG_OPER_BLOCK_NO_NEW_SCOPE
:
387 case SLANG_OPER_BLOCK_NEW_SCOPE
:
388 case SLANG_OPER_VARIABLE_DECL
:
390 case SLANG_OPER_BREAK
:
391 case SLANG_OPER_CONTINUE
:
392 case SLANG_OPER_DISCARD
:
393 case SLANG_OPER_RETURN
:
395 case SLANG_OPER_WHILE
:
398 case SLANG_OPER_VOID
:
399 ti
->spec
.type
= SLANG_SPEC_VOID
;
401 case SLANG_OPER_EXPRESSION
:
402 case SLANG_OPER_ASSIGN
:
403 case SLANG_OPER_ADDASSIGN
:
404 case SLANG_OPER_SUBASSIGN
:
405 case SLANG_OPER_MULASSIGN
:
406 case SLANG_OPER_DIVASSIGN
:
407 case SLANG_OPER_PREINCREMENT
:
408 case SLANG_OPER_PREDECREMENT
:
409 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
412 case SLANG_OPER_LITERAL_BOOL
:
413 if (op
->literal_size
== 1)
414 ti
->spec
.type
= SLANG_SPEC_BOOL
;
415 else if (op
->literal_size
== 2)
416 ti
->spec
.type
= SLANG_SPEC_BVEC2
;
417 else if (op
->literal_size
== 3)
418 ti
->spec
.type
= SLANG_SPEC_BVEC3
;
419 else if (op
->literal_size
== 4)
420 ti
->spec
.type
= SLANG_SPEC_BVEC4
;
423 "Unexpected bool literal_size %d in _slang_typeof_operation()",
425 ti
->spec
.type
= SLANG_SPEC_BOOL
;
428 case SLANG_OPER_LOGICALOR
:
429 case SLANG_OPER_LOGICALXOR
:
430 case SLANG_OPER_LOGICALAND
:
431 case SLANG_OPER_EQUAL
:
432 case SLANG_OPER_NOTEQUAL
:
433 case SLANG_OPER_LESS
:
434 case SLANG_OPER_GREATER
:
435 case SLANG_OPER_LESSEQUAL
:
436 case SLANG_OPER_GREATEREQUAL
:
438 ti
->spec
.type
= SLANG_SPEC_BOOL
;
440 case SLANG_OPER_LITERAL_INT
:
441 if (op
->literal_size
== 1)
442 ti
->spec
.type
= SLANG_SPEC_INT
;
443 else if (op
->literal_size
== 2)
444 ti
->spec
.type
= SLANG_SPEC_IVEC2
;
445 else if (op
->literal_size
== 3)
446 ti
->spec
.type
= SLANG_SPEC_IVEC3
;
447 else if (op
->literal_size
== 4)
448 ti
->spec
.type
= SLANG_SPEC_IVEC4
;
451 "Unexpected int literal_size %d in _slang_typeof_operation()",
453 ti
->spec
.type
= SLANG_SPEC_INT
;
456 case SLANG_OPER_LITERAL_FLOAT
:
457 if (op
->literal_size
== 1)
458 ti
->spec
.type
= SLANG_SPEC_FLOAT
;
459 else if (op
->literal_size
== 2)
460 ti
->spec
.type
= SLANG_SPEC_VEC2
;
461 else if (op
->literal_size
== 3)
462 ti
->spec
.type
= SLANG_SPEC_VEC3
;
463 else if (op
->literal_size
== 4)
464 ti
->spec
.type
= SLANG_SPEC_VEC4
;
467 "Unexpected float literal_size %d in _slang_typeof_operation()",
469 ti
->spec
.type
= SLANG_SPEC_FLOAT
;
472 case SLANG_OPER_IDENTIFIER
:
475 var
= _slang_locate_variable(op
->locals
, op
->a_id
, GL_TRUE
);
477 slang_info_log_error(log
, "undefined variable '%s'",
481 if (!slang_type_specifier_copy(&ti
->spec
, &var
->type
.specifier
)) {
482 slang_info_log_memory(log
);
485 ti
->can_be_referenced
= GL_TRUE
;
486 ti
->array_len
= var
->array_len
;
489 case SLANG_OPER_SEQUENCE
:
490 /* TODO: check [0] and [1] if they match */
491 if (!_slang_typeof_operation_(&op
->children
[1], space
, ti
, atoms
, log
)) {
494 ti
->can_be_referenced
= GL_FALSE
;
495 ti
->is_swizzled
= GL_FALSE
;
497 /*case SLANG_OPER_MODASSIGN: */
498 /*case SLANG_OPER_LSHASSIGN: */
499 /*case SLANG_OPER_RSHASSIGN: */
500 /*case SLANG_OPER_ORASSIGN: */
501 /*case SLANG_OPER_XORASSIGN: */
502 /*case SLANG_OPER_ANDASSIGN: */
503 case SLANG_OPER_SELECT
:
504 /* TODO: check [1] and [2] if they match */
505 if (!_slang_typeof_operation_(&op
->children
[1], space
, ti
, atoms
, log
)) {
508 ti
->can_be_referenced
= GL_FALSE
;
509 ti
->is_swizzled
= GL_FALSE
;
511 /*case SLANG_OPER_BITOR: */
512 /*case SLANG_OPER_BITXOR: */
513 /*case SLANG_OPER_BITAND: */
514 /*case SLANG_OPER_LSHIFT: */
515 /*case SLANG_OPER_RSHIFT: */
517 assert(op
->num_children
== 2);
518 if (!typeof_math_call("+", op
, space
, &ti
->spec
, atoms
, log
))
521 case SLANG_OPER_SUBTRACT
:
522 assert(op
->num_children
== 2);
523 if (!typeof_math_call("-", op
, space
, &ti
->spec
, atoms
, log
))
526 case SLANG_OPER_MULTIPLY
:
527 assert(op
->num_children
== 2);
528 if (!typeof_math_call("*", op
, space
, &ti
->spec
, atoms
, log
))
531 case SLANG_OPER_DIVIDE
:
532 assert(op
->num_children
== 2);
533 if (!typeof_math_call("/", op
, space
, &ti
->spec
, atoms
, log
))
536 /*case SLANG_OPER_MODULUS: */
537 case SLANG_OPER_PLUS
:
538 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
540 ti
->can_be_referenced
= GL_FALSE
;
541 ti
->is_swizzled
= GL_FALSE
;
543 case SLANG_OPER_MINUS
:
544 assert(op
->num_children
== 1);
545 if (!typeof_math_call("-", op
, space
, &ti
->spec
, atoms
, log
))
548 /*case SLANG_OPER_COMPLEMENT: */
549 case SLANG_OPER_SUBSCRIPT
:
553 if (!slang_typeinfo_construct(&_ti
))
555 if (!_slang_typeof_operation_(op
->children
, space
, &_ti
, atoms
, log
)) {
556 slang_typeinfo_destruct(&_ti
);
559 ti
->can_be_referenced
= _ti
.can_be_referenced
;
560 if (_ti
.spec
.type
== SLANG_SPEC_ARRAY
) {
561 if (!slang_type_specifier_copy(&ti
->spec
, _ti
.spec
._array
)) {
562 slang_typeinfo_destruct(&_ti
);
567 if (!_slang_type_is_vector(_ti
.spec
.type
)
568 && !_slang_type_is_matrix(_ti
.spec
.type
)) {
569 slang_typeinfo_destruct(&_ti
);
570 slang_info_log_error(log
, "cannot index a non-array type");
573 ti
->spec
.type
= _slang_type_base(_ti
.spec
.type
);
575 slang_typeinfo_destruct(&_ti
);
578 case SLANG_OPER_CALL
:
580 /* we've resolved this call before */
581 slang_type_specifier_copy(&ti
->spec
, &op
->fun
->header
.type
.specifier
);
585 if (!_slang_typeof_function(op
->a_id
, op
->children
, op
->num_children
,
586 space
, &ti
->spec
, &fun
, atoms
, log
))
589 /* save result for future use */
594 slang_struct_scope_find(space
->structs
, op
->a_id
, GL_TRUE
);
596 /* struct initializer */
597 ti
->spec
.type
= SLANG_SPEC_STRUCT
;
599 (slang_struct
*) _slang_alloc(sizeof(slang_struct
));
600 if (ti
->spec
._struct
== NULL
)
602 if (!slang_struct_construct(ti
->spec
._struct
)) {
603 _slang_free(ti
->spec
._struct
);
604 ti
->spec
._struct
= NULL
;
607 if (!slang_struct_copy(ti
->spec
._struct
, s
))
611 /* float, int, vec4, mat3, etc. constructor? */
613 slang_type_specifier_type type
;
615 name
= slang_atom_pool_id(atoms
, op
->a_id
);
616 type
= slang_type_specifier_type_from_string(name
);
617 if (type
== SLANG_SPEC_VOID
) {
618 slang_info_log_error(log
, "undefined function '%s'", name
);
621 ti
->spec
.type
= type
;
626 case SLANG_OPER_FIELD
:
630 if (!slang_typeinfo_construct(&_ti
))
632 if (!_slang_typeof_operation_(op
->children
, space
, &_ti
, atoms
, log
)) {
633 slang_typeinfo_destruct(&_ti
);
636 if (_ti
.spec
.type
== SLANG_SPEC_STRUCT
) {
637 slang_variable
*field
;
639 field
= _slang_locate_variable(_ti
.spec
._struct
->fields
, op
->a_id
,
642 slang_typeinfo_destruct(&_ti
);
645 if (!slang_type_specifier_copy(&ti
->spec
, &field
->type
.specifier
)) {
646 slang_typeinfo_destruct(&_ti
);
649 ti
->can_be_referenced
= _ti
.can_be_referenced
;
654 slang_type_specifier_type base
;
656 /* determine the swizzle of the field expression */
657 if (!_slang_type_is_vector(_ti
.spec
.type
)) {
658 slang_typeinfo_destruct(&_ti
);
659 slang_info_log_error(log
, "Can't swizzle scalar expression");
662 rows
= _slang_type_dim(_ti
.spec
.type
);
663 swizzle
= slang_atom_pool_id(atoms
, op
->a_id
);
664 if (!_slang_is_swizzle(swizzle
, rows
, &ti
->swz
)) {
665 slang_typeinfo_destruct(&_ti
);
666 slang_info_log_error(log
, "bad swizzle '%s'", swizzle
);
669 ti
->is_swizzled
= GL_TRUE
;
670 ti
->can_be_referenced
= _ti
.can_be_referenced
671 && _slang_is_swizzle_mask(&ti
->swz
, rows
);
672 if (_ti
.is_swizzled
) {
675 /* swizzle the swizzle */
676 _slang_multiply_swizzles(&swz
, &_ti
.swz
, &ti
->swz
);
679 base
= _slang_type_base(_ti
.spec
.type
);
680 switch (ti
->swz
.num_components
) {
682 ti
->spec
.type
= base
;
686 case SLANG_SPEC_FLOAT
:
687 ti
->spec
.type
= SLANG_SPEC_VEC2
;
690 ti
->spec
.type
= SLANG_SPEC_IVEC2
;
692 case SLANG_SPEC_BOOL
:
693 ti
->spec
.type
= SLANG_SPEC_BVEC2
;
701 case SLANG_SPEC_FLOAT
:
702 ti
->spec
.type
= SLANG_SPEC_VEC3
;
705 ti
->spec
.type
= SLANG_SPEC_IVEC3
;
707 case SLANG_SPEC_BOOL
:
708 ti
->spec
.type
= SLANG_SPEC_BVEC3
;
716 case SLANG_SPEC_FLOAT
:
717 ti
->spec
.type
= SLANG_SPEC_VEC4
;
720 ti
->spec
.type
= SLANG_SPEC_IVEC4
;
722 case SLANG_SPEC_BOOL
:
723 ti
->spec
.type
= SLANG_SPEC_BVEC4
;
733 slang_typeinfo_destruct(&_ti
);
736 case SLANG_OPER_POSTINCREMENT
:
737 case SLANG_OPER_POSTDECREMENT
:
738 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
740 ti
->can_be_referenced
= GL_FALSE
;
741 ti
->is_swizzled
= GL_FALSE
;
752 * Lookup a function according to name and parameter count/types.
755 _slang_locate_function(const slang_function_scope
* funcs
, slang_atom a_name
,
756 slang_operation
* args
, GLuint num_args
,
757 const slang_name_space
* space
, slang_atom_pool
* atoms
,
762 for (i
= 0; i
< funcs
->num_functions
; i
++) {
763 slang_function
*f
= &funcs
->functions
[i
];
764 const GLuint haveRetValue
= _slang_function_has_return_value(f
);
767 if (a_name
!= f
->header
.a_name
)
769 if (f
->param_count
- haveRetValue
!= num_args
)
772 /* compare parameter / argument types */
773 for (j
= 0; j
< num_args
; j
++) {
776 if (!slang_typeinfo_construct(&ti
))
778 if (!_slang_typeof_operation_(&args
[j
], space
, &ti
, atoms
, log
)) {
779 slang_typeinfo_destruct(&ti
);
782 if (!slang_type_specifier_compatible(&ti
.spec
,
783 &f
->parameters
->variables
[j
]->type
.specifier
)) {
784 slang_typeinfo_destruct(&ti
);
787 slang_typeinfo_destruct(&ti
);
789 /* "out" and "inout" formal parameter requires the actual
790 * parameter to be l-value.
792 if (!ti
.can_be_referenced
&&
793 (f
->parameters
->variables
[j
]->type
.qualifier
== SLANG_QUAL_OUT
||
794 f
->parameters
->variables
[j
]->type
.qualifier
== SLANG_QUAL_INOUT
))
800 if (funcs
->outer_scope
!= NULL
)
801 return _slang_locate_function(funcs
->outer_scope
, a_name
, args
,
802 num_args
, space
, atoms
, log
);
808 * Determine if a type is a matrix.
809 * \return GL_TRUE if is a matrix, GL_FALSE otherwise.
812 _slang_type_is_matrix(slang_type_specifier_type ty
)
815 case SLANG_SPEC_MAT2
:
816 case SLANG_SPEC_MAT3
:
817 case SLANG_SPEC_MAT4
:
818 case SLANG_SPEC_MAT23
:
819 case SLANG_SPEC_MAT32
:
820 case SLANG_SPEC_MAT24
:
821 case SLANG_SPEC_MAT42
:
822 case SLANG_SPEC_MAT34
:
823 case SLANG_SPEC_MAT43
:
832 * Determine if a type is a vector.
833 * \return GL_TRUE if is a vector, GL_FALSE otherwise.
836 _slang_type_is_vector(slang_type_specifier_type ty
)
839 case SLANG_SPEC_VEC2
:
840 case SLANG_SPEC_VEC3
:
841 case SLANG_SPEC_VEC4
:
842 case SLANG_SPEC_IVEC2
:
843 case SLANG_SPEC_IVEC3
:
844 case SLANG_SPEC_IVEC4
:
845 case SLANG_SPEC_BVEC2
:
846 case SLANG_SPEC_BVEC3
:
847 case SLANG_SPEC_BVEC4
:
856 * Given a vector type, return the type of the vector's elements.
857 * For a matrix, return the type of the columns.
859 slang_type_specifier_type
860 _slang_type_base(slang_type_specifier_type ty
)
863 case SLANG_SPEC_FLOAT
:
864 case SLANG_SPEC_VEC2
:
865 case SLANG_SPEC_VEC3
:
866 case SLANG_SPEC_VEC4
:
867 return SLANG_SPEC_FLOAT
;
869 case SLANG_SPEC_IVEC2
:
870 case SLANG_SPEC_IVEC3
:
871 case SLANG_SPEC_IVEC4
:
872 return SLANG_SPEC_INT
;
873 case SLANG_SPEC_BOOL
:
874 case SLANG_SPEC_BVEC2
:
875 case SLANG_SPEC_BVEC3
:
876 case SLANG_SPEC_BVEC4
:
877 return SLANG_SPEC_BOOL
;
878 case SLANG_SPEC_MAT2
:
879 return SLANG_SPEC_VEC2
;
880 case SLANG_SPEC_MAT3
:
881 return SLANG_SPEC_VEC3
;
882 case SLANG_SPEC_MAT4
:
883 return SLANG_SPEC_VEC4
;
884 case SLANG_SPEC_MAT23
:
885 return SLANG_SPEC_VEC3
;
886 case SLANG_SPEC_MAT32
:
887 return SLANG_SPEC_VEC2
;
888 case SLANG_SPEC_MAT24
:
889 return SLANG_SPEC_VEC4
;
890 case SLANG_SPEC_MAT42
:
891 return SLANG_SPEC_VEC2
;
892 case SLANG_SPEC_MAT34
:
893 return SLANG_SPEC_VEC4
;
894 case SLANG_SPEC_MAT43
:
895 return SLANG_SPEC_VEC3
;
897 return SLANG_SPEC_VOID
;
903 * Return the dimensionality of a vector, or for a matrix, return number
907 _slang_type_dim(slang_type_specifier_type ty
)
910 case SLANG_SPEC_FLOAT
:
912 case SLANG_SPEC_BOOL
:
914 case SLANG_SPEC_VEC2
:
915 case SLANG_SPEC_IVEC2
:
916 case SLANG_SPEC_BVEC2
:
917 case SLANG_SPEC_MAT2
:
919 case SLANG_SPEC_VEC3
:
920 case SLANG_SPEC_IVEC3
:
921 case SLANG_SPEC_BVEC3
:
922 case SLANG_SPEC_MAT3
:
924 case SLANG_SPEC_VEC4
:
925 case SLANG_SPEC_IVEC4
:
926 case SLANG_SPEC_BVEC4
:
927 case SLANG_SPEC_MAT4
:
930 case SLANG_SPEC_MAT23
:
932 case SLANG_SPEC_MAT32
:
934 case SLANG_SPEC_MAT24
:
936 case SLANG_SPEC_MAT42
:
938 case SLANG_SPEC_MAT34
:
940 case SLANG_SPEC_MAT43
:
950 * Return the GL_* type that corresponds to a SLANG_SPEC_* type.
953 _slang_gltype_from_specifier(const slang_type_specifier
*type
)
955 switch (type
->type
) {
956 case SLANG_SPEC_BOOL
:
958 case SLANG_SPEC_BVEC2
:
960 case SLANG_SPEC_BVEC3
:
962 case SLANG_SPEC_BVEC4
:
966 case SLANG_SPEC_IVEC2
:
968 case SLANG_SPEC_IVEC3
:
970 case SLANG_SPEC_IVEC4
:
972 case SLANG_SPEC_FLOAT
:
974 case SLANG_SPEC_VEC2
:
975 return GL_FLOAT_VEC2
;
976 case SLANG_SPEC_VEC3
:
977 return GL_FLOAT_VEC3
;
978 case SLANG_SPEC_VEC4
:
979 return GL_FLOAT_VEC4
;
980 case SLANG_SPEC_MAT2
:
981 return GL_FLOAT_MAT2
;
982 case SLANG_SPEC_MAT3
:
983 return GL_FLOAT_MAT3
;
984 case SLANG_SPEC_MAT4
:
985 return GL_FLOAT_MAT4
;
986 case SLANG_SPEC_MAT23
:
987 return GL_FLOAT_MAT2x3
;
988 case SLANG_SPEC_MAT32
:
989 return GL_FLOAT_MAT3x2
;
990 case SLANG_SPEC_MAT24
:
991 return GL_FLOAT_MAT2x4
;
992 case SLANG_SPEC_MAT42
:
993 return GL_FLOAT_MAT4x2
;
994 case SLANG_SPEC_MAT34
:
995 return GL_FLOAT_MAT3x4
;
996 case SLANG_SPEC_MAT43
:
997 return GL_FLOAT_MAT4x3
;
998 case SLANG_SPEC_SAMPLER1D
:
999 return GL_SAMPLER_1D
;
1000 case SLANG_SPEC_SAMPLER2D
:
1001 return GL_SAMPLER_2D
;
1002 case SLANG_SPEC_SAMPLER3D
:
1003 return GL_SAMPLER_3D
;
1004 case SLANG_SPEC_SAMPLERCUBE
:
1005 return GL_SAMPLER_CUBE
;
1006 case SLANG_SPEC_SAMPLER1DSHADOW
:
1007 return GL_SAMPLER_1D_SHADOW
;
1008 case SLANG_SPEC_SAMPLER2DSHADOW
:
1009 return GL_SAMPLER_2D_SHADOW
;
1010 case SLANG_SPEC_SAMPLER2DRECT
:
1011 return GL_SAMPLER_2D_RECT_ARB
;
1012 case SLANG_SPEC_SAMPLER2DRECTSHADOW
:
1013 return GL_SAMPLER_2D_RECT_SHADOW_ARB
;
1014 case SLANG_SPEC_ARRAY
:
1015 return _slang_gltype_from_specifier(type
->_array
);
1016 case SLANG_SPEC_STRUCT
: