b3ad06b65c24e8dfd1decba5bfcb475a3c82938a
[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 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 GLboolean *error);
78
79
80 extern GLboolean
81 _slang_is_swizzle(const char *field, GLuint rows, slang_swizzle *swz);
82
83 extern GLboolean
84 _slang_is_swizzle_mask(const slang_swizzle *swz, GLuint rows);
85
86 extern GLvoid
87 _slang_multiply_swizzles(slang_swizzle *, const slang_swizzle *,
88 const slang_swizzle *);
89
90
91 /**
92 * The basic shading language types (float, vec4, mat3, etc)
93 */
94 typedef enum slang_type_specifier_type_
95 {
96 SLANG_SPEC_VOID,
97 SLANG_SPEC_BOOL,
98 SLANG_SPEC_BVEC2,
99 SLANG_SPEC_BVEC3,
100 SLANG_SPEC_BVEC4,
101 SLANG_SPEC_INT,
102 SLANG_SPEC_IVEC2,
103 SLANG_SPEC_IVEC3,
104 SLANG_SPEC_IVEC4,
105 SLANG_SPEC_FLOAT,
106 SLANG_SPEC_VEC2,
107 SLANG_SPEC_VEC3,
108 SLANG_SPEC_VEC4,
109 SLANG_SPEC_MAT2,
110 SLANG_SPEC_MAT3,
111 SLANG_SPEC_MAT4,
112 SLANG_SPEC_MAT23,
113 SLANG_SPEC_MAT32,
114 SLANG_SPEC_MAT24,
115 SLANG_SPEC_MAT42,
116 SLANG_SPEC_MAT34,
117 SLANG_SPEC_MAT43,
118 SLANG_SPEC_SAMPLER1D,
119 SLANG_SPEC_SAMPLER2D,
120 SLANG_SPEC_SAMPLER3D,
121 SLANG_SPEC_SAMPLERCUBE,
122 SLANG_SPEC_SAMPLER2DRECT,
123 SLANG_SPEC_SAMPLER1DSHADOW,
124 SLANG_SPEC_SAMPLER2DSHADOW,
125 SLANG_SPEC_SAMPLER2DRECTSHADOW,
126 SLANG_SPEC_STRUCT,
127 SLANG_SPEC_ARRAY
128 } slang_type_specifier_type;
129
130
131 /**
132 * Describes more sophisticated types, like structs and arrays.
133 */
134 typedef struct slang_type_specifier_
135 {
136 slang_type_specifier_type type;
137 struct slang_struct_ *_struct; /**< used if type == spec_struct */
138 struct slang_type_specifier_ *_array; /**< used if type == spec_array */
139 } slang_type_specifier;
140
141
142 extern GLvoid
143 slang_type_specifier_ctr(slang_type_specifier *);
144
145 extern GLvoid
146 slang_type_specifier_dtr(slang_type_specifier *);
147
148 extern GLboolean
149 slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
150
151 extern GLboolean
152 slang_type_specifier_equal(const slang_type_specifier *,
153 const slang_type_specifier *);
154
155
156 typedef struct slang_typeinfo_
157 {
158 GLboolean can_be_referenced;
159 GLboolean is_swizzled;
160 slang_swizzle swz;
161 slang_type_specifier spec;
162 GLuint array_len;
163 } slang_typeinfo;
164
165 extern GLboolean
166 slang_typeinfo_construct(slang_typeinfo *);
167
168 extern GLvoid
169 slang_typeinfo_destruct(slang_typeinfo *);
170
171
172 /**
173 * Retrieves type information about an operation.
174 * Returns GL_TRUE on success.
175 * Returns GL_FALSE otherwise.
176 */
177 extern GLboolean
178 _slang_typeof_operation(const slang_assemble_ctx *,
179 struct slang_operation_ *,
180 slang_typeinfo *);
181
182 extern GLboolean
183 _slang_typeof_operation_(struct slang_operation_ *,
184 const slang_name_space *,
185 slang_typeinfo *, slang_atom_pool *,
186 slang_info_log *log);
187
188 extern GLboolean
189 _slang_type_is_matrix(slang_type_specifier_type);
190
191 extern GLboolean
192 _slang_type_is_vector(slang_type_specifier_type);
193
194 extern GLboolean
195 _slang_type_is_float_vec_mat(slang_type_specifier_type);
196
197 extern slang_type_specifier_type
198 _slang_type_base(slang_type_specifier_type);
199
200 extern GLuint
201 _slang_type_dim(slang_type_specifier_type);
202
203 extern GLenum
204 _slang_gltype_from_specifier(const slang_type_specifier *type);
205
206 #endif