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