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