e03a50c84381204fe0a73a6e0a1ad31496994def
[mesa.git] / src / compiler / 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 <math.h>
64 #include "builtin_functions.h"
65
66 #define M_PIf ((float) M_PI)
67 #define M_PI_2f ((float) M_PI_2)
68 #define M_PI_4f ((float) M_PI_4)
69
70 using namespace ir_builder;
71
72 /**
73 * Availability predicates:
74 * @{
75 */
76 static bool
77 always_available(const _mesa_glsl_parse_state *)
78 {
79 return true;
80 }
81
82 static bool
83 compatibility_vs_only(const _mesa_glsl_parse_state *state)
84 {
85 return state->stage == MESA_SHADER_VERTEX &&
86 state->language_version <= 130 &&
87 !state->es_shader;
88 }
89
90 static bool
91 fs_only(const _mesa_glsl_parse_state *state)
92 {
93 return state->stage == MESA_SHADER_FRAGMENT;
94 }
95
96 static bool
97 gs_only(const _mesa_glsl_parse_state *state)
98 {
99 return state->stage == MESA_SHADER_GEOMETRY;
100 }
101
102 static bool
103 v110(const _mesa_glsl_parse_state *state)
104 {
105 return !state->es_shader;
106 }
107
108 static bool
109 v110_fs_only(const _mesa_glsl_parse_state *state)
110 {
111 return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT;
112 }
113
114 static bool
115 v120(const _mesa_glsl_parse_state *state)
116 {
117 return state->is_version(120, 300);
118 }
119
120 static bool
121 v130(const _mesa_glsl_parse_state *state)
122 {
123 return state->is_version(130, 300);
124 }
125
126 static bool
127 v130_desktop(const _mesa_glsl_parse_state *state)
128 {
129 return state->is_version(130, 0);
130 }
131
132 static bool
133 v130_fs_only(const _mesa_glsl_parse_state *state)
134 {
135 return state->is_version(130, 300) &&
136 state->stage == MESA_SHADER_FRAGMENT;
137 }
138
139 static bool
140 v140_or_es3(const _mesa_glsl_parse_state *state)
141 {
142 return state->is_version(140, 300);
143 }
144
145 static bool
146 v400_fs_only(const _mesa_glsl_parse_state *state)
147 {
148 return state->is_version(400, 0) &&
149 state->stage == MESA_SHADER_FRAGMENT;
150 }
151
152 static bool
153 texture_rectangle(const _mesa_glsl_parse_state *state)
154 {
155 return state->ARB_texture_rectangle_enable;
156 }
157
158 static bool
159 texture_external(const _mesa_glsl_parse_state *state)
160 {
161 return state->OES_EGL_image_external_enable;
162 }
163
164 /** True if texturing functions with explicit LOD are allowed. */
165 static bool
166 lod_exists_in_stage(const _mesa_glsl_parse_state *state)
167 {
168 /* Texturing functions with "Lod" in their name exist:
169 * - In the vertex shader stage (for all languages)
170 * - In any stage for GLSL 1.30+ or GLSL ES 3.00
171 * - In any stage for desktop GLSL with ARB_shader_texture_lod enabled.
172 *
173 * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
174 * don't need to explicitly check state->es_shader.
175 */
176 return state->stage == MESA_SHADER_VERTEX ||
177 state->is_version(130, 300) ||
178 state->ARB_shader_texture_lod_enable;
179 }
180
181 static bool
182 v110_lod(const _mesa_glsl_parse_state *state)
183 {
184 return !state->es_shader && lod_exists_in_stage(state);
185 }
186
187 static bool
188 texture_buffer(const _mesa_glsl_parse_state *state)
189 {
190 return state->is_version(140, 320) ||
191 state->EXT_texture_buffer_enable ||
192 state->OES_texture_buffer_enable;
193 }
194
195 static bool
196 shader_texture_lod(const _mesa_glsl_parse_state *state)
197 {
198 return state->ARB_shader_texture_lod_enable;
199 }
200
201 static bool
202 shader_texture_lod_and_rect(const _mesa_glsl_parse_state *state)
203 {
204 return state->ARB_shader_texture_lod_enable &&
205 state->ARB_texture_rectangle_enable;
206 }
207
208 static bool
209 shader_bit_encoding(const _mesa_glsl_parse_state *state)
210 {
211 return state->is_version(330, 300) ||
212 state->ARB_shader_bit_encoding_enable ||
213 state->ARB_gpu_shader5_enable;
214 }
215
216 static bool
217 shader_integer_mix(const _mesa_glsl_parse_state *state)
218 {
219 return state->is_version(450, 310) ||
220 state->ARB_ES3_1_compatibility_enable ||
221 (v130(state) && state->EXT_shader_integer_mix_enable);
222 }
223
224 static bool
225 shader_packing_or_es3(const _mesa_glsl_parse_state *state)
226 {
227 return state->ARB_shading_language_packing_enable ||
228 state->is_version(420, 300);
229 }
230
231 static bool
232 shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state *state)
233 {
234 return state->ARB_shading_language_packing_enable ||
235 state->ARB_gpu_shader5_enable ||
236 state->is_version(400, 300);
237 }
238
239 static bool
240 gpu_shader5(const _mesa_glsl_parse_state *state)
241 {
242 return state->is_version(400, 0) || state->ARB_gpu_shader5_enable;
243 }
244
245 static bool
246 gpu_shader5_es(const _mesa_glsl_parse_state *state)
247 {
248 return state->is_version(400, 320) ||
249 state->ARB_gpu_shader5_enable ||
250 state->EXT_gpu_shader5_enable ||
251 state->OES_gpu_shader5_enable;
252 }
253
254 static bool
255 gpu_shader5_or_OES_texture_cube_map_array(const _mesa_glsl_parse_state *state)
256 {
257 return state->is_version(400, 320) ||
258 state->ARB_gpu_shader5_enable ||
259 state->EXT_texture_cube_map_array_enable ||
260 state->OES_texture_cube_map_array_enable;
261 }
262
263 static bool
264 es31_not_gs5(const _mesa_glsl_parse_state *state)
265 {
266 return state->is_version(0, 310) && !gpu_shader5_es(state);
267 }
268
269 static bool
270 gpu_shader5_or_es31(const _mesa_glsl_parse_state *state)
271 {
272 return state->is_version(400, 310) || state->ARB_gpu_shader5_enable;
273 }
274
275 static bool
276 shader_packing_or_es31_or_gpu_shader5(const _mesa_glsl_parse_state *state)
277 {
278 return state->ARB_shading_language_packing_enable ||
279 state->ARB_gpu_shader5_enable ||
280 state->is_version(400, 310);
281 }
282
283 static bool
284 gpu_shader5_or_es31_or_integer_functions(const _mesa_glsl_parse_state *state)
285 {
286 return gpu_shader5_or_es31(state) ||
287 state->MESA_shader_integer_functions_enable;
288 }
289
290 static bool
291 fs_interpolate_at(const _mesa_glsl_parse_state *state)
292 {
293 return state->stage == MESA_SHADER_FRAGMENT &&
294 (state->is_version(400, 320) ||
295 state->ARB_gpu_shader5_enable ||
296 state->OES_shader_multisample_interpolation_enable);
297 }
298
299
300 static bool
301 texture_array_lod(const _mesa_glsl_parse_state *state)
302 {
303 return lod_exists_in_stage(state) &&
304 state->EXT_texture_array_enable;
305 }
306
307 static bool
308 fs_texture_array(const _mesa_glsl_parse_state *state)
309 {
310 return state->stage == MESA_SHADER_FRAGMENT &&
311 state->EXT_texture_array_enable;
312 }
313
314 static bool
315 texture_array(const _mesa_glsl_parse_state *state)
316 {
317 return state->EXT_texture_array_enable;
318 }
319
320 static bool
321 texture_multisample(const _mesa_glsl_parse_state *state)
322 {
323 return state->is_version(150, 310) ||
324 state->ARB_texture_multisample_enable;
325 }
326
327 static bool
328 texture_multisample_array(const _mesa_glsl_parse_state *state)
329 {
330 return state->is_version(150, 320) ||
331 state->ARB_texture_multisample_enable ||
332 state->OES_texture_storage_multisample_2d_array_enable;
333 }
334
335 static bool
336 texture_samples_identical(const _mesa_glsl_parse_state *state)
337 {
338 return texture_multisample(state) &&
339 state->EXT_shader_samples_identical_enable;
340 }
341
342 static bool
343 texture_samples_identical_array(const _mesa_glsl_parse_state *state)
344 {
345 return texture_multisample_array(state) &&
346 state->EXT_shader_samples_identical_enable;
347 }
348
349 static bool
350 fs_texture_cube_map_array(const _mesa_glsl_parse_state *state)
351 {
352 return state->stage == MESA_SHADER_FRAGMENT &&
353 state->has_texture_cube_map_array();
354 }
355
356 static bool
357 texture_cube_map_array(const _mesa_glsl_parse_state *state)
358 {
359 return state->has_texture_cube_map_array();
360 }
361
362 static bool
363 texture_query_levels(const _mesa_glsl_parse_state *state)
364 {
365 return state->is_version(430, 0) ||
366 state->ARB_texture_query_levels_enable;
367 }
368
369 static bool
370 texture_query_lod(const _mesa_glsl_parse_state *state)
371 {
372 return state->stage == MESA_SHADER_FRAGMENT &&
373 state->ARB_texture_query_lod_enable;
374 }
375
376 static bool
377 texture_gather_cube_map_array(const _mesa_glsl_parse_state *state)
378 {
379 return state->is_version(400, 320) ||
380 state->ARB_texture_gather_enable ||
381 state->ARB_gpu_shader5_enable ||
382 state->EXT_texture_cube_map_array_enable ||
383 state->OES_texture_cube_map_array_enable;
384 }
385
386 static bool
387 texture_gather_or_es31(const _mesa_glsl_parse_state *state)
388 {
389 return state->is_version(400, 310) ||
390 state->ARB_texture_gather_enable ||
391 state->ARB_gpu_shader5_enable;
392 }
393
394 /* Only ARB_texture_gather but not GLSL 4.0 or ARB_gpu_shader5.
395 * used for relaxation of const offset requirements.
396 */
397 static bool
398 texture_gather_only_or_es31(const _mesa_glsl_parse_state *state)
399 {
400 return !state->is_version(400, 320) &&
401 !state->ARB_gpu_shader5_enable &&
402 !state->EXT_gpu_shader5_enable &&
403 !state->OES_gpu_shader5_enable &&
404 (state->ARB_texture_gather_enable ||
405 state->is_version(0, 310));
406 }
407
408 /* Desktop GL or OES_standard_derivatives + fragment shader only */
409 static bool
410 fs_oes_derivatives(const _mesa_glsl_parse_state *state)
411 {
412 return state->stage == MESA_SHADER_FRAGMENT &&
413 (state->is_version(110, 300) ||
414 state->OES_standard_derivatives_enable);
415 }
416
417 static bool
418 fs_derivative_control(const _mesa_glsl_parse_state *state)
419 {
420 return state->stage == MESA_SHADER_FRAGMENT &&
421 (state->is_version(450, 0) ||
422 state->ARB_derivative_control_enable);
423 }
424
425 static bool
426 tex1d_lod(const _mesa_glsl_parse_state *state)
427 {
428 return !state->es_shader && lod_exists_in_stage(state);
429 }
430
431 /** True if sampler3D exists */
432 static bool
433 tex3d(const _mesa_glsl_parse_state *state)
434 {
435 /* sampler3D exists in all desktop GLSL versions, GLSL ES 1.00 with the
436 * OES_texture_3D extension, and in GLSL ES 3.00.
437 */
438 return !state->es_shader ||
439 state->OES_texture_3D_enable ||
440 state->language_version >= 300;
441 }
442
443 static bool
444 fs_tex3d(const _mesa_glsl_parse_state *state)
445 {
446 return state->stage == MESA_SHADER_FRAGMENT &&
447 (!state->es_shader || state->OES_texture_3D_enable);
448 }
449
450 static bool
451 tex3d_lod(const _mesa_glsl_parse_state *state)
452 {
453 return tex3d(state) && lod_exists_in_stage(state);
454 }
455
456 static bool
457 shader_atomic_counters(const _mesa_glsl_parse_state *state)
458 {
459 return state->has_atomic_counters();
460 }
461
462 static bool
463 shader_atomic_counter_ops(const _mesa_glsl_parse_state *state)
464 {
465 return state->ARB_shader_atomic_counter_ops_enable;
466 }
467
468 static bool
469 shader_clock(const _mesa_glsl_parse_state *state)
470 {
471 return state->ARB_shader_clock_enable;
472 }
473
474 static bool
475 shader_clock_int64(const _mesa_glsl_parse_state *state)
476 {
477 return state->ARB_shader_clock_enable &&
478 state->ARB_gpu_shader_int64_enable;
479 }
480
481 static bool
482 shader_storage_buffer_object(const _mesa_glsl_parse_state *state)
483 {
484 return state->has_shader_storage_buffer_objects();
485 }
486
487 static bool
488 shader_trinary_minmax(const _mesa_glsl_parse_state *state)
489 {
490 return state->AMD_shader_trinary_minmax_enable;
491 }
492
493 static bool
494 shader_image_load_store(const _mesa_glsl_parse_state *state)
495 {
496 return (state->is_version(420, 310) ||
497 state->ARB_shader_image_load_store_enable);
498 }
499
500 static bool
501 shader_image_atomic(const _mesa_glsl_parse_state *state)
502 {
503 return (state->is_version(420, 320) ||
504 state->ARB_shader_image_load_store_enable ||
505 state->OES_shader_image_atomic_enable);
506 }
507
508 static bool
509 shader_image_atomic_exchange_float(const _mesa_glsl_parse_state *state)
510 {
511 return (state->is_version(450, 320) ||
512 state->ARB_ES3_1_compatibility_enable ||
513 state->OES_shader_image_atomic_enable);
514 }
515
516 static bool
517 shader_image_size(const _mesa_glsl_parse_state *state)
518 {
519 return state->is_version(430, 310) ||
520 state->ARB_shader_image_size_enable;
521 }
522
523 static bool
524 shader_samples(const _mesa_glsl_parse_state *state)
525 {
526 return state->is_version(450, 0) ||
527 state->ARB_shader_texture_image_samples_enable;
528 }
529
530 static bool
531 gs_streams(const _mesa_glsl_parse_state *state)
532 {
533 return gpu_shader5(state) && gs_only(state);
534 }
535
536 static bool
537 fp64(const _mesa_glsl_parse_state *state)
538 {
539 return state->has_double();
540 }
541
542 static bool
543 int64(const _mesa_glsl_parse_state *state)
544 {
545 return state->has_int64();
546 }
547
548 static bool
549 int64_fp64(const _mesa_glsl_parse_state *state)
550 {
551 return state->has_int64() && state->has_double();
552 }
553
554 static bool
555 compute_shader(const _mesa_glsl_parse_state *state)
556 {
557 return state->stage == MESA_SHADER_COMPUTE;
558 }
559
560 static bool
561 compute_shader_supported(const _mesa_glsl_parse_state *state)
562 {
563 return state->has_compute_shader();
564 }
565
566 static bool
567 buffer_atomics_supported(const _mesa_glsl_parse_state *state)
568 {
569 return compute_shader(state) || shader_storage_buffer_object(state);
570 }
571
572 static bool
573 barrier_supported(const _mesa_glsl_parse_state *state)
574 {
575 return compute_shader(state) ||
576 state->stage == MESA_SHADER_TESS_CTRL;
577 }
578
579 static bool
580 vote(const _mesa_glsl_parse_state *state)
581 {
582 return state->ARB_shader_group_vote_enable;
583 }
584
585 static bool
586 integer_functions_supported(const _mesa_glsl_parse_state *state)
587 {
588 return state->extensions->MESA_shader_integer_functions;
589 }
590 /** @} */
591
592 /******************************************************************************/
593
594 namespace {
595
596 /**
597 * builtin_builder: A singleton object representing the core of the built-in
598 * function module.
599 *
600 * It generates IR for every built-in function signature, and organizes them
601 * into functions.
602 */
603 class builtin_builder {
604 public:
605 builtin_builder();
606 ~builtin_builder();
607
608 void initialize();
609 void release();
610 ir_function_signature *find(_mesa_glsl_parse_state *state,
611 const char *name, exec_list *actual_parameters);
612
613 /**
614 * A shader to hold all the built-in signatures; created by this module.
615 *
616 * This includes signatures for every built-in, regardless of version or
617 * enabled extensions. The availability predicate associated with each
618 * signature allows matching_signature() to filter out the irrelevant ones.
619 */
620 gl_shader *shader;
621
622 private:
623 void *mem_ctx;
624
625 void create_shader();
626 void create_intrinsics();
627 void create_builtins();
628
629 /**
630 * IR builder helpers:
631 *
632 * These convenience functions assist in emitting IR, but don't necessarily
633 * fit in ir_builder itself. Many of them rely on having a mem_ctx class
634 * member available.
635 */
636 ir_variable *in_var(const glsl_type *type, const char *name);
637 ir_variable *out_var(const glsl_type *type, const char *name);
638 ir_constant *imm(float f, unsigned vector_elements=1);
639 ir_constant *imm(bool b, unsigned vector_elements=1);
640 ir_constant *imm(int i, unsigned vector_elements=1);
641 ir_constant *imm(unsigned u, unsigned vector_elements=1);
642 ir_constant *imm(double d, unsigned vector_elements=1);
643 ir_constant *imm(const glsl_type *type, const ir_constant_data &);
644 ir_dereference_variable *var_ref(ir_variable *var);
645 ir_dereference_array *array_ref(ir_variable *var, int i);
646 ir_swizzle *matrix_elt(ir_variable *var, int col, int row);
647
648 ir_expression *asin_expr(ir_variable *x, float p0, float p1);
649 void do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x);
650
651 /**
652 * Call function \param f with parameters specified as the linked
653 * list \param params of \c ir_variable objects. \param ret should
654 * point to the ir_variable that will hold the function return
655 * value, or be \c NULL if the function has void return type.
656 */
657 ir_call *call(ir_function *f, ir_variable *ret, exec_list params);
658
659 /** Create a new function and add the given signatures. */
660 void add_function(const char *name, ...);
661
662 typedef ir_function_signature *(builtin_builder::*image_prototype_ctr)(const glsl_type *image_type,
663 unsigned num_arguments,
664 unsigned flags);
665
666 /**
667 * Create a new image built-in function for all known image types.
668 * \p flags is a bitfield of \c image_function_flags flags.
669 */
670 void add_image_function(const char *name,
671 const char *intrinsic_name,
672 image_prototype_ctr prototype,
673 unsigned num_arguments,
674 unsigned flags,
675 enum ir_intrinsic_id id);
676
677 /**
678 * Create new functions for all known image built-ins and types.
679 * If \p glsl is \c true, use the GLSL built-in names and emit code
680 * to call into the actual compiler intrinsic. If \p glsl is
681 * false, emit a function prototype with no body for each image
682 * intrinsic name.
683 */
684 void add_image_functions(bool glsl);
685
686 ir_function_signature *new_sig(const glsl_type *return_type,
687 builtin_available_predicate avail,
688 int num_params, ...);
689
690 /**
691 * Function signature generators:
692 * @{
693 */
694 ir_function_signature *unop(builtin_available_predicate avail,
695 ir_expression_operation opcode,
696 const glsl_type *return_type,
697 const glsl_type *param_type);
698 ir_function_signature *binop(builtin_available_predicate avail,
699 ir_expression_operation opcode,
700 const glsl_type *return_type,
701 const glsl_type *param0_type,
702 const glsl_type *param1_type);
703
704 #define B0(X) ir_function_signature *_##X();
705 #define B1(X) ir_function_signature *_##X(const glsl_type *);
706 #define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *);
707 #define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *, const glsl_type *);
708 #define BA1(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *);
709 #define BA2(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *, const glsl_type *);
710 B1(radians)
711 B1(degrees)
712 B1(sin)
713 B1(cos)
714 B1(tan)
715 B1(asin)
716 B1(acos)
717 B1(atan2)
718 B1(atan)
719 B1(sinh)
720 B1(cosh)
721 B1(tanh)
722 B1(asinh)
723 B1(acosh)
724 B1(atanh)
725 B1(pow)
726 B1(exp)
727 B1(log)
728 B1(exp2)
729 B1(log2)
730 BA1(sqrt)
731 BA1(inversesqrt)
732 BA1(abs)
733 BA1(sign)
734 BA1(floor)
735 BA1(trunc)
736 BA1(round)
737 BA1(roundEven)
738 BA1(ceil)
739 BA1(fract)
740 BA2(mod)
741 BA1(modf)
742 BA2(min)
743 BA2(max)
744 BA2(clamp)
745 BA2(mix_lrp)
746 ir_function_signature *_mix_sel(builtin_available_predicate avail,
747 const glsl_type *val_type,
748 const glsl_type *blend_type);
749 BA2(step)
750 BA2(smoothstep)
751 BA1(isnan)
752 BA1(isinf)
753 B1(floatBitsToInt)
754 B1(floatBitsToUint)
755 B1(intBitsToFloat)
756 B1(uintBitsToFloat)
757
758 BA1(doubleBitsToInt64)
759 BA1(doubleBitsToUint64)
760 BA1(int64BitsToDouble)
761 BA1(uint64BitsToDouble)
762
763 ir_function_signature *_packUnorm2x16(builtin_available_predicate avail);
764 ir_function_signature *_packSnorm2x16(builtin_available_predicate avail);
765 ir_function_signature *_packUnorm4x8(builtin_available_predicate avail);
766 ir_function_signature *_packSnorm4x8(builtin_available_predicate avail);
767 ir_function_signature *_unpackUnorm2x16(builtin_available_predicate avail);
768 ir_function_signature *_unpackSnorm2x16(builtin_available_predicate avail);
769 ir_function_signature *_unpackUnorm4x8(builtin_available_predicate avail);
770 ir_function_signature *_unpackSnorm4x8(builtin_available_predicate avail);
771 ir_function_signature *_packHalf2x16(builtin_available_predicate avail);
772 ir_function_signature *_unpackHalf2x16(builtin_available_predicate avail);
773 ir_function_signature *_packDouble2x32(builtin_available_predicate avail);
774 ir_function_signature *_unpackDouble2x32(builtin_available_predicate avail);
775 ir_function_signature *_packInt2x32(builtin_available_predicate avail);
776 ir_function_signature *_unpackInt2x32(builtin_available_predicate avail);
777 ir_function_signature *_packUint2x32(builtin_available_predicate avail);
778 ir_function_signature *_unpackUint2x32(builtin_available_predicate avail);
779
780 BA1(length)
781 BA1(distance);
782 BA1(dot);
783 BA1(cross);
784 BA1(normalize);
785 B0(ftransform);
786 BA1(faceforward);
787 BA1(reflect);
788 BA1(refract);
789 BA1(matrixCompMult);
790 BA1(outerProduct);
791 BA1(determinant_mat2);
792 BA1(determinant_mat3);
793 BA1(determinant_mat4);
794 BA1(inverse_mat2);
795 BA1(inverse_mat3);
796 BA1(inverse_mat4);
797 BA1(transpose);
798 BA1(lessThan);
799 BA1(lessThanEqual);
800 BA1(greaterThan);
801 BA1(greaterThanEqual);
802 BA1(equal);
803 BA1(notEqual);
804 B1(any);
805 B1(all);
806 B1(not);
807 BA2(textureSize);
808 B1(textureSamples);
809
810 /** Flags to _texture() */
811 #define TEX_PROJECT 1
812 #define TEX_OFFSET 2
813 #define TEX_COMPONENT 4
814 #define TEX_OFFSET_NONCONST 8
815 #define TEX_OFFSET_ARRAY 16
816
817 ir_function_signature *_texture(ir_texture_opcode opcode,
818 builtin_available_predicate avail,
819 const glsl_type *return_type,
820 const glsl_type *sampler_type,
821 const glsl_type *coord_type,
822 int flags = 0);
823 B0(textureCubeArrayShadow);
824 ir_function_signature *_texelFetch(builtin_available_predicate avail,
825 const glsl_type *return_type,
826 const glsl_type *sampler_type,
827 const glsl_type *coord_type,
828 const glsl_type *offset_type = NULL);
829
830 B0(EmitVertex)
831 B0(EndPrimitive)
832 ir_function_signature *_EmitStreamVertex(builtin_available_predicate avail,
833 const glsl_type *stream_type);
834 ir_function_signature *_EndStreamPrimitive(builtin_available_predicate avail,
835 const glsl_type *stream_type);
836 B0(barrier)
837
838 BA2(textureQueryLod);
839 B1(textureQueryLevels);
840 BA2(textureSamplesIdentical);
841 B1(dFdx);
842 B1(dFdy);
843 B1(fwidth);
844 B1(dFdxCoarse);
845 B1(dFdyCoarse);
846 B1(fwidthCoarse);
847 B1(dFdxFine);
848 B1(dFdyFine);
849 B1(fwidthFine);
850 B1(noise1);
851 B1(noise2);
852 B1(noise3);
853 B1(noise4);
854
855 B1(bitfieldExtract)
856 B1(bitfieldInsert)
857 B1(bitfieldReverse)
858 B1(bitCount)
859 B1(findLSB)
860 B1(findMSB)
861 BA1(fma)
862 B2(ldexp)
863 B2(frexp)
864 B2(dfrexp)
865 B1(uaddCarry)
866 B1(usubBorrow)
867 B1(mulExtended)
868 B1(interpolateAtCentroid)
869 B1(interpolateAtOffset)
870 B1(interpolateAtSample)
871
872 ir_function_signature *_atomic_counter_intrinsic(builtin_available_predicate avail,
873 enum ir_intrinsic_id id);
874 ir_function_signature *_atomic_counter_intrinsic1(builtin_available_predicate avail,
875 enum ir_intrinsic_id id);
876 ir_function_signature *_atomic_counter_intrinsic2(builtin_available_predicate avail,
877 enum ir_intrinsic_id id);
878 ir_function_signature *_atomic_counter_op(const char *intrinsic,
879 builtin_available_predicate avail);
880 ir_function_signature *_atomic_counter_op1(const char *intrinsic,
881 builtin_available_predicate avail);
882 ir_function_signature *_atomic_counter_op2(const char *intrinsic,
883 builtin_available_predicate avail);
884
885 ir_function_signature *_atomic_intrinsic2(builtin_available_predicate avail,
886 const glsl_type *type,
887 enum ir_intrinsic_id id);
888 ir_function_signature *_atomic_op2(const char *intrinsic,
889 builtin_available_predicate avail,
890 const glsl_type *type);
891 ir_function_signature *_atomic_intrinsic3(builtin_available_predicate avail,
892 const glsl_type *type,
893 enum ir_intrinsic_id id);
894 ir_function_signature *_atomic_op3(const char *intrinsic,
895 builtin_available_predicate avail,
896 const glsl_type *type);
897
898 B1(min3)
899 B1(max3)
900 B1(mid3)
901
902 ir_function_signature *_image_prototype(const glsl_type *image_type,
903 unsigned num_arguments,
904 unsigned flags);
905 ir_function_signature *_image_size_prototype(const glsl_type *image_type,
906 unsigned num_arguments,
907 unsigned flags);
908 ir_function_signature *_image_samples_prototype(const glsl_type *image_type,
909 unsigned num_arguments,
910 unsigned flags);
911 ir_function_signature *_image(image_prototype_ctr prototype,
912 const glsl_type *image_type,
913 const char *intrinsic_name,
914 unsigned num_arguments,
915 unsigned flags,
916 enum ir_intrinsic_id id);
917
918 ir_function_signature *_memory_barrier_intrinsic(
919 builtin_available_predicate avail,
920 enum ir_intrinsic_id id);
921 ir_function_signature *_memory_barrier(const char *intrinsic_name,
922 builtin_available_predicate avail);
923
924 ir_function_signature *_shader_clock_intrinsic(builtin_available_predicate avail,
925 const glsl_type *type);
926 ir_function_signature *_shader_clock(builtin_available_predicate avail,
927 const glsl_type *type);
928
929 ir_function_signature *_vote(enum ir_expression_operation opcode);
930
931 #undef B0
932 #undef B1
933 #undef B2
934 #undef B3
935 #undef BA1
936 #undef BA2
937 /** @} */
938 };
939
940 enum image_function_flags {
941 IMAGE_FUNCTION_EMIT_STUB = (1 << 0),
942 IMAGE_FUNCTION_RETURNS_VOID = (1 << 1),
943 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE = (1 << 2),
944 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE = (1 << 3),
945 IMAGE_FUNCTION_READ_ONLY = (1 << 4),
946 IMAGE_FUNCTION_WRITE_ONLY = (1 << 5),
947 IMAGE_FUNCTION_AVAIL_ATOMIC = (1 << 6),
948 IMAGE_FUNCTION_MS_ONLY = (1 << 7),
949 IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE = (1 << 8)
950 };
951
952 } /* anonymous namespace */
953
954 /**
955 * Core builtin_builder functionality:
956 * @{
957 */
958 builtin_builder::builtin_builder()
959 : shader(NULL)
960 {
961 mem_ctx = NULL;
962 }
963
964 builtin_builder::~builtin_builder()
965 {
966 ralloc_free(mem_ctx);
967 }
968
969 ir_function_signature *
970 builtin_builder::find(_mesa_glsl_parse_state *state,
971 const char *name, exec_list *actual_parameters)
972 {
973 /* The shader currently being compiled requested a built-in function;
974 * it needs to link against builtin_builder::shader in order to get them.
975 *
976 * Even if we don't find a matching signature, we still need to do this so
977 * that the "no matching signature" error will list potential candidates
978 * from the available built-ins.
979 */
980 state->uses_builtin_functions = true;
981
982 ir_function *f = shader->symbols->get_function(name);
983 if (f == NULL)
984 return NULL;
985
986 ir_function_signature *sig =
987 f->matching_signature(state, actual_parameters, true);
988 if (sig == NULL)
989 return NULL;
990
991 return sig;
992 }
993
994 void
995 builtin_builder::initialize()
996 {
997 /* If already initialized, don't do it again. */
998 if (mem_ctx != NULL)
999 return;
1000
1001 mem_ctx = ralloc_context(NULL);
1002 create_shader();
1003 create_intrinsics();
1004 create_builtins();
1005 }
1006
1007 void
1008 builtin_builder::release()
1009 {
1010 ralloc_free(mem_ctx);
1011 mem_ctx = NULL;
1012
1013 ralloc_free(shader);
1014 shader = NULL;
1015 }
1016
1017 void
1018 builtin_builder::create_shader()
1019 {
1020 /* The target doesn't actually matter. There's no target for generic
1021 * GLSL utility code that could be linked against any stage, so just
1022 * arbitrarily pick GL_VERTEX_SHADER.
1023 */
1024 shader = _mesa_new_shader(0, MESA_SHADER_VERTEX);
1025 shader->symbols = new(mem_ctx) glsl_symbol_table;
1026 }
1027
1028 /** @} */
1029
1030 /**
1031 * Create ir_function and ir_function_signature objects for each
1032 * intrinsic.
1033 */
1034 void
1035 builtin_builder::create_intrinsics()
1036 {
1037 add_function("__intrinsic_atomic_read",
1038 _atomic_counter_intrinsic(shader_atomic_counters,
1039 ir_intrinsic_atomic_counter_read),
1040 NULL);
1041 add_function("__intrinsic_atomic_increment",
1042 _atomic_counter_intrinsic(shader_atomic_counters,
1043 ir_intrinsic_atomic_counter_increment),
1044 NULL);
1045 add_function("__intrinsic_atomic_predecrement",
1046 _atomic_counter_intrinsic(shader_atomic_counters,
1047 ir_intrinsic_atomic_counter_predecrement),
1048 NULL);
1049
1050 add_function("__intrinsic_atomic_add",
1051 _atomic_intrinsic2(buffer_atomics_supported,
1052 glsl_type::uint_type,
1053 ir_intrinsic_generic_atomic_add),
1054 _atomic_intrinsic2(buffer_atomics_supported,
1055 glsl_type::int_type,
1056 ir_intrinsic_generic_atomic_add),
1057 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1058 ir_intrinsic_atomic_counter_add),
1059 NULL);
1060 add_function("__intrinsic_atomic_min",
1061 _atomic_intrinsic2(buffer_atomics_supported,
1062 glsl_type::uint_type,
1063 ir_intrinsic_generic_atomic_min),
1064 _atomic_intrinsic2(buffer_atomics_supported,
1065 glsl_type::int_type,
1066 ir_intrinsic_generic_atomic_min),
1067 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1068 ir_intrinsic_atomic_counter_min),
1069 NULL);
1070 add_function("__intrinsic_atomic_max",
1071 _atomic_intrinsic2(buffer_atomics_supported,
1072 glsl_type::uint_type,
1073 ir_intrinsic_generic_atomic_max),
1074 _atomic_intrinsic2(buffer_atomics_supported,
1075 glsl_type::int_type,
1076 ir_intrinsic_generic_atomic_max),
1077 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1078 ir_intrinsic_atomic_counter_max),
1079 NULL);
1080 add_function("__intrinsic_atomic_and",
1081 _atomic_intrinsic2(buffer_atomics_supported,
1082 glsl_type::uint_type,
1083 ir_intrinsic_generic_atomic_and),
1084 _atomic_intrinsic2(buffer_atomics_supported,
1085 glsl_type::int_type,
1086 ir_intrinsic_generic_atomic_and),
1087 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1088 ir_intrinsic_atomic_counter_and),
1089 NULL);
1090 add_function("__intrinsic_atomic_or",
1091 _atomic_intrinsic2(buffer_atomics_supported,
1092 glsl_type::uint_type,
1093 ir_intrinsic_generic_atomic_or),
1094 _atomic_intrinsic2(buffer_atomics_supported,
1095 glsl_type::int_type,
1096 ir_intrinsic_generic_atomic_or),
1097 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1098 ir_intrinsic_atomic_counter_or),
1099 NULL);
1100 add_function("__intrinsic_atomic_xor",
1101 _atomic_intrinsic2(buffer_atomics_supported,
1102 glsl_type::uint_type,
1103 ir_intrinsic_generic_atomic_xor),
1104 _atomic_intrinsic2(buffer_atomics_supported,
1105 glsl_type::int_type,
1106 ir_intrinsic_generic_atomic_xor),
1107 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1108 ir_intrinsic_atomic_counter_xor),
1109 NULL);
1110 add_function("__intrinsic_atomic_exchange",
1111 _atomic_intrinsic2(buffer_atomics_supported,
1112 glsl_type::uint_type,
1113 ir_intrinsic_generic_atomic_exchange),
1114 _atomic_intrinsic2(buffer_atomics_supported,
1115 glsl_type::int_type,
1116 ir_intrinsic_generic_atomic_exchange),
1117 _atomic_counter_intrinsic1(shader_atomic_counter_ops,
1118 ir_intrinsic_atomic_counter_exchange),
1119 NULL);
1120 add_function("__intrinsic_atomic_comp_swap",
1121 _atomic_intrinsic3(buffer_atomics_supported,
1122 glsl_type::uint_type,
1123 ir_intrinsic_generic_atomic_comp_swap),
1124 _atomic_intrinsic3(buffer_atomics_supported,
1125 glsl_type::int_type,
1126 ir_intrinsic_generic_atomic_comp_swap),
1127 _atomic_counter_intrinsic2(shader_atomic_counter_ops,
1128 ir_intrinsic_atomic_counter_comp_swap),
1129 NULL);
1130
1131 add_image_functions(false);
1132
1133 add_function("__intrinsic_memory_barrier",
1134 _memory_barrier_intrinsic(shader_image_load_store,
1135 ir_intrinsic_memory_barrier),
1136 NULL);
1137 add_function("__intrinsic_group_memory_barrier",
1138 _memory_barrier_intrinsic(compute_shader,
1139 ir_intrinsic_group_memory_barrier),
1140 NULL);
1141 add_function("__intrinsic_memory_barrier_atomic_counter",
1142 _memory_barrier_intrinsic(compute_shader_supported,
1143 ir_intrinsic_memory_barrier_atomic_counter),
1144 NULL);
1145 add_function("__intrinsic_memory_barrier_buffer",
1146 _memory_barrier_intrinsic(compute_shader_supported,
1147 ir_intrinsic_memory_barrier_buffer),
1148 NULL);
1149 add_function("__intrinsic_memory_barrier_image",
1150 _memory_barrier_intrinsic(compute_shader_supported,
1151 ir_intrinsic_memory_barrier_image),
1152 NULL);
1153 add_function("__intrinsic_memory_barrier_shared",
1154 _memory_barrier_intrinsic(compute_shader,
1155 ir_intrinsic_memory_barrier_shared),
1156 NULL);
1157
1158 add_function("__intrinsic_shader_clock",
1159 _shader_clock_intrinsic(shader_clock,
1160 glsl_type::uvec2_type),
1161 NULL);
1162 }
1163
1164 /**
1165 * Create ir_function and ir_function_signature objects for each built-in.
1166 *
1167 * Contains a list of every available built-in.
1168 */
1169 void
1170 builtin_builder::create_builtins()
1171 {
1172 #define F(NAME) \
1173 add_function(#NAME, \
1174 _##NAME(glsl_type::float_type), \
1175 _##NAME(glsl_type::vec2_type), \
1176 _##NAME(glsl_type::vec3_type), \
1177 _##NAME(glsl_type::vec4_type), \
1178 NULL);
1179
1180 #define FD(NAME) \
1181 add_function(#NAME, \
1182 _##NAME(always_available, glsl_type::float_type), \
1183 _##NAME(always_available, glsl_type::vec2_type), \
1184 _##NAME(always_available, glsl_type::vec3_type), \
1185 _##NAME(always_available, glsl_type::vec4_type), \
1186 _##NAME(fp64, glsl_type::double_type), \
1187 _##NAME(fp64, glsl_type::dvec2_type), \
1188 _##NAME(fp64, glsl_type::dvec3_type), \
1189 _##NAME(fp64, glsl_type::dvec4_type), \
1190 NULL);
1191
1192 #define FD130(NAME) \
1193 add_function(#NAME, \
1194 _##NAME(v130, glsl_type::float_type), \
1195 _##NAME(v130, glsl_type::vec2_type), \
1196 _##NAME(v130, glsl_type::vec3_type), \
1197 _##NAME(v130, glsl_type::vec4_type), \
1198 _##NAME(fp64, glsl_type::double_type), \
1199 _##NAME(fp64, glsl_type::dvec2_type), \
1200 _##NAME(fp64, glsl_type::dvec3_type), \
1201 _##NAME(fp64, glsl_type::dvec4_type), \
1202 NULL);
1203
1204 #define FDGS5(NAME) \
1205 add_function(#NAME, \
1206 _##NAME(gpu_shader5_es, glsl_type::float_type), \
1207 _##NAME(gpu_shader5_es, glsl_type::vec2_type), \
1208 _##NAME(gpu_shader5_es, glsl_type::vec3_type), \
1209 _##NAME(gpu_shader5_es, glsl_type::vec4_type), \
1210 _##NAME(fp64, glsl_type::double_type), \
1211 _##NAME(fp64, glsl_type::dvec2_type), \
1212 _##NAME(fp64, glsl_type::dvec3_type), \
1213 _##NAME(fp64, glsl_type::dvec4_type), \
1214 NULL);
1215
1216 #define FI(NAME) \
1217 add_function(#NAME, \
1218 _##NAME(glsl_type::float_type), \
1219 _##NAME(glsl_type::vec2_type), \
1220 _##NAME(glsl_type::vec3_type), \
1221 _##NAME(glsl_type::vec4_type), \
1222 _##NAME(glsl_type::int_type), \
1223 _##NAME(glsl_type::ivec2_type), \
1224 _##NAME(glsl_type::ivec3_type), \
1225 _##NAME(glsl_type::ivec4_type), \
1226 NULL);
1227
1228 #define FI64(NAME) \
1229 add_function(#NAME, \
1230 _##NAME(always_available, glsl_type::float_type), \
1231 _##NAME(always_available, glsl_type::vec2_type), \
1232 _##NAME(always_available, glsl_type::vec3_type), \
1233 _##NAME(always_available, glsl_type::vec4_type), \
1234 _##NAME(always_available, glsl_type::int_type), \
1235 _##NAME(always_available, glsl_type::ivec2_type), \
1236 _##NAME(always_available, glsl_type::ivec3_type), \
1237 _##NAME(always_available, glsl_type::ivec4_type), \
1238 _##NAME(fp64, glsl_type::double_type), \
1239 _##NAME(fp64, glsl_type::dvec2_type), \
1240 _##NAME(fp64, glsl_type::dvec3_type), \
1241 _##NAME(fp64, glsl_type::dvec4_type), \
1242 _##NAME(int64, glsl_type::int64_t_type), \
1243 _##NAME(int64, glsl_type::i64vec2_type), \
1244 _##NAME(int64, glsl_type::i64vec3_type), \
1245 _##NAME(int64, glsl_type::i64vec4_type), \
1246 NULL);
1247
1248 #define FIUD_VEC(NAME) \
1249 add_function(#NAME, \
1250 _##NAME(always_available, glsl_type::vec2_type), \
1251 _##NAME(always_available, glsl_type::vec3_type), \
1252 _##NAME(always_available, glsl_type::vec4_type), \
1253 \
1254 _##NAME(always_available, glsl_type::ivec2_type), \
1255 _##NAME(always_available, glsl_type::ivec3_type), \
1256 _##NAME(always_available, glsl_type::ivec4_type), \
1257 \
1258 _##NAME(v130, glsl_type::uvec2_type), \
1259 _##NAME(v130, glsl_type::uvec3_type), \
1260 _##NAME(v130, glsl_type::uvec4_type), \
1261 _##NAME(fp64, glsl_type::dvec2_type), \
1262 _##NAME(fp64, glsl_type::dvec3_type), \
1263 _##NAME(fp64, glsl_type::dvec4_type), \
1264 _##NAME(int64, glsl_type::int64_t_type), \
1265 _##NAME(int64, glsl_type::i64vec2_type), \
1266 _##NAME(int64, glsl_type::i64vec3_type), \
1267 _##NAME(int64, glsl_type::i64vec4_type), \
1268 _##NAME(int64, glsl_type::uint64_t_type), \
1269 _##NAME(int64, glsl_type::u64vec2_type), \
1270 _##NAME(int64, glsl_type::u64vec3_type), \
1271 _##NAME(int64, glsl_type::u64vec4_type), \
1272 NULL);
1273
1274 #define IU(NAME) \
1275 add_function(#NAME, \
1276 _##NAME(glsl_type::int_type), \
1277 _##NAME(glsl_type::ivec2_type), \
1278 _##NAME(glsl_type::ivec3_type), \
1279 _##NAME(glsl_type::ivec4_type), \
1280 \
1281 _##NAME(glsl_type::uint_type), \
1282 _##NAME(glsl_type::uvec2_type), \
1283 _##NAME(glsl_type::uvec3_type), \
1284 _##NAME(glsl_type::uvec4_type), \
1285 NULL);
1286
1287 #define FIUBD_VEC(NAME) \
1288 add_function(#NAME, \
1289 _##NAME(always_available, glsl_type::vec2_type), \
1290 _##NAME(always_available, glsl_type::vec3_type), \
1291 _##NAME(always_available, glsl_type::vec4_type), \
1292 \
1293 _##NAME(always_available, glsl_type::ivec2_type), \
1294 _##NAME(always_available, glsl_type::ivec3_type), \
1295 _##NAME(always_available, glsl_type::ivec4_type), \
1296 \
1297 _##NAME(v130, glsl_type::uvec2_type), \
1298 _##NAME(v130, glsl_type::uvec3_type), \
1299 _##NAME(v130, glsl_type::uvec4_type), \
1300 \
1301 _##NAME(always_available, glsl_type::bvec2_type), \
1302 _##NAME(always_available, glsl_type::bvec3_type), \
1303 _##NAME(always_available, glsl_type::bvec4_type), \
1304 \
1305 _##NAME(fp64, glsl_type::dvec2_type), \
1306 _##NAME(fp64, glsl_type::dvec3_type), \
1307 _##NAME(fp64, glsl_type::dvec4_type), \
1308 _##NAME(int64, glsl_type::int64_t_type), \
1309 _##NAME(int64, glsl_type::i64vec2_type), \
1310 _##NAME(int64, glsl_type::i64vec3_type), \
1311 _##NAME(int64, glsl_type::i64vec4_type), \
1312 _##NAME(int64, glsl_type::uint64_t_type), \
1313 _##NAME(int64, glsl_type::u64vec2_type), \
1314 _##NAME(int64, glsl_type::u64vec3_type), \
1315 _##NAME(int64, glsl_type::u64vec4_type), \
1316 NULL);
1317
1318 #define FIUD2_MIXED(NAME) \
1319 add_function(#NAME, \
1320 _##NAME(always_available, glsl_type::float_type, glsl_type::float_type), \
1321 _##NAME(always_available, glsl_type::vec2_type, glsl_type::float_type), \
1322 _##NAME(always_available, glsl_type::vec3_type, glsl_type::float_type), \
1323 _##NAME(always_available, glsl_type::vec4_type, glsl_type::float_type), \
1324 \
1325 _##NAME(always_available, glsl_type::vec2_type, glsl_type::vec2_type), \
1326 _##NAME(always_available, glsl_type::vec3_type, glsl_type::vec3_type), \
1327 _##NAME(always_available, glsl_type::vec4_type, glsl_type::vec4_type), \
1328 \
1329 _##NAME(always_available, glsl_type::int_type, glsl_type::int_type), \
1330 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::int_type), \
1331 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::int_type), \
1332 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::int_type), \
1333 \
1334 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::ivec2_type), \
1335 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
1336 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
1337 \
1338 _##NAME(v130, glsl_type::uint_type, glsl_type::uint_type), \
1339 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uint_type), \
1340 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uint_type), \
1341 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uint_type), \
1342 \
1343 _##NAME(v130, glsl_type::uvec2_type, glsl_type::uvec2_type), \
1344 _##NAME(v130, glsl_type::uvec3_type, glsl_type::uvec3_type), \
1345 _##NAME(v130, glsl_type::uvec4_type, glsl_type::uvec4_type), \
1346 \
1347 _##NAME(fp64, glsl_type::double_type, glsl_type::double_type), \
1348 _##NAME(fp64, glsl_type::dvec2_type, glsl_type::double_type), \
1349 _##NAME(fp64, glsl_type::dvec3_type, glsl_type::double_type), \
1350 _##NAME(fp64, glsl_type::dvec4_type, glsl_type::double_type), \
1351 _##NAME(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type), \
1352 _##NAME(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type), \
1353 _##NAME(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type), \
1354 \
1355 _##NAME(int64, glsl_type::int64_t_type, glsl_type::int64_t_type), \
1356 _##NAME(int64, glsl_type::i64vec2_type, glsl_type::int64_t_type), \
1357 _##NAME(int64, glsl_type::i64vec3_type, glsl_type::int64_t_type), \
1358 _##NAME(int64, glsl_type::i64vec4_type, glsl_type::int64_t_type), \
1359 _##NAME(int64, glsl_type::i64vec2_type, glsl_type::i64vec2_type), \
1360 _##NAME(int64, glsl_type::i64vec3_type, glsl_type::i64vec3_type), \
1361 _##NAME(int64, glsl_type::i64vec4_type, glsl_type::i64vec4_type), \
1362 _##NAME(int64, glsl_type::uint64_t_type, glsl_type::uint64_t_type), \
1363 _##NAME(int64, glsl_type::u64vec2_type, glsl_type::uint64_t_type), \
1364 _##NAME(int64, glsl_type::u64vec3_type, glsl_type::uint64_t_type), \
1365 _##NAME(int64, glsl_type::u64vec4_type, glsl_type::uint64_t_type), \
1366 _##NAME(int64, glsl_type::u64vec2_type, glsl_type::u64vec2_type), \
1367 _##NAME(int64, glsl_type::u64vec3_type, glsl_type::u64vec3_type), \
1368 _##NAME(int64, glsl_type::u64vec4_type, glsl_type::u64vec4_type), \
1369 NULL);
1370
1371 F(radians)
1372 F(degrees)
1373 F(sin)
1374 F(cos)
1375 F(tan)
1376 F(asin)
1377 F(acos)
1378
1379 add_function("atan",
1380 _atan(glsl_type::float_type),
1381 _atan(glsl_type::vec2_type),
1382 _atan(glsl_type::vec3_type),
1383 _atan(glsl_type::vec4_type),
1384 _atan2(glsl_type::float_type),
1385 _atan2(glsl_type::vec2_type),
1386 _atan2(glsl_type::vec3_type),
1387 _atan2(glsl_type::vec4_type),
1388 NULL);
1389
1390 F(sinh)
1391 F(cosh)
1392 F(tanh)
1393 F(asinh)
1394 F(acosh)
1395 F(atanh)
1396 F(pow)
1397 F(exp)
1398 F(log)
1399 F(exp2)
1400 F(log2)
1401 FD(sqrt)
1402 FD(inversesqrt)
1403 FI64(abs)
1404 FI64(sign)
1405 FD(floor)
1406 FD(trunc)
1407 FD(round)
1408 FD(roundEven)
1409 FD(ceil)
1410 FD(fract)
1411
1412 add_function("mod",
1413 _mod(always_available, glsl_type::float_type, glsl_type::float_type),
1414 _mod(always_available, glsl_type::vec2_type, glsl_type::float_type),
1415 _mod(always_available, glsl_type::vec3_type, glsl_type::float_type),
1416 _mod(always_available, glsl_type::vec4_type, glsl_type::float_type),
1417
1418 _mod(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1419 _mod(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1420 _mod(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1421
1422 _mod(fp64, glsl_type::double_type, glsl_type::double_type),
1423 _mod(fp64, glsl_type::dvec2_type, glsl_type::double_type),
1424 _mod(fp64, glsl_type::dvec3_type, glsl_type::double_type),
1425 _mod(fp64, glsl_type::dvec4_type, glsl_type::double_type),
1426
1427 _mod(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1428 _mod(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1429 _mod(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1430 NULL);
1431
1432 FD(modf)
1433
1434 FIUD2_MIXED(min)
1435 FIUD2_MIXED(max)
1436 FIUD2_MIXED(clamp)
1437
1438 add_function("mix",
1439 _mix_lrp(always_available, glsl_type::float_type, glsl_type::float_type),
1440 _mix_lrp(always_available, glsl_type::vec2_type, glsl_type::float_type),
1441 _mix_lrp(always_available, glsl_type::vec3_type, glsl_type::float_type),
1442 _mix_lrp(always_available, glsl_type::vec4_type, glsl_type::float_type),
1443
1444 _mix_lrp(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1445 _mix_lrp(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1446 _mix_lrp(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1447
1448 _mix_lrp(fp64, glsl_type::double_type, glsl_type::double_type),
1449 _mix_lrp(fp64, glsl_type::dvec2_type, glsl_type::double_type),
1450 _mix_lrp(fp64, glsl_type::dvec3_type, glsl_type::double_type),
1451 _mix_lrp(fp64, glsl_type::dvec4_type, glsl_type::double_type),
1452
1453 _mix_lrp(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1454 _mix_lrp(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1455 _mix_lrp(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1456
1457 _mix_sel(v130, glsl_type::float_type, glsl_type::bool_type),
1458 _mix_sel(v130, glsl_type::vec2_type, glsl_type::bvec2_type),
1459 _mix_sel(v130, glsl_type::vec3_type, glsl_type::bvec3_type),
1460 _mix_sel(v130, glsl_type::vec4_type, glsl_type::bvec4_type),
1461
1462 _mix_sel(fp64, glsl_type::double_type, glsl_type::bool_type),
1463 _mix_sel(fp64, glsl_type::dvec2_type, glsl_type::bvec2_type),
1464 _mix_sel(fp64, glsl_type::dvec3_type, glsl_type::bvec3_type),
1465 _mix_sel(fp64, glsl_type::dvec4_type, glsl_type::bvec4_type),
1466
1467 _mix_sel(shader_integer_mix, glsl_type::int_type, glsl_type::bool_type),
1468 _mix_sel(shader_integer_mix, glsl_type::ivec2_type, glsl_type::bvec2_type),
1469 _mix_sel(shader_integer_mix, glsl_type::ivec3_type, glsl_type::bvec3_type),
1470 _mix_sel(shader_integer_mix, glsl_type::ivec4_type, glsl_type::bvec4_type),
1471
1472 _mix_sel(shader_integer_mix, glsl_type::uint_type, glsl_type::bool_type),
1473 _mix_sel(shader_integer_mix, glsl_type::uvec2_type, glsl_type::bvec2_type),
1474 _mix_sel(shader_integer_mix, glsl_type::uvec3_type, glsl_type::bvec3_type),
1475 _mix_sel(shader_integer_mix, glsl_type::uvec4_type, glsl_type::bvec4_type),
1476
1477 _mix_sel(shader_integer_mix, glsl_type::bool_type, glsl_type::bool_type),
1478 _mix_sel(shader_integer_mix, glsl_type::bvec2_type, glsl_type::bvec2_type),
1479 _mix_sel(shader_integer_mix, glsl_type::bvec3_type, glsl_type::bvec3_type),
1480 _mix_sel(shader_integer_mix, glsl_type::bvec4_type, glsl_type::bvec4_type),
1481
1482 _mix_sel(int64, glsl_type::int64_t_type, glsl_type::bool_type),
1483 _mix_sel(int64, glsl_type::i64vec2_type, glsl_type::bvec2_type),
1484 _mix_sel(int64, glsl_type::i64vec3_type, glsl_type::bvec3_type),
1485 _mix_sel(int64, glsl_type::i64vec4_type, glsl_type::bvec4_type),
1486
1487 _mix_sel(int64, glsl_type::uint64_t_type, glsl_type::bool_type),
1488 _mix_sel(int64, glsl_type::u64vec2_type, glsl_type::bvec2_type),
1489 _mix_sel(int64, glsl_type::u64vec3_type, glsl_type::bvec3_type),
1490 _mix_sel(int64, glsl_type::u64vec4_type, glsl_type::bvec4_type),
1491 NULL);
1492
1493 add_function("step",
1494 _step(always_available, glsl_type::float_type, glsl_type::float_type),
1495 _step(always_available, glsl_type::float_type, glsl_type::vec2_type),
1496 _step(always_available, glsl_type::float_type, glsl_type::vec3_type),
1497 _step(always_available, glsl_type::float_type, glsl_type::vec4_type),
1498
1499 _step(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1500 _step(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1501 _step(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1502 _step(fp64, glsl_type::double_type, glsl_type::double_type),
1503 _step(fp64, glsl_type::double_type, glsl_type::dvec2_type),
1504 _step(fp64, glsl_type::double_type, glsl_type::dvec3_type),
1505 _step(fp64, glsl_type::double_type, glsl_type::dvec4_type),
1506
1507 _step(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1508 _step(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1509 _step(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1510 NULL);
1511
1512 add_function("smoothstep",
1513 _smoothstep(always_available, glsl_type::float_type, glsl_type::float_type),
1514 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec2_type),
1515 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec3_type),
1516 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec4_type),
1517
1518 _smoothstep(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1519 _smoothstep(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1520 _smoothstep(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1521 _smoothstep(fp64, glsl_type::double_type, glsl_type::double_type),
1522 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec2_type),
1523 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec3_type),
1524 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec4_type),
1525
1526 _smoothstep(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1527 _smoothstep(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1528 _smoothstep(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1529 NULL);
1530
1531 FD130(isnan)
1532 FD130(isinf)
1533
1534 F(floatBitsToInt)
1535 F(floatBitsToUint)
1536 add_function("intBitsToFloat",
1537 _intBitsToFloat(glsl_type::int_type),
1538 _intBitsToFloat(glsl_type::ivec2_type),
1539 _intBitsToFloat(glsl_type::ivec3_type),
1540 _intBitsToFloat(glsl_type::ivec4_type),
1541 NULL);
1542 add_function("uintBitsToFloat",
1543 _uintBitsToFloat(glsl_type::uint_type),
1544 _uintBitsToFloat(glsl_type::uvec2_type),
1545 _uintBitsToFloat(glsl_type::uvec3_type),
1546 _uintBitsToFloat(glsl_type::uvec4_type),
1547 NULL);
1548
1549 add_function("doubleBitsToInt64",
1550 _doubleBitsToInt64(int64_fp64, glsl_type::double_type),
1551 _doubleBitsToInt64(int64_fp64, glsl_type::dvec2_type),
1552 _doubleBitsToInt64(int64_fp64, glsl_type::dvec3_type),
1553 _doubleBitsToInt64(int64_fp64, glsl_type::dvec4_type),
1554 NULL);
1555
1556 add_function("doubleBitsToUint64",
1557 _doubleBitsToUint64(int64_fp64, glsl_type::double_type),
1558 _doubleBitsToUint64(int64_fp64, glsl_type::dvec2_type),
1559 _doubleBitsToUint64(int64_fp64, glsl_type::dvec3_type),
1560 _doubleBitsToUint64(int64_fp64, glsl_type::dvec4_type),
1561 NULL);
1562
1563 add_function("int64BitsToDouble",
1564 _int64BitsToDouble(int64_fp64, glsl_type::int64_t_type),
1565 _int64BitsToDouble(int64_fp64, glsl_type::i64vec2_type),
1566 _int64BitsToDouble(int64_fp64, glsl_type::i64vec3_type),
1567 _int64BitsToDouble(int64_fp64, glsl_type::i64vec4_type),
1568 NULL);
1569
1570 add_function("uint64BitsToDouble",
1571 _uint64BitsToDouble(int64_fp64, glsl_type::uint64_t_type),
1572 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec2_type),
1573 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec3_type),
1574 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec4_type),
1575 NULL);
1576
1577 add_function("packUnorm2x16", _packUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
1578 add_function("packSnorm2x16", _packSnorm2x16(shader_packing_or_es3), NULL);
1579 add_function("packUnorm4x8", _packUnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
1580 add_function("packSnorm4x8", _packSnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
1581 add_function("unpackUnorm2x16", _unpackUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
1582 add_function("unpackSnorm2x16", _unpackSnorm2x16(shader_packing_or_es3), NULL);
1583 add_function("unpackUnorm4x8", _unpackUnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
1584 add_function("unpackSnorm4x8", _unpackSnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
1585 add_function("packHalf2x16", _packHalf2x16(shader_packing_or_es3), NULL);
1586 add_function("unpackHalf2x16", _unpackHalf2x16(shader_packing_or_es3), NULL);
1587 add_function("packDouble2x32", _packDouble2x32(fp64), NULL);
1588 add_function("unpackDouble2x32", _unpackDouble2x32(fp64), NULL);
1589
1590 add_function("packInt2x32", _packInt2x32(int64), NULL);
1591 add_function("unpackInt2x32", _unpackInt2x32(int64), NULL);
1592 add_function("packUint2x32", _packUint2x32(int64), NULL);
1593 add_function("unpackUint2x32", _unpackUint2x32(int64), NULL);
1594
1595 FD(length)
1596 FD(distance)
1597 FD(dot)
1598
1599 add_function("cross", _cross(always_available, glsl_type::vec3_type),
1600 _cross(fp64, glsl_type::dvec3_type), NULL);
1601
1602 FD(normalize)
1603 add_function("ftransform", _ftransform(), NULL);
1604 FD(faceforward)
1605 FD(reflect)
1606 FD(refract)
1607 // ...
1608 add_function("matrixCompMult",
1609 _matrixCompMult(always_available, glsl_type::mat2_type),
1610 _matrixCompMult(always_available, glsl_type::mat3_type),
1611 _matrixCompMult(always_available, glsl_type::mat4_type),
1612 _matrixCompMult(always_available, glsl_type::mat2x3_type),
1613 _matrixCompMult(always_available, glsl_type::mat2x4_type),
1614 _matrixCompMult(always_available, glsl_type::mat3x2_type),
1615 _matrixCompMult(always_available, glsl_type::mat3x4_type),
1616 _matrixCompMult(always_available, glsl_type::mat4x2_type),
1617 _matrixCompMult(always_available, glsl_type::mat4x3_type),
1618 _matrixCompMult(fp64, glsl_type::dmat2_type),
1619 _matrixCompMult(fp64, glsl_type::dmat3_type),
1620 _matrixCompMult(fp64, glsl_type::dmat4_type),
1621 _matrixCompMult(fp64, glsl_type::dmat2x3_type),
1622 _matrixCompMult(fp64, glsl_type::dmat2x4_type),
1623 _matrixCompMult(fp64, glsl_type::dmat3x2_type),
1624 _matrixCompMult(fp64, glsl_type::dmat3x4_type),
1625 _matrixCompMult(fp64, glsl_type::dmat4x2_type),
1626 _matrixCompMult(fp64, glsl_type::dmat4x3_type),
1627 NULL);
1628 add_function("outerProduct",
1629 _outerProduct(v120, glsl_type::mat2_type),
1630 _outerProduct(v120, glsl_type::mat3_type),
1631 _outerProduct(v120, glsl_type::mat4_type),
1632 _outerProduct(v120, glsl_type::mat2x3_type),
1633 _outerProduct(v120, glsl_type::mat2x4_type),
1634 _outerProduct(v120, glsl_type::mat3x2_type),
1635 _outerProduct(v120, glsl_type::mat3x4_type),
1636 _outerProduct(v120, glsl_type::mat4x2_type),
1637 _outerProduct(v120, glsl_type::mat4x3_type),
1638 _outerProduct(fp64, glsl_type::dmat2_type),
1639 _outerProduct(fp64, glsl_type::dmat3_type),
1640 _outerProduct(fp64, glsl_type::dmat4_type),
1641 _outerProduct(fp64, glsl_type::dmat2x3_type),
1642 _outerProduct(fp64, glsl_type::dmat2x4_type),
1643 _outerProduct(fp64, glsl_type::dmat3x2_type),
1644 _outerProduct(fp64, glsl_type::dmat3x4_type),
1645 _outerProduct(fp64, glsl_type::dmat4x2_type),
1646 _outerProduct(fp64, glsl_type::dmat4x3_type),
1647 NULL);
1648 add_function("determinant",
1649 _determinant_mat2(v120, glsl_type::mat2_type),
1650 _determinant_mat3(v120, glsl_type::mat3_type),
1651 _determinant_mat4(v120, glsl_type::mat4_type),
1652 _determinant_mat2(fp64, glsl_type::dmat2_type),
1653 _determinant_mat3(fp64, glsl_type::dmat3_type),
1654 _determinant_mat4(fp64, glsl_type::dmat4_type),
1655
1656 NULL);
1657 add_function("inverse",
1658 _inverse_mat2(v140_or_es3, glsl_type::mat2_type),
1659 _inverse_mat3(v140_or_es3, glsl_type::mat3_type),
1660 _inverse_mat4(v140_or_es3, glsl_type::mat4_type),
1661 _inverse_mat2(fp64, glsl_type::dmat2_type),
1662 _inverse_mat3(fp64, glsl_type::dmat3_type),
1663 _inverse_mat4(fp64, glsl_type::dmat4_type),
1664 NULL);
1665 add_function("transpose",
1666 _transpose(v120, glsl_type::mat2_type),
1667 _transpose(v120, glsl_type::mat3_type),
1668 _transpose(v120, glsl_type::mat4_type),
1669 _transpose(v120, glsl_type::mat2x3_type),
1670 _transpose(v120, glsl_type::mat2x4_type),
1671 _transpose(v120, glsl_type::mat3x2_type),
1672 _transpose(v120, glsl_type::mat3x4_type),
1673 _transpose(v120, glsl_type::mat4x2_type),
1674 _transpose(v120, glsl_type::mat4x3_type),
1675 _transpose(fp64, glsl_type::dmat2_type),
1676 _transpose(fp64, glsl_type::dmat3_type),
1677 _transpose(fp64, glsl_type::dmat4_type),
1678 _transpose(fp64, glsl_type::dmat2x3_type),
1679 _transpose(fp64, glsl_type::dmat2x4_type),
1680 _transpose(fp64, glsl_type::dmat3x2_type),
1681 _transpose(fp64, glsl_type::dmat3x4_type),
1682 _transpose(fp64, glsl_type::dmat4x2_type),
1683 _transpose(fp64, glsl_type::dmat4x3_type),
1684 NULL);
1685 FIUD_VEC(lessThan)
1686 FIUD_VEC(lessThanEqual)
1687 FIUD_VEC(greaterThan)
1688 FIUD_VEC(greaterThanEqual)
1689 FIUBD_VEC(notEqual)
1690 FIUBD_VEC(equal)
1691
1692 add_function("any",
1693 _any(glsl_type::bvec2_type),
1694 _any(glsl_type::bvec3_type),
1695 _any(glsl_type::bvec4_type),
1696 NULL);
1697
1698 add_function("all",
1699 _all(glsl_type::bvec2_type),
1700 _all(glsl_type::bvec3_type),
1701 _all(glsl_type::bvec4_type),
1702 NULL);
1703
1704 add_function("not",
1705 _not(glsl_type::bvec2_type),
1706 _not(glsl_type::bvec3_type),
1707 _not(glsl_type::bvec4_type),
1708 NULL);
1709
1710 add_function("textureSize",
1711 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1D_type),
1712 _textureSize(v130, glsl_type::int_type, glsl_type::isampler1D_type),
1713 _textureSize(v130, glsl_type::int_type, glsl_type::usampler1D_type),
1714
1715 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2D_type),
1716 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2D_type),
1717 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2D_type),
1718
1719 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler3D_type),
1720 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler3D_type),
1721 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler3D_type),
1722
1723 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCube_type),
1724 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
1725 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
1726
1727 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1DShadow_type),
1728 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DShadow_type),
1729 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCubeShadow_type),
1730
1731 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
1732 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
1733 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
1734 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
1735 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
1736 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
1737
1738 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArrayShadow_type),
1739 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArrayShadow_type),
1740
1741 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArray_type),
1742 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::isamplerCubeArray_type),
1743 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::usamplerCubeArray_type),
1744 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArrayShadow_type),
1745
1746 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
1747 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
1748 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
1749 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRectShadow_type),
1750
1751 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::samplerBuffer_type),
1752 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::isamplerBuffer_type),
1753 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::usamplerBuffer_type),
1754 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::sampler2DMS_type),
1755 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::isampler2DMS_type),
1756 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::usampler2DMS_type),
1757
1758 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::sampler2DMSArray_type),
1759 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::isampler2DMSArray_type),
1760 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::usampler2DMSArray_type),
1761 NULL);
1762
1763 add_function("textureSamples",
1764 _textureSamples(glsl_type::sampler2DMS_type),
1765 _textureSamples(glsl_type::isampler2DMS_type),
1766 _textureSamples(glsl_type::usampler2DMS_type),
1767
1768 _textureSamples(glsl_type::sampler2DMSArray_type),
1769 _textureSamples(glsl_type::isampler2DMSArray_type),
1770 _textureSamples(glsl_type::usampler2DMSArray_type),
1771 NULL);
1772
1773 add_function("texture",
1774 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1775 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1776 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1777
1778 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1779 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1780 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1781
1782 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1783 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1784 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1785
1786 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1787 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1788 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1789
1790 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1791 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1792 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1793
1794 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1795 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1796 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1797
1798 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1799 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1800 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1801
1802 _texture(ir_tex, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1803 _texture(ir_tex, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1804 _texture(ir_tex, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1805
1806 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1807 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
1808 /* samplerCubeArrayShadow is special; it has an extra parameter
1809 * for the shadow comparator since there is no vec5 type.
1810 */
1811 _textureCubeArrayShadow(),
1812
1813 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
1814 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
1815 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
1816
1817 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
1818
1819 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1820 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1821 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1822
1823 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1824 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1825 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1826
1827 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1828 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1829 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1830
1831 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1832 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1833 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1834
1835 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1836 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1837 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
1838
1839 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1840 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1841 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1842
1843 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1844 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1845 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1846
1847 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1848 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1849 _texture(ir_txb, fs_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1850
1851 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1852 NULL);
1853
1854 add_function("textureLod",
1855 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
1856 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
1857 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
1858
1859 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
1860 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
1861 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
1862
1863 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
1864 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
1865 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
1866
1867 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
1868 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
1869 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
1870
1871 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
1872 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
1873
1874 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
1875 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
1876 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
1877
1878 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
1879 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
1880 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
1881
1882 _texture(ir_txl, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
1883 _texture(ir_txl, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
1884 _texture(ir_txl, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
1885
1886 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
1887 NULL);
1888
1889 add_function("textureOffset",
1890 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1891 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1892 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1893
1894 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1895 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1896 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1897
1898 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1899 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1900 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1901
1902 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1903 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1904 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
1905
1906 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1907
1908 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1909 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1910
1911 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1912 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1913 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1914
1915 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1916 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1917 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1918
1919 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1920 /* The next one was forgotten in GLSL 1.30 spec. It's from
1921 * EXT_gpu_shader4 originally. It was added in 4.30 with the
1922 * wrong syntax. This was corrected in 4.40. 4.30 indicates
1923 * that it was intended to be included previously, so allow it
1924 * in 1.30.
1925 */
1926 _texture(ir_tex, v130_desktop, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
1927
1928 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
1929 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
1930 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
1931
1932 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1933 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1934 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
1935
1936 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1937 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1938 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
1939
1940 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1941 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1942
1943 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1944 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1945 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
1946
1947 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1948 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1949 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
1950
1951 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
1952 NULL);
1953
1954 add_function("textureProj",
1955 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1956 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1957 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1958 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1959 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1960 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1961
1962 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1963 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1964 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1965 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1966 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1967 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1968
1969 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1970 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1971 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
1972
1973 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1974 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1975
1976 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1977 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1978 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
1979 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1980 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1981 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
1982
1983 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
1984
1985 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1986 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1987 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
1988 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1989 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1990 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
1991
1992 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1993 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1994 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
1995 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1996 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1997 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
1998
1999 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2000 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2001 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2002
2003 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2004 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2005 NULL);
2006
2007 add_function("texelFetch",
2008 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
2009 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
2010 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
2011
2012 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
2013 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
2014 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
2015
2016 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
2017 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
2018 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
2019
2020 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
2021 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
2022 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
2023
2024 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
2025 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
2026 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
2027
2028 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
2029 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
2030 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
2031
2032 _texelFetch(texture_buffer, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
2033 _texelFetch(texture_buffer, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
2034 _texelFetch(texture_buffer, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
2035
2036 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
2037 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
2038 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
2039
2040 _texelFetch(texture_multisample_array, glsl_type::vec4_type, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
2041 _texelFetch(texture_multisample_array, glsl_type::ivec4_type, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
2042 _texelFetch(texture_multisample_array, glsl_type::uvec4_type, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
2043 NULL);
2044
2045 add_function("texelFetchOffset",
2046 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
2047 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
2048 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
2049
2050 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2051 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2052 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2053
2054 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2055 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2056 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2057
2058 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2059 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2060 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2061
2062 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2063 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2064 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2065
2066 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2067 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2068 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2069
2070 NULL);
2071
2072 add_function("textureProjOffset",
2073 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2074 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2075 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2076 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2077 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2078 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2079
2080 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2081 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2082 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2083 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2084 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2085 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2086
2087 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2088 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2089 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2090
2091 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2092 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2093
2094 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2095 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2096 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2097 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2098 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2099 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2100
2101 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2102
2103 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2104 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2105 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2106 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2107 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2108 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2109
2110 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2111 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2112 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2113 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2114 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2115 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2116
2117 _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2118 _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2119 _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2120
2121 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2122 _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2123 NULL);
2124
2125 add_function("textureLodOffset",
2126 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2127 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2128 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2129
2130 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2131 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2132 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2133
2134 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2135 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2136 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2137
2138 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2139 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2140
2141 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2142 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2143 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2144
2145 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2146 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2147 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2148
2149 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2150 NULL);
2151
2152 add_function("textureProjLod",
2153 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2154 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2155 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2156 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2157 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2158 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2159
2160 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2161 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2162 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2163 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2164 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2165 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2166
2167 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2168 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2169 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2170
2171 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2172 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2173 NULL);
2174
2175 add_function("textureProjLodOffset",
2176 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2177 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2178 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2179 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2180 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2181 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2182
2183 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2184 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2185 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2186 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2187 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2188 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2189
2190 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2191 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2192 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2193
2194 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2195 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2196 NULL);
2197
2198 add_function("textureGrad",
2199 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2200 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
2201 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
2202
2203 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2204 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2205 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2206
2207 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2208 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
2209 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
2210
2211 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2212 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2213 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2214
2215 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2216 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
2217 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
2218
2219 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
2220
2221 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2222 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2223 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
2224
2225 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2226 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
2227 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
2228
2229 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2230 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2231 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2232
2233 _texture(ir_txd, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2234 _texture(ir_txd, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2235 _texture(ir_txd, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2236
2237 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2238 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2239 NULL);
2240
2241 add_function("textureGradOffset",
2242 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2243 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2244 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2245
2246 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2247 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2248 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2249
2250 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2251 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2252 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2253
2254 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2255 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2256 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2257
2258 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2259
2260 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2261 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2262
2263 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2264 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2265 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2266
2267 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2268 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2269 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2270
2271 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2272 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2273 NULL);
2274
2275 add_function("textureProjGrad",
2276 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2277 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2278 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2279 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2280 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2281 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2282
2283 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2284 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2285 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2286 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2287 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2288 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2289
2290 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2291 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2292 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2293
2294 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2295 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2296 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2297 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2298 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2299 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2300
2301 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2302
2303 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2304 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2305 NULL);
2306
2307 add_function("textureProjGradOffset",
2308 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2309 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2310 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2311 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2312 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2313 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2314
2315 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2316 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2317 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2318 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2319 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2320 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2321
2322 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2323 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2324 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2325
2326 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2327 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2328 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2329 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2330 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2331 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2332
2333 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2334
2335 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2336 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2337 NULL);
2338
2339 add_function("EmitVertex", _EmitVertex(), NULL);
2340 add_function("EndPrimitive", _EndPrimitive(), NULL);
2341 add_function("EmitStreamVertex",
2342 _EmitStreamVertex(gs_streams, glsl_type::uint_type),
2343 _EmitStreamVertex(gs_streams, glsl_type::int_type),
2344 NULL);
2345 add_function("EndStreamPrimitive",
2346 _EndStreamPrimitive(gs_streams, glsl_type::uint_type),
2347 _EndStreamPrimitive(gs_streams, glsl_type::int_type),
2348 NULL);
2349 add_function("barrier", _barrier(), NULL);
2350
2351 add_function("textureQueryLOD",
2352 _textureQueryLod(texture_query_lod, glsl_type::sampler1D_type, glsl_type::float_type),
2353 _textureQueryLod(texture_query_lod, glsl_type::isampler1D_type, glsl_type::float_type),
2354 _textureQueryLod(texture_query_lod, glsl_type::usampler1D_type, glsl_type::float_type),
2355
2356 _textureQueryLod(texture_query_lod, glsl_type::sampler2D_type, glsl_type::vec2_type),
2357 _textureQueryLod(texture_query_lod, glsl_type::isampler2D_type, glsl_type::vec2_type),
2358 _textureQueryLod(texture_query_lod, glsl_type::usampler2D_type, glsl_type::vec2_type),
2359
2360 _textureQueryLod(texture_query_lod, glsl_type::sampler3D_type, glsl_type::vec3_type),
2361 _textureQueryLod(texture_query_lod, glsl_type::isampler3D_type, glsl_type::vec3_type),
2362 _textureQueryLod(texture_query_lod, glsl_type::usampler3D_type, glsl_type::vec3_type),
2363
2364 _textureQueryLod(texture_query_lod, glsl_type::samplerCube_type, glsl_type::vec3_type),
2365 _textureQueryLod(texture_query_lod, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2366 _textureQueryLod(texture_query_lod, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2367
2368 _textureQueryLod(texture_query_lod, glsl_type::sampler1DArray_type, glsl_type::float_type),
2369 _textureQueryLod(texture_query_lod, glsl_type::isampler1DArray_type, glsl_type::float_type),
2370 _textureQueryLod(texture_query_lod, glsl_type::usampler1DArray_type, glsl_type::float_type),
2371
2372 _textureQueryLod(texture_query_lod, glsl_type::sampler2DArray_type, glsl_type::vec2_type),
2373 _textureQueryLod(texture_query_lod, glsl_type::isampler2DArray_type, glsl_type::vec2_type),
2374 _textureQueryLod(texture_query_lod, glsl_type::usampler2DArray_type, glsl_type::vec2_type),
2375
2376 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
2377 _textureQueryLod(texture_query_lod, glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
2378 _textureQueryLod(texture_query_lod, glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
2379
2380 _textureQueryLod(texture_query_lod, glsl_type::sampler1DShadow_type, glsl_type::float_type),
2381 _textureQueryLod(texture_query_lod, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
2382 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
2383 _textureQueryLod(texture_query_lod, glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
2384 _textureQueryLod(texture_query_lod, glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
2385 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
2386 NULL);
2387
2388 add_function("textureQueryLod",
2389 _textureQueryLod(v400_fs_only, glsl_type::sampler1D_type, glsl_type::float_type),
2390 _textureQueryLod(v400_fs_only, glsl_type::isampler1D_type, glsl_type::float_type),
2391 _textureQueryLod(v400_fs_only, glsl_type::usampler1D_type, glsl_type::float_type),
2392
2393 _textureQueryLod(v400_fs_only, glsl_type::sampler2D_type, glsl_type::vec2_type),
2394 _textureQueryLod(v400_fs_only, glsl_type::isampler2D_type, glsl_type::vec2_type),
2395 _textureQueryLod(v400_fs_only, glsl_type::usampler2D_type, glsl_type::vec2_type),
2396
2397 _textureQueryLod(v400_fs_only, glsl_type::sampler3D_type, glsl_type::vec3_type),
2398 _textureQueryLod(v400_fs_only, glsl_type::isampler3D_type, glsl_type::vec3_type),
2399 _textureQueryLod(v400_fs_only, glsl_type::usampler3D_type, glsl_type::vec3_type),
2400
2401 _textureQueryLod(v400_fs_only, glsl_type::samplerCube_type, glsl_type::vec3_type),
2402 _textureQueryLod(v400_fs_only, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2403 _textureQueryLod(v400_fs_only, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2404
2405 _textureQueryLod(v400_fs_only, glsl_type::sampler1DArray_type, glsl_type::float_type),
2406 _textureQueryLod(v400_fs_only, glsl_type::isampler1DArray_type, glsl_type::float_type),
2407 _textureQueryLod(v400_fs_only, glsl_type::usampler1DArray_type, glsl_type::float_type),
2408
2409 _textureQueryLod(v400_fs_only, glsl_type::sampler2DArray_type, glsl_type::vec2_type),
2410 _textureQueryLod(v400_fs_only, glsl_type::isampler2DArray_type, glsl_type::vec2_type),
2411 _textureQueryLod(v400_fs_only, glsl_type::usampler2DArray_type, glsl_type::vec2_type),
2412
2413 _textureQueryLod(v400_fs_only, glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
2414 _textureQueryLod(v400_fs_only, glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
2415 _textureQueryLod(v400_fs_only, glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
2416
2417 _textureQueryLod(v400_fs_only, glsl_type::sampler1DShadow_type, glsl_type::float_type),
2418 _textureQueryLod(v400_fs_only, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
2419 _textureQueryLod(v400_fs_only, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
2420 _textureQueryLod(v400_fs_only, glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
2421 _textureQueryLod(v400_fs_only, glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
2422 _textureQueryLod(v400_fs_only, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
2423 NULL);
2424
2425 add_function("textureQueryLevels",
2426 _textureQueryLevels(glsl_type::sampler1D_type),
2427 _textureQueryLevels(glsl_type::sampler2D_type),
2428 _textureQueryLevels(glsl_type::sampler3D_type),
2429 _textureQueryLevels(glsl_type::samplerCube_type),
2430 _textureQueryLevels(glsl_type::sampler1DArray_type),
2431 _textureQueryLevels(glsl_type::sampler2DArray_type),
2432 _textureQueryLevels(glsl_type::samplerCubeArray_type),
2433 _textureQueryLevels(glsl_type::sampler1DShadow_type),
2434 _textureQueryLevels(glsl_type::sampler2DShadow_type),
2435 _textureQueryLevels(glsl_type::samplerCubeShadow_type),
2436 _textureQueryLevels(glsl_type::sampler1DArrayShadow_type),
2437 _textureQueryLevels(glsl_type::sampler2DArrayShadow_type),
2438 _textureQueryLevels(glsl_type::samplerCubeArrayShadow_type),
2439
2440 _textureQueryLevels(glsl_type::isampler1D_type),
2441 _textureQueryLevels(glsl_type::isampler2D_type),
2442 _textureQueryLevels(glsl_type::isampler3D_type),
2443 _textureQueryLevels(glsl_type::isamplerCube_type),
2444 _textureQueryLevels(glsl_type::isampler1DArray_type),
2445 _textureQueryLevels(glsl_type::isampler2DArray_type),
2446 _textureQueryLevels(glsl_type::isamplerCubeArray_type),
2447
2448 _textureQueryLevels(glsl_type::usampler1D_type),
2449 _textureQueryLevels(glsl_type::usampler2D_type),
2450 _textureQueryLevels(glsl_type::usampler3D_type),
2451 _textureQueryLevels(glsl_type::usamplerCube_type),
2452 _textureQueryLevels(glsl_type::usampler1DArray_type),
2453 _textureQueryLevels(glsl_type::usampler2DArray_type),
2454 _textureQueryLevels(glsl_type::usamplerCubeArray_type),
2455
2456 NULL);
2457
2458 add_function("textureSamplesIdenticalEXT",
2459 _textureSamplesIdentical(texture_samples_identical, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
2460 _textureSamplesIdentical(texture_samples_identical, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
2461 _textureSamplesIdentical(texture_samples_identical, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
2462
2463 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
2464 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
2465 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
2466 NULL);
2467
2468 add_function("texture1D",
2469 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2470 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2471 NULL);
2472
2473 add_function("texture1DArray",
2474 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2475 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2476 NULL);
2477
2478 add_function("texture1DProj",
2479 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2480 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2481 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2482 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2483 NULL);
2484
2485 add_function("texture1DLod",
2486 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2487 NULL);
2488
2489 add_function("texture1DArrayLod",
2490 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2491 NULL);
2492
2493 add_function("texture1DProjLod",
2494 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2495 _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2496 NULL);
2497
2498 add_function("texture2D",
2499 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2500 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2501 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
2502 NULL);
2503
2504 add_function("texture2DArray",
2505 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2506 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2507 NULL);
2508
2509 add_function("texture2DProj",
2510 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2511 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2512 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2513 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2514 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
2515 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
2516 NULL);
2517
2518 add_function("texture2DLod",
2519 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2520 NULL);
2521
2522 add_function("texture2DArrayLod",
2523 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2524 NULL);
2525
2526 add_function("texture2DProjLod",
2527 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2528 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2529 NULL);
2530
2531 add_function("texture3D",
2532 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2533 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2534 NULL);
2535
2536 add_function("texture3DProj",
2537 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2538 _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2539 NULL);
2540
2541 add_function("texture3DLod",
2542 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2543 NULL);
2544
2545 add_function("texture3DProjLod",
2546 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2547 NULL);
2548
2549 add_function("textureCube",
2550 _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2551 _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2552 NULL);
2553
2554 add_function("textureCubeLod",
2555 _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2556 NULL);
2557
2558 add_function("texture2DRect",
2559 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2560 NULL);
2561
2562 add_function("texture2DRectProj",
2563 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2564 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2565 NULL);
2566
2567 add_function("shadow1D",
2568 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2569 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2570 NULL);
2571
2572 add_function("shadow1DArray",
2573 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2574 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2575 NULL);
2576
2577 add_function("shadow2D",
2578 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2579 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2580 NULL);
2581
2582 add_function("shadow2DArray",
2583 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2584 _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2585 NULL);
2586
2587 add_function("shadow1DProj",
2588 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2589 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2590 NULL);
2591
2592 add_function("shadow2DProj",
2593 _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2594 _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2595 NULL);
2596
2597 add_function("shadow1DLod",
2598 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2599 NULL);
2600
2601 add_function("shadow2DLod",
2602 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2603 NULL);
2604
2605 add_function("shadow1DArrayLod",
2606 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2607 NULL);
2608
2609 add_function("shadow1DProjLod",
2610 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2611 NULL);
2612
2613 add_function("shadow2DProjLod",
2614 _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2615 NULL);
2616
2617 add_function("shadow2DRect",
2618 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
2619 NULL);
2620
2621 add_function("shadow2DRectProj",
2622 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2623 NULL);
2624
2625 add_function("texture1DGradARB",
2626 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2627 NULL);
2628
2629 add_function("texture1DProjGradARB",
2630 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2631 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2632 NULL);
2633
2634 add_function("texture2DGradARB",
2635 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2636 NULL);
2637
2638 add_function("texture2DProjGradARB",
2639 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2640 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2641 NULL);
2642
2643 add_function("texture3DGradARB",
2644 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2645 NULL);
2646
2647 add_function("texture3DProjGradARB",
2648 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2649 NULL);
2650
2651 add_function("textureCubeGradARB",
2652 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2653 NULL);
2654
2655 add_function("shadow1DGradARB",
2656 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2657 NULL);
2658
2659 add_function("shadow1DProjGradARB",
2660 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2661 NULL);
2662
2663 add_function("shadow2DGradARB",
2664 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2665 NULL);
2666
2667 add_function("shadow2DProjGradARB",
2668 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2669 NULL);
2670
2671 add_function("texture2DRectGradARB",
2672 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2673 NULL);
2674
2675 add_function("texture2DRectProjGradARB",
2676 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2677 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2678 NULL);
2679
2680 add_function("shadow2DRectGradARB",
2681 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
2682 NULL);
2683
2684 add_function("shadow2DRectProjGradARB",
2685 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2686 NULL);
2687
2688 add_function("textureGather",
2689 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2690 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2691 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2692
2693 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2694 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
2695 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
2696
2697 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2698 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2699 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2700
2701 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2702 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2703 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2704
2705 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2706 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2707 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2708
2709 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2710 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2711 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
2712
2713 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2714 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2715 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
2716
2717 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2718 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2719 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
2720
2721 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2722 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2723 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
2724
2725 _texture(ir_tg4, gpu_shader5_or_OES_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2726 _texture(ir_tg4, gpu_shader5_or_OES_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2727 _texture(ir_tg4, gpu_shader5_or_OES_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
2728
2729 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
2730 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type),
2731 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
2732 _texture(ir_tg4, gpu_shader5_or_OES_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec4_type),
2733 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type),
2734 NULL);
2735
2736 add_function("textureGatherOffset",
2737 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2738 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2739 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2740
2741 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2742 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2743 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2744
2745 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
2746 _texture(ir_tg4, es31_not_gs5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
2747 _texture(ir_tg4, es31_not_gs5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
2748
2749 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
2750 _texture(ir_tg4, es31_not_gs5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
2751 _texture(ir_tg4, es31_not_gs5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
2752
2753 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2754 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2755 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2756
2757 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2758 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2759 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2760
2761 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2762 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2763 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2764
2765 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2766 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2767 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2768
2769 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2770 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2771 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2772
2773 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2774 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2775 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
2776
2777 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2778 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
2779 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
2780
2781 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET),
2782 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2783 NULL);
2784
2785 add_function("textureGatherOffsets",
2786 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2787 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2788 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2789
2790 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2791 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2792 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2793
2794 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2795 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2796 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2797
2798 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2799 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2800 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2801
2802 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2803 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2804 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2805
2806 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2807 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2808 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
2809
2810 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2811 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
2812 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
2813 NULL);
2814
2815 F(dFdx)
2816 F(dFdy)
2817 F(fwidth)
2818 F(dFdxCoarse)
2819 F(dFdyCoarse)
2820 F(fwidthCoarse)
2821 F(dFdxFine)
2822 F(dFdyFine)
2823 F(fwidthFine)
2824 F(noise1)
2825 F(noise2)
2826 F(noise3)
2827 F(noise4)
2828
2829 IU(bitfieldExtract)
2830 IU(bitfieldInsert)
2831 IU(bitfieldReverse)
2832 IU(bitCount)
2833 IU(findLSB)
2834 IU(findMSB)
2835 FDGS5(fma)
2836
2837 add_function("ldexp",
2838 _ldexp(glsl_type::float_type, glsl_type::int_type),
2839 _ldexp(glsl_type::vec2_type, glsl_type::ivec2_type),
2840 _ldexp(glsl_type::vec3_type, glsl_type::ivec3_type),
2841 _ldexp(glsl_type::vec4_type, glsl_type::ivec4_type),
2842 _ldexp(glsl_type::double_type, glsl_type::int_type),
2843 _ldexp(glsl_type::dvec2_type, glsl_type::ivec2_type),
2844 _ldexp(glsl_type::dvec3_type, glsl_type::ivec3_type),
2845 _ldexp(glsl_type::dvec4_type, glsl_type::ivec4_type),
2846 NULL);
2847
2848 add_function("frexp",
2849 _frexp(glsl_type::float_type, glsl_type::int_type),
2850 _frexp(glsl_type::vec2_type, glsl_type::ivec2_type),
2851 _frexp(glsl_type::vec3_type, glsl_type::ivec3_type),
2852 _frexp(glsl_type::vec4_type, glsl_type::ivec4_type),
2853 _dfrexp(glsl_type::double_type, glsl_type::int_type),
2854 _dfrexp(glsl_type::dvec2_type, glsl_type::ivec2_type),
2855 _dfrexp(glsl_type::dvec3_type, glsl_type::ivec3_type),
2856 _dfrexp(glsl_type::dvec4_type, glsl_type::ivec4_type),
2857 NULL);
2858 add_function("uaddCarry",
2859 _uaddCarry(glsl_type::uint_type),
2860 _uaddCarry(glsl_type::uvec2_type),
2861 _uaddCarry(glsl_type::uvec3_type),
2862 _uaddCarry(glsl_type::uvec4_type),
2863 NULL);
2864 add_function("usubBorrow",
2865 _usubBorrow(glsl_type::uint_type),
2866 _usubBorrow(glsl_type::uvec2_type),
2867 _usubBorrow(glsl_type::uvec3_type),
2868 _usubBorrow(glsl_type::uvec4_type),
2869 NULL);
2870 add_function("imulExtended",
2871 _mulExtended(glsl_type::int_type),
2872 _mulExtended(glsl_type::ivec2_type),
2873 _mulExtended(glsl_type::ivec3_type),
2874 _mulExtended(glsl_type::ivec4_type),
2875 NULL);
2876 add_function("umulExtended",
2877 _mulExtended(glsl_type::uint_type),
2878 _mulExtended(glsl_type::uvec2_type),
2879 _mulExtended(glsl_type::uvec3_type),
2880 _mulExtended(glsl_type::uvec4_type),
2881 NULL);
2882 add_function("interpolateAtCentroid",
2883 _interpolateAtCentroid(glsl_type::float_type),
2884 _interpolateAtCentroid(glsl_type::vec2_type),
2885 _interpolateAtCentroid(glsl_type::vec3_type),
2886 _interpolateAtCentroid(glsl_type::vec4_type),
2887 NULL);
2888 add_function("interpolateAtOffset",
2889 _interpolateAtOffset(glsl_type::float_type),
2890 _interpolateAtOffset(glsl_type::vec2_type),
2891 _interpolateAtOffset(glsl_type::vec3_type),
2892 _interpolateAtOffset(glsl_type::vec4_type),
2893 NULL);
2894 add_function("interpolateAtSample",
2895 _interpolateAtSample(glsl_type::float_type),
2896 _interpolateAtSample(glsl_type::vec2_type),
2897 _interpolateAtSample(glsl_type::vec3_type),
2898 _interpolateAtSample(glsl_type::vec4_type),
2899 NULL);
2900
2901 add_function("atomicCounter",
2902 _atomic_counter_op("__intrinsic_atomic_read",
2903 shader_atomic_counters),
2904 NULL);
2905 add_function("atomicCounterIncrement",
2906 _atomic_counter_op("__intrinsic_atomic_increment",
2907 shader_atomic_counters),
2908 NULL);
2909 add_function("atomicCounterDecrement",
2910 _atomic_counter_op("__intrinsic_atomic_predecrement",
2911 shader_atomic_counters),
2912 NULL);
2913
2914 add_function("atomicCounterAddARB",
2915 _atomic_counter_op1("__intrinsic_atomic_add",
2916 shader_atomic_counter_ops),
2917 NULL);
2918 add_function("atomicCounterSubtractARB",
2919 _atomic_counter_op1("__intrinsic_atomic_sub",
2920 shader_atomic_counter_ops),
2921 NULL);
2922 add_function("atomicCounterMinARB",
2923 _atomic_counter_op1("__intrinsic_atomic_min",
2924 shader_atomic_counter_ops),
2925 NULL);
2926 add_function("atomicCounterMaxARB",
2927 _atomic_counter_op1("__intrinsic_atomic_max",
2928 shader_atomic_counter_ops),
2929 NULL);
2930 add_function("atomicCounterAndARB",
2931 _atomic_counter_op1("__intrinsic_atomic_and",
2932 shader_atomic_counter_ops),
2933 NULL);
2934 add_function("atomicCounterOrARB",
2935 _atomic_counter_op1("__intrinsic_atomic_or",
2936 shader_atomic_counter_ops),
2937 NULL);
2938 add_function("atomicCounterXorARB",
2939 _atomic_counter_op1("__intrinsic_atomic_xor",
2940 shader_atomic_counter_ops),
2941 NULL);
2942 add_function("atomicCounterExchangeARB",
2943 _atomic_counter_op1("__intrinsic_atomic_exchange",
2944 shader_atomic_counter_ops),
2945 NULL);
2946 add_function("atomicCounterCompSwapARB",
2947 _atomic_counter_op2("__intrinsic_atomic_comp_swap",
2948 shader_atomic_counter_ops),
2949 NULL);
2950
2951 add_function("atomicAdd",
2952 _atomic_op2("__intrinsic_atomic_add",
2953 buffer_atomics_supported,
2954 glsl_type::uint_type),
2955 _atomic_op2("__intrinsic_atomic_add",
2956 buffer_atomics_supported,
2957 glsl_type::int_type),
2958 NULL);
2959 add_function("atomicMin",
2960 _atomic_op2("__intrinsic_atomic_min",
2961 buffer_atomics_supported,
2962 glsl_type::uint_type),
2963 _atomic_op2("__intrinsic_atomic_min",
2964 buffer_atomics_supported,
2965 glsl_type::int_type),
2966 NULL);
2967 add_function("atomicMax",
2968 _atomic_op2("__intrinsic_atomic_max",
2969 buffer_atomics_supported,
2970 glsl_type::uint_type),
2971 _atomic_op2("__intrinsic_atomic_max",
2972 buffer_atomics_supported,
2973 glsl_type::int_type),
2974 NULL);
2975 add_function("atomicAnd",
2976 _atomic_op2("__intrinsic_atomic_and",
2977 buffer_atomics_supported,
2978 glsl_type::uint_type),
2979 _atomic_op2("__intrinsic_atomic_and",
2980 buffer_atomics_supported,
2981 glsl_type::int_type),
2982 NULL);
2983 add_function("atomicOr",
2984 _atomic_op2("__intrinsic_atomic_or",
2985 buffer_atomics_supported,
2986 glsl_type::uint_type),
2987 _atomic_op2("__intrinsic_atomic_or",
2988 buffer_atomics_supported,
2989 glsl_type::int_type),
2990 NULL);
2991 add_function("atomicXor",
2992 _atomic_op2("__intrinsic_atomic_xor",
2993 buffer_atomics_supported,
2994 glsl_type::uint_type),
2995 _atomic_op2("__intrinsic_atomic_xor",
2996 buffer_atomics_supported,
2997 glsl_type::int_type),
2998 NULL);
2999 add_function("atomicExchange",
3000 _atomic_op2("__intrinsic_atomic_exchange",
3001 buffer_atomics_supported,
3002 glsl_type::uint_type),
3003 _atomic_op2("__intrinsic_atomic_exchange",
3004 buffer_atomics_supported,
3005 glsl_type::int_type),
3006 NULL);
3007 add_function("atomicCompSwap",
3008 _atomic_op3("__intrinsic_atomic_comp_swap",
3009 buffer_atomics_supported,
3010 glsl_type::uint_type),
3011 _atomic_op3("__intrinsic_atomic_comp_swap",
3012 buffer_atomics_supported,
3013 glsl_type::int_type),
3014 NULL);
3015
3016 add_function("min3",
3017 _min3(glsl_type::float_type),
3018 _min3(glsl_type::vec2_type),
3019 _min3(glsl_type::vec3_type),
3020 _min3(glsl_type::vec4_type),
3021
3022 _min3(glsl_type::int_type),
3023 _min3(glsl_type::ivec2_type),
3024 _min3(glsl_type::ivec3_type),
3025 _min3(glsl_type::ivec4_type),
3026
3027 _min3(glsl_type::uint_type),
3028 _min3(glsl_type::uvec2_type),
3029 _min3(glsl_type::uvec3_type),
3030 _min3(glsl_type::uvec4_type),
3031 NULL);
3032
3033 add_function("max3",
3034 _max3(glsl_type::float_type),
3035 _max3(glsl_type::vec2_type),
3036 _max3(glsl_type::vec3_type),
3037 _max3(glsl_type::vec4_type),
3038
3039 _max3(glsl_type::int_type),
3040 _max3(glsl_type::ivec2_type),
3041 _max3(glsl_type::ivec3_type),
3042 _max3(glsl_type::ivec4_type),
3043
3044 _max3(glsl_type::uint_type),
3045 _max3(glsl_type::uvec2_type),
3046 _max3(glsl_type::uvec3_type),
3047 _max3(glsl_type::uvec4_type),
3048 NULL);
3049
3050 add_function("mid3",
3051 _mid3(glsl_type::float_type),
3052 _mid3(glsl_type::vec2_type),
3053 _mid3(glsl_type::vec3_type),
3054 _mid3(glsl_type::vec4_type),
3055
3056 _mid3(glsl_type::int_type),
3057 _mid3(glsl_type::ivec2_type),
3058 _mid3(glsl_type::ivec3_type),
3059 _mid3(glsl_type::ivec4_type),
3060
3061 _mid3(glsl_type::uint_type),
3062 _mid3(glsl_type::uvec2_type),
3063 _mid3(glsl_type::uvec3_type),
3064 _mid3(glsl_type::uvec4_type),
3065 NULL);
3066
3067 add_image_functions(true);
3068
3069 add_function("memoryBarrier",
3070 _memory_barrier("__intrinsic_memory_barrier",
3071 shader_image_load_store),
3072 NULL);
3073 add_function("groupMemoryBarrier",
3074 _memory_barrier("__intrinsic_group_memory_barrier",
3075 compute_shader),
3076 NULL);
3077 add_function("memoryBarrierAtomicCounter",
3078 _memory_barrier("__intrinsic_memory_barrier_atomic_counter",
3079 compute_shader_supported),
3080 NULL);
3081 add_function("memoryBarrierBuffer",
3082 _memory_barrier("__intrinsic_memory_barrier_buffer",
3083 compute_shader_supported),
3084 NULL);
3085 add_function("memoryBarrierImage",
3086 _memory_barrier("__intrinsic_memory_barrier_image",
3087 compute_shader_supported),
3088 NULL);
3089 add_function("memoryBarrierShared",
3090 _memory_barrier("__intrinsic_memory_barrier_shared",
3091 compute_shader),
3092 NULL);
3093
3094 add_function("clock2x32ARB",
3095 _shader_clock(shader_clock,
3096 glsl_type::uvec2_type),
3097 NULL);
3098
3099 add_function("clockARB",
3100 _shader_clock(shader_clock_int64,
3101 glsl_type::uint64_t_type),
3102 NULL);
3103
3104 add_function("anyInvocationARB", _vote(ir_unop_vote_any), NULL);
3105 add_function("allInvocationsARB", _vote(ir_unop_vote_all), NULL);
3106 add_function("allInvocationsEqualARB", _vote(ir_unop_vote_eq), NULL);
3107
3108 add_function("__builtin_idiv64",
3109 generate_ir::idiv64(mem_ctx, integer_functions_supported),
3110 NULL);
3111
3112 add_function("__builtin_imod64",
3113 generate_ir::imod64(mem_ctx, integer_functions_supported),
3114 NULL);
3115
3116 add_function("__builtin_sign64",
3117 generate_ir::sign64(mem_ctx, integer_functions_supported),
3118 NULL);
3119
3120 add_function("__builtin_udiv64",
3121 generate_ir::udiv64(mem_ctx, integer_functions_supported),
3122 NULL);
3123
3124 add_function("__builtin_umod64",
3125 generate_ir::umod64(mem_ctx, integer_functions_supported),
3126 NULL);
3127
3128 add_function("__builtin_umul64",
3129 generate_ir::umul64(mem_ctx, integer_functions_supported),
3130 NULL);
3131
3132 #undef F
3133 #undef FI
3134 #undef FIUD_VEC
3135 #undef FIUBD_VEC
3136 #undef FIU2_MIXED
3137 }
3138
3139 void
3140 builtin_builder::add_function(const char *name, ...)
3141 {
3142 va_list ap;
3143
3144 ir_function *f = new(mem_ctx) ir_function(name);
3145
3146 va_start(ap, name);
3147 while (true) {
3148 ir_function_signature *sig = va_arg(ap, ir_function_signature *);
3149 if (sig == NULL)
3150 break;
3151
3152 if (false) {
3153 exec_list stuff;
3154 stuff.push_tail(sig);
3155 validate_ir_tree(&stuff);
3156 }
3157
3158 f->add_signature(sig);
3159 }
3160 va_end(ap);
3161
3162 shader->symbols->add_function(f);
3163 }
3164
3165 void
3166 builtin_builder::add_image_function(const char *name,
3167 const char *intrinsic_name,
3168 image_prototype_ctr prototype,
3169 unsigned num_arguments,
3170 unsigned flags,
3171 enum ir_intrinsic_id intrinsic_id)
3172 {
3173 static const glsl_type *const types[] = {
3174 glsl_type::image1D_type,
3175 glsl_type::image2D_type,
3176 glsl_type::image3D_type,
3177 glsl_type::image2DRect_type,
3178 glsl_type::imageCube_type,
3179 glsl_type::imageBuffer_type,
3180 glsl_type::image1DArray_type,
3181 glsl_type::image2DArray_type,
3182 glsl_type::imageCubeArray_type,
3183 glsl_type::image2DMS_type,
3184 glsl_type::image2DMSArray_type,
3185 glsl_type::iimage1D_type,
3186 glsl_type::iimage2D_type,
3187 glsl_type::iimage3D_type,
3188 glsl_type::iimage2DRect_type,
3189 glsl_type::iimageCube_type,
3190 glsl_type::iimageBuffer_type,
3191 glsl_type::iimage1DArray_type,
3192 glsl_type::iimage2DArray_type,
3193 glsl_type::iimageCubeArray_type,
3194 glsl_type::iimage2DMS_type,
3195 glsl_type::iimage2DMSArray_type,
3196 glsl_type::uimage1D_type,
3197 glsl_type::uimage2D_type,
3198 glsl_type::uimage3D_type,
3199 glsl_type::uimage2DRect_type,
3200 glsl_type::uimageCube_type,
3201 glsl_type::uimageBuffer_type,
3202 glsl_type::uimage1DArray_type,
3203 glsl_type::uimage2DArray_type,
3204 glsl_type::uimageCubeArray_type,
3205 glsl_type::uimage2DMS_type,
3206 glsl_type::uimage2DMSArray_type
3207 };
3208
3209 ir_function *f = new(mem_ctx) ir_function(name);
3210
3211 for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
3212 if ((types[i]->sampled_type != GLSL_TYPE_FLOAT ||
3213 (flags & IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE)) &&
3214 (types[i]->sampler_dimensionality == GLSL_SAMPLER_DIM_MS ||
3215 !(flags & IMAGE_FUNCTION_MS_ONLY)))
3216 f->add_signature(_image(prototype, types[i], intrinsic_name,
3217 num_arguments, flags, intrinsic_id));
3218 }
3219
3220 shader->symbols->add_function(f);
3221 }
3222
3223 void
3224 builtin_builder::add_image_functions(bool glsl)
3225 {
3226 const unsigned flags = (glsl ? IMAGE_FUNCTION_EMIT_STUB : 0);
3227
3228 add_image_function(glsl ? "imageLoad" : "__intrinsic_image_load",
3229 "__intrinsic_image_load",
3230 &builtin_builder::_image_prototype, 0,
3231 (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
3232 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
3233 IMAGE_FUNCTION_READ_ONLY),
3234 ir_intrinsic_image_load);
3235
3236 add_image_function(glsl ? "imageStore" : "__intrinsic_image_store",
3237 "__intrinsic_image_store",
3238 &builtin_builder::_image_prototype, 1,
3239 (flags | IMAGE_FUNCTION_RETURNS_VOID |
3240 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
3241 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
3242 IMAGE_FUNCTION_WRITE_ONLY),
3243 ir_intrinsic_image_store);
3244
3245 const unsigned atom_flags = flags | IMAGE_FUNCTION_AVAIL_ATOMIC;
3246
3247 add_image_function(glsl ? "imageAtomicAdd" : "__intrinsic_image_atomic_add",
3248 "__intrinsic_image_atomic_add",
3249 &builtin_builder::_image_prototype, 1, atom_flags,
3250 ir_intrinsic_image_atomic_add);
3251
3252 add_image_function(glsl ? "imageAtomicMin" : "__intrinsic_image_atomic_min",
3253 "__intrinsic_image_atomic_min",
3254 &builtin_builder::_image_prototype, 1, atom_flags,
3255 ir_intrinsic_image_atomic_min);
3256
3257 add_image_function(glsl ? "imageAtomicMax" : "__intrinsic_image_atomic_max",
3258 "__intrinsic_image_atomic_max",
3259 &builtin_builder::_image_prototype, 1, atom_flags,
3260 ir_intrinsic_image_atomic_max);
3261
3262 add_image_function(glsl ? "imageAtomicAnd" : "__intrinsic_image_atomic_and",
3263 "__intrinsic_image_atomic_and",
3264 &builtin_builder::_image_prototype, 1, atom_flags,
3265 ir_intrinsic_image_atomic_and);
3266
3267 add_image_function(glsl ? "imageAtomicOr" : "__intrinsic_image_atomic_or",
3268 "__intrinsic_image_atomic_or",
3269 &builtin_builder::_image_prototype, 1, atom_flags,
3270 ir_intrinsic_image_atomic_or);
3271
3272 add_image_function(glsl ? "imageAtomicXor" : "__intrinsic_image_atomic_xor",
3273 "__intrinsic_image_atomic_xor",
3274 &builtin_builder::_image_prototype, 1, atom_flags,
3275 ir_intrinsic_image_atomic_xor);
3276
3277 add_image_function((glsl ? "imageAtomicExchange" :
3278 "__intrinsic_image_atomic_exchange"),
3279 "__intrinsic_image_atomic_exchange",
3280 &builtin_builder::_image_prototype, 1,
3281 (flags | IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE |
3282 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE),
3283 ir_intrinsic_image_atomic_exchange);
3284
3285 add_image_function((glsl ? "imageAtomicCompSwap" :
3286 "__intrinsic_image_atomic_comp_swap"),
3287 "__intrinsic_image_atomic_comp_swap",
3288 &builtin_builder::_image_prototype, 2, atom_flags,
3289 ir_intrinsic_image_atomic_comp_swap);
3290
3291 add_image_function(glsl ? "imageSize" : "__intrinsic_image_size",
3292 "__intrinsic_image_size",
3293 &builtin_builder::_image_size_prototype, 1,
3294 flags | IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE,
3295 ir_intrinsic_image_size);
3296
3297 add_image_function(glsl ? "imageSamples" : "__intrinsic_image_samples",
3298 "__intrinsic_image_samples",
3299 &builtin_builder::_image_samples_prototype, 1,
3300 flags | IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
3301 IMAGE_FUNCTION_MS_ONLY,
3302 ir_intrinsic_image_samples);
3303 }
3304
3305 ir_variable *
3306 builtin_builder::in_var(const glsl_type *type, const char *name)
3307 {
3308 return new(mem_ctx) ir_variable(type, name, ir_var_function_in);
3309 }
3310
3311 ir_variable *
3312 builtin_builder::out_var(const glsl_type *type, const char *name)
3313 {
3314 return new(mem_ctx) ir_variable(type, name, ir_var_function_out);
3315 }
3316
3317 ir_constant *
3318 builtin_builder::imm(bool b, unsigned vector_elements)
3319 {
3320 return new(mem_ctx) ir_constant(b, vector_elements);
3321 }
3322
3323 ir_constant *
3324 builtin_builder::imm(float f, unsigned vector_elements)
3325 {
3326 return new(mem_ctx) ir_constant(f, vector_elements);
3327 }
3328
3329 ir_constant *
3330 builtin_builder::imm(int i, unsigned vector_elements)
3331 {
3332 return new(mem_ctx) ir_constant(i, vector_elements);
3333 }
3334
3335 ir_constant *
3336 builtin_builder::imm(unsigned u, unsigned vector_elements)
3337 {
3338 return new(mem_ctx) ir_constant(u, vector_elements);
3339 }
3340
3341 ir_constant *
3342 builtin_builder::imm(double d, unsigned vector_elements)
3343 {
3344 return new(mem_ctx) ir_constant(d, vector_elements);
3345 }
3346
3347 ir_constant *
3348 builtin_builder::imm(const glsl_type *type, const ir_constant_data &data)
3349 {
3350 return new(mem_ctx) ir_constant(type, &data);
3351 }
3352
3353 #define IMM_FP(type, val) (type->base_type == GLSL_TYPE_DOUBLE) ? imm(val) : imm((float)val)
3354
3355 ir_dereference_variable *
3356 builtin_builder::var_ref(ir_variable *var)
3357 {
3358 return new(mem_ctx) ir_dereference_variable(var);
3359 }
3360
3361 ir_dereference_array *
3362 builtin_builder::array_ref(ir_variable *var, int idx)
3363 {
3364 return new(mem_ctx) ir_dereference_array(var, imm(idx));
3365 }
3366
3367 /** Return an element of a matrix */
3368 ir_swizzle *
3369 builtin_builder::matrix_elt(ir_variable *var, int column, int row)
3370 {
3371 return swizzle(array_ref(var, column), row, 1);
3372 }
3373
3374 /**
3375 * Implementations of built-in functions:
3376 * @{
3377 */
3378 ir_function_signature *
3379 builtin_builder::new_sig(const glsl_type *return_type,
3380 builtin_available_predicate avail,
3381 int num_params,
3382 ...)
3383 {
3384 va_list ap;
3385
3386 ir_function_signature *sig =
3387 new(mem_ctx) ir_function_signature(return_type, avail);
3388
3389 exec_list plist;
3390 va_start(ap, num_params);
3391 for (int i = 0; i < num_params; i++) {
3392 plist.push_tail(va_arg(ap, ir_variable *));
3393 }
3394 va_end(ap);
3395
3396 sig->replace_parameters(&plist);
3397 return sig;
3398 }
3399
3400 #define MAKE_SIG(return_type, avail, ...) \
3401 ir_function_signature *sig = \
3402 new_sig(return_type, avail, __VA_ARGS__); \
3403 ir_factory body(&sig->body, mem_ctx); \
3404 sig->is_defined = true;
3405
3406 #define MAKE_INTRINSIC(return_type, id, avail, ...) \
3407 ir_function_signature *sig = \
3408 new_sig(return_type, avail, __VA_ARGS__); \
3409 sig->intrinsic_id = id;
3410
3411 ir_function_signature *
3412 builtin_builder::unop(builtin_available_predicate avail,
3413 ir_expression_operation opcode,
3414 const glsl_type *return_type,
3415 const glsl_type *param_type)
3416 {
3417 ir_variable *x = in_var(param_type, "x");
3418 MAKE_SIG(return_type, avail, 1, x);
3419 body.emit(ret(expr(opcode, x)));
3420 return sig;
3421 }
3422
3423 #define UNOP(NAME, OPCODE, AVAIL) \
3424 ir_function_signature * \
3425 builtin_builder::_##NAME(const glsl_type *type) \
3426 { \
3427 return unop(&AVAIL, OPCODE, type, type); \
3428 }
3429
3430 #define UNOPA(NAME, OPCODE) \
3431 ir_function_signature * \
3432 builtin_builder::_##NAME(builtin_available_predicate avail, const glsl_type *type) \
3433 { \
3434 return unop(avail, OPCODE, type, type); \
3435 }
3436
3437 ir_function_signature *
3438 builtin_builder::binop(builtin_available_predicate avail,
3439 ir_expression_operation opcode,
3440 const glsl_type *return_type,
3441 const glsl_type *param0_type,
3442 const glsl_type *param1_type)
3443 {
3444 ir_variable *x = in_var(param0_type, "x");
3445 ir_variable *y = in_var(param1_type, "y");
3446 MAKE_SIG(return_type, avail, 2, x, y);
3447 body.emit(ret(expr(opcode, x, y)));
3448 return sig;
3449 }
3450
3451 #define BINOP(NAME, OPCODE, AVAIL) \
3452 ir_function_signature * \
3453 builtin_builder::_##NAME(const glsl_type *return_type, \
3454 const glsl_type *param0_type, \
3455 const glsl_type *param1_type) \
3456 { \
3457 return binop(&AVAIL, OPCODE, return_type, param0_type, param1_type); \
3458 }
3459
3460 /**
3461 * Angle and Trigonometry Functions @{
3462 */
3463
3464 ir_function_signature *
3465 builtin_builder::_radians(const glsl_type *type)
3466 {
3467 ir_variable *degrees = in_var(type, "degrees");
3468 MAKE_SIG(type, always_available, 1, degrees);
3469 body.emit(ret(mul(degrees, imm(0.0174532925f))));
3470 return sig;
3471 }
3472
3473 ir_function_signature *
3474 builtin_builder::_degrees(const glsl_type *type)
3475 {
3476 ir_variable *radians = in_var(type, "radians");
3477 MAKE_SIG(type, always_available, 1, radians);
3478 body.emit(ret(mul(radians, imm(57.29578f))));
3479 return sig;
3480 }
3481
3482 UNOP(sin, ir_unop_sin, always_available)
3483 UNOP(cos, ir_unop_cos, always_available)
3484
3485 ir_function_signature *
3486 builtin_builder::_tan(const glsl_type *type)
3487 {
3488 ir_variable *theta = in_var(type, "theta");
3489 MAKE_SIG(type, always_available, 1, theta);
3490 body.emit(ret(div(sin(theta), cos(theta))));
3491 return sig;
3492 }
3493
3494 ir_expression *
3495 builtin_builder::asin_expr(ir_variable *x, float p0, float p1)
3496 {
3497 return mul(sign(x),
3498 sub(imm(M_PI_2f),
3499 mul(sqrt(sub(imm(1.0f), abs(x))),
3500 add(imm(M_PI_2f),
3501 mul(abs(x),
3502 add(imm(M_PI_4f - 1.0f),
3503 mul(abs(x),
3504 add(imm(p0),
3505 mul(abs(x), imm(p1))))))))));
3506 }
3507
3508 /**
3509 * Generate a ir_call to a function with a set of parameters
3510 *
3511 * The input \c params can either be a list of \c ir_variable or a list of
3512 * \c ir_dereference_variable. In the latter case, all nodes will be removed
3513 * from \c params and used directly as the parameters to the generated
3514 * \c ir_call.
3515 */
3516 ir_call *
3517 builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)
3518 {
3519 exec_list actual_params;
3520
3521 foreach_in_list_safe(ir_instruction, ir, &params) {
3522 ir_dereference_variable *d = ir->as_dereference_variable();
3523 if (d != NULL) {
3524 d->remove();
3525 actual_params.push_tail(d);
3526 } else {
3527 ir_variable *var = ir->as_variable();
3528 assert(var != NULL);
3529 actual_params.push_tail(var_ref(var));
3530 }
3531 }
3532
3533 ir_function_signature *sig =
3534 f->exact_matching_signature(NULL, &actual_params);
3535 if (!sig)
3536 return NULL;
3537
3538 ir_dereference_variable *deref =
3539 (sig->return_type->is_void() ? NULL : var_ref(ret));
3540
3541 return new(mem_ctx) ir_call(sig, deref, &actual_params);
3542 }
3543
3544 ir_function_signature *
3545 builtin_builder::_asin(const glsl_type *type)
3546 {
3547 ir_variable *x = in_var(type, "x");
3548 MAKE_SIG(type, always_available, 1, x);
3549
3550 body.emit(ret(asin_expr(x, 0.086566724f, -0.03102955f)));
3551
3552 return sig;
3553 }
3554
3555 ir_function_signature *
3556 builtin_builder::_acos(const glsl_type *type)
3557 {
3558 ir_variable *x = in_var(type, "x");
3559 MAKE_SIG(type, always_available, 1, x);
3560
3561 body.emit(ret(sub(imm(M_PI_2f), asin_expr(x, 0.08132463f, -0.02363318f))));
3562
3563 return sig;
3564 }
3565
3566 ir_function_signature *
3567 builtin_builder::_atan2(const glsl_type *type)
3568 {
3569 const unsigned n = type->vector_elements;
3570 ir_variable *y = in_var(type, "y");
3571 ir_variable *x = in_var(type, "x");
3572 MAKE_SIG(type, always_available, 2, y, x);
3573
3574 /* If we're on the left half-plane rotate the coordinates π/2 clock-wise
3575 * for the y=0 discontinuity to end up aligned with the vertical
3576 * discontinuity of atan(s/t) along t=0. This also makes sure that we
3577 * don't attempt to divide by zero along the vertical line, which may give
3578 * unspecified results on non-GLSL 4.1-capable hardware.
3579 */
3580 ir_variable *flip = body.make_temp(glsl_type::bvec(n), "flip");
3581 body.emit(assign(flip, gequal(imm(0.0f, n), x)));
3582 ir_variable *s = body.make_temp(type, "s");
3583 body.emit(assign(s, csel(flip, abs(x), y)));
3584 ir_variable *t = body.make_temp(type, "t");
3585 body.emit(assign(t, csel(flip, y, abs(x))));
3586
3587 /* If the magnitude of the denominator exceeds some huge value, scale down
3588 * the arguments in order to prevent the reciprocal operation from flushing
3589 * its result to zero, which would cause precision problems, and for s
3590 * infinite would cause us to return a NaN instead of the correct finite
3591 * value.
3592 *
3593 * If fmin and fmax are respectively the smallest and largest positive
3594 * normalized floating point values representable by the implementation,
3595 * the constants below should be in agreement with:
3596 *
3597 * huge <= 1 / fmin
3598 * scale <= 1 / fmin / fmax (for |t| >= huge)
3599 *
3600 * In addition scale should be a negative power of two in order to avoid
3601 * loss of precision. The values chosen below should work for most usual
3602 * floating point representations with at least the dynamic range of ATI's
3603 * 24-bit representation.
3604 */
3605 ir_constant *huge = imm(1e18f, n);
3606 ir_variable *scale = body.make_temp(type, "scale");
3607 body.emit(assign(scale, csel(gequal(abs(t), huge),
3608 imm(0.25f, n), imm(1.0f, n))));
3609 ir_variable *rcp_scaled_t = body.make_temp(type, "rcp_scaled_t");
3610 body.emit(assign(rcp_scaled_t, rcp(mul(t, scale))));
3611 ir_expression *s_over_t = mul(mul(s, scale), rcp_scaled_t);
3612
3613 /* For |x| = |y| assume tan = 1 even if infinite (i.e. pretend momentarily
3614 * that ∞/∞ = 1) in order to comply with the rather artificial rules
3615 * inherited from IEEE 754-2008, namely:
3616 *
3617 * "atan2(±∞, −∞) is ±3π/4
3618 * atan2(±∞, +∞) is ±π/4"
3619 *
3620 * Note that this is inconsistent with the rules for the neighborhood of
3621 * zero that are based on iterated limits:
3622 *
3623 * "atan2(±0, −0) is ±π
3624 * atan2(±0, +0) is ±0"
3625 *
3626 * but GLSL specifically allows implementations to deviate from IEEE rules
3627 * at (0,0), so we take that license (i.e. pretend that 0/0 = 1 here as
3628 * well).
3629 */
3630 ir_expression *tan = csel(equal(abs(x), abs(y)),
3631 imm(1.0f, n), abs(s_over_t));
3632
3633 /* Calculate the arctangent and fix up the result if we had flipped the
3634 * coordinate system.
3635 */
3636 ir_variable *arc = body.make_temp(type, "arc");
3637 do_atan(body, type, arc, tan);
3638 body.emit(assign(arc, add(arc, mul(b2f(flip), imm(M_PI_2f)))));
3639
3640 /* Rather convoluted calculation of the sign of the result. When x < 0 we
3641 * cannot use fsign because we need to be able to distinguish between
3642 * negative and positive zero. Unfortunately we cannot use bitwise
3643 * arithmetic tricks either because of back-ends without integer support.
3644 * When x >= 0 rcp_scaled_t will always be non-negative so this won't be
3645 * able to distinguish between negative and positive zero, but we don't
3646 * care because atan2 is continuous along the whole positive y = 0
3647 * half-line, so it won't affect the result significantly.
3648 */
3649 body.emit(ret(csel(less(min2(y, rcp_scaled_t), imm(0.0f, n)),
3650 neg(arc), arc)));
3651
3652 return sig;
3653 }
3654
3655 void
3656 builtin_builder::do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x)
3657 {
3658 /*
3659 * range-reduction, first step:
3660 *
3661 * / y_over_x if |y_over_x| <= 1.0;
3662 * x = <
3663 * \ 1.0 / y_over_x otherwise
3664 */
3665 ir_variable *x = body.make_temp(type, "atan_x");
3666 body.emit(assign(x, div(min2(abs(y_over_x),
3667 imm(1.0f)),
3668 max2(abs(y_over_x),
3669 imm(1.0f)))));
3670
3671 /*
3672 * approximate atan by evaluating polynomial:
3673 *
3674 * x * 0.9999793128310355 - x^3 * 0.3326756418091246 +
3675 * x^5 * 0.1938924977115610 - x^7 * 0.1173503194786851 +
3676 * x^9 * 0.0536813784310406 - x^11 * 0.0121323213173444
3677 */
3678 ir_variable *tmp = body.make_temp(type, "atan_tmp");
3679 body.emit(assign(tmp, mul(x, x)));
3680 body.emit(assign(tmp, mul(add(mul(sub(mul(add(mul(sub(mul(add(mul(imm(-0.0121323213173444f),
3681 tmp),
3682 imm(0.0536813784310406f)),
3683 tmp),
3684 imm(0.1173503194786851f)),
3685 tmp),
3686 imm(0.1938924977115610f)),
3687 tmp),
3688 imm(0.3326756418091246f)),
3689 tmp),
3690 imm(0.9999793128310355f)),
3691 x)));
3692
3693 /* range-reduction fixup */
3694 body.emit(assign(tmp, add(tmp,
3695 mul(b2f(greater(abs(y_over_x),
3696 imm(1.0f, type->components()))),
3697 add(mul(tmp,
3698 imm(-2.0f)),
3699 imm(M_PI_2f))))));
3700
3701 /* sign fixup */
3702 body.emit(assign(res, mul(tmp, sign(y_over_x))));
3703 }
3704
3705 ir_function_signature *
3706 builtin_builder::_atan(const glsl_type *type)
3707 {
3708 ir_variable *y_over_x = in_var(type, "y_over_x");
3709 MAKE_SIG(type, always_available, 1, y_over_x);
3710
3711 ir_variable *tmp = body.make_temp(type, "tmp");
3712 do_atan(body, type, tmp, y_over_x);
3713 body.emit(ret(tmp));
3714
3715 return sig;
3716 }
3717
3718 ir_function_signature *
3719 builtin_builder::_sinh(const glsl_type *type)
3720 {
3721 ir_variable *x = in_var(type, "x");
3722 MAKE_SIG(type, v130, 1, x);
3723
3724 /* 0.5 * (e^x - e^(-x)) */
3725 body.emit(ret(mul(imm(0.5f), sub(exp(x), exp(neg(x))))));
3726
3727 return sig;
3728 }
3729
3730 ir_function_signature *
3731 builtin_builder::_cosh(const glsl_type *type)
3732 {
3733 ir_variable *x = in_var(type, "x");
3734 MAKE_SIG(type, v130, 1, x);
3735
3736 /* 0.5 * (e^x + e^(-x)) */
3737 body.emit(ret(mul(imm(0.5f), add(exp(x), exp(neg(x))))));
3738
3739 return sig;
3740 }
3741
3742 ir_function_signature *
3743 builtin_builder::_tanh(const glsl_type *type)
3744 {
3745 ir_variable *x = in_var(type, "x");
3746 MAKE_SIG(type, v130, 1, x);
3747
3748 /* tanh(x) := (0.5 * (e^x - e^(-x))) / (0.5 * (e^x + e^(-x)))
3749 *
3750 * With a little algebra this reduces to (e^2x - 1) / (e^2x + 1)
3751 *
3752 * Clamp x to (-inf, +10] to avoid precision problems. When x > 10, e^2x
3753 * is so much larger than 1.0 that 1.0 gets flushed to zero in the
3754 * computation e^2x +/- 1 so it can be ignored.
3755 */
3756 ir_variable *t = body.make_temp(type, "tmp");
3757 body.emit(assign(t, min2(x, imm(10.0f))));
3758
3759 body.emit(ret(div(sub(exp(mul(t, imm(2.0f))), imm(1.0f)),
3760 add(exp(mul(t, imm(2.0f))), imm(1.0f)))));
3761
3762 return sig;
3763 }
3764
3765 ir_function_signature *
3766 builtin_builder::_asinh(const glsl_type *type)
3767 {
3768 ir_variable *x = in_var(type, "x");
3769 MAKE_SIG(type, v130, 1, x);
3770
3771 body.emit(ret(mul(sign(x), log(add(abs(x), sqrt(add(mul(x, x),
3772 imm(1.0f))))))));
3773 return sig;
3774 }
3775
3776 ir_function_signature *
3777 builtin_builder::_acosh(const glsl_type *type)
3778 {
3779 ir_variable *x = in_var(type, "x");
3780 MAKE_SIG(type, v130, 1, x);
3781
3782 body.emit(ret(log(add(x, sqrt(sub(mul(x, x), imm(1.0f)))))));
3783 return sig;
3784 }
3785
3786 ir_function_signature *
3787 builtin_builder::_atanh(const glsl_type *type)
3788 {
3789 ir_variable *x = in_var(type, "x");
3790 MAKE_SIG(type, v130, 1, x);
3791
3792 body.emit(ret(mul(imm(0.5f), log(div(add(imm(1.0f), x),
3793 sub(imm(1.0f), x))))));
3794 return sig;
3795 }
3796 /** @} */
3797
3798 /**
3799 * Exponential Functions @{
3800 */
3801
3802 ir_function_signature *
3803 builtin_builder::_pow(const glsl_type *type)
3804 {
3805 return binop(always_available, ir_binop_pow, type, type, type);
3806 }
3807
3808 UNOP(exp, ir_unop_exp, always_available)
3809 UNOP(log, ir_unop_log, always_available)
3810 UNOP(exp2, ir_unop_exp2, always_available)
3811 UNOP(log2, ir_unop_log2, always_available)
3812 UNOPA(sqrt, ir_unop_sqrt)
3813 UNOPA(inversesqrt, ir_unop_rsq)
3814
3815 /** @} */
3816
3817 UNOPA(abs, ir_unop_abs)
3818 UNOPA(sign, ir_unop_sign)
3819 UNOPA(floor, ir_unop_floor)
3820 UNOPA(trunc, ir_unop_trunc)
3821 UNOPA(round, ir_unop_round_even)
3822 UNOPA(roundEven, ir_unop_round_even)
3823 UNOPA(ceil, ir_unop_ceil)
3824 UNOPA(fract, ir_unop_fract)
3825
3826 ir_function_signature *
3827 builtin_builder::_mod(builtin_available_predicate avail,
3828 const glsl_type *x_type, const glsl_type *y_type)
3829 {
3830 return binop(avail, ir_binop_mod, x_type, x_type, y_type);
3831 }
3832
3833 ir_function_signature *
3834 builtin_builder::_modf(builtin_available_predicate avail, const glsl_type *type)
3835 {
3836 ir_variable *x = in_var(type, "x");
3837 ir_variable *i = out_var(type, "i");
3838 MAKE_SIG(type, avail, 2, x, i);
3839
3840 ir_variable *t = body.make_temp(type, "t");
3841 body.emit(assign(t, expr(ir_unop_trunc, x)));
3842 body.emit(assign(i, t));
3843 body.emit(ret(sub(x, t)));
3844
3845 return sig;
3846 }
3847
3848 ir_function_signature *
3849 builtin_builder::_min(builtin_available_predicate avail,
3850 const glsl_type *x_type, const glsl_type *y_type)
3851 {
3852 return binop(avail, ir_binop_min, x_type, x_type, y_type);
3853 }
3854
3855 ir_function_signature *
3856 builtin_builder::_max(builtin_available_predicate avail,
3857 const glsl_type *x_type, const glsl_type *y_type)
3858 {
3859 return binop(avail, ir_binop_max, x_type, x_type, y_type);
3860 }
3861
3862 ir_function_signature *
3863 builtin_builder::_clamp(builtin_available_predicate avail,
3864 const glsl_type *val_type, const glsl_type *bound_type)
3865 {
3866 ir_variable *x = in_var(val_type, "x");
3867 ir_variable *minVal = in_var(bound_type, "minVal");
3868 ir_variable *maxVal = in_var(bound_type, "maxVal");
3869 MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
3870
3871 body.emit(ret(clamp(x, minVal, maxVal)));
3872
3873 return sig;
3874 }
3875
3876 ir_function_signature *
3877 builtin_builder::_mix_lrp(builtin_available_predicate avail, const glsl_type *val_type, const glsl_type *blend_type)
3878 {
3879 ir_variable *x = in_var(val_type, "x");
3880 ir_variable *y = in_var(val_type, "y");
3881 ir_variable *a = in_var(blend_type, "a");
3882 MAKE_SIG(val_type, avail, 3, x, y, a);
3883
3884 body.emit(ret(lrp(x, y, a)));
3885
3886 return sig;
3887 }
3888
3889 ir_function_signature *
3890 builtin_builder::_mix_sel(builtin_available_predicate avail,
3891 const glsl_type *val_type,
3892 const glsl_type *blend_type)
3893 {
3894 ir_variable *x = in_var(val_type, "x");
3895 ir_variable *y = in_var(val_type, "y");
3896 ir_variable *a = in_var(blend_type, "a");
3897 MAKE_SIG(val_type, avail, 3, x, y, a);
3898
3899 /* csel matches the ternary operator in that a selector of true choses the
3900 * first argument. This differs from mix(x, y, false) which choses the
3901 * second argument (to remain consistent with the interpolating version of
3902 * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
3903 *
3904 * To handle the behavior mismatch, reverse the x and y arguments.
3905 */
3906 body.emit(ret(csel(a, y, x)));
3907
3908 return sig;
3909 }
3910
3911 ir_function_signature *
3912 builtin_builder::_step(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
3913 {
3914 ir_variable *edge = in_var(edge_type, "edge");
3915 ir_variable *x = in_var(x_type, "x");
3916 MAKE_SIG(x_type, avail, 2, edge, x);
3917
3918 ir_variable *t = body.make_temp(x_type, "t");
3919 if (x_type->vector_elements == 1) {
3920 /* Both are floats */
3921 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3922 body.emit(assign(t, f2d(b2f(gequal(x, edge)))));
3923 else
3924 body.emit(assign(t, b2f(gequal(x, edge))));
3925 } else if (edge_type->vector_elements == 1) {
3926 /* x is a vector but edge is a float */
3927 for (int i = 0; i < x_type->vector_elements; i++) {
3928 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3929 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), edge))), 1 << i));
3930 else
3931 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
3932 }
3933 } else {
3934 /* Both are vectors */
3935 for (int i = 0; i < x_type->vector_elements; i++) {
3936 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3937 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1)))),
3938 1 << i));
3939 else
3940 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
3941 1 << i));
3942
3943 }
3944 }
3945 body.emit(ret(t));
3946
3947 return sig;
3948 }
3949
3950 ir_function_signature *
3951 builtin_builder::_smoothstep(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
3952 {
3953 ir_variable *edge0 = in_var(edge_type, "edge0");
3954 ir_variable *edge1 = in_var(edge_type, "edge1");
3955 ir_variable *x = in_var(x_type, "x");
3956 MAKE_SIG(x_type, avail, 3, edge0, edge1, x);
3957
3958 /* From the GLSL 1.10 specification:
3959 *
3960 * genType t;
3961 * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
3962 * return t * t * (3 - 2 * t);
3963 */
3964
3965 ir_variable *t = body.make_temp(x_type, "t");
3966 body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
3967 IMM_FP(x_type, 0.0), IMM_FP(x_type, 1.0))));
3968
3969 body.emit(ret(mul(t, mul(t, sub(IMM_FP(x_type, 3.0), mul(IMM_FP(x_type, 2.0), t))))));
3970
3971 return sig;
3972 }
3973
3974 ir_function_signature *
3975 builtin_builder::_isnan(builtin_available_predicate avail, const glsl_type *type)
3976 {
3977 ir_variable *x = in_var(type, "x");
3978 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
3979
3980 body.emit(ret(nequal(x, x)));
3981
3982 return sig;
3983 }
3984
3985 ir_function_signature *
3986 builtin_builder::_isinf(builtin_available_predicate avail, const glsl_type *type)
3987 {
3988 ir_variable *x = in_var(type, "x");
3989 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
3990
3991 ir_constant_data infinities;
3992 for (int i = 0; i < type->vector_elements; i++) {
3993 switch (type->base_type) {
3994 case GLSL_TYPE_FLOAT:
3995 infinities.f[i] = INFINITY;
3996 break;
3997 case GLSL_TYPE_DOUBLE:
3998 infinities.d[i] = INFINITY;
3999 break;
4000 default:
4001 unreachable("unknown type");
4002 }
4003 }
4004
4005 body.emit(ret(equal(abs(x), imm(type, infinities))));
4006
4007 return sig;
4008 }
4009
4010 ir_function_signature *
4011 builtin_builder::_floatBitsToInt(const glsl_type *type)
4012 {
4013 ir_variable *x = in_var(type, "x");
4014 MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
4015 body.emit(ret(bitcast_f2i(x)));
4016 return sig;
4017 }
4018
4019 ir_function_signature *
4020 builtin_builder::_floatBitsToUint(const glsl_type *type)
4021 {
4022 ir_variable *x = in_var(type, "x");
4023 MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
4024 body.emit(ret(bitcast_f2u(x)));
4025 return sig;
4026 }
4027
4028 ir_function_signature *
4029 builtin_builder::_intBitsToFloat(const glsl_type *type)
4030 {
4031 ir_variable *x = in_var(type, "x");
4032 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
4033 body.emit(ret(bitcast_i2f(x)));
4034 return sig;
4035 }
4036
4037 ir_function_signature *
4038 builtin_builder::_uintBitsToFloat(const glsl_type *type)
4039 {
4040 ir_variable *x = in_var(type, "x");
4041 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
4042 body.emit(ret(bitcast_u2f(x)));
4043 return sig;
4044 }
4045
4046 ir_function_signature *
4047 builtin_builder::_doubleBitsToInt64(builtin_available_predicate avail, const glsl_type *type)
4048 {
4049 ir_variable *x = in_var(type, "x");
4050 MAKE_SIG(glsl_type::i64vec(type->vector_elements), avail, 1, x);
4051 body.emit(ret(bitcast_d2i64(x)));
4052 return sig;
4053 }
4054
4055 ir_function_signature *
4056 builtin_builder::_doubleBitsToUint64(builtin_available_predicate avail, const glsl_type *type)
4057 {
4058 ir_variable *x = in_var(type, "x");
4059 MAKE_SIG(glsl_type::u64vec(type->vector_elements), avail, 1, x);
4060 body.emit(ret(bitcast_d2u64(x)));
4061 return sig;
4062 }
4063
4064 ir_function_signature *
4065 builtin_builder::_int64BitsToDouble(builtin_available_predicate avail, const glsl_type *type)
4066 {
4067 ir_variable *x = in_var(type, "x");
4068 MAKE_SIG(glsl_type::dvec(type->vector_elements), avail, 1, x);
4069 body.emit(ret(bitcast_i642d(x)));
4070 return sig;
4071 }
4072
4073 ir_function_signature *
4074 builtin_builder::_uint64BitsToDouble(builtin_available_predicate avail, const glsl_type *type)
4075 {
4076 ir_variable *x = in_var(type, "x");
4077 MAKE_SIG(glsl_type::dvec(type->vector_elements), avail, 1, x);
4078 body.emit(ret(bitcast_u642d(x)));
4079 return sig;
4080 }
4081
4082 ir_function_signature *
4083 builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
4084 {
4085 ir_variable *v = in_var(glsl_type::vec2_type, "v");
4086 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
4087 body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
4088 return sig;
4089 }
4090
4091 ir_function_signature *
4092 builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
4093 {
4094 ir_variable *v = in_var(glsl_type::vec2_type, "v");
4095 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
4096 body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
4097 return sig;
4098 }
4099
4100 ir_function_signature *
4101 builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
4102 {
4103 ir_variable *v = in_var(glsl_type::vec4_type, "v");
4104 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
4105 body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
4106 return sig;
4107 }
4108
4109 ir_function_signature *
4110 builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
4111 {
4112 ir_variable *v = in_var(glsl_type::vec4_type, "v");
4113 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
4114 body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
4115 return sig;
4116 }
4117
4118 ir_function_signature *
4119 builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
4120 {
4121 ir_variable *p = in_var(glsl_type::uint_type, "p");
4122 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
4123 body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
4124 return sig;
4125 }
4126
4127 ir_function_signature *
4128 builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
4129 {
4130 ir_variable *p = in_var(glsl_type::uint_type, "p");
4131 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
4132 body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
4133 return sig;
4134 }
4135
4136
4137 ir_function_signature *
4138 builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
4139 {
4140 ir_variable *p = in_var(glsl_type::uint_type, "p");
4141 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
4142 body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
4143 return sig;
4144 }
4145
4146 ir_function_signature *
4147 builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
4148 {
4149 ir_variable *p = in_var(glsl_type::uint_type, "p");
4150 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
4151 body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
4152 return sig;
4153 }
4154
4155 ir_function_signature *
4156 builtin_builder::_packHalf2x16(builtin_available_predicate avail)
4157 {
4158 ir_variable *v = in_var(glsl_type::vec2_type, "v");
4159 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
4160 body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
4161 return sig;
4162 }
4163
4164 ir_function_signature *
4165 builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
4166 {
4167 ir_variable *p = in_var(glsl_type::uint_type, "p");
4168 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
4169 body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
4170 return sig;
4171 }
4172
4173 ir_function_signature *
4174 builtin_builder::_packDouble2x32(builtin_available_predicate avail)
4175 {
4176 ir_variable *v = in_var(glsl_type::uvec2_type, "v");
4177 MAKE_SIG(glsl_type::double_type, avail, 1, v);
4178 body.emit(ret(expr(ir_unop_pack_double_2x32, v)));
4179 return sig;
4180 }
4181
4182 ir_function_signature *
4183 builtin_builder::_unpackDouble2x32(builtin_available_predicate avail)
4184 {
4185 ir_variable *p = in_var(glsl_type::double_type, "p");
4186 MAKE_SIG(glsl_type::uvec2_type, avail, 1, p);
4187 body.emit(ret(expr(ir_unop_unpack_double_2x32, p)));
4188 return sig;
4189 }
4190
4191 ir_function_signature *
4192 builtin_builder::_packInt2x32(builtin_available_predicate avail)
4193 {
4194 ir_variable *v = in_var(glsl_type::ivec2_type, "v");
4195 MAKE_SIG(glsl_type::int64_t_type, avail, 1, v);
4196 body.emit(ret(expr(ir_unop_pack_int_2x32, v)));
4197 return sig;
4198 }
4199
4200 ir_function_signature *
4201 builtin_builder::_unpackInt2x32(builtin_available_predicate avail)
4202 {
4203 ir_variable *p = in_var(glsl_type::int64_t_type, "p");
4204 MAKE_SIG(glsl_type::ivec2_type, avail, 1, p);
4205 body.emit(ret(expr(ir_unop_unpack_int_2x32, p)));
4206 return sig;
4207 }
4208
4209 ir_function_signature *
4210 builtin_builder::_packUint2x32(builtin_available_predicate avail)
4211 {
4212 ir_variable *v = in_var(glsl_type::uvec2_type, "v");
4213 MAKE_SIG(glsl_type::uint64_t_type, avail, 1, v);
4214 body.emit(ret(expr(ir_unop_pack_uint_2x32, v)));
4215 return sig;
4216 }
4217
4218 ir_function_signature *
4219 builtin_builder::_unpackUint2x32(builtin_available_predicate avail)
4220 {
4221 ir_variable *p = in_var(glsl_type::uint64_t_type, "p");
4222 MAKE_SIG(glsl_type::uvec2_type, avail, 1, p);
4223 body.emit(ret(expr(ir_unop_unpack_uint_2x32, p)));
4224 return sig;
4225 }
4226
4227 ir_function_signature *
4228 builtin_builder::_length(builtin_available_predicate avail, const glsl_type *type)
4229 {
4230 ir_variable *x = in_var(type, "x");
4231 MAKE_SIG(type->get_base_type(), avail, 1, x);
4232
4233 body.emit(ret(sqrt(dot(x, x))));
4234
4235 return sig;
4236 }
4237
4238 ir_function_signature *
4239 builtin_builder::_distance(builtin_available_predicate avail, const glsl_type *type)
4240 {
4241 ir_variable *p0 = in_var(type, "p0");
4242 ir_variable *p1 = in_var(type, "p1");
4243 MAKE_SIG(type->get_base_type(), avail, 2, p0, p1);
4244
4245 if (type->vector_elements == 1) {
4246 body.emit(ret(abs(sub(p0, p1))));
4247 } else {
4248 ir_variable *p = body.make_temp(type, "p");
4249 body.emit(assign(p, sub(p0, p1)));
4250 body.emit(ret(sqrt(dot(p, p))));
4251 }
4252
4253 return sig;
4254 }
4255
4256 ir_function_signature *
4257 builtin_builder::_dot(builtin_available_predicate avail, const glsl_type *type)
4258 {
4259 if (type->vector_elements == 1)
4260 return binop(avail, ir_binop_mul, type, type, type);
4261
4262 return binop(avail, ir_binop_dot,
4263 type->get_base_type(), type, type);
4264 }
4265
4266 ir_function_signature *
4267 builtin_builder::_cross(builtin_available_predicate avail, const glsl_type *type)
4268 {
4269 ir_variable *a = in_var(type, "a");
4270 ir_variable *b = in_var(type, "b");
4271 MAKE_SIG(type, avail, 2, a, b);
4272
4273 int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
4274 int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
4275
4276 body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
4277 mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
4278
4279 return sig;
4280 }
4281
4282 ir_function_signature *
4283 builtin_builder::_normalize(builtin_available_predicate avail, const glsl_type *type)
4284 {
4285 ir_variable *x = in_var(type, "x");
4286 MAKE_SIG(type, avail, 1, x);
4287
4288 if (type->vector_elements == 1) {
4289 body.emit(ret(sign(x)));
4290 } else {
4291 body.emit(ret(mul(x, rsq(dot(x, x)))));
4292 }
4293
4294 return sig;
4295 }
4296
4297 ir_function_signature *
4298 builtin_builder::_ftransform()
4299 {
4300 MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
4301
4302 /* ftransform() refers to global variables, and is always emitted
4303 * directly by ast_function.cpp. Just emit a prototype here so we
4304 * can recognize calls to it.
4305 */
4306 return sig;
4307 }
4308
4309 ir_function_signature *
4310 builtin_builder::_faceforward(builtin_available_predicate avail, const glsl_type *type)
4311 {
4312 ir_variable *N = in_var(type, "N");
4313 ir_variable *I = in_var(type, "I");
4314 ir_variable *Nref = in_var(type, "Nref");
4315 MAKE_SIG(type, avail, 3, N, I, Nref);
4316
4317 body.emit(if_tree(less(dot(Nref, I), IMM_FP(type, 0.0)),
4318 ret(N), ret(neg(N))));
4319
4320 return sig;
4321 }
4322
4323 ir_function_signature *
4324 builtin_builder::_reflect(builtin_available_predicate avail, const glsl_type *type)
4325 {
4326 ir_variable *I = in_var(type, "I");
4327 ir_variable *N = in_var(type, "N");
4328 MAKE_SIG(type, avail, 2, I, N);
4329
4330 /* I - 2 * dot(N, I) * N */
4331 body.emit(ret(sub(I, mul(IMM_FP(type, 2.0), mul(dot(N, I), N)))));
4332
4333 return sig;
4334 }
4335
4336 ir_function_signature *
4337 builtin_builder::_refract(builtin_available_predicate avail, const glsl_type *type)
4338 {
4339 ir_variable *I = in_var(type, "I");
4340 ir_variable *N = in_var(type, "N");
4341 ir_variable *eta = in_var(type->get_base_type(), "eta");
4342 MAKE_SIG(type, avail, 3, I, N, eta);
4343
4344 ir_variable *n_dot_i = body.make_temp(type->get_base_type(), "n_dot_i");
4345 body.emit(assign(n_dot_i, dot(N, I)));
4346
4347 /* From the GLSL 1.10 specification:
4348 * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
4349 * if (k < 0.0)
4350 * return genType(0.0)
4351 * else
4352 * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
4353 */
4354 ir_variable *k = body.make_temp(type->get_base_type(), "k");
4355 body.emit(assign(k, sub(IMM_FP(type, 1.0),
4356 mul(eta, mul(eta, sub(IMM_FP(type, 1.0),
4357 mul(n_dot_i, n_dot_i)))))));
4358 body.emit(if_tree(less(k, IMM_FP(type, 0.0)),
4359 ret(ir_constant::zero(mem_ctx, type)),
4360 ret(sub(mul(eta, I),
4361 mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
4362
4363 return sig;
4364 }
4365
4366 ir_function_signature *
4367 builtin_builder::_matrixCompMult(builtin_available_predicate avail, const glsl_type *type)
4368 {
4369 ir_variable *x = in_var(type, "x");
4370 ir_variable *y = in_var(type, "y");
4371 MAKE_SIG(type, avail, 2, x, y);
4372
4373 ir_variable *z = body.make_temp(type, "z");
4374 for (int i = 0; i < type->matrix_columns; i++) {
4375 body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
4376 }
4377 body.emit(ret(z));
4378
4379 return sig;
4380 }
4381
4382 ir_function_signature *
4383 builtin_builder::_outerProduct(builtin_available_predicate avail, const glsl_type *type)
4384 {
4385 ir_variable *c;
4386 ir_variable *r;
4387
4388 if (type->base_type == GLSL_TYPE_DOUBLE) {
4389 r = in_var(glsl_type::dvec(type->matrix_columns), "r");
4390 c = in_var(glsl_type::dvec(type->vector_elements), "c");
4391 } else {
4392 r = in_var(glsl_type::vec(type->matrix_columns), "r");
4393 c = in_var(glsl_type::vec(type->vector_elements), "c");
4394 }
4395 MAKE_SIG(type, avail, 2, c, r);
4396
4397 ir_variable *m = body.make_temp(type, "m");
4398 for (int i = 0; i < type->matrix_columns; i++) {
4399 body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
4400 }
4401 body.emit(ret(m));
4402
4403 return sig;
4404 }
4405
4406 ir_function_signature *
4407 builtin_builder::_transpose(builtin_available_predicate avail, const glsl_type *orig_type)
4408 {
4409 const glsl_type *transpose_type =
4410 glsl_type::get_instance(orig_type->base_type,
4411 orig_type->matrix_columns,
4412 orig_type->vector_elements);
4413
4414 ir_variable *m = in_var(orig_type, "m");
4415 MAKE_SIG(transpose_type, avail, 1, m);
4416
4417 ir_variable *t = body.make_temp(transpose_type, "t");
4418 for (int i = 0; i < orig_type->matrix_columns; i++) {
4419 for (int j = 0; j < orig_type->vector_elements; j++) {
4420 body.emit(assign(array_ref(t, j),
4421 matrix_elt(m, i, j),
4422 1 << i));
4423 }
4424 }
4425 body.emit(ret(t));
4426
4427 return sig;
4428 }
4429
4430 ir_function_signature *
4431 builtin_builder::_determinant_mat2(builtin_available_predicate avail, const glsl_type *type)
4432 {
4433 ir_variable *m = in_var(type, "m");
4434 MAKE_SIG(type->get_base_type(), avail, 1, m);
4435
4436 body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
4437 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
4438
4439 return sig;
4440 }
4441
4442 ir_function_signature *
4443 builtin_builder::_determinant_mat3(builtin_available_predicate avail, const glsl_type *type)
4444 {
4445 ir_variable *m = in_var(type, "m");
4446 MAKE_SIG(type->get_base_type(), avail, 1, m);
4447
4448 ir_expression *f1 =
4449 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
4450 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
4451
4452 ir_expression *f2 =
4453 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
4454 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
4455
4456 ir_expression *f3 =
4457 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
4458 mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
4459
4460 body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
4461 mul(matrix_elt(m, 0, 1), f2)),
4462 mul(matrix_elt(m, 0, 2), f3))));
4463
4464 return sig;
4465 }
4466
4467 ir_function_signature *
4468 builtin_builder::_determinant_mat4(builtin_available_predicate avail, const glsl_type *type)
4469 {
4470 ir_variable *m = in_var(type, "m");
4471 const glsl_type *btype = type->get_base_type();
4472 MAKE_SIG(btype, avail, 1, m);
4473
4474 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
4475 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
4476 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
4477 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
4478 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
4479 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
4480 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
4481 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
4482 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
4483 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
4484 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
4485 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
4486 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
4487 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
4488 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
4489 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
4490 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
4491 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
4492 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
4493
4494 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)))));
4495 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)))));
4496 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)))));
4497 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)))));
4498 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)))));
4499 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)))));
4500 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)))));
4501 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)))));
4502 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)))));
4503 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)))));
4504 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)))));
4505 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)))));
4506 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)))));
4507 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)))));
4508 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)))));
4509 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)))));
4510 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)))));
4511 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)))));
4512 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)))));
4513
4514 ir_variable *adj_0 = body.make_temp(btype == glsl_type::float_type ? glsl_type::vec4_type : glsl_type::dvec4_type, "adj_0");
4515
4516 body.emit(assign(adj_0,
4517 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
4518 mul(matrix_elt(m, 1, 2), SubFactor01)),
4519 mul(matrix_elt(m, 1, 3), SubFactor02)),
4520 WRITEMASK_X));
4521 body.emit(assign(adj_0, neg(
4522 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
4523 mul(matrix_elt(m, 1, 2), SubFactor03)),
4524 mul(matrix_elt(m, 1, 3), SubFactor04))),
4525 WRITEMASK_Y));
4526 body.emit(assign(adj_0,
4527 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
4528 mul(matrix_elt(m, 1, 1), SubFactor03)),
4529 mul(matrix_elt(m, 1, 3), SubFactor05)),
4530 WRITEMASK_Z));
4531 body.emit(assign(adj_0, neg(
4532 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
4533 mul(matrix_elt(m, 1, 1), SubFactor04)),
4534 mul(matrix_elt(m, 1, 2), SubFactor05))),
4535 WRITEMASK_W));
4536
4537 body.emit(ret(dot(array_ref(m, 0), adj_0)));
4538
4539 return sig;
4540 }
4541
4542 ir_function_signature *
4543 builtin_builder::_inverse_mat2(builtin_available_predicate avail, const glsl_type *type)
4544 {
4545 ir_variable *m = in_var(type, "m");
4546 MAKE_SIG(type, avail, 1, m);
4547
4548 ir_variable *adj = body.make_temp(type, "adj");
4549 body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
4550 body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
4551 body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
4552 body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
4553
4554 ir_expression *det =
4555 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
4556 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
4557
4558 body.emit(ret(div(adj, det)));
4559 return sig;
4560 }
4561
4562 ir_function_signature *
4563 builtin_builder::_inverse_mat3(builtin_available_predicate avail, const glsl_type *type)
4564 {
4565 ir_variable *m = in_var(type, "m");
4566 const glsl_type *btype = type->get_base_type();
4567 MAKE_SIG(type, avail, 1, m);
4568
4569 ir_variable *f11_22_21_12 = body.make_temp(btype, "f11_22_21_12");
4570 ir_variable *f10_22_20_12 = body.make_temp(btype, "f10_22_20_12");
4571 ir_variable *f10_21_20_11 = body.make_temp(btype, "f10_21_20_11");
4572
4573 body.emit(assign(f11_22_21_12,
4574 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
4575 mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
4576 body.emit(assign(f10_22_20_12,
4577 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
4578 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
4579 body.emit(assign(f10_21_20_11,
4580 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
4581 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
4582
4583 ir_variable *adj = body.make_temp(type, "adj");
4584 body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
4585 body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
4586 body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
4587
4588 body.emit(assign(array_ref(adj, 0), neg(
4589 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
4590 mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
4591 WRITEMASK_Y));
4592 body.emit(assign(array_ref(adj, 1),
4593 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
4594 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
4595 WRITEMASK_Y));
4596 body.emit(assign(array_ref(adj, 2), neg(
4597 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
4598 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
4599 WRITEMASK_Y));
4600
4601 body.emit(assign(array_ref(adj, 0),
4602 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
4603 mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
4604 WRITEMASK_Z));
4605 body.emit(assign(array_ref(adj, 1), neg(
4606 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
4607 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
4608 WRITEMASK_Z));
4609 body.emit(assign(array_ref(adj, 2),
4610 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
4611 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
4612 WRITEMASK_Z));
4613
4614 ir_expression *det =
4615 add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
4616 mul(matrix_elt(m, 0, 1), f10_22_20_12)),
4617 mul(matrix_elt(m, 0, 2), f10_21_20_11));
4618
4619 body.emit(ret(div(adj, det)));
4620
4621 return sig;
4622 }
4623
4624 ir_function_signature *
4625 builtin_builder::_inverse_mat4(builtin_available_predicate avail, const glsl_type *type)
4626 {
4627 ir_variable *m = in_var(type, "m");
4628 const glsl_type *btype = type->get_base_type();
4629 MAKE_SIG(type, avail, 1, m);
4630
4631 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
4632 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
4633 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
4634 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
4635 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
4636 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
4637 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
4638 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
4639 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
4640 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
4641 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
4642 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
4643 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
4644 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
4645 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
4646 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
4647 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
4648 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
4649 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
4650
4651 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)))));
4652 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)))));
4653 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)))));
4654 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)))));
4655 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)))));
4656 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)))));
4657 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)))));
4658 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)))));
4659 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)))));
4660 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)))));
4661 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)))));
4662 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)))));
4663 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)))));
4664 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)))));
4665 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)))));
4666 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)))));
4667 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)))));
4668 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)))));
4669 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)))));
4670
4671 ir_variable *adj = body.make_temp(btype == glsl_type::float_type ? glsl_type::mat4_type : glsl_type::dmat4_type, "adj");
4672 body.emit(assign(array_ref(adj, 0),
4673 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
4674 mul(matrix_elt(m, 1, 2), SubFactor01)),
4675 mul(matrix_elt(m, 1, 3), SubFactor02)),
4676 WRITEMASK_X));
4677 body.emit(assign(array_ref(adj, 1), neg(
4678 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
4679 mul(matrix_elt(m, 1, 2), SubFactor03)),
4680 mul(matrix_elt(m, 1, 3), SubFactor04))),
4681 WRITEMASK_X));
4682 body.emit(assign(array_ref(adj, 2),
4683 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
4684 mul(matrix_elt(m, 1, 1), SubFactor03)),
4685 mul(matrix_elt(m, 1, 3), SubFactor05)),
4686 WRITEMASK_X));
4687 body.emit(assign(array_ref(adj, 3), neg(
4688 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
4689 mul(matrix_elt(m, 1, 1), SubFactor04)),
4690 mul(matrix_elt(m, 1, 2), SubFactor05))),
4691 WRITEMASK_X));
4692
4693 body.emit(assign(array_ref(adj, 0), neg(
4694 add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
4695 mul(matrix_elt(m, 0, 2), SubFactor01)),
4696 mul(matrix_elt(m, 0, 3), SubFactor02))),
4697 WRITEMASK_Y));
4698 body.emit(assign(array_ref(adj, 1),
4699 add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
4700 mul(matrix_elt(m, 0, 2), SubFactor03)),
4701 mul(matrix_elt(m, 0, 3), SubFactor04)),
4702 WRITEMASK_Y));
4703 body.emit(assign(array_ref(adj, 2), neg(
4704 add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
4705 mul(matrix_elt(m, 0, 1), SubFactor03)),
4706 mul(matrix_elt(m, 0, 3), SubFactor05))),
4707 WRITEMASK_Y));
4708 body.emit(assign(array_ref(adj, 3),
4709 add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
4710 mul(matrix_elt(m, 0, 1), SubFactor04)),
4711 mul(matrix_elt(m, 0, 2), SubFactor05)),
4712 WRITEMASK_Y));
4713
4714 body.emit(assign(array_ref(adj, 0),
4715 add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
4716 mul(matrix_elt(m, 0, 2), SubFactor07)),
4717 mul(matrix_elt(m, 0, 3), SubFactor08)),
4718 WRITEMASK_Z));
4719 body.emit(assign(array_ref(adj, 1), neg(
4720 add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
4721 mul(matrix_elt(m, 0, 2), SubFactor09)),
4722 mul(matrix_elt(m, 0, 3), SubFactor10))),
4723 WRITEMASK_Z));
4724 body.emit(assign(array_ref(adj, 2),
4725 add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
4726 mul(matrix_elt(m, 0, 1), SubFactor09)),
4727 mul(matrix_elt(m, 0, 3), SubFactor12)),
4728 WRITEMASK_Z));
4729 body.emit(assign(array_ref(adj, 3), neg(
4730 add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
4731 mul(matrix_elt(m, 0, 1), SubFactor10)),
4732 mul(matrix_elt(m, 0, 2), SubFactor12))),
4733 WRITEMASK_Z));
4734
4735 body.emit(assign(array_ref(adj, 0), neg(
4736 add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
4737 mul(matrix_elt(m, 0, 2), SubFactor14)),
4738 mul(matrix_elt(m, 0, 3), SubFactor15))),
4739 WRITEMASK_W));
4740 body.emit(assign(array_ref(adj, 1),
4741 add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
4742 mul(matrix_elt(m, 0, 2), SubFactor16)),
4743 mul(matrix_elt(m, 0, 3), SubFactor17)),
4744 WRITEMASK_W));
4745 body.emit(assign(array_ref(adj, 2), neg(
4746 add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
4747 mul(matrix_elt(m, 0, 1), SubFactor16)),
4748 mul(matrix_elt(m, 0, 3), SubFactor18))),
4749 WRITEMASK_W));
4750 body.emit(assign(array_ref(adj, 3),
4751 add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
4752 mul(matrix_elt(m, 0, 1), SubFactor17)),
4753 mul(matrix_elt(m, 0, 2), SubFactor18)),
4754 WRITEMASK_W));
4755
4756 ir_expression *det =
4757 add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
4758 add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
4759 add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
4760 mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
4761
4762 body.emit(ret(div(adj, det)));
4763
4764 return sig;
4765 }
4766
4767
4768 ir_function_signature *
4769 builtin_builder::_lessThan(builtin_available_predicate avail,
4770 const glsl_type *type)
4771 {
4772 return binop(avail, ir_binop_less,
4773 glsl_type::bvec(type->vector_elements), type, type);
4774 }
4775
4776 ir_function_signature *
4777 builtin_builder::_lessThanEqual(builtin_available_predicate avail,
4778 const glsl_type *type)
4779 {
4780 return binop(avail, ir_binop_lequal,
4781 glsl_type::bvec(type->vector_elements), type, type);
4782 }
4783
4784 ir_function_signature *
4785 builtin_builder::_greaterThan(builtin_available_predicate avail,
4786 const glsl_type *type)
4787 {
4788 return binop(avail, ir_binop_greater,
4789 glsl_type::bvec(type->vector_elements), type, type);
4790 }
4791
4792 ir_function_signature *
4793 builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
4794 const glsl_type *type)
4795 {
4796 return binop(avail, ir_binop_gequal,
4797 glsl_type::bvec(type->vector_elements), type, type);
4798 }
4799
4800 ir_function_signature *
4801 builtin_builder::_equal(builtin_available_predicate avail,
4802 const glsl_type *type)
4803 {
4804 return binop(avail, ir_binop_equal,
4805 glsl_type::bvec(type->vector_elements), type, type);
4806 }
4807
4808 ir_function_signature *
4809 builtin_builder::_notEqual(builtin_available_predicate avail,
4810 const glsl_type *type)
4811 {
4812 return binop(avail, ir_binop_nequal,
4813 glsl_type::bvec(type->vector_elements), type, type);
4814 }
4815
4816 ir_function_signature *
4817 builtin_builder::_any(const glsl_type *type)
4818 {
4819 ir_variable *v = in_var(type, "v");
4820 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
4821
4822 const unsigned vec_elem = v->type->vector_elements;
4823 body.emit(ret(expr(ir_binop_any_nequal, v, imm(false, vec_elem))));
4824
4825 return sig;
4826 }
4827
4828 ir_function_signature *
4829 builtin_builder::_all(const glsl_type *type)
4830 {
4831 ir_variable *v = in_var(type, "v");
4832 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
4833
4834 const unsigned vec_elem = v->type->vector_elements;
4835 body.emit(ret(expr(ir_binop_all_equal, v, imm(true, vec_elem))));
4836
4837 return sig;
4838 }
4839
4840 UNOP(not, ir_unop_logic_not, always_available)
4841
4842 static bool
4843 has_lod(const glsl_type *sampler_type)
4844 {
4845 assert(sampler_type->is_sampler());
4846
4847 switch (sampler_type->sampler_dimensionality) {
4848 case GLSL_SAMPLER_DIM_RECT:
4849 case GLSL_SAMPLER_DIM_BUF:
4850 case GLSL_SAMPLER_DIM_MS:
4851 return false;
4852 default:
4853 return true;
4854 }
4855 }
4856
4857 ir_function_signature *
4858 builtin_builder::_textureSize(builtin_available_predicate avail,
4859 const glsl_type *return_type,
4860 const glsl_type *sampler_type)
4861 {
4862 ir_variable *s = in_var(sampler_type, "sampler");
4863 /* The sampler always exists; add optional lod later. */
4864 MAKE_SIG(return_type, avail, 1, s);
4865
4866 ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
4867 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
4868
4869 if (has_lod(sampler_type)) {
4870 ir_variable *lod = in_var(glsl_type::int_type, "lod");
4871 sig->parameters.push_tail(lod);
4872 tex->lod_info.lod = var_ref(lod);
4873 } else {
4874 tex->lod_info.lod = imm(0u);
4875 }
4876
4877 body.emit(ret(tex));
4878
4879 return sig;
4880 }
4881
4882 ir_function_signature *
4883 builtin_builder::_textureSamples(const glsl_type *sampler_type)
4884 {
4885 ir_variable *s = in_var(sampler_type, "sampler");
4886 MAKE_SIG(glsl_type::int_type, shader_samples, 1, s);
4887
4888 ir_texture *tex = new(mem_ctx) ir_texture(ir_texture_samples);
4889 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), glsl_type::int_type);
4890 body.emit(ret(tex));
4891
4892 return sig;
4893 }
4894
4895 ir_function_signature *
4896 builtin_builder::_texture(ir_texture_opcode opcode,
4897 builtin_available_predicate avail,
4898 const glsl_type *return_type,
4899 const glsl_type *sampler_type,
4900 const glsl_type *coord_type,
4901 int flags)
4902 {
4903 ir_variable *s = in_var(sampler_type, "sampler");
4904 ir_variable *P = in_var(coord_type, "P");
4905 /* The sampler and coordinate always exist; add optional parameters later. */
4906 MAKE_SIG(return_type, avail, 2, s, P);
4907
4908 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
4909 tex->set_sampler(var_ref(s), return_type);
4910
4911 const int coord_size = sampler_type->coordinate_components();
4912
4913 if (coord_size == coord_type->vector_elements) {
4914 tex->coordinate = var_ref(P);
4915 } else {
4916 /* The incoming coordinate also has the projector or shadow comparator,
4917 * so we need to swizzle those away.
4918 */
4919 tex->coordinate = swizzle_for_size(P, coord_size);
4920 }
4921
4922 /* The projector is always in the last component. */
4923 if (flags & TEX_PROJECT)
4924 tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
4925
4926 if (sampler_type->sampler_shadow) {
4927 if (opcode == ir_tg4) {
4928 /* gather has refz as a separate parameter, immediately after the
4929 * coordinate
4930 */
4931 ir_variable *refz = in_var(glsl_type::float_type, "refz");
4932 sig->parameters.push_tail(refz);
4933 tex->shadow_comparator = var_ref(refz);
4934 } else {
4935 /* The shadow comparator is normally in the Z component, but a few types
4936 * have sufficiently large coordinates that it's in W.
4937 */
4938 tex->shadow_comparator = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
4939 }
4940 }
4941
4942 if (opcode == ir_txl) {
4943 ir_variable *lod = in_var(glsl_type::float_type, "lod");
4944 sig->parameters.push_tail(lod);
4945 tex->lod_info.lod = var_ref(lod);
4946 } else if (opcode == ir_txd) {
4947 int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
4948 ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
4949 ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
4950 sig->parameters.push_tail(dPdx);
4951 sig->parameters.push_tail(dPdy);
4952 tex->lod_info.grad.dPdx = var_ref(dPdx);
4953 tex->lod_info.grad.dPdy = var_ref(dPdy);
4954 }
4955
4956 if (flags & (TEX_OFFSET | TEX_OFFSET_NONCONST)) {
4957 int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
4958 ir_variable *offset =
4959 new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset",
4960 (flags & TEX_OFFSET) ? ir_var_const_in : ir_var_function_in);
4961 sig->parameters.push_tail(offset);
4962 tex->offset = var_ref(offset);
4963 }
4964
4965 if (flags & TEX_OFFSET_ARRAY) {
4966 ir_variable *offsets =
4967 new(mem_ctx) ir_variable(glsl_type::get_array_instance(glsl_type::ivec2_type, 4),
4968 "offsets", ir_var_const_in);
4969 sig->parameters.push_tail(offsets);
4970 tex->offset = var_ref(offsets);
4971 }
4972
4973 if (opcode == ir_tg4) {
4974 if (flags & TEX_COMPONENT) {
4975 ir_variable *component =
4976 new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in);
4977 sig->parameters.push_tail(component);
4978 tex->lod_info.component = var_ref(component);
4979 }
4980 else {
4981 tex->lod_info.component = imm(0);
4982 }
4983 }
4984
4985 /* The "bias" parameter comes /after/ the "offset" parameter, which is
4986 * inconsistent with both textureLodOffset and textureGradOffset.
4987 */
4988 if (opcode == ir_txb) {
4989 ir_variable *bias = in_var(glsl_type::float_type, "bias");
4990 sig->parameters.push_tail(bias);
4991 tex->lod_info.bias = var_ref(bias);
4992 }
4993
4994 body.emit(ret(tex));
4995
4996 return sig;
4997 }
4998
4999 ir_function_signature *
5000 builtin_builder::_textureCubeArrayShadow()
5001 {
5002 ir_variable *s = in_var(glsl_type::samplerCubeArrayShadow_type, "sampler");
5003 ir_variable *P = in_var(glsl_type::vec4_type, "P");
5004 ir_variable *compare = in_var(glsl_type::float_type, "compare");
5005 MAKE_SIG(glsl_type::float_type, texture_cube_map_array, 3, s, P, compare);
5006
5007 ir_texture *tex = new(mem_ctx) ir_texture(ir_tex);
5008 tex->set_sampler(var_ref(s), glsl_type::float_type);
5009
5010 tex->coordinate = var_ref(P);
5011 tex->shadow_comparator = var_ref(compare);
5012
5013 body.emit(ret(tex));
5014
5015 return sig;
5016 }
5017
5018 ir_function_signature *
5019 builtin_builder::_texelFetch(builtin_available_predicate avail,
5020 const glsl_type *return_type,
5021 const glsl_type *sampler_type,
5022 const glsl_type *coord_type,
5023 const glsl_type *offset_type)
5024 {
5025 ir_variable *s = in_var(sampler_type, "sampler");
5026 ir_variable *P = in_var(coord_type, "P");
5027 /* The sampler and coordinate always exist; add optional parameters later. */
5028 MAKE_SIG(return_type, avail, 2, s, P);
5029
5030 ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
5031 tex->coordinate = var_ref(P);
5032 tex->set_sampler(var_ref(s), return_type);
5033
5034 if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
5035 ir_variable *sample = in_var(glsl_type::int_type, "sample");
5036 sig->parameters.push_tail(sample);
5037 tex->lod_info.sample_index = var_ref(sample);
5038 tex->op = ir_txf_ms;
5039 } else if (has_lod(sampler_type)) {
5040 ir_variable *lod = in_var(glsl_type::int_type, "lod");
5041 sig->parameters.push_tail(lod);
5042 tex->lod_info.lod = var_ref(lod);
5043 } else {
5044 tex->lod_info.lod = imm(0u);
5045 }
5046
5047 if (offset_type != NULL) {
5048 ir_variable *offset =
5049 new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in);
5050 sig->parameters.push_tail(offset);
5051 tex->offset = var_ref(offset);
5052 }
5053
5054 body.emit(ret(tex));
5055
5056 return sig;
5057 }
5058
5059 ir_function_signature *
5060 builtin_builder::_EmitVertex()
5061 {
5062 MAKE_SIG(glsl_type::void_type, gs_only, 0);
5063
5064 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
5065 body.emit(new(mem_ctx) ir_emit_vertex(stream));
5066
5067 return sig;
5068 }
5069
5070 ir_function_signature *
5071 builtin_builder::_EmitStreamVertex(builtin_available_predicate avail,
5072 const glsl_type *stream_type)
5073 {
5074 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
5075 *
5076 * "Emit the current values of output variables to the current output
5077 * primitive on stream stream. The argument to stream must be a constant
5078 * integral expression."
5079 */
5080 ir_variable *stream =
5081 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
5082
5083 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
5084
5085 body.emit(new(mem_ctx) ir_emit_vertex(var_ref(stream)));
5086
5087 return sig;
5088 }
5089
5090 ir_function_signature *
5091 builtin_builder::_EndPrimitive()
5092 {
5093 MAKE_SIG(glsl_type::void_type, gs_only, 0);
5094
5095 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
5096 body.emit(new(mem_ctx) ir_end_primitive(stream));
5097
5098 return sig;
5099 }
5100
5101 ir_function_signature *
5102 builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
5103 const glsl_type *stream_type)
5104 {
5105 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
5106 *
5107 * "Completes the current output primitive on stream stream and starts
5108 * a new one. The argument to stream must be a constant integral
5109 * expression."
5110 */
5111 ir_variable *stream =
5112 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
5113
5114 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
5115
5116 body.emit(new(mem_ctx) ir_end_primitive(var_ref(stream)));
5117
5118 return sig;
5119 }
5120
5121 ir_function_signature *
5122 builtin_builder::_barrier()
5123 {
5124 MAKE_SIG(glsl_type::void_type, barrier_supported, 0);
5125
5126 body.emit(new(mem_ctx) ir_barrier());
5127 return sig;
5128 }
5129
5130 ir_function_signature *
5131 builtin_builder::_textureQueryLod(builtin_available_predicate avail,
5132 const glsl_type *sampler_type,
5133 const glsl_type *coord_type)
5134 {
5135 ir_variable *s = in_var(sampler_type, "sampler");
5136 ir_variable *coord = in_var(coord_type, "coord");
5137 /* The sampler and coordinate always exist; add optional parameters later. */
5138 MAKE_SIG(glsl_type::vec2_type, avail, 2, s, coord);
5139
5140 ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
5141 tex->coordinate = var_ref(coord);
5142 tex->set_sampler(var_ref(s), glsl_type::vec2_type);
5143
5144 body.emit(ret(tex));
5145
5146 return sig;
5147 }
5148
5149 ir_function_signature *
5150 builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
5151 {
5152 ir_variable *s = in_var(sampler_type, "sampler");
5153 const glsl_type *return_type = glsl_type::int_type;
5154 MAKE_SIG(return_type, texture_query_levels, 1, s);
5155
5156 ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
5157 tex->set_sampler(var_ref(s), return_type);
5158
5159 body.emit(ret(tex));
5160
5161 return sig;
5162 }
5163
5164 ir_function_signature *
5165 builtin_builder::_textureSamplesIdentical(builtin_available_predicate avail,
5166 const glsl_type *sampler_type,
5167 const glsl_type *coord_type)
5168 {
5169 ir_variable *s = in_var(sampler_type, "sampler");
5170 ir_variable *P = in_var(coord_type, "P");
5171 const glsl_type *return_type = glsl_type::bool_type;
5172 MAKE_SIG(return_type, avail, 2, s, P);
5173
5174 ir_texture *tex = new(mem_ctx) ir_texture(ir_samples_identical);
5175 tex->coordinate = var_ref(P);
5176 tex->set_sampler(var_ref(s), return_type);
5177
5178 body.emit(ret(tex));
5179
5180 return sig;
5181 }
5182
5183 UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
5184 UNOP(dFdxCoarse, ir_unop_dFdx_coarse, fs_derivative_control)
5185 UNOP(dFdxFine, ir_unop_dFdx_fine, fs_derivative_control)
5186 UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
5187 UNOP(dFdyCoarse, ir_unop_dFdy_coarse, fs_derivative_control)
5188 UNOP(dFdyFine, ir_unop_dFdy_fine, fs_derivative_control)
5189
5190 ir_function_signature *
5191 builtin_builder::_fwidth(const glsl_type *type)
5192 {
5193 ir_variable *p = in_var(type, "p");
5194 MAKE_SIG(type, fs_oes_derivatives, 1, p);
5195
5196 body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
5197
5198 return sig;
5199 }
5200
5201 ir_function_signature *
5202 builtin_builder::_fwidthCoarse(const glsl_type *type)
5203 {
5204 ir_variable *p = in_var(type, "p");
5205 MAKE_SIG(type, fs_derivative_control, 1, p);
5206
5207 body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
5208 abs(expr(ir_unop_dFdy_coarse, p)))));
5209
5210 return sig;
5211 }
5212
5213 ir_function_signature *
5214 builtin_builder::_fwidthFine(const glsl_type *type)
5215 {
5216 ir_variable *p = in_var(type, "p");
5217 MAKE_SIG(type, fs_derivative_control, 1, p);
5218
5219 body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
5220 abs(expr(ir_unop_dFdy_fine, p)))));
5221
5222 return sig;
5223 }
5224
5225 ir_function_signature *
5226 builtin_builder::_noise1(const glsl_type *type)
5227 {
5228 return unop(v110, ir_unop_noise, glsl_type::float_type, type);
5229 }
5230
5231 ir_function_signature *
5232 builtin_builder::_noise2(const glsl_type *type)
5233 {
5234 ir_variable *p = in_var(type, "p");
5235 MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
5236
5237 ir_constant_data b_offset;
5238 b_offset.f[0] = 601.0f;
5239 b_offset.f[1] = 313.0f;
5240 b_offset.f[2] = 29.0f;
5241 b_offset.f[3] = 277.0f;
5242
5243 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
5244 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
5245 ir_variable *t = body.make_temp(glsl_type::vec2_type, "t");
5246 body.emit(assign(a, expr(ir_unop_noise, p)));
5247 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
5248 body.emit(assign(t, a, WRITEMASK_X));
5249 body.emit(assign(t, b, WRITEMASK_Y));
5250 body.emit(ret(t));
5251
5252 return sig;
5253 }
5254
5255 ir_function_signature *
5256 builtin_builder::_noise3(const glsl_type *type)
5257 {
5258 ir_variable *p = in_var(type, "p");
5259 MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
5260
5261 ir_constant_data b_offset;
5262 b_offset.f[0] = 601.0f;
5263 b_offset.f[1] = 313.0f;
5264 b_offset.f[2] = 29.0f;
5265 b_offset.f[3] = 277.0f;
5266
5267 ir_constant_data c_offset;
5268 c_offset.f[0] = 1559.0f;
5269 c_offset.f[1] = 113.0f;
5270 c_offset.f[2] = 1861.0f;
5271 c_offset.f[3] = 797.0f;
5272
5273 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
5274 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
5275 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
5276 ir_variable *t = body.make_temp(glsl_type::vec3_type, "t");
5277 body.emit(assign(a, expr(ir_unop_noise, p)));
5278 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
5279 body.emit(assign(c, expr(ir_unop_noise, add(p, imm(type, c_offset)))));
5280 body.emit(assign(t, a, WRITEMASK_X));
5281 body.emit(assign(t, b, WRITEMASK_Y));
5282 body.emit(assign(t, c, WRITEMASK_Z));
5283 body.emit(ret(t));
5284
5285 return sig;
5286 }
5287
5288 ir_function_signature *
5289 builtin_builder::_noise4(const glsl_type *type)
5290 {
5291 ir_variable *p = in_var(type, "p");
5292 MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
5293
5294 ir_variable *_p = body.make_temp(type, "_p");
5295
5296 ir_constant_data p_offset;
5297 p_offset.f[0] = 1559.0f;
5298 p_offset.f[1] = 113.0f;
5299 p_offset.f[2] = 1861.0f;
5300 p_offset.f[3] = 797.0f;
5301
5302 body.emit(assign(_p, add(p, imm(type, p_offset))));
5303
5304 ir_constant_data offset;
5305 offset.f[0] = 601.0f;
5306 offset.f[1] = 313.0f;
5307 offset.f[2] = 29.0f;
5308 offset.f[3] = 277.0f;
5309
5310 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
5311 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
5312 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
5313 ir_variable *d = body.make_temp(glsl_type::float_type, "d");
5314 ir_variable *t = body.make_temp(glsl_type::vec4_type, "t");
5315 body.emit(assign(a, expr(ir_unop_noise, p)));
5316 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, offset)))));
5317 body.emit(assign(c, expr(ir_unop_noise, _p)));
5318 body.emit(assign(d, expr(ir_unop_noise, add(_p, imm(type, offset)))));
5319 body.emit(assign(t, a, WRITEMASK_X));
5320 body.emit(assign(t, b, WRITEMASK_Y));
5321 body.emit(assign(t, c, WRITEMASK_Z));
5322 body.emit(assign(t, d, WRITEMASK_W));
5323 body.emit(ret(t));
5324
5325 return sig;
5326 }
5327
5328 ir_function_signature *
5329 builtin_builder::_bitfieldExtract(const glsl_type *type)
5330 {
5331 bool is_uint = type->base_type == GLSL_TYPE_UINT;
5332 ir_variable *value = in_var(type, "value");
5333 ir_variable *offset = in_var(glsl_type::int_type, "offset");
5334 ir_variable *bits = in_var(glsl_type::int_type, "bits");
5335 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, value, offset,
5336 bits);
5337
5338 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
5339 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
5340
5341 body.emit(ret(expr(ir_triop_bitfield_extract, value,
5342 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
5343 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
5344
5345 return sig;
5346 }
5347
5348 ir_function_signature *
5349 builtin_builder::_bitfieldInsert(const glsl_type *type)
5350 {
5351 bool is_uint = type->base_type == GLSL_TYPE_UINT;
5352 ir_variable *base = in_var(type, "base");
5353 ir_variable *insert = in_var(type, "insert");
5354 ir_variable *offset = in_var(glsl_type::int_type, "offset");
5355 ir_variable *bits = in_var(glsl_type::int_type, "bits");
5356 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 4, base, insert,
5357 offset, bits);
5358
5359 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
5360 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
5361
5362 body.emit(ret(bitfield_insert(base, insert,
5363 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
5364 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
5365
5366 return sig;
5367 }
5368
5369 UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5_or_es31_or_integer_functions)
5370
5371 ir_function_signature *
5372 builtin_builder::_bitCount(const glsl_type *type)
5373 {
5374 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_bit_count,
5375 glsl_type::ivec(type->vector_elements), type);
5376 }
5377
5378 ir_function_signature *
5379 builtin_builder::_findLSB(const glsl_type *type)
5380 {
5381 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_find_lsb,
5382 glsl_type::ivec(type->vector_elements), type);
5383 }
5384
5385 ir_function_signature *
5386 builtin_builder::_findMSB(const glsl_type *type)
5387 {
5388 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_find_msb,
5389 glsl_type::ivec(type->vector_elements), type);
5390 }
5391
5392 ir_function_signature *
5393 builtin_builder::_fma(builtin_available_predicate avail, const glsl_type *type)
5394 {
5395 ir_variable *a = in_var(type, "a");
5396 ir_variable *b = in_var(type, "b");
5397 ir_variable *c = in_var(type, "c");
5398 MAKE_SIG(type, avail, 3, a, b, c);
5399
5400 body.emit(ret(ir_builder::fma(a, b, c)));
5401
5402 return sig;
5403 }
5404
5405 ir_function_signature *
5406 builtin_builder::_ldexp(const glsl_type *x_type, const glsl_type *exp_type)
5407 {
5408 return binop(x_type->base_type == GLSL_TYPE_DOUBLE ? fp64 : gpu_shader5_or_es31_or_integer_functions,
5409 ir_binop_ldexp, x_type, x_type, exp_type);
5410 }
5411
5412 ir_function_signature *
5413 builtin_builder::_dfrexp(const glsl_type *x_type, const glsl_type *exp_type)
5414 {
5415 ir_variable *x = in_var(x_type, "x");
5416 ir_variable *exponent = out_var(exp_type, "exp");
5417 MAKE_SIG(x_type, fp64, 2, x, exponent);
5418
5419 body.emit(assign(exponent, expr(ir_unop_frexp_exp, x)));
5420
5421 body.emit(ret(expr(ir_unop_frexp_sig, x)));
5422 return sig;
5423 }
5424
5425 ir_function_signature *
5426 builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
5427 {
5428 ir_variable *x = in_var(x_type, "x");
5429 ir_variable *exponent = out_var(exp_type, "exp");
5430 MAKE_SIG(x_type, gpu_shader5_or_es31_or_integer_functions, 2, x, exponent);
5431
5432 const unsigned vec_elem = x_type->vector_elements;
5433 const glsl_type *bvec = glsl_type::get_instance(GLSL_TYPE_BOOL, vec_elem, 1);
5434 const glsl_type *uvec = glsl_type::get_instance(GLSL_TYPE_UINT, vec_elem, 1);
5435
5436 /* Single-precision floating-point values are stored as
5437 * 1 sign bit;
5438 * 8 exponent bits;
5439 * 23 mantissa bits.
5440 *
5441 * An exponent shift of 23 will shift the mantissa out, leaving only the
5442 * exponent and sign bit (which itself may be zero, if the absolute value
5443 * was taken before the bitcast and shift.
5444 */
5445 ir_constant *exponent_shift = imm(23);
5446 ir_constant *exponent_bias = imm(-126, vec_elem);
5447
5448 ir_constant *sign_mantissa_mask = imm(0x807fffffu, vec_elem);
5449
5450 /* Exponent of floating-point values in the range [0.5, 1.0). */
5451 ir_constant *exponent_value = imm(0x3f000000u, vec_elem);
5452
5453 ir_variable *is_not_zero = body.make_temp(bvec, "is_not_zero");
5454 body.emit(assign(is_not_zero, nequal(abs(x), imm(0.0f, vec_elem))));
5455
5456 /* Since abs(x) ensures that the sign bit is zero, we don't need to bitcast
5457 * to unsigned integers to ensure that 1 bits aren't shifted in.
5458 */
5459 body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
5460 body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
5461 imm(0, vec_elem)))));
5462
5463 ir_variable *bits = body.make_temp(uvec, "bits");
5464 body.emit(assign(bits, bitcast_f2u(x)));
5465 body.emit(assign(bits, bit_and(bits, sign_mantissa_mask)));
5466 body.emit(assign(bits, bit_or(bits, csel(is_not_zero, exponent_value,
5467 imm(0u, vec_elem)))));
5468 body.emit(ret(bitcast_u2f(bits)));
5469
5470 return sig;
5471 }
5472
5473 ir_function_signature *
5474 builtin_builder::_uaddCarry(const glsl_type *type)
5475 {
5476 ir_variable *x = in_var(type, "x");
5477 ir_variable *y = in_var(type, "y");
5478 ir_variable *carry = out_var(type, "carry");
5479 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, x, y, carry);
5480
5481 body.emit(assign(carry, ir_builder::carry(x, y)));
5482 body.emit(ret(add(x, y)));
5483
5484 return sig;
5485 }
5486
5487 ir_function_signature *
5488 builtin_builder::_usubBorrow(const glsl_type *type)
5489 {
5490 ir_variable *x = in_var(type, "x");
5491 ir_variable *y = in_var(type, "y");
5492 ir_variable *borrow = out_var(type, "borrow");
5493 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, x, y, borrow);
5494
5495 body.emit(assign(borrow, ir_builder::borrow(x, y)));
5496 body.emit(ret(sub(x, y)));
5497
5498 return sig;
5499 }
5500
5501 /**
5502 * For both imulExtended() and umulExtended() built-ins.
5503 */
5504 ir_function_signature *
5505 builtin_builder::_mulExtended(const glsl_type *type)
5506 {
5507 ir_variable *x = in_var(type, "x");
5508 ir_variable *y = in_var(type, "y");
5509 ir_variable *msb = out_var(type, "msb");
5510 ir_variable *lsb = out_var(type, "lsb");
5511 MAKE_SIG(glsl_type::void_type, gpu_shader5_or_es31_or_integer_functions, 4, x, y, msb, lsb);
5512
5513 body.emit(assign(msb, imul_high(x, y)));
5514 body.emit(assign(lsb, mul(x, y)));
5515
5516 return sig;
5517 }
5518
5519 ir_function_signature *
5520 builtin_builder::_interpolateAtCentroid(const glsl_type *type)
5521 {
5522 ir_variable *interpolant = in_var(type, "interpolant");
5523 interpolant->data.must_be_shader_input = 1;
5524 MAKE_SIG(type, fs_interpolate_at, 1, interpolant);
5525
5526 body.emit(ret(interpolate_at_centroid(interpolant)));
5527
5528 return sig;
5529 }
5530
5531 ir_function_signature *
5532 builtin_builder::_interpolateAtOffset(const glsl_type *type)
5533 {
5534 ir_variable *interpolant = in_var(type, "interpolant");
5535 interpolant->data.must_be_shader_input = 1;
5536 ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
5537 MAKE_SIG(type, fs_interpolate_at, 2, interpolant, offset);
5538
5539 body.emit(ret(interpolate_at_offset(interpolant, offset)));
5540
5541 return sig;
5542 }
5543
5544 ir_function_signature *
5545 builtin_builder::_interpolateAtSample(const glsl_type *type)
5546 {
5547 ir_variable *interpolant = in_var(type, "interpolant");
5548 interpolant->data.must_be_shader_input = 1;
5549 ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
5550 MAKE_SIG(type, fs_interpolate_at, 2, interpolant, sample_num);
5551
5552 body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
5553
5554 return sig;
5555 }
5556
5557 ir_function_signature *
5558 builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail,
5559 enum ir_intrinsic_id id)
5560 {
5561 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
5562 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 1, counter);
5563 return sig;
5564 }
5565
5566 ir_function_signature *
5567 builtin_builder::_atomic_counter_intrinsic1(builtin_available_predicate avail,
5568 enum ir_intrinsic_id id)
5569 {
5570 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
5571 ir_variable *data = in_var(glsl_type::uint_type, "data");
5572 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 2, counter, data);
5573 return sig;
5574 }
5575
5576 ir_function_signature *
5577 builtin_builder::_atomic_counter_intrinsic2(builtin_available_predicate avail,
5578 enum ir_intrinsic_id id)
5579 {
5580 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
5581 ir_variable *compare = in_var(glsl_type::uint_type, "compare");
5582 ir_variable *data = in_var(glsl_type::uint_type, "data");
5583 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 3, counter, compare, data);
5584 return sig;
5585 }
5586
5587 ir_function_signature *
5588 builtin_builder::_atomic_intrinsic2(builtin_available_predicate avail,
5589 const glsl_type *type,
5590 enum ir_intrinsic_id id)
5591 {
5592 ir_variable *atomic = in_var(type, "atomic");
5593 ir_variable *data = in_var(type, "data");
5594 MAKE_INTRINSIC(type, id, avail, 2, atomic, data);
5595 return sig;
5596 }
5597
5598 ir_function_signature *
5599 builtin_builder::_atomic_intrinsic3(builtin_available_predicate avail,
5600 const glsl_type *type,
5601 enum ir_intrinsic_id id)
5602 {
5603 ir_variable *atomic = in_var(type, "atomic");
5604 ir_variable *data1 = in_var(type, "data1");
5605 ir_variable *data2 = in_var(type, "data2");
5606 MAKE_INTRINSIC(type, id, avail, 3, atomic, data1, data2);
5607 return sig;
5608 }
5609
5610 ir_function_signature *
5611 builtin_builder::_atomic_counter_op(const char *intrinsic,
5612 builtin_available_predicate avail)
5613 {
5614 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
5615 MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
5616
5617 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
5618 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5619 sig->parameters));
5620 body.emit(ret(retval));
5621 return sig;
5622 }
5623
5624 ir_function_signature *
5625 builtin_builder::_atomic_counter_op1(const char *intrinsic,
5626 builtin_available_predicate avail)
5627 {
5628 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
5629 ir_variable *data = in_var(glsl_type::uint_type, "data");
5630 MAKE_SIG(glsl_type::uint_type, avail, 2, counter, data);
5631
5632 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
5633
5634 /* Instead of generating an __intrinsic_atomic_sub, generate an
5635 * __intrinsic_atomic_add with the data parameter negated.
5636 */
5637 if (strcmp("__intrinsic_atomic_sub", intrinsic) == 0) {
5638 ir_variable *const neg_data =
5639 body.make_temp(glsl_type::uint_type, "neg_data");
5640
5641 body.emit(assign(neg_data, neg(data)));
5642
5643 exec_list parameters;
5644
5645 parameters.push_tail(new(mem_ctx) ir_dereference_variable(counter));
5646 parameters.push_tail(new(mem_ctx) ir_dereference_variable(neg_data));
5647
5648 ir_function *const func =
5649 shader->symbols->get_function("__intrinsic_atomic_add");
5650 ir_instruction *const c = call(func, retval, parameters);
5651
5652 assert(c != NULL);
5653 assert(parameters.is_empty());
5654
5655 body.emit(c);
5656 } else {
5657 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5658 sig->parameters));
5659 }
5660
5661 body.emit(ret(retval));
5662 return sig;
5663 }
5664
5665 ir_function_signature *
5666 builtin_builder::_atomic_counter_op2(const char *intrinsic,
5667 builtin_available_predicate avail)
5668 {
5669 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
5670 ir_variable *compare = in_var(glsl_type::uint_type, "compare");
5671 ir_variable *data = in_var(glsl_type::uint_type, "data");
5672 MAKE_SIG(glsl_type::uint_type, avail, 3, counter, compare, data);
5673
5674 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
5675 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5676 sig->parameters));
5677 body.emit(ret(retval));
5678 return sig;
5679 }
5680
5681 ir_function_signature *
5682 builtin_builder::_atomic_op2(const char *intrinsic,
5683 builtin_available_predicate avail,
5684 const glsl_type *type)
5685 {
5686 ir_variable *atomic = in_var(type, "atomic_var");
5687 ir_variable *data = in_var(type, "atomic_data");
5688 MAKE_SIG(type, avail, 2, atomic, data);
5689
5690 ir_variable *retval = body.make_temp(type, "atomic_retval");
5691 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5692 sig->parameters));
5693 body.emit(ret(retval));
5694 return sig;
5695 }
5696
5697 ir_function_signature *
5698 builtin_builder::_atomic_op3(const char *intrinsic,
5699 builtin_available_predicate avail,
5700 const glsl_type *type)
5701 {
5702 ir_variable *atomic = in_var(type, "atomic_var");
5703 ir_variable *data1 = in_var(type, "atomic_data1");
5704 ir_variable *data2 = in_var(type, "atomic_data2");
5705 MAKE_SIG(type, avail, 3, atomic, data1, data2);
5706
5707 ir_variable *retval = body.make_temp(type, "atomic_retval");
5708 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5709 sig->parameters));
5710 body.emit(ret(retval));
5711 return sig;
5712 }
5713
5714 ir_function_signature *
5715 builtin_builder::_min3(const glsl_type *type)
5716 {
5717 ir_variable *x = in_var(type, "x");
5718 ir_variable *y = in_var(type, "y");
5719 ir_variable *z = in_var(type, "z");
5720 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5721
5722 ir_expression *min3 = min2(x, min2(y,z));
5723 body.emit(ret(min3));
5724
5725 return sig;
5726 }
5727
5728 ir_function_signature *
5729 builtin_builder::_max3(const glsl_type *type)
5730 {
5731 ir_variable *x = in_var(type, "x");
5732 ir_variable *y = in_var(type, "y");
5733 ir_variable *z = in_var(type, "z");
5734 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5735
5736 ir_expression *max3 = max2(x, max2(y,z));
5737 body.emit(ret(max3));
5738
5739 return sig;
5740 }
5741
5742 ir_function_signature *
5743 builtin_builder::_mid3(const glsl_type *type)
5744 {
5745 ir_variable *x = in_var(type, "x");
5746 ir_variable *y = in_var(type, "y");
5747 ir_variable *z = in_var(type, "z");
5748 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5749
5750 ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
5751 body.emit(ret(mid3));
5752
5753 return sig;
5754 }
5755
5756 static builtin_available_predicate
5757 get_image_available_predicate(const glsl_type *type, unsigned flags)
5758 {
5759 if ((flags & IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE) &&
5760 type->sampled_type == GLSL_TYPE_FLOAT)
5761 return shader_image_atomic_exchange_float;
5762
5763 else if (flags & (IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE |
5764 IMAGE_FUNCTION_AVAIL_ATOMIC))
5765 return shader_image_atomic;
5766
5767 else
5768 return shader_image_load_store;
5769 }
5770
5771 ir_function_signature *
5772 builtin_builder::_image_prototype(const glsl_type *image_type,
5773 unsigned num_arguments,
5774 unsigned flags)
5775 {
5776 const glsl_type *data_type = glsl_type::get_instance(
5777 image_type->sampled_type,
5778 (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
5779 1);
5780 const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
5781 glsl_type::void_type : data_type);
5782
5783 /* Addressing arguments that are always present. */
5784 ir_variable *image = in_var(image_type, "image");
5785 ir_variable *coord = in_var(
5786 glsl_type::ivec(image_type->coordinate_components()), "coord");
5787
5788 ir_function_signature *sig = new_sig(
5789 ret_type, get_image_available_predicate(image_type, flags),
5790 2, image, coord);
5791
5792 /* Sample index for multisample images. */
5793 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
5794 sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
5795
5796 /* Data arguments. */
5797 for (unsigned i = 0; i < num_arguments; ++i) {
5798 char *arg_name = ralloc_asprintf(NULL, "arg%d", i);
5799 sig->parameters.push_tail(in_var(data_type, arg_name));
5800 ralloc_free(arg_name);
5801 }
5802
5803 /* Set the maximal set of qualifiers allowed for this image
5804 * built-in. Function calls with arguments having fewer
5805 * qualifiers than present in the prototype are allowed by the
5806 * spec, but not with more, i.e. this will make the compiler
5807 * accept everything that needs to be accepted, and reject cases
5808 * like loads from write-only or stores to read-only images.
5809 */
5810 image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
5811 image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
5812 image->data.image_coherent = true;
5813 image->data.image_volatile = true;
5814 image->data.image_restrict = true;
5815
5816 return sig;
5817 }
5818
5819 ir_function_signature *
5820 builtin_builder::_image_size_prototype(const glsl_type *image_type,
5821 unsigned /* num_arguments */,
5822 unsigned /* flags */)
5823 {
5824 const glsl_type *ret_type;
5825 unsigned num_components = image_type->coordinate_components();
5826
5827 /* From the ARB_shader_image_size extension:
5828 * "Cube images return the dimensions of one face."
5829 */
5830 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE &&
5831 !image_type->sampler_array) {
5832 num_components = 2;
5833 }
5834
5835 /* FIXME: Add the highp precision qualifier for GLES 3.10 when it is
5836 * supported by mesa.
5837 */
5838 ret_type = glsl_type::get_instance(GLSL_TYPE_INT, num_components, 1);
5839
5840 ir_variable *image = in_var(image_type, "image");
5841 ir_function_signature *sig = new_sig(ret_type, shader_image_size, 1, image);
5842
5843 /* Set the maximal set of qualifiers allowed for this image
5844 * built-in. Function calls with arguments having fewer
5845 * qualifiers than present in the prototype are allowed by the
5846 * spec, but not with more, i.e. this will make the compiler
5847 * accept everything that needs to be accepted, and reject cases
5848 * like loads from write-only or stores to read-only images.
5849 */
5850 image->data.image_read_only = true;
5851 image->data.image_write_only = true;
5852 image->data.image_coherent = true;
5853 image->data.image_volatile = true;
5854 image->data.image_restrict = true;
5855
5856 return sig;
5857 }
5858
5859 ir_function_signature *
5860 builtin_builder::_image_samples_prototype(const glsl_type *image_type,
5861 unsigned /* num_arguments */,
5862 unsigned /* flags */)
5863 {
5864 ir_variable *image = in_var(image_type, "image");
5865 ir_function_signature *sig =
5866 new_sig(glsl_type::int_type, shader_samples, 1, image);
5867
5868 /* Set the maximal set of qualifiers allowed for this image
5869 * built-in. Function calls with arguments having fewer
5870 * qualifiers than present in the prototype are allowed by the
5871 * spec, but not with more, i.e. this will make the compiler
5872 * accept everything that needs to be accepted, and reject cases
5873 * like loads from write-only or stores to read-only images.
5874 */
5875 image->data.image_read_only = true;
5876 image->data.image_write_only = true;
5877 image->data.image_coherent = true;
5878 image->data.image_volatile = true;
5879 image->data.image_restrict = true;
5880
5881 return sig;
5882 }
5883
5884 ir_function_signature *
5885 builtin_builder::_image(image_prototype_ctr prototype,
5886 const glsl_type *image_type,
5887 const char *intrinsic_name,
5888 unsigned num_arguments,
5889 unsigned flags,
5890 enum ir_intrinsic_id id)
5891 {
5892 ir_function_signature *sig = (this->*prototype)(image_type,
5893 num_arguments, flags);
5894
5895 if (flags & IMAGE_FUNCTION_EMIT_STUB) {
5896 ir_factory body(&sig->body, mem_ctx);
5897 ir_function *f = shader->symbols->get_function(intrinsic_name);
5898
5899 if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
5900 body.emit(call(f, NULL, sig->parameters));
5901 } else {
5902 ir_variable *ret_val =
5903 body.make_temp(sig->return_type, "_ret_val");
5904 body.emit(call(f, ret_val, sig->parameters));
5905 body.emit(ret(ret_val));
5906 }
5907
5908 sig->is_defined = true;
5909
5910 } else {
5911 sig->intrinsic_id = id;
5912 }
5913
5914 return sig;
5915 }
5916
5917 ir_function_signature *
5918 builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail,
5919 enum ir_intrinsic_id id)
5920 {
5921 MAKE_INTRINSIC(glsl_type::void_type, id, avail, 0);
5922 return sig;
5923 }
5924
5925 ir_function_signature *
5926 builtin_builder::_memory_barrier(const char *intrinsic_name,
5927 builtin_available_predicate avail)
5928 {
5929 MAKE_SIG(glsl_type::void_type, avail, 0);
5930 body.emit(call(shader->symbols->get_function(intrinsic_name),
5931 NULL, sig->parameters));
5932 return sig;
5933 }
5934
5935 ir_function_signature *
5936 builtin_builder::_shader_clock_intrinsic(builtin_available_predicate avail,
5937 const glsl_type *type)
5938 {
5939 MAKE_INTRINSIC(type, ir_intrinsic_shader_clock, avail, 0);
5940 return sig;
5941 }
5942
5943 ir_function_signature *
5944 builtin_builder::_shader_clock(builtin_available_predicate avail,
5945 const glsl_type *type)
5946 {
5947 MAKE_SIG(type, avail, 0);
5948
5949 ir_variable *retval = body.make_temp(type, "clock_retval");
5950
5951 body.emit(call(shader->symbols->get_function("__intrinsic_shader_clock"),
5952 retval, sig->parameters));
5953
5954 if (type == glsl_type::uint64_t_type) {
5955 body.emit(ret(expr(ir_unop_pack_uint_2x32, retval)));
5956 } else {
5957 body.emit(ret(retval));
5958 }
5959
5960 return sig;
5961 }
5962
5963 ir_function_signature *
5964 builtin_builder::_vote(enum ir_expression_operation opcode)
5965 {
5966 ir_variable *value = in_var(glsl_type::bool_type, "value");
5967
5968 MAKE_SIG(glsl_type::bool_type, vote, 1, value);
5969 body.emit(ret(expr(opcode, value)));
5970 return sig;
5971 }
5972
5973 /** @} */
5974
5975 /******************************************************************************/
5976
5977 /* The singleton instance of builtin_builder. */
5978 static builtin_builder builtins;
5979 static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
5980
5981 /**
5982 * External API (exposing the built-in module to the rest of the compiler):
5983 * @{
5984 */
5985 void
5986 _mesa_glsl_initialize_builtin_functions()
5987 {
5988 mtx_lock(&builtins_lock);
5989 builtins.initialize();
5990 mtx_unlock(&builtins_lock);
5991 }
5992
5993 void
5994 _mesa_glsl_release_builtin_functions()
5995 {
5996 mtx_lock(&builtins_lock);
5997 builtins.release();
5998 mtx_unlock(&builtins_lock);
5999 }
6000
6001 ir_function_signature *
6002 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
6003 const char *name, exec_list *actual_parameters)
6004 {
6005 ir_function_signature * s;
6006 mtx_lock(&builtins_lock);
6007 s = builtins.find(state, name, actual_parameters);
6008 mtx_unlock(&builtins_lock);
6009 return s;
6010 }
6011
6012 ir_function *
6013 _mesa_glsl_find_builtin_function_by_name(const char *name)
6014 {
6015 ir_function *f;
6016 mtx_lock(&builtins_lock);
6017 f = builtins.shader->symbols->get_function(name);
6018 mtx_unlock(&builtins_lock);
6019 return f;
6020 }
6021
6022 gl_shader *
6023 _mesa_glsl_get_builtin_function_shader()
6024 {
6025 return builtins.shader;
6026 }
6027
6028
6029 /**
6030 * Get the function signature for main from a shader
6031 */
6032 ir_function_signature *
6033 _mesa_get_main_function_signature(glsl_symbol_table *symbols)
6034 {
6035 ir_function *const f = symbols->get_function("main");
6036 if (f != NULL) {
6037 exec_list void_parameters;
6038
6039 /* Look for the 'void main()' signature and ensure that it's defined.
6040 * This keeps the linker from accidentally pick a shader that just
6041 * contains a prototype for main.
6042 *
6043 * We don't have to check for multiple definitions of main (in multiple
6044 * shaders) because that would have already been caught above.
6045 */
6046 ir_function_signature *sig =
6047 f->matching_signature(NULL, &void_parameters, false);
6048 if ((sig != NULL) && sig->is_defined) {
6049 return sig;
6050 }
6051 }
6052
6053 return NULL;
6054 }
6055
6056 /** @} */