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