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