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