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