Debian Codegraph @

third_party/rust/glslopt/glsl-optimizer/src/compiler/glsl/builtin_functions.cpp

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