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