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