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