eb661f115ee4369b70b04d98eb19d9a754a82357
[mesa.git] / src / glsl / builtin_functions.cpp
1 /*
2 * Copyright © 2013 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 /**
25 * \file builtin_functions.cpp
26 *
27 * Support for GLSL built-in functions.
28 *
29 * This file is split into several main components:
30 *
31 * 1. Availability predicates
32 *
33 * A series of small functions that check whether the current shader
34 * supports the version/extensions required to expose a built-in.
35 *
36 * 2. Core builtin_builder class functionality
37 *
38 * 3. Lists of built-in functions
39 *
40 * The builtin_builder::create_builtins() function contains lists of all
41 * built-in function signatures, where they're available, what types they
42 * take, and so on.
43 *
44 * 4. Implementations of built-in function signatures
45 *
46 * A series of functions which create ir_function_signatures and emit IR
47 * via ir_builder to implement them.
48 *
49 * 5. External API
50 *
51 * A few functions the rest of the compiler can use to interact with the
52 * built-in function module. For example, searching for a built-in by
53 * name and parameters.
54 */
55
56 #include <stdarg.h>
57 #include <stdio.h>
58 #include "main/core.h" /* for struct gl_shader */
59 #include "main/shaderobj.h"
60 #include "ir_builder.h"
61 #include "glsl_parser_extras.h"
62 #include "program/prog_instruction.h"
63 #include <limits>
64
65 using namespace ir_builder;
66
67 /**
68 * Availability predicates:
69 * @{
70 */
71 static bool
72 always_available(const _mesa_glsl_parse_state *state)
73 {
74 return true;
75 }
76
77 static bool
78 compatibility_vs_only(const _mesa_glsl_parse_state *state)
79 {
80 return state->target == vertex_shader &&
81 state->language_version <= 130 &&
82 !state->es_shader;
83 }
84
85 static bool
86 fs_only(const _mesa_glsl_parse_state *state)
87 {
88 return state->target == fragment_shader;
89 }
90
91 static bool
92 gs_only(const _mesa_glsl_parse_state *state)
93 {
94 return state->target == geometry_shader;
95 }
96
97 static bool
98 v110(const _mesa_glsl_parse_state *state)
99 {
100 return !state->es_shader;
101 }
102
103 static bool
104 v110_fs_only(const _mesa_glsl_parse_state *state)
105 {
106 return !state->es_shader && state->target == fragment_shader;
107 }
108
109 static bool
110 v120(const _mesa_glsl_parse_state *state)
111 {
112 return state->is_version(120, 300);
113 }
114
115 static bool
116 v130(const _mesa_glsl_parse_state *state)
117 {
118 return state->is_version(130, 300);
119 }
120
121 static bool
122 v130_fs_only(const _mesa_glsl_parse_state *state)
123 {
124 return state->is_version(130, 300) &&
125 state->target == fragment_shader;
126 }
127
128 static bool
129 v140(const _mesa_glsl_parse_state *state)
130 {
131 return state->is_version(140, 0);
132 }
133
134 static bool
135 texture_rectangle(const _mesa_glsl_parse_state *state)
136 {
137 return state->ARB_texture_rectangle_enable;
138 }
139
140 static bool
141 texture_external(const _mesa_glsl_parse_state *state)
142 {
143 return state->OES_EGL_image_external_enable;
144 }
145
146 /** True if texturing functions with explicit LOD are allowed. */
147 static bool
148 lod_exists_in_stage(const _mesa_glsl_parse_state *state)
149 {
150 /* Texturing functions with "Lod" in their name exist:
151 * - In the vertex shader stage (for all languages)
152 * - In any stage for GLSL 1.30+ or GLSL ES 3.00
153 * - In any stage for desktop GLSL with ARB_shader_texture_lod enabled.
154 *
155 * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
156 * don't need to explicitly check state->es_shader.
157 */
158 return state->target == vertex_shader ||
159 state->is_version(130, 300) ||
160 state->ARB_shader_texture_lod_enable;
161 }
162
163 static bool
164 v110_lod(const _mesa_glsl_parse_state *state)
165 {
166 return !state->es_shader && lod_exists_in_stage(state);
167 }
168
169 static bool
170 shader_texture_lod(const _mesa_glsl_parse_state *state)
171 {
172 return state->ARB_shader_texture_lod_enable;
173 }
174
175 static bool
176 shader_texture_lod_and_rect(const _mesa_glsl_parse_state *state)
177 {
178 return state->ARB_shader_texture_lod_enable &&
179 state->ARB_texture_rectangle_enable;
180 }
181
182 static bool
183 shader_bit_encoding(const _mesa_glsl_parse_state *state)
184 {
185 return state->is_version(330, 300) ||
186 state->ARB_shader_bit_encoding_enable ||
187 state->ARB_gpu_shader5_enable;
188 }
189
190 static bool
191 shader_integer_mix(const _mesa_glsl_parse_state *state)
192 {
193 return v130(state) && state->MESA_shader_integer_mix_enable;
194 }
195
196 static bool
197 shader_packing(const _mesa_glsl_parse_state *state)
198 {
199 return state->ARB_shading_language_packing_enable ||
200 state->is_version(400, 0);
201 }
202
203 static bool
204 shader_packing_or_es3(const _mesa_glsl_parse_state *state)
205 {
206 return state->ARB_shading_language_packing_enable ||
207 state->is_version(400, 300);
208 }
209
210 static bool
211 gpu_shader5(const _mesa_glsl_parse_state *state)
212 {
213 return state->is_version(400, 0) || state->ARB_gpu_shader5_enable;
214 }
215
216 static bool
217 vs_texture_array(const _mesa_glsl_parse_state *state)
218 {
219 return state->target == vertex_shader &&
220 state->EXT_texture_array_enable;
221 }
222
223 static bool
224 fs_texture_array(const _mesa_glsl_parse_state *state)
225 {
226 return state->target == fragment_shader &&
227 state->EXT_texture_array_enable;
228 }
229
230 static bool
231 texture_array(const _mesa_glsl_parse_state *state)
232 {
233 return state->EXT_texture_array_enable;
234 }
235
236 static bool
237 texture_multisample(const _mesa_glsl_parse_state *state)
238 {
239 return state->is_version(150, 0) ||
240 state->ARB_texture_multisample_enable;
241 }
242
243 static bool
244 fs_texture_cube_map_array(const _mesa_glsl_parse_state *state)
245 {
246 return state->target == fragment_shader &&
247 (state->is_version(400, 0) ||
248 state->ARB_texture_cube_map_array_enable);
249 }
250
251 static bool
252 texture_cube_map_array(const _mesa_glsl_parse_state *state)
253 {
254 return state->is_version(400, 0) ||
255 state->ARB_texture_cube_map_array_enable;
256 }
257
258 static bool
259 texture_query_lod(const _mesa_glsl_parse_state *state)
260 {
261 return state->target == fragment_shader &&
262 state->ARB_texture_query_lod_enable;
263 }
264
265 /* Desktop GL or OES_standard_derivatives + fragment shader only */
266 static bool
267 fs_oes_derivatives(const _mesa_glsl_parse_state *state)
268 {
269 return state->target == fragment_shader &&
270 (!state->es_shader || state->OES_standard_derivatives_enable);
271 }
272
273 static bool
274 tex1d_lod(const _mesa_glsl_parse_state *state)
275 {
276 return !state->es_shader && lod_exists_in_stage(state);
277 }
278
279 /** True if sampler3D exists */
280 static bool
281 tex3d(const _mesa_glsl_parse_state *state)
282 {
283 /* sampler3D exists in all desktop GLSL versions, GLSL ES 1.00 with the
284 * OES_texture_3D extension, and in GLSL ES 3.00.
285 */
286 return !state->es_shader ||
287 state->OES_texture_3D_enable ||
288 state->language_version >= 300;
289 }
290
291 static bool
292 fs_tex3d(const _mesa_glsl_parse_state *state)
293 {
294 return state->target == fragment_shader &&
295 (!state->es_shader || state->OES_texture_3D_enable);
296 }
297
298 static bool
299 tex3d_lod(const _mesa_glsl_parse_state *state)
300 {
301 return tex3d(state) && lod_exists_in_stage(state);
302 }
303 /** @} */
304
305 /******************************************************************************/
306
307 /**
308 * builtin_builder: A singleton object representing the core of the built-in
309 * function module.
310 *
311 * It generates IR for every built-in function signature, and organizes them
312 * into functions.
313 */
314 class builtin_builder {
315 public:
316 builtin_builder();
317 ~builtin_builder();
318
319 void initialize();
320 void release();
321 ir_function_signature *find(_mesa_glsl_parse_state *state,
322 const char *name, exec_list *actual_parameters);
323
324 private:
325 void *mem_ctx;
326 /**
327 * A shader to hold all the built-in signatures; created by this module.
328 *
329 * This includes signatures for every built-in, regardless of version or
330 * enabled extensions. The availability predicate associated with each
331 * signature allows matching_signature() to filter out the irrelevant ones.
332 */
333 gl_shader *shader;
334
335 /** Global variables used by built-in functions. */
336 ir_variable *gl_ModelViewProjectionMatrix;
337 ir_variable *gl_Vertex;
338
339 void create_shader();
340 void create_builtins();
341
342 /**
343 * IR builder helpers:
344 *
345 * These convenience functions assist in emitting IR, but don't necessarily
346 * fit in ir_builder itself. Many of them rely on having a mem_ctx class
347 * member available.
348 */
349 ir_variable *in_var(const glsl_type *type, const char *name);
350 ir_variable *out_var(const glsl_type *type, const char *name);
351 ir_constant *imm(float f);
352 ir_constant *imm(int i);
353 ir_constant *imm(unsigned u);
354 ir_constant *imm(const glsl_type *type, const ir_constant_data &);
355 ir_dereference_variable *var_ref(ir_variable *var);
356 ir_dereference_array *array_ref(ir_variable *var, int i);
357 ir_swizzle *matrix_elt(ir_variable *var, int col, int row);
358
359 ir_expression *asin_expr(ir_variable *x);
360
361 /** Create a new function and add the given signatures. */
362 void add_function(const char *name, ...);
363
364 ir_function_signature *new_sig(const glsl_type *return_type,
365 builtin_available_predicate avail,
366 int num_params, ...);
367
368 /**
369 * Function signature generators:
370 * @{
371 */
372 ir_function_signature *unop(builtin_available_predicate avail,
373 ir_expression_operation opcode,
374 const glsl_type *return_type,
375 const glsl_type *param_type);
376 ir_function_signature *binop(ir_expression_operation opcode,
377 builtin_available_predicate avail,
378 const glsl_type *return_type,
379 const glsl_type *param0_type,
380 const glsl_type *param1_type);
381
382 #define B0(X) ir_function_signature *_##X();
383 #define B1(X) ir_function_signature *_##X(const glsl_type *);
384 #define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *);
385 #define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *, const glsl_type *);
386 #define BA1(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *);
387 #define BA2(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *, const glsl_type *);
388 B1(radians)
389 B1(degrees)
390 B1(sin)
391 B1(cos)
392 B1(tan)
393 B1(asin)
394 B1(acos)
395 B1(atan2)
396 B1(atan)
397 B1(sinh)
398 B1(cosh)
399 B1(tanh)
400 B1(asinh)
401 B1(acosh)
402 B1(atanh)
403 B1(pow)
404 B1(exp)
405 B1(log)
406 B1(exp2)
407 B1(log2)
408 B1(sqrt)
409 B1(inversesqrt)
410 B1(abs)
411 B1(sign)
412 B1(floor)
413 B1(trunc)
414 B1(round)
415 B1(roundEven)
416 B1(ceil)
417 B1(fract)
418 B2(mod)
419 B1(modf)
420 BA2(min)
421 BA2(max)
422 BA2(clamp)
423 B2(mix_lrp)
424 ir_function_signature *_mix_sel(builtin_available_predicate avail,
425 const glsl_type *val_type,
426 const glsl_type *blend_type);
427 B2(step)
428 B2(smoothstep)
429 B1(isnan)
430 B1(isinf)
431 B1(floatBitsToInt)
432 B1(floatBitsToUint)
433 B1(intBitsToFloat)
434 B1(uintBitsToFloat)
435 ir_function_signature *_packUnorm2x16(builtin_available_predicate avail);
436 ir_function_signature *_packSnorm2x16(builtin_available_predicate avail);
437 ir_function_signature *_packUnorm4x8(builtin_available_predicate avail);
438 ir_function_signature *_packSnorm4x8(builtin_available_predicate avail);
439 ir_function_signature *_unpackUnorm2x16(builtin_available_predicate avail);
440 ir_function_signature *_unpackSnorm2x16(builtin_available_predicate avail);
441 ir_function_signature *_unpackUnorm4x8(builtin_available_predicate avail);
442 ir_function_signature *_unpackSnorm4x8(builtin_available_predicate avail);
443 ir_function_signature *_packHalf2x16(builtin_available_predicate avail);
444 ir_function_signature *_unpackHalf2x16(builtin_available_predicate avail);
445 B1(length)
446 B1(distance);
447 B1(dot);
448 B1(cross);
449 B1(normalize);
450 B0(ftransform);
451 B1(faceforward);
452 B1(reflect);
453 B1(refract);
454 B1(matrixCompMult);
455 B1(outerProduct);
456 B0(determinant_mat2);
457 B0(determinant_mat3);
458 B0(determinant_mat4);
459 B0(inverse_mat2);
460 B0(inverse_mat3);
461 B0(inverse_mat4);
462 B1(transpose);
463 BA1(lessThan);
464 BA1(lessThanEqual);
465 BA1(greaterThan);
466 BA1(greaterThanEqual);
467 BA1(equal);
468 BA1(notEqual);
469 B1(any);
470 B1(all);
471 B1(not);
472 B2(textureSize);
473 ir_function_signature *_textureSize(builtin_available_predicate avail,
474 const glsl_type *return_type,
475 const glsl_type *sampler_type);
476
477 /** Flags to _texture() */
478 #define TEX_PROJECT 1
479 #define TEX_OFFSET 2
480
481 ir_function_signature *_texture(ir_texture_opcode opcode,
482 builtin_available_predicate avail,
483 const glsl_type *return_type,
484 const glsl_type *sampler_type,
485 const glsl_type *coord_type,
486 int flags = 0);
487 B0(textureCubeArrayShadow);
488 ir_function_signature *_texelFetch(builtin_available_predicate avail,
489 const glsl_type *return_type,
490 const glsl_type *sampler_type,
491 const glsl_type *coord_type,
492 const glsl_type *offset_type = NULL);
493
494 B0(EmitVertex)
495 B0(EndPrimitive)
496
497 B2(textureQueryLod);
498 B1(dFdx);
499 B1(dFdy);
500 B1(fwidth);
501 B1(noise1);
502 B1(noise2);
503 B1(noise3);
504 B1(noise4);
505
506 B1(bitfieldExtract)
507 B1(bitfieldInsert)
508 B1(bitfieldReverse)
509 B1(bitCount)
510 B1(findLSB)
511 B1(findMSB)
512 B1(fma)
513 #undef B0
514 #undef B1
515 #undef B2
516 #undef B3
517 #undef BA1
518 #undef BA2
519 /** @} */
520 };
521
522 /**
523 * Core builtin_builder functionality:
524 * @{
525 */
526 builtin_builder::builtin_builder()
527 : shader(NULL),
528 gl_ModelViewProjectionMatrix(NULL),
529 gl_Vertex(NULL)
530 {
531 mem_ctx = NULL;
532 }
533
534 builtin_builder::~builtin_builder()
535 {
536 ralloc_free(mem_ctx);
537 }
538
539 ir_function_signature *
540 builtin_builder::find(_mesa_glsl_parse_state *state,
541 const char *name, exec_list *actual_parameters)
542 {
543 /* The shader currently being compiled requested a built-in function;
544 * it needs to link against builtin_builder::shader in order to get them.
545 *
546 * Even if we don't find a matching signature, we still need to do this so
547 * that the "no matching signature" error will list potential candidates
548 * from the available built-ins.
549 */
550 state->builtins_to_link[0] = shader;
551 state->num_builtins_to_link = 1;
552
553 ir_function *f = shader->symbols->get_function(name);
554 if (f == NULL)
555 return NULL;
556
557 ir_function_signature *sig = f->matching_signature(state, actual_parameters);
558 if (sig == NULL)
559 return NULL;
560
561 return sig;
562 }
563
564 void
565 builtin_builder::initialize()
566 {
567 /* If already initialized, don't do it again. */
568 if (mem_ctx != NULL)
569 return;
570
571 mem_ctx = ralloc_context(NULL);
572 create_shader();
573 create_builtins();
574 }
575
576 void
577 builtin_builder::release()
578 {
579 ralloc_free(mem_ctx);
580 mem_ctx = NULL;
581 }
582
583 void
584 builtin_builder::create_shader()
585 {
586 /* The target doesn't actually matter. There's no target for generic
587 * GLSL utility code that could be linked against any stage, so just
588 * arbitrarily pick GL_VERTEX_SHADER.
589 */
590 shader = _mesa_new_shader(NULL, 0, GL_VERTEX_SHADER);
591 shader->symbols = new(mem_ctx) glsl_symbol_table;
592
593 gl_ModelViewProjectionMatrix =
594 new(mem_ctx) ir_variable(glsl_type::mat4_type,
595 "gl_ModelViewProjectionMatrix",
596 ir_var_uniform);
597
598 shader->symbols->add_variable(gl_ModelViewProjectionMatrix);
599
600 gl_Vertex = in_var(glsl_type::vec4_type, "gl_Vertex");
601 shader->symbols->add_variable(gl_Vertex);
602 }
603
604 /** @} */
605
606 /**
607 * Create ir_function and ir_function_signature objects for each built-in.
608 *
609 * Contains a list of every available built-in.
610 */
611 void
612 builtin_builder::create_builtins()
613 {
614 #define F(NAME) \
615 add_function(#NAME, \
616 _##NAME(glsl_type::float_type), \
617 _##NAME(glsl_type::vec2_type), \
618 _##NAME(glsl_type::vec3_type), \
619 _##NAME(glsl_type::vec4_type), \
620 NULL);
621
622 #define FI(NAME) \
623 add_function(#NAME, \
624 _##NAME(glsl_type::float_type), \
625 _##NAME(glsl_type::vec2_type), \
626 _##NAME(glsl_type::vec3_type), \
627 _##NAME(glsl_type::vec4_type), \
628 _##NAME(glsl_type::int_type), \
629 _##NAME(glsl_type::ivec2_type), \
630 _##NAME(glsl_type::ivec3_type), \
631 _##NAME(glsl_type::ivec4_type), \
632 NULL);
633
634 #define FIU(NAME) \
635 add_function(#NAME, \
636 _##NAME(always_available, glsl_type::float_type), \
637 _##NAME(always_available, glsl_type::vec2_type), \
638 _##NAME(always_available, glsl_type::vec3_type), \
639 _##NAME(always_available, glsl_type::vec4_type), \
640 \
641 _##NAME(always_available, glsl_type::int_type), \
642 _##NAME(always_available, glsl_type::ivec2_type), \
643 _##NAME(always_available, glsl_type::ivec3_type), \
644 _##NAME(always_available, glsl_type::ivec4_type), \
645 \
646 _##NAME(v130, glsl_type::uint_type), \
647 _##NAME(v130, glsl_type::uvec2_type), \
648 _##NAME(v130, glsl_type::uvec3_type), \
649 _##NAME(v130, glsl_type::uvec4_type), \
650 NULL);
651
652 #define IU(NAME) \
653 add_function(#NAME, \
654 _##NAME(glsl_type::int_type), \
655 _##NAME(glsl_type::ivec2_type), \
656 _##NAME(glsl_type::ivec3_type), \
657 _##NAME(glsl_type::ivec4_type), \
658 \
659 _##NAME(glsl_type::uint_type), \
660 _##NAME(glsl_type::uvec2_type), \
661 _##NAME(glsl_type::uvec3_type), \
662 _##NAME(glsl_type::uvec4_type), \
663 NULL);
664
665 #define FIUB(NAME) \
666 add_function(#NAME, \
667 _##NAME(always_available, glsl_type::float_type), \
668 _##NAME(always_available, glsl_type::vec2_type), \
669 _##NAME(always_available, glsl_type::vec3_type), \
670 _##NAME(always_available, glsl_type::vec4_type), \
671 \
672 _##NAME(always_available, glsl_type::int_type), \
673 _##NAME(always_available, glsl_type::ivec2_type), \
674 _##NAME(always_available, glsl_type::ivec3_type), \
675 _##NAME(always_available, glsl_type::ivec4_type), \
676 \
677 _##NAME(v130, glsl_type::uint_type), \
678 _##NAME(v130, glsl_type::uvec2_type), \
679 _##NAME(v130, glsl_type::uvec3_type), \
680 _##NAME(v130, glsl_type::uvec4_type), \
681 \
682 _##NAME(always_available, glsl_type::bool_type), \
683 _##NAME(always_available, glsl_type::bvec2_type), \
684 _##NAME(always_available, glsl_type::bvec3_type), \
685 _##NAME(always_available, glsl_type::bvec4_type), \
686 NULL);
687
688 #define FIU2_MIXED(NAME) \
689 add_function(#NAME, \
690 _##NAME(always_available, glsl_type::float_type, glsl_type::float_type), \
691 _##NAME(always_available, glsl_type::vec2_type, glsl_type::float_type), \
692 _##NAME(always_available, glsl_type::vec3_type, glsl_type::float_type), \
693 _##NAME(always_available, glsl_type::vec4_type, glsl_type::float_type), \
694 \
695 _##NAME(always_available, glsl_type::vec2_type, glsl_type::vec2_type), \
696 _##NAME(always_available, glsl_type::vec3_type, glsl_type::vec3_type), \
697 _##NAME(always_available, glsl_type::vec4_type, glsl_type::vec4_type), \
698 \
699 _##NAME(always_available, glsl_type::int_type, glsl_type::int_type), \
700 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::int_type), \
701 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::int_type), \
702 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::int_type), \
703 \
704 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::ivec2_type), \
705 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
706 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
707 \
708 _##NAME(v130, glsl_type::uint_type, glsl_type::uint_type), \
709 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uint_type), \
710 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uint_type), \
711 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uint_type), \
712 \
713 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uvec2_type), \
714 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uvec3_type), \
715 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uvec4_type), \
716 NULL);
717
718 F(radians)
719 F(degrees)
720 F(sin)
721 F(cos)
722 F(tan)
723 F(asin)
724 F(acos)
725
726 add_function("atan",
727 _atan(glsl_type::float_type),
728 _atan(glsl_type::vec2_type),
729 _atan(glsl_type::vec3_type),
730 _atan(glsl_type::vec4_type),
731 _atan2(glsl_type::float_type),
732 _atan2(glsl_type::vec2_type),
733 _atan2(glsl_type::vec3_type),
734 _atan2(glsl_type::vec4_type),
735 NULL);
736
737 F(sinh)
738 F(cosh)
739 F(tanh)
740 F(asinh)
741 F(acosh)
742 F(atanh)
743 F(pow)
744 F(exp)
745 F(log)
746 F(exp2)
747 F(log2)
748 F(sqrt)
749 F(inversesqrt)
750 FI(abs)
751 FI(sign)
752 F(floor)
753 F(trunc)
754 F(round)
755 F(roundEven)
756 F(ceil)
757 F(fract)
758
759 add_function("mod",
760 _mod(glsl_type::float_type, glsl_type::float_type),
761 _mod(glsl_type::vec2_type, glsl_type::float_type),
762 _mod(glsl_type::vec3_type, glsl_type::float_type),
763 _mod(glsl_type::vec4_type, glsl_type::float_type),
764
765 _mod(glsl_type::vec2_type, glsl_type::vec2_type),
766 _mod(glsl_type::vec3_type, glsl_type::vec3_type),
767 _mod(glsl_type::vec4_type, glsl_type::vec4_type),
768 NULL);
769
770 F(modf)
771
772 FIU2_MIXED(min)
773 FIU2_MIXED(max)
774 FIU2_MIXED(clamp)
775
776 add_function("mix",
777 _mix_lrp(glsl_type::float_type, glsl_type::float_type),
778 _mix_lrp(glsl_type::vec2_type, glsl_type::float_type),
779 _mix_lrp(glsl_type::vec3_type, glsl_type::float_type),
780 _mix_lrp(glsl_type::vec4_type, glsl_type::float_type),
781
782 _mix_lrp(glsl_type::vec2_type, glsl_type::vec2_type),
783 _mix_lrp(glsl_type::vec3_type, glsl_type::vec3_type),
784 _mix_lrp(glsl_type::vec4_type, glsl_type::vec4_type),
785
786 _mix_sel(v130, glsl_type::float_type, glsl_type::bool_type),
787 _mix_sel(v130, glsl_type::vec2_type, glsl_type::bvec2_type),
788 _mix_sel(v130, glsl_type::vec3_type, glsl_type::bvec3_type),
789 _mix_sel(v130, glsl_type::vec4_type, glsl_type::bvec4_type),
790
791 _mix_sel(shader_integer_mix, glsl_type::int_type, glsl_type::bool_type),
792 _mix_sel(shader_integer_mix, glsl_type::ivec2_type, glsl_type::bvec2_type),
793 _mix_sel(shader_integer_mix, glsl_type::ivec3_type, glsl_type::bvec3_type),
794 _mix_sel(shader_integer_mix, glsl_type::ivec4_type, glsl_type::bvec4_type),
795
796 _mix_sel(shader_integer_mix, glsl_type::uint_type, glsl_type::bool_type),
797 _mix_sel(shader_integer_mix, glsl_type::uvec2_type, glsl_type::bvec2_type),
798 _mix_sel(shader_integer_mix, glsl_type::uvec3_type, glsl_type::bvec3_type),
799 _mix_sel(shader_integer_mix, glsl_type::uvec4_type, glsl_type::bvec4_type),
800
801 _mix_sel(shader_integer_mix, glsl_type::bool_type, glsl_type::bool_type),
802 _mix_sel(shader_integer_mix, glsl_type::bvec2_type, glsl_type::bvec2_type),
803 _mix_sel(shader_integer_mix, glsl_type::bvec3_type, glsl_type::bvec3_type),
804 _mix_sel(shader_integer_mix, glsl_type::bvec4_type, glsl_type::bvec4_type),
805 NULL);
806
807 add_function("step",
808 _step(glsl_type::float_type, glsl_type::float_type),
809 _step(glsl_type::float_type, glsl_type::vec2_type),
810 _step(glsl_type::float_type, glsl_type::vec3_type),
811 _step(glsl_type::float_type, glsl_type::vec4_type),
812
813 _step(glsl_type::vec2_type, glsl_type::vec2_type),
814 _step(glsl_type::vec3_type, glsl_type::vec3_type),
815 _step(glsl_type::vec4_type, glsl_type::vec4_type),
816 NULL);
817
818 add_function("smoothstep",
819 _smoothstep(glsl_type::float_type, glsl_type::float_type),
820 _smoothstep(glsl_type::float_type, glsl_type::vec2_type),
821 _smoothstep(glsl_type::float_type, glsl_type::vec3_type),
822 _smoothstep(glsl_type::float_type, glsl_type::vec4_type),
823
824 _smoothstep(glsl_type::vec2_type, glsl_type::vec2_type),
825 _smoothstep(glsl_type::vec3_type, glsl_type::vec3_type),
826 _smoothstep(glsl_type::vec4_type, glsl_type::vec4_type),
827 NULL);
828
829 F(isnan)
830 F(isinf)
831
832 F(floatBitsToInt)
833 F(floatBitsToUint)
834 add_function("intBitsToFloat",
835 _intBitsToFloat(glsl_type::int_type),
836 _intBitsToFloat(glsl_type::ivec2_type),
837 _intBitsToFloat(glsl_type::ivec3_type),
838 _intBitsToFloat(glsl_type::ivec4_type),
839 NULL);
840 add_function("uintBitsToFloat",
841 _uintBitsToFloat(glsl_type::uint_type),
842 _uintBitsToFloat(glsl_type::uvec2_type),
843 _uintBitsToFloat(glsl_type::uvec3_type),
844 _uintBitsToFloat(glsl_type::uvec4_type),
845 NULL);
846
847 add_function("packUnorm2x16", _packUnorm2x16(shader_packing_or_es3), NULL);
848 add_function("packSnorm2x16", _packSnorm2x16(shader_packing_or_es3), NULL);
849 add_function("packUnorm4x8", _packUnorm4x8(shader_packing), NULL);
850 add_function("packSnorm4x8", _packSnorm4x8(shader_packing), NULL);
851 add_function("unpackUnorm2x16", _unpackUnorm2x16(shader_packing_or_es3), NULL);
852 add_function("unpackSnorm2x16", _unpackSnorm2x16(shader_packing_or_es3), NULL);
853 add_function("unpackUnorm4x8", _unpackUnorm4x8(shader_packing), NULL);
854 add_function("unpackSnorm4x8", _unpackSnorm4x8(shader_packing), NULL);
855 add_function("packHalf2x16", _packHalf2x16(shader_packing_or_es3), NULL);
856 add_function("unpackHalf2x16", _unpackHalf2x16(shader_packing_or_es3), NULL);
857
858 F(length)
859 F(distance)
860 F(dot)
861
862 add_function("cross", _cross(glsl_type::vec3_type), NULL);
863
864 F(normalize)
865 add_function("ftransform", _ftransform(), NULL);
866 F(faceforward)
867 F(reflect)
868 F(refract)
869 // ...
870 add_function("matrixCompMult",
871 _matrixCompMult(glsl_type::mat2_type),
872 _matrixCompMult(glsl_type::mat3_type),
873 _matrixCompMult(glsl_type::mat4_type),
874 _matrixCompMult(glsl_type::mat2x3_type),
875 _matrixCompMult(glsl_type::mat2x4_type),
876 _matrixCompMult(glsl_type::mat3x2_type),
877 _matrixCompMult(glsl_type::mat3x4_type),
878 _matrixCompMult(glsl_type::mat4x2_type),
879 _matrixCompMult(glsl_type::mat4x3_type),
880 NULL);
881 add_function("outerProduct",
882 _outerProduct(glsl_type::mat2_type),
883 _outerProduct(glsl_type::mat3_type),
884 _outerProduct(glsl_type::mat4_type),
885 _outerProduct(glsl_type::mat2x3_type),
886 _outerProduct(glsl_type::mat2x4_type),
887 _outerProduct(glsl_type::mat3x2_type),
888 _outerProduct(glsl_type::mat3x4_type),
889 _outerProduct(glsl_type::mat4x2_type),
890 _outerProduct(glsl_type::mat4x3_type),
891 NULL);
892 add_function("determinant",
893 _determinant_mat2(),
894 _determinant_mat3(),
895 _determinant_mat4(),
896 NULL);
897 add_function("inverse",
898 _inverse_mat2(),
899 _inverse_mat3(),
900 _inverse_mat4(),
901 NULL);
902 add_function("transpose",
903 _transpose(glsl_type::mat2_type),
904 _transpose(glsl_type::mat3_type),
905 _transpose(glsl_type::mat4_type),
906 _transpose(glsl_type::mat2x3_type),
907 _transpose(glsl_type::mat2x4_type),
908 _transpose(glsl_type::mat3x2_type),
909 _transpose(glsl_type::mat3x4_type),
910 _transpose(glsl_type::mat4x2_type),
911 _transpose(glsl_type::mat4x3_type),
912 NULL);
913 FIU(lessThan)
914 FIU(lessThanEqual)
915 FIU(greaterThan)
916 FIU(greaterThanEqual)
917 FIUB(notEqual)
918 FIUB(equal)
919
920 add_function("any",
921 _any(glsl_type::bvec2_type),
922 _any(glsl_type::bvec3_type),
923 _any(glsl_type::bvec4_type),
924 NULL);
925
926 add_function("all",
927 _all(glsl_type::bvec2_type),
928 _all(glsl_type::bvec3_type),
929 _all(glsl_type::bvec4_type),
930 NULL);
931
932 add_function("not",
933 _not(glsl_type::bvec2_type),
934 _not(glsl_type::bvec3_type),
935 _not(glsl_type::bvec4_type),
936 NULL);
937
938 add_function("textureSize",
939 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1D_type),
940 _textureSize(v130, glsl_type::int_type, glsl_type::isampler1D_type),
941 _textureSize(v130, glsl_type::int_type, glsl_type::usampler1D_type),
942
943 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2D_type),
944 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2D_type),
945 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2D_type),
946
947 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler3D_type),
948 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler3D_type),
949 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler3D_type),
950
951 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCube_type),
952 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
953 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
954
955 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1DShadow_type),
956 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DShadow_type),
957 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCubeShadow_type),
958
959 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
960 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
961 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
962 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
963 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
964 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
965
966 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArrayShadow_type),
967 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArrayShadow_type),
968
969 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArray_type),
970 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::isamplerCubeArray_type),
971 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::usamplerCubeArray_type),
972 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArrayShadow_type),
973
974 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
975 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
976 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
977 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRectShadow_type),
978
979 _textureSize(v140, glsl_type::int_type, glsl_type::samplerBuffer_type),
980 _textureSize(v140, glsl_type::int_type, glsl_type::isamplerBuffer_type),
981 _textureSize(v140, glsl_type::int_type, glsl_type::usamplerBuffer_type),
982 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::sampler2DMS_type),
983 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::isampler2DMS_type),
984 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::usampler2DMS_type),
985
986 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::sampler2DMSArray_type),
987 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::isampler2DMSArray_type),
988 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::usampler2DMSArray_type),
989 NULL);
990
991 add_function("texture",
992 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
993 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
994 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
995
996 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
997 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
998 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
999
1000 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1001 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1002 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1003
1004 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1005 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1006 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1007
1008 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1009 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1010 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1011
1012 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1013 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1014 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1015
1016 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1017 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1018 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1019
1020 _texture(ir_tex, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1021 _texture(ir_tex, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1022 _texture(ir_tex, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1023
1024 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1025 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1026 /* samplerCubeArrayShadow is special; it has an extra parameter
1027 * for the shadow comparitor since there is no vec5 type.
1028 */
1029 _textureCubeArrayShadow(),
1030
1031 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1032 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
1033 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
1034
1035 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1036
1037 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1038 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1039 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1040
1041 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1042 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1043 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1044
1045 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1046 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1047 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1048
1049 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1050 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1051 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1052
1053 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1054 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1055 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1056
1057 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1058 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1059 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1060
1061 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1062 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1063 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1064
1065 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1066 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1067 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1068
1069 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1070 NULL);
1071
1072 add_function("textureLod",
1073 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1074 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1075 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1076
1077 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1078 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1079 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1080
1081 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1082 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1083 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1084
1085 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1086 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1087 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1088
1089 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1090 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1091
1092 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1093 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1094 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1095
1096 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1097 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1098 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1099
1100 _texture(ir_txl, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1101 _texture(ir_txl, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1102 _texture(ir_txl, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1103
1104 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1105 NULL);
1106
1107 add_function("textureOffset",
1108 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1109 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1110 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1111
1112 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1113 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1114 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1115
1116 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1117 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1118 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1119
1120 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1121 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1122 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1123
1124 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1125
1126 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1127 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1128
1129 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1130 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1131 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1132
1133 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1134 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1135 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1136
1137 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1138
1139 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1140 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1141 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1142
1143 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1144 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1145 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1146
1147 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1148 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1149 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1150
1151 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1152 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1153
1154 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1155 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1156 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1157
1158 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1159 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1160 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1161
1162 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1163 NULL);
1164
1165 add_function("textureProj",
1166 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1167 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1168 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1169 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1170 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1171 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1172
1173 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1174 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1175 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1176 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1177 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1178 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1179
1180 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1181 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1182 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1183
1184 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1185 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1186
1187 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1188 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1189 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1190 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1191 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1192 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1193
1194 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1195
1196 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1197 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1198 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1199 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1200 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1201 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1202
1203 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1204 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1205 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1206 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1207 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1208 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1209
1210 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1211 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1212 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1213
1214 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1215 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1216 NULL);
1217
1218 add_function("texelFetch",
1219 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
1220 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
1221 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
1222
1223 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
1224 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
1225 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
1226
1227 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
1228 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
1229 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
1230
1231 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
1232 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
1233 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
1234
1235 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
1236 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
1237 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
1238
1239 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
1240 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
1241 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
1242
1243 _texelFetch(v140, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
1244 _texelFetch(v140, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
1245 _texelFetch(v140, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
1246
1247 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
1248 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
1249 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
1250
1251 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
1252 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
1253 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
1254 NULL);
1255
1256 add_function("texelFetchOffset",
1257 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
1258 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
1259 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
1260
1261 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1262 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1263 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1264
1265 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1266 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1267 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1268
1269 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1270 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1271 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1272
1273 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1274 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1275 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1276
1277 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1278 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1279 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1280
1281 NULL);
1282
1283 add_function("textureProjOffset",
1284 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1285 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1286 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1287 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1288 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1289 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1290
1291 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1292 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1293 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1294 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1295 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1296 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1297
1298 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1299 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1300 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1301
1302 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1303 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1304
1305 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1306 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1307 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1308 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1309 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1310 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1311
1312 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1313
1314 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1315 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1316 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1317 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1318 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1319 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1320
1321 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1322 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1323 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1324 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1325 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1326 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1327
1328 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1329 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1330 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1331
1332 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1333 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1334 NULL);
1335
1336 add_function("textureLodOffset",
1337 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1338 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1339 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1340
1341 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1342 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1343 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1344
1345 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1346 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1347 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1348
1349 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1350 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1351
1352 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1353 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1354 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1355
1356 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1357 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1358 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1359
1360 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1361 NULL);
1362
1363 add_function("textureProjLod",
1364 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1365 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1366 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1367 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1368 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1369 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1370
1371 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1372 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1373 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1374 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1375 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1376 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1377
1378 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1379 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1380 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1381
1382 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1383 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1384 NULL);
1385
1386 add_function("textureProjLodOffset",
1387 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1388 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1389 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1390 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1391 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1392 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1393
1394 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1395 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1396 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1397 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1398 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1399 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1400
1401 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1402 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1403 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1404
1405 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1406 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1407 NULL);
1408
1409 add_function("textureGrad",
1410 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1411 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1412 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1413
1414 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1415 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1416 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1417
1418 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1419 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1420 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1421
1422 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1423 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1424 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1425
1426 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1427 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
1428 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
1429
1430 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1431
1432 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1433 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1434 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1435
1436 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1437 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1438 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1439
1440 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1441 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1442 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1443
1444 _texture(ir_txd, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1445 _texture(ir_txd, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1446 _texture(ir_txd, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1447
1448 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1449 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1450 NULL);
1451
1452 add_function("textureGradOffset",
1453 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1454 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1455 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1456
1457 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1458 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1459 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1460
1461 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1462 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1463 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1464
1465 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1466 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1467 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1468
1469 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1470
1471 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1472 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1473
1474 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1475 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1476 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1477
1478 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1479 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1480 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1481
1482 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1483 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
1484 NULL);
1485
1486 add_function("textureProjGrad",
1487 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1488 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1489 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1490 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1491 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1492 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1493
1494 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1495 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1496 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1497 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1498 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1499 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1500
1501 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1502 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1503 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1504
1505 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1506 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1507 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1508 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1509 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1510 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1511
1512 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1513
1514 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1515 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1516 NULL);
1517
1518 add_function("textureProjGradOffset",
1519 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1520 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1521 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1522 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1523 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1524 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1525
1526 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1527 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1528 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1529 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1530 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1531 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1532
1533 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1534 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1535 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1536
1537 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1538 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1539 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1540 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1541 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1542 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1543
1544 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1545
1546 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1547 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1548 NULL);
1549
1550 add_function("EmitVertex", _EmitVertex(), NULL);
1551 add_function("EndPrimitive", _EndPrimitive(), NULL);
1552
1553 add_function("textureQueryLOD",
1554 _textureQueryLod(glsl_type::sampler1D_type, glsl_type::float_type),
1555 _textureQueryLod(glsl_type::isampler1D_type, glsl_type::float_type),
1556 _textureQueryLod(glsl_type::usampler1D_type, glsl_type::float_type),
1557
1558 _textureQueryLod(glsl_type::sampler2D_type, glsl_type::vec2_type),
1559 _textureQueryLod(glsl_type::isampler2D_type, glsl_type::vec2_type),
1560 _textureQueryLod(glsl_type::usampler2D_type, glsl_type::vec2_type),
1561
1562 _textureQueryLod(glsl_type::sampler3D_type, glsl_type::vec3_type),
1563 _textureQueryLod(glsl_type::isampler3D_type, glsl_type::vec3_type),
1564 _textureQueryLod(glsl_type::usampler3D_type, glsl_type::vec3_type),
1565
1566 _textureQueryLod(glsl_type::samplerCube_type, glsl_type::vec3_type),
1567 _textureQueryLod(glsl_type::isamplerCube_type, glsl_type::vec3_type),
1568 _textureQueryLod(glsl_type::usamplerCube_type, glsl_type::vec3_type),
1569
1570 _textureQueryLod(glsl_type::sampler1DArray_type, glsl_type::float_type),
1571 _textureQueryLod(glsl_type::isampler1DArray_type, glsl_type::float_type),
1572 _textureQueryLod(glsl_type::usampler1DArray_type, glsl_type::float_type),
1573
1574 _textureQueryLod(glsl_type::sampler2DArray_type, glsl_type::vec2_type),
1575 _textureQueryLod(glsl_type::isampler2DArray_type, glsl_type::vec2_type),
1576 _textureQueryLod(glsl_type::usampler2DArray_type, glsl_type::vec2_type),
1577
1578 _textureQueryLod(glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
1579 _textureQueryLod(glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
1580 _textureQueryLod(glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
1581
1582 _textureQueryLod(glsl_type::sampler1DShadow_type, glsl_type::float_type),
1583 _textureQueryLod(glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
1584 _textureQueryLod(glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
1585 _textureQueryLod(glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
1586 _textureQueryLod(glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
1587 _textureQueryLod(glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
1588 NULL);
1589
1590 add_function("texture1D",
1591 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1592 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1593 NULL);
1594
1595 add_function("texture1DArray",
1596 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1597 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1598 NULL);
1599
1600 add_function("texture1DProj",
1601 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1602 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1603 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1604 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1605 NULL);
1606
1607 add_function("texture1DLod",
1608 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1609 NULL);
1610
1611 add_function("texture1DArrayLod",
1612 _texture(ir_txl, vs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1613 NULL);
1614
1615 add_function("texture1DProjLod",
1616 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1617 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1618 NULL);
1619
1620 add_function("texture2D",
1621 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1622 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1623 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
1624 NULL);
1625
1626 add_function("texture2DArray",
1627 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1628 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1629 NULL);
1630
1631 add_function("texture2DProj",
1632 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1633 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1634 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1635 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1636 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
1637 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
1638 NULL);
1639
1640 add_function("texture2DLod",
1641 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1642 NULL);
1643
1644 add_function("texture2DArrayLod",
1645 _texture(ir_txl, vs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1646 NULL);
1647
1648 add_function("texture2DProjLod",
1649 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1650 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1651 NULL);
1652
1653 add_function("texture3D",
1654 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1655 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1656 NULL);
1657
1658 add_function("texture3DProj",
1659 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1660 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1661 NULL);
1662
1663 add_function("texture3DLod",
1664 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1665 NULL);
1666
1667 add_function("texture3DProjLod",
1668 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1669 NULL);
1670
1671 add_function("textureCube",
1672 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1673 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1674 NULL);
1675
1676 add_function("textureCubeLod",
1677 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1678 NULL);
1679
1680 add_function("texture2DRect",
1681 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1682 NULL);
1683
1684 add_function("texture2DRectProj",
1685 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1686 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1687 NULL);
1688
1689 add_function("shadow1D",
1690 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1691 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1692 NULL);
1693
1694 add_function("shadow1DArray",
1695 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1696 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1697 NULL);
1698
1699 add_function("shadow2D",
1700 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1701 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1702 NULL);
1703
1704 add_function("shadow2DArray",
1705 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1706 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1707 NULL);
1708
1709 add_function("shadow1DProj",
1710 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1711 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1712 NULL);
1713
1714 add_function("shadow2DProj",
1715 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1716 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1717 NULL);
1718
1719 add_function("shadow1DLod",
1720 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1721 NULL);
1722
1723 add_function("shadow2DLod",
1724 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1725 NULL);
1726
1727 add_function("shadow1DArrayLod",
1728 _texture(ir_txl, vs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1729 NULL);
1730
1731 add_function("shadow1DProjLod",
1732 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1733 NULL);
1734
1735 add_function("shadow2DProjLod",
1736 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1737 NULL);
1738
1739 add_function("shadow2DRect",
1740 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1741 NULL);
1742
1743 add_function("shadow2DRectProj",
1744 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1745 NULL);
1746
1747 add_function("texture1DGradARB",
1748 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1749 NULL);
1750
1751 add_function("texture1DProjGradARB",
1752 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1753 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1754 NULL);
1755
1756 add_function("texture2DGradARB",
1757 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1758 NULL);
1759
1760 add_function("texture2DProjGradARB",
1761 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1762 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1763 NULL);
1764
1765 add_function("texture3DGradARB",
1766 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1767 NULL);
1768
1769 add_function("texture3DProjGradARB",
1770 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1771 NULL);
1772
1773 add_function("textureCubeGradARB",
1774 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1775 NULL);
1776
1777 add_function("shadow1DGradARB",
1778 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1779 NULL);
1780
1781 add_function("shadow1DProjGradARB",
1782 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1783 NULL);
1784
1785 add_function("shadow2DGradARB",
1786 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1787 NULL);
1788
1789 add_function("shadow2DProjGradARB",
1790 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1791 NULL);
1792
1793 add_function("texture2DRectGradARB",
1794 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1795 NULL);
1796
1797 add_function("texture2DRectProjGradARB",
1798 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1799 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1800 NULL);
1801
1802 add_function("shadow2DRectGradARB",
1803 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1804 NULL);
1805
1806 add_function("shadow2DRectProjGradARB",
1807 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1808 NULL);
1809
1810 F(dFdx)
1811 F(dFdy)
1812 F(fwidth)
1813 F(noise1)
1814 F(noise2)
1815 F(noise3)
1816 F(noise4)
1817
1818 IU(bitfieldExtract)
1819 IU(bitfieldInsert)
1820 IU(bitfieldReverse)
1821 IU(bitCount)
1822 IU(findLSB)
1823 IU(findMSB)
1824 F(fma)
1825 #undef F
1826 #undef FI
1827 #undef FIU
1828 #undef FIUB
1829 #undef FIU2_MIXED
1830 }
1831
1832 void
1833 builtin_builder::add_function(const char *name, ...)
1834 {
1835 va_list ap;
1836
1837 ir_function *f = new(mem_ctx) ir_function(name);
1838
1839 va_start(ap, name);
1840 while (true) {
1841 ir_function_signature *sig = va_arg(ap, ir_function_signature *);
1842 if (sig == NULL)
1843 break;
1844
1845 sig->is_defined = true;
1846
1847 if (false) {
1848 exec_list stuff;
1849 stuff.push_tail(sig);
1850 validate_ir_tree(&stuff);
1851 }
1852
1853 f->add_signature(sig);
1854 }
1855 va_end(ap);
1856
1857 shader->symbols->add_function(f);
1858 }
1859
1860 ir_variable *
1861 builtin_builder::in_var(const glsl_type *type, const char *name)
1862 {
1863 return new(mem_ctx) ir_variable(type, name, ir_var_function_in);
1864 }
1865
1866 ir_variable *
1867 builtin_builder::out_var(const glsl_type *type, const char *name)
1868 {
1869 return new(mem_ctx) ir_variable(type, name, ir_var_function_out);
1870 }
1871
1872 ir_constant *
1873 builtin_builder::imm(float f)
1874 {
1875 return new(mem_ctx) ir_constant(f);
1876 }
1877
1878 ir_constant *
1879 builtin_builder::imm(int i)
1880 {
1881 return new(mem_ctx) ir_constant(i);
1882 }
1883
1884 ir_constant *
1885 builtin_builder::imm(unsigned u)
1886 {
1887 return new(mem_ctx) ir_constant(u);
1888 }
1889
1890 ir_constant *
1891 builtin_builder::imm(const glsl_type *type, const ir_constant_data &data)
1892 {
1893 return new(mem_ctx) ir_constant(type, &data);
1894 }
1895
1896 ir_dereference_variable *
1897 builtin_builder::var_ref(ir_variable *var)
1898 {
1899 return new(mem_ctx) ir_dereference_variable(var);
1900 }
1901
1902 ir_dereference_array *
1903 builtin_builder::array_ref(ir_variable *var, int idx)
1904 {
1905 return new(mem_ctx) ir_dereference_array(var, imm(idx));
1906 }
1907
1908 /** Return an element of a matrix */
1909 ir_swizzle *
1910 builtin_builder::matrix_elt(ir_variable *var, int column, int row)
1911 {
1912 return swizzle(array_ref(var, column), row, 1);
1913 }
1914
1915 /**
1916 * Implementations of built-in functions:
1917 * @{
1918 */
1919 ir_function_signature *
1920 builtin_builder::new_sig(const glsl_type *return_type,
1921 builtin_available_predicate avail,
1922 int num_params,
1923 ...)
1924 {
1925 va_list ap;
1926
1927 ir_function_signature *sig =
1928 new(mem_ctx) ir_function_signature(return_type, avail);
1929
1930 exec_list plist;
1931 va_start(ap, num_params);
1932 for (int i = 0; i < num_params; i++) {
1933 plist.push_tail(va_arg(ap, ir_variable *));
1934 }
1935 va_end(ap);
1936
1937 sig->replace_parameters(&plist);
1938 return sig;
1939 }
1940
1941 #define MAKE_SIG(return_type, avail, ...) \
1942 ir_function_signature *sig = \
1943 new_sig(return_type, avail, __VA_ARGS__); \
1944 ir_factory body(&sig->body, mem_ctx);
1945
1946 ir_function_signature *
1947 builtin_builder::unop(builtin_available_predicate avail,
1948 ir_expression_operation opcode,
1949 const glsl_type *return_type,
1950 const glsl_type *param_type)
1951 {
1952 ir_variable *x = in_var(param_type, "x");
1953 MAKE_SIG(return_type, avail, 1, x);
1954 body.emit(ret(expr(opcode, x)));
1955 return sig;
1956 }
1957
1958 #define UNOP(NAME, OPCODE, AVAIL) \
1959 ir_function_signature * \
1960 builtin_builder::_##NAME(const glsl_type *type) \
1961 { \
1962 return unop(&AVAIL, OPCODE, type, type); \
1963 }
1964
1965 ir_function_signature *
1966 builtin_builder::binop(ir_expression_operation opcode,
1967 builtin_available_predicate avail,
1968 const glsl_type *return_type,
1969 const glsl_type *param0_type,
1970 const glsl_type *param1_type)
1971 {
1972 ir_variable *x = in_var(param0_type, "x");
1973 ir_variable *y = in_var(param1_type, "y");
1974 MAKE_SIG(return_type, avail, 2, x, y);
1975 body.emit(ret(expr(opcode, x, y)));
1976 return sig;
1977 }
1978
1979 #define BINOP(NAME, OPCODE, AVAIL) \
1980 ir_function_signature * \
1981 builtin_builder::_##NAME(const glsl_type *return_type, \
1982 const glsl_type *param0_type, \
1983 const glsl_type *param1_type) \
1984 { \
1985 return binop(&AVAIL, OPCODE, return_type, param0_type, param1_type); \
1986 }
1987
1988 /**
1989 * Angle and Trigonometry Functions @{
1990 */
1991
1992 ir_function_signature *
1993 builtin_builder::_radians(const glsl_type *type)
1994 {
1995 ir_variable *degrees = in_var(type, "degrees");
1996 MAKE_SIG(type, always_available, 1, degrees);
1997 body.emit(ret(mul(degrees, imm(0.0174532925f))));
1998 return sig;
1999 }
2000
2001 ir_function_signature *
2002 builtin_builder::_degrees(const glsl_type *type)
2003 {
2004 ir_variable *radians = in_var(type, "radians");
2005 MAKE_SIG(type, always_available, 1, radians);
2006 body.emit(ret(mul(radians, imm(57.29578f))));
2007 return sig;
2008 }
2009
2010 UNOP(sin, ir_unop_sin, always_available)
2011 UNOP(cos, ir_unop_cos, always_available)
2012
2013 ir_function_signature *
2014 builtin_builder::_tan(const glsl_type *type)
2015 {
2016 ir_variable *theta = in_var(type, "theta");
2017 MAKE_SIG(type, always_available, 1, theta);
2018 body.emit(ret(div(sin(theta), cos(theta))));
2019 return sig;
2020 }
2021
2022 ir_expression *
2023 builtin_builder::asin_expr(ir_variable *x)
2024 {
2025 return mul(sign(x),
2026 sub(imm(1.5707964f),
2027 mul(sqrt(sub(imm(1.0f), abs(x))),
2028 add(imm(1.5707964f),
2029 mul(abs(x),
2030 add(imm(-0.21460183f),
2031 mul(abs(x),
2032 add(imm(0.086566724f),
2033 mul(abs(x), imm(-0.03102955f))))))))));
2034 }
2035
2036
2037 ir_function_signature *
2038 builtin_builder::_asin(const glsl_type *type)
2039 {
2040 ir_variable *x = in_var(type, "x");
2041 MAKE_SIG(type, always_available, 1, x);
2042
2043 body.emit(ret(asin_expr(x)));
2044
2045 return sig;
2046 }
2047
2048 ir_function_signature *
2049 builtin_builder::_acos(const glsl_type *type)
2050 {
2051 ir_variable *x = in_var(type, "x");
2052 MAKE_SIG(type, always_available, 1, x);
2053
2054 body.emit(ret(sub(imm(1.5707964f), asin_expr(x))));
2055
2056 return sig;
2057 }
2058
2059 ir_function_signature *
2060 builtin_builder::_atan2(const glsl_type *type)
2061 {
2062 ir_variable *vec_y = in_var(type, "vec_y");
2063 ir_variable *vec_x = in_var(type, "vec_x");
2064 MAKE_SIG(type, always_available, 2, vec_y, vec_x);
2065
2066 ir_variable *vec_result = body.make_temp(type, "vec_result");
2067 ir_variable *r = body.make_temp(glsl_type::float_type, "r");
2068 for (int i = 0; i < type->vector_elements; i++) {
2069 ir_variable *y = body.make_temp(glsl_type::float_type, "y");
2070 ir_variable *x = body.make_temp(glsl_type::float_type, "x");
2071 body.emit(assign(y, swizzle(vec_y, i, 1)));
2072 body.emit(assign(x, swizzle(vec_x, i, 1)));
2073
2074 /* If |x| >= 1.0e-8 * |y|: */
2075 ir_if *outer_if =
2076 new(mem_ctx) ir_if(greater(abs(x), mul(imm(1.0e-8f), abs(y))));
2077
2078 ir_factory outer_then(&outer_if->then_instructions, mem_ctx);
2079
2080 /* Then...call atan(y/x) */
2081 ir_variable *y_over_x = outer_then.make_temp(glsl_type::float_type, "y_over_x");
2082 outer_then.emit(assign(y_over_x, div(y, x)));
2083 outer_then.emit(assign(r, mul(y_over_x, rsq(add(mul(y_over_x, y_over_x),
2084 imm(1.0f))))));
2085 outer_then.emit(assign(r, asin_expr(r)));
2086
2087 /* ...and fix it up: */
2088 ir_if *inner_if = new(mem_ctx) ir_if(less(x, imm(0.0f)));
2089 inner_if->then_instructions.push_tail(
2090 if_tree(gequal(y, imm(0.0f)),
2091 assign(r, add(r, imm(3.141593f))),
2092 assign(r, sub(r, imm(3.141593f)))));
2093 outer_then.emit(inner_if);
2094
2095 /* Else... */
2096 outer_if->else_instructions.push_tail(
2097 assign(r, mul(sign(y), imm(1.5707965f))));
2098
2099 body.emit(outer_if);
2100
2101 body.emit(assign(vec_result, r, 1 << i));
2102 }
2103 body.emit(ret(vec_result));
2104
2105 return sig;
2106 }
2107
2108 ir_function_signature *
2109 builtin_builder::_atan(const glsl_type *type)
2110 {
2111 ir_variable *y_over_x = in_var(type, "y_over_x");
2112 MAKE_SIG(type, always_available, 1, y_over_x);
2113
2114 ir_variable *t = body.make_temp(type, "t");
2115 body.emit(assign(t, mul(y_over_x, rsq(add(mul(y_over_x, y_over_x),
2116 imm(1.0f))))));
2117
2118 body.emit(ret(asin_expr(t)));
2119
2120 return sig;
2121 }
2122
2123 ir_function_signature *
2124 builtin_builder::_sinh(const glsl_type *type)
2125 {
2126 ir_variable *x = in_var(type, "x");
2127 MAKE_SIG(type, v130, 1, x);
2128
2129 /* 0.5 * (e^x - e^(-x)) */
2130 body.emit(ret(mul(imm(0.5f), sub(exp(x), exp(neg(x))))));
2131
2132 return sig;
2133 }
2134
2135 ir_function_signature *
2136 builtin_builder::_cosh(const glsl_type *type)
2137 {
2138 ir_variable *x = in_var(type, "x");
2139 MAKE_SIG(type, v130, 1, x);
2140
2141 /* 0.5 * (e^x + e^(-x)) */
2142 body.emit(ret(mul(imm(0.5f), add(exp(x), exp(neg(x))))));
2143
2144 return sig;
2145 }
2146
2147 ir_function_signature *
2148 builtin_builder::_tanh(const glsl_type *type)
2149 {
2150 ir_variable *x = in_var(type, "x");
2151 MAKE_SIG(type, v130, 1, x);
2152
2153 /* (e^x - e^(-x)) / (e^x + e^(-x)) */
2154 body.emit(ret(div(sub(exp(x), exp(neg(x))),
2155 add(exp(x), exp(neg(x))))));
2156
2157 return sig;
2158 }
2159
2160 ir_function_signature *
2161 builtin_builder::_asinh(const glsl_type *type)
2162 {
2163 ir_variable *x = in_var(type, "x");
2164 MAKE_SIG(type, v130, 1, x);
2165
2166 body.emit(ret(mul(sign(x), log(add(abs(x), sqrt(add(mul(x, x),
2167 imm(1.0f))))))));
2168 return sig;
2169 }
2170
2171 ir_function_signature *
2172 builtin_builder::_acosh(const glsl_type *type)
2173 {
2174 ir_variable *x = in_var(type, "x");
2175 MAKE_SIG(type, v130, 1, x);
2176
2177 body.emit(ret(log(add(x, sqrt(sub(mul(x, x), imm(1.0f)))))));
2178 return sig;
2179 }
2180
2181 ir_function_signature *
2182 builtin_builder::_atanh(const glsl_type *type)
2183 {
2184 ir_variable *x = in_var(type, "x");
2185 MAKE_SIG(type, v130, 1, x);
2186
2187 body.emit(ret(mul(imm(0.5f), log(div(add(imm(1.0f), x),
2188 sub(imm(1.0f), x))))));
2189 return sig;
2190 }
2191 /** @} */
2192
2193 /**
2194 * Exponential Functions @{
2195 */
2196
2197 ir_function_signature *
2198 builtin_builder::_pow(const glsl_type *type)
2199 {
2200 return binop(ir_binop_pow, always_available, type, type, type);
2201 }
2202
2203 UNOP(exp, ir_unop_exp, always_available)
2204 UNOP(log, ir_unop_log, always_available)
2205 UNOP(exp2, ir_unop_exp2, always_available)
2206 UNOP(log2, ir_unop_log2, always_available)
2207 UNOP(sqrt, ir_unop_sqrt, always_available)
2208 UNOP(inversesqrt, ir_unop_rsq, always_available)
2209
2210 /** @} */
2211
2212 UNOP(abs, ir_unop_abs, always_available)
2213 UNOP(sign, ir_unop_sign, always_available)
2214 UNOP(floor, ir_unop_floor, always_available)
2215 UNOP(trunc, ir_unop_trunc, v130)
2216 UNOP(round, ir_unop_round_even, always_available)
2217 UNOP(roundEven, ir_unop_round_even, always_available)
2218 UNOP(ceil, ir_unop_ceil, always_available)
2219 UNOP(fract, ir_unop_fract, always_available)
2220
2221 ir_function_signature *
2222 builtin_builder::_mod(const glsl_type *x_type, const glsl_type *y_type)
2223 {
2224 return binop(ir_binop_mod, always_available, x_type, x_type, y_type);
2225 }
2226
2227 ir_function_signature *
2228 builtin_builder::_modf(const glsl_type *type)
2229 {
2230 ir_variable *x = in_var(type, "x");
2231 ir_variable *i = out_var(type, "i");
2232 MAKE_SIG(type, v130, 2, x, i);
2233
2234 ir_variable *t = body.make_temp(type, "t");
2235 body.emit(assign(t, expr(ir_unop_trunc, x)));
2236 body.emit(assign(i, t));
2237 body.emit(ret(sub(x, t)));
2238
2239 return sig;
2240 }
2241
2242 ir_function_signature *
2243 builtin_builder::_min(builtin_available_predicate avail,
2244 const glsl_type *x_type, const glsl_type *y_type)
2245 {
2246 return binop(ir_binop_min, avail, x_type, x_type, y_type);
2247 }
2248
2249 ir_function_signature *
2250 builtin_builder::_max(builtin_available_predicate avail,
2251 const glsl_type *x_type, const glsl_type *y_type)
2252 {
2253 return binop(ir_binop_max, avail, x_type, x_type, y_type);
2254 }
2255
2256 ir_function_signature *
2257 builtin_builder::_clamp(builtin_available_predicate avail,
2258 const glsl_type *val_type, const glsl_type *bound_type)
2259 {
2260 ir_variable *x = in_var(val_type, "x");
2261 ir_variable *minVal = in_var(bound_type, "minVal");
2262 ir_variable *maxVal = in_var(bound_type, "maxVal");
2263 MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
2264
2265 body.emit(ret(clamp(x, minVal, maxVal)));
2266
2267 return sig;
2268 }
2269
2270 ir_function_signature *
2271 builtin_builder::_mix_lrp(const glsl_type *val_type, const glsl_type *blend_type)
2272 {
2273 ir_variable *x = in_var(val_type, "x");
2274 ir_variable *y = in_var(val_type, "y");
2275 ir_variable *a = in_var(blend_type, "a");
2276 MAKE_SIG(val_type, always_available, 3, x, y, a);
2277
2278 body.emit(ret(lrp(x, y, a)));
2279
2280 return sig;
2281 }
2282
2283 ir_function_signature *
2284 builtin_builder::_mix_sel(builtin_available_predicate avail,
2285 const glsl_type *val_type,
2286 const glsl_type *blend_type)
2287 {
2288 ir_variable *x = in_var(val_type, "x");
2289 ir_variable *y = in_var(val_type, "y");
2290 ir_variable *a = in_var(blend_type, "a");
2291 MAKE_SIG(val_type, avail, 3, x, y, a);
2292
2293 /* csel matches the ternary operator in that a selector of true choses the
2294 * first argument. This differs from mix(x, y, false) which choses the
2295 * second argument (to remain consistent with the interpolating version of
2296 * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
2297 *
2298 * To handle the behavior mismatch, reverse the x and y arguments.
2299 */
2300 body.emit(ret(csel(a, y, x)));
2301
2302 return sig;
2303 }
2304
2305 ir_function_signature *
2306 builtin_builder::_step(const glsl_type *edge_type, const glsl_type *x_type)
2307 {
2308 ir_variable *edge = in_var(edge_type, "edge");
2309 ir_variable *x = in_var(x_type, "x");
2310 MAKE_SIG(x_type, always_available, 2, edge, x);
2311
2312 ir_variable *t = body.make_temp(x_type, "t");
2313 if (x_type->vector_elements == 1) {
2314 /* Both are floats */
2315 body.emit(assign(t, b2f(gequal(x, edge))));
2316 } else if (edge_type->vector_elements == 1) {
2317 /* x is a vector but edge is a float */
2318 for (int i = 0; i < x_type->vector_elements; i++) {
2319 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
2320 }
2321 } else {
2322 /* Both are vectors */
2323 for (int i = 0; i < x_type->vector_elements; i++) {
2324 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
2325 1 << i));
2326 }
2327 }
2328 body.emit(ret(t));
2329
2330 return sig;
2331 }
2332
2333 ir_function_signature *
2334 builtin_builder::_smoothstep(const glsl_type *edge_type, const glsl_type *x_type)
2335 {
2336 ir_variable *edge0 = in_var(edge_type, "edge0");
2337 ir_variable *edge1 = in_var(edge_type, "edge1");
2338 ir_variable *x = in_var(x_type, "x");
2339 MAKE_SIG(x_type, always_available, 3, edge0, edge1, x);
2340
2341 /* From the GLSL 1.10 specification:
2342 *
2343 * genType t;
2344 * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
2345 * return t * t * (3 - 2 * t);
2346 */
2347
2348 ir_variable *t = body.make_temp(x_type, "t");
2349 body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
2350 imm(0.0f), imm(1.0f))));
2351
2352 body.emit(ret(mul(t, mul(t, sub(imm(3.0f), mul(imm(2.0f), t))))));
2353
2354 return sig;
2355 }
2356
2357 ir_function_signature *
2358 builtin_builder::_isnan(const glsl_type *type)
2359 {
2360 ir_variable *x = in_var(type, "x");
2361 MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
2362
2363 body.emit(ret(nequal(x, x)));
2364
2365 return sig;
2366 }
2367
2368 ir_function_signature *
2369 builtin_builder::_isinf(const glsl_type *type)
2370 {
2371 ir_variable *x = in_var(type, "x");
2372 MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
2373
2374 ir_constant_data infinities;
2375 for (int i = 0; i < type->vector_elements; i++) {
2376 infinities.f[i] = std::numeric_limits<float>::infinity();
2377 }
2378
2379 body.emit(ret(equal(abs(x), imm(type, infinities))));
2380
2381 return sig;
2382 }
2383
2384 ir_function_signature *
2385 builtin_builder::_floatBitsToInt(const glsl_type *type)
2386 {
2387 ir_variable *x = in_var(type, "x");
2388 MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
2389 body.emit(ret(bitcast_f2i(x)));
2390 return sig;
2391 }
2392
2393 ir_function_signature *
2394 builtin_builder::_floatBitsToUint(const glsl_type *type)
2395 {
2396 ir_variable *x = in_var(type, "x");
2397 MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
2398 body.emit(ret(bitcast_f2u(x)));
2399 return sig;
2400 }
2401
2402 ir_function_signature *
2403 builtin_builder::_intBitsToFloat(const glsl_type *type)
2404 {
2405 ir_variable *x = in_var(type, "x");
2406 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
2407 body.emit(ret(bitcast_i2f(x)));
2408 return sig;
2409 }
2410
2411 ir_function_signature *
2412 builtin_builder::_uintBitsToFloat(const glsl_type *type)
2413 {
2414 ir_variable *x = in_var(type, "x");
2415 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
2416 body.emit(ret(bitcast_u2f(x)));
2417 return sig;
2418 }
2419
2420 ir_function_signature *
2421 builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
2422 {
2423 ir_variable *v = in_var(glsl_type::vec2_type, "v");
2424 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
2425 body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
2426 return sig;
2427 }
2428
2429 ir_function_signature *
2430 builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
2431 {
2432 ir_variable *v = in_var(glsl_type::vec2_type, "v");
2433 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
2434 body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
2435 return sig;
2436 }
2437
2438 ir_function_signature *
2439 builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
2440 {
2441 ir_variable *v = in_var(glsl_type::vec4_type, "v");
2442 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
2443 body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
2444 return sig;
2445 }
2446
2447 ir_function_signature *
2448 builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
2449 {
2450 ir_variable *v = in_var(glsl_type::vec4_type, "v");
2451 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
2452 body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
2453 return sig;
2454 }
2455
2456 ir_function_signature *
2457 builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
2458 {
2459 ir_variable *p = in_var(glsl_type::uint_type, "p");
2460 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
2461 body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
2462 return sig;
2463 }
2464
2465 ir_function_signature *
2466 builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
2467 {
2468 ir_variable *p = in_var(glsl_type::uint_type, "p");
2469 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
2470 body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
2471 return sig;
2472 }
2473
2474
2475 ir_function_signature *
2476 builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
2477 {
2478 ir_variable *p = in_var(glsl_type::uint_type, "p");
2479 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
2480 body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
2481 return sig;
2482 }
2483
2484 ir_function_signature *
2485 builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
2486 {
2487 ir_variable *p = in_var(glsl_type::uint_type, "p");
2488 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
2489 body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
2490 return sig;
2491 }
2492
2493 ir_function_signature *
2494 builtin_builder::_packHalf2x16(builtin_available_predicate avail)
2495 {
2496 ir_variable *v = in_var(glsl_type::vec2_type, "v");
2497 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
2498 body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
2499 return sig;
2500 }
2501
2502 ir_function_signature *
2503 builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
2504 {
2505 ir_variable *p = in_var(glsl_type::uint_type, "p");
2506 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
2507 body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
2508 return sig;
2509 }
2510
2511 ir_function_signature *
2512 builtin_builder::_length(const glsl_type *type)
2513 {
2514 ir_variable *x = in_var(type, "x");
2515 MAKE_SIG(glsl_type::float_type, always_available, 1, x);
2516
2517 body.emit(ret(sqrt(dotlike(x, x))));
2518
2519 return sig;
2520 }
2521
2522 ir_function_signature *
2523 builtin_builder::_distance(const glsl_type *type)
2524 {
2525 ir_variable *p0 = in_var(type, "p0");
2526 ir_variable *p1 = in_var(type, "p1");
2527 MAKE_SIG(glsl_type::float_type, always_available, 2, p0, p1);
2528
2529 if (type->vector_elements == 1) {
2530 body.emit(ret(abs(sub(p0, p1))));
2531 } else {
2532 ir_variable *p = body.make_temp(type, "p");
2533 body.emit(assign(p, sub(p0, p1)));
2534 body.emit(ret(sqrt(dot(p, p))));
2535 }
2536
2537 return sig;
2538 }
2539
2540 ir_function_signature *
2541 builtin_builder::_dot(const glsl_type *type)
2542 {
2543 if (type->vector_elements == 1)
2544 return binop(ir_binop_mul, always_available, type, type, type);
2545
2546 return binop(ir_binop_dot, always_available,
2547 glsl_type::float_type, type, type);
2548 }
2549
2550 ir_function_signature *
2551 builtin_builder::_cross(const glsl_type *type)
2552 {
2553 ir_variable *a = in_var(type, "a");
2554 ir_variable *b = in_var(type, "b");
2555 MAKE_SIG(type, always_available, 2, a, b);
2556
2557 int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
2558 int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
2559
2560 body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
2561 mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
2562
2563 return sig;
2564 }
2565
2566 ir_function_signature *
2567 builtin_builder::_normalize(const glsl_type *type)
2568 {
2569 ir_variable *x = in_var(type, "x");
2570 MAKE_SIG(type, always_available, 1, x);
2571
2572 if (type->vector_elements == 1) {
2573 body.emit(ret(sign(x)));
2574 } else {
2575 body.emit(ret(mul(x, rsq(dot(x, x)))));
2576 }
2577
2578 return sig;
2579 }
2580
2581 ir_function_signature *
2582 builtin_builder::_ftransform()
2583 {
2584 MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
2585
2586 body.emit(ret(new(mem_ctx) ir_expression(ir_binop_mul,
2587 glsl_type::vec4_type,
2588 var_ref(gl_ModelViewProjectionMatrix),
2589 var_ref(gl_Vertex))));
2590
2591 /* FINISHME: Once the ir_expression() constructor handles type inference
2592 * for matrix operations, we can simplify this to:
2593 *
2594 * body.emit(ret(mul(gl_ModelViewProjectionMatrix, gl_Vertex)));
2595 */
2596 return sig;
2597 }
2598
2599 ir_function_signature *
2600 builtin_builder::_faceforward(const glsl_type *type)
2601 {
2602 ir_variable *N = in_var(type, "N");
2603 ir_variable *I = in_var(type, "I");
2604 ir_variable *Nref = in_var(type, "Nref");
2605 MAKE_SIG(type, always_available, 3, N, I, Nref);
2606
2607 body.emit(if_tree(less(dotlike(Nref, I), imm(0.0f)),
2608 ret(N), ret(neg(N))));
2609
2610 return sig;
2611 }
2612
2613 ir_function_signature *
2614 builtin_builder::_reflect(const glsl_type *type)
2615 {
2616 ir_variable *I = in_var(type, "I");
2617 ir_variable *N = in_var(type, "N");
2618 MAKE_SIG(type, always_available, 2, I, N);
2619
2620 /* I - 2 * dot(N, I) * N */
2621 body.emit(ret(sub(I, mul(imm(2.0f), mul(dotlike(N, I), N)))));
2622
2623 return sig;
2624 }
2625
2626 ir_function_signature *
2627 builtin_builder::_refract(const glsl_type *type)
2628 {
2629 ir_variable *I = in_var(type, "I");
2630 ir_variable *N = in_var(type, "N");
2631 ir_variable *eta = in_var(glsl_type::float_type, "eta");
2632 MAKE_SIG(type, always_available, 3, I, N, eta);
2633
2634 ir_variable *n_dot_i = body.make_temp(glsl_type::float_type, "n_dot_i");
2635 body.emit(assign(n_dot_i, dotlike(N, I)));
2636
2637 /* From the GLSL 1.10 specification:
2638 * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
2639 * if (k < 0.0)
2640 * return genType(0.0)
2641 * else
2642 * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
2643 */
2644 ir_variable *k = body.make_temp(glsl_type::float_type, "k");
2645 body.emit(assign(k, sub(imm(1.0f),
2646 mul(eta, mul(eta, sub(imm(1.0f),
2647 mul(n_dot_i, n_dot_i)))))));
2648 body.emit(if_tree(less(k, imm(0.0f)),
2649 ret(ir_constant::zero(mem_ctx, type)),
2650 ret(sub(mul(eta, I),
2651 mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
2652
2653 return sig;
2654 }
2655
2656 ir_function_signature *
2657 builtin_builder::_matrixCompMult(const glsl_type *type)
2658 {
2659 ir_variable *x = in_var(type, "x");
2660 ir_variable *y = in_var(type, "y");
2661 MAKE_SIG(type, always_available, 2, x, y);
2662
2663 ir_variable *z = body.make_temp(type, "z");
2664 for (int i = 0; i < type->matrix_columns; i++) {
2665 body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
2666 }
2667 body.emit(ret(z));
2668
2669 return sig;
2670 }
2671
2672 ir_function_signature *
2673 builtin_builder::_outerProduct(const glsl_type *type)
2674 {
2675 ir_variable *c = in_var(glsl_type::vec(type->vector_elements), "c");
2676 ir_variable *r = in_var(glsl_type::vec(type->matrix_columns), "r");
2677 MAKE_SIG(type, v120, 2, c, r);
2678
2679 ir_variable *m = body.make_temp(type, "m");
2680 for (int i = 0; i < type->matrix_columns; i++) {
2681 body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
2682 }
2683 body.emit(ret(m));
2684
2685 return sig;
2686 }
2687
2688 ir_function_signature *
2689 builtin_builder::_transpose(const glsl_type *orig_type)
2690 {
2691 const glsl_type *transpose_type =
2692 glsl_type::get_instance(GLSL_TYPE_FLOAT,
2693 orig_type->matrix_columns,
2694 orig_type->vector_elements);
2695
2696 ir_variable *m = in_var(orig_type, "m");
2697 MAKE_SIG(transpose_type, v120, 1, m);
2698
2699 ir_variable *t = body.make_temp(transpose_type, "t");
2700 for (int i = 0; i < orig_type->matrix_columns; i++) {
2701 for (int j = 0; j < orig_type->vector_elements; j++) {
2702 body.emit(assign(array_ref(t, j),
2703 matrix_elt(m, i, j),
2704 1 << i));
2705 }
2706 }
2707 body.emit(ret(t));
2708
2709 return sig;
2710 }
2711
2712 ir_function_signature *
2713 builtin_builder::_determinant_mat2()
2714 {
2715 ir_variable *m = in_var(glsl_type::mat2_type, "m");
2716 MAKE_SIG(glsl_type::float_type, v120, 1, m);
2717
2718 body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
2719 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
2720
2721 return sig;
2722 }
2723
2724 ir_function_signature *
2725 builtin_builder::_determinant_mat3()
2726 {
2727 ir_variable *m = in_var(glsl_type::mat3_type, "m");
2728 MAKE_SIG(glsl_type::float_type, v120, 1, m);
2729
2730 ir_expression *f1 =
2731 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
2732 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
2733
2734 ir_expression *f2 =
2735 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
2736 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
2737
2738 ir_expression *f3 =
2739 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
2740 mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
2741
2742 body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
2743 mul(matrix_elt(m, 0, 1), f2)),
2744 mul(matrix_elt(m, 0, 2), f3))));
2745
2746 return sig;
2747 }
2748
2749 ir_function_signature *
2750 builtin_builder::_determinant_mat4()
2751 {
2752 ir_variable *m = in_var(glsl_type::mat4_type, "m");
2753 MAKE_SIG(glsl_type::float_type, v120, 1, m);
2754
2755 ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
2756 ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
2757 ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
2758 ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
2759 ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
2760 ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
2761 ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
2762 ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
2763 ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
2764 ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
2765 ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
2766 ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
2767 ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
2768 ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
2769 ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
2770 ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
2771 ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
2772 ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
2773 ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
2774
2775 body.emit(assign(SubFactor00, sub(mul(matrix_elt(m, 2, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 2, 3)))));
2776 body.emit(assign(SubFactor01, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 3)))));
2777 body.emit(assign(SubFactor02, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 2)))));
2778 body.emit(assign(SubFactor03, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 3)))));
2779 body.emit(assign(SubFactor04, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 2)))));
2780 body.emit(assign(SubFactor05, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 1)))));
2781 body.emit(assign(SubFactor06, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 1, 3)))));
2782 body.emit(assign(SubFactor07, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
2783 body.emit(assign(SubFactor08, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 2)))));
2784 body.emit(assign(SubFactor09, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 3)))));
2785 body.emit(assign(SubFactor10, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 2)))));
2786 body.emit(assign(SubFactor11, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
2787 body.emit(assign(SubFactor12, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 1)))));
2788 body.emit(assign(SubFactor13, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 2), matrix_elt(m, 1, 3)))));
2789 body.emit(assign(SubFactor14, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 3)))));
2790 body.emit(assign(SubFactor15, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
2791 body.emit(assign(SubFactor16, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 3)))));
2792 body.emit(assign(SubFactor17, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
2793 body.emit(assign(SubFactor18, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
2794
2795 ir_variable *adj_0 = body.make_temp(glsl_type::vec4_type, "adj_0");
2796
2797 body.emit(assign(adj_0,
2798 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
2799 mul(matrix_elt(m, 1, 2), SubFactor01)),
2800 mul(matrix_elt(m, 1, 3), SubFactor02)),
2801 WRITEMASK_X));
2802 body.emit(assign(adj_0, neg(
2803 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
2804 mul(matrix_elt(m, 1, 2), SubFactor03)),
2805 mul(matrix_elt(m, 1, 3), SubFactor04))),
2806 WRITEMASK_Y));
2807 body.emit(assign(adj_0,
2808 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
2809 mul(matrix_elt(m, 1, 1), SubFactor03)),
2810 mul(matrix_elt(m, 1, 3), SubFactor05)),
2811 WRITEMASK_Z));
2812 body.emit(assign(adj_0, neg(
2813 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
2814 mul(matrix_elt(m, 1, 1), SubFactor04)),
2815 mul(matrix_elt(m, 1, 2), SubFactor05))),
2816 WRITEMASK_W));
2817
2818 body.emit(ret(dot(array_ref(m, 0), adj_0)));
2819
2820 return sig;
2821 }
2822
2823 ir_function_signature *
2824 builtin_builder::_inverse_mat2()
2825 {
2826 ir_variable *m = in_var(glsl_type::mat2_type, "m");
2827 MAKE_SIG(glsl_type::mat2_type, v120, 1, m);
2828
2829 ir_variable *adj = body.make_temp(glsl_type::mat2_type, "adj");
2830 body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
2831 body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
2832 body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
2833 body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
2834
2835 ir_expression *det =
2836 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
2837 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
2838
2839 body.emit(ret(div(adj, det)));
2840 return sig;
2841 }
2842
2843 ir_function_signature *
2844 builtin_builder::_inverse_mat3()
2845 {
2846 ir_variable *m = in_var(glsl_type::mat3_type, "m");
2847 MAKE_SIG(glsl_type::mat3_type, v120, 1, m);
2848
2849 ir_variable *f11_22_21_12 = body.make_temp(glsl_type::float_type, "f11_22_21_12");
2850 ir_variable *f10_22_20_12 = body.make_temp(glsl_type::float_type, "f10_22_20_12");
2851 ir_variable *f10_21_20_11 = body.make_temp(glsl_type::float_type, "f10_21_20_11");
2852
2853 body.emit(assign(f11_22_21_12,
2854 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
2855 mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
2856 body.emit(assign(f10_22_20_12,
2857 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
2858 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
2859 body.emit(assign(f10_21_20_11,
2860 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
2861 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
2862
2863 ir_variable *adj = body.make_temp(glsl_type::mat3_type, "adj");
2864 body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
2865 body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
2866 body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
2867
2868 body.emit(assign(array_ref(adj, 0), neg(
2869 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
2870 mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
2871 WRITEMASK_Y));
2872 body.emit(assign(array_ref(adj, 1),
2873 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
2874 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
2875 WRITEMASK_Y));
2876 body.emit(assign(array_ref(adj, 2), neg(
2877 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
2878 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
2879 WRITEMASK_Y));
2880
2881 body.emit(assign(array_ref(adj, 0),
2882 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
2883 mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
2884 WRITEMASK_Z));
2885 body.emit(assign(array_ref(adj, 1), neg(
2886 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
2887 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
2888 WRITEMASK_Z));
2889 body.emit(assign(array_ref(adj, 2),
2890 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
2891 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
2892 WRITEMASK_Z));
2893
2894 ir_expression *det =
2895 add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
2896 mul(matrix_elt(m, 0, 1), f10_22_20_12)),
2897 mul(matrix_elt(m, 0, 2), f10_21_20_11));
2898
2899 body.emit(ret(div(adj, det)));
2900
2901 return sig;
2902 }
2903
2904 ir_function_signature *
2905 builtin_builder::_inverse_mat4()
2906 {
2907 ir_variable *m = in_var(glsl_type::mat4_type, "m");
2908 MAKE_SIG(glsl_type::mat4_type, v120, 1, m);
2909
2910 ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
2911 ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
2912 ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
2913 ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
2914 ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
2915 ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
2916 ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
2917 ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
2918 ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
2919 ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
2920 ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
2921 ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
2922 ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
2923 ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
2924 ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
2925 ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
2926 ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
2927 ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
2928 ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
2929
2930 body.emit(assign(SubFactor00, sub(mul(matrix_elt(m, 2, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 2, 3)))));
2931 body.emit(assign(SubFactor01, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 3)))));
2932 body.emit(assign(SubFactor02, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 2)))));
2933 body.emit(assign(SubFactor03, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 3)))));
2934 body.emit(assign(SubFactor04, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 2)))));
2935 body.emit(assign(SubFactor05, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 1)))));
2936 body.emit(assign(SubFactor06, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 1, 3)))));
2937 body.emit(assign(SubFactor07, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
2938 body.emit(assign(SubFactor08, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 2)))));
2939 body.emit(assign(SubFactor09, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 3)))));
2940 body.emit(assign(SubFactor10, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 2)))));
2941 body.emit(assign(SubFactor11, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
2942 body.emit(assign(SubFactor12, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 1)))));
2943 body.emit(assign(SubFactor13, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 2), matrix_elt(m, 1, 3)))));
2944 body.emit(assign(SubFactor14, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 3)))));
2945 body.emit(assign(SubFactor15, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
2946 body.emit(assign(SubFactor16, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 3)))));
2947 body.emit(assign(SubFactor17, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
2948 body.emit(assign(SubFactor18, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
2949
2950 ir_variable *adj = body.make_temp(glsl_type::mat4_type, "adj");
2951 body.emit(assign(array_ref(adj, 0),
2952 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
2953 mul(matrix_elt(m, 1, 2), SubFactor01)),
2954 mul(matrix_elt(m, 1, 3), SubFactor02)),
2955 WRITEMASK_X));
2956 body.emit(assign(array_ref(adj, 1), neg(
2957 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
2958 mul(matrix_elt(m, 1, 2), SubFactor03)),
2959 mul(matrix_elt(m, 1, 3), SubFactor04))),
2960 WRITEMASK_X));
2961 body.emit(assign(array_ref(adj, 2),
2962 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
2963 mul(matrix_elt(m, 1, 1), SubFactor03)),
2964 mul(matrix_elt(m, 1, 3), SubFactor05)),
2965 WRITEMASK_X));
2966 body.emit(assign(array_ref(adj, 3), neg(
2967 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
2968 mul(matrix_elt(m, 1, 1), SubFactor04)),
2969 mul(matrix_elt(m, 1, 2), SubFactor05))),
2970 WRITEMASK_X));
2971
2972 body.emit(assign(array_ref(adj, 0), neg(
2973 add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
2974 mul(matrix_elt(m, 0, 2), SubFactor01)),
2975 mul(matrix_elt(m, 0, 3), SubFactor02))),
2976 WRITEMASK_Y));
2977 body.emit(assign(array_ref(adj, 1),
2978 add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
2979 mul(matrix_elt(m, 0, 2), SubFactor03)),
2980 mul(matrix_elt(m, 0, 3), SubFactor04)),
2981 WRITEMASK_Y));
2982 body.emit(assign(array_ref(adj, 2), neg(
2983 add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
2984 mul(matrix_elt(m, 0, 1), SubFactor03)),
2985 mul(matrix_elt(m, 0, 3), SubFactor05))),
2986 WRITEMASK_Y));
2987 body.emit(assign(array_ref(adj, 3),
2988 add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
2989 mul(matrix_elt(m, 0, 1), SubFactor04)),
2990 mul(matrix_elt(m, 0, 2), SubFactor05)),
2991 WRITEMASK_Y));
2992
2993 body.emit(assign(array_ref(adj, 0),
2994 add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
2995 mul(matrix_elt(m, 0, 2), SubFactor07)),
2996 mul(matrix_elt(m, 0, 3), SubFactor08)),
2997 WRITEMASK_Z));
2998 body.emit(assign(array_ref(adj, 1), neg(
2999 add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
3000 mul(matrix_elt(m, 0, 2), SubFactor09)),
3001 mul(matrix_elt(m, 0, 3), SubFactor10))),
3002 WRITEMASK_Z));
3003 body.emit(assign(array_ref(adj, 2),
3004 add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
3005 mul(matrix_elt(m, 0, 1), SubFactor09)),
3006 mul(matrix_elt(m, 0, 3), SubFactor12)),
3007 WRITEMASK_Z));
3008 body.emit(assign(array_ref(adj, 3), neg(
3009 add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
3010 mul(matrix_elt(m, 0, 1), SubFactor10)),
3011 mul(matrix_elt(m, 0, 2), SubFactor12))),
3012 WRITEMASK_Z));
3013
3014 body.emit(assign(array_ref(adj, 0), neg(
3015 add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
3016 mul(matrix_elt(m, 0, 2), SubFactor14)),
3017 mul(matrix_elt(m, 0, 3), SubFactor15))),
3018 WRITEMASK_W));
3019 body.emit(assign(array_ref(adj, 1),
3020 add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
3021 mul(matrix_elt(m, 0, 2), SubFactor16)),
3022 mul(matrix_elt(m, 0, 3), SubFactor17)),
3023 WRITEMASK_W));
3024 body.emit(assign(array_ref(adj, 2), neg(
3025 add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
3026 mul(matrix_elt(m, 0, 1), SubFactor16)),
3027 mul(matrix_elt(m, 0, 3), SubFactor18))),
3028 WRITEMASK_W));
3029 body.emit(assign(array_ref(adj, 3),
3030 add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
3031 mul(matrix_elt(m, 0, 1), SubFactor17)),
3032 mul(matrix_elt(m, 0, 2), SubFactor18)),
3033 WRITEMASK_W));
3034
3035 ir_expression *det =
3036 add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
3037 add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
3038 add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
3039 mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
3040
3041 body.emit(ret(div(adj, det)));
3042
3043 return sig;
3044 }
3045
3046
3047 ir_function_signature *
3048 builtin_builder::_lessThan(builtin_available_predicate avail,
3049 const glsl_type *type)
3050 {
3051 return binop(ir_binop_less, avail,
3052 glsl_type::bvec(type->vector_elements), type, type);
3053 }
3054
3055 ir_function_signature *
3056 builtin_builder::_lessThanEqual(builtin_available_predicate avail,
3057 const glsl_type *type)
3058 {
3059 return binop(ir_binop_lequal, avail,
3060 glsl_type::bvec(type->vector_elements), type, type);
3061 }
3062
3063 ir_function_signature *
3064 builtin_builder::_greaterThan(builtin_available_predicate avail,
3065 const glsl_type *type)
3066 {
3067 return binop(ir_binop_greater, avail,
3068 glsl_type::bvec(type->vector_elements), type, type);
3069 }
3070
3071 ir_function_signature *
3072 builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
3073 const glsl_type *type)
3074 {
3075 return binop(ir_binop_gequal, avail,
3076 glsl_type::bvec(type->vector_elements), type, type);
3077 }
3078
3079 ir_function_signature *
3080 builtin_builder::_equal(builtin_available_predicate avail,
3081 const glsl_type *type)
3082 {
3083 return binop(ir_binop_equal, avail,
3084 glsl_type::bvec(type->vector_elements), type, type);
3085 }
3086
3087 ir_function_signature *
3088 builtin_builder::_notEqual(builtin_available_predicate avail,
3089 const glsl_type *type)
3090 {
3091 return binop(ir_binop_nequal, avail,
3092 glsl_type::bvec(type->vector_elements), type, type);
3093 }
3094
3095 ir_function_signature *
3096 builtin_builder::_any(const glsl_type *type)
3097 {
3098 return unop(always_available, ir_unop_any, glsl_type::bool_type, type);
3099 }
3100
3101 ir_function_signature *
3102 builtin_builder::_all(const glsl_type *type)
3103 {
3104 ir_variable *v = in_var(type, "v");
3105 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
3106
3107 switch (type->vector_elements) {
3108 case 2:
3109 body.emit(ret(logic_and(swizzle_x(v), swizzle_y(v))));
3110 break;
3111 case 3:
3112 body.emit(ret(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
3113 swizzle_z(v))));
3114 break;
3115 case 4:
3116 body.emit(ret(logic_and(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
3117 swizzle_z(v)),
3118 swizzle_w(v))));
3119 break;
3120 }
3121
3122 return sig;
3123 }
3124
3125 UNOP(not, ir_unop_logic_not, always_available)
3126
3127 static bool
3128 has_lod(const glsl_type *sampler_type)
3129 {
3130 assert(sampler_type->is_sampler());
3131
3132 switch (sampler_type->sampler_dimensionality) {
3133 case GLSL_SAMPLER_DIM_RECT:
3134 case GLSL_SAMPLER_DIM_BUF:
3135 case GLSL_SAMPLER_DIM_MS:
3136 return false;
3137 default:
3138 return true;
3139 }
3140 }
3141
3142 ir_function_signature *
3143 builtin_builder::_textureSize(builtin_available_predicate avail,
3144 const glsl_type *return_type,
3145 const glsl_type *sampler_type)
3146 {
3147 ir_variable *s = in_var(sampler_type, "sampler");
3148 /* The sampler always exists; add optional lod later. */
3149 MAKE_SIG(return_type, avail, 1, s);
3150
3151 ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
3152 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
3153
3154 if (has_lod(sampler_type)) {
3155 ir_variable *lod = in_var(glsl_type::int_type, "lod");
3156 sig->parameters.push_tail(lod);
3157 tex->lod_info.lod = var_ref(lod);
3158 } else {
3159 tex->lod_info.lod = imm(0u);
3160 }
3161
3162 body.emit(ret(tex));
3163
3164 return sig;
3165 }
3166
3167 ir_function_signature *
3168 builtin_builder::_texture(ir_texture_opcode opcode,
3169 builtin_available_predicate avail,
3170 const glsl_type *return_type,
3171 const glsl_type *sampler_type,
3172 const glsl_type *coord_type,
3173 int flags)
3174 {
3175 ir_variable *s = in_var(sampler_type, "sampler");
3176 ir_variable *P = in_var(coord_type, "P");
3177 /* The sampler and coordinate always exist; add optional parameters later. */
3178 MAKE_SIG(return_type, avail, 2, s, P);
3179
3180 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
3181 tex->set_sampler(var_ref(s), return_type);
3182
3183 const int coord_size = sampler_type->sampler_coordinate_components();
3184
3185 if (coord_size == coord_type->vector_elements) {
3186 tex->coordinate = var_ref(P);
3187 } else {
3188 /* The incoming coordinate also has the projector or shadow comparitor,
3189 * so we need to swizzle those away.
3190 */
3191 tex->coordinate = swizzle_for_size(P, coord_size);
3192 }
3193
3194 /* The projector is always in the last component. */
3195 if (flags & TEX_PROJECT)
3196 tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
3197
3198 /* The shadow comparitor is normally in the Z component, but a few types
3199 * have sufficiently large coordinates that it's in W.
3200 */
3201 if (sampler_type->sampler_shadow)
3202 tex->shadow_comparitor = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
3203
3204 if (opcode == ir_txl) {
3205 ir_variable *lod = in_var(glsl_type::float_type, "lod");
3206 sig->parameters.push_tail(lod);
3207 tex->lod_info.lod = var_ref(lod);
3208 } else if (opcode == ir_txd) {
3209 int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
3210 ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
3211 ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
3212 sig->parameters.push_tail(dPdx);
3213 sig->parameters.push_tail(dPdy);
3214 tex->lod_info.grad.dPdx = var_ref(dPdx);
3215 tex->lod_info.grad.dPdy = var_ref(dPdy);
3216 }
3217
3218 if (flags & TEX_OFFSET) {
3219 int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
3220 ir_variable *offset =
3221 new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset", ir_var_const_in);
3222 sig->parameters.push_tail(offset);
3223 tex->offset = var_ref(offset);
3224 }
3225
3226 /* The "bias" parameter comes /after/ the "offset" parameter, which is
3227 * inconsistent with both textureLodOffset and textureGradOffset.
3228 */
3229 if (opcode == ir_txb) {
3230 ir_variable *bias = in_var(glsl_type::float_type, "bias");
3231 sig->parameters.push_tail(bias);
3232 tex->lod_info.bias = var_ref(bias);
3233 }
3234
3235 body.emit(ret(tex));
3236
3237 return sig;
3238 }
3239
3240 ir_function_signature *
3241 builtin_builder::_textureCubeArrayShadow()
3242 {
3243 ir_variable *s = in_var(glsl_type::samplerCubeArrayShadow_type, "sampler");
3244 ir_variable *P = in_var(glsl_type::vec4_type, "P");
3245 ir_variable *compare = in_var(glsl_type::float_type, "compare");
3246 MAKE_SIG(glsl_type::float_type, texture_cube_map_array, 3, s, P, compare);
3247
3248 ir_texture *tex = new(mem_ctx) ir_texture(ir_tex);
3249 tex->set_sampler(var_ref(s), glsl_type::float_type);
3250
3251 tex->coordinate = var_ref(P);
3252 tex->shadow_comparitor = var_ref(compare);
3253
3254 body.emit(ret(tex));
3255
3256 return sig;
3257 }
3258
3259 ir_function_signature *
3260 builtin_builder::_texelFetch(builtin_available_predicate avail,
3261 const glsl_type *return_type,
3262 const glsl_type *sampler_type,
3263 const glsl_type *coord_type,
3264 const glsl_type *offset_type)
3265 {
3266 ir_variable *s = in_var(sampler_type, "sampler");
3267 ir_variable *P = in_var(coord_type, "P");
3268 /* The sampler and coordinate always exist; add optional parameters later. */
3269 MAKE_SIG(return_type, avail, 2, s, P);
3270
3271 ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
3272 tex->coordinate = var_ref(P);
3273 tex->set_sampler(var_ref(s), return_type);
3274
3275 if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
3276 ir_variable *sample = in_var(glsl_type::int_type, "sample");
3277 sig->parameters.push_tail(sample);
3278 tex->lod_info.sample_index = var_ref(sample);
3279 tex->op = ir_txf_ms;
3280 } else if (has_lod(sampler_type)) {
3281 ir_variable *lod = in_var(glsl_type::int_type, "lod");
3282 sig->parameters.push_tail(lod);
3283 tex->lod_info.lod = var_ref(lod);
3284 } else {
3285 tex->lod_info.lod = imm(0u);
3286 }
3287
3288 if (offset_type != NULL) {
3289 ir_variable *offset =
3290 new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in);
3291 sig->parameters.push_tail(offset);
3292 tex->offset = var_ref(offset);
3293 }
3294
3295 body.emit(ret(tex));
3296
3297 return sig;
3298 }
3299
3300 ir_function_signature *
3301 builtin_builder::_EmitVertex()
3302 {
3303 MAKE_SIG(glsl_type::void_type, gs_only, 0);
3304
3305 body.emit(new(mem_ctx) ir_emit_vertex());
3306
3307 return sig;
3308 }
3309
3310 ir_function_signature *
3311 builtin_builder::_EndPrimitive()
3312 {
3313 MAKE_SIG(glsl_type::void_type, gs_only, 0);
3314
3315 body.emit(new(mem_ctx) ir_end_primitive());
3316
3317 return sig;
3318 }
3319
3320 ir_function_signature *
3321 builtin_builder::_textureQueryLod(const glsl_type *sampler_type,
3322 const glsl_type *coord_type)
3323 {
3324 ir_variable *s = in_var(sampler_type, "sampler");
3325 ir_variable *coord = in_var(coord_type, "coord");
3326 /* The sampler and coordinate always exist; add optional parameters later. */
3327 MAKE_SIG(glsl_type::vec2_type, texture_query_lod, 2, s, coord);
3328
3329 ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
3330 tex->coordinate = var_ref(coord);
3331 tex->set_sampler(var_ref(s), glsl_type::vec2_type);
3332
3333 body.emit(ret(tex));
3334
3335 return sig;
3336 }
3337
3338 UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
3339 UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
3340
3341 ir_function_signature *
3342 builtin_builder::_fwidth(const glsl_type *type)
3343 {
3344 ir_variable *p = in_var(type, "p");
3345 MAKE_SIG(type, fs_oes_derivatives, 1, p);
3346
3347 body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
3348
3349 return sig;
3350 }
3351
3352 ir_function_signature *
3353 builtin_builder::_noise1(const glsl_type *type)
3354 {
3355 return unop(v110, ir_unop_noise, glsl_type::float_type, type);
3356 }
3357
3358 ir_function_signature *
3359 builtin_builder::_noise2(const glsl_type *type)
3360 {
3361 ir_variable *p = in_var(type, "p");
3362 MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
3363
3364 ir_constant_data b_offset;
3365 b_offset.f[0] = 601.0f;
3366 b_offset.f[1] = 313.0f;
3367 b_offset.f[2] = 29.0f;
3368 b_offset.f[3] = 277.0f;
3369
3370 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
3371 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
3372 ir_variable *t = body.make_temp(glsl_type::vec2_type, "t");
3373 body.emit(assign(a, expr(ir_unop_noise, p)));
3374 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
3375 body.emit(assign(t, a, WRITEMASK_X));
3376 body.emit(assign(t, b, WRITEMASK_Y));
3377 body.emit(ret(t));
3378
3379 return sig;
3380 }
3381
3382 ir_function_signature *
3383 builtin_builder::_noise3(const glsl_type *type)
3384 {
3385 ir_variable *p = in_var(type, "p");
3386 MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
3387
3388 ir_constant_data b_offset;
3389 b_offset.f[0] = 601.0f;
3390 b_offset.f[1] = 313.0f;
3391 b_offset.f[2] = 29.0f;
3392 b_offset.f[3] = 277.0f;
3393
3394 ir_constant_data c_offset;
3395 c_offset.f[0] = 1559.0f;
3396 c_offset.f[1] = 113.0f;
3397 c_offset.f[2] = 1861.0f;
3398 c_offset.f[3] = 797.0f;
3399
3400 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
3401 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
3402 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
3403 ir_variable *t = body.make_temp(glsl_type::vec3_type, "t");
3404 body.emit(assign(a, expr(ir_unop_noise, p)));
3405 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
3406 body.emit(assign(c, expr(ir_unop_noise, add(p, imm(type, c_offset)))));
3407 body.emit(assign(t, a, WRITEMASK_X));
3408 body.emit(assign(t, b, WRITEMASK_Y));
3409 body.emit(assign(t, c, WRITEMASK_Z));
3410 body.emit(ret(t));
3411
3412 return sig;
3413 }
3414
3415 ir_function_signature *
3416 builtin_builder::_noise4(const glsl_type *type)
3417 {
3418 ir_variable *p = in_var(type, "p");
3419 MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
3420
3421 ir_variable *_p = body.make_temp(type, "_p");
3422
3423 ir_constant_data p_offset;
3424 p_offset.f[0] = 1559.0f;
3425 p_offset.f[1] = 113.0f;
3426 p_offset.f[2] = 1861.0f;
3427 p_offset.f[3] = 797.0f;
3428
3429 body.emit(assign(_p, add(p, imm(type, p_offset))));
3430
3431 ir_constant_data offset;
3432 offset.f[0] = 601.0f;
3433 offset.f[1] = 313.0f;
3434 offset.f[2] = 29.0f;
3435 offset.f[3] = 277.0f;
3436
3437 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
3438 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
3439 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
3440 ir_variable *d = body.make_temp(glsl_type::float_type, "d");
3441 ir_variable *t = body.make_temp(glsl_type::vec4_type, "t");
3442 body.emit(assign(a, expr(ir_unop_noise, p)));
3443 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, offset)))));
3444 body.emit(assign(c, expr(ir_unop_noise, _p)));
3445 body.emit(assign(d, expr(ir_unop_noise, add(_p, imm(type, offset)))));
3446 body.emit(assign(t, a, WRITEMASK_X));
3447 body.emit(assign(t, b, WRITEMASK_Y));
3448 body.emit(assign(t, c, WRITEMASK_Z));
3449 body.emit(assign(t, d, WRITEMASK_W));
3450 body.emit(ret(t));
3451
3452 return sig;
3453 }
3454
3455 ir_function_signature *
3456 builtin_builder::_bitfieldExtract(const glsl_type *type)
3457 {
3458 ir_variable *value = in_var(type, "value");
3459 ir_variable *offset = in_var(glsl_type::int_type, "offset");
3460 ir_variable *bits = in_var(glsl_type::int_type, "bits");
3461 MAKE_SIG(type, gpu_shader5, 3, value, offset, bits);
3462
3463 body.emit(ret(expr(ir_triop_bitfield_extract, value, offset, bits)));
3464
3465 return sig;
3466 }
3467
3468 ir_function_signature *
3469 builtin_builder::_bitfieldInsert(const glsl_type *type)
3470 {
3471 ir_variable *base = in_var(type, "base");
3472 ir_variable *insert = in_var(type, "insert");
3473 ir_variable *offset = in_var(glsl_type::int_type, "offset");
3474 ir_variable *bits = in_var(glsl_type::int_type, "bits");
3475 MAKE_SIG(type, gpu_shader5, 4, base, insert, offset, bits);
3476
3477 body.emit(ret(bitfield_insert(base, insert, offset, bits)));
3478
3479 return sig;
3480 }
3481
3482 UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5)
3483
3484 ir_function_signature *
3485 builtin_builder::_bitCount(const glsl_type *type)
3486 {
3487 return unop(gpu_shader5, ir_unop_bit_count,
3488 glsl_type::ivec(type->vector_elements), type);
3489 }
3490
3491 ir_function_signature *
3492 builtin_builder::_findLSB(const glsl_type *type)
3493 {
3494 return unop(gpu_shader5, ir_unop_find_lsb,
3495 glsl_type::ivec(type->vector_elements), type);
3496 }
3497
3498 ir_function_signature *
3499 builtin_builder::_findMSB(const glsl_type *type)
3500 {
3501 return unop(gpu_shader5, ir_unop_find_msb,
3502 glsl_type::ivec(type->vector_elements), type);
3503 }
3504
3505 ir_function_signature *
3506 builtin_builder::_fma(const glsl_type *type)
3507 {
3508 ir_variable *a = in_var(type, "a");
3509 ir_variable *b = in_var(type, "b");
3510 ir_variable *c = in_var(type, "c");
3511 MAKE_SIG(type, gpu_shader5, 3, a, b, c);
3512
3513 body.emit(ret(fma(a, b, c)));
3514
3515 return sig;
3516 }
3517 /** @} */
3518
3519 /******************************************************************************/
3520
3521 /* The singleton instance of builtin_builder. */
3522 static builtin_builder builtins;
3523
3524 /**
3525 * External API (exposing the built-in module to the rest of the compiler):
3526 * @{
3527 */
3528 void
3529 _mesa_glsl_initialize_builtin_functions()
3530 {
3531 builtins.initialize();
3532 }
3533
3534 void
3535 _mesa_glsl_release_builtin_functions()
3536 {
3537 builtins.release();
3538 }
3539
3540 ir_function_signature *
3541 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
3542 const char *name, exec_list *actual_parameters)
3543 {
3544 return builtins.find(state, name, actual_parameters);
3545 }
3546 /** @} */