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