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