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