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