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