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