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