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