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