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