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