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