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