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