More GLSL code - more support for vec4 operations on x86 back-end.
[mesa.git] / src / mesa / shader / slang / slang_assemble.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 #if !defined SLANG_ASSEMBLE_H
26 #define SLANG_ASSEMBLE_H
27
28 #include "slang_utility.h"
29
30 #if defined __cplusplus
31 extern "C" {
32 #endif
33
34 struct slang_operation_;
35
36 typedef enum slang_assembly_type_
37 {
38 /* core */
39 slang_asm_none,
40 slang_asm_float_copy,
41 slang_asm_float_move,
42 slang_asm_float_push,
43 slang_asm_float_deref,
44 slang_asm_float_add,
45 slang_asm_float_multiply,
46 slang_asm_float_divide,
47 slang_asm_float_negate,
48 slang_asm_float_less,
49 slang_asm_float_equal_exp,
50 slang_asm_float_equal_int,
51 slang_asm_float_to_int,
52 slang_asm_float_sine,
53 slang_asm_float_arcsine,
54 slang_asm_float_arctan,
55 slang_asm_float_power,
56 slang_asm_float_log2,
57 slang_asm_float_floor,
58 slang_asm_float_ceil,
59 slang_asm_float_noise1,
60 slang_asm_float_noise2,
61 slang_asm_float_noise3,
62 slang_asm_float_noise4,
63 slang_asm_int_copy,
64 slang_asm_int_move,
65 slang_asm_int_push,
66 slang_asm_int_deref,
67 slang_asm_int_to_float,
68 slang_asm_int_to_addr,
69 slang_asm_bool_copy,
70 slang_asm_bool_move,
71 slang_asm_bool_push,
72 slang_asm_bool_deref,
73 slang_asm_addr_copy,
74 slang_asm_addr_push,
75 slang_asm_addr_deref,
76 slang_asm_addr_add,
77 slang_asm_addr_multiply,
78 slang_asm_vec4_tex1d,
79 slang_asm_vec4_tex2d,
80 slang_asm_vec4_tex3d,
81 slang_asm_vec4_texcube,
82 slang_asm_vec4_shad1d,
83 slang_asm_vec4_shad2d,
84 slang_asm_jump,
85 slang_asm_jump_if_zero,
86 slang_asm_enter,
87 slang_asm_leave,
88 slang_asm_local_alloc,
89 slang_asm_local_free,
90 slang_asm_local_addr,
91 slang_asm_global_addr,
92 slang_asm_call,
93 slang_asm_return,
94 slang_asm_discard,
95 slang_asm_exit,
96 /* GL_MESA_shader_debug */
97 slang_asm_float_print,
98 slang_asm_int_print,
99 slang_asm_bool_print,
100 /* vec4 */
101 slang_asm_float_to_vec4,
102 slang_asm_vec4_add,
103 slang_asm_vec4_subtract,
104 slang_asm_vec4_multiply,
105 slang_asm_vec4_divide,
106 slang_asm_vec4_negate,
107 slang_asm_vec4_dot,
108 slang_asm_vec4_copy,
109 slang_asm_vec4_deref,
110 slang_asm_vec4_equal_int,
111 /* not a real assembly instruction */
112 slang_asm__last
113 } slang_assembly_type;
114
115 typedef struct slang_assembly_
116 {
117 slang_assembly_type type;
118 GLfloat literal;
119 GLuint param[2];
120 } slang_assembly;
121
122 typedef struct slang_assembly_file_
123 {
124 slang_assembly *code;
125 GLuint count;
126 GLuint capacity;
127 } slang_assembly_file;
128
129 extern GLvoid
130 _slang_assembly_file_ctr (slang_assembly_file *);
131
132 GLvoid slang_assembly_file_destruct (slang_assembly_file *);
133 GLboolean slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
134 GLboolean slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
135 GLboolean slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
136 GLboolean slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
137
138 typedef struct slang_assembly_file_restore_point_
139 {
140 GLuint count;
141 } slang_assembly_file_restore_point;
142
143 GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *,
144 slang_assembly_file_restore_point *);
145 GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *,
146 slang_assembly_file_restore_point *);
147
148 typedef struct slang_assembly_flow_control_
149 {
150 GLuint loop_start; /* for "continue" statement */
151 GLuint loop_end; /* for "break" statement */
152 GLuint function_end; /* for "return" statement */
153 } slang_assembly_flow_control;
154
155 typedef struct slang_assembly_local_info_
156 {
157 GLuint ret_size;
158 GLuint addr_tmp;
159 GLuint swizzle_tmp;
160 } slang_assembly_local_info;
161
162 typedef enum
163 {
164 slang_ref_force,
165 slang_ref_forbid/*,
166 slang_ref_freelance*/
167 } slang_ref_type;
168
169 /*
170 * Holds a complete information about vector swizzle - the <swizzle> array contains
171 * vector component source indices, where 0 is "x", 1 is "y", 2 is "z" and 3 is "w".
172 * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
173 */
174 typedef struct slang_swizzle_
175 {
176 GLuint num_components;
177 GLuint swizzle[4];
178 } slang_swizzle;
179
180 typedef struct slang_assembly_name_space_
181 {
182 struct slang_function_scope_ *funcs;
183 struct slang_struct_scope_ *structs;
184 struct slang_variable_scope_ *vars;
185 } slang_assembly_name_space;
186
187 typedef struct slang_assemble_ctx_
188 {
189 slang_assembly_file *file;
190 struct slang_machine_ *mach;
191 slang_atom_pool *atoms;
192 slang_assembly_name_space space;
193 slang_assembly_flow_control flow;
194 slang_assembly_local_info local;
195 slang_ref_type ref;
196 slang_swizzle swz;
197 } slang_assemble_ctx;
198
199 struct slang_function_ *_slang_locate_function (struct slang_function_scope_ *funcs, slang_atom name,
200 struct slang_operation_ *params, GLuint num_params, slang_assembly_name_space *space,
201 slang_atom_pool *);
202
203 GLboolean _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
204
205 GLboolean _slang_cleanup_stack (slang_assemble_ctx *, struct slang_operation_ *);
206
207 GLboolean _slang_dereference (slang_assemble_ctx *, struct slang_operation_ *);
208
209 GLboolean _slang_assemble_function_call (slang_assemble_ctx *, struct slang_function_ *,
210 struct slang_operation_ *, GLuint, GLboolean);
211
212 GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *, const char *,
213 struct slang_operation_ *, GLuint, GLboolean);
214
215 GLboolean _slang_assemble_operation (slang_assemble_ctx *, struct slang_operation_ *,
216 slang_ref_type);
217
218 #ifdef __cplusplus
219 }
220 #endif
221
222 #include "slang_assemble_assignment.h"
223 #include "slang_assemble_typeinfo.h"
224 #include "slang_assemble_constructor.h"
225 #include "slang_assemble_conditional.h"
226
227 #endif
228