171a899f64d851dae296bfb79f1cbe3bd2df6933
[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 "main/imports.h"
29 #include "main/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 struct slang_assemble_ctx_;
59
60
61 extern GLboolean
62 _slang_is_swizzle(const char *field, GLuint rows, slang_swizzle *swz);
63
64 extern GLboolean
65 _slang_is_swizzle_mask(const slang_swizzle *swz, GLuint rows);
66
67 extern GLvoid
68 _slang_multiply_swizzles(slang_swizzle *, const slang_swizzle *,
69 const slang_swizzle *);
70
71
72 typedef enum slang_type_variant_
73 {
74 SLANG_VARIANT, /* the default */
75 SLANG_INVARIANT /* indicates the "invariant" keyword */
76 } slang_type_variant;
77
78
79 typedef enum slang_type_centroid_
80 {
81 SLANG_CENTER, /* the default */
82 SLANG_CENTROID /* indicates the "centroid" keyword */
83 } slang_type_centroid;
84
85
86 typedef enum slang_type_qualifier_
87 {
88 SLANG_QUAL_NONE,
89 SLANG_QUAL_CONST,
90 SLANG_QUAL_ATTRIBUTE,
91 SLANG_QUAL_VARYING,
92 SLANG_QUAL_UNIFORM,
93 SLANG_QUAL_OUT,
94 SLANG_QUAL_INOUT,
95 SLANG_QUAL_FIXEDOUTPUT, /* internal */
96 SLANG_QUAL_FIXEDINPUT /* internal */
97 } slang_type_qualifier;
98
99
100 typedef enum slang_type_precision_
101 {
102 SLANG_PREC_DEFAULT,
103 SLANG_PREC_LOW,
104 SLANG_PREC_MEDIUM,
105 SLANG_PREC_HIGH
106 } slang_type_precision;
107
108
109 /**
110 * The basic shading language types (float, vec4, mat3, etc)
111 */
112 typedef enum slang_type_specifier_type_
113 {
114 SLANG_SPEC_VOID,
115 SLANG_SPEC_BOOL,
116 SLANG_SPEC_BVEC2,
117 SLANG_SPEC_BVEC3,
118 SLANG_SPEC_BVEC4,
119 SLANG_SPEC_INT,
120 SLANG_SPEC_IVEC2,
121 SLANG_SPEC_IVEC3,
122 SLANG_SPEC_IVEC4,
123 SLANG_SPEC_FLOAT,
124 SLANG_SPEC_VEC2,
125 SLANG_SPEC_VEC3,
126 SLANG_SPEC_VEC4,
127 SLANG_SPEC_MAT2,
128 SLANG_SPEC_MAT3,
129 SLANG_SPEC_MAT4,
130 SLANG_SPEC_MAT23,
131 SLANG_SPEC_MAT32,
132 SLANG_SPEC_MAT24,
133 SLANG_SPEC_MAT42,
134 SLANG_SPEC_MAT34,
135 SLANG_SPEC_MAT43,
136 SLANG_SPEC_SAMPLER1D,
137 SLANG_SPEC_SAMPLER2D,
138 SLANG_SPEC_SAMPLER3D,
139 SLANG_SPEC_SAMPLERCUBE,
140 SLANG_SPEC_SAMPLER2DRECT,
141 SLANG_SPEC_SAMPLER1DSHADOW,
142 SLANG_SPEC_SAMPLER2DSHADOW,
143 SLANG_SPEC_SAMPLER2DRECTSHADOW,
144 SLANG_SPEC_STRUCT,
145 SLANG_SPEC_ARRAY
146 } slang_type_specifier_type;
147
148
149 extern slang_type_specifier_type
150 slang_type_specifier_type_from_string(const char *);
151
152 extern const char *
153 slang_type_specifier_type_to_string(slang_type_specifier_type);
154
155
156 /**
157 * Describes more sophisticated types, like structs and arrays.
158 */
159 typedef struct slang_type_specifier_
160 {
161 slang_type_specifier_type type;
162 struct slang_struct_ *_struct; /**< if type == SLANG_SPEC_STRUCT */
163 struct slang_type_specifier_ *_array; /**< if type == SLANG_SPEC_ARRAY */
164 } slang_type_specifier;
165
166
167 extern GLvoid
168 slang_type_specifier_ctr(slang_type_specifier *);
169
170 extern GLvoid
171 slang_type_specifier_dtr(slang_type_specifier *);
172
173 extern slang_type_specifier *
174 slang_type_specifier_new(slang_type_specifier_type type,
175 struct slang_struct_ *_struct,
176 struct slang_type_specifier_ *_array);
177
178
179 extern GLboolean
180 slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
181
182 extern GLboolean
183 slang_type_specifier_equal(const slang_type_specifier *,
184 const slang_type_specifier *);
185
186
187 extern GLboolean
188 slang_type_specifier_compatible(const slang_type_specifier * x,
189 const slang_type_specifier * y);
190
191
192 typedef struct slang_fully_specified_type_
193 {
194 slang_type_qualifier qualifier;
195 slang_type_specifier specifier;
196 slang_type_precision precision;
197 slang_type_variant variant;
198 slang_type_centroid centroid;
199 GLint array_len; /**< -1 if not an array type */
200 } slang_fully_specified_type;
201
202 extern int
203 slang_fully_specified_type_construct(slang_fully_specified_type *);
204
205 extern void
206 slang_fully_specified_type_destruct(slang_fully_specified_type *);
207
208 extern int
209 slang_fully_specified_type_copy(slang_fully_specified_type *,
210 const slang_fully_specified_type *);
211
212
213
214 typedef struct slang_typeinfo_
215 {
216 GLboolean can_be_referenced;
217 GLboolean is_swizzled;
218 slang_swizzle swz;
219 slang_type_specifier spec;
220 GLuint array_len;
221 } slang_typeinfo;
222
223 extern GLboolean
224 slang_typeinfo_construct(slang_typeinfo *);
225
226 extern GLvoid
227 slang_typeinfo_destruct(slang_typeinfo *);
228
229
230 extern GLboolean
231 _slang_typeof_operation_(struct slang_operation_ *,
232 const slang_name_space *,
233 slang_typeinfo *, slang_atom_pool *,
234 slang_info_log *log);
235
236 extern GLboolean
237 _slang_type_is_matrix(slang_type_specifier_type);
238
239 extern GLboolean
240 _slang_type_is_vector(slang_type_specifier_type);
241
242 extern GLboolean
243 _slang_type_is_float_vec_mat(slang_type_specifier_type);
244
245 extern slang_type_specifier_type
246 _slang_type_base(slang_type_specifier_type);
247
248 extern GLuint
249 _slang_type_dim(slang_type_specifier_type);
250
251 extern GLenum
252 _slang_gltype_from_specifier(const slang_type_specifier *type);
253
254 #endif