blob: c83bdd0a2c52d9eb737131d2f88c70b8c753f73e [file] [log] [blame]
Eric Anholtc22c4002010-03-26 18:20:30 -07001/*
2 * Copyright © 2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include <stdlib.h>
Eric Anholtd1e31952010-03-28 01:55:38 -070025#include <math.h>
Eric Anholtc22c4002010-03-26 18:20:30 -070026#include "glsl_symbol_table.h"
27#include "glsl_parser_extras.h"
28#include "glsl_types.h"
29#include "ir.h"
30
31static void
Eric Anholt2eec73f2010-03-27 12:25:20 -070032generate_unop(exec_list *instructions,
33 ir_variable **declarations,
34 const glsl_type *type,
35 enum ir_expression_operation op)
Eric Anholtc22c4002010-03-26 18:20:30 -070036{
Eric Anholtc22c4002010-03-26 18:20:30 -070037 ir_dereference *const arg = new ir_dereference(declarations[0]);
38 ir_rvalue *result;
39
Eric Anholt2eec73f2010-03-27 12:25:20 -070040 result = new ir_expression(op, type, arg, NULL);
Eric Anholtc22c4002010-03-26 18:20:30 -070041
Eric Anholt7e78e072010-04-07 13:34:15 -070042 ir_instruction *inst = new ir_return(result);
Eric Anholtc22c4002010-03-26 18:20:30 -070043 instructions->push_tail(inst);
44}
45
Eric Anholt2eec73f2010-03-27 12:25:20 -070046static void
Eric Anholtbfe380a2010-03-27 12:43:13 -070047generate_binop(exec_list *instructions,
48 ir_variable **declarations,
49 const glsl_type *type,
50 enum ir_expression_operation op)
51{
Eric Anholtbfe380a2010-03-27 12:43:13 -070052 ir_dereference *const arg1 = new ir_dereference(declarations[0]);
53 ir_dereference *const arg2 = new ir_dereference(declarations[1]);
54 ir_rvalue *result;
55
56 result = new ir_expression(op, type, arg1, arg2);
57
Eric Anholt7e78e072010-04-07 13:34:15 -070058 ir_instruction *inst = new ir_return(result);
Eric Anholtbfe380a2010-03-27 12:43:13 -070059 instructions->push_tail(inst);
60}
61
62static void
Eric Anholtd1e31952010-03-28 01:55:38 -070063generate_radians(exec_list *instructions,
64 ir_variable **declarations,
65 const glsl_type *type)
66{
Eric Anholtd1e31952010-03-28 01:55:38 -070067 ir_dereference *const arg = new ir_dereference(declarations[0]);
68 ir_rvalue *result;
69
70 result = new ir_expression(ir_binop_mul, type,
71 arg,
72 new ir_constant((float)(M_PI / 180.0)));
73
Eric Anholt7e78e072010-04-07 13:34:15 -070074 ir_instruction *inst = new ir_return(result);
Eric Anholtd1e31952010-03-28 01:55:38 -070075 instructions->push_tail(inst);
76}
77
78static void
79generate_degrees(exec_list *instructions,
80 ir_variable **declarations,
81 const glsl_type *type)
82{
Eric Anholtd1e31952010-03-28 01:55:38 -070083 ir_dereference *const arg = new ir_dereference(declarations[0]);
84 ir_rvalue *result;
85
86 result = new ir_expression(ir_binop_mul, type,
87 arg,
88 new ir_constant((float)(180.0 / M_PI)));
89
Eric Anholt7e78e072010-04-07 13:34:15 -070090 ir_instruction *inst = new ir_return(result);
Eric Anholtd1e31952010-03-28 01:55:38 -070091 instructions->push_tail(inst);
92}
93
94static void
Eric Anholt2eec73f2010-03-27 12:25:20 -070095generate_exp(exec_list *instructions,
96 ir_variable **declarations,
97 const glsl_type *type)
98{
99 generate_unop(instructions, declarations, type, ir_unop_exp);
100}
101
102static void
103generate_log(exec_list *instructions,
104 ir_variable **declarations,
105 const glsl_type *type)
106{
107 generate_unop(instructions, declarations, type, ir_unop_log);
108}
109
110static void
Eric Anholt01665262010-03-27 13:56:35 -0700111generate_exp2(exec_list *instructions,
112 ir_variable **declarations,
113 const glsl_type *type)
114{
115 generate_unop(instructions, declarations, type, ir_unop_exp2);
116}
117
118static void
119generate_log2(exec_list *instructions,
120 ir_variable **declarations,
121 const glsl_type *type)
122{
123 generate_unop(instructions, declarations, type, ir_unop_log2);
124}
125
126static void
Eric Anholt2eec73f2010-03-27 12:25:20 -0700127generate_rsq(exec_list *instructions,
128 ir_variable **declarations,
129 const glsl_type *type)
130{
131 generate_unop(instructions, declarations, type, ir_unop_rsq);
132}
133
134static void
Eric Anholt44d68fd2010-03-27 13:01:51 -0700135generate_sqrt(exec_list *instructions,
136 ir_variable **declarations,
137 const glsl_type *type)
138{
139 generate_unop(instructions, declarations, type, ir_unop_sqrt);
140}
141
142static void
Eric Anholt2eec73f2010-03-27 12:25:20 -0700143generate_abs(exec_list *instructions,
144 ir_variable **declarations,
145 const glsl_type *type)
146{
147 generate_unop(instructions, declarations, type, ir_unop_abs);
148}
149
150static void
151generate_ceil(exec_list *instructions,
152 ir_variable **declarations,
153 const glsl_type *type)
154{
155 generate_unop(instructions, declarations, type, ir_unop_ceil);
156}
157
158static void
159generate_floor(exec_list *instructions,
160 ir_variable **declarations,
161 const glsl_type *type)
162{
163 generate_unop(instructions, declarations, type, ir_unop_floor);
164}
165
Eric Anholtbfe380a2010-03-27 12:43:13 -0700166static void
167generate_mod(exec_list *instructions,
168 ir_variable **declarations,
169 const glsl_type *type)
170{
171 generate_binop(instructions, declarations, type, ir_binop_mod);
172}
173
174static void
175generate_min(exec_list *instructions,
176 ir_variable **declarations,
177 const glsl_type *type)
178{
179 generate_binop(instructions, declarations, type, ir_binop_min);
180}
181
182static void
183generate_max(exec_list *instructions,
184 ir_variable **declarations,
185 const glsl_type *type)
186{
187 generate_binop(instructions, declarations, type, ir_binop_max);
188}
189
Eric Anholtcc49cea2010-04-08 15:10:37 -0700190static void
191generate_mix_vec(exec_list *instructions,
192 ir_variable **declarations,
193 const glsl_type *type)
194{
195 ir_dereference *const x = new ir_dereference(declarations[0]);
196 ir_dereference *const y = new ir_dereference(declarations[1]);
197 ir_dereference *const a = new ir_dereference(declarations[2]);
198 ir_rvalue *result, *temp;
199
200 temp = new ir_expression(ir_binop_sub, type, new ir_constant(1.0f), a);
201 result = new ir_expression(ir_binop_mul, type, x, temp);
202
203 temp = new ir_expression(ir_binop_mul, type, y, a);
204 result = new ir_expression(ir_binop_add, type, result, temp);
205
206 ir_instruction *inst = new ir_return(result);
207 instructions->push_tail(inst);
208}
209
Eric Anholtddd2e832010-03-27 12:59:42 -0700210
211static void
Eric Anholt92575922010-04-08 14:34:38 -0700212generate_normalize(exec_list *instructions,
213 ir_variable **declarations,
214 const glsl_type *type)
215{
216 ir_dereference *const arg = new ir_dereference(declarations[0]);
217 ir_rvalue *temp;
218 ir_rvalue *result;
219
220 temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
221 temp = new ir_expression(ir_unop_rsq, glsl_type::float_type, temp, NULL);
222 result = new ir_expression(ir_binop_mul, type, arg, temp);
223
224 ir_instruction *inst = new ir_return(result);
225 instructions->push_tail(inst);
226}
227
228
229static void
Eric Anholtddd2e832010-03-27 12:59:42 -0700230generate_pow(exec_list *instructions,
231 ir_variable **declarations,
232 const glsl_type *type)
233{
234 generate_binop(instructions, declarations, type, ir_binop_pow);
235}
236
Eric Anholtc22c4002010-03-26 18:20:30 -0700237void
238generate_function_instance(ir_function *f,
239 const char *name,
240 exec_list *instructions,
Eric Anholtbfe380a2010-03-27 12:43:13 -0700241 int n_args,
Eric Anholtc22c4002010-03-26 18:20:30 -0700242 void (*generate)(exec_list *instructions,
243 ir_variable **declarations,
244 const glsl_type *type),
Eric Anholt53afc362010-03-27 13:55:04 -0700245 const glsl_type *ret_type,
Eric Anholtc22c4002010-03-26 18:20:30 -0700246 const glsl_type *type)
247{
Eric Anholt7e78e072010-04-07 13:34:15 -0700248 ir_variable *declarations[16];
Eric Anholtc22c4002010-03-26 18:20:30 -0700249
Eric Anholt7e78e072010-04-07 13:34:15 -0700250 ir_function_signature *const sig = new ir_function_signature(ret_type);
Ian Romanick6a15d5b52010-03-31 16:37:10 -0700251 f->add_signature(sig);
Eric Anholtc22c4002010-03-26 18:20:30 -0700252
Eric Anholt894ea972010-04-07 13:19:11 -0700253 ir_label *const label = new ir_label(name, sig);
Eric Anholtc22c4002010-03-26 18:20:30 -0700254 instructions->push_tail(label);
255 sig->definition = label;
Eric Anholtbfe380a2010-03-27 12:43:13 -0700256 static const char *arg_names[] = {
257 "arg0",
Eric Anholtcc49cea2010-04-08 15:10:37 -0700258 "arg1",
259 "arg2"
Eric Anholtbfe380a2010-03-27 12:43:13 -0700260 };
261 int i;
Eric Anholtc22c4002010-03-26 18:20:30 -0700262
Eric Anholtbfe380a2010-03-27 12:43:13 -0700263 for (i = 0; i < n_args; i++) {
264 ir_variable *var = new ir_variable(type, arg_names[i]);
Eric Anholtc22c4002010-03-26 18:20:30 -0700265
Eric Anholtbfe380a2010-03-27 12:43:13 -0700266 var->mode = ir_var_in;
267 sig->parameters.push_tail(var);
Eric Anholtc22c4002010-03-26 18:20:30 -0700268
Eric Anholtbfe380a2010-03-27 12:43:13 -0700269 declarations[i] = var;
270 }
Eric Anholtc22c4002010-03-26 18:20:30 -0700271
Eric Anholt894ea972010-04-07 13:19:11 -0700272 generate(&sig->body, declarations, type);
Eric Anholtc22c4002010-03-26 18:20:30 -0700273}
274
275void
276make_gentype_function(glsl_symbol_table *symtab, exec_list *instructions,
277 const char *name,
Eric Anholtbfe380a2010-03-27 12:43:13 -0700278 int n_args,
Eric Anholtc22c4002010-03-26 18:20:30 -0700279 void (*generate)(exec_list *instructions,
280 ir_variable **declarations,
281 const glsl_type *type))
282{
283 ir_function *const f = new ir_function(name);
Eric Anholt53afc362010-03-27 13:55:04 -0700284 const glsl_type *float_type = glsl_type::float_type;
Eric Anholtc22c4002010-03-26 18:20:30 -0700285 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
286 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
287 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
288
289 bool added = symtab->add_function(name, f);
290 assert(added);
291
Eric Anholtbfe380a2010-03-27 12:43:13 -0700292 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700293 float_type, float_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700294 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700295 vec2_type, vec2_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700296 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700297 vec3_type, vec3_type);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700298 generate_function_instance(f, name, instructions, n_args, generate,
Eric Anholt53afc362010-03-27 13:55:04 -0700299 vec4_type, vec4_type);
300}
301
302static void
303generate_length(exec_list *instructions,
304 ir_variable **declarations,
305 const glsl_type *type)
306{
Eric Anholt53afc362010-03-27 13:55:04 -0700307 ir_dereference *const arg = new ir_dereference(declarations[0]);
308 ir_rvalue *result, *temp;
309
310 (void)type;
311
312 /* FINISHME: implement the abs(arg) variant for length(float f) */
313
314 temp = new ir_expression(ir_binop_dot, glsl_type::float_type, arg, arg);
315 result = new ir_expression(ir_unop_sqrt, glsl_type::float_type, temp, NULL);
316
Eric Anholt7e78e072010-04-07 13:34:15 -0700317 ir_instruction *inst = new ir_return(result);
Eric Anholt53afc362010-03-27 13:55:04 -0700318 instructions->push_tail(inst);
319}
320
321void
322generate_length_functions(glsl_symbol_table *symtab, exec_list *instructions)
323{
324 const char *name = "length";
325 ir_function *const f = new ir_function(name);
326 const glsl_type *float_type = glsl_type::float_type;
327 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
328 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
329 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
330
331 bool added = symtab->add_function(name, f);
332 assert(added);
333
334 generate_function_instance(f, name, instructions, 1, generate_length,
335 float_type, float_type);
336 generate_function_instance(f, name, instructions, 1, generate_length,
337 float_type, vec2_type);
338 generate_function_instance(f, name, instructions, 1, generate_length,
339 float_type, vec3_type);
340 generate_function_instance(f, name, instructions, 1, generate_length,
341 float_type, vec4_type);
Eric Anholtc22c4002010-03-26 18:20:30 -0700342}
343
Eric Anholt76a91e12010-03-27 14:04:43 -0700344static void
345generate_dot(exec_list *instructions,
346 ir_variable **declarations,
347 const glsl_type *type)
348{
Eric Anholt61733122010-04-07 15:18:37 -0700349 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
350 ir_dereference *const arg1 = new ir_dereference(declarations[1]);
Eric Anholt76a91e12010-03-27 14:04:43 -0700351 ir_rvalue *result;
352
353 (void)type;
354
Eric Anholt61733122010-04-07 15:18:37 -0700355 result = new ir_expression(ir_binop_dot, glsl_type::float_type, arg0, arg1);
Eric Anholt76a91e12010-03-27 14:04:43 -0700356
Eric Anholt7e78e072010-04-07 13:34:15 -0700357 ir_instruction *inst = new ir_return(result);
Eric Anholt76a91e12010-03-27 14:04:43 -0700358 instructions->push_tail(inst);
359}
360
361void
362generate_dot_functions(glsl_symbol_table *symtab, exec_list *instructions)
363{
364 const char *name = "dot";
365 ir_function *const f = new ir_function(name);
366 const glsl_type *float_type = glsl_type::float_type;
367 const glsl_type *vec2_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 2, 1);
368 const glsl_type *vec3_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 3, 1);
369 const glsl_type *vec4_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
370
371 bool added = symtab->add_function(name, f);
372 assert(added);
373
Eric Anholt61733122010-04-07 15:18:37 -0700374 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700375 float_type, float_type);
Eric Anholt61733122010-04-07 15:18:37 -0700376 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700377 float_type, vec2_type);
Eric Anholt61733122010-04-07 15:18:37 -0700378 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700379 float_type, vec3_type);
Eric Anholt61733122010-04-07 15:18:37 -0700380 generate_function_instance(f, name, instructions, 2, generate_dot,
Eric Anholt76a91e12010-03-27 14:04:43 -0700381 float_type, vec4_type);
382}
383
Eric Anholtfeeb43b2010-04-08 15:02:59 -0700384static void
385generate_any_bvec2(exec_list *instructions,
386 ir_variable **declarations,
387 const glsl_type *type)
388{
389 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
390 ir_rvalue *result;
391
392 (void)type;
393
394 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
395 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
396 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
397
398 ir_instruction *inst = new ir_return(result);
399 instructions->push_tail(inst);
400}
401
402static void
403generate_any_bvec3(exec_list *instructions,
404 ir_variable **declarations,
405 const glsl_type *type)
406{
407 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
408 ir_rvalue *result;
409
410 (void)type;
411
412 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
413 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
414 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
415 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
416 result,
417 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
418
419 ir_instruction *inst = new ir_return(result);
420 instructions->push_tail(inst);
421}
422
423static void
424generate_any_bvec4(exec_list *instructions,
425 ir_variable **declarations,
426 const glsl_type *type)
427{
428 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
429 ir_rvalue *result;
430
431 (void)type;
432
433 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
434 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
435 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
436 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
437 result,
438 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
439 result = new ir_expression(ir_binop_logic_or, glsl_type::bool_type,
440 result,
441 new ir_swizzle(arg0, 3, 0, 0, 0, 1));
442
443 ir_instruction *inst = new ir_return(result);
444 instructions->push_tail(inst);
445}
446
447static void
448generate_all_bvec2(exec_list *instructions,
449 ir_variable **declarations,
450 const glsl_type *type)
451{
452 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
453 ir_rvalue *result;
454
455 (void)type;
456
457 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
458 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
459 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
460
461 ir_instruction *inst = new ir_return(result);
462 instructions->push_tail(inst);
463}
464
465static void
466generate_all_bvec3(exec_list *instructions,
467 ir_variable **declarations,
468 const glsl_type *type)
469{
470 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
471 ir_rvalue *result;
472
473 (void)type;
474
475 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
476 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
477 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
478 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
479 result,
480 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
481
482 ir_instruction *inst = new ir_return(result);
483 instructions->push_tail(inst);
484}
485
486static void
487generate_all_bvec4(exec_list *instructions,
488 ir_variable **declarations,
489 const glsl_type *type)
490{
491 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
492 ir_rvalue *result;
493
494 (void)type;
495
496 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
497 new ir_swizzle(arg0, 0, 0, 0, 0, 1),
498 new ir_swizzle(arg0, 1, 0, 0, 0, 1));
499 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
500 result,
501 new ir_swizzle(arg0, 2, 0, 0, 0, 1));
502 result = new ir_expression(ir_binop_logic_and, glsl_type::bool_type,
503 result,
504 new ir_swizzle(arg0, 3, 0, 0, 0, 1));
505
506 ir_instruction *inst = new ir_return(result);
507 instructions->push_tail(inst);
508}
509
510static void
511generate_not(exec_list *instructions,
512 ir_variable **declarations,
513 const glsl_type *type)
514{
515 ir_dereference *const arg0 = new ir_dereference(declarations[0]);
516 ir_rvalue *result;
517
518 result = new ir_expression(ir_unop_logic_not, type, arg0, NULL);
519
520 ir_instruction *inst = new ir_return(result);
521 instructions->push_tail(inst);
522}
523
524void
525generate_any_functions(glsl_symbol_table *symtab, exec_list *instructions)
526{
527 const char *name = "any";
528 ir_function *const f = new ir_function(name);
529 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
530 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
531 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
532
533 bool added = symtab->add_function(name, f);
534 assert(added);
535
536 generate_function_instance(f, name, instructions, 1, generate_any_bvec2,
537 glsl_type::bool_type, bvec2_type);
538 generate_function_instance(f, name, instructions, 1, generate_any_bvec3,
539 glsl_type::bool_type, bvec3_type);
540 generate_function_instance(f, name, instructions, 1, generate_any_bvec4,
541 glsl_type::bool_type, bvec4_type);
542}
543
544void
545generate_all_functions(glsl_symbol_table *symtab, exec_list *instructions)
546{
547 const char *name = "all";
548 ir_function *const f = new ir_function(name);
549 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
550 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
551 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
552
553 bool added = symtab->add_function(name, f);
554 assert(added);
555
556 generate_function_instance(f, name, instructions, 1, generate_all_bvec2,
557 glsl_type::bool_type, bvec2_type);
558 generate_function_instance(f, name, instructions, 1, generate_all_bvec3,
559 glsl_type::bool_type, bvec3_type);
560 generate_function_instance(f, name, instructions, 1, generate_all_bvec4,
561 glsl_type::bool_type, bvec4_type);
562}
563
564void
565generate_not_functions(glsl_symbol_table *symtab, exec_list *instructions)
566{
567 const char *name = "not";
568 ir_function *const f = new ir_function(name);
569 const glsl_type *bvec2_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 2, 1);
570 const glsl_type *bvec3_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 3, 1);
571 const glsl_type *bvec4_type = glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1);
572
573 bool added = symtab->add_function(name, f);
574 assert(added);
575
576 generate_function_instance(f, name, instructions, 1, generate_not,
577 bvec2_type, bvec2_type);
578 generate_function_instance(f, name, instructions, 1, generate_not,
579 bvec3_type, bvec3_type);
580 generate_function_instance(f, name, instructions, 1, generate_not,
581 bvec4_type, bvec4_type);
582}
583
Eric Anholtc22c4002010-03-26 18:20:30 -0700584void
585generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions)
586{
Eric Anholtd1e31952010-03-28 01:55:38 -0700587 make_gentype_function(symtab, instructions, "radians", 1, generate_radians);
588 make_gentype_function(symtab, instructions, "degrees", 1, generate_degrees);
Eric Anholtc22c4002010-03-26 18:20:30 -0700589 /* FINISHME: sin() */
590 /* FINISHME: cos() */
591 /* FINISHME: tan() */
592 /* FINISHME: asin() */
593 /* FINISHME: acos() */
594 /* FINISHME: atan(y,x) */
595 /* FINISHME: atan(y/x) */
Eric Anholtddd2e832010-03-27 12:59:42 -0700596 make_gentype_function(symtab, instructions, "pow", 2, generate_pow);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700597 make_gentype_function(symtab, instructions, "exp", 1, generate_exp);
598 make_gentype_function(symtab, instructions, "log", 1, generate_log);
Eric Anholt01665262010-03-27 13:56:35 -0700599 make_gentype_function(symtab, instructions, "exp2", 1, generate_exp2);
600 make_gentype_function(symtab, instructions, "log2", 1, generate_log2);
Eric Anholt44d68fd2010-03-27 13:01:51 -0700601 make_gentype_function(symtab, instructions, "sqrt", 1, generate_sqrt);
Eric Anholtbfe380a2010-03-27 12:43:13 -0700602 make_gentype_function(symtab, instructions, "inversesqrt", 1, generate_rsq);
603 make_gentype_function(symtab, instructions, "abs", 1, generate_abs);
Eric Anholtc22c4002010-03-26 18:20:30 -0700604 /* FINISHME: sign() */
Eric Anholtbfe380a2010-03-27 12:43:13 -0700605 make_gentype_function(symtab, instructions, "floor", 1, generate_floor);
606 make_gentype_function(symtab, instructions, "ceil", 1, generate_ceil);
Eric Anholtc22c4002010-03-26 18:20:30 -0700607 /* FINISHME: fract() */
608 /* FINISHME: mod(x, float y) */
Eric Anholtbfe380a2010-03-27 12:43:13 -0700609 make_gentype_function(symtab, instructions, "mod", 2, generate_mod);
610 make_gentype_function(symtab, instructions, "min", 2, generate_min);
611 /* FINISHME: min(x, float y) */
612 make_gentype_function(symtab, instructions, "max", 2, generate_max);
613 /* FINISHME: max(x, float y) */
Eric Anholtc22c4002010-03-26 18:20:30 -0700614 /* FINISHME: clamp() */
615 /* FINISHME: clamp() */
Eric Anholtcc49cea2010-04-08 15:10:37 -0700616 make_gentype_function(symtab, instructions, "mix", 3, generate_mix_vec);
Eric Anholtc22c4002010-03-26 18:20:30 -0700617 /* FINISHME: mix() */
618 /* FINISHME: step() */
619 /* FINISHME: step() */
620 /* FINISHME: smoothstep() */
621 /* FINISHME: smoothstep() */
622 /* FINISHME: floor() */
623 /* FINISHME: step() */
Eric Anholt53afc362010-03-27 13:55:04 -0700624 generate_length_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700625 /* FINISHME: distance() */
Eric Anholt76a91e12010-03-27 14:04:43 -0700626 generate_dot_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700627 /* FINISHME: cross() */
Eric Anholt92575922010-04-08 14:34:38 -0700628 make_gentype_function(symtab, instructions, "normalize", 1,
629 generate_normalize);
Eric Anholtc22c4002010-03-26 18:20:30 -0700630 /* FINISHME: normalize() */
631 /* FINISHME: ftransform() */
632 /* FINISHME: faceforward() */
633 /* FINISHME: reflect() */
634 /* FINISHME: refract() */
635 /* FINISHME: matrixCompMult() */
636 /* FINISHME: lessThan() */
637 /* FINISHME: lessThanEqual() */
638 /* FINISHME: greaterThan() */
639 /* FINISHME: greaterThanEqual() */
640 /* FINISHME: equal() */
641 /* FINISHME: notEqual() */
Eric Anholtfeeb43b2010-04-08 15:02:59 -0700642 generate_any_functions(symtab, instructions);
643 generate_all_functions(symtab, instructions);
644 generate_not_functions(symtab, instructions);
Eric Anholtc22c4002010-03-26 18:20:30 -0700645 /* FINISHME: texture*() */
646 /* FINISHME: shadow*() */
647 /* FINISHME: dFd[xy]() */
648 /* FINISHME: fwidth() */
649}
650
651void
652_mesa_glsl_initialize_functions(exec_list *instructions,
653 struct _mesa_glsl_parse_state *state)
654{
655 generate_110_functions(state->symbols, instructions);
656}