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