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