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