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