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