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