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