587331e8b1e0dd55244e047006a32330c2ab85fc
[mesa.git] / src / mesa / shader / slang / slang_typeinfo.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 #ifndef SLANG_TYPEINFO_H
26 #define SLANG_TYPEINFO_H 1
27
28 #include "imports.h"
29 #include "mtypes.h"
30 #include "slang_log.h"
31 #include "slang_utility.h"
32 #include "slang_vartable.h"
33
34
35 struct slang_operation_;
36
37
38 /**
39 * Holds complete information about vector swizzle - the <swizzle>
40 * array contains vector component source indices, where 0 is "x", 1
41 * is "y", 2 is "z" and 3 is "w".
42 * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
43 */
44 typedef struct slang_swizzle_
45 {
46 GLuint num_components;
47 GLuint swizzle[4];
48 } slang_swizzle;
49
50 typedef struct slang_name_space_
51 {
52 struct slang_function_scope_ *funcs;
53 struct slang_struct_scope_ *structs;
54 struct slang_variable_scope_ *vars;
55 } slang_name_space;
56
57
58 typedef struct slang_assemble_ctx_
59 {
60 slang_atom_pool *atoms;
61 slang_name_space space;
62 struct gl_program *program;
63 slang_var_table *vartable;
64 slang_info_log *log;
65 struct slang_label_ *curFuncEndLabel;
66 struct slang_ir_node_ *CurLoop;
67 struct slang_function_ *CurFunction;
68 } slang_assemble_ctx;
69
70
71 extern struct slang_function_ *
72 _slang_locate_function(const struct slang_function_scope_ *funcs,
73 slang_atom name, struct slang_operation_ *params,
74 GLuint num_params,
75 const slang_name_space *space,
76 slang_atom_pool *atoms, slang_info_log *log);
77
78
79 extern GLboolean
80 _slang_is_swizzle(const char *field, GLuint rows, slang_swizzle *swz);
81
82 extern GLboolean
83 _slang_is_swizzle_mask(const slang_swizzle *swz, GLuint rows);
84
85 extern GLvoid
86 _slang_multiply_swizzles(slang_swizzle *, const slang_swizzle *,
87 const slang_swizzle *);
88
89
90 /**
91 * The basic shading language types (float, vec4, mat3, etc)
92 */
93 typedef enum slang_type_specifier_type_
94 {
95 SLANG_SPEC_VOID,
96 SLANG_SPEC_BOOL,
97 SLANG_SPEC_BVEC2,
98 SLANG_SPEC_BVEC3,
99 SLANG_SPEC_BVEC4,
100 SLANG_SPEC_INT,
101 SLANG_SPEC_IVEC2,
102 SLANG_SPEC_IVEC3,
103 SLANG_SPEC_IVEC4,
104 SLANG_SPEC_FLOAT,
105 SLANG_SPEC_VEC2,
106 SLANG_SPEC_VEC3,
107 SLANG_SPEC_VEC4,
108 SLANG_SPEC_MAT2,
109 SLANG_SPEC_MAT3,
110 SLANG_SPEC_MAT4,
111 SLANG_SPEC_MAT23,
112 SLANG_SPEC_MAT32,
113 SLANG_SPEC_MAT24,
114 SLANG_SPEC_MAT42,
115 SLANG_SPEC_MAT34,
116 SLANG_SPEC_MAT43,
117 SLANG_SPEC_SAMPLER1D,
118 SLANG_SPEC_SAMPLER2D,
119 SLANG_SPEC_SAMPLER3D,
120 SLANG_SPEC_SAMPLERCUBE,
121 SLANG_SPEC_SAMPLER2DRECT,
122 SLANG_SPEC_SAMPLER1DSHADOW,
123 SLANG_SPEC_SAMPLER2DSHADOW,
124 SLANG_SPEC_SAMPLER2DRECTSHADOW,
125 SLANG_SPEC_STRUCT,
126 SLANG_SPEC_ARRAY
127 } slang_type_specifier_type;
128
129
130 /**
131 * Describes more sophisticated types, like structs and arrays.
132 */
133 typedef struct slang_type_specifier_
134 {
135 slang_type_specifier_type type;
136 struct slang_struct_ *_struct; /**< used if type == spec_struct */
137 struct slang_type_specifier_ *_array; /**< used if type == spec_array */
138 } slang_type_specifier;
139
140
141 extern GLvoid
142 slang_type_specifier_ctr(slang_type_specifier *);
143
144 extern GLvoid
145 slang_type_specifier_dtr(slang_type_specifier *);
146
147 extern GLboolean
148 slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
149
150 extern GLboolean
151 slang_type_specifier_equal(const slang_type_specifier *,
152 const slang_type_specifier *);
153
154
155 typedef struct slang_typeinfo_
156 {
157 GLboolean can_be_referenced;
158 GLboolean is_swizzled;
159 slang_swizzle swz;
160 slang_type_specifier spec;
161 GLuint array_len;
162 } slang_typeinfo;
163
164 extern GLboolean
165 slang_typeinfo_construct(slang_typeinfo *);
166
167 extern GLvoid
168 slang_typeinfo_destruct(slang_typeinfo *);
169
170
171 /**
172 * Retrieves type information about an operation.
173 * Returns GL_TRUE on success.
174 * Returns GL_FALSE otherwise.
175 */
176 extern GLboolean
177 _slang_typeof_operation(const slang_assemble_ctx *,
178 struct slang_operation_ *,
179 slang_typeinfo *);
180
181 extern GLboolean
182 _slang_typeof_operation_(struct slang_operation_ *,
183 const slang_name_space *,
184 slang_typeinfo *, slang_atom_pool *,
185 slang_info_log *log);
186
187 extern GLboolean
188 _slang_type_is_matrix(slang_type_specifier_type);
189
190 extern GLboolean
191 _slang_type_is_vector(slang_type_specifier_type);
192
193 extern slang_type_specifier_type
194 _slang_type_base(slang_type_specifier_type);
195
196 extern GLuint
197 _slang_type_dim(slang_type_specifier_type);
198
199 extern GLenum
200 _slang_gltype_from_specifier(const slang_type_specifier *type);
201
202 #endif