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