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