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