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