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