Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / compiler / glsl / builtin_functions.cpp
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /**
25 * \file builtin_functions.cpp
26 *
27 * Support for GLSL built-in functions.
28 *
29 * This file is split into several main components:
30 *
31 * 1. Availability predicates
32 *
33 * A series of small functions that check whether the current shader
34 * supports the version/extensions required to expose a built-in.
35 *
36 * 2. Core builtin_builder class functionality
37 *
38 * 3. Lists of built-in functions
39 *
40 * The builtin_builder::create_builtins() function contains lists of all
41 * built-in function signatures, where they're available, what types they
42 * take, and so on.
43 *
44 * 4. Implementations of built-in function signatures
45 *
46 * A series of functions which create ir_function_signatures and emit IR
47 * via ir_builder to implement them.
48 *
49 * 5. External API
50 *
51 * A few functions the rest of the compiler can use to interact with the
52 * built-in function module. For example, searching for a built-in by
53 * name and parameters.
54 */
55
56 #include <stdarg.h>
57 #include <stdio.h>
58 #include "main/core.h" /* for struct gl_shader */
59 #include "main/shaderobj.h"
60 #include "ir_builder.h"
61 #include "glsl_parser_extras.h"
62 #include "program/prog_instruction.h"
63 #include <math.h>
64
65 #define M_PIf ((float) M_PI)
66 #define M_PI_2f ((float) M_PI_2)
67 #define M_PI_4f ((float) M_PI_4)
68
69 using namespace ir_builder;
70
71 /**
72 * Availability predicates:
73 * @{
74 */
75 static bool
76 always_available(const _mesa_glsl_parse_state *)
77 {
78 return true;
79 }
80
81 static bool
82 compatibility_vs_only(const _mesa_glsl_parse_state *state)
83 {
84 return state->stage == MESA_SHADER_VERTEX &&
85 state->language_version <= 130 &&
86 !state->es_shader;
87 }
88
89 static bool
90 fs_only(const _mesa_glsl_parse_state *state)
91 {
92 return state->stage == MESA_SHADER_FRAGMENT;
93 }
94
95 static bool
96 gs_only(const _mesa_glsl_parse_state *state)
97 {
98 return state->stage == MESA_SHADER_GEOMETRY;
99 }
100
101 static bool
102 v110(const _mesa_glsl_parse_state *state)
103 {
104 return !state->es_shader;
105 }
106
107 static bool
108 v110_fs_only(const _mesa_glsl_parse_state *state)
109 {
110 return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT;
111 }
112
113 static bool
114 v120(const _mesa_glsl_parse_state *state)
115 {
116 return state->is_version(120, 300);
117 }
118
119 static bool
120 v130(const _mesa_glsl_parse_state *state)
121 {
122 return state->is_version(130, 300);
123 }
124
125 static bool
126 v130_fs_only(const _mesa_glsl_parse_state *state)
127 {
128 return state->is_version(130, 300) &&
129 state->stage == MESA_SHADER_FRAGMENT;
130 }
131
132 static bool
133 v140(const _mesa_glsl_parse_state *state)
134 {
135 return state->is_version(140, 0);
136 }
137
138 static bool
139 v140_or_es3(const _mesa_glsl_parse_state *state)
140 {
141 return state->is_version(140, 300);
142 }
143
144 static bool
145 v400_fs_only(const _mesa_glsl_parse_state *state)
146 {
147 return state->is_version(400, 0) &&
148 state->stage == MESA_SHADER_FRAGMENT;
149 }
150
151 static bool
152 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 BA2(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(always_available, glsl_type::float_type, glsl_type::float_type),
1246 _mod(always_available, glsl_type::vec2_type, glsl_type::float_type),
1247 _mod(always_available, glsl_type::vec3_type, glsl_type::float_type),
1248 _mod(always_available, glsl_type::vec4_type, glsl_type::float_type),
1249
1250 _mod(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1251 _mod(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1252 _mod(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1253
1254 _mod(fp64, glsl_type::double_type, glsl_type::double_type),
1255 _mod(fp64, glsl_type::dvec2_type, glsl_type::double_type),
1256 _mod(fp64, glsl_type::dvec3_type, glsl_type::double_type),
1257 _mod(fp64, glsl_type::dvec4_type, glsl_type::double_type),
1258
1259 _mod(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1260 _mod(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1261 _mod(fp64, 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(builtin_available_predicate avail,
3456 const glsl_type *x_type, const glsl_type *y_type)
3457 {
3458 return binop(avail, ir_binop_mod, x_type, x_type, y_type);
3459 }
3460
3461 ir_function_signature *
3462 builtin_builder::_modf(builtin_available_predicate avail, const glsl_type *type)
3463 {
3464 ir_variable *x = in_var(type, "x");
3465 ir_variable *i = out_var(type, "i");
3466 MAKE_SIG(type, avail, 2, x, i);
3467
3468 ir_variable *t = body.make_temp(type, "t");
3469 body.emit(assign(t, expr(ir_unop_trunc, x)));
3470 body.emit(assign(i, t));
3471 body.emit(ret(sub(x, t)));
3472
3473 return sig;
3474 }
3475
3476 ir_function_signature *
3477 builtin_builder::_min(builtin_available_predicate avail,
3478 const glsl_type *x_type, const glsl_type *y_type)
3479 {
3480 return binop(avail, ir_binop_min, x_type, x_type, y_type);
3481 }
3482
3483 ir_function_signature *
3484 builtin_builder::_max(builtin_available_predicate avail,
3485 const glsl_type *x_type, const glsl_type *y_type)
3486 {
3487 return binop(avail, ir_binop_max, x_type, x_type, y_type);
3488 }
3489
3490 ir_function_signature *
3491 builtin_builder::_clamp(builtin_available_predicate avail,
3492 const glsl_type *val_type, const glsl_type *bound_type)
3493 {
3494 ir_variable *x = in_var(val_type, "x");
3495 ir_variable *minVal = in_var(bound_type, "minVal");
3496 ir_variable *maxVal = in_var(bound_type, "maxVal");
3497 MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
3498
3499 body.emit(ret(clamp(x, minVal, maxVal)));
3500
3501 return sig;
3502 }
3503
3504 ir_function_signature *
3505 builtin_builder::_mix_lrp(builtin_available_predicate avail, const glsl_type *val_type, const glsl_type *blend_type)
3506 {
3507 ir_variable *x = in_var(val_type, "x");
3508 ir_variable *y = in_var(val_type, "y");
3509 ir_variable *a = in_var(blend_type, "a");
3510 MAKE_SIG(val_type, avail, 3, x, y, a);
3511
3512 body.emit(ret(lrp(x, y, a)));
3513
3514 return sig;
3515 }
3516
3517 ir_function_signature *
3518 builtin_builder::_mix_sel(builtin_available_predicate avail,
3519 const glsl_type *val_type,
3520 const glsl_type *blend_type)
3521 {
3522 ir_variable *x = in_var(val_type, "x");
3523 ir_variable *y = in_var(val_type, "y");
3524 ir_variable *a = in_var(blend_type, "a");
3525 MAKE_SIG(val_type, avail, 3, x, y, a);
3526
3527 /* csel matches the ternary operator in that a selector of true choses the
3528 * first argument. This differs from mix(x, y, false) which choses the
3529 * second argument (to remain consistent with the interpolating version of
3530 * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
3531 *
3532 * To handle the behavior mismatch, reverse the x and y arguments.
3533 */
3534 body.emit(ret(csel(a, y, x)));
3535
3536 return sig;
3537 }
3538
3539 ir_function_signature *
3540 builtin_builder::_step(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
3541 {
3542 ir_variable *edge = in_var(edge_type, "edge");
3543 ir_variable *x = in_var(x_type, "x");
3544 MAKE_SIG(x_type, avail, 2, edge, x);
3545
3546 ir_variable *t = body.make_temp(x_type, "t");
3547 if (x_type->vector_elements == 1) {
3548 /* Both are floats */
3549 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3550 body.emit(assign(t, f2d(b2f(gequal(x, edge)))));
3551 else
3552 body.emit(assign(t, b2f(gequal(x, edge))));
3553 } else if (edge_type->vector_elements == 1) {
3554 /* x is a vector but edge is a float */
3555 for (int i = 0; i < x_type->vector_elements; i++) {
3556 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3557 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), edge))), 1 << i));
3558 else
3559 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
3560 }
3561 } else {
3562 /* Both are vectors */
3563 for (int i = 0; i < x_type->vector_elements; i++) {
3564 if (edge_type->base_type == GLSL_TYPE_DOUBLE)
3565 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1)))),
3566 1 << i));
3567 else
3568 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
3569 1 << i));
3570
3571 }
3572 }
3573 body.emit(ret(t));
3574
3575 return sig;
3576 }
3577
3578 ir_function_signature *
3579 builtin_builder::_smoothstep(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
3580 {
3581 ir_variable *edge0 = in_var(edge_type, "edge0");
3582 ir_variable *edge1 = in_var(edge_type, "edge1");
3583 ir_variable *x = in_var(x_type, "x");
3584 MAKE_SIG(x_type, avail, 3, edge0, edge1, x);
3585
3586 /* From the GLSL 1.10 specification:
3587 *
3588 * genType t;
3589 * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
3590 * return t * t * (3 - 2 * t);
3591 */
3592
3593 ir_variable *t = body.make_temp(x_type, "t");
3594 body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
3595 IMM_FP(x_type, 0.0), IMM_FP(x_type, 1.0))));
3596
3597 body.emit(ret(mul(t, mul(t, sub(IMM_FP(x_type, 3.0), mul(IMM_FP(x_type, 2.0), t))))));
3598
3599 return sig;
3600 }
3601
3602 ir_function_signature *
3603 builtin_builder::_isnan(builtin_available_predicate avail, const glsl_type *type)
3604 {
3605 ir_variable *x = in_var(type, "x");
3606 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
3607
3608 body.emit(ret(nequal(x, x)));
3609
3610 return sig;
3611 }
3612
3613 ir_function_signature *
3614 builtin_builder::_isinf(builtin_available_predicate avail, const glsl_type *type)
3615 {
3616 ir_variable *x = in_var(type, "x");
3617 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
3618
3619 ir_constant_data infinities;
3620 for (int i = 0; i < type->vector_elements; i++) {
3621 switch (type->base_type) {
3622 case GLSL_TYPE_FLOAT:
3623 infinities.f[i] = INFINITY;
3624 break;
3625 case GLSL_TYPE_DOUBLE:
3626 infinities.d[i] = INFINITY;
3627 break;
3628 default:
3629 unreachable("unknown type");
3630 }
3631 }
3632
3633 body.emit(ret(equal(abs(x), imm(type, infinities))));
3634
3635 return sig;
3636 }
3637
3638 ir_function_signature *
3639 builtin_builder::_floatBitsToInt(const glsl_type *type)
3640 {
3641 ir_variable *x = in_var(type, "x");
3642 MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
3643 body.emit(ret(bitcast_f2i(x)));
3644 return sig;
3645 }
3646
3647 ir_function_signature *
3648 builtin_builder::_floatBitsToUint(const glsl_type *type)
3649 {
3650 ir_variable *x = in_var(type, "x");
3651 MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
3652 body.emit(ret(bitcast_f2u(x)));
3653 return sig;
3654 }
3655
3656 ir_function_signature *
3657 builtin_builder::_intBitsToFloat(const glsl_type *type)
3658 {
3659 ir_variable *x = in_var(type, "x");
3660 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
3661 body.emit(ret(bitcast_i2f(x)));
3662 return sig;
3663 }
3664
3665 ir_function_signature *
3666 builtin_builder::_uintBitsToFloat(const glsl_type *type)
3667 {
3668 ir_variable *x = in_var(type, "x");
3669 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
3670 body.emit(ret(bitcast_u2f(x)));
3671 return sig;
3672 }
3673
3674 ir_function_signature *
3675 builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
3676 {
3677 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3678 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3679 body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
3680 return sig;
3681 }
3682
3683 ir_function_signature *
3684 builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
3685 {
3686 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3687 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3688 body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
3689 return sig;
3690 }
3691
3692 ir_function_signature *
3693 builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
3694 {
3695 ir_variable *v = in_var(glsl_type::vec4_type, "v");
3696 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3697 body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
3698 return sig;
3699 }
3700
3701 ir_function_signature *
3702 builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
3703 {
3704 ir_variable *v = in_var(glsl_type::vec4_type, "v");
3705 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3706 body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
3707 return sig;
3708 }
3709
3710 ir_function_signature *
3711 builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
3712 {
3713 ir_variable *p = in_var(glsl_type::uint_type, "p");
3714 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3715 body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
3716 return sig;
3717 }
3718
3719 ir_function_signature *
3720 builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
3721 {
3722 ir_variable *p = in_var(glsl_type::uint_type, "p");
3723 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3724 body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
3725 return sig;
3726 }
3727
3728
3729 ir_function_signature *
3730 builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
3731 {
3732 ir_variable *p = in_var(glsl_type::uint_type, "p");
3733 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
3734 body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
3735 return sig;
3736 }
3737
3738 ir_function_signature *
3739 builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
3740 {
3741 ir_variable *p = in_var(glsl_type::uint_type, "p");
3742 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
3743 body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
3744 return sig;
3745 }
3746
3747 ir_function_signature *
3748 builtin_builder::_packHalf2x16(builtin_available_predicate avail)
3749 {
3750 ir_variable *v = in_var(glsl_type::vec2_type, "v");
3751 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
3752 body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
3753 return sig;
3754 }
3755
3756 ir_function_signature *
3757 builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
3758 {
3759 ir_variable *p = in_var(glsl_type::uint_type, "p");
3760 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
3761 body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
3762 return sig;
3763 }
3764
3765 ir_function_signature *
3766 builtin_builder::_packDouble2x32(builtin_available_predicate avail)
3767 {
3768 ir_variable *v = in_var(glsl_type::uvec2_type, "v");
3769 MAKE_SIG(glsl_type::double_type, avail, 1, v);
3770 body.emit(ret(expr(ir_unop_pack_double_2x32, v)));
3771 return sig;
3772 }
3773
3774 ir_function_signature *
3775 builtin_builder::_unpackDouble2x32(builtin_available_predicate avail)
3776 {
3777 ir_variable *p = in_var(glsl_type::double_type, "p");
3778 MAKE_SIG(glsl_type::uvec2_type, avail, 1, p);
3779 body.emit(ret(expr(ir_unop_unpack_double_2x32, p)));
3780 return sig;
3781 }
3782
3783 ir_function_signature *
3784 builtin_builder::_length(builtin_available_predicate avail, const glsl_type *type)
3785 {
3786 ir_variable *x = in_var(type, "x");
3787 MAKE_SIG(type->get_base_type(), avail, 1, x);
3788
3789 body.emit(ret(sqrt(dot(x, x))));
3790
3791 return sig;
3792 }
3793
3794 ir_function_signature *
3795 builtin_builder::_distance(builtin_available_predicate avail, const glsl_type *type)
3796 {
3797 ir_variable *p0 = in_var(type, "p0");
3798 ir_variable *p1 = in_var(type, "p1");
3799 MAKE_SIG(type->get_base_type(), avail, 2, p0, p1);
3800
3801 if (type->vector_elements == 1) {
3802 body.emit(ret(abs(sub(p0, p1))));
3803 } else {
3804 ir_variable *p = body.make_temp(type, "p");
3805 body.emit(assign(p, sub(p0, p1)));
3806 body.emit(ret(sqrt(dot(p, p))));
3807 }
3808
3809 return sig;
3810 }
3811
3812 ir_function_signature *
3813 builtin_builder::_dot(builtin_available_predicate avail, const glsl_type *type)
3814 {
3815 if (type->vector_elements == 1)
3816 return binop(avail, ir_binop_mul, type, type, type);
3817
3818 return binop(avail, ir_binop_dot,
3819 type->get_base_type(), type, type);
3820 }
3821
3822 ir_function_signature *
3823 builtin_builder::_cross(builtin_available_predicate avail, const glsl_type *type)
3824 {
3825 ir_variable *a = in_var(type, "a");
3826 ir_variable *b = in_var(type, "b");
3827 MAKE_SIG(type, avail, 2, a, b);
3828
3829 int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
3830 int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
3831
3832 body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
3833 mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
3834
3835 return sig;
3836 }
3837
3838 ir_function_signature *
3839 builtin_builder::_normalize(builtin_available_predicate avail, const glsl_type *type)
3840 {
3841 ir_variable *x = in_var(type, "x");
3842 MAKE_SIG(type, avail, 1, x);
3843
3844 if (type->vector_elements == 1) {
3845 body.emit(ret(sign(x)));
3846 } else {
3847 body.emit(ret(mul(x, rsq(dot(x, x)))));
3848 }
3849
3850 return sig;
3851 }
3852
3853 ir_function_signature *
3854 builtin_builder::_ftransform()
3855 {
3856 MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
3857
3858 body.emit(ret(new(mem_ctx) ir_expression(ir_binop_mul,
3859 glsl_type::vec4_type,
3860 var_ref(gl_ModelViewProjectionMatrix),
3861 var_ref(gl_Vertex))));
3862
3863 /* FINISHME: Once the ir_expression() constructor handles type inference
3864 * for matrix operations, we can simplify this to:
3865 *
3866 * body.emit(ret(mul(gl_ModelViewProjectionMatrix, gl_Vertex)));
3867 */
3868 return sig;
3869 }
3870
3871 ir_function_signature *
3872 builtin_builder::_faceforward(builtin_available_predicate avail, const glsl_type *type)
3873 {
3874 ir_variable *N = in_var(type, "N");
3875 ir_variable *I = in_var(type, "I");
3876 ir_variable *Nref = in_var(type, "Nref");
3877 MAKE_SIG(type, avail, 3, N, I, Nref);
3878
3879 body.emit(if_tree(less(dot(Nref, I), IMM_FP(type, 0.0)),
3880 ret(N), ret(neg(N))));
3881
3882 return sig;
3883 }
3884
3885 ir_function_signature *
3886 builtin_builder::_reflect(builtin_available_predicate avail, const glsl_type *type)
3887 {
3888 ir_variable *I = in_var(type, "I");
3889 ir_variable *N = in_var(type, "N");
3890 MAKE_SIG(type, avail, 2, I, N);
3891
3892 /* I - 2 * dot(N, I) * N */
3893 body.emit(ret(sub(I, mul(IMM_FP(type, 2.0), mul(dot(N, I), N)))));
3894
3895 return sig;
3896 }
3897
3898 ir_function_signature *
3899 builtin_builder::_refract(builtin_available_predicate avail, const glsl_type *type)
3900 {
3901 ir_variable *I = in_var(type, "I");
3902 ir_variable *N = in_var(type, "N");
3903 ir_variable *eta = in_var(type->get_base_type(), "eta");
3904 MAKE_SIG(type, avail, 3, I, N, eta);
3905
3906 ir_variable *n_dot_i = body.make_temp(type->get_base_type(), "n_dot_i");
3907 body.emit(assign(n_dot_i, dot(N, I)));
3908
3909 /* From the GLSL 1.10 specification:
3910 * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
3911 * if (k < 0.0)
3912 * return genType(0.0)
3913 * else
3914 * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
3915 */
3916 ir_variable *k = body.make_temp(type->get_base_type(), "k");
3917 body.emit(assign(k, sub(IMM_FP(type, 1.0),
3918 mul(eta, mul(eta, sub(IMM_FP(type, 1.0),
3919 mul(n_dot_i, n_dot_i)))))));
3920 body.emit(if_tree(less(k, IMM_FP(type, 0.0)),
3921 ret(ir_constant::zero(mem_ctx, type)),
3922 ret(sub(mul(eta, I),
3923 mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
3924
3925 return sig;
3926 }
3927
3928 ir_function_signature *
3929 builtin_builder::_matrixCompMult(builtin_available_predicate avail, const glsl_type *type)
3930 {
3931 ir_variable *x = in_var(type, "x");
3932 ir_variable *y = in_var(type, "y");
3933 MAKE_SIG(type, avail, 2, x, y);
3934
3935 ir_variable *z = body.make_temp(type, "z");
3936 for (int i = 0; i < type->matrix_columns; i++) {
3937 body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
3938 }
3939 body.emit(ret(z));
3940
3941 return sig;
3942 }
3943
3944 ir_function_signature *
3945 builtin_builder::_outerProduct(builtin_available_predicate avail, const glsl_type *type)
3946 {
3947 ir_variable *c;
3948 ir_variable *r;
3949
3950 if (type->base_type == GLSL_TYPE_DOUBLE) {
3951 r = in_var(glsl_type::dvec(type->matrix_columns), "r");
3952 c = in_var(glsl_type::dvec(type->vector_elements), "c");
3953 } else {
3954 r = in_var(glsl_type::vec(type->matrix_columns), "r");
3955 c = in_var(glsl_type::vec(type->vector_elements), "c");
3956 }
3957 MAKE_SIG(type, avail, 2, c, r);
3958
3959 ir_variable *m = body.make_temp(type, "m");
3960 for (int i = 0; i < type->matrix_columns; i++) {
3961 body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
3962 }
3963 body.emit(ret(m));
3964
3965 return sig;
3966 }
3967
3968 ir_function_signature *
3969 builtin_builder::_transpose(builtin_available_predicate avail, const glsl_type *orig_type)
3970 {
3971 const glsl_type *transpose_type =
3972 glsl_type::get_instance(orig_type->base_type,
3973 orig_type->matrix_columns,
3974 orig_type->vector_elements);
3975
3976 ir_variable *m = in_var(orig_type, "m");
3977 MAKE_SIG(transpose_type, avail, 1, m);
3978
3979 ir_variable *t = body.make_temp(transpose_type, "t");
3980 for (int i = 0; i < orig_type->matrix_columns; i++) {
3981 for (int j = 0; j < orig_type->vector_elements; j++) {
3982 body.emit(assign(array_ref(t, j),
3983 matrix_elt(m, i, j),
3984 1 << i));
3985 }
3986 }
3987 body.emit(ret(t));
3988
3989 return sig;
3990 }
3991
3992 ir_function_signature *
3993 builtin_builder::_determinant_mat2(builtin_available_predicate avail, const glsl_type *type)
3994 {
3995 ir_variable *m = in_var(type, "m");
3996 MAKE_SIG(type->get_base_type(), avail, 1, m);
3997
3998 body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
3999 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
4000
4001 return sig;
4002 }
4003
4004 ir_function_signature *
4005 builtin_builder::_determinant_mat3(builtin_available_predicate avail, const glsl_type *type)
4006 {
4007 ir_variable *m = in_var(type, "m");
4008 MAKE_SIG(type->get_base_type(), avail, 1, m);
4009
4010 ir_expression *f1 =
4011 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
4012 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
4013
4014 ir_expression *f2 =
4015 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
4016 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
4017
4018 ir_expression *f3 =
4019 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
4020 mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
4021
4022 body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
4023 mul(matrix_elt(m, 0, 1), f2)),
4024 mul(matrix_elt(m, 0, 2), f3))));
4025
4026 return sig;
4027 }
4028
4029 ir_function_signature *
4030 builtin_builder::_determinant_mat4(builtin_available_predicate avail, const glsl_type *type)
4031 {
4032 ir_variable *m = in_var(type, "m");
4033 const glsl_type *btype = type->get_base_type();
4034 MAKE_SIG(btype, avail, 1, m);
4035
4036 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
4037 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
4038 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
4039 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
4040 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
4041 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
4042 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
4043 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
4044 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
4045 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
4046 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
4047 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
4048 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
4049 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
4050 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
4051 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
4052 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
4053 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
4054 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
4055
4056 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)))));
4057 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)))));
4058 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)))));
4059 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)))));
4060 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)))));
4061 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)))));
4062 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)))));
4063 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)))));
4064 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)))));
4065 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)))));
4066 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)))));
4067 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)))));
4068 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)))));
4069 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)))));
4070 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)))));
4071 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)))));
4072 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)))));
4073 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)))));
4074 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)))));
4075
4076 ir_variable *adj_0 = body.make_temp(btype == glsl_type::float_type ? glsl_type::vec4_type : glsl_type::dvec4_type, "adj_0");
4077
4078 body.emit(assign(adj_0,
4079 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
4080 mul(matrix_elt(m, 1, 2), SubFactor01)),
4081 mul(matrix_elt(m, 1, 3), SubFactor02)),
4082 WRITEMASK_X));
4083 body.emit(assign(adj_0, neg(
4084 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
4085 mul(matrix_elt(m, 1, 2), SubFactor03)),
4086 mul(matrix_elt(m, 1, 3), SubFactor04))),
4087 WRITEMASK_Y));
4088 body.emit(assign(adj_0,
4089 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
4090 mul(matrix_elt(m, 1, 1), SubFactor03)),
4091 mul(matrix_elt(m, 1, 3), SubFactor05)),
4092 WRITEMASK_Z));
4093 body.emit(assign(adj_0, neg(
4094 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
4095 mul(matrix_elt(m, 1, 1), SubFactor04)),
4096 mul(matrix_elt(m, 1, 2), SubFactor05))),
4097 WRITEMASK_W));
4098
4099 body.emit(ret(dot(array_ref(m, 0), adj_0)));
4100
4101 return sig;
4102 }
4103
4104 ir_function_signature *
4105 builtin_builder::_inverse_mat2(builtin_available_predicate avail, const glsl_type *type)
4106 {
4107 ir_variable *m = in_var(type, "m");
4108 MAKE_SIG(type, avail, 1, m);
4109
4110 ir_variable *adj = body.make_temp(type, "adj");
4111 body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
4112 body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
4113 body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
4114 body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
4115
4116 ir_expression *det =
4117 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
4118 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
4119
4120 body.emit(ret(div(adj, det)));
4121 return sig;
4122 }
4123
4124 ir_function_signature *
4125 builtin_builder::_inverse_mat3(builtin_available_predicate avail, const glsl_type *type)
4126 {
4127 ir_variable *m = in_var(type, "m");
4128 const glsl_type *btype = type->get_base_type();
4129 MAKE_SIG(type, avail, 1, m);
4130
4131 ir_variable *f11_22_21_12 = body.make_temp(btype, "f11_22_21_12");
4132 ir_variable *f10_22_20_12 = body.make_temp(btype, "f10_22_20_12");
4133 ir_variable *f10_21_20_11 = body.make_temp(btype, "f10_21_20_11");
4134
4135 body.emit(assign(f11_22_21_12,
4136 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
4137 mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
4138 body.emit(assign(f10_22_20_12,
4139 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
4140 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
4141 body.emit(assign(f10_21_20_11,
4142 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
4143 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
4144
4145 ir_variable *adj = body.make_temp(type, "adj");
4146 body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
4147 body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
4148 body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
4149
4150 body.emit(assign(array_ref(adj, 0), neg(
4151 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
4152 mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
4153 WRITEMASK_Y));
4154 body.emit(assign(array_ref(adj, 1),
4155 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
4156 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
4157 WRITEMASK_Y));
4158 body.emit(assign(array_ref(adj, 2), neg(
4159 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
4160 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
4161 WRITEMASK_Y));
4162
4163 body.emit(assign(array_ref(adj, 0),
4164 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
4165 mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
4166 WRITEMASK_Z));
4167 body.emit(assign(array_ref(adj, 1), neg(
4168 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
4169 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
4170 WRITEMASK_Z));
4171 body.emit(assign(array_ref(adj, 2),
4172 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
4173 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
4174 WRITEMASK_Z));
4175
4176 ir_expression *det =
4177 add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
4178 mul(matrix_elt(m, 0, 1), f10_22_20_12)),
4179 mul(matrix_elt(m, 0, 2), f10_21_20_11));
4180
4181 body.emit(ret(div(adj, det)));
4182
4183 return sig;
4184 }
4185
4186 ir_function_signature *
4187 builtin_builder::_inverse_mat4(builtin_available_predicate avail, const glsl_type *type)
4188 {
4189 ir_variable *m = in_var(type, "m");
4190 const glsl_type *btype = type->get_base_type();
4191 MAKE_SIG(type, avail, 1, m);
4192
4193 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
4194 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
4195 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
4196 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
4197 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
4198 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
4199 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
4200 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
4201 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
4202 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
4203 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
4204 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
4205 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
4206 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
4207 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
4208 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
4209 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
4210 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
4211 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
4212
4213 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)))));
4214 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)))));
4215 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)))));
4216 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)))));
4217 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)))));
4218 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)))));
4219 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)))));
4220 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)))));
4221 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)))));
4222 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)))));
4223 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)))));
4224 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)))));
4225 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)))));
4226 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)))));
4227 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)))));
4228 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)))));
4229 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)))));
4230 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)))));
4231 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)))));
4232
4233 ir_variable *adj = body.make_temp(btype == glsl_type::float_type ? glsl_type::mat4_type : glsl_type::dmat4_type, "adj");
4234 body.emit(assign(array_ref(adj, 0),
4235 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
4236 mul(matrix_elt(m, 1, 2), SubFactor01)),
4237 mul(matrix_elt(m, 1, 3), SubFactor02)),
4238 WRITEMASK_X));
4239 body.emit(assign(array_ref(adj, 1), neg(
4240 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
4241 mul(matrix_elt(m, 1, 2), SubFactor03)),
4242 mul(matrix_elt(m, 1, 3), SubFactor04))),
4243 WRITEMASK_X));
4244 body.emit(assign(array_ref(adj, 2),
4245 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
4246 mul(matrix_elt(m, 1, 1), SubFactor03)),
4247 mul(matrix_elt(m, 1, 3), SubFactor05)),
4248 WRITEMASK_X));
4249 body.emit(assign(array_ref(adj, 3), neg(
4250 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
4251 mul(matrix_elt(m, 1, 1), SubFactor04)),
4252 mul(matrix_elt(m, 1, 2), SubFactor05))),
4253 WRITEMASK_X));
4254
4255 body.emit(assign(array_ref(adj, 0), neg(
4256 add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
4257 mul(matrix_elt(m, 0, 2), SubFactor01)),
4258 mul(matrix_elt(m, 0, 3), SubFactor02))),
4259 WRITEMASK_Y));
4260 body.emit(assign(array_ref(adj, 1),
4261 add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
4262 mul(matrix_elt(m, 0, 2), SubFactor03)),
4263 mul(matrix_elt(m, 0, 3), SubFactor04)),
4264 WRITEMASK_Y));
4265 body.emit(assign(array_ref(adj, 2), neg(
4266 add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
4267 mul(matrix_elt(m, 0, 1), SubFactor03)),
4268 mul(matrix_elt(m, 0, 3), SubFactor05))),
4269 WRITEMASK_Y));
4270 body.emit(assign(array_ref(adj, 3),
4271 add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
4272 mul(matrix_elt(m, 0, 1), SubFactor04)),
4273 mul(matrix_elt(m, 0, 2), SubFactor05)),
4274 WRITEMASK_Y));
4275
4276 body.emit(assign(array_ref(adj, 0),
4277 add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
4278 mul(matrix_elt(m, 0, 2), SubFactor07)),
4279 mul(matrix_elt(m, 0, 3), SubFactor08)),
4280 WRITEMASK_Z));
4281 body.emit(assign(array_ref(adj, 1), neg(
4282 add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
4283 mul(matrix_elt(m, 0, 2), SubFactor09)),
4284 mul(matrix_elt(m, 0, 3), SubFactor10))),
4285 WRITEMASK_Z));
4286 body.emit(assign(array_ref(adj, 2),
4287 add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
4288 mul(matrix_elt(m, 0, 1), SubFactor09)),
4289 mul(matrix_elt(m, 0, 3), SubFactor12)),
4290 WRITEMASK_Z));
4291 body.emit(assign(array_ref(adj, 3), neg(
4292 add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
4293 mul(matrix_elt(m, 0, 1), SubFactor10)),
4294 mul(matrix_elt(m, 0, 2), SubFactor12))),
4295 WRITEMASK_Z));
4296
4297 body.emit(assign(array_ref(adj, 0), neg(
4298 add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
4299 mul(matrix_elt(m, 0, 2), SubFactor14)),
4300 mul(matrix_elt(m, 0, 3), SubFactor15))),
4301 WRITEMASK_W));
4302 body.emit(assign(array_ref(adj, 1),
4303 add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
4304 mul(matrix_elt(m, 0, 2), SubFactor16)),
4305 mul(matrix_elt(m, 0, 3), SubFactor17)),
4306 WRITEMASK_W));
4307 body.emit(assign(array_ref(adj, 2), neg(
4308 add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
4309 mul(matrix_elt(m, 0, 1), SubFactor16)),
4310 mul(matrix_elt(m, 0, 3), SubFactor18))),
4311 WRITEMASK_W));
4312 body.emit(assign(array_ref(adj, 3),
4313 add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
4314 mul(matrix_elt(m, 0, 1), SubFactor17)),
4315 mul(matrix_elt(m, 0, 2), SubFactor18)),
4316 WRITEMASK_W));
4317
4318 ir_expression *det =
4319 add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
4320 add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
4321 add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
4322 mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
4323
4324 body.emit(ret(div(adj, det)));
4325
4326 return sig;
4327 }
4328
4329
4330 ir_function_signature *
4331 builtin_builder::_lessThan(builtin_available_predicate avail,
4332 const glsl_type *type)
4333 {
4334 return binop(avail, ir_binop_less,
4335 glsl_type::bvec(type->vector_elements), type, type);
4336 }
4337
4338 ir_function_signature *
4339 builtin_builder::_lessThanEqual(builtin_available_predicate avail,
4340 const glsl_type *type)
4341 {
4342 return binop(avail, ir_binop_lequal,
4343 glsl_type::bvec(type->vector_elements), type, type);
4344 }
4345
4346 ir_function_signature *
4347 builtin_builder::_greaterThan(builtin_available_predicate avail,
4348 const glsl_type *type)
4349 {
4350 return binop(avail, ir_binop_greater,
4351 glsl_type::bvec(type->vector_elements), type, type);
4352 }
4353
4354 ir_function_signature *
4355 builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
4356 const glsl_type *type)
4357 {
4358 return binop(avail, ir_binop_gequal,
4359 glsl_type::bvec(type->vector_elements), type, type);
4360 }
4361
4362 ir_function_signature *
4363 builtin_builder::_equal(builtin_available_predicate avail,
4364 const glsl_type *type)
4365 {
4366 return binop(avail, ir_binop_equal,
4367 glsl_type::bvec(type->vector_elements), type, type);
4368 }
4369
4370 ir_function_signature *
4371 builtin_builder::_notEqual(builtin_available_predicate avail,
4372 const glsl_type *type)
4373 {
4374 return binop(avail, ir_binop_nequal,
4375 glsl_type::bvec(type->vector_elements), type, type);
4376 }
4377
4378 ir_function_signature *
4379 builtin_builder::_any(const glsl_type *type)
4380 {
4381 ir_variable *v = in_var(type, "v");
4382 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
4383
4384 const unsigned vec_elem = v->type->vector_elements;
4385 body.emit(ret(expr(ir_binop_any_nequal, v, imm(false, vec_elem))));
4386
4387 return sig;
4388 }
4389
4390 ir_function_signature *
4391 builtin_builder::_all(const glsl_type *type)
4392 {
4393 ir_variable *v = in_var(type, "v");
4394 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
4395
4396 const unsigned vec_elem = v->type->vector_elements;
4397 body.emit(ret(expr(ir_binop_all_equal, v, imm(true, vec_elem))));
4398
4399 return sig;
4400 }
4401
4402 UNOP(not, ir_unop_logic_not, always_available)
4403
4404 static bool
4405 has_lod(const glsl_type *sampler_type)
4406 {
4407 assert(sampler_type->is_sampler());
4408
4409 switch (sampler_type->sampler_dimensionality) {
4410 case GLSL_SAMPLER_DIM_RECT:
4411 case GLSL_SAMPLER_DIM_BUF:
4412 case GLSL_SAMPLER_DIM_MS:
4413 return false;
4414 default:
4415 return true;
4416 }
4417 }
4418
4419 ir_function_signature *
4420 builtin_builder::_textureSize(builtin_available_predicate avail,
4421 const glsl_type *return_type,
4422 const glsl_type *sampler_type)
4423 {
4424 ir_variable *s = in_var(sampler_type, "sampler");
4425 /* The sampler always exists; add optional lod later. */
4426 MAKE_SIG(return_type, avail, 1, s);
4427
4428 ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
4429 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
4430
4431 if (has_lod(sampler_type)) {
4432 ir_variable *lod = in_var(glsl_type::int_type, "lod");
4433 sig->parameters.push_tail(lod);
4434 tex->lod_info.lod = var_ref(lod);
4435 } else {
4436 tex->lod_info.lod = imm(0u);
4437 }
4438
4439 body.emit(ret(tex));
4440
4441 return sig;
4442 }
4443
4444 ir_function_signature *
4445 builtin_builder::_textureSamples(const glsl_type *sampler_type)
4446 {
4447 ir_variable *s = in_var(sampler_type, "sampler");
4448 MAKE_SIG(glsl_type::int_type, shader_samples, 1, s);
4449
4450 ir_texture *tex = new(mem_ctx) ir_texture(ir_texture_samples);
4451 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), glsl_type::int_type);
4452 body.emit(ret(tex));
4453
4454 return sig;
4455 }
4456
4457 ir_function_signature *
4458 builtin_builder::_texture(ir_texture_opcode opcode,
4459 builtin_available_predicate avail,
4460 const glsl_type *return_type,
4461 const glsl_type *sampler_type,
4462 const glsl_type *coord_type,
4463 int flags)
4464 {
4465 ir_variable *s = in_var(sampler_type, "sampler");
4466 ir_variable *P = in_var(coord_type, "P");
4467 /* The sampler and coordinate always exist; add optional parameters later. */
4468 MAKE_SIG(return_type, avail, 2, s, P);
4469
4470 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
4471 tex->set_sampler(var_ref(s), return_type);
4472
4473 const int coord_size = sampler_type->coordinate_components();
4474
4475 if (coord_size == coord_type->vector_elements) {
4476 tex->coordinate = var_ref(P);
4477 } else {
4478 /* The incoming coordinate also has the projector or shadow comparitor,
4479 * so we need to swizzle those away.
4480 */
4481 tex->coordinate = swizzle_for_size(P, coord_size);
4482 }
4483
4484 /* The projector is always in the last component. */
4485 if (flags & TEX_PROJECT)
4486 tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
4487
4488 if (sampler_type->sampler_shadow) {
4489 if (opcode == ir_tg4) {
4490 /* gather has refz as a separate parameter, immediately after the
4491 * coordinate
4492 */
4493 ir_variable *refz = in_var(glsl_type::float_type, "refz");
4494 sig->parameters.push_tail(refz);
4495 tex->shadow_comparitor = var_ref(refz);
4496 } else {
4497 /* The shadow comparitor is normally in the Z component, but a few types
4498 * have sufficiently large coordinates that it's in W.
4499 */
4500 tex->shadow_comparitor = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
4501 }
4502 }
4503
4504 if (opcode == ir_txl) {
4505 ir_variable *lod = in_var(glsl_type::float_type, "lod");
4506 sig->parameters.push_tail(lod);
4507 tex->lod_info.lod = var_ref(lod);
4508 } else if (opcode == ir_txd) {
4509 int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
4510 ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
4511 ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
4512 sig->parameters.push_tail(dPdx);
4513 sig->parameters.push_tail(dPdy);
4514 tex->lod_info.grad.dPdx = var_ref(dPdx);
4515 tex->lod_info.grad.dPdy = var_ref(dPdy);
4516 }
4517
4518 if (flags & (TEX_OFFSET | TEX_OFFSET_NONCONST)) {
4519 int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
4520 ir_variable *offset =
4521 new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset",
4522 (flags & TEX_OFFSET) ? ir_var_const_in : ir_var_function_in);
4523 sig->parameters.push_tail(offset);
4524 tex->offset = var_ref(offset);
4525 }
4526
4527 if (flags & TEX_OFFSET_ARRAY) {
4528 ir_variable *offsets =
4529 new(mem_ctx) ir_variable(glsl_type::get_array_instance(glsl_type::ivec2_type, 4),
4530 "offsets", ir_var_const_in);
4531 sig->parameters.push_tail(offsets);
4532 tex->offset = var_ref(offsets);
4533 }
4534
4535 if (opcode == ir_tg4) {
4536 if (flags & TEX_COMPONENT) {
4537 ir_variable *component =
4538 new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in);
4539 sig->parameters.push_tail(component);
4540 tex->lod_info.component = var_ref(component);
4541 }
4542 else {
4543 tex->lod_info.component = imm(0);
4544 }
4545 }
4546
4547 /* The "bias" parameter comes /after/ the "offset" parameter, which is
4548 * inconsistent with both textureLodOffset and textureGradOffset.
4549 */
4550 if (opcode == ir_txb) {
4551 ir_variable *bias = in_var(glsl_type::float_type, "bias");
4552 sig->parameters.push_tail(bias);
4553 tex->lod_info.bias = var_ref(bias);
4554 }
4555
4556 body.emit(ret(tex));
4557
4558 return sig;
4559 }
4560
4561 ir_function_signature *
4562 builtin_builder::_textureCubeArrayShadow()
4563 {
4564 ir_variable *s = in_var(glsl_type::samplerCubeArrayShadow_type, "sampler");
4565 ir_variable *P = in_var(glsl_type::vec4_type, "P");
4566 ir_variable *compare = in_var(glsl_type::float_type, "compare");
4567 MAKE_SIG(glsl_type::float_type, texture_cube_map_array, 3, s, P, compare);
4568
4569 ir_texture *tex = new(mem_ctx) ir_texture(ir_tex);
4570 tex->set_sampler(var_ref(s), glsl_type::float_type);
4571
4572 tex->coordinate = var_ref(P);
4573 tex->shadow_comparitor = var_ref(compare);
4574
4575 body.emit(ret(tex));
4576
4577 return sig;
4578 }
4579
4580 ir_function_signature *
4581 builtin_builder::_texelFetch(builtin_available_predicate avail,
4582 const glsl_type *return_type,
4583 const glsl_type *sampler_type,
4584 const glsl_type *coord_type,
4585 const glsl_type *offset_type)
4586 {
4587 ir_variable *s = in_var(sampler_type, "sampler");
4588 ir_variable *P = in_var(coord_type, "P");
4589 /* The sampler and coordinate always exist; add optional parameters later. */
4590 MAKE_SIG(return_type, avail, 2, s, P);
4591
4592 ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
4593 tex->coordinate = var_ref(P);
4594 tex->set_sampler(var_ref(s), return_type);
4595
4596 if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
4597 ir_variable *sample = in_var(glsl_type::int_type, "sample");
4598 sig->parameters.push_tail(sample);
4599 tex->lod_info.sample_index = var_ref(sample);
4600 tex->op = ir_txf_ms;
4601 } else if (has_lod(sampler_type)) {
4602 ir_variable *lod = in_var(glsl_type::int_type, "lod");
4603 sig->parameters.push_tail(lod);
4604 tex->lod_info.lod = var_ref(lod);
4605 } else {
4606 tex->lod_info.lod = imm(0u);
4607 }
4608
4609 if (offset_type != NULL) {
4610 ir_variable *offset =
4611 new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in);
4612 sig->parameters.push_tail(offset);
4613 tex->offset = var_ref(offset);
4614 }
4615
4616 body.emit(ret(tex));
4617
4618 return sig;
4619 }
4620
4621 ir_function_signature *
4622 builtin_builder::_EmitVertex()
4623 {
4624 MAKE_SIG(glsl_type::void_type, gs_only, 0);
4625
4626 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
4627 body.emit(new(mem_ctx) ir_emit_vertex(stream));
4628
4629 return sig;
4630 }
4631
4632 ir_function_signature *
4633 builtin_builder::_EmitStreamVertex(builtin_available_predicate avail,
4634 const glsl_type *stream_type)
4635 {
4636 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
4637 *
4638 * "Emit the current values of output variables to the current output
4639 * primitive on stream stream. The argument to stream must be a constant
4640 * integral expression."
4641 */
4642 ir_variable *stream =
4643 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
4644
4645 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
4646
4647 body.emit(new(mem_ctx) ir_emit_vertex(var_ref(stream)));
4648
4649 return sig;
4650 }
4651
4652 ir_function_signature *
4653 builtin_builder::_EndPrimitive()
4654 {
4655 MAKE_SIG(glsl_type::void_type, gs_only, 0);
4656
4657 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
4658 body.emit(new(mem_ctx) ir_end_primitive(stream));
4659
4660 return sig;
4661 }
4662
4663 ir_function_signature *
4664 builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
4665 const glsl_type *stream_type)
4666 {
4667 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
4668 *
4669 * "Completes the current output primitive on stream stream and starts
4670 * a new one. The argument to stream must be a constant integral
4671 * expression."
4672 */
4673 ir_variable *stream =
4674 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
4675
4676 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
4677
4678 body.emit(new(mem_ctx) ir_end_primitive(var_ref(stream)));
4679
4680 return sig;
4681 }
4682
4683 ir_function_signature *
4684 builtin_builder::_barrier()
4685 {
4686 MAKE_SIG(glsl_type::void_type, barrier_supported, 0);
4687
4688 body.emit(new(mem_ctx) ir_barrier());
4689 return sig;
4690 }
4691
4692 ir_function_signature *
4693 builtin_builder::_textureQueryLod(builtin_available_predicate avail,
4694 const glsl_type *sampler_type,
4695 const glsl_type *coord_type)
4696 {
4697 ir_variable *s = in_var(sampler_type, "sampler");
4698 ir_variable *coord = in_var(coord_type, "coord");
4699 /* The sampler and coordinate always exist; add optional parameters later. */
4700 MAKE_SIG(glsl_type::vec2_type, avail, 2, s, coord);
4701
4702 ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
4703 tex->coordinate = var_ref(coord);
4704 tex->set_sampler(var_ref(s), glsl_type::vec2_type);
4705
4706 body.emit(ret(tex));
4707
4708 return sig;
4709 }
4710
4711 ir_function_signature *
4712 builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
4713 {
4714 ir_variable *s = in_var(sampler_type, "sampler");
4715 const glsl_type *return_type = glsl_type::int_type;
4716 MAKE_SIG(return_type, texture_query_levels, 1, s);
4717
4718 ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
4719 tex->set_sampler(var_ref(s), return_type);
4720
4721 body.emit(ret(tex));
4722
4723 return sig;
4724 }
4725
4726 ir_function_signature *
4727 builtin_builder::_textureSamplesIdentical(builtin_available_predicate avail,
4728 const glsl_type *sampler_type,
4729 const glsl_type *coord_type)
4730 {
4731 ir_variable *s = in_var(sampler_type, "sampler");
4732 ir_variable *P = in_var(coord_type, "P");
4733 const glsl_type *return_type = glsl_type::bool_type;
4734 MAKE_SIG(return_type, avail, 2, s, P);
4735
4736 ir_texture *tex = new(mem_ctx) ir_texture(ir_samples_identical);
4737 tex->coordinate = var_ref(P);
4738 tex->set_sampler(var_ref(s), return_type);
4739
4740 body.emit(ret(tex));
4741
4742 return sig;
4743 }
4744
4745 UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
4746 UNOP(dFdxCoarse, ir_unop_dFdx_coarse, fs_derivative_control)
4747 UNOP(dFdxFine, ir_unop_dFdx_fine, fs_derivative_control)
4748 UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
4749 UNOP(dFdyCoarse, ir_unop_dFdy_coarse, fs_derivative_control)
4750 UNOP(dFdyFine, ir_unop_dFdy_fine, fs_derivative_control)
4751
4752 ir_function_signature *
4753 builtin_builder::_fwidth(const glsl_type *type)
4754 {
4755 ir_variable *p = in_var(type, "p");
4756 MAKE_SIG(type, fs_oes_derivatives, 1, p);
4757
4758 body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
4759
4760 return sig;
4761 }
4762
4763 ir_function_signature *
4764 builtin_builder::_fwidthCoarse(const glsl_type *type)
4765 {
4766 ir_variable *p = in_var(type, "p");
4767 MAKE_SIG(type, fs_derivative_control, 1, p);
4768
4769 body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
4770 abs(expr(ir_unop_dFdy_coarse, p)))));
4771
4772 return sig;
4773 }
4774
4775 ir_function_signature *
4776 builtin_builder::_fwidthFine(const glsl_type *type)
4777 {
4778 ir_variable *p = in_var(type, "p");
4779 MAKE_SIG(type, fs_derivative_control, 1, p);
4780
4781 body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
4782 abs(expr(ir_unop_dFdy_fine, p)))));
4783
4784 return sig;
4785 }
4786
4787 ir_function_signature *
4788 builtin_builder::_noise1(const glsl_type *type)
4789 {
4790 return unop(v110, ir_unop_noise, glsl_type::float_type, type);
4791 }
4792
4793 ir_function_signature *
4794 builtin_builder::_noise2(const glsl_type *type)
4795 {
4796 ir_variable *p = in_var(type, "p");
4797 MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
4798
4799 ir_constant_data b_offset;
4800 b_offset.f[0] = 601.0f;
4801 b_offset.f[1] = 313.0f;
4802 b_offset.f[2] = 29.0f;
4803 b_offset.f[3] = 277.0f;
4804
4805 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4806 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4807 ir_variable *t = body.make_temp(glsl_type::vec2_type, "t");
4808 body.emit(assign(a, expr(ir_unop_noise, p)));
4809 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
4810 body.emit(assign(t, a, WRITEMASK_X));
4811 body.emit(assign(t, b, WRITEMASK_Y));
4812 body.emit(ret(t));
4813
4814 return sig;
4815 }
4816
4817 ir_function_signature *
4818 builtin_builder::_noise3(const glsl_type *type)
4819 {
4820 ir_variable *p = in_var(type, "p");
4821 MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
4822
4823 ir_constant_data b_offset;
4824 b_offset.f[0] = 601.0f;
4825 b_offset.f[1] = 313.0f;
4826 b_offset.f[2] = 29.0f;
4827 b_offset.f[3] = 277.0f;
4828
4829 ir_constant_data c_offset;
4830 c_offset.f[0] = 1559.0f;
4831 c_offset.f[1] = 113.0f;
4832 c_offset.f[2] = 1861.0f;
4833 c_offset.f[3] = 797.0f;
4834
4835 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4836 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4837 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
4838 ir_variable *t = body.make_temp(glsl_type::vec3_type, "t");
4839 body.emit(assign(a, expr(ir_unop_noise, p)));
4840 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
4841 body.emit(assign(c, expr(ir_unop_noise, add(p, imm(type, c_offset)))));
4842 body.emit(assign(t, a, WRITEMASK_X));
4843 body.emit(assign(t, b, WRITEMASK_Y));
4844 body.emit(assign(t, c, WRITEMASK_Z));
4845 body.emit(ret(t));
4846
4847 return sig;
4848 }
4849
4850 ir_function_signature *
4851 builtin_builder::_noise4(const glsl_type *type)
4852 {
4853 ir_variable *p = in_var(type, "p");
4854 MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
4855
4856 ir_variable *_p = body.make_temp(type, "_p");
4857
4858 ir_constant_data p_offset;
4859 p_offset.f[0] = 1559.0f;
4860 p_offset.f[1] = 113.0f;
4861 p_offset.f[2] = 1861.0f;
4862 p_offset.f[3] = 797.0f;
4863
4864 body.emit(assign(_p, add(p, imm(type, p_offset))));
4865
4866 ir_constant_data offset;
4867 offset.f[0] = 601.0f;
4868 offset.f[1] = 313.0f;
4869 offset.f[2] = 29.0f;
4870 offset.f[3] = 277.0f;
4871
4872 ir_variable *a = body.make_temp(glsl_type::float_type, "a");
4873 ir_variable *b = body.make_temp(glsl_type::float_type, "b");
4874 ir_variable *c = body.make_temp(glsl_type::float_type, "c");
4875 ir_variable *d = body.make_temp(glsl_type::float_type, "d");
4876 ir_variable *t = body.make_temp(glsl_type::vec4_type, "t");
4877 body.emit(assign(a, expr(ir_unop_noise, p)));
4878 body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, offset)))));
4879 body.emit(assign(c, expr(ir_unop_noise, _p)));
4880 body.emit(assign(d, expr(ir_unop_noise, add(_p, imm(type, offset)))));
4881 body.emit(assign(t, a, WRITEMASK_X));
4882 body.emit(assign(t, b, WRITEMASK_Y));
4883 body.emit(assign(t, c, WRITEMASK_Z));
4884 body.emit(assign(t, d, WRITEMASK_W));
4885 body.emit(ret(t));
4886
4887 return sig;
4888 }
4889
4890 ir_function_signature *
4891 builtin_builder::_bitfieldExtract(const glsl_type *type)
4892 {
4893 bool is_uint = type->base_type == GLSL_TYPE_UINT;
4894 ir_variable *value = in_var(type, "value");
4895 ir_variable *offset = in_var(glsl_type::int_type, "offset");
4896 ir_variable *bits = in_var(glsl_type::int_type, "bits");
4897 MAKE_SIG(type, gpu_shader5_or_es31, 3, value, offset, bits);
4898
4899 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
4900 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
4901
4902 body.emit(ret(expr(ir_triop_bitfield_extract, value,
4903 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
4904 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
4905
4906 return sig;
4907 }
4908
4909 ir_function_signature *
4910 builtin_builder::_bitfieldInsert(const glsl_type *type)
4911 {
4912 bool is_uint = type->base_type == GLSL_TYPE_UINT;
4913 ir_variable *base = in_var(type, "base");
4914 ir_variable *insert = in_var(type, "insert");
4915 ir_variable *offset = in_var(glsl_type::int_type, "offset");
4916 ir_variable *bits = in_var(glsl_type::int_type, "bits");
4917 MAKE_SIG(type, gpu_shader5_or_es31, 4, base, insert, offset, bits);
4918
4919 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
4920 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
4921
4922 body.emit(ret(bitfield_insert(base, insert,
4923 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
4924 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
4925
4926 return sig;
4927 }
4928
4929 UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5_or_es31)
4930
4931 ir_function_signature *
4932 builtin_builder::_bitCount(const glsl_type *type)
4933 {
4934 return unop(gpu_shader5_or_es31, ir_unop_bit_count,
4935 glsl_type::ivec(type->vector_elements), type);
4936 }
4937
4938 ir_function_signature *
4939 builtin_builder::_findLSB(const glsl_type *type)
4940 {
4941 return unop(gpu_shader5_or_es31, ir_unop_find_lsb,
4942 glsl_type::ivec(type->vector_elements), type);
4943 }
4944
4945 ir_function_signature *
4946 builtin_builder::_findMSB(const glsl_type *type)
4947 {
4948 return unop(gpu_shader5_or_es31, ir_unop_find_msb,
4949 glsl_type::ivec(type->vector_elements), type);
4950 }
4951
4952 ir_function_signature *
4953 builtin_builder::_fma(builtin_available_predicate avail, const glsl_type *type)
4954 {
4955 ir_variable *a = in_var(type, "a");
4956 ir_variable *b = in_var(type, "b");
4957 ir_variable *c = in_var(type, "c");
4958 MAKE_SIG(type, avail, 3, a, b, c);
4959
4960 body.emit(ret(ir_builder::fma(a, b, c)));
4961
4962 return sig;
4963 }
4964
4965 ir_function_signature *
4966 builtin_builder::_ldexp(const glsl_type *x_type, const glsl_type *exp_type)
4967 {
4968 return binop(x_type->base_type == GLSL_TYPE_DOUBLE ? fp64 : gpu_shader5_or_es31,
4969 ir_binop_ldexp, x_type, x_type, exp_type);
4970 }
4971
4972 ir_function_signature *
4973 builtin_builder::_dfrexp(const glsl_type *x_type, const glsl_type *exp_type)
4974 {
4975 ir_variable *x = in_var(x_type, "x");
4976 ir_variable *exponent = out_var(exp_type, "exp");
4977 MAKE_SIG(x_type, fp64, 2, x, exponent);
4978
4979 body.emit(assign(exponent, expr(ir_unop_frexp_exp, x)));
4980
4981 body.emit(ret(expr(ir_unop_frexp_sig, x)));
4982 return sig;
4983 }
4984
4985 ir_function_signature *
4986 builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
4987 {
4988 ir_variable *x = in_var(x_type, "x");
4989 ir_variable *exponent = out_var(exp_type, "exp");
4990 MAKE_SIG(x_type, gpu_shader5_or_es31, 2, x, exponent);
4991
4992 const unsigned vec_elem = x_type->vector_elements;
4993 const glsl_type *bvec = glsl_type::get_instance(GLSL_TYPE_BOOL, vec_elem, 1);
4994 const glsl_type *uvec = glsl_type::get_instance(GLSL_TYPE_UINT, vec_elem, 1);
4995
4996 /* Single-precision floating-point values are stored as
4997 * 1 sign bit;
4998 * 8 exponent bits;
4999 * 23 mantissa bits.
5000 *
5001 * An exponent shift of 23 will shift the mantissa out, leaving only the
5002 * exponent and sign bit (which itself may be zero, if the absolute value
5003 * was taken before the bitcast and shift.
5004 */
5005 ir_constant *exponent_shift = imm(23);
5006 ir_constant *exponent_bias = imm(-126, vec_elem);
5007
5008 ir_constant *sign_mantissa_mask = imm(0x807fffffu, vec_elem);
5009
5010 /* Exponent of floating-point values in the range [0.5, 1.0). */
5011 ir_constant *exponent_value = imm(0x3f000000u, vec_elem);
5012
5013 ir_variable *is_not_zero = body.make_temp(bvec, "is_not_zero");
5014 body.emit(assign(is_not_zero, nequal(abs(x), imm(0.0f, vec_elem))));
5015
5016 /* Since abs(x) ensures that the sign bit is zero, we don't need to bitcast
5017 * to unsigned integers to ensure that 1 bits aren't shifted in.
5018 */
5019 body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
5020 body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
5021 imm(0, vec_elem)))));
5022
5023 ir_variable *bits = body.make_temp(uvec, "bits");
5024 body.emit(assign(bits, bitcast_f2u(x)));
5025 body.emit(assign(bits, bit_and(bits, sign_mantissa_mask)));
5026 body.emit(assign(bits, bit_or(bits, csel(is_not_zero, exponent_value,
5027 imm(0u, vec_elem)))));
5028 body.emit(ret(bitcast_u2f(bits)));
5029
5030 return sig;
5031 }
5032
5033 ir_function_signature *
5034 builtin_builder::_uaddCarry(const glsl_type *type)
5035 {
5036 ir_variable *x = in_var(type, "x");
5037 ir_variable *y = in_var(type, "y");
5038 ir_variable *carry = out_var(type, "carry");
5039 MAKE_SIG(type, gpu_shader5_or_es31, 3, x, y, carry);
5040
5041 body.emit(assign(carry, ir_builder::carry(x, y)));
5042 body.emit(ret(add(x, y)));
5043
5044 return sig;
5045 }
5046
5047 ir_function_signature *
5048 builtin_builder::_usubBorrow(const glsl_type *type)
5049 {
5050 ir_variable *x = in_var(type, "x");
5051 ir_variable *y = in_var(type, "y");
5052 ir_variable *borrow = out_var(type, "borrow");
5053 MAKE_SIG(type, gpu_shader5_or_es31, 3, x, y, borrow);
5054
5055 body.emit(assign(borrow, ir_builder::borrow(x, y)));
5056 body.emit(ret(sub(x, y)));
5057
5058 return sig;
5059 }
5060
5061 /**
5062 * For both imulExtended() and umulExtended() built-ins.
5063 */
5064 ir_function_signature *
5065 builtin_builder::_mulExtended(const glsl_type *type)
5066 {
5067 ir_variable *x = in_var(type, "x");
5068 ir_variable *y = in_var(type, "y");
5069 ir_variable *msb = out_var(type, "msb");
5070 ir_variable *lsb = out_var(type, "lsb");
5071 MAKE_SIG(glsl_type::void_type, gpu_shader5_or_es31, 4, x, y, msb, lsb);
5072
5073 body.emit(assign(msb, imul_high(x, y)));
5074 body.emit(assign(lsb, mul(x, y)));
5075
5076 return sig;
5077 }
5078
5079 ir_function_signature *
5080 builtin_builder::_interpolateAtCentroid(const glsl_type *type)
5081 {
5082 ir_variable *interpolant = in_var(type, "interpolant");
5083 interpolant->data.must_be_shader_input = 1;
5084 MAKE_SIG(type, fs_gpu_shader5, 1, interpolant);
5085
5086 body.emit(ret(interpolate_at_centroid(interpolant)));
5087
5088 return sig;
5089 }
5090
5091 ir_function_signature *
5092 builtin_builder::_interpolateAtOffset(const glsl_type *type)
5093 {
5094 ir_variable *interpolant = in_var(type, "interpolant");
5095 interpolant->data.must_be_shader_input = 1;
5096 ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
5097 MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, offset);
5098
5099 body.emit(ret(interpolate_at_offset(interpolant, offset)));
5100
5101 return sig;
5102 }
5103
5104 ir_function_signature *
5105 builtin_builder::_interpolateAtSample(const glsl_type *type)
5106 {
5107 ir_variable *interpolant = in_var(type, "interpolant");
5108 interpolant->data.must_be_shader_input = 1;
5109 ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
5110 MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, sample_num);
5111
5112 body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
5113
5114 return sig;
5115 }
5116
5117 ir_function_signature *
5118 builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail)
5119 {
5120 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
5121 MAKE_INTRINSIC(glsl_type::uint_type, avail, 1, counter);
5122 return sig;
5123 }
5124
5125 ir_function_signature *
5126 builtin_builder::_atomic_intrinsic2(builtin_available_predicate avail,
5127 const glsl_type *type)
5128 {
5129 ir_variable *atomic = in_var(type, "atomic");
5130 ir_variable *data = in_var(type, "data");
5131 MAKE_INTRINSIC(type, avail, 2, atomic, data);
5132 return sig;
5133 }
5134
5135 ir_function_signature *
5136 builtin_builder::_atomic_intrinsic3(builtin_available_predicate avail,
5137 const glsl_type *type)
5138 {
5139 ir_variable *atomic = in_var(type, "atomic");
5140 ir_variable *data1 = in_var(type, "data1");
5141 ir_variable *data2 = in_var(type, "data2");
5142 MAKE_INTRINSIC(type, avail, 3, atomic, data1, data2);
5143 return sig;
5144 }
5145
5146 ir_function_signature *
5147 builtin_builder::_atomic_counter_op(const char *intrinsic,
5148 builtin_available_predicate avail)
5149 {
5150 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
5151 MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
5152
5153 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
5154 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5155 sig->parameters));
5156 body.emit(ret(retval));
5157 return sig;
5158 }
5159
5160 ir_function_signature *
5161 builtin_builder::_atomic_op2(const char *intrinsic,
5162 builtin_available_predicate avail,
5163 const glsl_type *type)
5164 {
5165 ir_variable *atomic = in_var(type, "atomic_var");
5166 ir_variable *data = in_var(type, "atomic_data");
5167 MAKE_SIG(type, avail, 2, atomic, data);
5168
5169 ir_variable *retval = body.make_temp(type, "atomic_retval");
5170 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5171 sig->parameters));
5172 body.emit(ret(retval));
5173 return sig;
5174 }
5175
5176 ir_function_signature *
5177 builtin_builder::_atomic_op3(const char *intrinsic,
5178 builtin_available_predicate avail,
5179 const glsl_type *type)
5180 {
5181 ir_variable *atomic = in_var(type, "atomic_var");
5182 ir_variable *data1 = in_var(type, "atomic_data1");
5183 ir_variable *data2 = in_var(type, "atomic_data2");
5184 MAKE_SIG(type, avail, 3, atomic, data1, data2);
5185
5186 ir_variable *retval = body.make_temp(type, "atomic_retval");
5187 body.emit(call(shader->symbols->get_function(intrinsic), retval,
5188 sig->parameters));
5189 body.emit(ret(retval));
5190 return sig;
5191 }
5192
5193 ir_function_signature *
5194 builtin_builder::_min3(const glsl_type *type)
5195 {
5196 ir_variable *x = in_var(type, "x");
5197 ir_variable *y = in_var(type, "y");
5198 ir_variable *z = in_var(type, "z");
5199 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5200
5201 ir_expression *min3 = min2(x, min2(y,z));
5202 body.emit(ret(min3));
5203
5204 return sig;
5205 }
5206
5207 ir_function_signature *
5208 builtin_builder::_max3(const glsl_type *type)
5209 {
5210 ir_variable *x = in_var(type, "x");
5211 ir_variable *y = in_var(type, "y");
5212 ir_variable *z = in_var(type, "z");
5213 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5214
5215 ir_expression *max3 = max2(x, max2(y,z));
5216 body.emit(ret(max3));
5217
5218 return sig;
5219 }
5220
5221 ir_function_signature *
5222 builtin_builder::_mid3(const glsl_type *type)
5223 {
5224 ir_variable *x = in_var(type, "x");
5225 ir_variable *y = in_var(type, "y");
5226 ir_variable *z = in_var(type, "z");
5227 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
5228
5229 ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
5230 body.emit(ret(mid3));
5231
5232 return sig;
5233 }
5234
5235 ir_function_signature *
5236 builtin_builder::_image_prototype(const glsl_type *image_type,
5237 unsigned num_arguments,
5238 unsigned flags)
5239 {
5240 const glsl_type *data_type = glsl_type::get_instance(
5241 image_type->sampler_type,
5242 (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
5243 1);
5244 const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
5245 glsl_type::void_type : data_type);
5246
5247 /* Addressing arguments that are always present. */
5248 ir_variable *image = in_var(image_type, "image");
5249 ir_variable *coord = in_var(
5250 glsl_type::ivec(image_type->coordinate_components()), "coord");
5251
5252 const builtin_available_predicate avail =
5253 (flags & IMAGE_FUNCTION_AVAIL_ATOMIC ? shader_image_atomic :
5254 shader_image_load_store);
5255 ir_function_signature *sig = new_sig(ret_type, avail, 2, image, coord);
5256
5257 /* Sample index for multisample images. */
5258 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
5259 sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
5260
5261 /* Data arguments. */
5262 for (unsigned i = 0; i < num_arguments; ++i) {
5263 char *arg_name = ralloc_asprintf(NULL, "arg%d", i);
5264 sig->parameters.push_tail(in_var(data_type, arg_name));
5265 ralloc_free(arg_name);
5266 }
5267
5268 /* Set the maximal set of qualifiers allowed for this image
5269 * built-in. Function calls with arguments having fewer
5270 * qualifiers than present in the prototype are allowed by the
5271 * spec, but not with more, i.e. this will make the compiler
5272 * accept everything that needs to be accepted, and reject cases
5273 * like loads from write-only or stores to read-only images.
5274 */
5275 image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
5276 image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
5277 image->data.image_coherent = true;
5278 image->data.image_volatile = true;
5279 image->data.image_restrict = true;
5280
5281 return sig;
5282 }
5283
5284 ir_function_signature *
5285 builtin_builder::_image_size_prototype(const glsl_type *image_type,
5286 unsigned /* num_arguments */,
5287 unsigned /* flags */)
5288 {
5289 const glsl_type *ret_type;
5290 unsigned num_components = image_type->coordinate_components();
5291
5292 /* From the ARB_shader_image_size extension:
5293 * "Cube images return the dimensions of one face."
5294 */
5295 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE &&
5296 !image_type->sampler_array) {
5297 num_components = 2;
5298 }
5299
5300 /* FIXME: Add the highp precision qualifier for GLES 3.10 when it is
5301 * supported by mesa.
5302 */
5303 ret_type = glsl_type::get_instance(GLSL_TYPE_INT, num_components, 1);
5304
5305 ir_variable *image = in_var(image_type, "image");
5306 ir_function_signature *sig = new_sig(ret_type, shader_image_size, 1, image);
5307
5308 /* Set the maximal set of qualifiers allowed for this image
5309 * built-in. Function calls with arguments having fewer
5310 * qualifiers than present in the prototype are allowed by the
5311 * spec, but not with more, i.e. this will make the compiler
5312 * accept everything that needs to be accepted, and reject cases
5313 * like loads from write-only or stores to read-only images.
5314 */
5315 image->data.image_read_only = true;
5316 image->data.image_write_only = true;
5317 image->data.image_coherent = true;
5318 image->data.image_volatile = true;
5319 image->data.image_restrict = true;
5320
5321 return sig;
5322 }
5323
5324 ir_function_signature *
5325 builtin_builder::_image_samples_prototype(const glsl_type *image_type,
5326 unsigned /* num_arguments */,
5327 unsigned /* flags */)
5328 {
5329 ir_variable *image = in_var(image_type, "image");
5330 ir_function_signature *sig =
5331 new_sig(glsl_type::int_type, shader_samples, 1, image);
5332
5333 /* Set the maximal set of qualifiers allowed for this image
5334 * built-in. Function calls with arguments having fewer
5335 * qualifiers than present in the prototype are allowed by the
5336 * spec, but not with more, i.e. this will make the compiler
5337 * accept everything that needs to be accepted, and reject cases
5338 * like loads from write-only or stores to read-only images.
5339 */
5340 image->data.image_read_only = true;
5341 image->data.image_write_only = true;
5342 image->data.image_coherent = true;
5343 image->data.image_volatile = true;
5344 image->data.image_restrict = true;
5345
5346 return sig;
5347 }
5348
5349 ir_function_signature *
5350 builtin_builder::_image(image_prototype_ctr prototype,
5351 const glsl_type *image_type,
5352 const char *intrinsic_name,
5353 unsigned num_arguments,
5354 unsigned flags)
5355 {
5356 ir_function_signature *sig = (this->*prototype)(image_type,
5357 num_arguments, flags);
5358
5359 if (flags & IMAGE_FUNCTION_EMIT_STUB) {
5360 ir_factory body(&sig->body, mem_ctx);
5361 ir_function *f = shader->symbols->get_function(intrinsic_name);
5362
5363 if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
5364 body.emit(call(f, NULL, sig->parameters));
5365 } else {
5366 ir_variable *ret_val =
5367 body.make_temp(sig->return_type, "_ret_val");
5368 body.emit(call(f, ret_val, sig->parameters));
5369 body.emit(ret(ret_val));
5370 }
5371
5372 sig->is_defined = true;
5373
5374 } else {
5375 sig->is_intrinsic = true;
5376 }
5377
5378 return sig;
5379 }
5380
5381 ir_function_signature *
5382 builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail)
5383 {
5384 MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
5385 return sig;
5386 }
5387
5388 ir_function_signature *
5389 builtin_builder::_memory_barrier(const char *intrinsic_name,
5390 builtin_available_predicate avail)
5391 {
5392 MAKE_SIG(glsl_type::void_type, avail, 0);
5393 body.emit(call(shader->symbols->get_function(intrinsic_name),
5394 NULL, sig->parameters));
5395 return sig;
5396 }
5397
5398 ir_function_signature *
5399 builtin_builder::_shader_clock_intrinsic(builtin_available_predicate avail,
5400 const glsl_type *type)
5401 {
5402 MAKE_INTRINSIC(type, avail, 0);
5403 return sig;
5404 }
5405
5406 ir_function_signature *
5407 builtin_builder::_shader_clock(builtin_available_predicate avail,
5408 const glsl_type *type)
5409 {
5410 MAKE_SIG(type, avail, 0);
5411
5412 ir_variable *retval = body.make_temp(type, "clock_retval");
5413
5414 body.emit(call(shader->symbols->get_function("__intrinsic_shader_clock"),
5415 retval, sig->parameters));
5416 body.emit(ret(retval));
5417 return sig;
5418 }
5419
5420 /** @} */
5421
5422 /******************************************************************************/
5423
5424 /* The singleton instance of builtin_builder. */
5425 static builtin_builder builtins;
5426 static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
5427
5428 /**
5429 * External API (exposing the built-in module to the rest of the compiler):
5430 * @{
5431 */
5432 void
5433 _mesa_glsl_initialize_builtin_functions()
5434 {
5435 mtx_lock(&builtins_lock);
5436 builtins.initialize();
5437 mtx_unlock(&builtins_lock);
5438 }
5439
5440 void
5441 _mesa_glsl_release_builtin_functions()
5442 {
5443 mtx_lock(&builtins_lock);
5444 builtins.release();
5445 mtx_unlock(&builtins_lock);
5446 }
5447
5448 ir_function_signature *
5449 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
5450 const char *name, exec_list *actual_parameters)
5451 {
5452 ir_function_signature * s;
5453 mtx_lock(&builtins_lock);
5454 s = builtins.find(state, name, actual_parameters);
5455 mtx_unlock(&builtins_lock);
5456 return s;
5457 }
5458
5459 ir_function *
5460 _mesa_glsl_find_builtin_function_by_name(const char *name)
5461 {
5462 ir_function *f;
5463 mtx_lock(&builtins_lock);
5464 f = builtins.shader->symbols->get_function(name);
5465 mtx_unlock(&builtins_lock);
5466 return f;
5467 }
5468
5469 gl_shader *
5470 _mesa_glsl_get_builtin_function_shader()
5471 {
5472 return builtins.shader;
5473 }
5474
5475
5476 /**
5477 * Get the function signature for main from a shader
5478 */
5479 ir_function_signature *
5480 _mesa_get_main_function_signature(gl_shader *sh)
5481 {
5482 ir_function *const f = sh->symbols->get_function("main");
5483 if (f != NULL) {
5484 exec_list void_parameters;
5485
5486 /* Look for the 'void main()' signature and ensure that it's defined.
5487 * This keeps the linker from accidentally pick a shader that just
5488 * contains a prototype for main.
5489 *
5490 * We don't have to check for multiple definitions of main (in multiple
5491 * shaders) because that would have already been caught above.
5492 */
5493 ir_function_signature *sig =
5494 f->matching_signature(NULL, &void_parameters, false);
5495 if ((sig != NULL) && sig->is_defined) {
5496 return sig;
5497 }
5498 }
5499
5500 return NULL;
5501 }
5502
5503 /** @} */