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