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