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