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