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