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