9be7f6d1a76b6306350f892decdcf819abfc7c87
[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 #define M_PIf ((float) M_PI)
66 #define M_PI_2f ((float) M_PI_2)
67 #define M_PI_4f ((float) M_PI_4)
68
69 using namespace ir_builder;
70
71 /**
72 * Availability predicates:
73 * @{
74 */
75 static bool
76 always_available(const _mesa_glsl_parse_state *)
77 {
78 return true;
79 }
80
81 static bool
82 compatibility_vs_only(const _mesa_glsl_parse_state *state)
83 {
84 return state->stage == MESA_SHADER_VERTEX &&
85 state->language_version <= 130 &&
86 !state->es_shader;
87 }
88
89 static bool
90 fs_only(const _mesa_glsl_parse_state *state)
91 {
92 return state->stage == MESA_SHADER_FRAGMENT;
93 }
94
95 static bool
96 gs_only(const _mesa_glsl_parse_state *state)
97 {
98 return state->stage == MESA_SHADER_GEOMETRY;
99 }
100
101 static bool
102 v110(const _mesa_glsl_parse_state *state)
103 {
104 return !state->es_shader;
105 }
106
107 static bool
108 v110_fs_only(const _mesa_glsl_parse_state *state)
109 {
110 return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT;
111 }
112
113 static bool
114 v120(const _mesa_glsl_parse_state *state)
115 {
116 return state->is_version(120, 300);
117 }
118
119 static bool
120 v130(const _mesa_glsl_parse_state *state)
121 {
122 return state->is_version(130, 300);
123 }
124
125 static bool
126 v130_fs_only(const _mesa_glsl_parse_state *state)
127 {
128 return state->is_version(130, 300) &&
129 state->stage == MESA_SHADER_FRAGMENT;
130 }
131
132 static bool
133 v140(const _mesa_glsl_parse_state *state)
134 {
135 return state->is_version(140, 0);
136 }
137
138 static bool
139 texture_rectangle(const _mesa_glsl_parse_state *state)
140 {
141 return state->ARB_texture_rectangle_enable;
142 }
143
144 static bool
145 texture_external(const _mesa_glsl_parse_state *state)
146 {
147 return state->OES_EGL_image_external_enable;
148 }
149
150 /** True if texturing functions with explicit LOD are allowed. */
151 static bool
152 lod_exists_in_stage(const _mesa_glsl_parse_state *state)
153 {
154 /* Texturing functions with "Lod" in their name exist:
155 * - In the vertex shader stage (for all languages)
156 * - In any stage for GLSL 1.30+ or GLSL ES 3.00
157 * - In any stage for desktop GLSL with ARB_shader_texture_lod enabled.
158 *
159 * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
160 * don't need to explicitly check state->es_shader.
161 */
162 return state->stage == MESA_SHADER_VERTEX ||
163 state->is_version(130, 300) ||
164 state->ARB_shader_texture_lod_enable;
165 }
166
167 static bool
168 v110_lod(const _mesa_glsl_parse_state *state)
169 {
170 return !state->es_shader && lod_exists_in_stage(state);
171 }
172
173 static bool
174 shader_texture_lod(const _mesa_glsl_parse_state *state)
175 {
176 return state->ARB_shader_texture_lod_enable;
177 }
178
179 static bool
180 shader_texture_lod_and_rect(const _mesa_glsl_parse_state *state)
181 {
182 return state->ARB_shader_texture_lod_enable &&
183 state->ARB_texture_rectangle_enable;
184 }
185
186 static bool
187 shader_bit_encoding(const _mesa_glsl_parse_state *state)
188 {
189 return state->is_version(330, 300) ||
190 state->ARB_shader_bit_encoding_enable ||
191 state->ARB_gpu_shader5_enable;
192 }
193
194 static bool
195 shader_integer_mix(const _mesa_glsl_parse_state *state)
196 {
197 return v130(state) && state->EXT_shader_integer_mix_enable;
198 }
199
200 static bool
201 shader_packing_or_es3(const _mesa_glsl_parse_state *state)
202 {
203 return state->ARB_shading_language_packing_enable ||
204 state->is_version(400, 300);
205 }
206
207 static bool
208 shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state *state)
209 {
210 return state->ARB_shading_language_packing_enable ||
211 state->ARB_gpu_shader5_enable ||
212 state->is_version(400, 300);
213 }
214
215 static bool
216 gpu_shader5(const _mesa_glsl_parse_state *state)
217 {
218 return state->is_version(400, 0) || state->ARB_gpu_shader5_enable;
219 }
220
221 static bool
222 shader_packing_or_gpu_shader5(const _mesa_glsl_parse_state *state)
223 {
224 return state->ARB_shading_language_packing_enable ||
225 gpu_shader5(state);
226 }
227
228 static bool
229 fs_gpu_shader5(const _mesa_glsl_parse_state *state)
230 {
231 return state->stage == MESA_SHADER_FRAGMENT &&
232 (state->is_version(400, 0) || state->ARB_gpu_shader5_enable);
233 }
234
235
236 static bool
237 texture_array_lod(const _mesa_glsl_parse_state *state)
238 {
239 return lod_exists_in_stage(state) &&
240 state->EXT_texture_array_enable;
241 }
242
243 static bool
244 fs_texture_array(const _mesa_glsl_parse_state *state)
245 {
246 return state->stage == MESA_SHADER_FRAGMENT &&
247 state->EXT_texture_array_enable;
248 }
249
250 static bool
251 texture_array(const _mesa_glsl_parse_state *state)
252 {
253 return state->EXT_texture_array_enable;
254 }
255
256 static bool
257 texture_multisample(const _mesa_glsl_parse_state *state)
258 {
259 return state->is_version(150, 0) ||
260 state->ARB_texture_multisample_enable;
261 }
262
263 static bool
264 fs_texture_cube_map_array(const _mesa_glsl_parse_state *state)
265 {
266 return state->stage == MESA_SHADER_FRAGMENT &&
267 (state->is_version(400, 0) ||
268 state->ARB_texture_cube_map_array_enable);
269 }
270
271 static bool
272 texture_cube_map_array(const _mesa_glsl_parse_state *state)
273 {
274 return state->is_version(400, 0) ||
275 state->ARB_texture_cube_map_array_enable;
276 }
277
278 static bool
279 texture_query_levels(const _mesa_glsl_parse_state *state)
280 {
281 return state->is_version(430, 0) ||
282 state->ARB_texture_query_levels_enable;
283 }
284
285 static bool
286 texture_query_lod(const _mesa_glsl_parse_state *state)
287 {
288 return state->stage == MESA_SHADER_FRAGMENT &&
289 state->ARB_texture_query_lod_enable;
290 }
291
292 static bool
293 texture_gather(const _mesa_glsl_parse_state *state)
294 {
295 return state->is_version(400, 0) ||
296 state->ARB_texture_gather_enable ||
297 state->ARB_gpu_shader5_enable;
298 }
299
300 /* Only ARB_texture_gather but not GLSL 4.0 or ARB_gpu_shader5.
301 * used for relaxation of const offset requirements.
302 */
303 static bool
304 texture_gather_only(const _mesa_glsl_parse_state *state)
305 {
306 return !state->is_version(400, 0) &&
307 !state->ARB_gpu_shader5_enable &&
308 state->ARB_texture_gather_enable;
309 }
310
311 /* Desktop GL or OES_standard_derivatives + fragment shader only */
312 static bool
313 fs_oes_derivatives(const _mesa_glsl_parse_state *state)
314 {
315 return state->stage == MESA_SHADER_FRAGMENT &&
316 (state->is_version(110, 300) ||
317 state->OES_standard_derivatives_enable);
318 }
319
320 static bool
321 fs_derivative_control(const _mesa_glsl_parse_state *state)
322 {
323 return state->stage == MESA_SHADER_FRAGMENT &&
324 (state->is_version(450, 0) ||
325 state->ARB_derivative_control_enable);
326 }
327
328 static bool
329 tex1d_lod(const _mesa_glsl_parse_state *state)
330 {
331 return !state->es_shader && lod_exists_in_stage(state);
332 }
333
334 /** True if sampler3D exists */
335 static bool
336 tex3d(const _mesa_glsl_parse_state *state)
337 {
338 /* sampler3D exists in all desktop GLSL versions, GLSL ES 1.00 with the
339 * OES_texture_3D extension, and in GLSL ES 3.00.
340 */
341 return !state->es_shader ||
342 state->OES_texture_3D_enable ||
343 state->language_version >= 300;
344 }
345
346 static bool
347 fs_tex3d(const _mesa_glsl_parse_state *state)
348 {
349 return state->stage == MESA_SHADER_FRAGMENT &&
350 (!state->es_shader || state->OES_texture_3D_enable);
351 }
352
353 static bool
354 tex3d_lod(const _mesa_glsl_parse_state *state)
355 {
356 return tex3d(state) && lod_exists_in_stage(state);
357 }
358
359 static bool
360 shader_atomic_counters(const _mesa_glsl_parse_state *state)
361 {
362 return state->ARB_shader_atomic_counters_enable;
363 }
364
365 static bool
366 shader_trinary_minmax(const _mesa_glsl_parse_state *state)
367 {
368 return state->AMD_shader_trinary_minmax_enable;
369 }
370
371 static bool
372 shader_image_load_store(const _mesa_glsl_parse_state *state)
373 {
374 return (state->is_version(420, 0) ||
375 state->ARB_shader_image_load_store_enable);
376 }
377
378 static bool
379 gs_streams(const _mesa_glsl_parse_state *state)
380 {
381 return gpu_shader5(state) && gs_only(state);
382 }
383
384 /** @} */
385
386 /******************************************************************************/
387
388 namespace {
389
390 /**
391 * builtin_builder: A singleton object representing the core of the built-in
392 * function module.
393 *
394 * It generates IR for every built-in function signature, and organizes them
395 * into functions.
396 */
397 class builtin_builder {
398 public:
399 builtin_builder();
400 ~builtin_builder();
401
402 void initialize();
403 void release();
404 ir_function_signature *find(_mesa_glsl_parse_state *state,
405 const char *name, exec_list *actual_parameters);
406
407 /**
408 * A shader to hold all the built-in signatures; created by this module.
409 *
410 * This includes signatures for every built-in, regardless of version or
411 * enabled extensions. The availability predicate associated with each
412 * signature allows matching_signature() to filter out the irrelevant ones.
413 */
414 gl_shader *shader;
415
416 private:
417 void *mem_ctx;
418
419 /** Global variables used by built-in functions. */
420 ir_variable *gl_ModelViewProjectionMatrix;
421 ir_variable *gl_Vertex;
422
423 void create_shader();
424 void create_intrinsics();
425 void create_builtins();
426
427 /**
428 * IR builder helpers:
429 *
430 * These convenience functions assist in emitting IR, but don't necessarily
431 * fit in ir_builder itself. Many of them rely on having a mem_ctx class
432 * member available.
433 */
434 ir_variable *in_var(const glsl_type *type, const char *name);
435 ir_variable *out_var(const glsl_type *type, const char *name);
436 ir_constant *imm(float f, unsigned vector_elements=1);
437 ir_constant *imm(int i, unsigned vector_elements=1);
438 ir_constant *imm(unsigned u, unsigned vector_elements=1);
439 ir_constant *imm(const glsl_type *type, const ir_constant_data &);
440 ir_dereference_variable *var_ref(ir_variable *var);
441 ir_dereference_array *array_ref(ir_variable *var, int i);
442 ir_swizzle *matrix_elt(ir_variable *var, int col, int row);
443
444 ir_expression *asin_expr(ir_variable *x);
445
446 /**
447 * Call function \param f with parameters specified as the linked
448 * list \param params of \c ir_variable objects. \param ret should
449 * point to the ir_variable that will hold the function return
450 * value, or be \c NULL if the function has void return type.
451 */
452 ir_call *call(ir_function *f, ir_variable *ret, exec_list params);
453
454 /** Create a new function and add the given signatures. */
455 void add_function(const char *name, ...);
456
457 enum image_function_flags {
458 IMAGE_FUNCTION_EMIT_STUB = (1 << 0),
459 IMAGE_FUNCTION_RETURNS_VOID = (1 << 1),
460 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE = (1 << 2),
461 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE = (1 << 3),
462 IMAGE_FUNCTION_READ_ONLY = (1 << 4),
463 IMAGE_FUNCTION_WRITE_ONLY = (1 << 5)
464 };
465
466 /**
467 * Create a new image built-in function for all known image types.
468 * \p flags is a bitfield of \c image_function_flags flags.
469 */
470 void add_image_function(const char *name,
471 const char *intrinsic_name,
472 unsigned num_arguments,
473 unsigned flags);
474
475 /**
476 * Create new functions for all known image built-ins and types.
477 * If \p glsl is \c true, use the GLSL built-in names and emit code
478 * to call into the actual compiler intrinsic. If \p glsl is
479 * false, emit a function prototype with no body for each image
480 * intrinsic name.
481 */
482 void add_image_functions(bool glsl);
483
484 ir_function_signature *new_sig(const glsl_type *return_type,
485 builtin_available_predicate avail,
486 int num_params, ...);
487
488 /**
489 * Function signature generators:
490 * @{
491 */
492 ir_function_signature *unop(builtin_available_predicate avail,
493 ir_expression_operation opcode,
494 const glsl_type *return_type,
495 const glsl_type *param_type);
496 ir_function_signature *binop(ir_expression_operation opcode,
497 builtin_available_predicate avail,
498 const glsl_type *return_type,
499 const glsl_type *param0_type,
500 const glsl_type *param1_type);
501
502 #define B0(X) ir_function_signature *_##X();
503 #define B1(X) ir_function_signature *_##X(const glsl_type *);
504 #define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *);
505 #define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *, const glsl_type *);
506 #define BA1(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *);
507 #define BA2(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *, const glsl_type *);
508 B1(radians)
509 B1(degrees)
510 B1(sin)
511 B1(cos)
512 B1(tan)
513 B1(asin)
514 B1(acos)
515 B1(atan2)
516 B1(atan)
517 B1(sinh)
518 B1(cosh)
519 B1(tanh)
520 B1(asinh)
521 B1(acosh)
522 B1(atanh)
523 B1(pow)
524 B1(exp)
525 B1(log)
526 B1(exp2)
527 B1(log2)
528 B1(sqrt)
529 B1(inversesqrt)
530 B1(abs)
531 B1(sign)
532 B1(floor)
533 B1(trunc)
534 B1(round)
535 B1(roundEven)
536 B1(ceil)
537 B1(fract)
538 B2(mod)
539 B1(modf)
540 BA2(min)
541 BA2(max)
542 BA2(clamp)
543 B2(mix_lrp)
544 ir_function_signature *_mix_sel(builtin_available_predicate avail,
545 const glsl_type *val_type,
546 const glsl_type *blend_type);
547 B2(step)
548 B2(smoothstep)
549 B1(isnan)
550 B1(isinf)
551 B1(floatBitsToInt)
552 B1(floatBitsToUint)
553 B1(intBitsToFloat)
554 B1(uintBitsToFloat)
555 ir_function_signature *_packUnorm2x16(builtin_available_predicate avail);
556 ir_function_signature *_packSnorm2x16(builtin_available_predicate avail);
557 ir_function_signature *_packUnorm4x8(builtin_available_predicate avail);
558 ir_function_signature *_packSnorm4x8(builtin_available_predicate avail);
559 ir_function_signature *_unpackUnorm2x16(builtin_available_predicate avail);
560 ir_function_signature *_unpackSnorm2x16(builtin_available_predicate avail);
561 ir_function_signature *_unpackUnorm4x8(builtin_available_predicate avail);
562 ir_function_signature *_unpackSnorm4x8(builtin_available_predicate avail);
563 ir_function_signature *_packHalf2x16(builtin_available_predicate avail);
564 ir_function_signature *_unpackHalf2x16(builtin_available_predicate avail);
565 B1(length)
566 B1(distance);
567 B1(dot);
568 B1(cross);
569 B1(normalize);
570 B0(ftransform);
571 B1(faceforward);
572 B1(reflect);
573 B1(refract);
574 B1(matrixCompMult);
575 B1(outerProduct);
576 B0(determinant_mat2);
577 B0(determinant_mat3);
578 B0(determinant_mat4);
579 B0(inverse_mat2);
580 B0(inverse_mat3);
581 B0(inverse_mat4);
582 B1(transpose);
583 BA1(lessThan);
584 BA1(lessThanEqual);
585 BA1(greaterThan);
586 BA1(greaterThanEqual);
587 BA1(equal);
588 BA1(notEqual);
589 B1(any);
590 B1(all);
591 B1(not);
592 B2(textureSize);
593 ir_function_signature *_textureSize(builtin_available_predicate avail,
594 const glsl_type *return_type,
595 const glsl_type *sampler_type);
596
597 /** Flags to _texture() */
598 #define TEX_PROJECT 1
599 #define TEX_OFFSET 2
600 #define TEX_COMPONENT 4
601 #define TEX_OFFSET_NONCONST 8
602 #define TEX_OFFSET_ARRAY 16
603
604 ir_function_signature *_texture(ir_texture_opcode opcode,
605 builtin_available_predicate avail,
606 const glsl_type *return_type,
607 const glsl_type *sampler_type,
608 const glsl_type *coord_type,
609 int flags = 0);
610 B0(textureCubeArrayShadow);
611 ir_function_signature *_texelFetch(builtin_available_predicate avail,
612 const glsl_type *return_type,
613 const glsl_type *sampler_type,
614 const glsl_type *coord_type,
615 const glsl_type *offset_type = NULL);
616
617 B0(EmitVertex)
618 B0(EndPrimitive)
619 ir_function_signature *_EmitStreamVertex(builtin_available_predicate avail,
620 const glsl_type *stream_type);
621 ir_function_signature *_EndStreamPrimitive(builtin_available_predicate avail,
622 const glsl_type *stream_type);
623
624 B2(textureQueryLod);
625 B1(textureQueryLevels);
626 B1(dFdx);
627 B1(dFdy);
628 B1(fwidth);
629 B1(dFdxCoarse);
630 B1(dFdyCoarse);
631 B1(fwidthCoarse);
632 B1(dFdxFine);
633 B1(dFdyFine);
634 B1(fwidthFine);
635 B1(noise1);
636 B1(noise2);
637 B1(noise3);
638 B1(noise4);
639
640 B1(bitfieldExtract)
641 B1(bitfieldInsert)
642 B1(bitfieldReverse)
643 B1(bitCount)
644 B1(findLSB)
645 B1(findMSB)
646 B1(fma)
647 B2(ldexp)
648 B2(frexp)
649 B1(uaddCarry)
650 B1(usubBorrow)
651 B1(mulExtended)
652 B1(interpolateAtCentroid)
653 B1(interpolateAtOffset)
654 B1(interpolateAtSample)
655
656 ir_function_signature *_atomic_intrinsic(builtin_available_predicate avail);
657 ir_function_signature *_atomic_op(const char *intrinsic,
658 builtin_available_predicate avail);
659
660 B1(min3)
661 B1(max3)
662 B1(mid3)
663
664 ir_function_signature *_image_prototype(const glsl_type *image_type,
665 const char *intrinsic_name,
666 unsigned num_arguments,
667 unsigned flags);
668 ir_function_signature *_image(const glsl_type *image_type,
669 const char *intrinsic_name,
670 unsigned num_arguments,
671 unsigned flags);
672
673 ir_function_signature *_memory_barrier_intrinsic(
674 builtin_available_predicate avail);
675 ir_function_signature *_memory_barrier(
676 builtin_available_predicate avail);
677
678 #undef B0
679 #undef B1
680 #undef B2
681 #undef B3
682 #undef BA1
683 #undef BA2
684 /** @} */
685 };
686
687 } /* anonymous namespace */
688
689 /**
690 * Core builtin_builder functionality:
691 * @{
692 */
693 builtin_builder::builtin_builder()
694 : shader(NULL),
695 gl_ModelViewProjectionMatrix(NULL),
696 gl_Vertex(NULL)
697 {
698 mem_ctx = NULL;
699 }
700
701 builtin_builder::~builtin_builder()
702 {
703 ralloc_free(mem_ctx);
704 }
705
706 ir_function_signature *
707 builtin_builder::find(_mesa_glsl_parse_state *state,
708 const char *name, exec_list *actual_parameters)
709 {
710 /* The shader currently being compiled requested a built-in function;
711 * it needs to link against builtin_builder::shader in order to get them.
712 *
713 * Even if we don't find a matching signature, we still need to do this so
714 * that the "no matching signature" error will list potential candidates
715 * from the available built-ins.
716 */
717 state->uses_builtin_functions = true;
718
719 ir_function *f = shader->symbols->get_function(name);
720 if (f == NULL)
721 return NULL;
722
723 ir_function_signature *sig =
724 f->matching_signature(state, actual_parameters, true);
725 if (sig == NULL)
726 return NULL;
727
728 return sig;
729 }
730
731 void
732 builtin_builder::initialize()
733 {
734 /* If already initialized, don't do it again. */
735 if (mem_ctx != NULL)
736 return;
737
738 mem_ctx = ralloc_context(NULL);
739 create_shader();
740 create_intrinsics();
741 create_builtins();
742 }
743
744 void
745 builtin_builder::release()
746 {
747 ralloc_free(mem_ctx);
748 mem_ctx = NULL;
749
750 ralloc_free(shader);
751 shader = NULL;
752 }
753
754 void
755 builtin_builder::create_shader()
756 {
757 /* The target doesn't actually matter. There's no target for generic
758 * GLSL utility code that could be linked against any stage, so just
759 * arbitrarily pick GL_VERTEX_SHADER.
760 */
761 shader = _mesa_new_shader(NULL, 0, GL_VERTEX_SHADER);
762 shader->symbols = new(mem_ctx) glsl_symbol_table;
763
764 gl_ModelViewProjectionMatrix =
765 new(mem_ctx) ir_variable(glsl_type::mat4_type,
766 "gl_ModelViewProjectionMatrix",
767 ir_var_uniform);
768
769 shader->symbols->add_variable(gl_ModelViewProjectionMatrix);
770
771 gl_Vertex = in_var(glsl_type::vec4_type, "gl_Vertex");
772 shader->symbols->add_variable(gl_Vertex);
773 }
774
775 /** @} */
776
777 /**
778 * Create ir_function and ir_function_signature objects for each
779 * intrinsic.
780 */
781 void
782 builtin_builder::create_intrinsics()
783 {
784 add_function("__intrinsic_atomic_read",
785 _atomic_intrinsic(shader_atomic_counters),
786 NULL);
787 add_function("__intrinsic_atomic_increment",
788 _atomic_intrinsic(shader_atomic_counters),
789 NULL);
790 add_function("__intrinsic_atomic_predecrement",
791 _atomic_intrinsic(shader_atomic_counters),
792 NULL);
793
794 add_image_functions(false);
795
796 add_function("__intrinsic_memory_barrier",
797 _memory_barrier_intrinsic(shader_image_load_store),
798 NULL);
799 }
800
801 /**
802 * Create ir_function and ir_function_signature objects for each built-in.
803 *
804 * Contains a list of every available built-in.
805 */
806 void
807 builtin_builder::create_builtins()
808 {
809 #define F(NAME) \
810 add_function(#NAME, \
811 _##NAME(glsl_type::float_type), \
812 _##NAME(glsl_type::vec2_type), \
813 _##NAME(glsl_type::vec3_type), \
814 _##NAME(glsl_type::vec4_type), \
815 NULL);
816
817 #define FI(NAME) \
818 add_function(#NAME, \
819 _##NAME(glsl_type::float_type), \
820 _##NAME(glsl_type::vec2_type), \
821 _##NAME(glsl_type::vec3_type), \
822 _##NAME(glsl_type::vec4_type), \
823 _##NAME(glsl_type::int_type), \
824 _##NAME(glsl_type::ivec2_type), \
825 _##NAME(glsl_type::ivec3_type), \
826 _##NAME(glsl_type::ivec4_type), \
827 NULL);
828
829 #define FIU(NAME) \
830 add_function(#NAME, \
831 _##NAME(always_available, glsl_type::float_type), \
832 _##NAME(always_available, glsl_type::vec2_type), \
833 _##NAME(always_available, glsl_type::vec3_type), \
834 _##NAME(always_available, glsl_type::vec4_type), \
835 \
836 _##NAME(always_available, glsl_type::int_type), \
837 _##NAME(always_available, glsl_type::ivec2_type), \
838 _##NAME(always_available, glsl_type::ivec3_type), \
839 _##NAME(always_available, glsl_type::ivec4_type), \
840 \
841 _##NAME(v130, glsl_type::uint_type), \
842 _##NAME(v130, glsl_type::uvec2_type), \
843 _##NAME(v130, glsl_type::uvec3_type), \
844 _##NAME(v130, glsl_type::uvec4_type), \
845 NULL);
846
847 #define IU(NAME) \
848 add_function(#NAME, \
849 _##NAME(glsl_type::int_type), \
850 _##NAME(glsl_type::ivec2_type), \
851 _##NAME(glsl_type::ivec3_type), \
852 _##NAME(glsl_type::ivec4_type), \
853 \
854 _##NAME(glsl_type::uint_type), \
855 _##NAME(glsl_type::uvec2_type), \
856 _##NAME(glsl_type::uvec3_type), \
857 _##NAME(glsl_type::uvec4_type), \
858 NULL);
859
860 #define FIUB(NAME) \
861 add_function(#NAME, \
862 _##NAME(always_available, glsl_type::float_type), \
863 _##NAME(always_available, glsl_type::vec2_type), \
864 _##NAME(always_available, glsl_type::vec3_type), \
865 _##NAME(always_available, glsl_type::vec4_type), \
866 \
867 _##NAME(always_available, glsl_type::int_type), \
868 _##NAME(always_available, glsl_type::ivec2_type), \
869 _##NAME(always_available, glsl_type::ivec3_type), \
870 _##NAME(always_available, glsl_type::ivec4_type), \
871 \
872 _##NAME(v130, glsl_type::uint_type), \
873 _##NAME(v130, glsl_type::uvec2_type), \
874 _##NAME(v130, glsl_type::uvec3_type), \
875 _##NAME(v130, glsl_type::uvec4_type), \
876 \
877 _##NAME(always_available, glsl_type::bool_type), \
878 _##NAME(always_available, glsl_type::bvec2_type), \
879 _##NAME(always_available, glsl_type::bvec3_type), \
880 _##NAME(always_available, glsl_type::bvec4_type), \
881 NULL);
882
883 #define FIU2_MIXED(NAME) \
884 add_function(#NAME, \
885 _##NAME(always_available, glsl_type::float_type, glsl_type::float_type), \
886 _##NAME(always_available, glsl_type::vec2_type, glsl_type::float_type), \
887 _##NAME(always_available, glsl_type::vec3_type, glsl_type::float_type), \
888 _##NAME(always_available, glsl_type::vec4_type, glsl_type::float_type), \
889 \
890 _##NAME(always_available, glsl_type::vec2_type, glsl_type::vec2_type), \
891 _##NAME(always_available, glsl_type::vec3_type, glsl_type::vec3_type), \
892 _##NAME(always_available, glsl_type::vec4_type, glsl_type::vec4_type), \
893 \
894 _##NAME(always_available, glsl_type::int_type, glsl_type::int_type), \
895 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::int_type), \
896 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::int_type), \
897 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::int_type), \
898 \
899 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::ivec2_type), \
900 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
901 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
902 \
903 _##NAME(v130, glsl_type::uint_type, glsl_type::uint_type), \
904 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uint_type), \
905 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uint_type), \
906 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uint_type), \
907 \
908 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uvec2_type), \
909 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uvec3_type), \
910 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uvec4_type), \
911 NULL);
912
913 F(radians)
914 F(degrees)
915 F(sin)
916 F(cos)
917 F(tan)
918 F(asin)
919 F(acos)
920
921 add_function("atan",
922 _atan(glsl_type::float_type),
923 _atan(glsl_type::vec2_type),
924 _atan(glsl_type::vec3_type),
925 _atan(glsl_type::vec4_type),
926 _atan2(glsl_type::float_type),
927 _atan2(glsl_type::vec2_type),
928 _atan2(glsl_type::vec3_type),
929 _atan2(glsl_type::vec4_type),
930 NULL);
931
932 F(sinh)
933 F(cosh)
934 F(tanh)
935 F(asinh)
936 F(acosh)
937 F(atanh)
938 F(pow)
939 F(exp)
940 F(log)
941 F(exp2)
942 F(log2)
943 F(sqrt)
944 F(inversesqrt)
945 FI(abs)
946 FI(sign)
947 F(floor)
948 F(trunc)
949 F(round)
950 F(roundEven)
951 F(ceil)
952 F(fract)
953
954 add_function("mod",
955 _mod(glsl_type::float_type, glsl_type::float_type),
956 _mod(glsl_type::vec2_type, glsl_type::float_type),
957 _mod(glsl_type::vec3_type, glsl_type::float_type),
958 _mod(glsl_type::vec4_type, glsl_type::float_type),
959
960 _mod(glsl_type::vec2_type, glsl_type::vec2_type),
961 _mod(glsl_type::vec3_type, glsl_type::vec3_type),
962 _mod(glsl_type::vec4_type, glsl_type::vec4_type),
963 NULL);
964
965 F(modf)
966
967 FIU2_MIXED(min)
968 FIU2_MIXED(max)
969 FIU2_MIXED(clamp)
970
971 add_function("mix",
972 _mix_lrp(glsl_type::float_type, glsl_type::float_type),
973 _mix_lrp(glsl_type::vec2_type, glsl_type::float_type),
974 _mix_lrp(glsl_type::vec3_type, glsl_type::float_type),
975 _mix_lrp(glsl_type::vec4_type, glsl_type::float_type),
976
977 _mix_lrp(glsl_type::vec2_type, glsl_type::vec2_type),
978 _mix_lrp(glsl_type::vec3_type, glsl_type::vec3_type),
979 _mix_lrp(glsl_type::vec4_type, glsl_type::vec4_type),
980
981 _mix_sel(v130, glsl_type::float_type, glsl_type::bool_type),
982 _mix_sel(v130, glsl_type::vec2_type, glsl_type::bvec2_type),
983 _mix_sel(v130, glsl_type::vec3_type, glsl_type::bvec3_type),
984 _mix_sel(v130, glsl_type::vec4_type, glsl_type::bvec4_type),
985
986 _mix_sel(shader_integer_mix, glsl_type::int_type, glsl_type::bool_type),
987 _mix_sel(shader_integer_mix, glsl_type::ivec2_type, glsl_type::bvec2_type),
988 _mix_sel(shader_integer_mix, glsl_type::ivec3_type, glsl_type::bvec3_type),
989 _mix_sel(shader_integer_mix, glsl_type::ivec4_type, glsl_type::bvec4_type),
990
991 _mix_sel(shader_integer_mix, glsl_type::uint_type, glsl_type::bool_type),
992 _mix_sel(shader_integer_mix, glsl_type::uvec2_type, glsl_type::bvec2_type),
993 _mix_sel(shader_integer_mix, glsl_type::uvec3_type, glsl_type::bvec3_type),
994 _mix_sel(shader_integer_mix, glsl_type::uvec4_type, glsl_type::bvec4_type),
995
996 _mix_sel(shader_integer_mix, glsl_type::bool_type, glsl_type::bool_type),
997 _mix_sel(shader_integer_mix, glsl_type::bvec2_type, glsl_type::bvec2_type),
998 _mix_sel(shader_integer_mix, glsl_type::bvec3_type, glsl_type::bvec3_type),
999 _mix_sel(shader_integer_mix, glsl_type::bvec4_type, glsl_type::bvec4_type),
1000 NULL);
1001
1002 add_function("step",
1003 _step(glsl_type::float_type, glsl_type::float_type),
1004 _step(glsl_type::float_type, glsl_type::vec2_type),
1005 _step(glsl_type::float_type, glsl_type::vec3_type),
1006 _step(glsl_type::float_type, glsl_type::vec4_type),
1007
1008 _step(glsl_type::vec2_type, glsl_type::vec2_type),
1009 _step(glsl_type::vec3_type, glsl_type::vec3_type),
1010 _step(glsl_type::vec4_type, glsl_type::vec4_type),
1011 NULL);
1012
1013 add_function("smoothstep",
1014 _smoothstep(glsl_type::float_type, glsl_type::float_type),
1015 _smoothstep(glsl_type::float_type, glsl_type::vec2_type),
1016 _smoothstep(glsl_type::float_type, glsl_type::vec3_type),
1017 _smoothstep(glsl_type::float_type, glsl_type::vec4_type),
1018
1019 _smoothstep(glsl_type::vec2_type, glsl_type::vec2_type),
1020 _smoothstep(glsl_type::vec3_type, glsl_type::vec3_type),
1021 _smoothstep(glsl_type::vec4_type, glsl_type::vec4_type),
1022 NULL);
1023
1024 F(isnan)
1025 F(isinf)
1026
1027 F(floatBitsToInt)
1028 F(floatBitsToUint)
1029 add_function("intBitsToFloat",
1030 _intBitsToFloat(glsl_type::int_type),
1031 _intBitsToFloat(glsl_type::ivec2_type),
1032 _intBitsToFloat(glsl_type::ivec3_type),
1033 _intBitsToFloat(glsl_type::ivec4_type),
1034 NULL);
1035 add_function("uintBitsToFloat",
1036 _uintBitsToFloat(glsl_type::uint_type),
1037 _uintBitsToFloat(glsl_type::uvec2_type),
1038 _uintBitsToFloat(glsl_type::uvec3_type),
1039 _uintBitsToFloat(glsl_type::uvec4_type),
1040 NULL);
1041
1042 add_function("packUnorm2x16", _packUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
1043 add_function("packSnorm2x16", _packSnorm2x16(shader_packing_or_es3), NULL);
1044 add_function("packUnorm4x8", _packUnorm4x8(shader_packing_or_gpu_shader5), NULL);
1045 add_function("packSnorm4x8", _packSnorm4x8(shader_packing_or_gpu_shader5), NULL);
1046 add_function("unpackUnorm2x16", _unpackUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
1047 add_function("unpackSnorm2x16", _unpackSnorm2x16(shader_packing_or_es3), NULL);
1048 add_function("unpackUnorm4x8", _unpackUnorm4x8(shader_packing_or_gpu_shader5), NULL);
1049 add_function("unpackSnorm4x8", _unpackSnorm4x8(shader_packing_or_gpu_shader5), NULL);
1050 add_function("packHalf2x16", _packHalf2x16(shader_packing_or_es3), NULL);
1051 add_function("unpackHalf2x16", _unpackHalf2x16(shader_packing_or_es3), NULL);
1052
1053 F(length)
1054 F(distance)
1055 F(dot)
1056
1057 add_function("cross", _cross(glsl_type::vec3_type), NULL);
1058
1059 F(normalize)
1060 add_function("ftransform", _ftransform(), NULL);
1061 F(faceforward)
1062 F(reflect)
1063 F(refract)
1064 // ...
1065 add_function("matrixCompMult",
1066 _matrixCompMult(glsl_type::mat2_type),
1067 _matrixCompMult(glsl_type::mat3_type),
1068 _matrixCompMult(glsl_type::mat4_type),
1069 _matrixCompMult(glsl_type::mat2x3_type),
1070 _matrixCompMult(glsl_type::mat2x4_type),
1071 _matrixCompMult(glsl_type::mat3x2_type),
1072 _matrixCompMult(glsl_type::mat3x4_type),
1073 _matrixCompMult(glsl_type::mat4x2_type),
1074 _matrixCompMult(glsl_type::mat4x3_type),
1075 NULL);
1076 add_function("outerProduct",
1077 _outerProduct(glsl_type::mat2_type),
1078 _outerProduct(glsl_type::mat3_type),
1079 _outerProduct(glsl_type::mat4_type),
1080 _outerProduct(glsl_type::mat2x3_type),
1081 _outerProduct(glsl_type::mat2x4_type),
1082 _outerProduct(glsl_type::mat3x2_type),
1083 _outerProduct(glsl_type::mat3x4_type),
1084 _outerProduct(glsl_type::mat4x2_type),
1085 _outerProduct(glsl_type::mat4x3_type),
1086 NULL);
1087 add_function("determinant",
1088 _determinant_mat2(),
1089 _determinant_mat3(),
1090 _determinant_mat4(),
1091 NULL);
1092 add_function("inverse",
1093 _inverse_mat2(),
1094 _inverse_mat3(),
1095 _inverse_mat4(),
1096 NULL);
1097 add_function("transpose",
1098 _transpose(glsl_type::mat2_type),
1099 _transpose(glsl_type::mat3_type),
1100 _transpose(glsl_type::mat4_type),
1101 _transpose(glsl_type::mat2x3_type),
1102 _transpose(glsl_type::mat2x4_type),
1103 _transpose(glsl_type::mat3x2_type),
1104 _transpose(glsl_type::mat3x4_type),
1105 _transpose(glsl_type::mat4x2_type),
1106 _transpose(glsl_type::mat4x3_type),
1107 NULL);
1108 FIU(lessThan)
1109 FIU(lessThanEqual)
1110 FIU(greaterThan)
1111 FIU(greaterThanEqual)
1112 FIUB(notEqual)
1113 FIUB(equal)
1114
1115 add_function("any",
1116 _any(glsl_type::bvec2_type),
1117 _any(glsl_type::bvec3_type),
1118 _any(glsl_type::bvec4_type),
1119 NULL);
1120
1121 add_function("all",
1122 _all(glsl_type::bvec2_type),
1123 _all(glsl_type::bvec3_type),
1124 _all(glsl_type::bvec4_type),
1125 NULL);
1126
1127 add_function("not",
1128 _not(glsl_type::bvec2_type),
1129 _not(glsl_type::bvec3_type),
1130 _not(glsl_type::bvec4_type),
1131 NULL);
1132
1133 add_function("textureSize",
1134 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1D_type),
1135 _textureSize(v130, glsl_type::int_type, glsl_type::isampler1D_type),
1136 _textureSize(v130, glsl_type::int_type, glsl_type::usampler1D_type),
1137
1138 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2D_type),
1139 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2D_type),
1140 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2D_type),
1141
1142 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler3D_type),
1143 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler3D_type),
1144 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler3D_type),
1145
1146 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCube_type),
1147 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
1148 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
1149
1150 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1DShadow_type),
1151 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DShadow_type),
1152 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCubeShadow_type),
1153
1154 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
1155 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
1156 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
1157 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
1158 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
1159 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
1160
1161 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArrayShadow_type),
1162 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArrayShadow_type),
1163
1164 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArray_type),
1165 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::isamplerCubeArray_type),
1166 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::usamplerCubeArray_type),
1167 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArrayShadow_type),
1168
1169 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
1170 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
1171 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
1172 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRectShadow_type),
1173
1174 _textureSize(v140, glsl_type::int_type, glsl_type::samplerBuffer_type),
1175 _textureSize(v140, glsl_type::int_type, glsl_type::isamplerBuffer_type),
1176 _textureSize(v140, glsl_type::int_type, glsl_type::usamplerBuffer_type),
1177 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::sampler2DMS_type),
1178 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::isampler2DMS_type),
1179 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::usampler2DMS_type),
1180
1181 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::sampler2DMSArray_type),
1182 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::isampler2DMSArray_type),
1183 _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::usampler2DMSArray_type),
1184 NULL);
1185
1186 add_function("texture",
1187 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1188 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1189 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1190
1191 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1192 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1193 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1194
1195 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1196 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1197 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1198
1199 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1200 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1201 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1202
1203 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1204 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1205 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1206
1207 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1208 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1209 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1210
1211 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1212 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1213 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1214
1215 _texture(ir_tex, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1216 _texture(ir_tex, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1217 _texture(ir_tex, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1218
1219 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1220 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1221 /* samplerCubeArrayShadow is special; it has an extra parameter
1222 * for the shadow comparitor since there is no vec5 type.
1223 */
1224 _textureCubeArrayShadow(),
1225
1226 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1227 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
1228 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
1229
1230 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1231
1232 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1233 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1234 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1235
1236 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1237 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1238 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1239
1240 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1241 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1242 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1243
1244 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1245 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1246 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1247
1248 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1249 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1250 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1251
1252 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1253 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1254 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1255
1256 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1257 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1258 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1259
1260 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1261 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1262 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1263
1264 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1265 NULL);
1266
1267 add_function("textureLod",
1268 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1269 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1270 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1271
1272 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1273 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1274 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1275
1276 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1277 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1278 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1279
1280 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1281 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1282 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1283
1284 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1285 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1286
1287 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1288 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1289 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1290
1291 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1292 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1293 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1294
1295 _texture(ir_txl, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1296 _texture(ir_txl, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1297 _texture(ir_txl, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1298
1299 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1300 NULL);
1301
1302 add_function("textureOffset",
1303 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1304 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1305 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1306
1307 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1308 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1309 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1310
1311 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1312 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1313 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1314
1315 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1316 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1317 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1318
1319 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1320
1321 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1322 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1323
1324 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1325 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1326 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1327
1328 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1329 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1330 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1331
1332 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1333
1334 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1335 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1336 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1337
1338 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1339 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1340 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1341
1342 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1343 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1344 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1345
1346 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1347 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1348
1349 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1350 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1351 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1352
1353 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1354 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1355 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1356
1357 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1358 NULL);
1359
1360 add_function("textureProj",
1361 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1362 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1363 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1364 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1365 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1366 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1367
1368 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1369 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1370 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1371 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1372 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1373 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1374
1375 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1376 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1377 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1378
1379 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1380 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1381
1382 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1383 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1384 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1385 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1386 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1387 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1388
1389 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1390
1391 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1392 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1393 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1394 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1395 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1396 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1397
1398 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1399 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1400 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1401 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1402 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1403 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1404
1405 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1406 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1407 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1408
1409 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1410 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1411 NULL);
1412
1413 add_function("texelFetch",
1414 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
1415 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
1416 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
1417
1418 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
1419 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
1420 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
1421
1422 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
1423 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
1424 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
1425
1426 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
1427 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
1428 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
1429
1430 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
1431 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
1432 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
1433
1434 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
1435 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
1436 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
1437
1438 _texelFetch(v140, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
1439 _texelFetch(v140, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
1440 _texelFetch(v140, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
1441
1442 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
1443 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
1444 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
1445
1446 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
1447 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
1448 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
1449 NULL);
1450
1451 add_function("texelFetchOffset",
1452 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
1453 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
1454 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
1455
1456 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1457 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1458 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1459
1460 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1461 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1462 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
1463
1464 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1465 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1466 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
1467
1468 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1469 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1470 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
1471
1472 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1473 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1474 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
1475
1476 NULL);
1477
1478 add_function("textureProjOffset",
1479 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1480 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1481 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1482 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1483 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1484 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1485
1486 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1487 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1488 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1489 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1490 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1491 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1492
1493 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1494 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1495 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1496
1497 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1498 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1499
1500 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1501 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1502 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1503 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1504 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1505 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1506
1507 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1508
1509 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1510 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1511 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1512 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1513 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1514 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1515
1516 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1517 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1518 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1519 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1520 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1521 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1522
1523 _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1524 _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1525 _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1526
1527 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1528 _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1529 NULL);
1530
1531 add_function("textureLodOffset",
1532 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1533 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1534 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1535
1536 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1537 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1538 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1539
1540 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1541 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1542 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1543
1544 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1545 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1546
1547 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1548 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1549 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1550
1551 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1552 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1553 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1554
1555 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1556 NULL);
1557
1558 add_function("textureProjLod",
1559 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1560 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1561 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1562 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1563 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1564 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1565
1566 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1567 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1568 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1569 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1570 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1571 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1572
1573 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1574 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1575 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1576
1577 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1578 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1579 NULL);
1580
1581 add_function("textureProjLodOffset",
1582 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1583 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1584 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1585 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1586 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1587 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1588
1589 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1590 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1591 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1592 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1593 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1594 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1595
1596 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1597 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1598 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1599
1600 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1601 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1602 NULL);
1603
1604 add_function("textureGrad",
1605 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1606 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1607 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1608
1609 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1610 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1611 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1612
1613 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1614 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1615 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1616
1617 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1618 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1619 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1620
1621 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1622 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
1623 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
1624
1625 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1626
1627 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1628 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1629 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1630
1631 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1632 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1633 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1634
1635 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1636 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1637 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1638
1639 _texture(ir_txd, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1640 _texture(ir_txd, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1641 _texture(ir_txd, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1642
1643 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1644 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1645 NULL);
1646
1647 add_function("textureGradOffset",
1648 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1649 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1650 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1651
1652 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1653 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1654 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1655
1656 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1657 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1658 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1659
1660 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1661 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1662 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1663
1664 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1665
1666 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1667 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1668
1669 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1670 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1671 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1672
1673 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1674 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1675 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1676
1677 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1678 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
1679 NULL);
1680
1681 add_function("textureProjGrad",
1682 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1683 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1684 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1685 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1686 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1687 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1688
1689 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1690 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1691 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1692 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1693 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1694 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1695
1696 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1697 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1698 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1699
1700 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1701 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1702 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1703 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1704 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1705 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1706
1707 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1708
1709 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1710 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1711 NULL);
1712
1713 add_function("textureProjGradOffset",
1714 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1715 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1716 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
1717 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1718 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1719 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1720
1721 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1722 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1723 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1724 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1725 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1726 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1727
1728 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1729 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1730 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1731
1732 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1733 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1734 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
1735 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1736 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1737 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1738
1739 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1740
1741 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1742 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
1743 NULL);
1744
1745 add_function("EmitVertex", _EmitVertex(), NULL);
1746 add_function("EndPrimitive", _EndPrimitive(), NULL);
1747 add_function("EmitStreamVertex",
1748 _EmitStreamVertex(gs_streams, glsl_type::uint_type),
1749 _EmitStreamVertex(gs_streams, glsl_type::int_type),
1750 NULL);
1751 add_function("EndStreamPrimitive",
1752 _EndStreamPrimitive(gs_streams, glsl_type::uint_type),
1753 _EndStreamPrimitive(gs_streams, glsl_type::int_type),
1754 NULL);
1755
1756 add_function("textureQueryLOD",
1757 _textureQueryLod(glsl_type::sampler1D_type, glsl_type::float_type),
1758 _textureQueryLod(glsl_type::isampler1D_type, glsl_type::float_type),
1759 _textureQueryLod(glsl_type::usampler1D_type, glsl_type::float_type),
1760
1761 _textureQueryLod(glsl_type::sampler2D_type, glsl_type::vec2_type),
1762 _textureQueryLod(glsl_type::isampler2D_type, glsl_type::vec2_type),
1763 _textureQueryLod(glsl_type::usampler2D_type, glsl_type::vec2_type),
1764
1765 _textureQueryLod(glsl_type::sampler3D_type, glsl_type::vec3_type),
1766 _textureQueryLod(glsl_type::isampler3D_type, glsl_type::vec3_type),
1767 _textureQueryLod(glsl_type::usampler3D_type, glsl_type::vec3_type),
1768
1769 _textureQueryLod(glsl_type::samplerCube_type, glsl_type::vec3_type),
1770 _textureQueryLod(glsl_type::isamplerCube_type, glsl_type::vec3_type),
1771 _textureQueryLod(glsl_type::usamplerCube_type, glsl_type::vec3_type),
1772
1773 _textureQueryLod(glsl_type::sampler1DArray_type, glsl_type::float_type),
1774 _textureQueryLod(glsl_type::isampler1DArray_type, glsl_type::float_type),
1775 _textureQueryLod(glsl_type::usampler1DArray_type, glsl_type::float_type),
1776
1777 _textureQueryLod(glsl_type::sampler2DArray_type, glsl_type::vec2_type),
1778 _textureQueryLod(glsl_type::isampler2DArray_type, glsl_type::vec2_type),
1779 _textureQueryLod(glsl_type::usampler2DArray_type, glsl_type::vec2_type),
1780
1781 _textureQueryLod(glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
1782 _textureQueryLod(glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
1783 _textureQueryLod(glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
1784
1785 _textureQueryLod(glsl_type::sampler1DShadow_type, glsl_type::float_type),
1786 _textureQueryLod(glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
1787 _textureQueryLod(glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
1788 _textureQueryLod(glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
1789 _textureQueryLod(glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
1790 _textureQueryLod(glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
1791 NULL);
1792
1793 add_function("textureQueryLevels",
1794 _textureQueryLevels(glsl_type::sampler1D_type),
1795 _textureQueryLevels(glsl_type::sampler2D_type),
1796 _textureQueryLevels(glsl_type::sampler3D_type),
1797 _textureQueryLevels(glsl_type::samplerCube_type),
1798 _textureQueryLevels(glsl_type::sampler1DArray_type),
1799 _textureQueryLevels(glsl_type::sampler2DArray_type),
1800 _textureQueryLevels(glsl_type::samplerCubeArray_type),
1801 _textureQueryLevels(glsl_type::sampler1DShadow_type),
1802 _textureQueryLevels(glsl_type::sampler2DShadow_type),
1803 _textureQueryLevels(glsl_type::samplerCubeShadow_type),
1804 _textureQueryLevels(glsl_type::sampler1DArrayShadow_type),
1805 _textureQueryLevels(glsl_type::sampler2DArrayShadow_type),
1806 _textureQueryLevels(glsl_type::samplerCubeArrayShadow_type),
1807
1808 _textureQueryLevels(glsl_type::isampler1D_type),
1809 _textureQueryLevels(glsl_type::isampler2D_type),
1810 _textureQueryLevels(glsl_type::isampler3D_type),
1811 _textureQueryLevels(glsl_type::isamplerCube_type),
1812 _textureQueryLevels(glsl_type::isampler1DArray_type),
1813 _textureQueryLevels(glsl_type::isampler2DArray_type),
1814 _textureQueryLevels(glsl_type::isamplerCubeArray_type),
1815
1816 _textureQueryLevels(glsl_type::usampler1D_type),
1817 _textureQueryLevels(glsl_type::usampler2D_type),
1818 _textureQueryLevels(glsl_type::usampler3D_type),
1819 _textureQueryLevels(glsl_type::usamplerCube_type),
1820 _textureQueryLevels(glsl_type::usampler1DArray_type),
1821 _textureQueryLevels(glsl_type::usampler2DArray_type),
1822 _textureQueryLevels(glsl_type::usamplerCubeArray_type),
1823
1824 NULL);
1825
1826 add_function("texture1D",
1827 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1828 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1829 NULL);
1830
1831 add_function("texture1DArray",
1832 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1833 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1834 NULL);
1835
1836 add_function("texture1DProj",
1837 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1838 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1839 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1840 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1841 NULL);
1842
1843 add_function("texture1DLod",
1844 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1845 NULL);
1846
1847 add_function("texture1DArrayLod",
1848 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1849 NULL);
1850
1851 add_function("texture1DProjLod",
1852 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1853 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1854 NULL);
1855
1856 add_function("texture2D",
1857 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1858 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1859 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
1860 NULL);
1861
1862 add_function("texture2DArray",
1863 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1864 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1865 NULL);
1866
1867 add_function("texture2DProj",
1868 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1869 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1870 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1871 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1872 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
1873 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
1874 NULL);
1875
1876 add_function("texture2DLod",
1877 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1878 NULL);
1879
1880 add_function("texture2DArrayLod",
1881 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1882 NULL);
1883
1884 add_function("texture2DProjLod",
1885 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1886 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1887 NULL);
1888
1889 add_function("texture3D",
1890 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1891 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1892 NULL);
1893
1894 add_function("texture3DProj",
1895 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1896 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1897 NULL);
1898
1899 add_function("texture3DLod",
1900 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1901 NULL);
1902
1903 add_function("texture3DProjLod",
1904 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1905 NULL);
1906
1907 add_function("textureCube",
1908 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1909 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1910 NULL);
1911
1912 add_function("textureCubeLod",
1913 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1914 NULL);
1915
1916 add_function("texture2DRect",
1917 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1918 NULL);
1919
1920 add_function("texture2DRectProj",
1921 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1922 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1923 NULL);
1924
1925 add_function("shadow1D",
1926 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1927 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1928 NULL);
1929
1930 add_function("shadow1DArray",
1931 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1932 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1933 NULL);
1934
1935 add_function("shadow2D",
1936 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1937 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1938 NULL);
1939
1940 add_function("shadow2DArray",
1941 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1942 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1943 NULL);
1944
1945 add_function("shadow1DProj",
1946 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1947 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1948 NULL);
1949
1950 add_function("shadow2DProj",
1951 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1952 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1953 NULL);
1954
1955 add_function("shadow1DLod",
1956 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1957 NULL);
1958
1959 add_function("shadow2DLod",
1960 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1961 NULL);
1962
1963 add_function("shadow1DArrayLod",
1964 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1965 NULL);
1966
1967 add_function("shadow1DProjLod",
1968 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1969 NULL);
1970
1971 add_function("shadow2DProjLod",
1972 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1973 NULL);
1974
1975 add_function("shadow2DRect",
1976 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1977 NULL);
1978
1979 add_function("shadow2DRectProj",
1980 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1981 NULL);
1982
1983 add_function("texture1DGradARB",
1984 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1985 NULL);
1986
1987 add_function("texture1DProjGradARB",
1988 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1989 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1990 NULL);
1991
1992 add_function("texture2DGradARB",
1993 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1994 NULL);
1995
1996 add_function("texture2DProjGradARB",
1997 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1998 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1999 NULL);
2000
2001 add_function("texture3DGradARB",
2002 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2003 NULL);
2004
2005 add_function("texture3DProjGradARB",
2006 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2007 NULL);
2008
2009 add_function("textureCubeGradARB",
2010 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2011 NULL);
2012
2013 add_function("shadow1DGradARB",
2014 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2015 NULL);
2016
2017 add_function("shadow1DProjGradARB",
2018 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2019 NULL);
2020
2021 add_function("shadow2DGradARB",
2022 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2023 NULL);
2024
2025 add_function("shadow2DProjGradARB",
2026 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2027 NULL);
2028
2029 add_function("texture2DRectGradARB",
2030 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2031 NULL);
2032
2033 add_function("texture2DRectProjGradARB",
2034 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2035 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2036 NULL);
2037
2038 add_function("shadow2DRectGradARB",
2039 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
2040 NULL);
2041
2042 add_function("shadow2DRectProjGradARB",
2043 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2044 NULL);
2045
2046 add_function("textureGather",
2047 _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2048 _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2049 _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2050
2051 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2052 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
2053 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
2054
2055 _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2056 _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2057 _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2058
2059 _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2060 _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2061 _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2062
2063 _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2064 _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2065 _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2066
2067 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2068 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2069 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2070
2071 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2072 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2073 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2074
2075 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2076 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2077 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2078
2079 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2080 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2081 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2082
2083 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2084 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2085 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2086
2087 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
2088 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type),
2089 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
2090 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec4_type),
2091 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type),
2092 NULL);
2093
2094 add_function("textureGatherOffset",
2095 _texture(ir_tg4, texture_gather_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2096 _texture(ir_tg4, texture_gather_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2097 _texture(ir_tg4, texture_gather_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2098
2099 _texture(ir_tg4, texture_gather_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2100 _texture(ir_tg4, texture_gather_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2101 _texture(ir_tg4, texture_gather_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2102
2103 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2104 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2105 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2106
2107 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2108 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2109 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2110
2111 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2112 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2113 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2114
2115 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2116 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2117 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2118
2119 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2120 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2121 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2122
2123 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2124 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2125 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2126
2127 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2128 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2129 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2130 NULL);
2131
2132 add_function("textureGatherOffsets",
2133 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2134 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2135 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2136
2137 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2138 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2139 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2140
2141 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2142 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2143 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2144
2145 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2146 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2147 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2148
2149 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2150 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2151 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2152
2153 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2154 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2155 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2156
2157 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2158 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2159 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2160 NULL);
2161
2162 F(dFdx)
2163 F(dFdy)
2164 F(fwidth)
2165 F(dFdxCoarse)
2166 F(dFdyCoarse)
2167 F(fwidthCoarse)
2168 F(dFdxFine)
2169 F(dFdyFine)
2170 F(fwidthFine)
2171 F(noise1)
2172 F(noise2)
2173 F(noise3)
2174 F(noise4)
2175
2176 IU(bitfieldExtract)
2177 IU(bitfieldInsert)
2178 IU(bitfieldReverse)
2179 IU(bitCount)
2180 IU(findLSB)
2181 IU(findMSB)
2182 F(fma)
2183
2184 add_function("ldexp",
2185 _ldexp(glsl_type::float_type, glsl_type::int_type),
2186 _ldexp(glsl_type::vec2_type, glsl_type::ivec2_type),
2187 _ldexp(glsl_type::vec3_type, glsl_type::ivec3_type),
2188 _ldexp(glsl_type::vec4_type, glsl_type::ivec4_type),
2189 NULL);
2190
2191 add_function("frexp",
2192 _frexp(glsl_type::float_type, glsl_type::int_type),
2193 _frexp(glsl_type::vec2_type, glsl_type::ivec2_type),
2194 _frexp(glsl_type::vec3_type, glsl_type::ivec3_type),
2195 _frexp(glsl_type::vec4_type, glsl_type::ivec4_type),
2196 NULL);
2197 add_function("uaddCarry",
2198 _uaddCarry(glsl_type::uint_type),
2199 _uaddCarry(glsl_type::uvec2_type),
2200 _uaddCarry(glsl_type::uvec3_type),
2201 _uaddCarry(glsl_type::uvec4_type),
2202 NULL);
2203 add_function("usubBorrow",
2204 _usubBorrow(glsl_type::uint_type),
2205 _usubBorrow(glsl_type::uvec2_type),
2206 _usubBorrow(glsl_type::uvec3_type),
2207 _usubBorrow(glsl_type::uvec4_type),
2208 NULL);
2209 add_function("imulExtended",
2210 _mulExtended(glsl_type::int_type),
2211 _mulExtended(glsl_type::ivec2_type),
2212 _mulExtended(glsl_type::ivec3_type),
2213 _mulExtended(glsl_type::ivec4_type),
2214 NULL);
2215 add_function("umulExtended",
2216 _mulExtended(glsl_type::uint_type),
2217 _mulExtended(glsl_type::uvec2_type),
2218 _mulExtended(glsl_type::uvec3_type),
2219 _mulExtended(glsl_type::uvec4_type),
2220 NULL);
2221 add_function("interpolateAtCentroid",
2222 _interpolateAtCentroid(glsl_type::float_type),
2223 _interpolateAtCentroid(glsl_type::vec2_type),
2224 _interpolateAtCentroid(glsl_type::vec3_type),
2225 _interpolateAtCentroid(glsl_type::vec4_type),
2226 NULL);
2227 add_function("interpolateAtOffset",
2228 _interpolateAtOffset(glsl_type::float_type),
2229 _interpolateAtOffset(glsl_type::vec2_type),
2230 _interpolateAtOffset(glsl_type::vec3_type),
2231 _interpolateAtOffset(glsl_type::vec4_type),
2232 NULL);
2233 add_function("interpolateAtSample",
2234 _interpolateAtSample(glsl_type::float_type),
2235 _interpolateAtSample(glsl_type::vec2_type),
2236 _interpolateAtSample(glsl_type::vec3_type),
2237 _interpolateAtSample(glsl_type::vec4_type),
2238 NULL);
2239
2240 add_function("atomicCounter",
2241 _atomic_op("__intrinsic_atomic_read",
2242 shader_atomic_counters),
2243 NULL);
2244 add_function("atomicCounterIncrement",
2245 _atomic_op("__intrinsic_atomic_increment",
2246 shader_atomic_counters),
2247 NULL);
2248 add_function("atomicCounterDecrement",
2249 _atomic_op("__intrinsic_atomic_predecrement",
2250 shader_atomic_counters),
2251 NULL);
2252
2253 add_function("min3",
2254 _min3(glsl_type::float_type),
2255 _min3(glsl_type::vec2_type),
2256 _min3(glsl_type::vec3_type),
2257 _min3(glsl_type::vec4_type),
2258
2259 _min3(glsl_type::int_type),
2260 _min3(glsl_type::ivec2_type),
2261 _min3(glsl_type::ivec3_type),
2262 _min3(glsl_type::ivec4_type),
2263
2264 _min3(glsl_type::uint_type),
2265 _min3(glsl_type::uvec2_type),
2266 _min3(glsl_type::uvec3_type),
2267 _min3(glsl_type::uvec4_type),
2268 NULL);
2269
2270 add_function("max3",
2271 _max3(glsl_type::float_type),
2272 _max3(glsl_type::vec2_type),
2273 _max3(glsl_type::vec3_type),
2274 _max3(glsl_type::vec4_type),
2275
2276 _max3(glsl_type::int_type),
2277 _max3(glsl_type::ivec2_type),
2278 _max3(glsl_type::ivec3_type),
2279 _max3(glsl_type::ivec4_type),
2280
2281 _max3(glsl_type::uint_type),
2282 _max3(glsl_type::uvec2_type),
2283 _max3(glsl_type::uvec3_type),
2284 _max3(glsl_type::uvec4_type),
2285 NULL);
2286
2287 add_function("mid3",
2288 _mid3(glsl_type::float_type),
2289 _mid3(glsl_type::vec2_type),
2290 _mid3(glsl_type::vec3_type),
2291 _mid3(glsl_type::vec4_type),
2292
2293 _mid3(glsl_type::int_type),
2294 _mid3(glsl_type::ivec2_type),
2295 _mid3(glsl_type::ivec3_type),
2296 _mid3(glsl_type::ivec4_type),
2297
2298 _mid3(glsl_type::uint_type),
2299 _mid3(glsl_type::uvec2_type),
2300 _mid3(glsl_type::uvec3_type),
2301 _mid3(glsl_type::uvec4_type),
2302 NULL);
2303
2304 add_image_functions(true);
2305
2306 add_function("memoryBarrier",
2307 _memory_barrier(shader_image_load_store),
2308 NULL);
2309
2310 #undef F
2311 #undef FI
2312 #undef FIU
2313 #undef FIUB
2314 #undef FIU2_MIXED
2315 }
2316
2317 void
2318 builtin_builder::add_function(const char *name, ...)
2319 {
2320 va_list ap;
2321
2322 ir_function *f = new(mem_ctx) ir_function(name);
2323
2324 va_start(ap, name);
2325 while (true) {
2326 ir_function_signature *sig = va_arg(ap, ir_function_signature *);
2327 if (sig == NULL)
2328 break;
2329
2330 if (false) {
2331 exec_list stuff;
2332 stuff.push_tail(sig);
2333 validate_ir_tree(&stuff);
2334 }
2335
2336 f->add_signature(sig);
2337 }
2338 va_end(ap);
2339
2340 shader->symbols->add_function(f);
2341 }
2342
2343 void
2344 builtin_builder::add_image_function(const char *name,
2345 const char *intrinsic_name,
2346 unsigned num_arguments,
2347 unsigned flags)
2348 {
2349 static const glsl_type *const types[] = {
2350 glsl_type::image1D_type,
2351 glsl_type::image2D_type,
2352 glsl_type::image3D_type,
2353 glsl_type::image2DRect_type,
2354 glsl_type::imageCube_type,
2355 glsl_type::imageBuffer_type,
2356 glsl_type::image1DArray_type,
2357 glsl_type::image2DArray_type,
2358 glsl_type::imageCubeArray_type,
2359 glsl_type::image2DMS_type,
2360 glsl_type::image2DMSArray_type,
2361 glsl_type::iimage1D_type,
2362 glsl_type::iimage2D_type,
2363 glsl_type::iimage3D_type,
2364 glsl_type::iimage2DRect_type,
2365 glsl_type::iimageCube_type,
2366 glsl_type::iimageBuffer_type,
2367 glsl_type::iimage1DArray_type,
2368 glsl_type::iimage2DArray_type,
2369 glsl_type::iimageCubeArray_type,
2370 glsl_type::iimage2DMS_type,
2371 glsl_type::iimage2DMSArray_type,
2372 glsl_type::uimage1D_type,
2373 glsl_type::uimage2D_type,
2374 glsl_type::uimage3D_type,
2375 glsl_type::uimage2DRect_type,
2376 glsl_type::uimageCube_type,
2377 glsl_type::uimageBuffer_type,
2378 glsl_type::uimage1DArray_type,
2379 glsl_type::uimage2DArray_type,
2380 glsl_type::uimageCubeArray_type,
2381 glsl_type::uimage2DMS_type,
2382 glsl_type::uimage2DMSArray_type
2383 };
2384 ir_function *f = new(mem_ctx) ir_function(name);
2385
2386 for (unsigned i = 0; i < Elements(types); ++i) {
2387 if (types[i]->sampler_type != GLSL_TYPE_FLOAT ||
2388 (flags & IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE))
2389 f->add_signature(_image(types[i], intrinsic_name,
2390 num_arguments, flags));
2391 }
2392
2393 shader->symbols->add_function(f);
2394 }
2395
2396 void
2397 builtin_builder::add_image_functions(bool glsl)
2398 {
2399 const unsigned flags = (glsl ? IMAGE_FUNCTION_EMIT_STUB : 0);
2400
2401 add_image_function(glsl ? "imageLoad" : "__intrinsic_image_load",
2402 "__intrinsic_image_load", 0,
2403 (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
2404 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
2405 IMAGE_FUNCTION_READ_ONLY));
2406
2407 add_image_function(glsl ? "imageStore" : "__intrinsic_image_store",
2408 "__intrinsic_image_store", 1,
2409 (flags | IMAGE_FUNCTION_RETURNS_VOID |
2410 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
2411 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
2412 IMAGE_FUNCTION_WRITE_ONLY));
2413
2414 add_image_function(glsl ? "imageAtomicAdd" : "__intrinsic_image_atomic_add",
2415 "__intrinsic_image_atomic_add", 1, flags);
2416
2417 add_image_function(glsl ? "imageAtomicMin" : "__intrinsic_image_atomic_min",
2418 "__intrinsic_image_atomic_min", 1, flags);
2419
2420 add_image_function(glsl ? "imageAtomicMax" : "__intrinsic_image_atomic_max",
2421 "__intrinsic_image_atomic_max", 1, flags);
2422
2423 add_image_function(glsl ? "imageAtomicAnd" : "__intrinsic_image_atomic_and",
2424 "__intrinsic_image_atomic_and", 1, flags);
2425
2426 add_image_function(glsl ? "imageAtomicOr" : "__intrinsic_image_atomic_or",
2427 "__intrinsic_image_atomic_or", 1, flags);
2428
2429 add_image_function(glsl ? "imageAtomicXor" : "__intrinsic_image_atomic_xor",
2430 "__intrinsic_image_atomic_xor", 1, flags);
2431
2432 add_image_function((glsl ? "imageAtomicExchange" :
2433 "__intrinsic_image_atomic_exchange"),
2434 "__intrinsic_image_atomic_exchange", 1, flags);
2435
2436 add_image_function((glsl ? "imageAtomicCompSwap" :
2437 "__intrinsic_image_atomic_comp_swap"),
2438 "__intrinsic_image_atomic_comp_swap", 2, flags);
2439 }
2440
2441 ir_variable *
2442 builtin_builder::in_var(const glsl_type *type, const char *name)
2443 {
2444 return new(mem_ctx) ir_variable(type, name, ir_var_function_in);
2445 }
2446
2447 ir_variable *
2448 builtin_builder::out_var(const glsl_type *type, const char *name)
2449 {
2450 return new(mem_ctx) ir_variable(type, name, ir_var_function_out);
2451 }
2452
2453 ir_constant *
2454 builtin_builder::imm(float f, unsigned vector_elements)
2455 {
2456 return new(mem_ctx) ir_constant(f, vector_elements);
2457 }
2458
2459 ir_constant *
2460 builtin_builder::imm(int i, unsigned vector_elements)
2461 {
2462 return new(mem_ctx) ir_constant(i, vector_elements);
2463 }
2464
2465 ir_constant *
2466 builtin_builder::imm(unsigned u, unsigned vector_elements)
2467 {
2468 return new(mem_ctx) ir_constant(u, vector_elements);
2469 }
2470
2471 ir_constant *
2472 builtin_builder::imm(const glsl_type *type, const ir_constant_data &data)
2473 {
2474 return new(mem_ctx) ir_constant(type, &data);
2475 }
2476
2477 ir_dereference_variable *
2478 builtin_builder::var_ref(ir_variable *var)
2479 {
2480 return new(mem_ctx) ir_dereference_variable(var);
2481 }
2482
2483 ir_dereference_array *
2484 builtin_builder::array_ref(ir_variable *var, int idx)
2485 {
2486 return new(mem_ctx) ir_dereference_array(var, imm(idx));
2487 }
2488
2489 /** Return an element of a matrix */
2490 ir_swizzle *
2491 builtin_builder::matrix_elt(ir_variable *var, int column, int row)
2492 {
2493 return swizzle(array_ref(var, column), row, 1);
2494 }
2495
2496 /**
2497 * Implementations of built-in functions:
2498 * @{
2499 */
2500 ir_function_signature *
2501 builtin_builder::new_sig(const glsl_type *return_type,
2502 builtin_available_predicate avail,
2503 int num_params,
2504 ...)
2505 {
2506 va_list ap;
2507
2508 ir_function_signature *sig =
2509 new(mem_ctx) ir_function_signature(return_type, avail);
2510
2511 exec_list plist;
2512 va_start(ap, num_params);
2513 for (int i = 0; i < num_params; i++) {
2514 plist.push_tail(va_arg(ap, ir_variable *));
2515 }
2516 va_end(ap);
2517
2518 sig->replace_parameters(&plist);
2519 return sig;
2520 }
2521
2522 #define MAKE_SIG(return_type, avail, ...) \
2523 ir_function_signature *sig = \
2524 new_sig(return_type, avail, __VA_ARGS__); \
2525 ir_factory body(&sig->body, mem_ctx); \
2526 sig->is_defined = true;
2527
2528 #define MAKE_INTRINSIC(return_type, avail, ...) \
2529 ir_function_signature *sig = \
2530 new_sig(return_type, avail, __VA_ARGS__); \
2531 sig->is_intrinsic = true;
2532
2533 ir_function_signature *
2534 builtin_builder::unop(builtin_available_predicate avail,
2535 ir_expression_operation opcode,
2536 const glsl_type *return_type,
2537 const glsl_type *param_type)
2538 {
2539 ir_variable *x = in_var(param_type, "x");
2540 MAKE_SIG(return_type, avail, 1, x);
2541 body.emit(ret(expr(opcode, x)));
2542 return sig;
2543 }
2544
2545 #define UNOP(NAME, OPCODE, AVAIL) \
2546 ir_function_signature * \
2547 builtin_builder::_##NAME(const glsl_type *type) \
2548 { \
2549 return unop(&AVAIL, OPCODE, type, type); \
2550 }
2551
2552 ir_function_signature *
2553 builtin_builder::binop(ir_expression_operation opcode,
2554 builtin_available_predicate avail,
2555 const glsl_type *return_type,
2556 const glsl_type *param0_type,
2557 const glsl_type *param1_type)
2558 {
2559 ir_variable *x = in_var(param0_type, "x");
2560 ir_variable *y = in_var(param1_type, "y");
2561 MAKE_SIG(return_type, avail, 2, x, y);
2562 body.emit(ret(expr(opcode, x, y)));
2563 return sig;
2564 }
2565
2566 #define BINOP(NAME, OPCODE, AVAIL) \
2567 ir_function_signature * \
2568 builtin_builder::_##NAME(const glsl_type *return_type, \
2569 const glsl_type *param0_type, \
2570 const glsl_type *param1_type) \
2571 { \
2572 return binop(&AVAIL, OPCODE, return_type, param0_type, param1_type); \
2573 }
2574
2575 /**
2576 * Angle and Trigonometry Functions @{
2577 */
2578
2579 ir_function_signature *
2580 builtin_builder::_radians(const glsl_type *type)
2581 {
2582 ir_variable *degrees = in_var(type, "degrees");
2583 MAKE_SIG(type, always_available, 1, degrees);
2584 body.emit(ret(mul(degrees, imm(0.0174532925f))));
2585 return sig;
2586 }
2587
2588 ir_function_signature *
2589 builtin_builder::_degrees(const glsl_type *type)
2590 {
2591 ir_variable *radians = in_var(type, "radians");
2592 MAKE_SIG(type, always_available, 1, radians);
2593 body.emit(ret(mul(radians, imm(57.29578f))));
2594 return sig;
2595 }
2596
2597 UNOP(sin, ir_unop_sin, always_available)
2598 UNOP(cos, ir_unop_cos, always_available)
2599
2600 ir_function_signature *
2601 builtin_builder::_tan(const glsl_type *type)
2602 {
2603 ir_variable *theta = in_var(type, "theta");
2604 MAKE_SIG(type, always_available, 1, theta);
2605 body.emit(ret(div(sin(theta), cos(theta))));
2606 return sig;
2607 }
2608
2609 ir_expression *
2610 builtin_builder::asin_expr(ir_variable *x)
2611 {
2612 return mul(sign(x),
2613 sub(imm(M_PI_2f),
2614 mul(sqrt(sub(imm(1.0f), abs(x))),
2615 add(imm(M_PI_2f),
2616 mul(abs(x),
2617 add(imm(M_PI_4f - 1.0f),
2618 mul(abs(x),
2619 add(imm(0.086566724f),
2620 mul(abs(x), imm(-0.03102955f))))))))));
2621 }
2622
2623 ir_call *
2624 builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)
2625 {
2626 exec_list actual_params;
2627
2628 foreach_in_list(ir_variable, var, &params) {
2629 actual_params.push_tail(var_ref(var));
2630 }
2631
2632 ir_function_signature *sig =
2633 f->exact_matching_signature(NULL, &actual_params);
2634 if (!sig)
2635 return NULL;
2636
2637 ir_dereference_variable *deref =
2638 (sig->return_type->is_void() ? NULL : var_ref(ret));
2639
2640 return new(mem_ctx) ir_call(sig, deref, &actual_params);
2641 }
2642
2643 ir_function_signature *
2644 builtin_builder::_asin(const glsl_type *type)
2645 {
2646 ir_variable *x = in_var(type, "x");
2647 MAKE_SIG(type, always_available, 1, x);
2648
2649 body.emit(ret(asin_expr(x)));
2650
2651 return sig;
2652 }
2653
2654 ir_function_signature *
2655 builtin_builder::_acos(const glsl_type *type)
2656 {
2657 ir_variable *x = in_var(type, "x");
2658 MAKE_SIG(type, always_available, 1, x);
2659
2660 body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
2661
2662 return sig;
2663 }
2664
2665 ir_function_signature *
2666 builtin_builder::_atan2(const glsl_type *type)
2667 {
2668 ir_variable *vec_y = in_var(type, "vec_y");
2669 ir_variable *vec_x = in_var(type, "vec_x");
2670 MAKE_SIG(type, always_available, 2, vec_y, vec_x);
2671
2672 ir_variable *vec_result = body.make_temp(type, "vec_result");
2673 ir_variable *r = body.make_temp(glsl_type::float_type, "r");
2674 for (int i = 0; i < type->vector_elements; i++) {
2675 ir_variable *y = body.make_temp(glsl_type::float_type, "y");
2676 ir_variable *x = body.make_temp(glsl_type::float_type, "x");
2677 body.emit(assign(y, swizzle(vec_y, i, 1)));
2678 body.emit(assign(x, swizzle(vec_x, i, 1)));
2679
2680 /* If |x| >= 1.0e-8 * |y|: */
2681 ir_if *outer_if =
2682 new(mem_ctx) ir_if(greater(abs(x), mul(imm(1.0e-8f), abs(y))));
2683
2684 ir_factory outer_then(&outer_if->then_instructions, mem_ctx);
2685
2686 /* Then...call atan(y/x) */
2687 ir_variable *y_over_x = outer_then.make_temp(glsl_type::float_type, "y_over_x");
2688 outer_then.emit(assign(y_over_x, div(y, x)));
2689 outer_then.emit(assign(r, mul(y_over_x, rsq(add(mul(y_over_x, y_over_x),
2690 imm(1.0f))))));
2691 outer_then.emit(assign(r, asin_expr(r)));
2692
2693 /* ...and fix it up: */
2694 ir_if *inner_if = new(mem_ctx) ir_if(less(x, imm(0.0f)));
2695 inner_if->then_instructions.push_tail(
2696 if_tree(gequal(y, imm(0.0f)),
2697 assign(r, add(r, imm(M_PIf))),
2698 assign(r, sub(r, imm(M_PIf)))));
2699 outer_then.emit(inner_if);
2700
2701 /* Else... */
2702 outer_if->else_instructions.push_tail(
2703 assign(r, mul(sign(y), imm(M_PI_2f))));
2704
2705 body.emit(outer_if);
2706
2707 body.emit(assign(vec_result, r, 1 << i));
2708 }
2709 body.emit(ret(vec_result));
2710
2711 return sig;
2712 }
2713
2714 ir_function_signature *
2715 builtin_builder::_atan(const glsl_type *type)
2716 {
2717 ir_variable *y_over_x = in_var(type, "y_over_x");
2718 MAKE_SIG(type, always_available, 1, y_over_x);
2719
2720 ir_variable *t = body.make_temp(type, "t");
2721 body.emit(assign(t, mul(y_over_x, rsq(add(mul(y_over_x, y_over_x),
2722 imm(1.0f))))));
2723
2724 body.emit(ret(asin_expr(t)));
2725
2726 return sig;
2727 }
2728
2729 ir_function_signature *
2730 builtin_builder::_sinh(const glsl_type *type)
2731 {
2732 ir_variable *x = in_var(type, "x");
2733 MAKE_SIG(type, v130, 1, x);
2734
2735 /* 0.5 * (e^x - e^(-x)) */
2736 body.emit(ret(mul(imm(0.5f), sub(exp(x), exp(neg(x))))));
2737
2738 return sig;
2739 }
2740
2741 ir_function_signature *
2742 builtin_builder::_cosh(const glsl_type *type)
2743 {
2744 ir_variable *x = in_var(type, "x");
2745 MAKE_SIG(type, v130, 1, x);
2746
2747 /* 0.5 * (e^x + e^(-x)) */
2748 body.emit(ret(mul(imm(0.5f), add(exp(x), exp(neg(x))))));
2749
2750 return sig;
2751 }
2752
2753 ir_function_signature *
2754 builtin_builder::_tanh(const glsl_type *type)
2755 {
2756 ir_variable *x = in_var(type, "x");
2757 MAKE_SIG(type, v130, 1, x);
2758
2759 /* (e^x - e^(-x)) / (e^x + e^(-x)) */
2760 body.emit(ret(div(sub(exp(x), exp(neg(x))),
2761 add(exp(x), exp(neg(x))))));
2762
2763 return sig;
2764 }
2765
2766 ir_function_signature *
2767 builtin_builder::_asinh(const glsl_type *type)
2768 {
2769 ir_variable *x = in_var(type, "x");
2770 MAKE_SIG(type, v130, 1, x);
2771
2772 body.emit(ret(mul(sign(x), log(add(abs(x), sqrt(add(mul(x, x),
2773 imm(1.0f))))))));
2774 return sig;
2775 }
2776
2777 ir_function_signature *
2778 builtin_builder::_acosh(const glsl_type *type)
2779 {
2780 ir_variable *x = in_var(type, "x");
2781 MAKE_SIG(type, v130, 1, x);
2782
2783 body.emit(ret(log(add(x, sqrt(sub(mul(x, x), imm(1.0f)))))));
2784 return sig;
2785 }
2786
2787 ir_function_signature *
2788 builtin_builder::_atanh(const glsl_type *type)
2789 {
2790 ir_variable *x = in_var(type, "x");
2791 MAKE_SIG(type, v130, 1, x);
2792
2793 body.emit(ret(mul(imm(0.5f), log(div(add(imm(1.0f), x),
2794 sub(imm(1.0f), x))))));
2795 return sig;
2796 }
2797 /** @} */
2798
2799 /**
2800 * Exponential Functions @{
2801 */
2802
2803 ir_function_signature *
2804 builtin_builder::_pow(const glsl_type *type)
2805 {
2806 return binop(ir_binop_pow, always_available, type, type, type);
2807 }
2808
2809 UNOP(exp, ir_unop_exp, always_available)
2810 UNOP(log, ir_unop_log, always_available)
2811 UNOP(exp2, ir_unop_exp2, always_available)
2812 UNOP(log2, ir_unop_log2, always_available)
2813 UNOP(sqrt, ir_unop_sqrt, always_available)
2814 UNOP(inversesqrt, ir_unop_rsq, always_available)
2815
2816 /** @} */
2817
2818 UNOP(abs, ir_unop_abs, always_available)
2819 UNOP(sign, ir_unop_sign, always_available)
2820 UNOP(floor, ir_unop_floor, always_available)
2821 UNOP(trunc, ir_unop_trunc, v130)
2822 UNOP(round, ir_unop_round_even, always_available)
2823 UNOP(roundEven, ir_unop_round_even, always_available)
2824 UNOP(ceil, ir_unop_ceil, always_available)
2825 UNOP(fract, ir_unop_fract, always_available)
2826
2827 ir_function_signature *
2828 builtin_builder::_mod(const glsl_type *x_type, const glsl_type *y_type)
2829 {
2830 return binop(ir_binop_mod, always_available, x_type, x_type, y_type);
2831 }
2832
2833 ir_function_signature *
2834 builtin_builder::_modf(const glsl_type *type)
2835 {
2836 ir_variable *x = in_var(type, "x");
2837 ir_variable *i = out_var(type, "i");
2838 MAKE_SIG(type, v130, 2, x, i);
2839
2840 ir_variable *t = body.make_temp(type, "t");
2841 body.emit(assign(t, expr(ir_unop_trunc, x)));
2842 body.emit(assign(i, t));
2843 body.emit(ret(sub(x, t)));
2844
2845 return sig;
2846 }
2847
2848 ir_function_signature *
2849 builtin_builder::_min(builtin_available_predicate avail,
2850 const glsl_type *x_type, const glsl_type *y_type)
2851 {
2852 return binop(ir_binop_min, avail, x_type, x_type, y_type);
2853 }
2854
2855 ir_function_signature *
2856 builtin_builder::_max(builtin_available_predicate avail,
2857 const glsl_type *x_type, const glsl_type *y_type)
2858 {
2859 return binop(ir_binop_max, avail, x_type, x_type, y_type);
2860 }
2861
2862 ir_function_signature *
2863 builtin_builder::_clamp(builtin_available_predicate avail,
2864 const glsl_type *val_type, const glsl_type *bound_type)
2865 {
2866 ir_variable *x = in_var(val_type, "x");
2867 ir_variable *minVal = in_var(bound_type, "minVal");
2868 ir_variable *maxVal = in_var(bound_type, "maxVal");
2869 MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
2870
2871 body.emit(ret(clamp(x, minVal, maxVal)));
2872
2873 return sig;
2874 }
2875
2876 ir_function_signature *
2877 builtin_builder::_mix_lrp(const glsl_type *val_type, const glsl_type *blend_type)
2878 {
2879 ir_variable *x = in_var(val_type, "x");
2880 ir_variable *y = in_var(val_type, "y");
2881 ir_variable *a = in_var(blend_type, "a");
2882 MAKE_SIG(val_type, always_available, 3, x, y, a);
2883
2884 body.emit(ret(lrp(x, y, a)));
2885
2886 return sig;
2887 }
2888
2889 ir_function_signature *
2890 builtin_builder::_mix_sel(builtin_available_predicate avail,
2891 const glsl_type *val_type,
2892 const glsl_type *blend_type)
2893 {
2894 ir_variable *x = in_var(val_type, "x");
2895 ir_variable *y = in_var(val_type, "y");
2896 ir_variable *a = in_var(blend_type, "a");
2897 MAKE_SIG(val_type, avail, 3, x, y, a);
2898
2899 /* csel matches the ternary operator in that a selector of true choses the
2900 * first argument. This differs from mix(x, y, false) which choses the
2901 * second argument (to remain consistent with the interpolating version of
2902 * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
2903 *
2904 * To handle the behavior mismatch, reverse the x and y arguments.
2905 */
2906 body.emit(ret(csel(a, y, x)));
2907
2908 return sig;
2909 }
2910
2911 ir_function_signature *
2912 builtin_builder::_step(const glsl_type *edge_type, const glsl_type *x_type)
2913 {
2914 ir_variable *edge = in_var(edge_type, "edge");
2915 ir_variable *x = in_var(x_type, "x");
2916 MAKE_SIG(x_type, always_available, 2, edge, x);
2917
2918 ir_variable *t = body.make_temp(x_type, "t");
2919 if (x_type->vector_elements == 1) {
2920 /* Both are floats */
2921 body.emit(assign(t, b2f(gequal(x, edge))));
2922 } else if (edge_type->vector_elements == 1) {
2923 /* x is a vector but edge is a float */
2924 for (int i = 0; i < x_type->vector_elements; i++) {
2925 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
2926 }
2927 } else {
2928 /* Both are vectors */
2929 for (int i = 0; i < x_type->vector_elements; i++) {
2930 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
2931 1 << i));
2932 }
2933 }
2934 body.emit(ret(t));
2935
2936 return sig;
2937 }
2938
2939 ir_function_signature *
2940 builtin_builder::_smoothstep(const glsl_type *edge_type, const glsl_type *x_type)
2941 {
2942 ir_variable *edge0 = in_var(edge_type, "edge0");
2943 ir_variable *edge1 = in_var(edge_type, "edge1");
2944 ir_variable *x = in_var(x_type, "x");
2945 MAKE_SIG(x_type, always_available, 3, edge0, edge1, x);
2946
2947 /* From the GLSL 1.10 specification:
2948 *
2949 * genType t;
2950 * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
2951 * return t * t * (3 - 2 * t);
2952 */
2953
2954 ir_variable *t = body.make_temp(x_type, "t");
2955 body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
2956 imm(0.0f), imm(1.0f))));
2957
2958 body.emit(ret(mul(t, mul(t, sub(imm(3.0f), mul(imm(2.0f), t))))));
2959
2960 return sig;
2961 }
2962
2963 ir_function_signature *
2964 builtin_builder::_isnan(const glsl_type *type)
2965 {
2966 ir_variable *x = in_var(type, "x");
2967 MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
2968
2969 body.emit(ret(nequal(x, x)));
2970
2971 return sig;
2972 }
2973
2974 ir_function_signature *
2975 builtin_builder::_isinf(const glsl_type *type)
2976 {
2977 ir_variable *x = in_var(type, "x");
2978 MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
2979
2980 ir_constant_data infinities;
2981 for (int i = 0; i < type->vector_elements; i++) {
2982 infinities.f[i] = std::numeric_limits<float>::infinity();
2983 }
2984
2985 body.emit(ret(equal(abs(x), imm(type, infinities))));
2986
2987 return sig;
2988 }
2989
2990 ir_function_signature *
2991 builtin_builder::_floatBitsToInt(const glsl_type *type)
2992 {
2993 ir_variable *x = in_var(type, "x");
2994 MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
2995 body.emit(ret(bitcast_f2i(x)));
2996 return sig;
2997 }
2998
2999 ir_function_signature *
3000 builtin_builder::_floatBitsToUint(const glsl_type *type)
3001 {
3002 ir_variable *x = in_var(type, "x");
3003 MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
3004 body.emit(ret(bitcast_f2u(x)));
3005 return sig;
3006 }
3007
3008 ir_function_signature *
3009 builtin_builder::_intBitsToFloat(const glsl_type *type)
3010 {
3011 ir_variable *x = in_var(type, "x");
3012 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
3013 body.emit(ret(bitcast_i2f(x)));
3014 return sig;
3015 }
3016
3017 ir_function_signature *
3018 builtin_builder::_uintBitsToFloat(const glsl_type *type)
3019 {
3020 ir_variable *x = in_var(type, "x");
3021 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
3022 body.emit(ret(bitcast_u2f(x)));
3023 return sig;
3024 }
3025
3026 ir_function_signature *
3027 builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
3028 {
3029 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3030 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3031 body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
3032 return sig;
3033 }
3034
3035 ir_function_signature *
3036 builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
3037 {
3038 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3039 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3040 body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
3041 return sig;
3042 }
3043
3044 ir_function_signature *
3045 builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
3046 {
3047 ir_variable *v = in_var(glsl_type::vec4_type, "v");
3048 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3049 body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
3050 return sig;
3051 }
3052
3053 ir_function_signature *
3054 builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
3055 {
3056 ir_variable *v = in_var(glsl_type::vec4_type, "v");
3057 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3058 body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
3059 return sig;
3060 }
3061
3062 ir_function_signature *
3063 builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
3064 {
3065 ir_variable *p = in_var(glsl_type::uint_type, "p");
3066 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3067 body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
3068 return sig;
3069 }
3070
3071 ir_function_signature *
3072 builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
3073 {
3074 ir_variable *p = in_var(glsl_type::uint_type, "p");
3075 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3076 body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
3077 return sig;
3078 }
3079
3080
3081 ir_function_signature *
3082 builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
3083 {
3084 ir_variable *p = in_var(glsl_type::uint_type, "p");
3085 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
3086 body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
3087 return sig;
3088 }
3089
3090 ir_function_signature *
3091 builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
3092 {
3093 ir_variable *p = in_var(glsl_type::uint_type, "p");
3094 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
3095 body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
3096 return sig;
3097 }
3098
3099 ir_function_signature *
3100 builtin_builder::_packHalf2x16(builtin_available_predicate avail)
3101 {
3102 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3103 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3104 body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
3105 return sig;
3106 }
3107
3108 ir_function_signature *
3109 builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
3110 {
3111 ir_variable *p = in_var(glsl_type::uint_type, "p");
3112 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3113 body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
3114 return sig;
3115 }
3116
3117 ir_function_signature *
3118 builtin_builder::_length(const glsl_type *type)
3119 {
3120 ir_variable *x = in_var(type, "x");
3121 MAKE_SIG(glsl_type::float_type, always_available, 1, x);
3122
3123 body.emit(ret(sqrt(dot(x, x))));
3124
3125 return sig;
3126 }
3127
3128 ir_function_signature *
3129 builtin_builder::_distance(const glsl_type *type)
3130 {
3131 ir_variable *p0 = in_var(type, "p0");
3132 ir_variable *p1 = in_var(type, "p1");
3133 MAKE_SIG(glsl_type::float_type, always_available, 2, p0, p1);
3134
3135 if (type->vector_elements == 1) {
3136 body.emit(ret(abs(sub(p0, p1))));
3137 } else {
3138 ir_variable *p = body.make_temp(type, "p");
3139 body.emit(assign(p, sub(p0, p1)));
3140 body.emit(ret(sqrt(dot(p, p))));
3141 }
3142
3143 return sig;
3144 }
3145
3146 ir_function_signature *
3147 builtin_builder::_dot(const glsl_type *type)
3148 {
3149 if (type->vector_elements == 1)
3150 return binop(ir_binop_mul, always_available, type, type, type);
3151
3152 return binop(ir_binop_dot, always_available,
3153 glsl_type::float_type, type, type);
3154 }
3155
3156 ir_function_signature *
3157 builtin_builder::_cross(const glsl_type *type)
3158 {
3159 ir_variable *a = in_var(type, "a");
3160 ir_variable *b = in_var(type, "b");
3161 MAKE_SIG(type, always_available, 2, a, b);
3162
3163 int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
3164 int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
3165
3166 body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
3167 mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
3168
3169 return sig;
3170 }
3171
3172 ir_function_signature *
3173 builtin_builder::_normalize(const glsl_type *type)
3174 {
3175 ir_variable *x = in_var(type, "x");
3176 MAKE_SIG(type, always_available, 1, x);
3177
3178 if (type->vector_elements == 1) {
3179 body.emit(ret(sign(x)));
3180 } else {
3181 body.emit(ret(mul(x, rsq(dot(x, x)))));
3182 }
3183
3184 return sig;
3185 }
3186
3187 ir_function_signature *
3188 builtin_builder::_ftransform()
3189 {
3190 MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
3191
3192 body.emit(ret(new(mem_ctx) ir_expression(ir_binop_mul,
3193 glsl_type::vec4_type,
3194 var_ref(gl_ModelViewProjectionMatrix),
3195 var_ref(gl_Vertex))));
3196
3197 /* FINISHME: Once the ir_expression() constructor handles type inference
3198 * for matrix operations, we can simplify this to:
3199 *
3200 * body.emit(ret(mul(gl_ModelViewProjectionMatrix, gl_Vertex)));
3201 */
3202 return sig;
3203 }
3204
3205 ir_function_signature *
3206 builtin_builder::_faceforward(const glsl_type *type)
3207 {
3208 ir_variable *N = in_var(type, "N");
3209 ir_variable *I = in_var(type, "I");
3210 ir_variable *Nref = in_var(type, "Nref");
3211 MAKE_SIG(type, always_available, 3, N, I, Nref);
3212
3213 body.emit(if_tree(less(dot(Nref, I), imm(0.0f)),
3214 ret(N), ret(neg(N))));
3215
3216 return sig;
3217 }
3218
3219 ir_function_signature *
3220 builtin_builder::_reflect(const glsl_type *type)
3221 {
3222 ir_variable *I = in_var(type, "I");
3223 ir_variable *N = in_var(type, "N");
3224 MAKE_SIG(type, always_available, 2, I, N);
3225
3226 /* I - 2 * dot(N, I) * N */
3227 body.emit(ret(sub(I, mul(imm(2.0f), mul(dot(N, I), N)))));
3228
3229 return sig;
3230 }
3231
3232 ir_function_signature *
3233 builtin_builder::_refract(const glsl_type *type)
3234 {
3235 ir_variable *I = in_var(type, "I");
3236 ir_variable *N = in_var(type, "N");
3237 ir_variable *eta = in_var(glsl_type::float_type, "eta");
3238 MAKE_SIG(type, always_available, 3, I, N, eta);
3239
3240 ir_variable *n_dot_i = body.make_temp(glsl_type::float_type, "n_dot_i");
3241 body.emit(assign(n_dot_i, dot(N, I)));
3242
3243 /* From the GLSL 1.10 specification:
3244 * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
3245 * if (k < 0.0)
3246 * return genType(0.0)
3247 * else
3248 * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
3249 */
3250 ir_variable *k = body.make_temp(glsl_type::float_type, "k");
3251 body.emit(assign(k, sub(imm(1.0f),
3252 mul(eta, mul(eta, sub(imm(1.0f),
3253 mul(n_dot_i, n_dot_i)))))));
3254 body.emit(if_tree(less(k, imm(0.0f)),
3255 ret(ir_constant::zero(mem_ctx, type)),
3256 ret(sub(mul(eta, I),
3257 mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
3258
3259 return sig;
3260 }
3261
3262 ir_function_signature *
3263 builtin_builder::_matrixCompMult(const glsl_type *type)
3264 {
3265 ir_variable *x = in_var(type, "x");
3266 ir_variable *y = in_var(type, "y");
3267 MAKE_SIG(type, always_available, 2, x, y);
3268
3269 ir_variable *z = body.make_temp(type, "z");
3270 for (int i = 0; i < type->matrix_columns; i++) {
3271 body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
3272 }
3273 body.emit(ret(z));
3274
3275 return sig;
3276 }
3277
3278 ir_function_signature *
3279 builtin_builder::_outerProduct(const glsl_type *type)
3280 {
3281 ir_variable *c = in_var(glsl_type::vec(type->vector_elements), "c");
3282 ir_variable *r = in_var(glsl_type::vec(type->matrix_columns), "r");
3283 MAKE_SIG(type, v120, 2, c, r);
3284
3285 ir_variable *m = body.make_temp(type, "m");
3286 for (int i = 0; i < type->matrix_columns; i++) {
3287 body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
3288 }
3289 body.emit(ret(m));
3290
3291 return sig;
3292 }
3293
3294 ir_function_signature *
3295 builtin_builder::_transpose(const glsl_type *orig_type)
3296 {
3297 const glsl_type *transpose_type =
3298 glsl_type::get_instance(GLSL_TYPE_FLOAT,
3299 orig_type->matrix_columns,
3300 orig_type->vector_elements);
3301
3302 ir_variable *m = in_var(orig_type, "m");
3303 MAKE_SIG(transpose_type, v120, 1, m);
3304
3305 ir_variable *t = body.make_temp(transpose_type, "t");
3306 for (int i = 0; i < orig_type->matrix_columns; i++) {
3307 for (int j = 0; j < orig_type->vector_elements; j++) {
3308 body.emit(assign(array_ref(t, j),
3309 matrix_elt(m, i, j),
3310 1 << i));
3311 }
3312 }
3313 body.emit(ret(t));
3314
3315 return sig;
3316 }
3317
3318 ir_function_signature *
3319 builtin_builder::_determinant_mat2()
3320 {
3321 ir_variable *m = in_var(glsl_type::mat2_type, "m");
3322 MAKE_SIG(glsl_type::float_type, v120, 1, m);
3323
3324 body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
3325 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
3326
3327 return sig;
3328 }
3329
3330 ir_function_signature *
3331 builtin_builder::_determinant_mat3()
3332 {
3333 ir_variable *m = in_var(glsl_type::mat3_type, "m");
3334 MAKE_SIG(glsl_type::float_type, v120, 1, m);
3335
3336 ir_expression *f1 =
3337 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
3338 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
3339
3340 ir_expression *f2 =
3341 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
3342 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
3343
3344 ir_expression *f3 =
3345 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
3346 mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
3347
3348 body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
3349 mul(matrix_elt(m, 0, 1), f2)),
3350 mul(matrix_elt(m, 0, 2), f3))));
3351
3352 return sig;
3353 }
3354
3355 ir_function_signature *
3356 builtin_builder::_determinant_mat4()
3357 {
3358 ir_variable *m = in_var(glsl_type::mat4_type, "m");
3359 MAKE_SIG(glsl_type::float_type, v120, 1, m);
3360
3361 ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
3362 ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
3363 ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
3364 ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
3365 ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
3366 ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
3367 ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
3368 ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
3369 ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
3370 ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
3371 ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
3372 ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
3373 ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
3374 ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
3375 ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
3376 ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
3377 ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
3378 ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
3379 ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
3380
3381 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)))));
3382 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)))));
3383 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)))));
3384 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)))));
3385 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)))));
3386 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)))));
3387 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)))));
3388 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)))));
3389 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)))));
3390 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)))));
3391 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)))));
3392 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)))));
3393 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)))));
3394 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)))));
3395 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)))));
3396 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)))));
3397 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)))));
3398 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)))));
3399 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)))));
3400
3401 ir_variable *adj_0 = body.make_temp(glsl_type::vec4_type, "adj_0");
3402
3403 body.emit(assign(adj_0,
3404 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
3405 mul(matrix_elt(m, 1, 2), SubFactor01)),
3406 mul(matrix_elt(m, 1, 3), SubFactor02)),
3407 WRITEMASK_X));
3408 body.emit(assign(adj_0, neg(
3409 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
3410 mul(matrix_elt(m, 1, 2), SubFactor03)),
3411 mul(matrix_elt(m, 1, 3), SubFactor04))),
3412 WRITEMASK_Y));
3413 body.emit(assign(adj_0,
3414 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
3415 mul(matrix_elt(m, 1, 1), SubFactor03)),
3416 mul(matrix_elt(m, 1, 3), SubFactor05)),
3417 WRITEMASK_Z));
3418 body.emit(assign(adj_0, neg(
3419 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
3420 mul(matrix_elt(m, 1, 1), SubFactor04)),
3421 mul(matrix_elt(m, 1, 2), SubFactor05))),
3422 WRITEMASK_W));
3423
3424 body.emit(ret(dot(array_ref(m, 0), adj_0)));
3425
3426 return sig;
3427 }
3428
3429 ir_function_signature *
3430 builtin_builder::_inverse_mat2()
3431 {
3432 ir_variable *m = in_var(glsl_type::mat2_type, "m");
3433 MAKE_SIG(glsl_type::mat2_type, v120, 1, m);
3434
3435 ir_variable *adj = body.make_temp(glsl_type::mat2_type, "adj");
3436 body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
3437 body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
3438 body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
3439 body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
3440
3441 ir_expression *det =
3442 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
3443 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
3444
3445 body.emit(ret(div(adj, det)));
3446 return sig;
3447 }
3448
3449 ir_function_signature *
3450 builtin_builder::_inverse_mat3()
3451 {
3452 ir_variable *m = in_var(glsl_type::mat3_type, "m");
3453 MAKE_SIG(glsl_type::mat3_type, v120, 1, m);
3454
3455 ir_variable *f11_22_21_12 = body.make_temp(glsl_type::float_type, "f11_22_21_12");
3456 ir_variable *f10_22_20_12 = body.make_temp(glsl_type::float_type, "f10_22_20_12");
3457 ir_variable *f10_21_20_11 = body.make_temp(glsl_type::float_type, "f10_21_20_11");
3458
3459 body.emit(assign(f11_22_21_12,
3460 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
3461 mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
3462 body.emit(assign(f10_22_20_12,
3463 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
3464 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
3465 body.emit(assign(f10_21_20_11,
3466 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
3467 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
3468
3469 ir_variable *adj = body.make_temp(glsl_type::mat3_type, "adj");
3470 body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
3471 body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
3472 body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
3473
3474 body.emit(assign(array_ref(adj, 0), neg(
3475 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
3476 mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
3477 WRITEMASK_Y));
3478 body.emit(assign(array_ref(adj, 1),
3479 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
3480 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
3481 WRITEMASK_Y));
3482 body.emit(assign(array_ref(adj, 2), neg(
3483 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
3484 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
3485 WRITEMASK_Y));
3486
3487 body.emit(assign(array_ref(adj, 0),
3488 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
3489 mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
3490 WRITEMASK_Z));
3491 body.emit(assign(array_ref(adj, 1), neg(
3492 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
3493 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
3494 WRITEMASK_Z));
3495 body.emit(assign(array_ref(adj, 2),
3496 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
3497 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
3498 WRITEMASK_Z));
3499
3500 ir_expression *det =
3501 add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
3502 mul(matrix_elt(m, 0, 1), f10_22_20_12)),
3503 mul(matrix_elt(m, 0, 2), f10_21_20_11));
3504
3505 body.emit(ret(div(adj, det)));
3506
3507 return sig;
3508 }
3509
3510 ir_function_signature *
3511 builtin_builder::_inverse_mat4()
3512 {
3513 ir_variable *m = in_var(glsl_type::mat4_type, "m");
3514 MAKE_SIG(glsl_type::mat4_type, v120, 1, m);
3515
3516 ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
3517 ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
3518 ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
3519 ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
3520 ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
3521 ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
3522 ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
3523 ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
3524 ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
3525 ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
3526 ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
3527 ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
3528 ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
3529 ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
3530 ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
3531 ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
3532 ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
3533 ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
3534 ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
3535
3536 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)))));
3537 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)))));
3538 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)))));
3539 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)))));
3540 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)))));
3541 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)))));
3542 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)))));
3543 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)))));
3544 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)))));
3545 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)))));
3546 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)))));
3547 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)))));
3548 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)))));
3549 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)))));
3550 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)))));
3551 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)))));
3552 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)))));
3553 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)))));
3554 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)))));
3555
3556 ir_variable *adj = body.make_temp(glsl_type::mat4_type, "adj");
3557 body.emit(assign(array_ref(adj, 0),
3558 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
3559 mul(matrix_elt(m, 1, 2), SubFactor01)),
3560 mul(matrix_elt(m, 1, 3), SubFactor02)),
3561 WRITEMASK_X));
3562 body.emit(assign(array_ref(adj, 1), neg(
3563 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
3564 mul(matrix_elt(m, 1, 2), SubFactor03)),
3565 mul(matrix_elt(m, 1, 3), SubFactor04))),
3566 WRITEMASK_X));
3567 body.emit(assign(array_ref(adj, 2),
3568 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
3569 mul(matrix_elt(m, 1, 1), SubFactor03)),
3570 mul(matrix_elt(m, 1, 3), SubFactor05)),
3571 WRITEMASK_X));
3572 body.emit(assign(array_ref(adj, 3), neg(
3573 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
3574 mul(matrix_elt(m, 1, 1), SubFactor04)),
3575 mul(matrix_elt(m, 1, 2), SubFactor05))),
3576 WRITEMASK_X));
3577
3578 body.emit(assign(array_ref(adj, 0), neg(
3579 add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
3580 mul(matrix_elt(m, 0, 2), SubFactor01)),
3581 mul(matrix_elt(m, 0, 3), SubFactor02))),
3582 WRITEMASK_Y));
3583 body.emit(assign(array_ref(adj, 1),
3584 add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
3585 mul(matrix_elt(m, 0, 2), SubFactor03)),
3586 mul(matrix_elt(m, 0, 3), SubFactor04)),
3587 WRITEMASK_Y));
3588 body.emit(assign(array_ref(adj, 2), neg(
3589 add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
3590 mul(matrix_elt(m, 0, 1), SubFactor03)),
3591 mul(matrix_elt(m, 0, 3), SubFactor05))),
3592 WRITEMASK_Y));
3593 body.emit(assign(array_ref(adj, 3),
3594 add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
3595 mul(matrix_elt(m, 0, 1), SubFactor04)),
3596 mul(matrix_elt(m, 0, 2), SubFactor05)),
3597 WRITEMASK_Y));
3598
3599 body.emit(assign(array_ref(adj, 0),
3600 add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
3601 mul(matrix_elt(m, 0, 2), SubFactor07)),
3602 mul(matrix_elt(m, 0, 3), SubFactor08)),
3603 WRITEMASK_Z));
3604 body.emit(assign(array_ref(adj, 1), neg(
3605 add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
3606 mul(matrix_elt(m, 0, 2), SubFactor09)),
3607 mul(matrix_elt(m, 0, 3), SubFactor10))),
3608 WRITEMASK_Z));
3609 body.emit(assign(array_ref(adj, 2),
3610 add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
3611 mul(matrix_elt(m, 0, 1), SubFactor09)),
3612 mul(matrix_elt(m, 0, 3), SubFactor12)),
3613 WRITEMASK_Z));
3614 body.emit(assign(array_ref(adj, 3), neg(
3615 add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
3616 mul(matrix_elt(m, 0, 1), SubFactor10)),
3617 mul(matrix_elt(m, 0, 2), SubFactor12))),
3618 WRITEMASK_Z));
3619
3620 body.emit(assign(array_ref(adj, 0), neg(
3621 add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
3622 mul(matrix_elt(m, 0, 2), SubFactor14)),
3623 mul(matrix_elt(m, 0, 3), SubFactor15))),
3624 WRITEMASK_W));
3625 body.emit(assign(array_ref(adj, 1),
3626 add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
3627 mul(matrix_elt(m, 0, 2), SubFactor16)),
3628 mul(matrix_elt(m, 0, 3), SubFactor17)),
3629 WRITEMASK_W));
3630 body.emit(assign(array_ref(adj, 2), neg(
3631 add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
3632 mul(matrix_elt(m, 0, 1), SubFactor16)),
3633 mul(matrix_elt(m, 0, 3), SubFactor18))),
3634 WRITEMASK_W));
3635 body.emit(assign(array_ref(adj, 3),
3636 add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
3637 mul(matrix_elt(m, 0, 1), SubFactor17)),
3638 mul(matrix_elt(m, 0, 2), SubFactor18)),
3639 WRITEMASK_W));
3640
3641 ir_expression *det =
3642 add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
3643 add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
3644 add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
3645 mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
3646
3647 body.emit(ret(div(adj, det)));
3648
3649 return sig;
3650 }
3651
3652
3653 ir_function_signature *
3654 builtin_builder::_lessThan(builtin_available_predicate avail,
3655 const glsl_type *type)
3656 {
3657 return binop(ir_binop_less, avail,
3658 glsl_type::bvec(type->vector_elements), type, type);
3659 }
3660
3661 ir_function_signature *
3662 builtin_builder::_lessThanEqual(builtin_available_predicate avail,
3663 const glsl_type *type)
3664 {
3665 return binop(ir_binop_lequal, avail,
3666 glsl_type::bvec(type->vector_elements), type, type);
3667 }
3668
3669 ir_function_signature *
3670 builtin_builder::_greaterThan(builtin_available_predicate avail,
3671 const glsl_type *type)
3672 {
3673 return binop(ir_binop_greater, avail,
3674 glsl_type::bvec(type->vector_elements), type, type);
3675 }
3676
3677 ir_function_signature *
3678 builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
3679 const glsl_type *type)
3680 {
3681 return binop(ir_binop_gequal, avail,
3682 glsl_type::bvec(type->vector_elements), type, type);
3683 }
3684
3685 ir_function_signature *
3686 builtin_builder::_equal(builtin_available_predicate avail,
3687 const glsl_type *type)
3688 {
3689 return binop(ir_binop_equal, avail,
3690 glsl_type::bvec(type->vector_elements), type, type);
3691 }
3692
3693 ir_function_signature *
3694 builtin_builder::_notEqual(builtin_available_predicate avail,
3695 const glsl_type *type)
3696 {
3697 return binop(ir_binop_nequal, avail,
3698 glsl_type::bvec(type->vector_elements), type, type);
3699 }
3700
3701 ir_function_signature *
3702 builtin_builder::_any(const glsl_type *type)
3703 {
3704 return unop(always_available, ir_unop_any, glsl_type::bool_type, type);
3705 }
3706
3707 ir_function_signature *
3708 builtin_builder::_all(const glsl_type *type)
3709 {
3710 ir_variable *v = in_var(type, "v");
3711 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
3712
3713 switch (type->vector_elements) {
3714 case 2:
3715 body.emit(ret(logic_and(swizzle_x(v), swizzle_y(v))));
3716 break;
3717 case 3:
3718 body.emit(ret(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
3719 swizzle_z(v))));
3720 break;
3721 case 4:
3722 body.emit(ret(logic_and(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
3723 swizzle_z(v)),
3724 swizzle_w(v))));
3725 break;
3726 }
3727
3728 return sig;
3729 }
3730
3731 UNOP(not, ir_unop_logic_not, always_available)
3732
3733 static bool
3734 has_lod(const glsl_type *sampler_type)
3735 {
3736 assert(sampler_type->is_sampler());
3737
3738 switch (sampler_type->sampler_dimensionality) {
3739 case GLSL_SAMPLER_DIM_RECT:
3740 case GLSL_SAMPLER_DIM_BUF:
3741 case GLSL_SAMPLER_DIM_MS:
3742 return false;
3743 default:
3744 return true;
3745 }
3746 }
3747
3748 ir_function_signature *
3749 builtin_builder::_textureSize(builtin_available_predicate avail,
3750 const glsl_type *return_type,
3751 const glsl_type *sampler_type)
3752 {
3753 ir_variable *s = in_var(sampler_type, "sampler");
3754 /* The sampler always exists; add optional lod later. */
3755 MAKE_SIG(return_type, avail, 1, s);
3756
3757 ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
3758 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
3759
3760 if (has_lod(sampler_type)) {
3761 ir_variable *lod = in_var(glsl_type::int_type, "lod");
3762 sig->parameters.push_tail(lod);
3763 tex->lod_info.lod = var_ref(lod);
3764 } else {
3765 tex->lod_info.lod = imm(0u);
3766 }
3767
3768 body.emit(ret(tex));
3769
3770 return sig;
3771 }
3772
3773 ir_function_signature *
3774 builtin_builder::_texture(ir_texture_opcode opcode,
3775 builtin_available_predicate avail,
3776 const glsl_type *return_type,
3777 const glsl_type *sampler_type,
3778 const glsl_type *coord_type,
3779 int flags)
3780 {
3781 ir_variable *s = in_var(sampler_type, "sampler");
3782 ir_variable *P = in_var(coord_type, "P");
3783 /* The sampler and coordinate always exist; add optional parameters later. */
3784 MAKE_SIG(return_type, avail, 2, s, P);
3785
3786 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
3787 tex->set_sampler(var_ref(s), return_type);
3788
3789 const int coord_size = sampler_type->coordinate_components();
3790
3791 if (coord_size == coord_type->vector_elements) {
3792 tex->coordinate = var_ref(P);
3793 } else {
3794 /* The incoming coordinate also has the projector or shadow comparitor,
3795 * so we need to swizzle those away.
3796 */
3797 tex->coordinate = swizzle_for_size(P, coord_size);
3798 }
3799
3800 /* The projector is always in the last component. */
3801 if (flags & TEX_PROJECT)
3802 tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
3803
3804 if (sampler_type->sampler_shadow) {
3805 if (opcode == ir_tg4) {
3806 /* gather has refz as a separate parameter, immediately after the
3807 * coordinate
3808 */
3809 ir_variable *refz = in_var(glsl_type::float_type, "refz");
3810 sig->parameters.push_tail(refz);
3811 tex->shadow_comparitor = var_ref(refz);
3812 } else {
3813 /* The shadow comparitor is normally in the Z component, but a few types
3814 * have sufficiently large coordinates that it's in W.
3815 */
3816 tex->shadow_comparitor = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
3817 }
3818 }
3819
3820 if (opcode == ir_txl) {
3821 ir_variable *lod = in_var(glsl_type::float_type, "lod");
3822 sig->parameters.push_tail(lod);
3823 tex->lod_info.lod = var_ref(lod);
3824 } else if (opcode == ir_txd) {
3825 int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
3826 ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
3827 ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
3828 sig->parameters.push_tail(dPdx);
3829 sig->parameters.push_tail(dPdy);
3830 tex->lod_info.grad.dPdx = var_ref(dPdx);
3831 tex->lod_info.grad.dPdy = var_ref(dPdy);
3832 }
3833
3834 if (flags & (TEX_OFFSET | TEX_OFFSET_NONCONST)) {
3835 int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
3836 ir_variable *offset =
3837 new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset",
3838 (flags & TEX_OFFSET) ? ir_var_const_in : ir_var_function_in);
3839 sig->parameters.push_tail(offset);
3840 tex->offset = var_ref(offset);
3841 }
3842
3843 if (flags & TEX_OFFSET_ARRAY) {
3844 ir_variable *offsets =
3845 new(mem_ctx) ir_variable(glsl_type::get_array_instance(glsl_type::ivec2_type, 4),
3846 "offsets", ir_var_const_in);
3847 sig->parameters.push_tail(offsets);
3848 tex->offset = var_ref(offsets);
3849 }
3850
3851 if (opcode == ir_tg4) {
3852 if (flags & TEX_COMPONENT) {
3853 ir_variable *component =
3854 new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in);
3855 sig->parameters.push_tail(component);
3856 tex->lod_info.component = var_ref(component);
3857 }
3858 else {
3859 tex->lod_info.component = imm(0);
3860 }
3861 }
3862
3863 /* The "bias" parameter comes /after/ the "offset" parameter, which is
3864 * inconsistent with both textureLodOffset and textureGradOffset.
3865 */
3866 if (opcode == ir_txb) {
3867 ir_variable *bias = in_var(glsl_type::float_type, "bias");
3868 sig->parameters.push_tail(bias);
3869 tex->lod_info.bias = var_ref(bias);
3870 }
3871
3872 body.emit(ret(tex));
3873
3874 return sig;
3875 }
3876
3877 ir_function_signature *
3878 builtin_builder::_textureCubeArrayShadow()
3879 {
3880 ir_variable *s = in_var(glsl_type::samplerCubeArrayShadow_type, "sampler");
3881 ir_variable *P = in_var(glsl_type::vec4_type, "P");
3882 ir_variable *compare = in_var(glsl_type::float_type, "compare");
3883 MAKE_SIG(glsl_type::float_type, texture_cube_map_array, 3, s, P, compare);
3884
3885 ir_texture *tex = new(mem_ctx) ir_texture(ir_tex);
3886 tex->set_sampler(var_ref(s), glsl_type::float_type);
3887
3888 tex->coordinate = var_ref(P);
3889 tex->shadow_comparitor = var_ref(compare);
3890
3891 body.emit(ret(tex));
3892
3893 return sig;
3894 }
3895
3896 ir_function_signature *
3897 builtin_builder::_texelFetch(builtin_available_predicate avail,
3898 const glsl_type *return_type,
3899 const glsl_type *sampler_type,
3900 const glsl_type *coord_type,
3901 const glsl_type *offset_type)
3902 {
3903 ir_variable *s = in_var(sampler_type, "sampler");
3904 ir_variable *P = in_var(coord_type, "P");
3905 /* The sampler and coordinate always exist; add optional parameters later. */
3906 MAKE_SIG(return_type, avail, 2, s, P);
3907
3908 ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
3909 tex->coordinate = var_ref(P);
3910 tex->set_sampler(var_ref(s), return_type);
3911
3912 if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
3913 ir_variable *sample = in_var(glsl_type::int_type, "sample");
3914 sig->parameters.push_tail(sample);
3915 tex->lod_info.sample_index = var_ref(sample);
3916 tex->op = ir_txf_ms;
3917 } else if (has_lod(sampler_type)) {
3918 ir_variable *lod = in_var(glsl_type::int_type, "lod");
3919 sig->parameters.push_tail(lod);
3920 tex->lod_info.lod = var_ref(lod);
3921 } else {
3922 tex->lod_info.lod = imm(0u);
3923 }
3924
3925 if (offset_type != NULL) {
3926 ir_variable *offset =
3927 new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in);
3928 sig->parameters.push_tail(offset);
3929 tex->offset = var_ref(offset);
3930 }
3931
3932 body.emit(ret(tex));
3933
3934 return sig;
3935 }
3936
3937 ir_function_signature *
3938 builtin_builder::_EmitVertex()
3939 {
3940 MAKE_SIG(glsl_type::void_type, gs_only, 0);
3941
3942 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
3943 body.emit(new(mem_ctx) ir_emit_vertex(stream));
3944
3945 return sig;
3946 }
3947
3948 ir_function_signature *
3949 builtin_builder::_EmitStreamVertex(builtin_available_predicate avail,
3950 const glsl_type *stream_type)
3951 {
3952 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
3953 *
3954 * "Emit the current values of output variables to the current output
3955 * primitive on stream stream. The argument to stream must be a constant
3956 * integral expression."
3957 */
3958 ir_variable *stream =
3959 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
3960
3961 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
3962
3963 body.emit(new(mem_ctx) ir_emit_vertex(var_ref(stream)));
3964
3965 return sig;
3966 }
3967
3968 ir_function_signature *
3969 builtin_builder::_EndPrimitive()
3970 {
3971 MAKE_SIG(glsl_type::void_type, gs_only, 0);
3972
3973 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
3974 body.emit(new(mem_ctx) ir_end_primitive(stream));
3975
3976 return sig;
3977 }
3978
3979 ir_function_signature *
3980 builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
3981 const glsl_type *stream_type)
3982 {
3983 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
3984 *
3985 * "Completes the current output primitive on stream stream and starts
3986 * a new one. The argument to stream must be a constant integral
3987 * expression."
3988 */
3989 ir_variable *stream =
3990 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
3991
3992 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
3993
3994 body.emit(new(mem_ctx) ir_end_primitive(var_ref(stream)));
3995
3996 return sig;
3997 }
3998
3999 ir_function_signature *
4000 builtin_builder::_textureQueryLod(const glsl_type *sampler_type,
4001 const glsl_type *coord_type)
4002 {
4003 ir_variable *s = in_var(sampler_type, "sampler");
4004 ir_variable *coord = in_var(coord_type, "coord");
4005 /* The sampler and coordinate always exist; add optional parameters later. */
4006 MAKE_SIG(glsl_type::vec2_type, texture_query_lod, 2, s, coord);
4007
4008 ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
4009 tex->coordinate = var_ref(coord);
4010 tex->set_sampler(var_ref(s), glsl_type::vec2_type);
4011
4012 body.emit(ret(tex));
4013
4014 return sig;
4015 }
4016
4017 ir_function_signature *
4018 builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
4019 {
4020 ir_variable *s = in_var(sampler_type, "sampler");
4021 const glsl_type *return_type = glsl_type::int_type;
4022 MAKE_SIG(return_type, texture_query_levels, 1, s);
4023
4024 ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
4025 tex->set_sampler(var_ref(s), return_type);
4026
4027 body.emit(ret(tex));
4028
4029 return sig;
4030 }
4031
4032 UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
4033 UNOP(dFdxCoarse, ir_unop_dFdx_coarse, fs_derivative_control)
4034 UNOP(dFdxFine, ir_unop_dFdx_fine, fs_derivative_control)
4035 UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
4036 UNOP(dFdyCoarse, ir_unop_dFdy_coarse, fs_derivative_control)
4037 UNOP(dFdyFine, ir_unop_dFdy_fine, fs_derivative_control)
4038
4039 ir_function_signature *
4040 builtin_builder::_fwidth(const glsl_type *type)
4041 {
4042 ir_variable *p = in_var(type, "p");
4043 MAKE_SIG(type, fs_oes_derivatives, 1, p);
4044
4045 body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
4046
4047 return sig;
4048 }
4049
4050 ir_function_signature *
4051 builtin_builder::_fwidthCoarse(const glsl_type *type)
4052 {
4053 ir_variable *p = in_var(type, "p");
4054 MAKE_SIG(type, fs_derivative_control, 1, p);
4055
4056 body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
4057 abs(expr(ir_unop_dFdy_coarse, p)))));
4058
4059 return sig;
4060 }
4061
4062 ir_function_signature *
4063 builtin_builder::_fwidthFine(const glsl_type *type)
4064 {
4065 ir_variable *p = in_var(type, "p");
4066 MAKE_SIG(type, fs_derivative_control, 1, p);
4067
4068 body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
4069 abs(expr(ir_unop_dFdy_fine, p)))));
4070
4071 return sig;
4072 }
4073
4074 ir_function_signature *
4075 builtin_builder::_noise1(const glsl_type *type)
4076 {
4077 return unop(v110, ir_unop_noise, glsl_type::float_type, type);
4078 }
4079
4080 ir_function_signature *
4081 builtin_builder::_noise2(const glsl_type *type)
4082 {
4083 ir_variable *p = in_var(type, "p");
4084 MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
4085
4086 ir_constant_data b_offset;
4087 b_offset.f[0] = 601.0f;
4088 b_offset.f[1] = 313.0f;
4089 b_offset.f[2] = 29.0f;
4090 b_offset.f[3] = 277.0f;
4091
4092 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4093 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4094 ir_variable *t = body.make_temp(glsl_type::vec2_type, "t");
4095 body.emit(assign(a, expr(ir_unop_noise, p)));
4096 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
4097 body.emit(assign(t, a, WRITEMASK_X));
4098 body.emit(assign(t, b, WRITEMASK_Y));
4099 body.emit(ret(t));
4100
4101 return sig;
4102 }
4103
4104 ir_function_signature *
4105 builtin_builder::_noise3(const glsl_type *type)
4106 {
4107 ir_variable *p = in_var(type, "p");
4108 MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
4109
4110 ir_constant_data b_offset;
4111 b_offset.f[0] = 601.0f;
4112 b_offset.f[1] = 313.0f;
4113 b_offset.f[2] = 29.0f;
4114 b_offset.f[3] = 277.0f;
4115
4116 ir_constant_data c_offset;
4117 c_offset.f[0] = 1559.0f;
4118 c_offset.f[1] = 113.0f;
4119 c_offset.f[2] = 1861.0f;
4120 c_offset.f[3] = 797.0f;
4121
4122 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4123 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4124 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
4125 ir_variable *t = body.make_temp(glsl_type::vec3_type, "t");
4126 body.emit(assign(a, expr(ir_unop_noise, p)));
4127 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
4128 body.emit(assign(c, expr(ir_unop_noise, add(p, imm(type, c_offset)))));
4129 body.emit(assign(t, a, WRITEMASK_X));
4130 body.emit(assign(t, b, WRITEMASK_Y));
4131 body.emit(assign(t, c, WRITEMASK_Z));
4132 body.emit(ret(t));
4133
4134 return sig;
4135 }
4136
4137 ir_function_signature *
4138 builtin_builder::_noise4(const glsl_type *type)
4139 {
4140 ir_variable *p = in_var(type, "p");
4141 MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
4142
4143 ir_variable *_p = body.make_temp(type, "_p");
4144
4145 ir_constant_data p_offset;
4146 p_offset.f[0] = 1559.0f;
4147 p_offset.f[1] = 113.0f;
4148 p_offset.f[2] = 1861.0f;
4149 p_offset.f[3] = 797.0f;
4150
4151 body.emit(assign(_p, add(p, imm(type, p_offset))));
4152
4153 ir_constant_data offset;
4154 offset.f[0] = 601.0f;
4155 offset.f[1] = 313.0f;
4156 offset.f[2] = 29.0f;
4157 offset.f[3] = 277.0f;
4158
4159 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4160 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4161 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
4162 ir_variable *d = body.make_temp(glsl_type::float_type, "d");
4163 ir_variable *t = body.make_temp(glsl_type::vec4_type, "t");
4164 body.emit(assign(a, expr(ir_unop_noise, p)));
4165 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, offset)))));
4166 body.emit(assign(c, expr(ir_unop_noise, _p)));
4167 body.emit(assign(d, expr(ir_unop_noise, add(_p, imm(type, offset)))));
4168 body.emit(assign(t, a, WRITEMASK_X));
4169 body.emit(assign(t, b, WRITEMASK_Y));
4170 body.emit(assign(t, c, WRITEMASK_Z));
4171 body.emit(assign(t, d, WRITEMASK_W));
4172 body.emit(ret(t));
4173
4174 return sig;
4175 }
4176
4177 ir_function_signature *
4178 builtin_builder::_bitfieldExtract(const glsl_type *type)
4179 {
4180 ir_variable *value = in_var(type, "value");
4181 ir_variable *offset = in_var(glsl_type::int_type, "offset");
4182 ir_variable *bits = in_var(glsl_type::int_type, "bits");
4183 MAKE_SIG(type, gpu_shader5, 3, value, offset, bits);
4184
4185 body.emit(ret(expr(ir_triop_bitfield_extract, value, offset, bits)));
4186
4187 return sig;
4188 }
4189
4190 ir_function_signature *
4191 builtin_builder::_bitfieldInsert(const glsl_type *type)
4192 {
4193 ir_variable *base = in_var(type, "base");
4194 ir_variable *insert = in_var(type, "insert");
4195 ir_variable *offset = in_var(glsl_type::int_type, "offset");
4196 ir_variable *bits = in_var(glsl_type::int_type, "bits");
4197 MAKE_SIG(type, gpu_shader5, 4, base, insert, offset, bits);
4198
4199 body.emit(ret(bitfield_insert(base, insert, offset, bits)));
4200
4201 return sig;
4202 }
4203
4204 UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5)
4205
4206 ir_function_signature *
4207 builtin_builder::_bitCount(const glsl_type *type)
4208 {
4209 return unop(gpu_shader5, ir_unop_bit_count,
4210 glsl_type::ivec(type->vector_elements), type);
4211 }
4212
4213 ir_function_signature *
4214 builtin_builder::_findLSB(const glsl_type *type)
4215 {
4216 return unop(gpu_shader5, ir_unop_find_lsb,
4217 glsl_type::ivec(type->vector_elements), type);
4218 }
4219
4220 ir_function_signature *
4221 builtin_builder::_findMSB(const glsl_type *type)
4222 {
4223 return unop(gpu_shader5, ir_unop_find_msb,
4224 glsl_type::ivec(type->vector_elements), type);
4225 }
4226
4227 ir_function_signature *
4228 builtin_builder::_fma(const glsl_type *type)
4229 {
4230 ir_variable *a = in_var(type, "a");
4231 ir_variable *b = in_var(type, "b");
4232 ir_variable *c = in_var(type, "c");
4233 MAKE_SIG(type, gpu_shader5, 3, a, b, c);
4234
4235 body.emit(ret(ir_builder::fma(a, b, c)));
4236
4237 return sig;
4238 }
4239
4240 ir_function_signature *
4241 builtin_builder::_ldexp(const glsl_type *x_type, const glsl_type *exp_type)
4242 {
4243 return binop(ir_binop_ldexp, gpu_shader5, x_type, x_type, exp_type);
4244 }
4245
4246 ir_function_signature *
4247 builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
4248 {
4249 ir_variable *x = in_var(x_type, "x");
4250 ir_variable *exponent = out_var(exp_type, "exp");
4251 MAKE_SIG(x_type, gpu_shader5, 2, x, exponent);
4252
4253 const unsigned vec_elem = x_type->vector_elements;
4254 const glsl_type *bvec = glsl_type::get_instance(GLSL_TYPE_BOOL, vec_elem, 1);
4255 const glsl_type *uvec = glsl_type::get_instance(GLSL_TYPE_UINT, vec_elem, 1);
4256
4257 /* Single-precision floating-point values are stored as
4258 * 1 sign bit;
4259 * 8 exponent bits;
4260 * 23 mantissa bits.
4261 *
4262 * An exponent shift of 23 will shift the mantissa out, leaving only the
4263 * exponent and sign bit (which itself may be zero, if the absolute value
4264 * was taken before the bitcast and shift.
4265 */
4266 ir_constant *exponent_shift = imm(23);
4267 ir_constant *exponent_bias = imm(-126, vec_elem);
4268
4269 ir_constant *sign_mantissa_mask = imm(0x807fffffu, vec_elem);
4270
4271 /* Exponent of floating-point values in the range [0.5, 1.0). */
4272 ir_constant *exponent_value = imm(0x3f000000u, vec_elem);
4273
4274 ir_variable *is_not_zero = body.make_temp(bvec, "is_not_zero");
4275 body.emit(assign(is_not_zero, nequal(abs(x), imm(0.0f, vec_elem))));
4276
4277 /* Since abs(x) ensures that the sign bit is zero, we don't need to bitcast
4278 * to unsigned integers to ensure that 1 bits aren't shifted in.
4279 */
4280 body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
4281 body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
4282 imm(0, vec_elem)))));
4283
4284 ir_variable *bits = body.make_temp(uvec, "bits");
4285 body.emit(assign(bits, bitcast_f2u(x)));
4286 body.emit(assign(bits, bit_and(bits, sign_mantissa_mask)));
4287 body.emit(assign(bits, bit_or(bits, csel(is_not_zero, exponent_value,
4288 imm(0u, vec_elem)))));
4289 body.emit(ret(bitcast_u2f(bits)));
4290
4291 return sig;
4292 }
4293
4294 ir_function_signature *
4295 builtin_builder::_uaddCarry(const glsl_type *type)
4296 {
4297 ir_variable *x = in_var(type, "x");
4298 ir_variable *y = in_var(type, "y");
4299 ir_variable *carry = out_var(type, "carry");
4300 MAKE_SIG(type, gpu_shader5, 3, x, y, carry);
4301
4302 body.emit(assign(carry, ir_builder::carry(x, y)));
4303 body.emit(ret(add(x, y)));
4304
4305 return sig;
4306 }
4307
4308 ir_function_signature *
4309 builtin_builder::_usubBorrow(const glsl_type *type)
4310 {
4311 ir_variable *x = in_var(type, "x");
4312 ir_variable *y = in_var(type, "y");
4313 ir_variable *borrow = out_var(type, "borrow");
4314 MAKE_SIG(type, gpu_shader5, 3, x, y, borrow);
4315
4316 body.emit(assign(borrow, ir_builder::borrow(x, y)));
4317 body.emit(ret(sub(x, y)));
4318
4319 return sig;
4320 }
4321
4322 /**
4323 * For both imulExtended() and umulExtended() built-ins.
4324 */
4325 ir_function_signature *
4326 builtin_builder::_mulExtended(const glsl_type *type)
4327 {
4328 ir_variable *x = in_var(type, "x");
4329 ir_variable *y = in_var(type, "y");
4330 ir_variable *msb = out_var(type, "msb");
4331 ir_variable *lsb = out_var(type, "lsb");
4332 MAKE_SIG(glsl_type::void_type, gpu_shader5, 4, x, y, msb, lsb);
4333
4334 body.emit(assign(msb, imul_high(x, y)));
4335 body.emit(assign(lsb, mul(x, y)));
4336
4337 return sig;
4338 }
4339
4340 ir_function_signature *
4341 builtin_builder::_interpolateAtCentroid(const glsl_type *type)
4342 {
4343 ir_variable *interpolant = in_var(type, "interpolant");
4344 interpolant->data.must_be_shader_input = 1;
4345 MAKE_SIG(type, fs_gpu_shader5, 1, interpolant);
4346
4347 body.emit(ret(interpolate_at_centroid(interpolant)));
4348
4349 return sig;
4350 }
4351
4352 ir_function_signature *
4353 builtin_builder::_interpolateAtOffset(const glsl_type *type)
4354 {
4355 ir_variable *interpolant = in_var(type, "interpolant");
4356 interpolant->data.must_be_shader_input = 1;
4357 ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
4358 MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, offset);
4359
4360 body.emit(ret(interpolate_at_offset(interpolant, offset)));
4361
4362 return sig;
4363 }
4364
4365 ir_function_signature *
4366 builtin_builder::_interpolateAtSample(const glsl_type *type)
4367 {
4368 ir_variable *interpolant = in_var(type, "interpolant");
4369 interpolant->data.must_be_shader_input = 1;
4370 ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
4371 MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, sample_num);
4372
4373 body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
4374
4375 return sig;
4376 }
4377
4378 ir_function_signature *
4379 builtin_builder::_atomic_intrinsic(builtin_available_predicate avail)
4380 {
4381 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
4382 MAKE_INTRINSIC(glsl_type::uint_type, avail, 1, counter);
4383 return sig;
4384 }
4385
4386 ir_function_signature *
4387 builtin_builder::_atomic_op(const char *intrinsic,
4388 builtin_available_predicate avail)
4389 {
4390 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
4391 MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
4392
4393 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
4394 body.emit(call(shader->symbols->get_function(intrinsic), retval,
4395 sig->parameters));
4396 body.emit(ret(retval));
4397 return sig;
4398 }
4399
4400 ir_function_signature *
4401 builtin_builder::_min3(const glsl_type *type)
4402 {
4403 ir_variable *x = in_var(type, "x");
4404 ir_variable *y = in_var(type, "y");
4405 ir_variable *z = in_var(type, "z");
4406 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
4407
4408 ir_expression *min3 = min2(x, min2(y,z));
4409 body.emit(ret(min3));
4410
4411 return sig;
4412 }
4413
4414 ir_function_signature *
4415 builtin_builder::_max3(const glsl_type *type)
4416 {
4417 ir_variable *x = in_var(type, "x");
4418 ir_variable *y = in_var(type, "y");
4419 ir_variable *z = in_var(type, "z");
4420 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
4421
4422 ir_expression *max3 = max2(x, max2(y,z));
4423 body.emit(ret(max3));
4424
4425 return sig;
4426 }
4427
4428 ir_function_signature *
4429 builtin_builder::_mid3(const glsl_type *type)
4430 {
4431 ir_variable *x = in_var(type, "x");
4432 ir_variable *y = in_var(type, "y");
4433 ir_variable *z = in_var(type, "z");
4434 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
4435
4436 ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
4437 body.emit(ret(mid3));
4438
4439 return sig;
4440 }
4441
4442 ir_function_signature *
4443 builtin_builder::_image_prototype(const glsl_type *image_type,
4444 const char *intrinsic_name,
4445 unsigned num_arguments,
4446 unsigned flags)
4447 {
4448 const glsl_type *data_type = glsl_type::get_instance(
4449 image_type->sampler_type,
4450 (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
4451 1);
4452 const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
4453 glsl_type::void_type : data_type);
4454
4455 /* Addressing arguments that are always present. */
4456 ir_variable *image = in_var(image_type, "image");
4457 ir_variable *coord = in_var(
4458 glsl_type::ivec(image_type->coordinate_components()), "coord");
4459
4460 ir_function_signature *sig = new_sig(
4461 ret_type, shader_image_load_store, 2, image, coord);
4462
4463 /* Sample index for multisample images. */
4464 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
4465 sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
4466
4467 /* Data arguments. */
4468 for (unsigned i = 0; i < num_arguments; ++i)
4469 sig->parameters.push_tail(in_var(data_type,
4470 ralloc_asprintf(NULL, "arg%d", i)));
4471
4472 /* Set the maximal set of qualifiers allowed for this image
4473 * built-in. Function calls with arguments having fewer
4474 * qualifiers than present in the prototype are allowed by the
4475 * spec, but not with more, i.e. this will make the compiler
4476 * accept everything that needs to be accepted, and reject cases
4477 * like loads from write-only or stores to read-only images.
4478 */
4479 image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
4480 image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
4481 image->data.image_coherent = true;
4482 image->data.image_volatile = true;
4483 image->data.image_restrict = true;
4484
4485 return sig;
4486 }
4487
4488 ir_function_signature *
4489 builtin_builder::_image(const glsl_type *image_type,
4490 const char *intrinsic_name,
4491 unsigned num_arguments,
4492 unsigned flags)
4493 {
4494 ir_function_signature *sig = _image_prototype(image_type, intrinsic_name,
4495 num_arguments, flags);
4496
4497 if (flags & IMAGE_FUNCTION_EMIT_STUB) {
4498 ir_factory body(&sig->body, mem_ctx);
4499 ir_function *f = shader->symbols->get_function(intrinsic_name);
4500
4501 if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
4502 body.emit(call(f, NULL, sig->parameters));
4503 } else {
4504 ir_variable *ret_val =
4505 body.make_temp(sig->return_type, "_ret_val");
4506 body.emit(call(f, ret_val, sig->parameters));
4507 body.emit(ret(ret_val));
4508 }
4509
4510 sig->is_defined = true;
4511
4512 } else {
4513 sig->is_intrinsic = true;
4514 }
4515
4516 return sig;
4517 }
4518
4519 ir_function_signature *
4520 builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail)
4521 {
4522 MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
4523 return sig;
4524 }
4525
4526 ir_function_signature *
4527 builtin_builder::_memory_barrier(builtin_available_predicate avail)
4528 {
4529 MAKE_SIG(glsl_type::void_type, avail, 0);
4530 body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier"),
4531 NULL, sig->parameters));
4532 return sig;
4533 }
4534
4535 /** @} */
4536
4537 /******************************************************************************/
4538
4539 /* The singleton instance of builtin_builder. */
4540 static builtin_builder builtins;
4541 static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
4542
4543 /**
4544 * External API (exposing the built-in module to the rest of the compiler):
4545 * @{
4546 */
4547 void
4548 _mesa_glsl_initialize_builtin_functions()
4549 {
4550 mtx_lock(&builtins_lock);
4551 builtins.initialize();
4552 mtx_unlock(&builtins_lock);
4553 }
4554
4555 void
4556 _mesa_glsl_release_builtin_functions()
4557 {
4558 mtx_lock(&builtins_lock);
4559 builtins.release();
4560 mtx_unlock(&builtins_lock);
4561 }
4562
4563 ir_function_signature *
4564 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
4565 const char *name, exec_list *actual_parameters)
4566 {
4567 ir_function_signature * s;
4568 mtx_lock(&builtins_lock);
4569 s = builtins.find(state, name, actual_parameters);
4570 mtx_unlock(&builtins_lock);
4571 return s;
4572 }
4573
4574 gl_shader *
4575 _mesa_glsl_get_builtin_function_shader()
4576 {
4577 return builtins.shader;
4578 }
4579
4580 /** @} */