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