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