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