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