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