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