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