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