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