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