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