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