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
57 /**
58 * Unfortunately, some versions of MinGW produce bad code if this file
59 * is compiled with -O2 or -O3. The resulting driver will crash in random
60 * places if the app uses GLSL.
61 * The work-around is to disable optimizations for just this file. Luckily,
62 * this code is basically just executed once.
63 *
64 * MinGW 4.6.3 (in Ubuntu 13.10) does not have this bug.
65 * MinGW 5.3.1 (in Ubuntu 16.04) definitely has this bug.
66 * MinGW 6.2.0 (in Ubuntu 16.10) definitely has this bug.
67 * MinGW 7.3.0 (in Ubuntu 18.04) does not have this bug. Assume versions before 7.3.x are buggy
68 */
69
70 #if defined(__MINGW32__) && ((__GNUC__ * 100) + __GNUC_MINOR < 703)
71 #warning "disabling optimizations for this file to work around compiler bug"
72 #pragma GCC optimize("O1")
73 #endif
74
75
76 #include <stdarg.h>
77 #include <stdio.h>
78 #include "main/mtypes.h"
79 #include "main/shaderobj.h"
80 #include "ir_builder.h"
81 #include "glsl_parser_extras.h"
82 #include "program/prog_instruction.h"
83 #include <math.h>
84 #include "builtin_functions.h"
85 #include "util/hash_table.h"
86
87 #define M_PIf ((float) M_PI)
88 #define M_PI_2f ((float) M_PI_2)
89 #define M_PI_4f ((float) M_PI_4)
90
91 using namespace ir_builder;
92
93 static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
94
95 /**
96 * Availability predicates:
97 * @{
98 */
99 static bool
always_available(const _mesa_glsl_parse_state *)100 always_available(const _mesa_glsl_parse_state *)
101 {
102 return true;
103 }
104
105 static bool
compatibility_vs_only(const _mesa_glsl_parse_state * state)106 compatibility_vs_only(const _mesa_glsl_parse_state *state)
107 {
108 return state->stage == MESA_SHADER_VERTEX &&
109 (state->compat_shader || state->ARB_compatibility_enable) &&
110 !state->es_shader;
111 }
112
113 static bool
derivatives_only(const _mesa_glsl_parse_state * state)114 derivatives_only(const _mesa_glsl_parse_state *state)
115 {
116 return state->stage == MESA_SHADER_FRAGMENT ||
117 (state->stage == MESA_SHADER_COMPUTE &&
118 state->NV_compute_shader_derivatives_enable);
119 }
120
121 static bool
gs_only(const _mesa_glsl_parse_state * state)122 gs_only(const _mesa_glsl_parse_state *state)
123 {
124 return state->stage == MESA_SHADER_GEOMETRY;
125 }
126
127 /* For texture functions moved to compat profile in GLSL 4.20 */
128 static bool
deprecated_texture(const _mesa_glsl_parse_state * state)129 deprecated_texture(const _mesa_glsl_parse_state *state)
130 {
131 return state->compat_shader || !state->is_version(420, 0);
132 }
133
134 static bool
deprecated_texture_derivatives_only(const _mesa_glsl_parse_state * state)135 deprecated_texture_derivatives_only(const _mesa_glsl_parse_state *state)
136 {
137 return deprecated_texture(state) && derivatives_only(state);
138 }
139
140 static bool
v110(const _mesa_glsl_parse_state * state)141 v110(const _mesa_glsl_parse_state *state)
142 {
143 return !state->es_shader;
144 }
145
146 static bool
v110_deprecated_texture(const _mesa_glsl_parse_state * state)147 v110_deprecated_texture(const _mesa_glsl_parse_state *state)
148 {
149 return !state->es_shader && deprecated_texture(state);
150 }
151
152 static bool
v110_derivatives_only_deprecated_texture(const _mesa_glsl_parse_state * state)153 v110_derivatives_only_deprecated_texture(const _mesa_glsl_parse_state *state)
154 {
155 return v110_deprecated_texture(state) &&
156 derivatives_only(state);
157 }
158
159 static bool
v120(const _mesa_glsl_parse_state * state)160 v120(const _mesa_glsl_parse_state *state)
161 {
162 return state->is_version(120, 300);
163 }
164
165 static bool
v130(const _mesa_glsl_parse_state * state)166 v130(const _mesa_glsl_parse_state *state)
167 {
168 return state->is_version(130, 300);
169 }
170
171 static bool
v130_desktop(const _mesa_glsl_parse_state * state)172 v130_desktop(const _mesa_glsl_parse_state *state)
173 {
174 return state->is_version(130, 0);
175 }
176
177 static bool
v460_desktop(const _mesa_glsl_parse_state * state)178 v460_desktop(const _mesa_glsl_parse_state *state)
179 {
180 return state->is_version(460, 0);
181 }
182
183 static bool
v130_derivatives_only(const _mesa_glsl_parse_state * state)184 v130_derivatives_only(const _mesa_glsl_parse_state *state)
185 {
186 return state->is_version(130, 300) &&
187 derivatives_only(state);
188 }
189
190 static bool
v140_or_es3(const _mesa_glsl_parse_state * state)191 v140_or_es3(const _mesa_glsl_parse_state *state)
192 {
193 return state->is_version(140, 300);
194 }
195
196 static bool
v400_derivatives_only(const _mesa_glsl_parse_state * state)197 v400_derivatives_only(const _mesa_glsl_parse_state *state)
198 {
199 return state->is_version(400, 0) &&
200 derivatives_only(state);
201 }
202
203 static bool
texture_rectangle(const _mesa_glsl_parse_state * state)204 texture_rectangle(const _mesa_glsl_parse_state *state)
205 {
206 return state->ARB_texture_rectangle_enable;
207 }
208
209 static bool
texture_external(const _mesa_glsl_parse_state * state)210 texture_external(const _mesa_glsl_parse_state *state)
211 {
212 return state->OES_EGL_image_external_enable;
213 }
214
215 static bool
texture_external_es3(const _mesa_glsl_parse_state * state)216 texture_external_es3(const _mesa_glsl_parse_state *state)
217 {
218 return state->OES_EGL_image_external_essl3_enable &&
219 state->es_shader &&
220 state->is_version(0, 300);
221 }
222
223 /** True if texturing functions with explicit LOD are allowed. */
224 static bool
lod_exists_in_stage(const _mesa_glsl_parse_state * state)225 lod_exists_in_stage(const _mesa_glsl_parse_state *state)
226 {
227 /* Texturing functions with "Lod" in their name exist:
228 * - In the vertex shader stage (for all languages)
229 * - In any stage for GLSL 1.30+ or GLSL ES 3.00
230 * - In any stage for desktop GLSL with ARB_shader_texture_lod enabled.
231 *
232 * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
233 * don't need to explicitly check state->es_shader.
234 */
235 return state->stage == MESA_SHADER_VERTEX ||
236 state->is_version(130, 300) ||
237 state->ARB_shader_texture_lod_enable ||
238 state->EXT_gpu_shader4_enable;
239 }
240
241 static bool
lod_deprecated_texture(const _mesa_glsl_parse_state * state)242 lod_deprecated_texture(const _mesa_glsl_parse_state *state)
243 {
244 return deprecated_texture(state) && lod_exists_in_stage(state);
245 }
246
247 static bool
v110_lod_deprecated_texture(const _mesa_glsl_parse_state * state)248 v110_lod_deprecated_texture(const _mesa_glsl_parse_state *state)
249 {
250 return !state->es_shader && lod_deprecated_texture(state);
251 }
252
253 static bool
texture_buffer(const _mesa_glsl_parse_state * state)254 texture_buffer(const _mesa_glsl_parse_state *state)
255 {
256 return state->is_version(140, 320) ||
257 state->EXT_texture_buffer_enable ||
258 state->OES_texture_buffer_enable;
259 }
260
261 static bool
shader_texture_lod(const _mesa_glsl_parse_state * state)262 shader_texture_lod(const _mesa_glsl_parse_state *state)
263 {
264 return state->ARB_shader_texture_lod_enable;
265 }
266
267 static bool
shader_texture_lod_and_rect(const _mesa_glsl_parse_state * state)268 shader_texture_lod_and_rect(const _mesa_glsl_parse_state *state)
269 {
270 return state->ARB_shader_texture_lod_enable &&
271 state->ARB_texture_rectangle_enable;
272 }
273
274 static bool
shader_bit_encoding(const _mesa_glsl_parse_state * state)275 shader_bit_encoding(const _mesa_glsl_parse_state *state)
276 {
277 return state->is_version(330, 300) ||
278 state->ARB_shader_bit_encoding_enable ||
279 state->ARB_gpu_shader5_enable;
280 }
281
282 static bool
shader_integer_mix(const _mesa_glsl_parse_state * state)283 shader_integer_mix(const _mesa_glsl_parse_state *state)
284 {
285 return state->is_version(450, 310) ||
286 state->ARB_ES3_1_compatibility_enable ||
287 (v130(state) && state->EXT_shader_integer_mix_enable);
288 }
289
290 static bool
shader_packing_or_es3(const _mesa_glsl_parse_state * state)291 shader_packing_or_es3(const _mesa_glsl_parse_state *state)
292 {
293 return state->ARB_shading_language_packing_enable ||
294 state->is_version(420, 300);
295 }
296
297 static bool
shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state * state)298 shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state *state)
299 {
300 return state->ARB_shading_language_packing_enable ||
301 state->ARB_gpu_shader5_enable ||
302 state->is_version(400, 300);
303 }
304
305 static bool
gpu_shader4(const _mesa_glsl_parse_state * state)306 gpu_shader4(const _mesa_glsl_parse_state *state)
307 {
308 return state->EXT_gpu_shader4_enable;
309 }
310
311 static bool
gpu_shader4_integer(const _mesa_glsl_parse_state * state)312 gpu_shader4_integer(const _mesa_glsl_parse_state *state)
313 {
314 return state->EXT_gpu_shader4_enable &&
315 state->ctx->Extensions.EXT_texture_integer;
316 }
317
318 static bool
gpu_shader4_array(const _mesa_glsl_parse_state * state)319 gpu_shader4_array(const _mesa_glsl_parse_state *state)
320 {
321 return state->EXT_gpu_shader4_enable &&
322 state->ctx->Extensions.EXT_texture_array;
323 }
324
325 static bool
gpu_shader4_array_integer(const _mesa_glsl_parse_state * state)326 gpu_shader4_array_integer(const _mesa_glsl_parse_state *state)
327 {
328 return gpu_shader4_array(state) &&
329 state->ctx->Extensions.EXT_texture_integer;
330 }
331
332 static bool
gpu_shader4_rect(const _mesa_glsl_parse_state * state)333 gpu_shader4_rect(const _mesa_glsl_parse_state *state)
334 {
335 return state->EXT_gpu_shader4_enable &&
336 state->ctx->Extensions.NV_texture_rectangle;
337 }
338
339 static bool
gpu_shader4_rect_integer(const _mesa_glsl_parse_state * state)340 gpu_shader4_rect_integer(const _mesa_glsl_parse_state *state)
341 {
342 return gpu_shader4_rect(state) &&
343 state->ctx->Extensions.EXT_texture_integer;
344 }
345
346 static bool
gpu_shader4_tbo(const _mesa_glsl_parse_state * state)347 gpu_shader4_tbo(const _mesa_glsl_parse_state *state)
348 {
349 return state->EXT_gpu_shader4_enable &&
350 state->ctx->Extensions.EXT_texture_buffer_object;
351 }
352
353 static bool
gpu_shader4_tbo_integer(const _mesa_glsl_parse_state * state)354 gpu_shader4_tbo_integer(const _mesa_glsl_parse_state *state)
355 {
356 return gpu_shader4_tbo(state) &&
357 state->ctx->Extensions.EXT_texture_integer;
358 }
359
360 static bool
gpu_shader4_derivs_only(const _mesa_glsl_parse_state * state)361 gpu_shader4_derivs_only(const _mesa_glsl_parse_state *state)
362 {
363 return state->EXT_gpu_shader4_enable &&
364 derivatives_only(state);
365 }
366
367 static bool
gpu_shader4_integer_derivs_only(const _mesa_glsl_parse_state * state)368 gpu_shader4_integer_derivs_only(const _mesa_glsl_parse_state *state)
369 {
370 return gpu_shader4_derivs_only(state) &&
371 state->ctx->Extensions.EXT_texture_integer;
372 }
373
374 static bool
gpu_shader4_array_derivs_only(const _mesa_glsl_parse_state * state)375 gpu_shader4_array_derivs_only(const _mesa_glsl_parse_state *state)
376 {
377 return gpu_shader4_derivs_only(state) &&
378 state->ctx->Extensions.EXT_texture_array;
379 }
380
381 static bool
gpu_shader4_array_integer_derivs_only(const _mesa_glsl_parse_state * state)382 gpu_shader4_array_integer_derivs_only(const _mesa_glsl_parse_state *state)
383 {
384 return gpu_shader4_array_derivs_only(state) &&
385 state->ctx->Extensions.EXT_texture_integer;
386 }
387
388 static bool
v130_or_gpu_shader4(const _mesa_glsl_parse_state * state)389 v130_or_gpu_shader4(const _mesa_glsl_parse_state *state)
390 {
391 return state->is_version(130, 300) || state->EXT_gpu_shader4_enable;
392 }
393
394 static bool
v130_or_gpu_shader4_and_tex_shadow_lod(const _mesa_glsl_parse_state * state)395 v130_or_gpu_shader4_and_tex_shadow_lod(const _mesa_glsl_parse_state *state)
396 {
397 return v130_or_gpu_shader4(state) &&
398 state->EXT_texture_shadow_lod_enable;
399 }
400
401 static bool
gpu_shader5(const _mesa_glsl_parse_state * state)402 gpu_shader5(const _mesa_glsl_parse_state *state)
403 {
404 return state->is_version(400, 0) || state->ARB_gpu_shader5_enable;
405 }
406
407 static bool
gpu_shader5_es(const _mesa_glsl_parse_state * state)408 gpu_shader5_es(const _mesa_glsl_parse_state *state)
409 {
410 return state->is_version(400, 320) ||
411 state->ARB_gpu_shader5_enable ||
412 state->EXT_gpu_shader5_enable ||
413 state->OES_gpu_shader5_enable;
414 }
415
416 static bool
gpu_shader5_or_OES_texture_cube_map_array(const _mesa_glsl_parse_state * state)417 gpu_shader5_or_OES_texture_cube_map_array(const _mesa_glsl_parse_state *state)
418 {
419 return state->is_version(400, 320) ||
420 state->ARB_gpu_shader5_enable ||
421 state->EXT_texture_cube_map_array_enable ||
422 state->OES_texture_cube_map_array_enable;
423 }
424
425 static bool
es31_not_gs5(const _mesa_glsl_parse_state * state)426 es31_not_gs5(const _mesa_glsl_parse_state *state)
427 {
428 return state->is_version(0, 310) && !gpu_shader5_es(state);
429 }
430
431 static bool
gpu_shader5_or_es31(const _mesa_glsl_parse_state * state)432 gpu_shader5_or_es31(const _mesa_glsl_parse_state *state)
433 {
434 return state->is_version(400, 310) || state->ARB_gpu_shader5_enable;
435 }
436
437 static bool
shader_packing_or_es31_or_gpu_shader5(const _mesa_glsl_parse_state * state)438 shader_packing_or_es31_or_gpu_shader5(const _mesa_glsl_parse_state *state)
439 {
440 return state->ARB_shading_language_packing_enable ||
441 state->ARB_gpu_shader5_enable ||
442 state->is_version(400, 310);
443 }
444
445 static bool
gpu_shader5_or_es31_or_integer_functions(const _mesa_glsl_parse_state * state)446 gpu_shader5_or_es31_or_integer_functions(const _mesa_glsl_parse_state *state)
447 {
448 return gpu_shader5_or_es31(state) ||
449 state->MESA_shader_integer_functions_enable;
450 }
451
452 static bool
fs_interpolate_at(const _mesa_glsl_parse_state * state)453 fs_interpolate_at(const _mesa_glsl_parse_state *state)
454 {
455 return state->stage == MESA_SHADER_FRAGMENT &&
456 (state->is_version(400, 320) ||
457 state->ARB_gpu_shader5_enable ||
458 state->OES_shader_multisample_interpolation_enable);
459 }
460
461
462 static bool
texture_array_lod(const _mesa_glsl_parse_state * state)463 texture_array_lod(const _mesa_glsl_parse_state *state)
464 {
465 return lod_exists_in_stage(state) &&
466 (state->EXT_texture_array_enable ||
467 (state->EXT_gpu_shader4_enable &&
468 state->ctx->Extensions.EXT_texture_array));
469 }
470
471 static bool
texture_array(const _mesa_glsl_parse_state * state)472 texture_array(const _mesa_glsl_parse_state *state)
473 {
474 return state->EXT_texture_array_enable ||
475 (state->EXT_gpu_shader4_enable &&
476 state->ctx->Extensions.EXT_texture_array);
477 }
478
479 static bool
texture_array_derivs_only(const _mesa_glsl_parse_state * state)480 texture_array_derivs_only(const _mesa_glsl_parse_state *state)
481 {
482 return derivatives_only(state) &&
483 texture_array(state);
484 }
485
486 static bool
texture_multisample(const _mesa_glsl_parse_state * state)487 texture_multisample(const _mesa_glsl_parse_state *state)
488 {
489 return state->is_version(150, 310) ||
490 state->ARB_texture_multisample_enable;
491 }
492
493 static bool
texture_multisample_array(const _mesa_glsl_parse_state * state)494 texture_multisample_array(const _mesa_glsl_parse_state *state)
495 {
496 return state->is_version(150, 320) ||
497 state->ARB_texture_multisample_enable ||
498 state->OES_texture_storage_multisample_2d_array_enable;
499 }
500
501 static bool
texture_samples_identical(const _mesa_glsl_parse_state * state)502 texture_samples_identical(const _mesa_glsl_parse_state *state)
503 {
504 return texture_multisample(state) &&
505 state->EXT_shader_samples_identical_enable;
506 }
507
508 static bool
texture_samples_identical_array(const _mesa_glsl_parse_state * state)509 texture_samples_identical_array(const _mesa_glsl_parse_state *state)
510 {
511 return texture_multisample_array(state) &&
512 state->EXT_shader_samples_identical_enable;
513 }
514
515 static bool
derivatives_texture_cube_map_array(const _mesa_glsl_parse_state * state)516 derivatives_texture_cube_map_array(const _mesa_glsl_parse_state *state)
517 {
518 return state->has_texture_cube_map_array() &&
519 derivatives_only(state);
520 }
521
522 static bool
texture_cube_map_array(const _mesa_glsl_parse_state * state)523 texture_cube_map_array(const _mesa_glsl_parse_state *state)
524 {
525 return state->has_texture_cube_map_array();
526 }
527
528 static bool
v130_or_gpu_shader4_and_tex_cube_map_array(const _mesa_glsl_parse_state * state)529 v130_or_gpu_shader4_and_tex_cube_map_array(const _mesa_glsl_parse_state *state)
530 {
531 return texture_cube_map_array(state) &&
532 v130_or_gpu_shader4(state) &&
533 state->EXT_texture_shadow_lod_enable;
534 }
535
536 static bool
texture_query_levels(const _mesa_glsl_parse_state * state)537 texture_query_levels(const _mesa_glsl_parse_state *state)
538 {
539 return state->is_version(430, 0) ||
540 state->ARB_texture_query_levels_enable;
541 }
542
543 static bool
texture_query_lod(const _mesa_glsl_parse_state * state)544 texture_query_lod(const _mesa_glsl_parse_state *state)
545 {
546 return derivatives_only(state) &&
547 (state->ARB_texture_query_lod_enable ||
548 state->EXT_texture_query_lod_enable);
549 }
550
551 static bool
texture_gather_cube_map_array(const _mesa_glsl_parse_state * state)552 texture_gather_cube_map_array(const _mesa_glsl_parse_state *state)
553 {
554 return state->is_version(400, 320) ||
555 state->ARB_texture_gather_enable ||
556 state->ARB_gpu_shader5_enable ||
557 state->EXT_texture_cube_map_array_enable ||
558 state->OES_texture_cube_map_array_enable;
559 }
560
561 static bool
texture_texture4(const _mesa_glsl_parse_state * state)562 texture_texture4(const _mesa_glsl_parse_state *state)
563 {
564 return state->AMD_texture_texture4_enable;
565 }
566
567 static bool
texture_gather_or_es31(const _mesa_glsl_parse_state * state)568 texture_gather_or_es31(const _mesa_glsl_parse_state *state)
569 {
570 return state->is_version(400, 310) ||
571 state->ARB_texture_gather_enable ||
572 state->ARB_gpu_shader5_enable;
573 }
574
575 /* Only ARB_texture_gather but not GLSL 4.0 or ARB_gpu_shader5.
576 * used for relaxation of const offset requirements.
577 */
578 static bool
texture_gather_only_or_es31(const _mesa_glsl_parse_state * state)579 texture_gather_only_or_es31(const _mesa_glsl_parse_state *state)
580 {
581 return !state->is_version(400, 320) &&
582 !state->ARB_gpu_shader5_enable &&
583 !state->EXT_gpu_shader5_enable &&
584 !state->OES_gpu_shader5_enable &&
585 (state->ARB_texture_gather_enable ||
586 state->is_version(0, 310));
587 }
588
589 /* Desktop GL or OES_standard_derivatives */
590 static bool
derivatives(const _mesa_glsl_parse_state * state)591 derivatives(const _mesa_glsl_parse_state *state)
592 {
593 return derivatives_only(state) &&
594 (state->is_version(110, 300) ||
595 state->OES_standard_derivatives_enable ||
596 state->ctx->Const.AllowGLSLRelaxedES);
597 }
598
599 static bool
derivative_control(const _mesa_glsl_parse_state * state)600 derivative_control(const _mesa_glsl_parse_state *state)
601 {
602 return derivatives_only(state) &&
603 (state->is_version(450, 0) ||
604 state->ARB_derivative_control_enable);
605 }
606
607 /** True if sampler3D exists */
608 static bool
tex3d(const _mesa_glsl_parse_state * state)609 tex3d(const _mesa_glsl_parse_state *state)
610 {
611 /* sampler3D exists in all desktop GLSL versions, GLSL ES 1.00 with the
612 * OES_texture_3D extension, and in GLSL ES 3.00.
613 */
614 return (!state->es_shader ||
615 state->OES_texture_3D_enable ||
616 state->language_version >= 300) && deprecated_texture(state);
617 }
618
619 static bool
derivatives_tex3d(const _mesa_glsl_parse_state * state)620 derivatives_tex3d(const _mesa_glsl_parse_state *state)
621 {
622 return (!state->es_shader || state->OES_texture_3D_enable) &&
623 derivatives_only(state) && deprecated_texture(state);
624 }
625
626 static bool
tex3d_lod(const _mesa_glsl_parse_state * state)627 tex3d_lod(const _mesa_glsl_parse_state *state)
628 {
629 return tex3d(state) && lod_exists_in_stage(state);
630 }
631
632 static bool
shader_atomic_counters(const _mesa_glsl_parse_state * state)633 shader_atomic_counters(const _mesa_glsl_parse_state *state)
634 {
635 return state->has_atomic_counters();
636 }
637
638 static bool
shader_atomic_counter_ops(const _mesa_glsl_parse_state * state)639 shader_atomic_counter_ops(const _mesa_glsl_parse_state *state)
640 {
641 return state->ARB_shader_atomic_counter_ops_enable;
642 }
643
644 static bool
shader_atomic_counter_ops_or_v460_desktop(const _mesa_glsl_parse_state * state)645 shader_atomic_counter_ops_or_v460_desktop(const _mesa_glsl_parse_state *state)
646 {
647 return state->ARB_shader_atomic_counter_ops_enable || v460_desktop(state);
648 }
649
650 static bool
shader_ballot(const _mesa_glsl_parse_state * state)651 shader_ballot(const _mesa_glsl_parse_state *state)
652 {
653 return state->ARB_shader_ballot_enable;
654 }
655
656 static bool
supports_arb_fragment_shader_interlock(const _mesa_glsl_parse_state * state)657 supports_arb_fragment_shader_interlock(const _mesa_glsl_parse_state *state)
658 {
659 return state->ARB_fragment_shader_interlock_enable;
660 }
661
662 static bool
supports_nv_fragment_shader_interlock(const _mesa_glsl_parse_state * state)663 supports_nv_fragment_shader_interlock(const _mesa_glsl_parse_state *state)
664 {
665 return state->NV_fragment_shader_interlock_enable;
666 }
667
668 static bool
shader_clock(const _mesa_glsl_parse_state * state)669 shader_clock(const _mesa_glsl_parse_state *state)
670 {
671 return state->ARB_shader_clock_enable;
672 }
673
674 static bool
shader_clock_int64(const _mesa_glsl_parse_state * state)675 shader_clock_int64(const _mesa_glsl_parse_state *state)
676 {
677 return state->ARB_shader_clock_enable &&
678 (state->ARB_gpu_shader_int64_enable ||
679 state->AMD_gpu_shader_int64_enable);
680 }
681
682 static bool
shader_storage_buffer_object(const _mesa_glsl_parse_state * state)683 shader_storage_buffer_object(const _mesa_glsl_parse_state *state)
684 {
685 return state->has_shader_storage_buffer_objects();
686 }
687
688 static bool
shader_trinary_minmax(const _mesa_glsl_parse_state * state)689 shader_trinary_minmax(const _mesa_glsl_parse_state *state)
690 {
691 return state->AMD_shader_trinary_minmax_enable;
692 }
693
694 static bool
shader_image_load_store(const _mesa_glsl_parse_state * state)695 shader_image_load_store(const _mesa_glsl_parse_state *state)
696 {
697 return (state->is_version(420, 310) ||
698 state->ARB_shader_image_load_store_enable ||
699 state->EXT_shader_image_load_store_enable);
700 }
701
702 static bool
shader_image_load_store_ext(const _mesa_glsl_parse_state * state)703 shader_image_load_store_ext(const _mesa_glsl_parse_state *state)
704 {
705 return state->EXT_shader_image_load_store_enable;
706 }
707
708 static bool
shader_image_atomic(const _mesa_glsl_parse_state * state)709 shader_image_atomic(const _mesa_glsl_parse_state *state)
710 {
711 return (state->is_version(420, 320) ||
712 state->ARB_shader_image_load_store_enable ||
713 state->EXT_shader_image_load_store_enable ||
714 state->OES_shader_image_atomic_enable);
715 }
716
717 static bool
shader_image_atomic_exchange_float(const _mesa_glsl_parse_state * state)718 shader_image_atomic_exchange_float(const _mesa_glsl_parse_state *state)
719 {
720 return (state->is_version(450, 320) ||
721 state->ARB_ES3_1_compatibility_enable ||
722 state->OES_shader_image_atomic_enable ||
723 state->NV_shader_atomic_float_enable);
724 }
725
726 static bool
shader_image_atomic_add_float(const _mesa_glsl_parse_state * state)727 shader_image_atomic_add_float(const _mesa_glsl_parse_state *state)
728 {
729 return state->NV_shader_atomic_float_enable;
730 }
731
732 static bool
shader_image_size(const _mesa_glsl_parse_state * state)733 shader_image_size(const _mesa_glsl_parse_state *state)
734 {
735 return state->is_version(430, 310) ||
736 state->ARB_shader_image_size_enable;
737 }
738
739 static bool
shader_samples(const _mesa_glsl_parse_state * state)740 shader_samples(const _mesa_glsl_parse_state *state)
741 {
742 return state->is_version(450, 0) ||
743 state->ARB_shader_texture_image_samples_enable;
744 }
745
746 static bool
gs_streams(const _mesa_glsl_parse_state * state)747 gs_streams(const _mesa_glsl_parse_state *state)
748 {
749 return gpu_shader5(state) && gs_only(state);
750 }
751
752 static bool
fp64(const _mesa_glsl_parse_state * state)753 fp64(const _mesa_glsl_parse_state *state)
754 {
755 return state->has_double();
756 }
757
758 static bool
int64_avail(const _mesa_glsl_parse_state * state)759 int64_avail(const _mesa_glsl_parse_state *state)
760 {
761 return state->has_int64();
762 }
763
764 static bool
int64_fp64(const _mesa_glsl_parse_state * state)765 int64_fp64(const _mesa_glsl_parse_state *state)
766 {
767 return state->has_int64() && state->has_double();
768 }
769
770 static bool
compute_shader(const _mesa_glsl_parse_state * state)771 compute_shader(const _mesa_glsl_parse_state *state)
772 {
773 return state->stage == MESA_SHADER_COMPUTE;
774 }
775
776 static bool
compute_shader_supported(const _mesa_glsl_parse_state * state)777 compute_shader_supported(const _mesa_glsl_parse_state *state)
778 {
779 return state->has_compute_shader();
780 }
781
782 static bool
buffer_atomics_supported(const _mesa_glsl_parse_state * state)783 buffer_atomics_supported(const _mesa_glsl_parse_state *state)
784 {
785 return compute_shader(state) || shader_storage_buffer_object(state);
786 }
787
788 static bool
buffer_int64_atomics_supported(const _mesa_glsl_parse_state * state)789 buffer_int64_atomics_supported(const _mesa_glsl_parse_state *state)
790 {
791 return state->NV_shader_atomic_int64_enable &&
792 buffer_atomics_supported(state);
793 }
794
795 static bool
barrier_supported(const _mesa_glsl_parse_state * state)796 barrier_supported(const _mesa_glsl_parse_state *state)
797 {
798 return compute_shader(state) ||
799 state->stage == MESA_SHADER_TESS_CTRL;
800 }
801
802 static bool
vote(const _mesa_glsl_parse_state * state)803 vote(const _mesa_glsl_parse_state *state)
804 {
805 return state->ARB_shader_group_vote_enable;
806 }
807
808 static bool
vote_ext(const _mesa_glsl_parse_state * state)809 vote_ext(const _mesa_glsl_parse_state *state)
810 {
811 return state->EXT_shader_group_vote_enable;
812 }
813
814 static bool
vote_or_v460_desktop(const _mesa_glsl_parse_state * state)815 vote_or_v460_desktop(const _mesa_glsl_parse_state *state)
816 {
817 return state->EXT_shader_group_vote_enable || state->ARB_shader_group_vote_enable || v460_desktop(state);
818 }
819
820 static bool
integer_functions_supported(const _mesa_glsl_parse_state * state)821 integer_functions_supported(const _mesa_glsl_parse_state *state)
822 {
823 return state->extensions->MESA_shader_integer_functions;
824 }
825
826 static bool
NV_shader_atomic_float_supported(const _mesa_glsl_parse_state * state)827 NV_shader_atomic_float_supported(const _mesa_glsl_parse_state *state)
828 {
829 return state->extensions->NV_shader_atomic_float;
830 }
831
832 static bool
shader_atomic_float_add(const _mesa_glsl_parse_state * state)833 shader_atomic_float_add(const _mesa_glsl_parse_state *state)
834 {
835 return state->NV_shader_atomic_float_enable;
836 }
837
838 static bool
shader_atomic_float_exchange(const _mesa_glsl_parse_state * state)839 shader_atomic_float_exchange(const _mesa_glsl_parse_state *state)
840 {
841 return state->NV_shader_atomic_float_enable ||
842 state->INTEL_shader_atomic_float_minmax_enable;
843 }
844
845 static bool
INTEL_shader_atomic_float_minmax_supported(const _mesa_glsl_parse_state * state)846 INTEL_shader_atomic_float_minmax_supported(const _mesa_glsl_parse_state *state)
847 {
848 return state->extensions->INTEL_shader_atomic_float_minmax;
849 }
850
851 static bool
shader_atomic_float_minmax(const _mesa_glsl_parse_state * state)852 shader_atomic_float_minmax(const _mesa_glsl_parse_state *state)
853 {
854 return state->INTEL_shader_atomic_float_minmax_enable;
855 }
856
857 static bool
demote_to_helper_invocation(const _mesa_glsl_parse_state * state)858 demote_to_helper_invocation(const _mesa_glsl_parse_state *state)
859 {
860 return state->EXT_demote_to_helper_invocation_enable;
861 }
862
863 static bool
shader_integer_functions2(const _mesa_glsl_parse_state * state)864 shader_integer_functions2(const _mesa_glsl_parse_state *state)
865 {
866 return state->INTEL_shader_integer_functions2_enable;
867 }
868
869 static bool
shader_integer_functions2_int64(const _mesa_glsl_parse_state * state)870 shader_integer_functions2_int64(const _mesa_glsl_parse_state *state)
871 {
872 return state->INTEL_shader_integer_functions2_enable && state->has_int64();
873 }
874
875 static bool
is_nir(const _mesa_glsl_parse_state * state)876 is_nir(const _mesa_glsl_parse_state *state)
877 {
878 return state->ctx->Const.ShaderCompilerOptions[state->stage].NirOptions;
879 }
880
881 static bool
is_not_nir(const _mesa_glsl_parse_state * state)882 is_not_nir(const _mesa_glsl_parse_state *state)
883 {
884 return !is_nir(state);
885 }
886
887 /** @} */
888
889 /******************************************************************************/
890
891 namespace {
892
893 /**
894 * builtin_builder: A singleton object representing the core of the built-in
895 * function module.
896 *
897 * It generates IR for every built-in function signature, and organizes them
898 * into functions.
899 */
900 class builtin_builder {
901 public:
902 builtin_builder();
903 ~builtin_builder();
904
905 void initialize();
906 void release();
907 ir_function_signature *find(_mesa_glsl_parse_state *state,
908 const char *name, exec_list *actual_parameters);
909
910 /**
911 * A shader to hold all the built-in signatures; created by this module.
912 *
913 * This includes signatures for every built-in, regardless of version or
914 * enabled extensions. The availability predicate associated with each
915 * signature allows matching_signature() to filter out the irrelevant ones.
916 */
917 gl_shader *shader;
918
919 private:
920 void *mem_ctx;
921
922 void create_shader();
923 void create_intrinsics();
924 void create_builtins();
925
926 /**
927 * IR builder helpers:
928 *
929 * These convenience functions assist in emitting IR, but don't necessarily
930 * fit in ir_builder itself. Many of them rely on having a mem_ctx class
931 * member available.
932 */
933 ir_variable *in_var(const glsl_type *type, const char *name);
934 ir_variable *out_var(const glsl_type *type, const char *name);
935 ir_constant *imm(float f, unsigned vector_elements=1);
936 ir_constant *imm(bool b, unsigned vector_elements=1);
937 ir_constant *imm(int i, unsigned vector_elements=1);
938 ir_constant *imm(unsigned u, unsigned vector_elements=1);
939 ir_constant *imm(double d, unsigned vector_elements=1);
940 ir_constant *imm(const glsl_type *type, const ir_constant_data &);
941 ir_dereference_variable *var_ref(ir_variable *var);
942 ir_dereference_array *array_ref(ir_variable *var, int i);
943 ir_swizzle *matrix_elt(ir_variable *var, int col, int row);
944
945 ir_expression *asin_expr(ir_variable *x, float p0, float p1);
946 void do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x);
947
948 /**
949 * Call function \param f with parameters specified as the linked
950 * list \param params of \c ir_variable objects. \param ret should
951 * point to the ir_variable that will hold the function return
952 * value, or be \c NULL if the function has void return type.
953 */
954 ir_call *call(ir_function *f, ir_variable *ret, exec_list params);
955
956 /** Create a new function and add the given signatures. */
957 void add_function(const char *name, ...);
958
959 typedef ir_function_signature *(builtin_builder::*image_prototype_ctr)(const glsl_type *image_type,
960 unsigned num_arguments,
961 unsigned flags);
962
963 /**
964 * Create a new image built-in function for all known image types.
965 * \p flags is a bitfield of \c image_function_flags flags.
966 */
967 void add_image_function(const char *name,
968 const char *intrinsic_name,
969 image_prototype_ctr prototype,
970 unsigned num_arguments,
971 unsigned flags,
972 enum ir_intrinsic_id id);
973
974 /**
975 * Create new functions for all known image built-ins and types.
976 * If \p glsl is \c true, use the GLSL built-in names and emit code
977 * to call into the actual compiler intrinsic. If \p glsl is
978 * false, emit a function prototype with no body for each image
979 * intrinsic name.
980 */
981 void add_image_functions(bool glsl);
982
983 ir_function_signature *new_sig(const glsl_type *return_type,
984 builtin_available_predicate avail,
985 int num_params, ...);
986
987 /**
988 * Function signature generators:
989 * @{
990 */
991 ir_function_signature *unop(builtin_available_predicate avail,
992 ir_expression_operation opcode,
993 const glsl_type *return_type,
994 const glsl_type *param_type);
995 ir_function_signature *binop(builtin_available_predicate avail,
996 ir_expression_operation opcode,
997 const glsl_type *return_type,
998 const glsl_type *param0_type,
999 const glsl_type *param1_type,
1000 bool swap_operands = false);
1001
1002 #define B0(X) ir_function_signature *_##X();
1003 #define B1(X) ir_function_signature *_##X(const glsl_type *);
1004 #define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *);
1005 #define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *, const glsl_type *);
1006 #define BA1(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *);
1007 #define BA2(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *, const glsl_type *);
1008 B1(radians)
1009 B1(degrees)
1010 B1(sin)
1011 B1(cos)
1012 B1(tan)
1013 B1(asin)
1014 B1(acos)
1015 B1(atan2)
1016 B1(atan)
1017 B1(atan2_op)
1018 B1(atan_op)
1019 B1(sinh)
1020 B1(cosh)
1021 B1(tanh)
1022 B1(asinh)
1023 B1(acosh)
1024 B1(atanh)
1025 B1(pow)
1026 B1(exp)
1027 B1(log)
1028 B1(exp2)
1029 B1(log2)
1030 BA1(sqrt)
1031 BA1(inversesqrt)
1032 BA1(abs)
1033 BA1(sign)
1034 BA1(floor)
1035 BA1(truncate)
1036 BA1(trunc)
1037 BA1(round)
1038 BA1(roundEven)
1039 BA1(ceil)
1040 BA1(fract)
1041 BA2(mod)
1042 BA1(modf)
1043 BA2(min)
1044 BA2(max)
1045 BA2(clamp)
1046 BA2(mix_lrp)
1047 ir_function_signature *_mix_sel(builtin_available_predicate avail,
1048 const glsl_type *val_type,
1049 const glsl_type *blend_type);
1050 BA2(step)
1051 BA2(smoothstep)
1052 BA1(isnan)
1053 BA1(isinf)
1054 B1(floatBitsToInt)
1055 B1(floatBitsToUint)
1056 B1(intBitsToFloat)
1057 B1(uintBitsToFloat)
1058
1059 BA1(doubleBitsToInt64)
1060 BA1(doubleBitsToUint64)
1061 BA1(int64BitsToDouble)
1062 BA1(uint64BitsToDouble)
1063
1064 ir_function_signature *_packUnorm2x16(builtin_available_predicate avail);
1065 ir_function_signature *_packSnorm2x16(builtin_available_predicate avail);
1066 ir_function_signature *_packUnorm4x8(builtin_available_predicate avail);
1067 ir_function_signature *_packSnorm4x8(builtin_available_predicate avail);
1068 ir_function_signature *_unpackUnorm2x16(builtin_available_predicate avail);
1069 ir_function_signature *_unpackSnorm2x16(builtin_available_predicate avail);
1070 ir_function_signature *_unpackUnorm4x8(builtin_available_predicate avail);
1071 ir_function_signature *_unpackSnorm4x8(builtin_available_predicate avail);
1072 ir_function_signature *_packHalf2x16(builtin_available_predicate avail);
1073 ir_function_signature *_unpackHalf2x16(builtin_available_predicate avail);
1074 ir_function_signature *_packDouble2x32(builtin_available_predicate avail);
1075 ir_function_signature *_unpackDouble2x32(builtin_available_predicate avail);
1076 ir_function_signature *_packInt2x32(builtin_available_predicate avail);
1077 ir_function_signature *_unpackInt2x32(builtin_available_predicate avail);
1078 ir_function_signature *_packUint2x32(builtin_available_predicate avail);
1079 ir_function_signature *_unpackUint2x32(builtin_available_predicate avail);
1080
1081 BA1(length)
1082 BA1(distance);
1083 BA1(dot);
1084 BA1(cross);
1085 BA1(normalize);
1086 B0(ftransform);
1087 BA1(faceforward);
1088 BA1(reflect);
1089 BA1(refract);
1090 BA1(matrixCompMult);
1091 BA1(outerProduct);
1092 BA1(determinant_mat2);
1093 BA1(determinant_mat3);
1094 BA1(determinant_mat4);
1095 BA1(inverse_mat2);
1096 BA1(inverse_mat3);
1097 BA1(inverse_mat4);
1098 BA1(transpose);
1099 BA1(lessThan);
1100 BA1(lessThanEqual);
1101 BA1(greaterThan);
1102 BA1(greaterThanEqual);
1103 BA1(equal);
1104 BA1(notEqual);
1105 B1(any);
1106 B1(all);
1107 B1(not);
1108 BA2(textureSize);
1109 BA1(textureSamples);
1110
1111 /** Flags to _texture() */
1112 #define TEX_PROJECT 1
1113 #define TEX_OFFSET 2
1114 #define TEX_COMPONENT 4
1115 #define TEX_OFFSET_NONCONST 8
1116 #define TEX_OFFSET_ARRAY 16
1117
1118 ir_function_signature *_texture(ir_texture_opcode opcode,
1119 builtin_available_predicate avail,
1120 const glsl_type *return_type,
1121 const glsl_type *sampler_type,
1122 const glsl_type *coord_type,
1123 int flags = 0);
1124 ir_function_signature *_textureCubeArrayShadow(ir_texture_opcode opcode,
1125 builtin_available_predicate avail,
1126 const glsl_type *x);
1127 ir_function_signature *_texelFetch(builtin_available_predicate avail,
1128 const glsl_type *return_type,
1129 const glsl_type *sampler_type,
1130 const glsl_type *coord_type,
1131 const glsl_type *offset_type = NULL);
1132
1133 B0(EmitVertex)
1134 B0(EndPrimitive)
1135 ir_function_signature *_EmitStreamVertex(builtin_available_predicate avail,
1136 const glsl_type *stream_type);
1137 ir_function_signature *_EndStreamPrimitive(builtin_available_predicate avail,
1138 const glsl_type *stream_type);
1139 B0(barrier)
1140
1141 BA2(textureQueryLod);
1142 BA1(textureQueryLevels);
1143 BA2(textureSamplesIdentical);
1144 B1(dFdx);
1145 B1(dFdy);
1146 B1(fwidth);
1147 B1(dFdxCoarse);
1148 B1(dFdyCoarse);
1149 B1(fwidthCoarse);
1150 B1(dFdxFine);
1151 B1(dFdyFine);
1152 B1(fwidthFine);
1153 B1(noise1);
1154 B1(noise2);
1155 B1(noise3);
1156 B1(noise4);
1157
1158 B1(bitfieldExtract)
1159 B1(bitfieldInsert)
1160 B1(bitfieldReverse)
1161 B1(bitCount)
1162 B1(findLSB)
1163 B1(findMSB)
1164 BA1(countLeadingZeros)
1165 BA1(countTrailingZeros)
1166 BA1(fma)
1167 B2(ldexp)
1168 B2(frexp)
1169 B2(dfrexp)
1170 B1(uaddCarry)
1171 B1(usubBorrow)
1172 BA1(addSaturate)
1173 BA1(subtractSaturate)
1174 BA1(absoluteDifference)
1175 BA1(average)
1176 BA1(averageRounded)
1177 B1(mulExtended)
1178 BA1(multiply32x16)
1179 B1(interpolateAtCentroid)
1180 B1(interpolateAtOffset)
1181 B1(interpolateAtSample)
1182
1183 ir_function_signature *_atomic_counter_intrinsic(builtin_available_predicate avail,
1184 enum ir_intrinsic_id id);
1185 ir_function_signature *_atomic_counter_intrinsic1(builtin_available_predicate avail,
1186 enum ir_intrinsic_id id);
1187 ir_function_signature *_atomic_counter_intrinsic2(builtin_available_predicate avail,
1188 enum ir_intrinsic_id id);
1189 ir_function_signature *_atomic_counter_op(const char *intrinsic,
1190 builtin_available_predicate avail);
1191 ir_function_signature *_atomic_counter_op1(const char *intrinsic,
1192 builtin_available_predicate avail);
1193 ir_function_signature *_atomic_counter_op2(const char *intrinsic,
1194 builtin_available_predicate avail);
1195
1196 ir_function_signature *_atomic_intrinsic2(builtin_available_predicate avail,
1197 const glsl_type *type,
1198 enum ir_intrinsic_id id);
1199 ir_function_signature *_atomic_op2(const char *intrinsic,
1200 builtin_available_predicate avail,
1201 const glsl_type *type);
1202 ir_function_signature *_atomic_intrinsic3(builtin_available_predicate avail,
1203 const glsl_type *type,
1204 enum ir_intrinsic_id id);
1205 ir_function_signature *_atomic_op3(const char *intrinsic,
1206 builtin_available_predicate avail,
1207 const glsl_type *type);
1208
1209 B1(min3)
1210 B1(max3)
1211 B1(mid3)
1212
1213 ir_function_signature *_image_prototype(const glsl_type *image_type,
1214 unsigned num_arguments,
1215 unsigned flags);
1216 ir_function_signature *_image_size_prototype(const glsl_type *image_type,
1217 unsigned num_arguments,
1218 unsigned flags);
1219 ir_function_signature *_image_samples_prototype(const glsl_type *image_type,
1220 unsigned num_arguments,
1221 unsigned flags);
1222 ir_function_signature *_image(image_prototype_ctr prototype,
1223 const glsl_type *image_type,
1224 const char *intrinsic_name,
1225 unsigned num_arguments,
1226 unsigned flags,
1227 enum ir_intrinsic_id id);
1228
1229 ir_function_signature *_memory_barrier_intrinsic(
1230 builtin_available_predicate avail,
1231 enum ir_intrinsic_id id);
1232 ir_function_signature *_memory_barrier(const char *intrinsic_name,
1233 builtin_available_predicate avail);
1234
1235 ir_function_signature *_ballot_intrinsic();
1236 ir_function_signature *_ballot();
1237 ir_function_signature *_read_first_invocation_intrinsic(const glsl_type *type);
1238 ir_function_signature *_read_first_invocation(const glsl_type *type);
1239 ir_function_signature *_read_invocation_intrinsic(const glsl_type *type);
1240 ir_function_signature *_read_invocation(const glsl_type *type);
1241
1242
1243 ir_function_signature *_invocation_interlock_intrinsic(
1244 builtin_available_predicate avail,
1245 enum ir_intrinsic_id id);
1246 ir_function_signature *_invocation_interlock(
1247 const char *intrinsic_name,
1248 builtin_available_predicate avail);
1249
1250 ir_function_signature *_shader_clock_intrinsic(builtin_available_predicate avail,
1251 const glsl_type *type);
1252 ir_function_signature *_shader_clock(builtin_available_predicate avail,
1253 const glsl_type *type);
1254
1255 ir_function_signature *_vote_intrinsic(builtin_available_predicate avail,
1256 enum ir_intrinsic_id id);
1257 ir_function_signature *_vote(const char *intrinsic_name,
1258 builtin_available_predicate avail);
1259
1260 ir_function_signature *_helper_invocation_intrinsic();
1261 ir_function_signature *_helper_invocation();
1262
1263 #undef B0
1264 #undef B1
1265 #undef B2
1266 #undef B3
1267 #undef BA1
1268 #undef BA2
1269 /** @} */
1270 };
1271
1272 enum image_function_flags {
1273 IMAGE_FUNCTION_EMIT_STUB = (1 << 0),
1274 IMAGE_FUNCTION_RETURNS_VOID = (1 << 1),
1275 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE = (1 << 2),
1276 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE = (1 << 3),
1277 IMAGE_FUNCTION_READ_ONLY = (1 << 4),
1278 IMAGE_FUNCTION_WRITE_ONLY = (1 << 5),
1279 IMAGE_FUNCTION_AVAIL_ATOMIC = (1 << 6),
1280 IMAGE_FUNCTION_MS_ONLY = (1 << 7),
1281 IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE = (1 << 8),
1282 IMAGE_FUNCTION_AVAIL_ATOMIC_ADD = (1 << 9),
1283 IMAGE_FUNCTION_EXT_ONLY = (1 << 10),
1284 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE = (1 << 11),
1285 };
1286
1287 } /* anonymous namespace */
1288
1289 /**
1290 * Core builtin_builder functionality:
1291 * @{
1292 */
builtin_builder()1293 builtin_builder::builtin_builder()
1294 : shader(NULL)
1295 {
1296 mem_ctx = NULL;
1297 }
1298
~builtin_builder()1299 builtin_builder::~builtin_builder()
1300 {
1301 mtx_lock(&builtins_lock);
1302
1303 ralloc_free(mem_ctx);
1304 mem_ctx = NULL;
1305
1306 ralloc_free(shader);
1307 shader = NULL;
1308
1309 mtx_unlock(&builtins_lock);
1310 }
1311
1312 ir_function_signature *
find(_mesa_glsl_parse_state * state,const char * name,exec_list * actual_parameters)1313 builtin_builder::find(_mesa_glsl_parse_state *state,
1314 const char *name, exec_list *actual_parameters)
1315 {
1316 /* The shader currently being compiled requested a built-in function;
1317 * it needs to link against builtin_builder::shader in order to get them.
1318 *
1319 * Even if we don't find a matching signature, we still need to do this so
1320 * that the "no matching signature" error will list potential candidates
1321 * from the available built-ins.
1322 */
1323 state->uses_builtin_functions = true;
1324
1325 ir_function *f = shader->symbols->get_function(name);
1326 if (f == NULL)
1327 return NULL;
1328
1329 ir_function_signature *sig =
1330 f->matching_signature(state, actual_parameters, true);
1331 if (sig == NULL)
1332 return NULL;
1333
1334 return sig;
1335 }
1336
1337 void
initialize()1338 builtin_builder::initialize()
1339 {
1340 /* If already initialized, don't do it again. */
1341 if (mem_ctx != NULL)
1342 return;
1343
1344 glsl_type_singleton_init_or_ref();
1345
1346 mem_ctx = ralloc_context(NULL);
1347 create_shader();
1348 create_intrinsics();
1349 create_builtins();
1350 }
1351
1352 void
release()1353 builtin_builder::release()
1354 {
1355 ralloc_free(mem_ctx);
1356 mem_ctx = NULL;
1357
1358 ralloc_free(shader);
1359 shader = NULL;
1360
1361 glsl_type_singleton_decref();
1362 }
1363
1364 void
create_shader()1365 builtin_builder::create_shader()
1366 {
1367 /* The target doesn't actually matter. There's no target for generic
1368 * GLSL utility code that could be linked against any stage, so just
1369 * arbitrarily pick GL_VERTEX_SHADER.
1370 */
1371 shader = _mesa_new_shader(0, MESA_SHADER_VERTEX);
1372 shader->symbols = new(mem_ctx) glsl_symbol_table;
1373 }
1374
1375 /** @} */
1376
1377 /**
1378 * Create ir_function and ir_function_signature objects for each
1379 * intrinsic.
1380 */
1381 void
create_intrinsics()1382 builtin_builder::create_intrinsics()
1383 {
1384 add_function("__intrinsic_atomic_read",
1385 _atomic_counter_intrinsic(shader_atomic_counters,
1386 ir_intrinsic_atomic_counter_read),
1387 NULL);
1388 add_function("__intrinsic_atomic_increment",
1389 _atomic_counter_intrinsic(shader_atomic_counters,
1390 ir_intrinsic_atomic_counter_increment),
1391 NULL);
1392 add_function("__intrinsic_atomic_predecrement",
1393 _atomic_counter_intrinsic(shader_atomic_counters,
1394 ir_intrinsic_atomic_counter_predecrement),
1395 NULL);
1396
1397 add_function("__intrinsic_atomic_add",
1398 _atomic_intrinsic2(buffer_atomics_supported,
1399 glsl_type::uint_type,
1400 ir_intrinsic_generic_atomic_add),
1401 _atomic_intrinsic2(buffer_atomics_supported,
1402 glsl_type::int_type,
1403 ir_intrinsic_generic_atomic_add),
1404 _atomic_intrinsic2(NV_shader_atomic_float_supported,
1405 glsl_type::float_type,
1406 ir_intrinsic_generic_atomic_add),
1407 _atomic_intrinsic2(buffer_int64_atomics_supported,
1408 glsl_type::int64_t_type,
1409 ir_intrinsic_generic_atomic_add),
1410 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1411 ir_intrinsic_atomic_counter_add),
1412 NULL);
1413 add_function("__intrinsic_atomic_min",
1414 _atomic_intrinsic2(buffer_atomics_supported,
1415 glsl_type::uint_type,
1416 ir_intrinsic_generic_atomic_min),
1417 _atomic_intrinsic2(buffer_atomics_supported,
1418 glsl_type::int_type,
1419 ir_intrinsic_generic_atomic_min),
1420 _atomic_intrinsic2(INTEL_shader_atomic_float_minmax_supported,
1421 glsl_type::float_type,
1422 ir_intrinsic_generic_atomic_min),
1423 _atomic_intrinsic2(buffer_int64_atomics_supported,
1424 glsl_type::uint64_t_type,
1425 ir_intrinsic_generic_atomic_min),
1426 _atomic_intrinsic2(buffer_int64_atomics_supported,
1427 glsl_type::int64_t_type,
1428 ir_intrinsic_generic_atomic_min),
1429 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1430 ir_intrinsic_atomic_counter_min),
1431 NULL);
1432 add_function("__intrinsic_atomic_max",
1433 _atomic_intrinsic2(buffer_atomics_supported,
1434 glsl_type::uint_type,
1435 ir_intrinsic_generic_atomic_max),
1436 _atomic_intrinsic2(buffer_atomics_supported,
1437 glsl_type::int_type,
1438 ir_intrinsic_generic_atomic_max),
1439 _atomic_intrinsic2(INTEL_shader_atomic_float_minmax_supported,
1440 glsl_type::float_type,
1441 ir_intrinsic_generic_atomic_max),
1442 _atomic_intrinsic2(buffer_int64_atomics_supported,
1443 glsl_type::uint64_t_type,
1444 ir_intrinsic_generic_atomic_max),
1445 _atomic_intrinsic2(buffer_int64_atomics_supported,
1446 glsl_type::int64_t_type,
1447 ir_intrinsic_generic_atomic_max),
1448 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1449 ir_intrinsic_atomic_counter_max),
1450 NULL);
1451 add_function("__intrinsic_atomic_and",
1452 _atomic_intrinsic2(buffer_atomics_supported,
1453 glsl_type::uint_type,
1454 ir_intrinsic_generic_atomic_and),
1455 _atomic_intrinsic2(buffer_atomics_supported,
1456 glsl_type::int_type,
1457 ir_intrinsic_generic_atomic_and),
1458 _atomic_intrinsic2(buffer_int64_atomics_supported,
1459 glsl_type::uint64_t_type,
1460 ir_intrinsic_generic_atomic_and),
1461 _atomic_intrinsic2(buffer_int64_atomics_supported,
1462 glsl_type::int64_t_type,
1463 ir_intrinsic_generic_atomic_and),
1464 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1465 ir_intrinsic_atomic_counter_and),
1466 NULL);
1467 add_function("__intrinsic_atomic_or",
1468 _atomic_intrinsic2(buffer_atomics_supported,
1469 glsl_type::uint_type,
1470 ir_intrinsic_generic_atomic_or),
1471 _atomic_intrinsic2(buffer_atomics_supported,
1472 glsl_type::int_type,
1473 ir_intrinsic_generic_atomic_or),
1474 _atomic_intrinsic2(buffer_int64_atomics_supported,
1475 glsl_type::uint64_t_type,
1476 ir_intrinsic_generic_atomic_or),
1477 _atomic_intrinsic2(buffer_int64_atomics_supported,
1478 glsl_type::int64_t_type,
1479 ir_intrinsic_generic_atomic_or),
1480 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1481 ir_intrinsic_atomic_counter_or),
1482 NULL);
1483 add_function("__intrinsic_atomic_xor",
1484 _atomic_intrinsic2(buffer_atomics_supported,
1485 glsl_type::uint_type,
1486 ir_intrinsic_generic_atomic_xor),
1487 _atomic_intrinsic2(buffer_atomics_supported,
1488 glsl_type::int_type,
1489 ir_intrinsic_generic_atomic_xor),
1490 _atomic_intrinsic2(buffer_int64_atomics_supported,
1491 glsl_type::uint64_t_type,
1492 ir_intrinsic_generic_atomic_xor),
1493 _atomic_intrinsic2(buffer_int64_atomics_supported,
1494 glsl_type::int64_t_type,
1495 ir_intrinsic_generic_atomic_xor),
1496 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1497 ir_intrinsic_atomic_counter_xor),
1498 NULL);
1499 add_function("__intrinsic_atomic_exchange",
1500 _atomic_intrinsic2(buffer_atomics_supported,
1501 glsl_type::uint_type,
1502 ir_intrinsic_generic_atomic_exchange),
1503 _atomic_intrinsic2(buffer_atomics_supported,
1504 glsl_type::int_type,
1505 ir_intrinsic_generic_atomic_exchange),
1506 _atomic_intrinsic2(buffer_int64_atomics_supported,
1507 glsl_type::int64_t_type,
1508 ir_intrinsic_generic_atomic_exchange),
1509 _atomic_intrinsic2(NV_shader_atomic_float_supported,
1510 glsl_type::float_type,
1511 ir_intrinsic_generic_atomic_exchange),
1512 _atomic_counter_intrinsic1(shader_atomic_counter_ops_or_v460_desktop,
1513 ir_intrinsic_atomic_counter_exchange),
1514 NULL);
1515 add_function("__intrinsic_atomic_comp_swap",
1516 _atomic_intrinsic3(buffer_atomics_supported,
1517 glsl_type::uint_type,
1518 ir_intrinsic_generic_atomic_comp_swap),
1519 _atomic_intrinsic3(buffer_atomics_supported,
1520 glsl_type::int_type,
1521 ir_intrinsic_generic_atomic_comp_swap),
1522 _atomic_intrinsic3(buffer_int64_atomics_supported,
1523 glsl_type::int64_t_type,
1524 ir_intrinsic_generic_atomic_comp_swap),
1525 _atomic_intrinsic3(INTEL_shader_atomic_float_minmax_supported,
1526 glsl_type::float_type,
1527 ir_intrinsic_generic_atomic_comp_swap),
1528 _atomic_counter_intrinsic2(shader_atomic_counter_ops_or_v460_desktop,
1529 ir_intrinsic_atomic_counter_comp_swap),
1530 NULL);
1531
1532 add_image_functions(false);
1533
1534 add_function("__intrinsic_memory_barrier",
1535 _memory_barrier_intrinsic(shader_image_load_store,
1536 ir_intrinsic_memory_barrier),
1537 NULL);
1538 add_function("__intrinsic_group_memory_barrier",
1539 _memory_barrier_intrinsic(compute_shader,
1540 ir_intrinsic_group_memory_barrier),
1541 NULL);
1542 add_function("__intrinsic_memory_barrier_atomic_counter",
1543 _memory_barrier_intrinsic(compute_shader_supported,
1544 ir_intrinsic_memory_barrier_atomic_counter),
1545 NULL);
1546 add_function("__intrinsic_memory_barrier_buffer",
1547 _memory_barrier_intrinsic(compute_shader_supported,
1548 ir_intrinsic_memory_barrier_buffer),
1549 NULL);
1550 add_function("__intrinsic_memory_barrier_image",
1551 _memory_barrier_intrinsic(compute_shader_supported,
1552 ir_intrinsic_memory_barrier_image),
1553 NULL);
1554 add_function("__intrinsic_memory_barrier_shared",
1555 _memory_barrier_intrinsic(compute_shader,
1556 ir_intrinsic_memory_barrier_shared),
1557 NULL);
1558
1559 add_function("__intrinsic_begin_invocation_interlock",
1560 _invocation_interlock_intrinsic(
1561 supports_arb_fragment_shader_interlock,
1562 ir_intrinsic_begin_invocation_interlock), NULL);
1563
1564 add_function("__intrinsic_end_invocation_interlock",
1565 _invocation_interlock_intrinsic(
1566 supports_arb_fragment_shader_interlock,
1567 ir_intrinsic_end_invocation_interlock), NULL);
1568
1569 add_function("__intrinsic_shader_clock",
1570 _shader_clock_intrinsic(shader_clock,
1571 glsl_type::uvec2_type),
1572 NULL);
1573
1574 add_function("__intrinsic_vote_all",
1575 _vote_intrinsic(vote_or_v460_desktop, ir_intrinsic_vote_all),
1576 NULL);
1577 add_function("__intrinsic_vote_any",
1578 _vote_intrinsic(vote_or_v460_desktop, ir_intrinsic_vote_any),
1579 NULL);
1580 add_function("__intrinsic_vote_eq",
1581 _vote_intrinsic(vote_or_v460_desktop, ir_intrinsic_vote_eq),
1582 NULL);
1583
1584 add_function("__intrinsic_ballot", _ballot_intrinsic(), NULL);
1585
1586 add_function("__intrinsic_read_invocation",
1587 _read_invocation_intrinsic(glsl_type::float_type),
1588 _read_invocation_intrinsic(glsl_type::vec2_type),
1589 _read_invocation_intrinsic(glsl_type::vec3_type),
1590 _read_invocation_intrinsic(glsl_type::vec4_type),
1591
1592 _read_invocation_intrinsic(glsl_type::int_type),
1593 _read_invocation_intrinsic(glsl_type::ivec2_type),
1594 _read_invocation_intrinsic(glsl_type::ivec3_type),
1595 _read_invocation_intrinsic(glsl_type::ivec4_type),
1596
1597 _read_invocation_intrinsic(glsl_type::uint_type),
1598 _read_invocation_intrinsic(glsl_type::uvec2_type),
1599 _read_invocation_intrinsic(glsl_type::uvec3_type),
1600 _read_invocation_intrinsic(glsl_type::uvec4_type),
1601 NULL);
1602
1603 add_function("__intrinsic_read_first_invocation",
1604 _read_first_invocation_intrinsic(glsl_type::float_type),
1605 _read_first_invocation_intrinsic(glsl_type::vec2_type),
1606 _read_first_invocation_intrinsic(glsl_type::vec3_type),
1607 _read_first_invocation_intrinsic(glsl_type::vec4_type),
1608
1609 _read_first_invocation_intrinsic(glsl_type::int_type),
1610 _read_first_invocation_intrinsic(glsl_type::ivec2_type),
1611 _read_first_invocation_intrinsic(glsl_type::ivec3_type),
1612 _read_first_invocation_intrinsic(glsl_type::ivec4_type),
1613
1614 _read_first_invocation_intrinsic(glsl_type::uint_type),
1615 _read_first_invocation_intrinsic(glsl_type::uvec2_type),
1616 _read_first_invocation_intrinsic(glsl_type::uvec3_type),
1617 _read_first_invocation_intrinsic(glsl_type::uvec4_type),
1618 NULL);
1619
1620 add_function("__intrinsic_helper_invocation",
1621 _helper_invocation_intrinsic(), NULL);
1622 }
1623
1624 /**
1625 * Create ir_function and ir_function_signature objects for each built-in.
1626 *
1627 * Contains a list of every available built-in.
1628 */
1629 void
create_builtins()1630 builtin_builder::create_builtins()
1631 {
1632 #define F(NAME) \
1633 add_function(#NAME, \
1634 _##NAME(glsl_type::float_type), \
1635 _##NAME(glsl_type::vec2_type), \
1636 _##NAME(glsl_type::vec3_type), \
1637 _##NAME(glsl_type::vec4_type), \
1638 NULL);
1639
1640 #define FD(NAME) \
1641 add_function(#NAME, \
1642 _##NAME(always_available, glsl_type::float_type), \
1643 _##NAME(always_available, glsl_type::vec2_type), \
1644 _##NAME(always_available, glsl_type::vec3_type), \
1645 _##NAME(always_available, glsl_type::vec4_type), \
1646 _##NAME(fp64, glsl_type::double_type), \
1647 _##NAME(fp64, glsl_type::dvec2_type), \
1648 _##NAME(fp64, glsl_type::dvec3_type), \
1649 _##NAME(fp64, glsl_type::dvec4_type), \
1650 NULL);
1651
1652 #define FD130(NAME) \
1653 add_function(#NAME, \
1654 _##NAME(v130, glsl_type::float_type), \
1655 _##NAME(v130, glsl_type::vec2_type), \
1656 _##NAME(v130, glsl_type::vec3_type), \
1657 _##NAME(v130, glsl_type::vec4_type), \
1658 _##NAME(fp64, glsl_type::double_type), \
1659 _##NAME(fp64, glsl_type::dvec2_type), \
1660 _##NAME(fp64, glsl_type::dvec3_type), \
1661 _##NAME(fp64, glsl_type::dvec4_type), \
1662 NULL);
1663
1664 #define FD130GS4(NAME) \
1665 add_function(#NAME, \
1666 _##NAME(v130_or_gpu_shader4, glsl_type::float_type), \
1667 _##NAME(v130_or_gpu_shader4, glsl_type::vec2_type), \
1668 _##NAME(v130_or_gpu_shader4, glsl_type::vec3_type), \
1669 _##NAME(v130_or_gpu_shader4, glsl_type::vec4_type), \
1670 _##NAME(fp64, glsl_type::double_type), \
1671 _##NAME(fp64, glsl_type::dvec2_type), \
1672 _##NAME(fp64, glsl_type::dvec3_type), \
1673 _##NAME(fp64, glsl_type::dvec4_type), \
1674 NULL);
1675
1676 #define FDGS5(NAME) \
1677 add_function(#NAME, \
1678 _##NAME(gpu_shader5_es, glsl_type::float_type), \
1679 _##NAME(gpu_shader5_es, glsl_type::vec2_type), \
1680 _##NAME(gpu_shader5_es, glsl_type::vec3_type), \
1681 _##NAME(gpu_shader5_es, glsl_type::vec4_type), \
1682 _##NAME(fp64, glsl_type::double_type), \
1683 _##NAME(fp64, glsl_type::dvec2_type), \
1684 _##NAME(fp64, glsl_type::dvec3_type), \
1685 _##NAME(fp64, glsl_type::dvec4_type), \
1686 NULL);
1687
1688 #define FI(NAME) \
1689 add_function(#NAME, \
1690 _##NAME(glsl_type::float_type), \
1691 _##NAME(glsl_type::vec2_type), \
1692 _##NAME(glsl_type::vec3_type), \
1693 _##NAME(glsl_type::vec4_type), \
1694 _##NAME(glsl_type::int_type), \
1695 _##NAME(glsl_type::ivec2_type), \
1696 _##NAME(glsl_type::ivec3_type), \
1697 _##NAME(glsl_type::ivec4_type), \
1698 NULL);
1699
1700 #define FI64(NAME) \
1701 add_function(#NAME, \
1702 _##NAME(always_available, glsl_type::float_type), \
1703 _##NAME(always_available, glsl_type::vec2_type), \
1704 _##NAME(always_available, glsl_type::vec3_type), \
1705 _##NAME(always_available, glsl_type::vec4_type), \
1706 _##NAME(always_available, glsl_type::int_type), \
1707 _##NAME(always_available, glsl_type::ivec2_type), \
1708 _##NAME(always_available, glsl_type::ivec3_type), \
1709 _##NAME(always_available, glsl_type::ivec4_type), \
1710 _##NAME(fp64, glsl_type::double_type), \
1711 _##NAME(fp64, glsl_type::dvec2_type), \
1712 _##NAME(fp64, glsl_type::dvec3_type), \
1713 _##NAME(fp64, glsl_type::dvec4_type), \
1714 _##NAME(int64_avail, glsl_type::int64_t_type), \
1715 _##NAME(int64_avail, glsl_type::i64vec2_type), \
1716 _##NAME(int64_avail, glsl_type::i64vec3_type), \
1717 _##NAME(int64_avail, glsl_type::i64vec4_type), \
1718 NULL);
1719
1720 #define FIUD_VEC(NAME) \
1721 add_function(#NAME, \
1722 _##NAME(always_available, glsl_type::vec2_type), \
1723 _##NAME(always_available, glsl_type::vec3_type), \
1724 _##NAME(always_available, glsl_type::vec4_type), \
1725 \
1726 _##NAME(always_available, glsl_type::ivec2_type), \
1727 _##NAME(always_available, glsl_type::ivec3_type), \
1728 _##NAME(always_available, glsl_type::ivec4_type), \
1729 \
1730 _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type), \
1731 _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type), \
1732 _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type), \
1733 _##NAME(fp64, glsl_type::dvec2_type), \
1734 _##NAME(fp64, glsl_type::dvec3_type), \
1735 _##NAME(fp64, glsl_type::dvec4_type), \
1736 _##NAME(int64_avail, glsl_type::int64_t_type), \
1737 _##NAME(int64_avail, glsl_type::i64vec2_type), \
1738 _##NAME(int64_avail, glsl_type::i64vec3_type), \
1739 _##NAME(int64_avail, glsl_type::i64vec4_type), \
1740 _##NAME(int64_avail, glsl_type::uint64_t_type), \
1741 _##NAME(int64_avail, glsl_type::u64vec2_type), \
1742 _##NAME(int64_avail, glsl_type::u64vec3_type), \
1743 _##NAME(int64_avail, glsl_type::u64vec4_type), \
1744 NULL);
1745
1746 #define IU(NAME) \
1747 add_function(#NAME, \
1748 _##NAME(glsl_type::int_type), \
1749 _##NAME(glsl_type::ivec2_type), \
1750 _##NAME(glsl_type::ivec3_type), \
1751 _##NAME(glsl_type::ivec4_type), \
1752 \
1753 _##NAME(glsl_type::uint_type), \
1754 _##NAME(glsl_type::uvec2_type), \
1755 _##NAME(glsl_type::uvec3_type), \
1756 _##NAME(glsl_type::uvec4_type), \
1757 NULL);
1758
1759 #define FIUBD_VEC(NAME) \
1760 add_function(#NAME, \
1761 _##NAME(always_available, glsl_type::vec2_type), \
1762 _##NAME(always_available, glsl_type::vec3_type), \
1763 _##NAME(always_available, glsl_type::vec4_type), \
1764 \
1765 _##NAME(always_available, glsl_type::ivec2_type), \
1766 _##NAME(always_available, glsl_type::ivec3_type), \
1767 _##NAME(always_available, glsl_type::ivec4_type), \
1768 \
1769 _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type), \
1770 _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type), \
1771 _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type), \
1772 \
1773 _##NAME(always_available, glsl_type::bvec2_type), \
1774 _##NAME(always_available, glsl_type::bvec3_type), \
1775 _##NAME(always_available, glsl_type::bvec4_type), \
1776 \
1777 _##NAME(fp64, glsl_type::dvec2_type), \
1778 _##NAME(fp64, glsl_type::dvec3_type), \
1779 _##NAME(fp64, glsl_type::dvec4_type), \
1780 _##NAME(int64_avail, glsl_type::int64_t_type), \
1781 _##NAME(int64_avail, glsl_type::i64vec2_type), \
1782 _##NAME(int64_avail, glsl_type::i64vec3_type), \
1783 _##NAME(int64_avail, glsl_type::i64vec4_type), \
1784 _##NAME(int64_avail, glsl_type::uint64_t_type), \
1785 _##NAME(int64_avail, glsl_type::u64vec2_type), \
1786 _##NAME(int64_avail, glsl_type::u64vec3_type), \
1787 _##NAME(int64_avail, glsl_type::u64vec4_type), \
1788 NULL);
1789
1790 #define FIUD2_MIXED(NAME) \
1791 add_function(#NAME, \
1792 _##NAME(always_available, glsl_type::float_type, glsl_type::float_type), \
1793 _##NAME(always_available, glsl_type::vec2_type, glsl_type::float_type), \
1794 _##NAME(always_available, glsl_type::vec3_type, glsl_type::float_type), \
1795 _##NAME(always_available, glsl_type::vec4_type, glsl_type::float_type), \
1796 \
1797 _##NAME(always_available, glsl_type::vec2_type, glsl_type::vec2_type), \
1798 _##NAME(always_available, glsl_type::vec3_type, glsl_type::vec3_type), \
1799 _##NAME(always_available, glsl_type::vec4_type, glsl_type::vec4_type), \
1800 \
1801 _##NAME(always_available, glsl_type::int_type, glsl_type::int_type), \
1802 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::int_type), \
1803 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::int_type), \
1804 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::int_type), \
1805 \
1806 _##NAME(always_available, glsl_type::ivec2_type, glsl_type::ivec2_type), \
1807 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
1808 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
1809 \
1810 _##NAME(v130_or_gpu_shader4, glsl_type::uint_type, glsl_type::uint_type), \
1811 _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type, glsl_type::uint_type), \
1812 _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type, glsl_type::uint_type), \
1813 _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type, glsl_type::uint_type), \
1814 \
1815 _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type, glsl_type::uvec2_type), \
1816 _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type, glsl_type::uvec3_type), \
1817 _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type, glsl_type::uvec4_type), \
1818 \
1819 _##NAME(fp64, glsl_type::double_type, glsl_type::double_type), \
1820 _##NAME(fp64, glsl_type::dvec2_type, glsl_type::double_type), \
1821 _##NAME(fp64, glsl_type::dvec3_type, glsl_type::double_type), \
1822 _##NAME(fp64, glsl_type::dvec4_type, glsl_type::double_type), \
1823 _##NAME(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type), \
1824 _##NAME(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type), \
1825 _##NAME(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type), \
1826 \
1827 _##NAME(int64_avail, glsl_type::int64_t_type, glsl_type::int64_t_type), \
1828 _##NAME(int64_avail, glsl_type::i64vec2_type, glsl_type::int64_t_type), \
1829 _##NAME(int64_avail, glsl_type::i64vec3_type, glsl_type::int64_t_type), \
1830 _##NAME(int64_avail, glsl_type::i64vec4_type, glsl_type::int64_t_type), \
1831 _##NAME(int64_avail, glsl_type::i64vec2_type, glsl_type::i64vec2_type), \
1832 _##NAME(int64_avail, glsl_type::i64vec3_type, glsl_type::i64vec3_type), \
1833 _##NAME(int64_avail, glsl_type::i64vec4_type, glsl_type::i64vec4_type), \
1834 _##NAME(int64_avail, glsl_type::uint64_t_type, glsl_type::uint64_t_type), \
1835 _##NAME(int64_avail, glsl_type::u64vec2_type, glsl_type::uint64_t_type), \
1836 _##NAME(int64_avail, glsl_type::u64vec3_type, glsl_type::uint64_t_type), \
1837 _##NAME(int64_avail, glsl_type::u64vec4_type, glsl_type::uint64_t_type), \
1838 _##NAME(int64_avail, glsl_type::u64vec2_type, glsl_type::u64vec2_type), \
1839 _##NAME(int64_avail, glsl_type::u64vec3_type, glsl_type::u64vec3_type), \
1840 _##NAME(int64_avail, glsl_type::u64vec4_type, glsl_type::u64vec4_type), \
1841 NULL);
1842
1843 F(radians)
1844 F(degrees)
1845 F(sin)
1846 F(cos)
1847 F(tan)
1848 F(asin)
1849 F(acos)
1850
1851 add_function("atan",
1852 _atan(glsl_type::float_type),
1853 _atan(glsl_type::vec2_type),
1854 _atan(glsl_type::vec3_type),
1855 _atan(glsl_type::vec4_type),
1856 _atan2(glsl_type::float_type),
1857 _atan2(glsl_type::vec2_type),
1858 _atan2(glsl_type::vec3_type),
1859 _atan2(glsl_type::vec4_type),
1860 _atan_op(glsl_type::float_type),
1861 _atan_op(glsl_type::vec2_type),
1862 _atan_op(glsl_type::vec3_type),
1863 _atan_op(glsl_type::vec4_type),
1864 _atan2_op(glsl_type::float_type),
1865 _atan2_op(glsl_type::vec2_type),
1866 _atan2_op(glsl_type::vec3_type),
1867 _atan2_op(glsl_type::vec4_type),
1868 NULL);
1869
1870 F(sinh)
1871 F(cosh)
1872 F(tanh)
1873 F(asinh)
1874 F(acosh)
1875 F(atanh)
1876 F(pow)
1877 F(exp)
1878 F(log)
1879 F(exp2)
1880 F(log2)
1881 FD(sqrt)
1882 FD(inversesqrt)
1883 FI64(abs)
1884 FI64(sign)
1885 FD(floor)
1886 FD130(trunc)
1887 FD130GS4(round)
1888 FD130(roundEven)
1889 FD(ceil)
1890 FD(fract)
1891
1892 add_function("truncate",
1893 _truncate(gpu_shader4, glsl_type::float_type),
1894 _truncate(gpu_shader4, glsl_type::vec2_type),
1895 _truncate(gpu_shader4, glsl_type::vec3_type),
1896 _truncate(gpu_shader4, glsl_type::vec4_type),
1897 NULL);
1898
1899
1900 add_function("mod",
1901 _mod(always_available, glsl_type::float_type, glsl_type::float_type),
1902 _mod(always_available, glsl_type::vec2_type, glsl_type::float_type),
1903 _mod(always_available, glsl_type::vec3_type, glsl_type::float_type),
1904 _mod(always_available, glsl_type::vec4_type, glsl_type::float_type),
1905
1906 _mod(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1907 _mod(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1908 _mod(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1909
1910 _mod(fp64, glsl_type::double_type, glsl_type::double_type),
1911 _mod(fp64, glsl_type::dvec2_type, glsl_type::double_type),
1912 _mod(fp64, glsl_type::dvec3_type, glsl_type::double_type),
1913 _mod(fp64, glsl_type::dvec4_type, glsl_type::double_type),
1914
1915 _mod(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1916 _mod(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1917 _mod(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1918 NULL);
1919
1920 FD130(modf)
1921
1922 FIUD2_MIXED(min)
1923 FIUD2_MIXED(max)
1924 FIUD2_MIXED(clamp)
1925
1926 add_function("mix",
1927 _mix_lrp(always_available, glsl_type::float_type, glsl_type::float_type),
1928 _mix_lrp(always_available, glsl_type::vec2_type, glsl_type::float_type),
1929 _mix_lrp(always_available, glsl_type::vec3_type, glsl_type::float_type),
1930 _mix_lrp(always_available, glsl_type::vec4_type, glsl_type::float_type),
1931
1932 _mix_lrp(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1933 _mix_lrp(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1934 _mix_lrp(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1935
1936 _mix_lrp(fp64, glsl_type::double_type, glsl_type::double_type),
1937 _mix_lrp(fp64, glsl_type::dvec2_type, glsl_type::double_type),
1938 _mix_lrp(fp64, glsl_type::dvec3_type, glsl_type::double_type),
1939 _mix_lrp(fp64, glsl_type::dvec4_type, glsl_type::double_type),
1940
1941 _mix_lrp(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1942 _mix_lrp(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1943 _mix_lrp(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1944
1945 _mix_sel(v130, glsl_type::float_type, glsl_type::bool_type),
1946 _mix_sel(v130, glsl_type::vec2_type, glsl_type::bvec2_type),
1947 _mix_sel(v130, glsl_type::vec3_type, glsl_type::bvec3_type),
1948 _mix_sel(v130, glsl_type::vec4_type, glsl_type::bvec4_type),
1949
1950 _mix_sel(fp64, glsl_type::double_type, glsl_type::bool_type),
1951 _mix_sel(fp64, glsl_type::dvec2_type, glsl_type::bvec2_type),
1952 _mix_sel(fp64, glsl_type::dvec3_type, glsl_type::bvec3_type),
1953 _mix_sel(fp64, glsl_type::dvec4_type, glsl_type::bvec4_type),
1954
1955 _mix_sel(shader_integer_mix, glsl_type::int_type, glsl_type::bool_type),
1956 _mix_sel(shader_integer_mix, glsl_type::ivec2_type, glsl_type::bvec2_type),
1957 _mix_sel(shader_integer_mix, glsl_type::ivec3_type, glsl_type::bvec3_type),
1958 _mix_sel(shader_integer_mix, glsl_type::ivec4_type, glsl_type::bvec4_type),
1959
1960 _mix_sel(shader_integer_mix, glsl_type::uint_type, glsl_type::bool_type),
1961 _mix_sel(shader_integer_mix, glsl_type::uvec2_type, glsl_type::bvec2_type),
1962 _mix_sel(shader_integer_mix, glsl_type::uvec3_type, glsl_type::bvec3_type),
1963 _mix_sel(shader_integer_mix, glsl_type::uvec4_type, glsl_type::bvec4_type),
1964
1965 _mix_sel(shader_integer_mix, glsl_type::bool_type, glsl_type::bool_type),
1966 _mix_sel(shader_integer_mix, glsl_type::bvec2_type, glsl_type::bvec2_type),
1967 _mix_sel(shader_integer_mix, glsl_type::bvec3_type, glsl_type::bvec3_type),
1968 _mix_sel(shader_integer_mix, glsl_type::bvec4_type, glsl_type::bvec4_type),
1969
1970 _mix_sel(int64_avail, glsl_type::int64_t_type, glsl_type::bool_type),
1971 _mix_sel(int64_avail, glsl_type::i64vec2_type, glsl_type::bvec2_type),
1972 _mix_sel(int64_avail, glsl_type::i64vec3_type, glsl_type::bvec3_type),
1973 _mix_sel(int64_avail, glsl_type::i64vec4_type, glsl_type::bvec4_type),
1974
1975 _mix_sel(int64_avail, glsl_type::uint64_t_type, glsl_type::bool_type),
1976 _mix_sel(int64_avail, glsl_type::u64vec2_type, glsl_type::bvec2_type),
1977 _mix_sel(int64_avail, glsl_type::u64vec3_type, glsl_type::bvec3_type),
1978 _mix_sel(int64_avail, glsl_type::u64vec4_type, glsl_type::bvec4_type),
1979 NULL);
1980
1981 add_function("step",
1982 _step(always_available, glsl_type::float_type, glsl_type::float_type),
1983 _step(always_available, glsl_type::float_type, glsl_type::vec2_type),
1984 _step(always_available, glsl_type::float_type, glsl_type::vec3_type),
1985 _step(always_available, glsl_type::float_type, glsl_type::vec4_type),
1986
1987 _step(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
1988 _step(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
1989 _step(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
1990 _step(fp64, glsl_type::double_type, glsl_type::double_type),
1991 _step(fp64, glsl_type::double_type, glsl_type::dvec2_type),
1992 _step(fp64, glsl_type::double_type, glsl_type::dvec3_type),
1993 _step(fp64, glsl_type::double_type, glsl_type::dvec4_type),
1994
1995 _step(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
1996 _step(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
1997 _step(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
1998 NULL);
1999
2000 add_function("smoothstep",
2001 _smoothstep(always_available, glsl_type::float_type, glsl_type::float_type),
2002 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec2_type),
2003 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec3_type),
2004 _smoothstep(always_available, glsl_type::float_type, glsl_type::vec4_type),
2005
2006 _smoothstep(always_available, glsl_type::vec2_type, glsl_type::vec2_type),
2007 _smoothstep(always_available, glsl_type::vec3_type, glsl_type::vec3_type),
2008 _smoothstep(always_available, glsl_type::vec4_type, glsl_type::vec4_type),
2009 _smoothstep(fp64, glsl_type::double_type, glsl_type::double_type),
2010 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec2_type),
2011 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec3_type),
2012 _smoothstep(fp64, glsl_type::double_type, glsl_type::dvec4_type),
2013
2014 _smoothstep(fp64, glsl_type::dvec2_type, glsl_type::dvec2_type),
2015 _smoothstep(fp64, glsl_type::dvec3_type, glsl_type::dvec3_type),
2016 _smoothstep(fp64, glsl_type::dvec4_type, glsl_type::dvec4_type),
2017 NULL);
2018
2019 FD130(isnan)
2020 FD130(isinf)
2021
2022 F(floatBitsToInt)
2023 F(floatBitsToUint)
2024 add_function("intBitsToFloat",
2025 _intBitsToFloat(glsl_type::int_type),
2026 _intBitsToFloat(glsl_type::ivec2_type),
2027 _intBitsToFloat(glsl_type::ivec3_type),
2028 _intBitsToFloat(glsl_type::ivec4_type),
2029 NULL);
2030 add_function("uintBitsToFloat",
2031 _uintBitsToFloat(glsl_type::uint_type),
2032 _uintBitsToFloat(glsl_type::uvec2_type),
2033 _uintBitsToFloat(glsl_type::uvec3_type),
2034 _uintBitsToFloat(glsl_type::uvec4_type),
2035 NULL);
2036
2037 add_function("doubleBitsToInt64",
2038 _doubleBitsToInt64(int64_fp64, glsl_type::double_type),
2039 _doubleBitsToInt64(int64_fp64, glsl_type::dvec2_type),
2040 _doubleBitsToInt64(int64_fp64, glsl_type::dvec3_type),
2041 _doubleBitsToInt64(int64_fp64, glsl_type::dvec4_type),
2042 NULL);
2043
2044 add_function("doubleBitsToUint64",
2045 _doubleBitsToUint64(int64_fp64, glsl_type::double_type),
2046 _doubleBitsToUint64(int64_fp64, glsl_type::dvec2_type),
2047 _doubleBitsToUint64(int64_fp64, glsl_type::dvec3_type),
2048 _doubleBitsToUint64(int64_fp64, glsl_type::dvec4_type),
2049 NULL);
2050
2051 add_function("int64BitsToDouble",
2052 _int64BitsToDouble(int64_fp64, glsl_type::int64_t_type),
2053 _int64BitsToDouble(int64_fp64, glsl_type::i64vec2_type),
2054 _int64BitsToDouble(int64_fp64, glsl_type::i64vec3_type),
2055 _int64BitsToDouble(int64_fp64, glsl_type::i64vec4_type),
2056 NULL);
2057
2058 add_function("uint64BitsToDouble",
2059 _uint64BitsToDouble(int64_fp64, glsl_type::uint64_t_type),
2060 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec2_type),
2061 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec3_type),
2062 _uint64BitsToDouble(int64_fp64, glsl_type::u64vec4_type),
2063 NULL);
2064
2065 add_function("packUnorm2x16", _packUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
2066 add_function("packSnorm2x16", _packSnorm2x16(shader_packing_or_es3), NULL);
2067 add_function("packUnorm4x8", _packUnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
2068 add_function("packSnorm4x8", _packSnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
2069 add_function("unpackUnorm2x16", _unpackUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
2070 add_function("unpackSnorm2x16", _unpackSnorm2x16(shader_packing_or_es3), NULL);
2071 add_function("unpackUnorm4x8", _unpackUnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
2072 add_function("unpackSnorm4x8", _unpackSnorm4x8(shader_packing_or_es31_or_gpu_shader5), NULL);
2073 add_function("packHalf2x16", _packHalf2x16(shader_packing_or_es3), NULL);
2074 add_function("unpackHalf2x16", _unpackHalf2x16(shader_packing_or_es3), NULL);
2075 add_function("packDouble2x32", _packDouble2x32(fp64), NULL);
2076 add_function("unpackDouble2x32", _unpackDouble2x32(fp64), NULL);
2077
2078 add_function("packInt2x32", _packInt2x32(int64_avail), NULL);
2079 add_function("unpackInt2x32", _unpackInt2x32(int64_avail), NULL);
2080 add_function("packUint2x32", _packUint2x32(int64_avail), NULL);
2081 add_function("unpackUint2x32", _unpackUint2x32(int64_avail), NULL);
2082
2083 FD(length)
2084 FD(distance)
2085 FD(dot)
2086
2087 add_function("cross", _cross(always_available, glsl_type::vec3_type),
2088 _cross(fp64, glsl_type::dvec3_type), NULL);
2089
2090 FD(normalize)
2091 add_function("ftransform", _ftransform(), NULL);
2092 FD(faceforward)
2093 FD(reflect)
2094 FD(refract)
2095 // ...
2096 add_function("matrixCompMult",
2097 _matrixCompMult(always_available, glsl_type::mat2_type),
2098 _matrixCompMult(always_available, glsl_type::mat3_type),
2099 _matrixCompMult(always_available, glsl_type::mat4_type),
2100 _matrixCompMult(always_available, glsl_type::mat2x3_type),
2101 _matrixCompMult(always_available, glsl_type::mat2x4_type),
2102 _matrixCompMult(always_available, glsl_type::mat3x2_type),
2103 _matrixCompMult(always_available, glsl_type::mat3x4_type),
2104 _matrixCompMult(always_available, glsl_type::mat4x2_type),
2105 _matrixCompMult(always_available, glsl_type::mat4x3_type),
2106 _matrixCompMult(fp64, glsl_type::dmat2_type),
2107 _matrixCompMult(fp64, glsl_type::dmat3_type),
2108 _matrixCompMult(fp64, glsl_type::dmat4_type),
2109 _matrixCompMult(fp64, glsl_type::dmat2x3_type),
2110 _matrixCompMult(fp64, glsl_type::dmat2x4_type),
2111 _matrixCompMult(fp64, glsl_type::dmat3x2_type),
2112 _matrixCompMult(fp64, glsl_type::dmat3x4_type),
2113 _matrixCompMult(fp64, glsl_type::dmat4x2_type),
2114 _matrixCompMult(fp64, glsl_type::dmat4x3_type),
2115 NULL);
2116 add_function("outerProduct",
2117 _outerProduct(v120, glsl_type::mat2_type),
2118 _outerProduct(v120, glsl_type::mat3_type),
2119 _outerProduct(v120, glsl_type::mat4_type),
2120 _outerProduct(v120, glsl_type::mat2x3_type),
2121 _outerProduct(v120, glsl_type::mat2x4_type),
2122 _outerProduct(v120, glsl_type::mat3x2_type),
2123 _outerProduct(v120, glsl_type::mat3x4_type),
2124 _outerProduct(v120, glsl_type::mat4x2_type),
2125 _outerProduct(v120, glsl_type::mat4x3_type),
2126 _outerProduct(fp64, glsl_type::dmat2_type),
2127 _outerProduct(fp64, glsl_type::dmat3_type),
2128 _outerProduct(fp64, glsl_type::dmat4_type),
2129 _outerProduct(fp64, glsl_type::dmat2x3_type),
2130 _outerProduct(fp64, glsl_type::dmat2x4_type),
2131 _outerProduct(fp64, glsl_type::dmat3x2_type),
2132 _outerProduct(fp64, glsl_type::dmat3x4_type),
2133 _outerProduct(fp64, glsl_type::dmat4x2_type),
2134 _outerProduct(fp64, glsl_type::dmat4x3_type),
2135 NULL);
2136 add_function("determinant",
2137 _determinant_mat2(v120, glsl_type::mat2_type),
2138 _determinant_mat3(v120, glsl_type::mat3_type),
2139 _determinant_mat4(v120, glsl_type::mat4_type),
2140 _determinant_mat2(fp64, glsl_type::dmat2_type),
2141 _determinant_mat3(fp64, glsl_type::dmat3_type),
2142 _determinant_mat4(fp64, glsl_type::dmat4_type),
2143
2144 NULL);
2145 add_function("inverse",
2146 _inverse_mat2(v140_or_es3, glsl_type::mat2_type),
2147 _inverse_mat3(v140_or_es3, glsl_type::mat3_type),
2148 _inverse_mat4(v140_or_es3, glsl_type::mat4_type),
2149 _inverse_mat2(fp64, glsl_type::dmat2_type),
2150 _inverse_mat3(fp64, glsl_type::dmat3_type),
2151 _inverse_mat4(fp64, glsl_type::dmat4_type),
2152 NULL);
2153 add_function("transpose",
2154 _transpose(v120, glsl_type::mat2_type),
2155 _transpose(v120, glsl_type::mat3_type),
2156 _transpose(v120, glsl_type::mat4_type),
2157 _transpose(v120, glsl_type::mat2x3_type),
2158 _transpose(v120, glsl_type::mat2x4_type),
2159 _transpose(v120, glsl_type::mat3x2_type),
2160 _transpose(v120, glsl_type::mat3x4_type),
2161 _transpose(v120, glsl_type::mat4x2_type),
2162 _transpose(v120, glsl_type::mat4x3_type),
2163 _transpose(fp64, glsl_type::dmat2_type),
2164 _transpose(fp64, glsl_type::dmat3_type),
2165 _transpose(fp64, glsl_type::dmat4_type),
2166 _transpose(fp64, glsl_type::dmat2x3_type),
2167 _transpose(fp64, glsl_type::dmat2x4_type),
2168 _transpose(fp64, glsl_type::dmat3x2_type),
2169 _transpose(fp64, glsl_type::dmat3x4_type),
2170 _transpose(fp64, glsl_type::dmat4x2_type),
2171 _transpose(fp64, glsl_type::dmat4x3_type),
2172 NULL);
2173 FIUD_VEC(lessThan)
2174 FIUD_VEC(lessThanEqual)
2175 FIUD_VEC(greaterThan)
2176 FIUD_VEC(greaterThanEqual)
2177 FIUBD_VEC(notEqual)
2178 FIUBD_VEC(equal)
2179
2180 add_function("any",
2181 _any(glsl_type::bvec2_type),
2182 _any(glsl_type::bvec3_type),
2183 _any(glsl_type::bvec4_type),
2184 NULL);
2185
2186 add_function("all",
2187 _all(glsl_type::bvec2_type),
2188 _all(glsl_type::bvec3_type),
2189 _all(glsl_type::bvec4_type),
2190 NULL);
2191
2192 add_function("not",
2193 _not(glsl_type::bvec2_type),
2194 _not(glsl_type::bvec3_type),
2195 _not(glsl_type::bvec4_type),
2196 NULL);
2197
2198 add_function("textureSize",
2199 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1D_type),
2200 _textureSize(v130, glsl_type::int_type, glsl_type::isampler1D_type),
2201 _textureSize(v130, glsl_type::int_type, glsl_type::usampler1D_type),
2202
2203 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2D_type),
2204 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2D_type),
2205 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2D_type),
2206
2207 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler3D_type),
2208 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler3D_type),
2209 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler3D_type),
2210
2211 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCube_type),
2212 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
2213 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
2214
2215 _textureSize(v130, glsl_type::int_type, glsl_type::sampler1DShadow_type),
2216 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DShadow_type),
2217 _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCubeShadow_type),
2218
2219 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
2220 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
2221 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
2222 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
2223 _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
2224 _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
2225
2226 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArrayShadow_type),
2227 _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArrayShadow_type),
2228
2229 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArray_type),
2230 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::isamplerCubeArray_type),
2231 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::usamplerCubeArray_type),
2232 _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArrayShadow_type),
2233
2234 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
2235 _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
2236 _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
2237 _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRectShadow_type),
2238
2239 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::samplerBuffer_type),
2240 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::isamplerBuffer_type),
2241 _textureSize(texture_buffer, glsl_type::int_type, glsl_type::usamplerBuffer_type),
2242 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::sampler2DMS_type),
2243 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::isampler2DMS_type),
2244 _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::usampler2DMS_type),
2245
2246 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::sampler2DMSArray_type),
2247 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::isampler2DMSArray_type),
2248 _textureSize(texture_multisample_array, glsl_type::ivec3_type, glsl_type::usampler2DMSArray_type),
2249
2250 _textureSize(texture_external_es3, glsl_type::ivec2_type, glsl_type::samplerExternalOES_type),
2251 NULL);
2252
2253 add_function("textureSize1D",
2254 _textureSize(gpu_shader4, glsl_type::int_type, glsl_type::sampler1D_type),
2255 _textureSize(gpu_shader4_integer, glsl_type::int_type, glsl_type::isampler1D_type),
2256 _textureSize(gpu_shader4_integer, glsl_type::int_type, glsl_type::usampler1D_type),
2257 NULL);
2258
2259 add_function("textureSize2D",
2260 _textureSize(gpu_shader4, glsl_type::ivec2_type, glsl_type::sampler2D_type),
2261 _textureSize(gpu_shader4_integer, glsl_type::ivec2_type, glsl_type::isampler2D_type),
2262 _textureSize(gpu_shader4_integer, glsl_type::ivec2_type, glsl_type::usampler2D_type),
2263 NULL);
2264
2265 add_function("textureSize3D",
2266 _textureSize(gpu_shader4, glsl_type::ivec3_type, glsl_type::sampler3D_type),
2267 _textureSize(gpu_shader4_integer, glsl_type::ivec3_type, glsl_type::isampler3D_type),
2268 _textureSize(gpu_shader4_integer, glsl_type::ivec3_type, glsl_type::usampler3D_type),
2269 NULL);
2270
2271 add_function("textureSizeCube",
2272 _textureSize(gpu_shader4, glsl_type::ivec2_type, glsl_type::samplerCube_type),
2273 _textureSize(gpu_shader4_integer, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
2274 _textureSize(gpu_shader4_integer, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
2275 NULL);
2276
2277 add_function("textureSize1DArray",
2278 _textureSize(gpu_shader4_array, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
2279 _textureSize(gpu_shader4_array_integer, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
2280 _textureSize(gpu_shader4_array_integer, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
2281 NULL);
2282
2283 add_function("textureSize2DArray",
2284 _textureSize(gpu_shader4_array, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
2285 _textureSize(gpu_shader4_array_integer, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
2286 _textureSize(gpu_shader4_array_integer, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
2287 NULL);
2288
2289 add_function("textureSize2DRect",
2290 _textureSize(gpu_shader4_rect, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
2291 _textureSize(gpu_shader4_rect_integer, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
2292 _textureSize(gpu_shader4_rect_integer, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
2293 NULL);
2294
2295 add_function("textureSizeBuffer",
2296 _textureSize(gpu_shader4_tbo, glsl_type::int_type, glsl_type::samplerBuffer_type),
2297 _textureSize(gpu_shader4_tbo_integer, glsl_type::int_type, glsl_type::isamplerBuffer_type),
2298 _textureSize(gpu_shader4_tbo_integer, glsl_type::int_type, glsl_type::usamplerBuffer_type),
2299 NULL);
2300
2301 add_function("textureSamples",
2302 _textureSamples(shader_samples, glsl_type::sampler2DMS_type),
2303 _textureSamples(shader_samples, glsl_type::isampler2DMS_type),
2304 _textureSamples(shader_samples, glsl_type::usampler2DMS_type),
2305
2306 _textureSamples(shader_samples, glsl_type::sampler2DMSArray_type),
2307 _textureSamples(shader_samples, glsl_type::isampler2DMSArray_type),
2308 _textureSamples(shader_samples, glsl_type::usampler2DMSArray_type),
2309 NULL);
2310
2311 add_function("texture",
2312 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2313 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
2314 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
2315
2316 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2317 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2318 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2319
2320 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2321 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
2322 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
2323
2324 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2325 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2326 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2327
2328 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2329 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2330 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
2331
2332 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2333 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
2334 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
2335
2336 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2337 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2338 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2339
2340 _texture(ir_tex, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2341 _texture(ir_tex, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2342 _texture(ir_tex, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2343
2344 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2345 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2346 /* samplerCubeArrayShadow is special; it has an extra parameter
2347 * for the shadow comparator since there is no vec5 type.
2348 */
2349 _textureCubeArrayShadow(ir_tex, texture_cube_map_array, glsl_type::samplerCubeArrayShadow_type),
2350
2351 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
2352 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
2353 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
2354
2355 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
2356
2357 _texture(ir_tex, texture_external_es3, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
2358
2359 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2360 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
2361 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
2362
2363 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2364 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2365 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2366
2367 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2368 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
2369 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
2370
2371 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2372 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2373 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2374
2375 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2376 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2377 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
2378
2379 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2380 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
2381 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
2382
2383 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2384 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2385 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2386
2387 _texture(ir_txb, derivatives_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2388 _texture(ir_txb, derivatives_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2389 _texture(ir_txb, derivatives_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2390
2391 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2392 _texture(ir_tex, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2393 _texture(ir_txb, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2394
2395 _textureCubeArrayShadow(ir_tex, v130_or_gpu_shader4_and_tex_cube_map_array, glsl_type::samplerCubeArrayShadow_type),
2396 _textureCubeArrayShadow(ir_txb, v130_or_gpu_shader4_and_tex_cube_map_array, glsl_type::samplerCubeArrayShadow_type),
2397 NULL);
2398
2399 add_function("textureLod",
2400 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
2401 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
2402 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
2403
2404 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
2405 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
2406 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
2407
2408 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
2409 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
2410 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
2411
2412 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
2413 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
2414 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
2415
2416 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
2417 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
2418
2419 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
2420 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
2421 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
2422
2423 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
2424 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
2425 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
2426
2427 _texture(ir_txl, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
2428 _texture(ir_txl, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
2429 _texture(ir_txl, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
2430
2431 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
2432 _texture(ir_txl, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
2433 _texture(ir_txl, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
2434 _textureCubeArrayShadow(ir_txl, v130_or_gpu_shader4_and_tex_cube_map_array, glsl_type::samplerCubeArrayShadow_type),
2435 NULL);
2436
2437 add_function("textureOffset",
2438 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2439 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2440 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2441
2442 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2443 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2444 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2445
2446 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2447 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2448 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2449
2450 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2451 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2452 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2453
2454 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2455
2456 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2457 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2458
2459 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2460 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2461 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2462
2463 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2464 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2465 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2466
2467 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2468 /* The next one was forgotten in GLSL 1.30 spec. It's from
2469 * EXT_gpu_shader4 originally. It was added in 4.30 with the
2470 * wrong syntax. This was corrected in 4.40. 4.30 indicates
2471 * that it was intended to be included previously, so allow it
2472 * in 1.30.
2473 */
2474 _texture(ir_tex, v130_desktop, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2475
2476 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2477 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2478 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2479
2480 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2481 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2482 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2483
2484 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2485 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2486 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2487
2488 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2489 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2490
2491 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2492 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2493 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2494
2495 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2496 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2497 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2498
2499 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2500 _texture(ir_tex, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2501 _texture(ir_txb, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2502 NULL);
2503
2504 add_function("texture1DOffset",
2505 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2506 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2507 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2508 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2509 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2510 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2511 NULL);
2512
2513 add_function("texture2DOffset",
2514 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2515 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2516 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2517 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2518 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2519 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2520 NULL);
2521
2522 add_function("texture3DOffset",
2523 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2524 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2525 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2526 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2527 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2528 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2529 NULL);
2530
2531 add_function("texture2DRectOffset",
2532 _texture(ir_tex, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2533 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2534 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
2535 NULL);
2536
2537 add_function("shadow2DRectOffset",
2538 _texture(ir_tex, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2539 NULL);
2540
2541 add_function("shadow1DOffset",
2542 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2543 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2544 NULL);
2545
2546 add_function("shadow2DOffset",
2547 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2548 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2549 NULL);
2550
2551 add_function("texture1DArrayOffset",
2552 _texture(ir_tex, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2553 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2554 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2555 _texture(ir_txb, gpu_shader4_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2556 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2557 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2558 NULL);
2559
2560 add_function("texture2DArrayOffset",
2561 _texture(ir_tex, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2562 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2563 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2564 _texture(ir_txb, gpu_shader4_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2565 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2566 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2567 NULL);
2568
2569 add_function("shadow1DArrayOffset",
2570 _texture(ir_tex, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2571 _texture(ir_txb, gpu_shader4_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2572 NULL);
2573
2574 add_function("shadow2DArrayOffset",
2575 _texture(ir_tex, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2576 NULL);
2577
2578 add_function("textureProj",
2579 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2580 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2581 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2582 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2583 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2584 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2585
2586 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2587 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2588 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2589 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2590 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2591 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2592
2593 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2594 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2595 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2596
2597 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2598 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2599
2600 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2601 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2602 _texture(ir_tex, texture_external_es3, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
2603 _texture(ir_tex, texture_external_es3, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
2604
2605 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
2606 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2607 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2608 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
2609
2610 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2611
2612 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2613 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2614 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2615 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2616 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2617 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2618
2619 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2620 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2621 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2622 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2623 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2624 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2625
2626 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2627 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2628 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2629
2630 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2631 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2632 NULL);
2633
2634 add_function("texelFetch",
2635 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
2636 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
2637 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
2638
2639 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
2640 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
2641 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
2642
2643 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
2644 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
2645 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
2646
2647 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
2648 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
2649 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
2650
2651 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
2652 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
2653 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
2654
2655 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
2656 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
2657 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
2658
2659 _texelFetch(texture_buffer, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
2660 _texelFetch(texture_buffer, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
2661 _texelFetch(texture_buffer, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
2662
2663 _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
2664 _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
2665 _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
2666
2667 _texelFetch(texture_multisample_array, glsl_type::vec4_type, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
2668 _texelFetch(texture_multisample_array, glsl_type::ivec4_type, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
2669 _texelFetch(texture_multisample_array, glsl_type::uvec4_type, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
2670
2671 _texelFetch(texture_external_es3, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::ivec2_type),
2672
2673 NULL);
2674
2675 add_function("texelFetch1D",
2676 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
2677 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
2678 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
2679 NULL);
2680
2681 add_function("texelFetch2D",
2682 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
2683 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
2684 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
2685 NULL);
2686
2687 add_function("texelFetch3D",
2688 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
2689 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
2690 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
2691 NULL);
2692
2693 add_function("texelFetch2DRect",
2694 _texelFetch(gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
2695 _texelFetch(gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
2696 _texelFetch(gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
2697 NULL);
2698
2699 add_function("texelFetch1DArray",
2700 _texelFetch(gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
2701 _texelFetch(gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
2702 _texelFetch(gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
2703 NULL);
2704
2705 add_function("texelFetch2DArray",
2706 _texelFetch(gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
2707 _texelFetch(gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
2708 _texelFetch(gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
2709 NULL);
2710
2711 add_function("texelFetchBuffer",
2712 _texelFetch(gpu_shader4_tbo, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
2713 _texelFetch(gpu_shader4_tbo_integer, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
2714 _texelFetch(gpu_shader4_tbo_integer, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
2715 NULL);
2716
2717 add_function("texelFetchOffset",
2718 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
2719 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
2720 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
2721
2722 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2723 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2724 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2725
2726 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2727 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2728 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2729
2730 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2731 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2732 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2733
2734 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2735 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2736 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2737
2738 _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2739 _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2740 _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2741
2742 NULL);
2743
2744 add_function("texelFetch1DOffset",
2745 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
2746 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
2747 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
2748 NULL);
2749
2750 add_function("texelFetch2DOffset",
2751 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2752 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2753 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2754 NULL);
2755
2756 add_function("texelFetch3DOffset",
2757 _texelFetch(gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2758 _texelFetch(gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2759 _texelFetch(gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
2760 NULL);
2761
2762 add_function("texelFetch2DRectOffset",
2763 _texelFetch(gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2764 _texelFetch(gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2765 _texelFetch(gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
2766 NULL);
2767
2768 add_function("texelFetch1DArrayOffset",
2769 _texelFetch(gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2770 _texelFetch(gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2771 _texelFetch(gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
2772 NULL);
2773
2774 add_function("texelFetch2DArrayOffset",
2775 _texelFetch(gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2776 _texelFetch(gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2777 _texelFetch(gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
2778 NULL);
2779
2780 add_function("textureProjOffset",
2781 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2782 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2783 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2784 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2785 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2786 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2787
2788 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2789 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2790 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2791 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2792 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2793 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2794
2795 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2796 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2797 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2798
2799 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2800 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2801
2802 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2803 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2804 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2805 _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2806 _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2807 _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2808
2809 _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2810
2811 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2812 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2813 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2814 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2815 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2816 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2817
2818 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2819 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2820 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2821 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2822 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2823 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2824
2825 _texture(ir_txb, v130_derivatives_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2826 _texture(ir_txb, v130_derivatives_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2827 _texture(ir_txb, v130_derivatives_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2828
2829 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2830 _texture(ir_txb, v130_derivatives_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2831 NULL);
2832
2833 add_function("texture1DProjOffset",
2834 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2835 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2836 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2837 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2838 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2839 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2840 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2841 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2842 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2843 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2844 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2845 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2846 NULL);
2847
2848 add_function("texture2DProjOffset",
2849 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2850 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2851 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2852 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2853 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2854 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2855 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2856 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2857 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2858 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2859 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2860 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2861 NULL);
2862
2863 add_function("texture3DProjOffset",
2864 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2865 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2866 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2867 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2868 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2869 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2870 NULL);
2871
2872 add_function("shadow1DProjOffset",
2873 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2874 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2875 NULL);
2876
2877 add_function("shadow2DProjOffset",
2878 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2879 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2880 NULL);
2881
2882 add_function("texture2DRectProjOffset",
2883 _texture(ir_tex, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2884 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2885 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2886 _texture(ir_tex, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2887 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2888 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2889 NULL);
2890
2891 add_function("shadow2DRectProjOffset",
2892 _texture(ir_tex, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2893 NULL);
2894
2895 add_function("textureLodOffset",
2896 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2897 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2898 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2899
2900 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2901 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2902 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2903
2904 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2905 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2906 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2907
2908 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2909 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2910
2911 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2912 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2913 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2914
2915 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2916 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2917 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2918
2919 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2920 _texture(ir_txl, v130_or_gpu_shader4_and_tex_shadow_lod, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
2921 NULL);
2922
2923 add_function("texture1DLodOffset",
2924 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
2925 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
2926 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
2927 NULL);
2928
2929 add_function("texture2DLodOffset",
2930 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2931 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2932 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
2933 NULL);
2934
2935 add_function("texture3DLodOffset",
2936 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2937 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2938 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
2939 NULL);
2940
2941 add_function("shadow1DLodOffset",
2942 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2943 NULL);
2944
2945 add_function("shadow2DLodOffset",
2946 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2947 NULL);
2948
2949 add_function("texture1DArrayLodOffset",
2950 _texture(ir_txl, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2951 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2952 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
2953 NULL);
2954
2955 add_function("texture2DArrayLodOffset",
2956 _texture(ir_txl, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2957 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2958 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
2959 NULL);
2960
2961 add_function("shadow1DArrayLodOffset",
2962 _texture(ir_txl, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
2963 NULL);
2964
2965 add_function("textureProjLod",
2966 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2967 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2968 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
2969 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2970 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2971 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
2972
2973 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2974 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2975 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
2976 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2977 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2978 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
2979
2980 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2981 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2982 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
2983
2984 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2985 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
2986 NULL);
2987
2988 add_function("textureProjLodOffset",
2989 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2990 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2991 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
2992 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2993 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2994 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
2995
2996 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2997 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2998 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
2999 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3000 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3001 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3002
3003 _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3004 _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3005 _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3006
3007 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3008 _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3009 NULL);
3010
3011 add_function("texture1DProjLodOffset",
3012 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3013 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3014 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3015 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3016 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3017 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3018 NULL);
3019
3020 add_function("texture2DProjLodOffset",
3021 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3022 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3023 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3024 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3025 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3026 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3027 NULL);
3028
3029 add_function("texture3DProjLodOffset",
3030 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3031 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3032 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3033 NULL);
3034
3035 add_function("shadow1DProjLodOffset",
3036 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3037 NULL);
3038
3039 add_function("shadow2DProjLodOffset",
3040 _texture(ir_txl, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3041 NULL);
3042
3043 add_function("textureGrad",
3044 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3045 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
3046 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
3047
3048 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3049 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3050 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3051
3052 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3053 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
3054 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
3055
3056 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3057 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3058 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3059
3060 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
3061 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
3062 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
3063
3064 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
3065
3066 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3067 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3068 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
3069
3070 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
3071 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
3072 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
3073
3074 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3075 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3076 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3077
3078 _texture(ir_txd, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
3079 _texture(ir_txd, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
3080 _texture(ir_txd, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
3081
3082 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
3083 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3084 NULL);
3085
3086 add_function("textureGradOffset",
3087 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
3088 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
3089 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
3090
3091 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3092 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3093 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3094
3095 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3096 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3097 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3098
3099 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3100 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3101 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3102
3103 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3104
3105 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3106 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3107
3108 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3109 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3110 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3111
3112 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3113 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3114 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3115
3116 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3117 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
3118 NULL);
3119
3120 add_function("texture1DGradOffset",
3121 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
3122 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
3123 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
3124 NULL);
3125
3126 add_function("texture2DGradOffset",
3127 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3128 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3129 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3130 NULL);
3131
3132 add_function("texture3DGradOffset",
3133 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3134 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3135 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
3136 NULL);
3137
3138 add_function("texture2DRectGradOffset",
3139 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3140 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3141 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
3142 NULL);
3143
3144 add_function("shadow2DRectGradOffset",
3145 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3146 NULL);
3147
3148 add_function("shadow1DGradOffset",
3149 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3150 NULL);
3151
3152 add_function("shadow2DGradOffset",
3153 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3154 NULL);
3155
3156 add_function("texture1DArrayGradOffset",
3157 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3158 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3159 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
3160 NULL);
3161
3162 add_function("texture2DArrayGradOffset",
3163 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3164 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3165 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3166 NULL);
3167
3168 add_function("shadow1DArrayGradOffset",
3169 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3170 NULL);
3171
3172 add_function("shadow2DArrayGradOffset",
3173 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
3174 NULL);
3175
3176 add_function("textureProjGrad",
3177 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3178 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3179 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3180 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3181 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3182 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3183
3184 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3185 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3186 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3187 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3188 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3189 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3190
3191 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3192 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3193 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3194
3195 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3196 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3197 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3198 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3199 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3200 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3201
3202 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3203
3204 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3205 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3206 NULL);
3207
3208 add_function("textureProjGradOffset",
3209 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3210 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3211 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3212 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3213 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3214 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3215
3216 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3217 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3218 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3219 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3220 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3221 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3222
3223 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3224 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3225 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3226
3227 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3228 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3229 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3230 _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3231 _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3232 _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3233
3234 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3235
3236 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3237 _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3238 NULL);
3239
3240 add_function("texture1DProjGradOffset",
3241 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3242 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3243 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
3244 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3245 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3246 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3247 NULL);
3248
3249 add_function("texture2DProjGradOffset",
3250 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3251 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3252 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3253 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3254 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3255 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3256 NULL);
3257
3258 add_function("texture3DProjGradOffset",
3259 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3260 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3261 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3262 NULL);
3263
3264 add_function("texture2DRectProjGradOffset",
3265 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3266 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3267 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
3268 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3269 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3270 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3271 NULL);
3272
3273 add_function("shadow2DRectProjGradOffset",
3274 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3275 NULL);
3276
3277 add_function("shadow1DProjGradOffset",
3278 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3279 NULL);
3280
3281 add_function("shadow2DProjGradOffset",
3282 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
3283 NULL);
3284
3285 add_function("EmitVertex", _EmitVertex(), NULL);
3286 add_function("EndPrimitive", _EndPrimitive(), NULL);
3287 add_function("EmitStreamVertex",
3288 _EmitStreamVertex(gs_streams, glsl_type::uint_type),
3289 _EmitStreamVertex(gs_streams, glsl_type::int_type),
3290 NULL);
3291 add_function("EndStreamPrimitive",
3292 _EndStreamPrimitive(gs_streams, glsl_type::uint_type),
3293 _EndStreamPrimitive(gs_streams, glsl_type::int_type),
3294 NULL);
3295 add_function("barrier", _barrier(), NULL);
3296
3297 add_function("textureQueryLOD",
3298 _textureQueryLod(texture_query_lod, glsl_type::sampler1D_type, glsl_type::float_type),
3299 _textureQueryLod(texture_query_lod, glsl_type::isampler1D_type, glsl_type::float_type),
3300 _textureQueryLod(texture_query_lod, glsl_type::usampler1D_type, glsl_type::float_type),
3301
3302 _textureQueryLod(texture_query_lod, glsl_type::sampler2D_type, glsl_type::vec2_type),
3303 _textureQueryLod(texture_query_lod, glsl_type::isampler2D_type, glsl_type::vec2_type),
3304 _textureQueryLod(texture_query_lod, glsl_type::usampler2D_type, glsl_type::vec2_type),
3305
3306 _textureQueryLod(texture_query_lod, glsl_type::sampler3D_type, glsl_type::vec3_type),
3307 _textureQueryLod(texture_query_lod, glsl_type::isampler3D_type, glsl_type::vec3_type),
3308 _textureQueryLod(texture_query_lod, glsl_type::usampler3D_type, glsl_type::vec3_type),
3309
3310 _textureQueryLod(texture_query_lod, glsl_type::samplerCube_type, glsl_type::vec3_type),
3311 _textureQueryLod(texture_query_lod, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3312 _textureQueryLod(texture_query_lod, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3313
3314 _textureQueryLod(texture_query_lod, glsl_type::sampler1DArray_type, glsl_type::float_type),
3315 _textureQueryLod(texture_query_lod, glsl_type::isampler1DArray_type, glsl_type::float_type),
3316 _textureQueryLod(texture_query_lod, glsl_type::usampler1DArray_type, glsl_type::float_type),
3317
3318 _textureQueryLod(texture_query_lod, glsl_type::sampler2DArray_type, glsl_type::vec2_type),
3319 _textureQueryLod(texture_query_lod, glsl_type::isampler2DArray_type, glsl_type::vec2_type),
3320 _textureQueryLod(texture_query_lod, glsl_type::usampler2DArray_type, glsl_type::vec2_type),
3321
3322 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
3323 _textureQueryLod(texture_query_lod, glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
3324 _textureQueryLod(texture_query_lod, glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
3325
3326 _textureQueryLod(texture_query_lod, glsl_type::sampler1DShadow_type, glsl_type::float_type),
3327 _textureQueryLod(texture_query_lod, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
3328 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
3329 _textureQueryLod(texture_query_lod, glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
3330 _textureQueryLod(texture_query_lod, glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
3331 _textureQueryLod(texture_query_lod, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
3332 NULL);
3333
3334 add_function("textureQueryLod",
3335 _textureQueryLod(v400_derivatives_only, glsl_type::sampler1D_type, glsl_type::float_type),
3336 _textureQueryLod(v400_derivatives_only, glsl_type::isampler1D_type, glsl_type::float_type),
3337 _textureQueryLod(v400_derivatives_only, glsl_type::usampler1D_type, glsl_type::float_type),
3338
3339 _textureQueryLod(v400_derivatives_only, glsl_type::sampler2D_type, glsl_type::vec2_type),
3340 _textureQueryLod(v400_derivatives_only, glsl_type::isampler2D_type, glsl_type::vec2_type),
3341 _textureQueryLod(v400_derivatives_only, glsl_type::usampler2D_type, glsl_type::vec2_type),
3342
3343 _textureQueryLod(v400_derivatives_only, glsl_type::sampler3D_type, glsl_type::vec3_type),
3344 _textureQueryLod(v400_derivatives_only, glsl_type::isampler3D_type, glsl_type::vec3_type),
3345 _textureQueryLod(v400_derivatives_only, glsl_type::usampler3D_type, glsl_type::vec3_type),
3346
3347 _textureQueryLod(v400_derivatives_only, glsl_type::samplerCube_type, glsl_type::vec3_type),
3348 _textureQueryLod(v400_derivatives_only, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3349 _textureQueryLod(v400_derivatives_only, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3350
3351 _textureQueryLod(v400_derivatives_only, glsl_type::sampler1DArray_type, glsl_type::float_type),
3352 _textureQueryLod(v400_derivatives_only, glsl_type::isampler1DArray_type, glsl_type::float_type),
3353 _textureQueryLod(v400_derivatives_only, glsl_type::usampler1DArray_type, glsl_type::float_type),
3354
3355 _textureQueryLod(v400_derivatives_only, glsl_type::sampler2DArray_type, glsl_type::vec2_type),
3356 _textureQueryLod(v400_derivatives_only, glsl_type::isampler2DArray_type, glsl_type::vec2_type),
3357 _textureQueryLod(v400_derivatives_only, glsl_type::usampler2DArray_type, glsl_type::vec2_type),
3358
3359 _textureQueryLod(v400_derivatives_only, glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
3360 _textureQueryLod(v400_derivatives_only, glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
3361 _textureQueryLod(v400_derivatives_only, glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
3362
3363 _textureQueryLod(v400_derivatives_only, glsl_type::sampler1DShadow_type, glsl_type::float_type),
3364 _textureQueryLod(v400_derivatives_only, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
3365 _textureQueryLod(v400_derivatives_only, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
3366 _textureQueryLod(v400_derivatives_only, glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
3367 _textureQueryLod(v400_derivatives_only, glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
3368 _textureQueryLod(v400_derivatives_only, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
3369 NULL);
3370
3371 add_function("textureQueryLevels",
3372 _textureQueryLevels(texture_query_levels, glsl_type::sampler1D_type),
3373 _textureQueryLevels(texture_query_levels, glsl_type::sampler2D_type),
3374 _textureQueryLevels(texture_query_levels, glsl_type::sampler3D_type),
3375 _textureQueryLevels(texture_query_levels, glsl_type::samplerCube_type),
3376 _textureQueryLevels(texture_query_levels, glsl_type::sampler1DArray_type),
3377 _textureQueryLevels(texture_query_levels, glsl_type::sampler2DArray_type),
3378 _textureQueryLevels(texture_query_levels, glsl_type::samplerCubeArray_type),
3379 _textureQueryLevels(texture_query_levels, glsl_type::sampler1DShadow_type),
3380 _textureQueryLevels(texture_query_levels, glsl_type::sampler2DShadow_type),
3381 _textureQueryLevels(texture_query_levels, glsl_type::samplerCubeShadow_type),
3382 _textureQueryLevels(texture_query_levels, glsl_type::sampler1DArrayShadow_type),
3383 _textureQueryLevels(texture_query_levels, glsl_type::sampler2DArrayShadow_type),
3384 _textureQueryLevels(texture_query_levels, glsl_type::samplerCubeArrayShadow_type),
3385
3386 _textureQueryLevels(texture_query_levels, glsl_type::isampler1D_type),
3387 _textureQueryLevels(texture_query_levels, glsl_type::isampler2D_type),
3388 _textureQueryLevels(texture_query_levels, glsl_type::isampler3D_type),
3389 _textureQueryLevels(texture_query_levels, glsl_type::isamplerCube_type),
3390 _textureQueryLevels(texture_query_levels, glsl_type::isampler1DArray_type),
3391 _textureQueryLevels(texture_query_levels, glsl_type::isampler2DArray_type),
3392 _textureQueryLevels(texture_query_levels, glsl_type::isamplerCubeArray_type),
3393
3394 _textureQueryLevels(texture_query_levels, glsl_type::usampler1D_type),
3395 _textureQueryLevels(texture_query_levels, glsl_type::usampler2D_type),
3396 _textureQueryLevels(texture_query_levels, glsl_type::usampler3D_type),
3397 _textureQueryLevels(texture_query_levels, glsl_type::usamplerCube_type),
3398 _textureQueryLevels(texture_query_levels, glsl_type::usampler1DArray_type),
3399 _textureQueryLevels(texture_query_levels, glsl_type::usampler2DArray_type),
3400 _textureQueryLevels(texture_query_levels, glsl_type::usamplerCubeArray_type),
3401
3402 NULL);
3403
3404 add_function("textureSamplesIdenticalEXT",
3405 _textureSamplesIdentical(texture_samples_identical, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
3406 _textureSamplesIdentical(texture_samples_identical, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
3407 _textureSamplesIdentical(texture_samples_identical, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
3408
3409 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
3410 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
3411 _textureSamplesIdentical(texture_samples_identical_array, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
3412 NULL);
3413
3414 add_function("texture1D",
3415 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3416 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3417 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
3418 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
3419 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
3420 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
3421 NULL);
3422
3423 add_function("texture1DArray",
3424 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
3425 _texture(ir_txb, texture_array_derivs_only,glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
3426 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
3427 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
3428 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
3429 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
3430 NULL);
3431
3432 add_function("texture1DProj",
3433 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3434 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3435 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3436 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3437 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3438 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3439 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3440 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3441 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3442 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3443 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3444 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3445 NULL);
3446
3447 add_function("texture1DLod",
3448 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3449 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
3450 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
3451 NULL);
3452
3453 add_function("texture1DArrayLod",
3454 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
3455 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
3456 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
3457 NULL);
3458
3459 add_function("texture1DProjLod",
3460 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3461 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3462 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3463 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3464 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3465 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3466 NULL);
3467
3468 add_function("texture2D",
3469 _texture(ir_tex, deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3470 _texture(ir_txb, deprecated_texture_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3471 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3472 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3473 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3474 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3475 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
3476 NULL);
3477
3478 add_function("texture2DArray",
3479 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3480 _texture(ir_txb, texture_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3481 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3482 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3483 _texture(ir_tex, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3484 _texture(ir_txb, gpu_shader4_array_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3485 NULL);
3486
3487 add_function("texture2DProj",
3488 _texture(ir_tex, deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3489 _texture(ir_tex, deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3490 _texture(ir_txb, deprecated_texture_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3491 _texture(ir_txb, deprecated_texture_derivatives_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3492 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3493 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3494 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3495 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3496 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3497 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3498 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3499 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3500 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
3501 _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
3502 NULL);
3503
3504 add_function("texture2DLod",
3505 _texture(ir_txl, lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3506 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3507 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3508 NULL);
3509
3510 add_function("texture2DArrayLod",
3511 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3512 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3513 _texture(ir_txl, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3514 NULL);
3515
3516 add_function("texture2DProjLod",
3517 _texture(ir_txl, lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3518 _texture(ir_txl, lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3519 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3520 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3521 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3522 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3523 NULL);
3524
3525 add_function("texture3D",
3526 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3527 _texture(ir_txb, derivatives_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3528 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
3529 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
3530 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
3531 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
3532 NULL);
3533
3534 add_function("texture3DProj",
3535 _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3536 _texture(ir_txb, derivatives_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3537 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3538 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3539 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3540 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3541 NULL);
3542
3543 add_function("texture3DLod",
3544 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3545 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
3546 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
3547 NULL);
3548
3549 add_function("texture3DProjLod",
3550 _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3551 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3552 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3553 NULL);
3554
3555 add_function("textureCube",
3556 _texture(ir_tex, deprecated_texture, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3557 _texture(ir_txb, deprecated_texture_derivatives_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3558 _texture(ir_tex, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3559 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3560 _texture(ir_tex, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3561 _texture(ir_txb, gpu_shader4_integer_derivs_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3562 NULL);
3563
3564 add_function("textureCubeLod",
3565 _texture(ir_txl, lod_deprecated_texture, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3566 _texture(ir_txl, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3567 _texture(ir_txl, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3568 NULL);
3569
3570 add_function("texture2DRect",
3571 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
3572 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
3573 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
3574 NULL);
3575
3576 add_function("texture2DRectProj",
3577 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3578 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3579 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3580 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3581 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3582 _texture(ir_tex, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3583 NULL);
3584
3585 add_function("shadow1D",
3586 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3587 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3588 NULL);
3589
3590 add_function("shadow1DArray",
3591 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
3592 _texture(ir_txb, texture_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
3593 NULL);
3594
3595 add_function("shadow2D",
3596 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3597 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3598 NULL);
3599
3600 add_function("shadow2DArray",
3601 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3602 _texture(ir_txb, texture_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3603 NULL);
3604
3605 add_function("shadow1DProj",
3606 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3607 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3608 NULL);
3609
3610 add_function("shadow2DArray",
3611 _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3612 _texture(ir_txb, texture_array_derivs_only, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3613 NULL);
3614
3615 add_function("shadowCube",
3616 _texture(ir_tex, gpu_shader4, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
3617 _texture(ir_txb, gpu_shader4_derivs_only, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
3618 NULL);
3619
3620 add_function("shadow2DProj",
3621 _texture(ir_tex, v110_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3622 _texture(ir_txb, v110_derivatives_only_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3623 NULL);
3624
3625 add_function("shadow1DLod",
3626 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3627 NULL);
3628
3629 add_function("shadow2DLod",
3630 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3631 NULL);
3632
3633 add_function("shadow1DArrayLod",
3634 _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
3635 NULL);
3636
3637 add_function("shadow1DProjLod",
3638 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3639 NULL);
3640
3641 add_function("shadow2DProjLod",
3642 _texture(ir_txl, v110_lod_deprecated_texture, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3643 NULL);
3644
3645 add_function("shadow2DRect",
3646 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
3647 NULL);
3648
3649 add_function("shadow2DRectProj",
3650 _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3651 NULL);
3652
3653 add_function("texture1DGradARB",
3654 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3655 NULL);
3656
3657 add_function("texture1DProjGradARB",
3658 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3659 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3660 NULL);
3661
3662 add_function("texture2DGradARB",
3663 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3664 NULL);
3665
3666 add_function("texture2DProjGradARB",
3667 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3668 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3669 NULL);
3670
3671 add_function("texture3DGradARB",
3672 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3673 NULL);
3674
3675 add_function("texture3DProjGradARB",
3676 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3677 NULL);
3678
3679 add_function("textureCubeGradARB",
3680 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3681 NULL);
3682
3683 add_function("shadow1DGradARB",
3684 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3685 NULL);
3686
3687 add_function("shadow1DProjGradARB",
3688 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3689 NULL);
3690
3691 add_function("shadow2DGradARB",
3692 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3693 NULL);
3694
3695 add_function("shadow2DProjGradARB",
3696 _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3697 NULL);
3698
3699 add_function("texture2DRectGradARB",
3700 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
3701 NULL);
3702
3703 add_function("texture2DRectProjGradARB",
3704 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3705 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3706 NULL);
3707
3708 add_function("shadow2DRectGradARB",
3709 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
3710 NULL);
3711
3712 add_function("shadow2DRectProjGradARB",
3713 _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3714 NULL);
3715
3716 add_function("texture4",
3717 _texture(ir_tg4, texture_texture4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3718 NULL);
3719
3720 add_function("texture1DGrad",
3721 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
3722 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
3723 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
3724 NULL);
3725
3726 add_function("texture1DProjGrad",
3727 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3728 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3729 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3730 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3731 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
3732 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
3733 NULL);
3734
3735 add_function("texture1DArrayGrad",
3736 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
3737 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
3738 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
3739 NULL);
3740
3741 add_function("texture2DGrad",
3742 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3743 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3744 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3745 NULL);
3746
3747 add_function("texture2DProjGrad",
3748 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3749 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3750 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3751 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3752 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
3753 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
3754 NULL);
3755
3756 add_function("texture2DArrayGrad",
3757 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3758 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3759 _texture(ir_txd, gpu_shader4_array_integer, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3760 NULL);
3761
3762 add_function("texture3DGrad",
3763 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
3764 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
3765 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
3766 NULL);
3767
3768 add_function("texture3DProjGrad",
3769 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3770 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3771 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
3772 NULL);
3773
3774 add_function("textureCubeGrad",
3775 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3776 _texture(ir_txd, gpu_shader4_integer, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3777 _texture(ir_txd, gpu_shader4_integer, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3778 NULL);
3779
3780 add_function("shadow1DGrad",
3781 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
3782 NULL);
3783
3784 add_function("shadow1DProjGrad",
3785 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3786 NULL);
3787
3788 add_function("shadow1DArrayGrad",
3789 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
3790 NULL);
3791
3792 add_function("shadow2DGrad",
3793 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
3794 NULL);
3795
3796 add_function("shadow2DProjGrad",
3797 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3798 NULL);
3799
3800 add_function("shadow2DArrayGrad",
3801 _texture(ir_txd, gpu_shader4_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
3802 NULL);
3803
3804 add_function("texture2DRectGrad",
3805 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
3806 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
3807 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
3808 NULL);
3809
3810 add_function("texture2DRectProjGrad",
3811 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3812 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3813 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3814 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3815 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
3816 _texture(ir_txd, gpu_shader4_rect_integer, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
3817 NULL);
3818
3819 add_function("shadow2DRectGrad",
3820 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
3821 NULL);
3822
3823 add_function("shadow2DRectProjGrad",
3824 _texture(ir_txd, gpu_shader4_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
3825 NULL);
3826
3827 add_function("shadowCubeGrad",
3828 _texture(ir_txd, gpu_shader4, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
3829 NULL);
3830
3831 add_function("textureGather",
3832 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
3833 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
3834 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
3835
3836 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
3837 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
3838 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
3839
3840 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
3841 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
3842 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
3843
3844 _texture(ir_tg4, texture_gather_or_es31, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
3845 _texture(ir_tg4, texture_gather_or_es31, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
3846 _texture(ir_tg4, texture_gather_or_es31, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
3847
3848 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
3849 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
3850 _texture(ir_tg4, texture_gather_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
3851
3852 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
3853 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
3854 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
3855
3856 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
3857 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
3858 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
3859
3860 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
3861 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
3862 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
3863
3864 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
3865 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
3866 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
3867
3868 _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),
3869 _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),
3870 _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),
3871
3872 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
3873 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type),
3874 _texture(ir_tg4, gpu_shader5_or_es31, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
3875 _texture(ir_tg4, gpu_shader5_or_OES_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec4_type),
3876 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type),
3877 NULL);
3878
3879 add_function("textureGatherOffset",
3880 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3881 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3882 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
3883
3884 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3885 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3886 _texture(ir_tg4, texture_gather_only_or_es31, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
3887
3888 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
3889 _texture(ir_tg4, es31_not_gs5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
3890 _texture(ir_tg4, es31_not_gs5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET | TEX_COMPONENT),
3891
3892 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
3893 _texture(ir_tg4, es31_not_gs5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
3894 _texture(ir_tg4, es31_not_gs5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET | TEX_COMPONENT),
3895
3896 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3897 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3898 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3899
3900 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
3901 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
3902 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
3903
3904 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3905 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3906 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3907
3908 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3909 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3910 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3911
3912 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3913 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3914 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3915
3916 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3917 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3918 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
3919
3920 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3921 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
3922 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
3923
3924 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET),
3925 _texture(ir_tg4, es31_not_gs5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
3926 NULL);
3927
3928 add_function("textureGatherOffsets",
3929 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3930 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3931 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3932
3933 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3934 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3935 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3936
3937 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
3938 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
3939 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
3940
3941 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3942 _texture(ir_tg4, gpu_shader5_es, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3943 _texture(ir_tg4, gpu_shader5_es, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3944
3945 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3946 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3947 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3948
3949 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3950 _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3951 _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
3952
3953 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3954 _texture(ir_tg4, gpu_shader5_es, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
3955 _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
3956 NULL);
3957
3958 F(dFdx)
3959 F(dFdy)
3960 F(fwidth)
3961 F(dFdxCoarse)
3962 F(dFdyCoarse)
3963 F(fwidthCoarse)
3964 F(dFdxFine)
3965 F(dFdyFine)
3966 F(fwidthFine)
3967 F(noise1)
3968 F(noise2)
3969 F(noise3)
3970 F(noise4)
3971
3972 IU(bitfieldExtract)
3973 IU(bitfieldInsert)
3974 IU(bitfieldReverse)
3975 IU(bitCount)
3976 IU(findLSB)
3977 IU(findMSB)
3978 FDGS5(fma)
3979
3980 add_function("ldexp",
3981 _ldexp(glsl_type::float_type, glsl_type::int_type),
3982 _ldexp(glsl_type::vec2_type, glsl_type::ivec2_type),
3983 _ldexp(glsl_type::vec3_type, glsl_type::ivec3_type),
3984 _ldexp(glsl_type::vec4_type, glsl_type::ivec4_type),
3985 _ldexp(glsl_type::double_type, glsl_type::int_type),
3986 _ldexp(glsl_type::dvec2_type, glsl_type::ivec2_type),
3987 _ldexp(glsl_type::dvec3_type, glsl_type::ivec3_type),
3988 _ldexp(glsl_type::dvec4_type, glsl_type::ivec4_type),
3989 NULL);
3990
3991 add_function("frexp",
3992 _frexp(glsl_type::float_type, glsl_type::int_type),
3993 _frexp(glsl_type::vec2_type, glsl_type::ivec2_type),
3994 _frexp(glsl_type::vec3_type, glsl_type::ivec3_type),
3995 _frexp(glsl_type::vec4_type, glsl_type::ivec4_type),
3996 _dfrexp(glsl_type::double_type, glsl_type::int_type),
3997 _dfrexp(glsl_type::dvec2_type, glsl_type::ivec2_type),
3998 _dfrexp(glsl_type::dvec3_type, glsl_type::ivec3_type),
3999 _dfrexp(glsl_type::dvec4_type, glsl_type::ivec4_type),
4000 NULL);
4001 add_function("uaddCarry",
4002 _uaddCarry(glsl_type::uint_type),
4003 _uaddCarry(glsl_type::uvec2_type),
4004 _uaddCarry(glsl_type::uvec3_type),
4005 _uaddCarry(glsl_type::uvec4_type),
4006 NULL);
4007 add_function("usubBorrow",
4008 _usubBorrow(glsl_type::uint_type),
4009 _usubBorrow(glsl_type::uvec2_type),
4010 _usubBorrow(glsl_type::uvec3_type),
4011 _usubBorrow(glsl_type::uvec4_type),
4012 NULL);
4013 add_function("imulExtended",
4014 _mulExtended(glsl_type::int_type),
4015 _mulExtended(glsl_type::ivec2_type),
4016 _mulExtended(glsl_type::ivec3_type),
4017 _mulExtended(glsl_type::ivec4_type),
4018 NULL);
4019 add_function("umulExtended",
4020 _mulExtended(glsl_type::uint_type),
4021 _mulExtended(glsl_type::uvec2_type),
4022 _mulExtended(glsl_type::uvec3_type),
4023 _mulExtended(glsl_type::uvec4_type),
4024 NULL);
4025 add_function("interpolateAtCentroid",
4026 _interpolateAtCentroid(glsl_type::float_type),
4027 _interpolateAtCentroid(glsl_type::vec2_type),
4028 _interpolateAtCentroid(glsl_type::vec3_type),
4029 _interpolateAtCentroid(glsl_type::vec4_type),
4030 NULL);
4031 add_function("interpolateAtOffset",
4032 _interpolateAtOffset(glsl_type::float_type),
4033 _interpolateAtOffset(glsl_type::vec2_type),
4034 _interpolateAtOffset(glsl_type::vec3_type),
4035 _interpolateAtOffset(glsl_type::vec4_type),
4036 NULL);
4037 add_function("interpolateAtSample",
4038 _interpolateAtSample(glsl_type::float_type),
4039 _interpolateAtSample(glsl_type::vec2_type),
4040 _interpolateAtSample(glsl_type::vec3_type),
4041 _interpolateAtSample(glsl_type::vec4_type),
4042 NULL);
4043
4044 add_function("atomicCounter",
4045 _atomic_counter_op("__intrinsic_atomic_read",
4046 shader_atomic_counters),
4047 NULL);
4048 add_function("atomicCounterIncrement",
4049 _atomic_counter_op("__intrinsic_atomic_increment",
4050 shader_atomic_counters),
4051 NULL);
4052 add_function("atomicCounterDecrement",
4053 _atomic_counter_op("__intrinsic_atomic_predecrement",
4054 shader_atomic_counters),
4055 NULL);
4056
4057 add_function("atomicCounterAddARB",
4058 _atomic_counter_op1("__intrinsic_atomic_add",
4059 shader_atomic_counter_ops),
4060 NULL);
4061 add_function("atomicCounterSubtractARB",
4062 _atomic_counter_op1("__intrinsic_atomic_sub",
4063 shader_atomic_counter_ops),
4064 NULL);
4065 add_function("atomicCounterMinARB",
4066 _atomic_counter_op1("__intrinsic_atomic_min",
4067 shader_atomic_counter_ops),
4068 NULL);
4069 add_function("atomicCounterMaxARB",
4070 _atomic_counter_op1("__intrinsic_atomic_max",
4071 shader_atomic_counter_ops),
4072 NULL);
4073 add_function("atomicCounterAndARB",
4074 _atomic_counter_op1("__intrinsic_atomic_and",
4075 shader_atomic_counter_ops),
4076 NULL);
4077 add_function("atomicCounterOrARB",
4078 _atomic_counter_op1("__intrinsic_atomic_or",
4079 shader_atomic_counter_ops),
4080 NULL);
4081 add_function("atomicCounterXorARB",
4082 _atomic_counter_op1("__intrinsic_atomic_xor",
4083 shader_atomic_counter_ops),
4084 NULL);
4085 add_function("atomicCounterExchangeARB",
4086 _atomic_counter_op1("__intrinsic_atomic_exchange",
4087 shader_atomic_counter_ops),
4088 NULL);
4089 add_function("atomicCounterCompSwapARB",
4090 _atomic_counter_op2("__intrinsic_atomic_comp_swap",
4091 shader_atomic_counter_ops),
4092 NULL);
4093
4094 add_function("atomicCounterAdd",
4095 _atomic_counter_op1("__intrinsic_atomic_add",
4096 v460_desktop),
4097 NULL);
4098 add_function("atomicCounterSubtract",
4099 _atomic_counter_op1("__intrinsic_atomic_sub",
4100 v460_desktop),
4101 NULL);
4102 add_function("atomicCounterMin",
4103 _atomic_counter_op1("__intrinsic_atomic_min",
4104 v460_desktop),
4105 NULL);
4106 add_function("atomicCounterMax",
4107 _atomic_counter_op1("__intrinsic_atomic_max",
4108 v460_desktop),
4109 NULL);
4110 add_function("atomicCounterAnd",
4111 _atomic_counter_op1("__intrinsic_atomic_and",
4112 v460_desktop),
4113 NULL);
4114 add_function("atomicCounterOr",
4115 _atomic_counter_op1("__intrinsic_atomic_or",
4116 v460_desktop),
4117 NULL);
4118 add_function("atomicCounterXor",
4119 _atomic_counter_op1("__intrinsic_atomic_xor",
4120 v460_desktop),
4121 NULL);
4122 add_function("atomicCounterExchange",
4123 _atomic_counter_op1("__intrinsic_atomic_exchange",
4124 v460_desktop),
4125 NULL);
4126 add_function("atomicCounterCompSwap",
4127 _atomic_counter_op2("__intrinsic_atomic_comp_swap",
4128 v460_desktop),
4129 NULL);
4130
4131 add_function("atomicAdd",
4132 _atomic_op2("__intrinsic_atomic_add",
4133 buffer_atomics_supported,
4134 glsl_type::uint_type),
4135 _atomic_op2("__intrinsic_atomic_add",
4136 buffer_atomics_supported,
4137 glsl_type::int_type),
4138 _atomic_op2("__intrinsic_atomic_add",
4139 shader_atomic_float_add,
4140 glsl_type::float_type),
4141 _atomic_op2("__intrinsic_atomic_add",
4142 buffer_int64_atomics_supported,
4143 glsl_type::int64_t_type),
4144 NULL);
4145 add_function("atomicMin",
4146 _atomic_op2("__intrinsic_atomic_min",
4147 buffer_atomics_supported,
4148 glsl_type::uint_type),
4149 _atomic_op2("__intrinsic_atomic_min",
4150 buffer_atomics_supported,
4151 glsl_type::int_type),
4152 _atomic_op2("__intrinsic_atomic_min",
4153 shader_atomic_float_minmax,
4154 glsl_type::float_type),
4155 _atomic_op2("__intrinsic_atomic_min",
4156 buffer_int64_atomics_supported,
4157 glsl_type::uint64_t_type),
4158 _atomic_op2("__intrinsic_atomic_min",
4159 buffer_int64_atomics_supported,
4160 glsl_type::int64_t_type),
4161 NULL);
4162 add_function("atomicMax",
4163 _atomic_op2("__intrinsic_atomic_max",
4164 buffer_atomics_supported,
4165 glsl_type::uint_type),
4166 _atomic_op2("__intrinsic_atomic_max",
4167 buffer_atomics_supported,
4168 glsl_type::int_type),
4169 _atomic_op2("__intrinsic_atomic_max",
4170 shader_atomic_float_minmax,
4171 glsl_type::float_type),
4172 _atomic_op2("__intrinsic_atomic_max",
4173 buffer_int64_atomics_supported,
4174 glsl_type::uint64_t_type),
4175 _atomic_op2("__intrinsic_atomic_max",
4176 buffer_int64_atomics_supported,
4177 glsl_type::int64_t_type),
4178 NULL);
4179 add_function("atomicAnd",
4180 _atomic_op2("__intrinsic_atomic_and",
4181 buffer_atomics_supported,
4182 glsl_type::uint_type),
4183 _atomic_op2("__intrinsic_atomic_and",
4184 buffer_atomics_supported,
4185 glsl_type::int_type),
4186 _atomic_op2("__intrinsic_atomic_and",
4187 buffer_int64_atomics_supported,
4188 glsl_type::uint64_t_type),
4189 _atomic_op2("__intrinsic_atomic_and",
4190 buffer_int64_atomics_supported,
4191 glsl_type::int64_t_type),
4192 NULL);
4193 add_function("atomicOr",
4194 _atomic_op2("__intrinsic_atomic_or",
4195 buffer_atomics_supported,
4196 glsl_type::uint_type),
4197 _atomic_op2("__intrinsic_atomic_or",
4198 buffer_atomics_supported,
4199 glsl_type::int_type),
4200 _atomic_op2("__intrinsic_atomic_or",
4201 buffer_int64_atomics_supported,
4202 glsl_type::uint64_t_type),
4203 _atomic_op2("__intrinsic_atomic_or",
4204 buffer_int64_atomics_supported,
4205 glsl_type::int64_t_type),
4206 NULL);
4207 add_function("atomicXor",
4208 _atomic_op2("__intrinsic_atomic_xor",
4209 buffer_atomics_supported,
4210 glsl_type::uint_type),
4211 _atomic_op2("__intrinsic_atomic_xor",
4212 buffer_atomics_supported,
4213 glsl_type::int_type),
4214 _atomic_op2("__intrinsic_atomic_xor",
4215 buffer_int64_atomics_supported,
4216 glsl_type::uint64_t_type),
4217 _atomic_op2("__intrinsic_atomic_xor",
4218 buffer_int64_atomics_supported,
4219 glsl_type::int64_t_type),
4220 NULL);
4221 add_function("atomicExchange",
4222 _atomic_op2("__intrinsic_atomic_exchange",
4223 buffer_atomics_supported,
4224 glsl_type::uint_type),
4225 _atomic_op2("__intrinsic_atomic_exchange",
4226 buffer_atomics_supported,
4227 glsl_type::int_type),
4228 _atomic_op2("__intrinsic_atomic_exchange",
4229 buffer_int64_atomics_supported,
4230 glsl_type::int64_t_type),
4231 _atomic_op2("__intrinsic_atomic_exchange",
4232 shader_atomic_float_exchange,
4233 glsl_type::float_type),
4234 NULL);
4235 add_function("atomicCompSwap",
4236 _atomic_op3("__intrinsic_atomic_comp_swap",
4237 buffer_atomics_supported,
4238 glsl_type::uint_type),
4239 _atomic_op3("__intrinsic_atomic_comp_swap",
4240 buffer_atomics_supported,
4241 glsl_type::int_type),
4242 _atomic_op3("__intrinsic_atomic_comp_swap",
4243 buffer_int64_atomics_supported,
4244 glsl_type::int64_t_type),
4245 _atomic_op3("__intrinsic_atomic_comp_swap",
4246 shader_atomic_float_minmax,
4247 glsl_type::float_type),
4248 NULL);
4249
4250 add_function("min3",
4251 _min3(glsl_type::float_type),
4252 _min3(glsl_type::vec2_type),
4253 _min3(glsl_type::vec3_type),
4254 _min3(glsl_type::vec4_type),
4255
4256 _min3(glsl_type::int_type),
4257 _min3(glsl_type::ivec2_type),
4258 _min3(glsl_type::ivec3_type),
4259 _min3(glsl_type::ivec4_type),
4260
4261 _min3(glsl_type::uint_type),
4262 _min3(glsl_type::uvec2_type),
4263 _min3(glsl_type::uvec3_type),
4264 _min3(glsl_type::uvec4_type),
4265 NULL);
4266
4267 add_function("max3",
4268 _max3(glsl_type::float_type),
4269 _max3(glsl_type::vec2_type),
4270 _max3(glsl_type::vec3_type),
4271 _max3(glsl_type::vec4_type),
4272
4273 _max3(glsl_type::int_type),
4274 _max3(glsl_type::ivec2_type),
4275 _max3(glsl_type::ivec3_type),
4276 _max3(glsl_type::ivec4_type),
4277
4278 _max3(glsl_type::uint_type),
4279 _max3(glsl_type::uvec2_type),
4280 _max3(glsl_type::uvec3_type),
4281 _max3(glsl_type::uvec4_type),
4282 NULL);
4283
4284 add_function("mid3",
4285 _mid3(glsl_type::float_type),
4286 _mid3(glsl_type::vec2_type),
4287 _mid3(glsl_type::vec3_type),
4288 _mid3(glsl_type::vec4_type),
4289
4290 _mid3(glsl_type::int_type),
4291 _mid3(glsl_type::ivec2_type),
4292 _mid3(glsl_type::ivec3_type),
4293 _mid3(glsl_type::ivec4_type),
4294
4295 _mid3(glsl_type::uint_type),
4296 _mid3(glsl_type::uvec2_type),
4297 _mid3(glsl_type::uvec3_type),
4298 _mid3(glsl_type::uvec4_type),
4299 NULL);
4300
4301 add_image_functions(true);
4302
4303 add_function("memoryBarrier",
4304 _memory_barrier("__intrinsic_memory_barrier",
4305 shader_image_load_store),
4306 NULL);
4307 add_function("groupMemoryBarrier",
4308 _memory_barrier("__intrinsic_group_memory_barrier",
4309 compute_shader),
4310 NULL);
4311 add_function("memoryBarrierAtomicCounter",
4312 _memory_barrier("__intrinsic_memory_barrier_atomic_counter",
4313 compute_shader_supported),
4314 NULL);
4315 add_function("memoryBarrierBuffer",
4316 _memory_barrier("__intrinsic_memory_barrier_buffer",
4317 compute_shader_supported),
4318 NULL);
4319 add_function("memoryBarrierImage",
4320 _memory_barrier("__intrinsic_memory_barrier_image",
4321 compute_shader_supported),
4322 NULL);
4323 add_function("memoryBarrierShared",
4324 _memory_barrier("__intrinsic_memory_barrier_shared",
4325 compute_shader),
4326 NULL);
4327
4328 add_function("ballotARB", _ballot(), NULL);
4329
4330 add_function("readInvocationARB",
4331 _read_invocation(glsl_type::float_type),
4332 _read_invocation(glsl_type::vec2_type),
4333 _read_invocation(glsl_type::vec3_type),
4334 _read_invocation(glsl_type::vec4_type),
4335
4336 _read_invocation(glsl_type::int_type),
4337 _read_invocation(glsl_type::ivec2_type),
4338 _read_invocation(glsl_type::ivec3_type),
4339 _read_invocation(glsl_type::ivec4_type),
4340
4341 _read_invocation(glsl_type::uint_type),
4342 _read_invocation(glsl_type::uvec2_type),
4343 _read_invocation(glsl_type::uvec3_type),
4344 _read_invocation(glsl_type::uvec4_type),
4345 NULL);
4346
4347 add_function("readFirstInvocationARB",
4348 _read_first_invocation(glsl_type::float_type),
4349 _read_first_invocation(glsl_type::vec2_type),
4350 _read_first_invocation(glsl_type::vec3_type),
4351 _read_first_invocation(glsl_type::vec4_type),
4352
4353 _read_first_invocation(glsl_type::int_type),
4354 _read_first_invocation(glsl_type::ivec2_type),
4355 _read_first_invocation(glsl_type::ivec3_type),
4356 _read_first_invocation(glsl_type::ivec4_type),
4357
4358 _read_first_invocation(glsl_type::uint_type),
4359 _read_first_invocation(glsl_type::uvec2_type),
4360 _read_first_invocation(glsl_type::uvec3_type),
4361 _read_first_invocation(glsl_type::uvec4_type),
4362 NULL);
4363
4364 add_function("clock2x32ARB",
4365 _shader_clock(shader_clock,
4366 glsl_type::uvec2_type),
4367 NULL);
4368
4369 add_function("clockARB",
4370 _shader_clock(shader_clock_int64,
4371 glsl_type::uint64_t_type),
4372 NULL);
4373
4374 add_function("beginInvocationInterlockARB",
4375 _invocation_interlock(
4376 "__intrinsic_begin_invocation_interlock",
4377 supports_arb_fragment_shader_interlock),
4378 NULL);
4379
4380 add_function("endInvocationInterlockARB",
4381 _invocation_interlock(
4382 "__intrinsic_end_invocation_interlock",
4383 supports_arb_fragment_shader_interlock),
4384 NULL);
4385
4386 add_function("beginInvocationInterlockNV",
4387 _invocation_interlock(
4388 "__intrinsic_begin_invocation_interlock",
4389 supports_nv_fragment_shader_interlock),
4390 NULL);
4391
4392 add_function("endInvocationInterlockNV",
4393 _invocation_interlock(
4394 "__intrinsic_end_invocation_interlock",
4395 supports_nv_fragment_shader_interlock),
4396 NULL);
4397
4398 add_function("anyInvocationARB",
4399 _vote("__intrinsic_vote_any", vote),
4400 NULL);
4401
4402 add_function("allInvocationsARB",
4403 _vote("__intrinsic_vote_all", vote),
4404 NULL);
4405
4406 add_function("allInvocationsEqualARB",
4407 _vote("__intrinsic_vote_eq", vote),
4408 NULL);
4409
4410 add_function("anyInvocationEXT",
4411 _vote("__intrinsic_vote_any", vote_ext),
4412 NULL);
4413
4414 add_function("allInvocationsEXT",
4415 _vote("__intrinsic_vote_all", vote_ext),
4416 NULL);
4417
4418 add_function("allInvocationsEqualEXT",
4419 _vote("__intrinsic_vote_eq", vote_ext),
4420 NULL);
4421
4422 add_function("anyInvocation",
4423 _vote("__intrinsic_vote_any", v460_desktop),
4424 NULL);
4425
4426 add_function("allInvocations",
4427 _vote("__intrinsic_vote_all", v460_desktop),
4428 NULL);
4429
4430 add_function("allInvocationsEqual",
4431 _vote("__intrinsic_vote_eq", v460_desktop),
4432 NULL);
4433
4434 add_function("helperInvocationEXT", _helper_invocation(), NULL);
4435
4436 add_function("__builtin_idiv64",
4437 generate_ir::idiv64(mem_ctx, integer_functions_supported),
4438 NULL);
4439
4440 add_function("__builtin_imod64",
4441 generate_ir::imod64(mem_ctx, integer_functions_supported),
4442 NULL);
4443
4444 add_function("__builtin_sign64",
4445 generate_ir::sign64(mem_ctx, integer_functions_supported),
4446 NULL);
4447
4448 add_function("__builtin_udiv64",
4449 generate_ir::udiv64(mem_ctx, integer_functions_supported),
4450 NULL);
4451
4452 add_function("__builtin_umod64",
4453 generate_ir::umod64(mem_ctx, integer_functions_supported),
4454 NULL);
4455
4456 add_function("__builtin_umul64",
4457 generate_ir::umul64(mem_ctx, integer_functions_supported),
4458 NULL);
4459
4460 add_function("countLeadingZeros",
4461 _countLeadingZeros(shader_integer_functions2,
4462 glsl_type::uint_type),
4463 _countLeadingZeros(shader_integer_functions2,
4464 glsl_type::uvec2_type),
4465 _countLeadingZeros(shader_integer_functions2,
4466 glsl_type::uvec3_type),
4467 _countLeadingZeros(shader_integer_functions2,
4468 glsl_type::uvec4_type),
4469 NULL);
4470
4471 add_function("countTrailingZeros",
4472 _countTrailingZeros(shader_integer_functions2,
4473 glsl_type::uint_type),
4474 _countTrailingZeros(shader_integer_functions2,
4475 glsl_type::uvec2_type),
4476 _countTrailingZeros(shader_integer_functions2,
4477 glsl_type::uvec3_type),
4478 _countTrailingZeros(shader_integer_functions2,
4479 glsl_type::uvec4_type),
4480 NULL);
4481
4482 add_function("absoluteDifference",
4483 _absoluteDifference(shader_integer_functions2,
4484 glsl_type::int_type),
4485 _absoluteDifference(shader_integer_functions2,
4486 glsl_type::ivec2_type),
4487 _absoluteDifference(shader_integer_functions2,
4488 glsl_type::ivec3_type),
4489 _absoluteDifference(shader_integer_functions2,
4490 glsl_type::ivec4_type),
4491 _absoluteDifference(shader_integer_functions2,
4492 glsl_type::uint_type),
4493 _absoluteDifference(shader_integer_functions2,
4494 glsl_type::uvec2_type),
4495 _absoluteDifference(shader_integer_functions2,
4496 glsl_type::uvec3_type),
4497 _absoluteDifference(shader_integer_functions2,
4498 glsl_type::uvec4_type),
4499
4500 _absoluteDifference(shader_integer_functions2_int64,
4501 glsl_type::int64_t_type),
4502 _absoluteDifference(shader_integer_functions2_int64,
4503 glsl_type::i64vec2_type),
4504 _absoluteDifference(shader_integer_functions2_int64,
4505 glsl_type::i64vec3_type),
4506 _absoluteDifference(shader_integer_functions2_int64,
4507 glsl_type::i64vec4_type),
4508 _absoluteDifference(shader_integer_functions2_int64,
4509 glsl_type::uint64_t_type),
4510 _absoluteDifference(shader_integer_functions2_int64,
4511 glsl_type::u64vec2_type),
4512 _absoluteDifference(shader_integer_functions2_int64,
4513 glsl_type::u64vec3_type),
4514 _absoluteDifference(shader_integer_functions2_int64,
4515 glsl_type::u64vec4_type),
4516 NULL);
4517
4518 add_function("addSaturate",
4519 _addSaturate(shader_integer_functions2,
4520 glsl_type::int_type),
4521 _addSaturate(shader_integer_functions2,
4522 glsl_type::ivec2_type),
4523 _addSaturate(shader_integer_functions2,
4524 glsl_type::ivec3_type),
4525 _addSaturate(shader_integer_functions2,
4526 glsl_type::ivec4_type),
4527 _addSaturate(shader_integer_functions2,
4528 glsl_type::uint_type),
4529 _addSaturate(shader_integer_functions2,
4530 glsl_type::uvec2_type),
4531 _addSaturate(shader_integer_functions2,
4532 glsl_type::uvec3_type),
4533 _addSaturate(shader_integer_functions2,
4534 glsl_type::uvec4_type),
4535
4536 _addSaturate(shader_integer_functions2_int64,
4537 glsl_type::int64_t_type),
4538 _addSaturate(shader_integer_functions2_int64,
4539 glsl_type::i64vec2_type),
4540 _addSaturate(shader_integer_functions2_int64,
4541 glsl_type::i64vec3_type),
4542 _addSaturate(shader_integer_functions2_int64,
4543 glsl_type::i64vec4_type),
4544 _addSaturate(shader_integer_functions2_int64,
4545 glsl_type::uint64_t_type),
4546 _addSaturate(shader_integer_functions2_int64,
4547 glsl_type::u64vec2_type),
4548 _addSaturate(shader_integer_functions2_int64,
4549 glsl_type::u64vec3_type),
4550 _addSaturate(shader_integer_functions2_int64,
4551 glsl_type::u64vec4_type),
4552 NULL);
4553
4554 add_function("average",
4555 _average(shader_integer_functions2,
4556 glsl_type::int_type),
4557 _average(shader_integer_functions2,
4558 glsl_type::ivec2_type),
4559 _average(shader_integer_functions2,
4560 glsl_type::ivec3_type),
4561 _average(shader_integer_functions2,
4562 glsl_type::ivec4_type),
4563 _average(shader_integer_functions2,
4564 glsl_type::uint_type),
4565 _average(shader_integer_functions2,
4566 glsl_type::uvec2_type),
4567 _average(shader_integer_functions2,
4568 glsl_type::uvec3_type),
4569 _average(shader_integer_functions2,
4570 glsl_type::uvec4_type),
4571
4572 _average(shader_integer_functions2_int64,
4573 glsl_type::int64_t_type),
4574 _average(shader_integer_functions2_int64,
4575 glsl_type::i64vec2_type),
4576 _average(shader_integer_functions2_int64,
4577 glsl_type::i64vec3_type),
4578 _average(shader_integer_functions2_int64,
4579 glsl_type::i64vec4_type),
4580 _average(shader_integer_functions2_int64,
4581 glsl_type::uint64_t_type),
4582 _average(shader_integer_functions2_int64,
4583 glsl_type::u64vec2_type),
4584 _average(shader_integer_functions2_int64,
4585 glsl_type::u64vec3_type),
4586 _average(shader_integer_functions2_int64,
4587 glsl_type::u64vec4_type),
4588 NULL);
4589
4590 add_function("averageRounded",
4591 _averageRounded(shader_integer_functions2,
4592 glsl_type::int_type),
4593 _averageRounded(shader_integer_functions2,
4594 glsl_type::ivec2_type),
4595 _averageRounded(shader_integer_functions2,
4596 glsl_type::ivec3_type),
4597 _averageRounded(shader_integer_functions2,
4598 glsl_type::ivec4_type),
4599 _averageRounded(shader_integer_functions2,
4600 glsl_type::uint_type),
4601 _averageRounded(shader_integer_functions2,
4602 glsl_type::uvec2_type),
4603 _averageRounded(shader_integer_functions2,
4604 glsl_type::uvec3_type),
4605 _averageRounded(shader_integer_functions2,
4606 glsl_type::uvec4_type),
4607
4608 _averageRounded(shader_integer_functions2_int64,
4609 glsl_type::int64_t_type),
4610 _averageRounded(shader_integer_functions2_int64,
4611 glsl_type::i64vec2_type),
4612 _averageRounded(shader_integer_functions2_int64,
4613 glsl_type::i64vec3_type),
4614 _averageRounded(shader_integer_functions2_int64,
4615 glsl_type::i64vec4_type),
4616 _averageRounded(shader_integer_functions2_int64,
4617 glsl_type::uint64_t_type),
4618 _averageRounded(shader_integer_functions2_int64,
4619 glsl_type::u64vec2_type),
4620 _averageRounded(shader_integer_functions2_int64,
4621 glsl_type::u64vec3_type),
4622 _averageRounded(shader_integer_functions2_int64,
4623 glsl_type::u64vec4_type),
4624 NULL);
4625
4626 add_function("subtractSaturate",
4627 _subtractSaturate(shader_integer_functions2,
4628 glsl_type::int_type),
4629 _subtractSaturate(shader_integer_functions2,
4630 glsl_type::ivec2_type),
4631 _subtractSaturate(shader_integer_functions2,
4632 glsl_type::ivec3_type),
4633 _subtractSaturate(shader_integer_functions2,
4634 glsl_type::ivec4_type),
4635 _subtractSaturate(shader_integer_functions2,
4636 glsl_type::uint_type),
4637 _subtractSaturate(shader_integer_functions2,
4638 glsl_type::uvec2_type),
4639 _subtractSaturate(shader_integer_functions2,
4640 glsl_type::uvec3_type),
4641 _subtractSaturate(shader_integer_functions2,
4642 glsl_type::uvec4_type),
4643
4644 _subtractSaturate(shader_integer_functions2_int64,
4645 glsl_type::int64_t_type),
4646 _subtractSaturate(shader_integer_functions2_int64,
4647 glsl_type::i64vec2_type),
4648 _subtractSaturate(shader_integer_functions2_int64,
4649 glsl_type::i64vec3_type),
4650 _subtractSaturate(shader_integer_functions2_int64,
4651 glsl_type::i64vec4_type),
4652 _subtractSaturate(shader_integer_functions2_int64,
4653 glsl_type::uint64_t_type),
4654 _subtractSaturate(shader_integer_functions2_int64,
4655 glsl_type::u64vec2_type),
4656 _subtractSaturate(shader_integer_functions2_int64,
4657 glsl_type::u64vec3_type),
4658 _subtractSaturate(shader_integer_functions2_int64,
4659 glsl_type::u64vec4_type),
4660 NULL);
4661
4662 add_function("multiply32x16",
4663 _multiply32x16(shader_integer_functions2,
4664 glsl_type::int_type),
4665 _multiply32x16(shader_integer_functions2,
4666 glsl_type::ivec2_type),
4667 _multiply32x16(shader_integer_functions2,
4668 glsl_type::ivec3_type),
4669 _multiply32x16(shader_integer_functions2,
4670 glsl_type::ivec4_type),
4671 _multiply32x16(shader_integer_functions2,
4672 glsl_type::uint_type),
4673 _multiply32x16(shader_integer_functions2,
4674 glsl_type::uvec2_type),
4675 _multiply32x16(shader_integer_functions2,
4676 glsl_type::uvec3_type),
4677 _multiply32x16(shader_integer_functions2,
4678 glsl_type::uvec4_type),
4679 NULL);
4680
4681 #undef F
4682 #undef FI
4683 #undef FIUD_VEC
4684 #undef FIUBD_VEC
4685 #undef FIU2_MIXED
4686 }
4687
4688 void
add_function(const char * name,...)4689 builtin_builder::add_function(const char *name, ...)
4690 {
4691 va_list ap;
4692
4693 ir_function *f = new(mem_ctx) ir_function(name);
4694
4695 va_start(ap, name);
4696 while (true) {
4697 ir_function_signature *sig = va_arg(ap, ir_function_signature *);
4698 if (sig == NULL)
4699 break;
4700
4701 if (false) {
4702 exec_list stuff;
4703 stuff.push_tail(sig);
4704 validate_ir_tree(&stuff);
4705 }
4706
4707 f->add_signature(sig);
4708 }
4709 va_end(ap);
4710
4711 shader->symbols->add_function(f);
4712 }
4713
4714 void
add_image_function(const char * name,const char * intrinsic_name,image_prototype_ctr prototype,unsigned num_arguments,unsigned flags,enum ir_intrinsic_id intrinsic_id)4715 builtin_builder::add_image_function(const char *name,
4716 const char *intrinsic_name,
4717 image_prototype_ctr prototype,
4718 unsigned num_arguments,
4719 unsigned flags,
4720 enum ir_intrinsic_id intrinsic_id)
4721 {
4722 static const glsl_type *const types[] = {
4723 glsl_type::image1D_type,
4724 glsl_type::image2D_type,
4725 glsl_type::image3D_type,
4726 glsl_type::image2DRect_type,
4727 glsl_type::imageCube_type,
4728 glsl_type::imageBuffer_type,
4729 glsl_type::image1DArray_type,
4730 glsl_type::image2DArray_type,
4731 glsl_type::imageCubeArray_type,
4732 glsl_type::image2DMS_type,
4733 glsl_type::image2DMSArray_type,
4734 glsl_type::iimage1D_type,
4735 glsl_type::iimage2D_type,
4736 glsl_type::iimage3D_type,
4737 glsl_type::iimage2DRect_type,
4738 glsl_type::iimageCube_type,
4739 glsl_type::iimageBuffer_type,
4740 glsl_type::iimage1DArray_type,
4741 glsl_type::iimage2DArray_type,
4742 glsl_type::iimageCubeArray_type,
4743 glsl_type::iimage2DMS_type,
4744 glsl_type::iimage2DMSArray_type,
4745 glsl_type::uimage1D_type,
4746 glsl_type::uimage2D_type,
4747 glsl_type::uimage3D_type,
4748 glsl_type::uimage2DRect_type,
4749 glsl_type::uimageCube_type,
4750 glsl_type::uimageBuffer_type,
4751 glsl_type::uimage1DArray_type,
4752 glsl_type::uimage2DArray_type,
4753 glsl_type::uimageCubeArray_type,
4754 glsl_type::uimage2DMS_type,
4755 glsl_type::uimage2DMSArray_type
4756 };
4757
4758 ir_function *f = new(mem_ctx) ir_function(name);
4759
4760 for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
4761 if (types[i]->sampled_type == GLSL_TYPE_FLOAT && !(flags & IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE))
4762 continue;
4763 if (types[i]->sampled_type == GLSL_TYPE_INT && !(flags & IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE))
4764 continue;
4765 if ((types[i]->sampler_dimensionality != GLSL_SAMPLER_DIM_MS) && (flags & IMAGE_FUNCTION_MS_ONLY))
4766 continue;
4767 f->add_signature(_image(prototype, types[i], intrinsic_name,
4768 num_arguments, flags, intrinsic_id));
4769 }
4770 shader->symbols->add_function(f);
4771 }
4772
4773 void
add_image_functions(bool glsl)4774 builtin_builder::add_image_functions(bool glsl)
4775 {
4776 const unsigned flags = (glsl ? IMAGE_FUNCTION_EMIT_STUB : 0);
4777
4778 add_image_function(glsl ? "imageLoad" : "__intrinsic_image_load",
4779 "__intrinsic_image_load",
4780 &builtin_builder::_image_prototype, 0,
4781 (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
4782 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
4783 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE |
4784 IMAGE_FUNCTION_READ_ONLY),
4785 ir_intrinsic_image_load);
4786
4787 add_image_function(glsl ? "imageStore" : "__intrinsic_image_store",
4788 "__intrinsic_image_store",
4789 &builtin_builder::_image_prototype, 1,
4790 (flags | IMAGE_FUNCTION_RETURNS_VOID |
4791 IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
4792 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
4793 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE |
4794 IMAGE_FUNCTION_WRITE_ONLY),
4795 ir_intrinsic_image_store);
4796
4797 const unsigned atom_flags = flags | IMAGE_FUNCTION_AVAIL_ATOMIC;
4798
4799 add_image_function(glsl ? "imageAtomicAdd" : "__intrinsic_image_atomic_add",
4800 "__intrinsic_image_atomic_add",
4801 &builtin_builder::_image_prototype, 1,
4802 (flags | IMAGE_FUNCTION_AVAIL_ATOMIC_ADD |
4803 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
4804 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE),
4805 ir_intrinsic_image_atomic_add);
4806
4807 add_image_function(glsl ? "imageAtomicMin" : "__intrinsic_image_atomic_min",
4808 "__intrinsic_image_atomic_min",
4809 &builtin_builder::_image_prototype, 1,
4810 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4811 ir_intrinsic_image_atomic_min);
4812
4813 add_image_function(glsl ? "imageAtomicMax" : "__intrinsic_image_atomic_max",
4814 "__intrinsic_image_atomic_max",
4815 &builtin_builder::_image_prototype, 1,
4816 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4817 ir_intrinsic_image_atomic_max);
4818
4819 add_image_function(glsl ? "imageAtomicAnd" : "__intrinsic_image_atomic_and",
4820 "__intrinsic_image_atomic_and",
4821 &builtin_builder::_image_prototype, 1,
4822 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4823 ir_intrinsic_image_atomic_and);
4824
4825 add_image_function(glsl ? "imageAtomicOr" : "__intrinsic_image_atomic_or",
4826 "__intrinsic_image_atomic_or",
4827 &builtin_builder::_image_prototype, 1,
4828 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4829 ir_intrinsic_image_atomic_or);
4830
4831 add_image_function(glsl ? "imageAtomicXor" : "__intrinsic_image_atomic_xor",
4832 "__intrinsic_image_atomic_xor",
4833 &builtin_builder::_image_prototype, 1,
4834 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4835 ir_intrinsic_image_atomic_xor);
4836
4837 add_image_function((glsl ? "imageAtomicExchange" :
4838 "__intrinsic_image_atomic_exchange"),
4839 "__intrinsic_image_atomic_exchange",
4840 &builtin_builder::_image_prototype, 1,
4841 (flags | IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE |
4842 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE |
4843 IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE),
4844 ir_intrinsic_image_atomic_exchange);
4845
4846 add_image_function((glsl ? "imageAtomicCompSwap" :
4847 "__intrinsic_image_atomic_comp_swap"),
4848 "__intrinsic_image_atomic_comp_swap",
4849 &builtin_builder::_image_prototype, 2,
4850 atom_flags | IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4851 ir_intrinsic_image_atomic_comp_swap);
4852
4853 add_image_function(glsl ? "imageSize" : "__intrinsic_image_size",
4854 "__intrinsic_image_size",
4855 &builtin_builder::_image_size_prototype, 1,
4856 flags | IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
4857 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE,
4858 ir_intrinsic_image_size);
4859
4860 add_image_function(glsl ? "imageSamples" : "__intrinsic_image_samples",
4861 "__intrinsic_image_samples",
4862 &builtin_builder::_image_samples_prototype, 1,
4863 flags | IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
4864 IMAGE_FUNCTION_SUPPORTS_SIGNED_DATA_TYPE |
4865 IMAGE_FUNCTION_MS_ONLY,
4866 ir_intrinsic_image_samples);
4867
4868 /* EXT_shader_image_load_store */
4869 add_image_function(glsl ? "imageAtomicIncWrap" : "__intrinsic_image_atomic_inc_wrap",
4870 "__intrinsic_image_atomic_inc_wrap",
4871 &builtin_builder::_image_prototype, 1,
4872 (atom_flags | IMAGE_FUNCTION_EXT_ONLY),
4873 ir_intrinsic_image_atomic_inc_wrap);
4874 add_image_function(glsl ? "imageAtomicDecWrap" : "__intrinsic_image_atomic_dec_wrap",
4875 "__intrinsic_image_atomic_dec_wrap",
4876 &builtin_builder::_image_prototype, 1,
4877 (atom_flags | IMAGE_FUNCTION_EXT_ONLY),
4878 ir_intrinsic_image_atomic_dec_wrap);
4879 }
4880
4881 ir_variable *
in_var(const glsl_type * type,const char * name)4882 builtin_builder::in_var(const glsl_type *type, const char *name)
4883 {
4884 return new(mem_ctx) ir_variable(type, name, ir_var_function_in);
4885 }
4886
4887 ir_variable *
out_var(const glsl_type * type,const char * name)4888 builtin_builder::out_var(const glsl_type *type, const char *name)
4889 {
4890 return new(mem_ctx) ir_variable(type, name, ir_var_function_out);
4891 }
4892
4893 ir_constant *
imm(bool b,unsigned vector_elements)4894 builtin_builder::imm(bool b, unsigned vector_elements)
4895 {
4896 return new(mem_ctx) ir_constant(b, vector_elements);
4897 }
4898
4899 ir_constant *
imm(float f,unsigned vector_elements)4900 builtin_builder::imm(float f, unsigned vector_elements)
4901 {
4902 return new(mem_ctx) ir_constant(f, vector_elements);
4903 }
4904
4905 ir_constant *
imm(int i,unsigned vector_elements)4906 builtin_builder::imm(int i, unsigned vector_elements)
4907 {
4908 return new(mem_ctx) ir_constant(i, vector_elements);
4909 }
4910
4911 ir_constant *
imm(unsigned u,unsigned vector_elements)4912 builtin_builder::imm(unsigned u, unsigned vector_elements)
4913 {
4914 return new(mem_ctx) ir_constant(u, vector_elements);
4915 }
4916
4917 ir_constant *
imm(double d,unsigned vector_elements)4918 builtin_builder::imm(double d, unsigned vector_elements)
4919 {
4920 return new(mem_ctx) ir_constant(d, vector_elements);
4921 }
4922
4923 ir_constant *
imm(const glsl_type * type,const ir_constant_data & data)4924 builtin_builder::imm(const glsl_type *type, const ir_constant_data &data)
4925 {
4926 return new(mem_ctx) ir_constant(type, &data);
4927 }
4928
4929 #define IMM_FP(type, val) (type->is_double()) ? imm(val) : imm((float)val)
4930
4931 ir_dereference_variable *
var_ref(ir_variable * var)4932 builtin_builder::var_ref(ir_variable *var)
4933 {
4934 return new(mem_ctx) ir_dereference_variable(var);
4935 }
4936
4937 ir_dereference_array *
array_ref(ir_variable * var,int idx)4938 builtin_builder::array_ref(ir_variable *var, int idx)
4939 {
4940 return new(mem_ctx) ir_dereference_array(var, imm(idx));
4941 }
4942
4943 /** Return an element of a matrix */
4944 ir_swizzle *
matrix_elt(ir_variable * var,int column,int row)4945 builtin_builder::matrix_elt(ir_variable *var, int column, int row)
4946 {
4947 return swizzle(array_ref(var, column), row, 1);
4948 }
4949
4950 /**
4951 * Implementations of built-in functions:
4952 * @{
4953 */
4954 ir_function_signature *
new_sig(const glsl_type * return_type,builtin_available_predicate avail,int num_params,...)4955 builtin_builder::new_sig(const glsl_type *return_type,
4956 builtin_available_predicate avail,
4957 int num_params,
4958 ...)
4959 {
4960 va_list ap;
4961
4962 ir_function_signature *sig =
4963 new(mem_ctx) ir_function_signature(return_type, avail);
4964
4965 exec_list plist;
4966 va_start(ap, num_params);
4967 for (int i = 0; i < num_params; i++) {
4968 plist.push_tail(va_arg(ap, ir_variable *));
4969 }
4970 va_end(ap);
4971
4972 sig->replace_parameters(&plist);
4973 return sig;
4974 }
4975
4976 #define MAKE_SIG(return_type, avail, ...) \
4977 ir_function_signature *sig = \
4978 new_sig(return_type, avail, __VA_ARGS__); \
4979 ir_factory body(&sig->body, mem_ctx); \
4980 sig->is_defined = true;
4981
4982 #define MAKE_INTRINSIC(return_type, id, avail, ...) \
4983 ir_function_signature *sig = \
4984 new_sig(return_type, avail, __VA_ARGS__); \
4985 sig->intrinsic_id = id;
4986
4987 ir_function_signature *
unop(builtin_available_predicate avail,ir_expression_operation opcode,const glsl_type * return_type,const glsl_type * param_type)4988 builtin_builder::unop(builtin_available_predicate avail,
4989 ir_expression_operation opcode,
4990 const glsl_type *return_type,
4991 const glsl_type *param_type)
4992 {
4993 ir_variable *x = in_var(param_type, "x");
4994 MAKE_SIG(return_type, avail, 1, x);
4995 body.emit(ret(expr(opcode, x)));
4996 return sig;
4997 }
4998
4999 #define UNOP(NAME, OPCODE, AVAIL) \
5000 ir_function_signature * \
5001 builtin_builder::_##NAME(const glsl_type *type) \
5002 { \
5003 return unop(&AVAIL, OPCODE, type, type); \
5004 }
5005
5006 #define UNOPA(NAME, OPCODE) \
5007 ir_function_signature * \
5008 builtin_builder::_##NAME(builtin_available_predicate avail, const glsl_type *type) \
5009 { \
5010 return unop(avail, OPCODE, type, type); \
5011 }
5012
5013 ir_function_signature *
binop(builtin_available_predicate avail,ir_expression_operation opcode,const glsl_type * return_type,const glsl_type * param0_type,const glsl_type * param1_type,bool swap_operands)5014 builtin_builder::binop(builtin_available_predicate avail,
5015 ir_expression_operation opcode,
5016 const glsl_type *return_type,
5017 const glsl_type *param0_type,
5018 const glsl_type *param1_type,
5019 bool swap_operands)
5020 {
5021 ir_variable *x = in_var(param0_type, "x");
5022 ir_variable *y = in_var(param1_type, "y");
5023 MAKE_SIG(return_type, avail, 2, x, y);
5024
5025 if (swap_operands)
5026 body.emit(ret(expr(opcode, y, x)));
5027 else
5028 body.emit(ret(expr(opcode, x, y)));
5029
5030 return sig;
5031 }
5032
5033 #define BINOP(NAME, OPCODE, AVAIL) \
5034 ir_function_signature * \
5035 builtin_builder::_##NAME(const glsl_type *return_type, \
5036 const glsl_type *param0_type, \
5037 const glsl_type *param1_type) \
5038 { \
5039 return binop(&AVAIL, OPCODE, return_type, param0_type, param1_type); \
5040 }
5041
5042 /**
5043 * Angle and Trigonometry Functions @{
5044 */
5045
5046 ir_function_signature *
_radians(const glsl_type * type)5047 builtin_builder::_radians(const glsl_type *type)
5048 {
5049 ir_variable *degrees = in_var(type, "degrees");
5050 MAKE_SIG(type, always_available, 1, degrees);
5051 body.emit(ret(mul(degrees, imm(0.0174532925f))));
5052 return sig;
5053 }
5054
5055 ir_function_signature *
_degrees(const glsl_type * type)5056 builtin_builder::_degrees(const glsl_type *type)
5057 {
5058 ir_variable *radians = in_var(type, "radians");
5059 MAKE_SIG(type, always_available, 1, radians);
5060 body.emit(ret(mul(radians, imm(57.29578f))));
5061 return sig;
5062 }
5063
UNOP(sin,ir_unop_sin,always_available)5064 UNOP(sin, ir_unop_sin, always_available)
5065 UNOP(cos, ir_unop_cos, always_available)
5066
5067 ir_function_signature *
5068 builtin_builder::_tan(const glsl_type *type)
5069 {
5070 ir_variable *theta = in_var(type, "theta");
5071 MAKE_SIG(type, always_available, 1, theta);
5072 body.emit(ret(div(sin(theta), cos(theta))));
5073 return sig;
5074 }
5075
5076 ir_expression *
asin_expr(ir_variable * x,float p0,float p1)5077 builtin_builder::asin_expr(ir_variable *x, float p0, float p1)
5078 {
5079 return mul(sign(x),
5080 sub(imm(M_PI_2f),
5081 mul(sqrt(sub(imm(1.0f), abs(x))),
5082 add(imm(M_PI_2f),
5083 mul(abs(x),
5084 add(imm(M_PI_4f - 1.0f),
5085 mul(abs(x),
5086 add(imm(p0),
5087 mul(abs(x), imm(p1))))))))));
5088 }
5089
5090 /**
5091 * Generate a ir_call to a function with a set of parameters
5092 *
5093 * The input \c params can either be a list of \c ir_variable or a list of
5094 * \c ir_dereference_variable. In the latter case, all nodes will be removed
5095 * from \c params and used directly as the parameters to the generated
5096 * \c ir_call.
5097 */
5098 ir_call *
call(ir_function * f,ir_variable * ret,exec_list params)5099 builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)
5100 {
5101 exec_list actual_params;
5102
5103 foreach_in_list_safe(ir_instruction, ir, ¶ms) {
5104 ir_dereference_variable *d = ir->as_dereference_variable();
5105 if (d != NULL) {
5106 d->remove();
5107 actual_params.push_tail(d);
5108 } else {
5109 ir_variable *var = ir->as_variable();
5110 assert(var != NULL);
5111 actual_params.push_tail(var_ref(var));
5112 }
5113 }
5114
5115 ir_function_signature *sig =
5116 f->exact_matching_signature(NULL, &actual_params);
5117 if (!sig)
5118 return NULL;
5119
5120 ir_dereference_variable *deref =
5121 (sig->return_type->is_void() ? NULL : var_ref(ret));
5122
5123 return new(mem_ctx) ir_call(sig, deref, &actual_params);
5124 }
5125
5126 ir_function_signature *
_asin(const glsl_type * type)5127 builtin_builder::_asin(const glsl_type *type)
5128 {
5129 ir_variable *x = in_var(type, "x");
5130 MAKE_SIG(type, always_available, 1, x);
5131
5132 body.emit(ret(asin_expr(x, 0.086566724f, -0.03102955f)));
5133
5134 return sig;
5135 }
5136
5137 ir_function_signature *
_acos(const glsl_type * type)5138 builtin_builder::_acos(const glsl_type *type)
5139 {
5140 ir_variable *x = in_var(type, "x");
5141 MAKE_SIG(type, always_available, 1, x);
5142
5143 body.emit(ret(sub(imm(M_PI_2f), asin_expr(x, 0.08132463f, -0.02363318f))));
5144
5145 return sig;
5146 }
5147
5148 ir_function_signature *
_atan2(const glsl_type * type)5149 builtin_builder::_atan2(const glsl_type *type)
5150 {
5151 const unsigned n = type->vector_elements;
5152 ir_variable *y = in_var(type, "y");
5153 ir_variable *x = in_var(type, "x");
5154 MAKE_SIG(type, is_not_nir, 2, y, x);
5155
5156 /* If we're on the left half-plane rotate the coordinates π/2 clock-wise
5157 * for the y=0 discontinuity to end up aligned with the vertical
5158 * discontinuity of atan(s/t) along t=0. This also makes sure that we
5159 * don't attempt to divide by zero along the vertical line, which may give
5160 * unspecified results on non-GLSL 4.1-capable hardware.
5161 */
5162 ir_variable *flip = body.make_temp(glsl_type::bvec(n), "flip");
5163 body.emit(assign(flip, gequal(imm(0.0f, n), x)));
5164 ir_variable *s = body.make_temp(type, "s");
5165 body.emit(assign(s, csel(flip, abs(x), y)));
5166 ir_variable *t = body.make_temp(type, "t");
5167 body.emit(assign(t, csel(flip, y, abs(x))));
5168
5169 /* If the magnitude of the denominator exceeds some huge value, scale down
5170 * the arguments in order to prevent the reciprocal operation from flushing
5171 * its result to zero, which would cause precision problems, and for s
5172 * infinite would cause us to return a NaN instead of the correct finite
5173 * value.
5174 *
5175 * If fmin and fmax are respectively the smallest and largest positive
5176 * normalized floating point values representable by the implementation,
5177 * the constants below should be in agreement with:
5178 *
5179 * huge <= 1 / fmin
5180 * scale <= 1 / fmin / fmax (for |t| >= huge)
5181 *
5182 * In addition scale should be a negative power of two in order to avoid
5183 * loss of precision. The values chosen below should work for most usual
5184 * floating point representations with at least the dynamic range of ATI's
5185 * 24-bit representation.
5186 */
5187 ir_constant *huge = imm(1e18f, n);
5188 ir_variable *scale = body.make_temp(type, "scale");
5189 body.emit(assign(scale, csel(gequal(abs(t), huge),
5190 imm(0.25f, n), imm(1.0f, n))));
5191 ir_variable *rcp_scaled_t = body.make_temp(type, "rcp_scaled_t");
5192 body.emit(assign(rcp_scaled_t, rcp(mul(t, scale))));
5193 ir_expression *s_over_t = mul(mul(s, scale), rcp_scaled_t);
5194
5195 /* For |x| = |y| assume tan = 1 even if infinite (i.e. pretend momentarily
5196 * that ∞/∞ = 1) in order to comply with the rather artificial rules
5197 * inherited from IEEE 754-2008, namely:
5198 *
5199 * "atan2(±∞, −∞) is ±3π/4
5200 * atan2(±∞, +∞) is ±π/4"
5201 *
5202 * Note that this is inconsistent with the rules for the neighborhood of
5203 * zero that are based on iterated limits:
5204 *
5205 * "atan2(±0, −0) is ±π
5206 * atan2(±0, +0) is ±0"
5207 *
5208 * but GLSL specifically allows implementations to deviate from IEEE rules
5209 * at (0,0), so we take that license (i.e. pretend that 0/0 = 1 here as
5210 * well).
5211 */
5212 ir_expression *tan = csel(equal(abs(x), abs(y)),
5213 imm(1.0f, n), abs(s_over_t));
5214
5215 /* Calculate the arctangent and fix up the result if we had flipped the
5216 * coordinate system.
5217 */
5218 ir_variable *arc = body.make_temp(type, "arc");
5219 do_atan(body, type, arc, tan);
5220 body.emit(assign(arc, add(arc, mul(b2f(flip), imm(M_PI_2f)))));
5221
5222 /* Rather convoluted calculation of the sign of the result. When x < 0 we
5223 * cannot use fsign because we need to be able to distinguish between
5224 * negative and positive zero. Unfortunately we cannot use bitwise
5225 * arithmetic tricks either because of back-ends without integer support.
5226 * When x >= 0 rcp_scaled_t will always be non-negative so this won't be
5227 * able to distinguish between negative and positive zero, but we don't
5228 * care because atan2 is continuous along the whole positive y = 0
5229 * half-line, so it won't affect the result significantly.
5230 */
5231 body.emit(ret(csel(less(min2(y, rcp_scaled_t), imm(0.0f, n)),
5232 neg(arc), arc)));
5233
5234 return sig;
5235 }
5236
5237 void
do_atan(ir_factory & body,const glsl_type * type,ir_variable * res,operand y_over_x)5238 builtin_builder::do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x)
5239 {
5240 /*
5241 * range-reduction, first step:
5242 *
5243 * / y_over_x if |y_over_x| <= 1.0;
5244 * x = <
5245 * \ 1.0 / y_over_x otherwise
5246 */
5247 ir_variable *x = body.make_temp(type, "atan_x");
5248 body.emit(assign(x, div(min2(abs(y_over_x),
5249 imm(1.0f)),
5250 max2(abs(y_over_x),
5251 imm(1.0f)))));
5252
5253 /*
5254 * approximate atan by evaluating polynomial:
5255 *
5256 * x * 0.9999793128310355 - x^3 * 0.3326756418091246 +
5257 * x^5 * 0.1938924977115610 - x^7 * 0.1173503194786851 +
5258 * x^9 * 0.0536813784310406 - x^11 * 0.0121323213173444
5259 */
5260 ir_variable *tmp = body.make_temp(type, "atan_tmp");
5261 body.emit(assign(tmp, mul(x, x)));
5262 body.emit(assign(tmp, mul(add(mul(sub(mul(add(mul(sub(mul(add(mul(imm(-0.0121323213173444f),
5263 tmp),
5264 imm(0.0536813784310406f)),
5265 tmp),
5266 imm(0.1173503194786851f)),
5267 tmp),
5268 imm(0.1938924977115610f)),
5269 tmp),
5270 imm(0.3326756418091246f)),
5271 tmp),
5272 imm(0.9999793128310355f)),
5273 x)));
5274
5275 /* range-reduction fixup */
5276 body.emit(assign(tmp, add(tmp,
5277 mul(b2f(greater(abs(y_over_x),
5278 imm(1.0f, type->components()))),
5279 add(mul(tmp,
5280 imm(-2.0f)),
5281 imm(M_PI_2f))))));
5282
5283 /* sign fixup */
5284 body.emit(assign(res, mul(tmp, sign(y_over_x))));
5285 }
5286
5287 ir_function_signature *
_atan(const glsl_type * type)5288 builtin_builder::_atan(const glsl_type *type)
5289 {
5290 ir_variable *y_over_x = in_var(type, "y_over_x");
5291 MAKE_SIG(type, is_not_nir, 1, y_over_x);
5292
5293 ir_variable *tmp = body.make_temp(type, "tmp");
5294 do_atan(body, type, tmp, y_over_x);
5295 body.emit(ret(tmp));
5296
5297 return sig;
5298 }
5299
5300 ir_function_signature *
_sinh(const glsl_type * type)5301 builtin_builder::_sinh(const glsl_type *type)
5302 {
5303 ir_variable *x = in_var(type, "x");
5304 MAKE_SIG(type, v130, 1, x);
5305
5306 /* 0.5 * (e^x - e^(-x)) */
5307 body.emit(ret(mul(imm(0.5f), sub(exp(x), exp(neg(x))))));
5308
5309 return sig;
5310 }
5311
5312 ir_function_signature *
_cosh(const glsl_type * type)5313 builtin_builder::_cosh(const glsl_type *type)
5314 {
5315 ir_variable *x = in_var(type, "x");
5316 MAKE_SIG(type, v130, 1, x);
5317
5318 /* 0.5 * (e^x + e^(-x)) */
5319 body.emit(ret(mul(imm(0.5f), add(exp(x), exp(neg(x))))));
5320
5321 return sig;
5322 }
5323
5324 ir_function_signature *
_tanh(const glsl_type * type)5325 builtin_builder::_tanh(const glsl_type *type)
5326 {
5327 ir_variable *x = in_var(type, "x");
5328 MAKE_SIG(type, v130, 1, x);
5329
5330 /* Clamp x to [-10, +10] to avoid precision problems.
5331 * When x > 10, e^(-x) is so small relative to e^x that it gets flushed to
5332 * zero in the computation e^x + e^(-x). The same happens in the other
5333 * direction when x < -10.
5334 */
5335 ir_variable *t = body.make_temp(type, "tmp");
5336 body.emit(assign(t, min2(max2(x, imm(-10.0f)), imm(10.0f))));
5337
5338 /* (e^x - e^(-x)) / (e^x + e^(-x)) */
5339 body.emit(ret(div(sub(exp(t), exp(neg(t))),
5340 add(exp(t), exp(neg(t))))));
5341
5342 return sig;
5343 }
5344
5345 ir_function_signature *
_asinh(const glsl_type * type)5346 builtin_builder::_asinh(const glsl_type *type)
5347 {
5348 ir_variable *x = in_var(type, "x");
5349 MAKE_SIG(type, v130, 1, x);
5350
5351 body.emit(ret(mul(sign(x), log(add(abs(x), sqrt(add(mul(x, x),
5352 imm(1.0f))))))));
5353 return sig;
5354 }
5355
5356 ir_function_signature *
_acosh(const glsl_type * type)5357 builtin_builder::_acosh(const glsl_type *type)
5358 {
5359 ir_variable *x = in_var(type, "x");
5360 MAKE_SIG(type, v130, 1, x);
5361
5362 body.emit(ret(log(add(x, sqrt(sub(mul(x, x), imm(1.0f)))))));
5363 return sig;
5364 }
5365
5366 ir_function_signature *
_atanh(const glsl_type * type)5367 builtin_builder::_atanh(const glsl_type *type)
5368 {
5369 ir_variable *x = in_var(type, "x");
5370 MAKE_SIG(type, v130, 1, x);
5371
5372 body.emit(ret(mul(imm(0.5f), log(div(add(imm(1.0f), x),
5373 sub(imm(1.0f), x))))));
5374 return sig;
5375 }
5376 /** @} */
5377
5378 /**
5379 * Exponential Functions @{
5380 */
5381
5382 ir_function_signature *
_pow(const glsl_type * type)5383 builtin_builder::_pow(const glsl_type *type)
5384 {
5385 return binop(always_available, ir_binop_pow, type, type, type);
5386 }
5387
UNOP(exp,ir_unop_exp,always_available)5388 UNOP(exp, ir_unop_exp, always_available)
5389 UNOP(log, ir_unop_log, always_available)
5390 UNOP(exp2, ir_unop_exp2, always_available)
5391 UNOP(log2, ir_unop_log2, always_available)
5392 UNOP(atan_op, ir_unop_atan, is_nir)
5393 UNOPA(sqrt, ir_unop_sqrt)
5394 UNOPA(inversesqrt, ir_unop_rsq)
5395
5396 /** @} */
5397
5398 UNOPA(abs, ir_unop_abs)
5399 UNOPA(sign, ir_unop_sign)
5400 UNOPA(floor, ir_unop_floor)
5401 UNOPA(truncate, ir_unop_trunc)
5402 UNOPA(trunc, ir_unop_trunc)
5403 UNOPA(round, ir_unop_round_even)
5404 UNOPA(roundEven, ir_unop_round_even)
5405 UNOPA(ceil, ir_unop_ceil)
5406 UNOPA(fract, ir_unop_fract)
5407
5408 ir_function_signature *
5409 builtin_builder::_mod(builtin_available_predicate avail,
5410 const glsl_type *x_type, const glsl_type *y_type)
5411 {
5412 return binop(avail, ir_binop_mod, x_type, x_type, y_type);
5413 }
5414
5415 ir_function_signature *
_modf(builtin_available_predicate avail,const glsl_type * type)5416 builtin_builder::_modf(builtin_available_predicate avail, const glsl_type *type)
5417 {
5418 ir_variable *x = in_var(type, "x");
5419 ir_variable *i = out_var(type, "i");
5420 MAKE_SIG(type, avail, 2, x, i);
5421
5422 ir_variable *t = body.make_temp(type, "t");
5423 body.emit(assign(t, expr(ir_unop_trunc, x)));
5424 body.emit(assign(i, t));
5425 body.emit(ret(sub(x, t)));
5426
5427 return sig;
5428 }
5429
5430 ir_function_signature *
_min(builtin_available_predicate avail,const glsl_type * x_type,const glsl_type * y_type)5431 builtin_builder::_min(builtin_available_predicate avail,
5432 const glsl_type *x_type, const glsl_type *y_type)
5433 {
5434 return binop(avail, ir_binop_min, x_type, x_type, y_type);
5435 }
5436
5437 ir_function_signature *
_max(builtin_available_predicate avail,const glsl_type * x_type,const glsl_type * y_type)5438 builtin_builder::_max(builtin_available_predicate avail,
5439 const glsl_type *x_type, const glsl_type *y_type)
5440 {
5441 return binop(avail, ir_binop_max, x_type, x_type, y_type);
5442 }
5443
5444 ir_function_signature *
_clamp(builtin_available_predicate avail,const glsl_type * val_type,const glsl_type * bound_type)5445 builtin_builder::_clamp(builtin_available_predicate avail,
5446 const glsl_type *val_type, const glsl_type *bound_type)
5447 {
5448 ir_variable *x = in_var(val_type, "x");
5449 ir_variable *minVal = in_var(bound_type, "minVal");
5450 ir_variable *maxVal = in_var(bound_type, "maxVal");
5451 MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
5452
5453 body.emit(ret(clamp(x, minVal, maxVal)));
5454
5455 return sig;
5456 }
5457
5458 ir_function_signature *
_mix_lrp(builtin_available_predicate avail,const glsl_type * val_type,const glsl_type * blend_type)5459 builtin_builder::_mix_lrp(builtin_available_predicate avail, const glsl_type *val_type, const glsl_type *blend_type)
5460 {
5461 ir_variable *x = in_var(val_type, "x");
5462 ir_variable *y = in_var(val_type, "y");
5463 ir_variable *a = in_var(blend_type, "a");
5464 MAKE_SIG(val_type, avail, 3, x, y, a);
5465
5466 body.emit(ret(lrp(x, y, a)));
5467
5468 return sig;
5469 }
5470
5471 ir_function_signature *
_mix_sel(builtin_available_predicate avail,const glsl_type * val_type,const glsl_type * blend_type)5472 builtin_builder::_mix_sel(builtin_available_predicate avail,
5473 const glsl_type *val_type,
5474 const glsl_type *blend_type)
5475 {
5476 ir_variable *x = in_var(val_type, "x");
5477 ir_variable *y = in_var(val_type, "y");
5478 ir_variable *a = in_var(blend_type, "a");
5479 MAKE_SIG(val_type, avail, 3, x, y, a);
5480
5481 /* csel matches the ternary operator in that a selector of true choses the
5482 * first argument. This differs from mix(x, y, false) which choses the
5483 * second argument (to remain consistent with the interpolating version of
5484 * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
5485 *
5486 * To handle the behavior mismatch, reverse the x and y arguments.
5487 */
5488 body.emit(ret(csel(a, y, x)));
5489
5490 return sig;
5491 }
5492
5493 ir_function_signature *
_step(builtin_available_predicate avail,const glsl_type * edge_type,const glsl_type * x_type)5494 builtin_builder::_step(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
5495 {
5496 ir_variable *edge = in_var(edge_type, "edge");
5497 ir_variable *x = in_var(x_type, "x");
5498 MAKE_SIG(x_type, avail, 2, edge, x);
5499
5500 ir_variable *t = body.make_temp(x_type, "t");
5501 if (x_type->vector_elements == 1) {
5502 /* Both are floats */
5503 if (edge_type->is_double())
5504 body.emit(assign(t, f2d(b2f(gequal(x, edge)))));
5505 else
5506 body.emit(assign(t, b2f(gequal(x, edge))));
5507 } else if (edge_type->vector_elements == 1) {
5508 /* x is a vector but edge is a float */
5509 for (int i = 0; i < x_type->vector_elements; i++) {
5510 if (edge_type->is_double())
5511 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), edge))), 1 << i));
5512 else
5513 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
5514 }
5515 } else {
5516 /* Both are vectors */
5517 for (int i = 0; i < x_type->vector_elements; i++) {
5518 if (edge_type->is_double())
5519 body.emit(assign(t, f2d(b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1)))),
5520 1 << i));
5521 else
5522 body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
5523 1 << i));
5524
5525 }
5526 }
5527 body.emit(ret(t));
5528
5529 return sig;
5530 }
5531
5532 ir_function_signature *
_smoothstep(builtin_available_predicate avail,const glsl_type * edge_type,const glsl_type * x_type)5533 builtin_builder::_smoothstep(builtin_available_predicate avail, const glsl_type *edge_type, const glsl_type *x_type)
5534 {
5535 ir_variable *edge0 = in_var(edge_type, "edge0");
5536 ir_variable *edge1 = in_var(edge_type, "edge1");
5537 ir_variable *x = in_var(x_type, "x");
5538 MAKE_SIG(x_type, avail, 3, edge0, edge1, x);
5539
5540 /* From the GLSL 1.10 specification:
5541 *
5542 * genType t;
5543 * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
5544 * return t * t * (3 - 2 * t);
5545 */
5546
5547 ir_variable *t = body.make_temp(x_type, "t");
5548 body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
5549 IMM_FP(x_type, 0.0), IMM_FP(x_type, 1.0))));
5550
5551 body.emit(ret(mul(t, mul(t, sub(IMM_FP(x_type, 3.0), mul(IMM_FP(x_type, 2.0), t))))));
5552
5553 return sig;
5554 }
5555
5556 ir_function_signature *
_isnan(builtin_available_predicate avail,const glsl_type * type)5557 builtin_builder::_isnan(builtin_available_predicate avail, const glsl_type *type)
5558 {
5559 ir_variable *x = in_var(type, "x");
5560 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
5561
5562 body.emit(ret(nequal(x, x)));
5563
5564 return sig;
5565 }
5566
5567 ir_function_signature *
_isinf(builtin_available_predicate avail,const glsl_type * type)5568 builtin_builder::_isinf(builtin_available_predicate avail, const glsl_type *type)
5569 {
5570 ir_variable *x = in_var(type, "x");
5571 MAKE_SIG(glsl_type::bvec(type->vector_elements), avail, 1, x);
5572
5573 ir_constant_data infinities;
5574 for (int i = 0; i < type->vector_elements; i++) {
5575 switch (type->base_type) {
5576 case GLSL_TYPE_FLOAT:
5577 infinities.f[i] = INFINITY;
5578 break;
5579 case GLSL_TYPE_DOUBLE:
5580 infinities.d[i] = INFINITY;
5581 break;
5582 default:
5583 unreachable("unknown type");
5584 }
5585 }
5586
5587 body.emit(ret(equal(abs(x), imm(type, infinities))));
5588
5589 return sig;
5590 }
5591
5592 ir_function_signature *
_atan2_op(const glsl_type * x_type)5593 builtin_builder::_atan2_op(const glsl_type *x_type)
5594 {
5595 return binop(is_nir, ir_binop_atan2, x_type, x_type, x_type);
5596 }
5597
5598 ir_function_signature *
_floatBitsToInt(const glsl_type * type)5599 builtin_builder::_floatBitsToInt(const glsl_type *type)
5600 {
5601 ir_variable *x = in_var(type, "x");
5602 MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
5603 body.emit(ret(bitcast_f2i(x)));
5604 return sig;
5605 }
5606
5607 ir_function_signature *
_floatBitsToUint(const glsl_type * type)5608 builtin_builder::_floatBitsToUint(const glsl_type *type)
5609 {
5610 ir_variable *x = in_var(type, "x");
5611 MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
5612 body.emit(ret(bitcast_f2u(x)));
5613 return sig;
5614 }
5615
5616 ir_function_signature *
_intBitsToFloat(const glsl_type * type)5617 builtin_builder::_intBitsToFloat(const glsl_type *type)
5618 {
5619 ir_variable *x = in_var(type, "x");
5620 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
5621 body.emit(ret(bitcast_i2f(x)));
5622 return sig;
5623 }
5624
5625 ir_function_signature *
_uintBitsToFloat(const glsl_type * type)5626 builtin_builder::_uintBitsToFloat(const glsl_type *type)
5627 {
5628 ir_variable *x = in_var(type, "x");
5629 MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
5630 body.emit(ret(bitcast_u2f(x)));
5631 return sig;
5632 }
5633
5634 ir_function_signature *
_doubleBitsToInt64(builtin_available_predicate avail,const glsl_type * type)5635 builtin_builder::_doubleBitsToInt64(builtin_available_predicate avail, const glsl_type *type)
5636 {
5637 ir_variable *x = in_var(type, "x");
5638 MAKE_SIG(glsl_type::i64vec(type->vector_elements), avail, 1, x);
5639 body.emit(ret(bitcast_d2i64(x)));
5640 return sig;
5641 }
5642
5643 ir_function_signature *
_doubleBitsToUint64(builtin_available_predicate avail,const glsl_type * type)5644 builtin_builder::_doubleBitsToUint64(builtin_available_predicate avail, const glsl_type *type)
5645 {
5646 ir_variable *x = in_var(type, "x");
5647 MAKE_SIG(glsl_type::u64vec(type->vector_elements), avail, 1, x);
5648 body.emit(ret(bitcast_d2u64(x)));
5649 return sig;
5650 }
5651
5652 ir_function_signature *
_int64BitsToDouble(builtin_available_predicate avail,const glsl_type * type)5653 builtin_builder::_int64BitsToDouble(builtin_available_predicate avail, const glsl_type *type)
5654 {
5655 ir_variable *x = in_var(type, "x");
5656 MAKE_SIG(glsl_type::dvec(type->vector_elements), avail, 1, x);
5657 body.emit(ret(bitcast_i642d(x)));
5658 return sig;
5659 }
5660
5661 ir_function_signature *
_uint64BitsToDouble(builtin_available_predicate avail,const glsl_type * type)5662 builtin_builder::_uint64BitsToDouble(builtin_available_predicate avail, const glsl_type *type)
5663 {
5664 ir_variable *x = in_var(type, "x");
5665 MAKE_SIG(glsl_type::dvec(type->vector_elements), avail, 1, x);
5666 body.emit(ret(bitcast_u642d(x)));
5667 return sig;
5668 }
5669
5670 ir_function_signature *
_packUnorm2x16(builtin_available_predicate avail)5671 builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
5672 {
5673 ir_variable *v = in_var(glsl_type::vec2_type, "v");
5674 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
5675 body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
5676 return sig;
5677 }
5678
5679 ir_function_signature *
_packSnorm2x16(builtin_available_predicate avail)5680 builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
5681 {
5682 ir_variable *v = in_var(glsl_type::vec2_type, "v");
5683 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
5684 body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
5685 return sig;
5686 }
5687
5688 ir_function_signature *
_packUnorm4x8(builtin_available_predicate avail)5689 builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
5690 {
5691 ir_variable *v = in_var(glsl_type::vec4_type, "v");
5692 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
5693 body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
5694 return sig;
5695 }
5696
5697 ir_function_signature *
_packSnorm4x8(builtin_available_predicate avail)5698 builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
5699 {
5700 ir_variable *v = in_var(glsl_type::vec4_type, "v");
5701 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
5702 body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
5703 return sig;
5704 }
5705
5706 ir_function_signature *
_unpackUnorm2x16(builtin_available_predicate avail)5707 builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
5708 {
5709 ir_variable *p = in_var(glsl_type::uint_type, "p");
5710 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
5711 body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
5712 return sig;
5713 }
5714
5715 ir_function_signature *
_unpackSnorm2x16(builtin_available_predicate avail)5716 builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
5717 {
5718 ir_variable *p = in_var(glsl_type::uint_type, "p");
5719 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
5720 body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
5721 return sig;
5722 }
5723
5724
5725 ir_function_signature *
_unpackUnorm4x8(builtin_available_predicate avail)5726 builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
5727 {
5728 ir_variable *p = in_var(glsl_type::uint_type, "p");
5729 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
5730 body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
5731 return sig;
5732 }
5733
5734 ir_function_signature *
_unpackSnorm4x8(builtin_available_predicate avail)5735 builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
5736 {
5737 ir_variable *p = in_var(glsl_type::uint_type, "p");
5738 MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
5739 body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
5740 return sig;
5741 }
5742
5743 ir_function_signature *
_packHalf2x16(builtin_available_predicate avail)5744 builtin_builder::_packHalf2x16(builtin_available_predicate avail)
5745 {
5746 ir_variable *v = in_var(glsl_type::vec2_type, "v");
5747 MAKE_SIG(glsl_type::uint_type, avail, 1, v);
5748 body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
5749 return sig;
5750 }
5751
5752 ir_function_signature *
_unpackHalf2x16(builtin_available_predicate avail)5753 builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
5754 {
5755 ir_variable *p = in_var(glsl_type::uint_type, "p");
5756 MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
5757 body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
5758 return sig;
5759 }
5760
5761 ir_function_signature *
_packDouble2x32(builtin_available_predicate avail)5762 builtin_builder::_packDouble2x32(builtin_available_predicate avail)
5763 {
5764 ir_variable *v = in_var(glsl_type::uvec2_type, "v");
5765 MAKE_SIG(glsl_type::double_type, avail, 1, v);
5766 body.emit(ret(expr(ir_unop_pack_double_2x32, v)));
5767 return sig;
5768 }
5769
5770 ir_function_signature *
_unpackDouble2x32(builtin_available_predicate avail)5771 builtin_builder::_unpackDouble2x32(builtin_available_predicate avail)
5772 {
5773 ir_variable *p = in_var(glsl_type::double_type, "p");
5774 MAKE_SIG(glsl_type::uvec2_type, avail, 1, p);
5775 body.emit(ret(expr(ir_unop_unpack_double_2x32, p)));
5776 return sig;
5777 }
5778
5779 ir_function_signature *
_packInt2x32(builtin_available_predicate avail)5780 builtin_builder::_packInt2x32(builtin_available_predicate avail)
5781 {
5782 ir_variable *v = in_var(glsl_type::ivec2_type, "v");
5783 MAKE_SIG(glsl_type::int64_t_type, avail, 1, v);
5784 body.emit(ret(expr(ir_unop_pack_int_2x32, v)));
5785 return sig;
5786 }
5787
5788 ir_function_signature *
_unpackInt2x32(builtin_available_predicate avail)5789 builtin_builder::_unpackInt2x32(builtin_available_predicate avail)
5790 {
5791 ir_variable *p = in_var(glsl_type::int64_t_type, "p");
5792 MAKE_SIG(glsl_type::ivec2_type, avail, 1, p);
5793 body.emit(ret(expr(ir_unop_unpack_int_2x32, p)));
5794 return sig;
5795 }
5796
5797 ir_function_signature *
_packUint2x32(builtin_available_predicate avail)5798 builtin_builder::_packUint2x32(builtin_available_predicate avail)
5799 {
5800 ir_variable *v = in_var(glsl_type::uvec2_type, "v");
5801 MAKE_SIG(glsl_type::uint64_t_type, avail, 1, v);
5802 body.emit(ret(expr(ir_unop_pack_uint_2x32, v)));
5803 return sig;
5804 }
5805
5806 ir_function_signature *
_unpackUint2x32(builtin_available_predicate avail)5807 builtin_builder::_unpackUint2x32(builtin_available_predicate avail)
5808 {
5809 ir_variable *p = in_var(glsl_type::uint64_t_type, "p");
5810 MAKE_SIG(glsl_type::uvec2_type, avail, 1, p);
5811 body.emit(ret(expr(ir_unop_unpack_uint_2x32, p)));
5812 return sig;
5813 }
5814
5815 ir_function_signature *
_length(builtin_available_predicate avail,const glsl_type * type)5816 builtin_builder::_length(builtin_available_predicate avail, const glsl_type *type)
5817 {
5818 ir_variable *x = in_var(type, "x");
5819 MAKE_SIG(type->get_base_type(), avail, 1, x);
5820
5821 body.emit(ret(sqrt(dot(x, x))));
5822
5823 return sig;
5824 }
5825
5826 ir_function_signature *
_distance(builtin_available_predicate avail,const glsl_type * type)5827 builtin_builder::_distance(builtin_available_predicate avail, const glsl_type *type)
5828 {
5829 ir_variable *p0 = in_var(type, "p0");
5830 ir_variable *p1 = in_var(type, "p1");
5831 MAKE_SIG(type->get_base_type(), avail, 2, p0, p1);
5832
5833 if (type->vector_elements == 1) {
5834 body.emit(ret(abs(sub(p0, p1))));
5835 } else {
5836 ir_variable *p = body.make_temp(type, "p");
5837 body.emit(assign(p, sub(p0, p1)));
5838 body.emit(ret(sqrt(dot(p, p))));
5839 }
5840
5841 return sig;
5842 }
5843
5844 ir_function_signature *
_dot(builtin_available_predicate avail,const glsl_type * type)5845 builtin_builder::_dot(builtin_available_predicate avail, const glsl_type *type)
5846 {
5847 if (type->vector_elements == 1)
5848 return binop(avail, ir_binop_mul, type, type, type);
5849
5850 return binop(avail, ir_binop_dot,
5851 type->get_base_type(), type, type);
5852 }
5853
5854 ir_function_signature *
_cross(builtin_available_predicate avail,const glsl_type * type)5855 builtin_builder::_cross(builtin_available_predicate avail, const glsl_type *type)
5856 {
5857 ir_variable *a = in_var(type, "a");
5858 ir_variable *b = in_var(type, "b");
5859 MAKE_SIG(type, avail, 2, a, b);
5860
5861 int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
5862 int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
5863
5864 body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
5865 mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
5866
5867 return sig;
5868 }
5869
5870 ir_function_signature *
_normalize(builtin_available_predicate avail,const glsl_type * type)5871 builtin_builder::_normalize(builtin_available_predicate avail, const glsl_type *type)
5872 {
5873 ir_variable *x = in_var(type, "x");
5874 MAKE_SIG(type, avail, 1, x);
5875
5876 if (type->vector_elements == 1) {
5877 body.emit(ret(sign(x)));
5878 } else {
5879 body.emit(ret(mul(x, rsq(dot(x, x)))));
5880 }
5881
5882 return sig;
5883 }
5884
5885 ir_function_signature *
_ftransform()5886 builtin_builder::_ftransform()
5887 {
5888 MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
5889
5890 /* ftransform() refers to global variables, and is always emitted
5891 * directly by ast_function.cpp. Just emit a prototype here so we
5892 * can recognize calls to it.
5893 */
5894 return sig;
5895 }
5896
5897 ir_function_signature *
_faceforward(builtin_available_predicate avail,const glsl_type * type)5898 builtin_builder::_faceforward(builtin_available_predicate avail, const glsl_type *type)
5899 {
5900 ir_variable *N = in_var(type, "N");
5901 ir_variable *I = in_var(type, "I");
5902 ir_variable *Nref = in_var(type, "Nref");
5903 MAKE_SIG(type, avail, 3, N, I, Nref);
5904
5905 body.emit(if_tree(less(dot(Nref, I), IMM_FP(type, 0.0)),
5906 ret(N), ret(neg(N))));
5907
5908 return sig;
5909 }
5910
5911 ir_function_signature *
_reflect(builtin_available_predicate avail,const glsl_type * type)5912 builtin_builder::_reflect(builtin_available_predicate avail, const glsl_type *type)
5913 {
5914 ir_variable *I = in_var(type, "I");
5915 ir_variable *N = in_var(type, "N");
5916 MAKE_SIG(type, avail, 2, I, N);
5917
5918 /* I - 2 * dot(N, I) * N */
5919 body.emit(ret(sub(I, mul(IMM_FP(type, 2.0), mul(dot(N, I), N)))));
5920
5921 return sig;
5922 }
5923
5924 ir_function_signature *
_refract(builtin_available_predicate avail,const glsl_type * type)5925 builtin_builder::_refract(builtin_available_predicate avail, const glsl_type *type)
5926 {
5927 ir_variable *I = in_var(type, "I");
5928 ir_variable *N = in_var(type, "N");
5929 ir_variable *eta = in_var(type->get_base_type(), "eta");
5930 MAKE_SIG(type, avail, 3, I, N, eta);
5931
5932 ir_variable *n_dot_i = body.make_temp(type->get_base_type(), "n_dot_i");
5933 body.emit(assign(n_dot_i, dot(N, I)));
5934
5935 /* From the GLSL 1.10 specification:
5936 * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
5937 * if (k < 0.0)
5938 * return genType(0.0)
5939 * else
5940 * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
5941 */
5942 ir_variable *k = body.make_temp(type->get_base_type(), "k");
5943 body.emit(assign(k, sub(IMM_FP(type, 1.0),
5944 mul(eta, mul(eta, sub(IMM_FP(type, 1.0),
5945 mul(n_dot_i, n_dot_i)))))));
5946 body.emit(if_tree(less(k, IMM_FP(type, 0.0)),
5947 ret(ir_constant::zero(mem_ctx, type)),
5948 ret(sub(mul(eta, I),
5949 mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
5950
5951 return sig;
5952 }
5953
5954 ir_function_signature *
_matrixCompMult(builtin_available_predicate avail,const glsl_type * type)5955 builtin_builder::_matrixCompMult(builtin_available_predicate avail, const glsl_type *type)
5956 {
5957 ir_variable *x = in_var(type, "x");
5958 ir_variable *y = in_var(type, "y");
5959 MAKE_SIG(type, avail, 2, x, y);
5960
5961 ir_variable *z = body.make_temp(type, "z");
5962 for (int i = 0; i < type->matrix_columns; i++) {
5963 body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
5964 }
5965 body.emit(ret(z));
5966
5967 return sig;
5968 }
5969
5970 ir_function_signature *
_outerProduct(builtin_available_predicate avail,const glsl_type * type)5971 builtin_builder::_outerProduct(builtin_available_predicate avail, const glsl_type *type)
5972 {
5973 ir_variable *c;
5974 ir_variable *r;
5975
5976 if (type->is_double()) {
5977 r = in_var(glsl_type::dvec(type->matrix_columns), "r");
5978 c = in_var(glsl_type::dvec(type->vector_elements), "c");
5979 } else {
5980 r = in_var(glsl_type::vec(type->matrix_columns), "r");
5981 c = in_var(glsl_type::vec(type->vector_elements), "c");
5982 }
5983 MAKE_SIG(type, avail, 2, c, r);
5984
5985 ir_variable *m = body.make_temp(type, "m");
5986 for (int i = 0; i < type->matrix_columns; i++) {
5987 body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
5988 }
5989 body.emit(ret(m));
5990
5991 return sig;
5992 }
5993
5994 ir_function_signature *
_transpose(builtin_available_predicate avail,const glsl_type * orig_type)5995 builtin_builder::_transpose(builtin_available_predicate avail, const glsl_type *orig_type)
5996 {
5997 const glsl_type *transpose_type =
5998 glsl_type::get_instance(orig_type->base_type,
5999 orig_type->matrix_columns,
6000 orig_type->vector_elements);
6001
6002 ir_variable *m = in_var(orig_type, "m");
6003 MAKE_SIG(transpose_type, avail, 1, m);
6004
6005 ir_variable *t = body.make_temp(transpose_type, "t");
6006 for (int i = 0; i < orig_type->matrix_columns; i++) {
6007 for (int j = 0; j < orig_type->vector_elements; j++) {
6008 body.emit(assign(array_ref(t, j),
6009 matrix_elt(m, i, j),
6010 1 << i));
6011 }
6012 }
6013 body.emit(ret(t));
6014
6015 return sig;
6016 }
6017
6018 ir_function_signature *
_determinant_mat2(builtin_available_predicate avail,const glsl_type * type)6019 builtin_builder::_determinant_mat2(builtin_available_predicate avail, const glsl_type *type)
6020 {
6021 ir_variable *m = in_var(type, "m");
6022 MAKE_SIG(type->get_base_type(), avail, 1, m);
6023
6024 body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
6025 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
6026
6027 return sig;
6028 }
6029
6030 ir_function_signature *
_determinant_mat3(builtin_available_predicate avail,const glsl_type * type)6031 builtin_builder::_determinant_mat3(builtin_available_predicate avail, const glsl_type *type)
6032 {
6033 ir_variable *m = in_var(type, "m");
6034 MAKE_SIG(type->get_base_type(), avail, 1, m);
6035
6036 ir_expression *f1 =
6037 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
6038 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
6039
6040 ir_expression *f2 =
6041 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
6042 mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
6043
6044 ir_expression *f3 =
6045 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
6046 mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
6047
6048 body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
6049 mul(matrix_elt(m, 0, 1), f2)),
6050 mul(matrix_elt(m, 0, 2), f3))));
6051
6052 return sig;
6053 }
6054
6055 ir_function_signature *
_determinant_mat4(builtin_available_predicate avail,const glsl_type * type)6056 builtin_builder::_determinant_mat4(builtin_available_predicate avail, const glsl_type *type)
6057 {
6058 ir_variable *m = in_var(type, "m");
6059 const glsl_type *btype = type->get_base_type();
6060 MAKE_SIG(btype, avail, 1, m);
6061
6062 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
6063 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
6064 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
6065 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
6066 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
6067 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
6068 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
6069 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
6070 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
6071 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
6072 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
6073 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
6074 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
6075 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
6076 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
6077 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
6078 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
6079 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
6080 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
6081
6082 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)))));
6083 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)))));
6084 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)))));
6085 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)))));
6086 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)))));
6087 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)))));
6088 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)))));
6089 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)))));
6090 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)))));
6091 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)))));
6092 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)))));
6093 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)))));
6094 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)))));
6095 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)))));
6096 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)))));
6097 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)))));
6098 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)))));
6099 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)))));
6100 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)))));
6101
6102 ir_variable *adj_0 = body.make_temp(btype == glsl_type::float_type ? glsl_type::vec4_type : glsl_type::dvec4_type, "adj_0");
6103
6104 body.emit(assign(adj_0,
6105 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
6106 mul(matrix_elt(m, 1, 2), SubFactor01)),
6107 mul(matrix_elt(m, 1, 3), SubFactor02)),
6108 WRITEMASK_X));
6109 body.emit(assign(adj_0, neg(
6110 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
6111 mul(matrix_elt(m, 1, 2), SubFactor03)),
6112 mul(matrix_elt(m, 1, 3), SubFactor04))),
6113 WRITEMASK_Y));
6114 body.emit(assign(adj_0,
6115 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
6116 mul(matrix_elt(m, 1, 1), SubFactor03)),
6117 mul(matrix_elt(m, 1, 3), SubFactor05)),
6118 WRITEMASK_Z));
6119 body.emit(assign(adj_0, neg(
6120 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
6121 mul(matrix_elt(m, 1, 1), SubFactor04)),
6122 mul(matrix_elt(m, 1, 2), SubFactor05))),
6123 WRITEMASK_W));
6124
6125 body.emit(ret(dot(array_ref(m, 0), adj_0)));
6126
6127 return sig;
6128 }
6129
6130 ir_function_signature *
_inverse_mat2(builtin_available_predicate avail,const glsl_type * type)6131 builtin_builder::_inverse_mat2(builtin_available_predicate avail, const glsl_type *type)
6132 {
6133 ir_variable *m = in_var(type, "m");
6134 MAKE_SIG(type, avail, 1, m);
6135
6136 ir_variable *adj = body.make_temp(type, "adj");
6137 body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
6138 body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
6139 body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
6140 body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
6141
6142 ir_expression *det =
6143 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
6144 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
6145
6146 body.emit(ret(div(adj, det)));
6147 return sig;
6148 }
6149
6150 ir_function_signature *
_inverse_mat3(builtin_available_predicate avail,const glsl_type * type)6151 builtin_builder::_inverse_mat3(builtin_available_predicate avail, const glsl_type *type)
6152 {
6153 ir_variable *m = in_var(type, "m");
6154 const glsl_type *btype = type->get_base_type();
6155 MAKE_SIG(type, avail, 1, m);
6156
6157 ir_variable *f11_22_21_12 = body.make_temp(btype, "f11_22_21_12");
6158 ir_variable *f10_22_20_12 = body.make_temp(btype, "f10_22_20_12");
6159 ir_variable *f10_21_20_11 = body.make_temp(btype, "f10_21_20_11");
6160
6161 body.emit(assign(f11_22_21_12,
6162 sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
6163 mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
6164 body.emit(assign(f10_22_20_12,
6165 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
6166 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
6167 body.emit(assign(f10_21_20_11,
6168 sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
6169 mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
6170
6171 ir_variable *adj = body.make_temp(type, "adj");
6172 body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
6173 body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
6174 body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
6175
6176 body.emit(assign(array_ref(adj, 0), neg(
6177 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
6178 mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
6179 WRITEMASK_Y));
6180 body.emit(assign(array_ref(adj, 1),
6181 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
6182 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
6183 WRITEMASK_Y));
6184 body.emit(assign(array_ref(adj, 2), neg(
6185 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
6186 mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
6187 WRITEMASK_Y));
6188
6189 body.emit(assign(array_ref(adj, 0),
6190 sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
6191 mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
6192 WRITEMASK_Z));
6193 body.emit(assign(array_ref(adj, 1), neg(
6194 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
6195 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
6196 WRITEMASK_Z));
6197 body.emit(assign(array_ref(adj, 2),
6198 sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
6199 mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
6200 WRITEMASK_Z));
6201
6202 ir_expression *det =
6203 add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
6204 mul(matrix_elt(m, 0, 1), f10_22_20_12)),
6205 mul(matrix_elt(m, 0, 2), f10_21_20_11));
6206
6207 body.emit(ret(div(adj, det)));
6208
6209 return sig;
6210 }
6211
6212 ir_function_signature *
_inverse_mat4(builtin_available_predicate avail,const glsl_type * type)6213 builtin_builder::_inverse_mat4(builtin_available_predicate avail, const glsl_type *type)
6214 {
6215 ir_variable *m = in_var(type, "m");
6216 const glsl_type *btype = type->get_base_type();
6217 MAKE_SIG(type, avail, 1, m);
6218
6219 ir_variable *SubFactor00 = body.make_temp(btype, "SubFactor00");
6220 ir_variable *SubFactor01 = body.make_temp(btype, "SubFactor01");
6221 ir_variable *SubFactor02 = body.make_temp(btype, "SubFactor02");
6222 ir_variable *SubFactor03 = body.make_temp(btype, "SubFactor03");
6223 ir_variable *SubFactor04 = body.make_temp(btype, "SubFactor04");
6224 ir_variable *SubFactor05 = body.make_temp(btype, "SubFactor05");
6225 ir_variable *SubFactor06 = body.make_temp(btype, "SubFactor06");
6226 ir_variable *SubFactor07 = body.make_temp(btype, "SubFactor07");
6227 ir_variable *SubFactor08 = body.make_temp(btype, "SubFactor08");
6228 ir_variable *SubFactor09 = body.make_temp(btype, "SubFactor09");
6229 ir_variable *SubFactor10 = body.make_temp(btype, "SubFactor10");
6230 ir_variable *SubFactor11 = body.make_temp(btype, "SubFactor11");
6231 ir_variable *SubFactor12 = body.make_temp(btype, "SubFactor12");
6232 ir_variable *SubFactor13 = body.make_temp(btype, "SubFactor13");
6233 ir_variable *SubFactor14 = body.make_temp(btype, "SubFactor14");
6234 ir_variable *SubFactor15 = body.make_temp(btype, "SubFactor15");
6235 ir_variable *SubFactor16 = body.make_temp(btype, "SubFactor16");
6236 ir_variable *SubFactor17 = body.make_temp(btype, "SubFactor17");
6237 ir_variable *SubFactor18 = body.make_temp(btype, "SubFactor18");
6238
6239 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)))));
6240 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)))));
6241 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)))));
6242 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)))));
6243 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)))));
6244 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)))));
6245 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)))));
6246 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)))));
6247 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)))));
6248 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)))));
6249 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)))));
6250 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)))));
6251 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)))));
6252 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)))));
6253 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)))));
6254 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)))));
6255 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)))));
6256 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)))));
6257 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)))));
6258
6259 ir_variable *adj = body.make_temp(btype == glsl_type::float_type ? glsl_type::mat4_type : glsl_type::dmat4_type, "adj");
6260 body.emit(assign(array_ref(adj, 0),
6261 add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
6262 mul(matrix_elt(m, 1, 2), SubFactor01)),
6263 mul(matrix_elt(m, 1, 3), SubFactor02)),
6264 WRITEMASK_X));
6265 body.emit(assign(array_ref(adj, 1), neg(
6266 add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
6267 mul(matrix_elt(m, 1, 2), SubFactor03)),
6268 mul(matrix_elt(m, 1, 3), SubFactor04))),
6269 WRITEMASK_X));
6270 body.emit(assign(array_ref(adj, 2),
6271 add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
6272 mul(matrix_elt(m, 1, 1), SubFactor03)),
6273 mul(matrix_elt(m, 1, 3), SubFactor05)),
6274 WRITEMASK_X));
6275 body.emit(assign(array_ref(adj, 3), neg(
6276 add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
6277 mul(matrix_elt(m, 1, 1), SubFactor04)),
6278 mul(matrix_elt(m, 1, 2), SubFactor05))),
6279 WRITEMASK_X));
6280
6281 body.emit(assign(array_ref(adj, 0), neg(
6282 add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
6283 mul(matrix_elt(m, 0, 2), SubFactor01)),
6284 mul(matrix_elt(m, 0, 3), SubFactor02))),
6285 WRITEMASK_Y));
6286 body.emit(assign(array_ref(adj, 1),
6287 add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
6288 mul(matrix_elt(m, 0, 2), SubFactor03)),
6289 mul(matrix_elt(m, 0, 3), SubFactor04)),
6290 WRITEMASK_Y));
6291 body.emit(assign(array_ref(adj, 2), neg(
6292 add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
6293 mul(matrix_elt(m, 0, 1), SubFactor03)),
6294 mul(matrix_elt(m, 0, 3), SubFactor05))),
6295 WRITEMASK_Y));
6296 body.emit(assign(array_ref(adj, 3),
6297 add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
6298 mul(matrix_elt(m, 0, 1), SubFactor04)),
6299 mul(matrix_elt(m, 0, 2), SubFactor05)),
6300 WRITEMASK_Y));
6301
6302 body.emit(assign(array_ref(adj, 0),
6303 add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
6304 mul(matrix_elt(m, 0, 2), SubFactor07)),
6305 mul(matrix_elt(m, 0, 3), SubFactor08)),
6306 WRITEMASK_Z));
6307 body.emit(assign(array_ref(adj, 1), neg(
6308 add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
6309 mul(matrix_elt(m, 0, 2), SubFactor09)),
6310 mul(matrix_elt(m, 0, 3), SubFactor10))),
6311 WRITEMASK_Z));
6312 body.emit(assign(array_ref(adj, 2),
6313 add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
6314 mul(matrix_elt(m, 0, 1), SubFactor09)),
6315 mul(matrix_elt(m, 0, 3), SubFactor12)),
6316 WRITEMASK_Z));
6317 body.emit(assign(array_ref(adj, 3), neg(
6318 add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
6319 mul(matrix_elt(m, 0, 1), SubFactor10)),
6320 mul(matrix_elt(m, 0, 2), SubFactor12))),
6321 WRITEMASK_Z));
6322
6323 body.emit(assign(array_ref(adj, 0), neg(
6324 add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
6325 mul(matrix_elt(m, 0, 2), SubFactor14)),
6326 mul(matrix_elt(m, 0, 3), SubFactor15))),
6327 WRITEMASK_W));
6328 body.emit(assign(array_ref(adj, 1),
6329 add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
6330 mul(matrix_elt(m, 0, 2), SubFactor16)),
6331 mul(matrix_elt(m, 0, 3), SubFactor17)),
6332 WRITEMASK_W));
6333 body.emit(assign(array_ref(adj, 2), neg(
6334 add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
6335 mul(matrix_elt(m, 0, 1), SubFactor16)),
6336 mul(matrix_elt(m, 0, 3), SubFactor18))),
6337 WRITEMASK_W));
6338 body.emit(assign(array_ref(adj, 3),
6339 add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
6340 mul(matrix_elt(m, 0, 1), SubFactor17)),
6341 mul(matrix_elt(m, 0, 2), SubFactor18)),
6342 WRITEMASK_W));
6343
6344 ir_expression *det =
6345 add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
6346 add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
6347 add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
6348 mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
6349
6350 body.emit(ret(div(adj, det)));
6351
6352 return sig;
6353 }
6354
6355
6356 ir_function_signature *
_lessThan(builtin_available_predicate avail,const glsl_type * type)6357 builtin_builder::_lessThan(builtin_available_predicate avail,
6358 const glsl_type *type)
6359 {
6360 return binop(avail, ir_binop_less,
6361 glsl_type::bvec(type->vector_elements), type, type);
6362 }
6363
6364 ir_function_signature *
_lessThanEqual(builtin_available_predicate avail,const glsl_type * type)6365 builtin_builder::_lessThanEqual(builtin_available_predicate avail,
6366 const glsl_type *type)
6367 {
6368 return binop(avail, ir_binop_gequal,
6369 glsl_type::bvec(type->vector_elements), type, type,
6370 true);
6371 }
6372
6373 ir_function_signature *
_greaterThan(builtin_available_predicate avail,const glsl_type * type)6374 builtin_builder::_greaterThan(builtin_available_predicate avail,
6375 const glsl_type *type)
6376 {
6377 return binop(avail, ir_binop_less,
6378 glsl_type::bvec(type->vector_elements), type, type,
6379 true);
6380 }
6381
6382 ir_function_signature *
_greaterThanEqual(builtin_available_predicate avail,const glsl_type * type)6383 builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
6384 const glsl_type *type)
6385 {
6386 return binop(avail, ir_binop_gequal,
6387 glsl_type::bvec(type->vector_elements), type, type);
6388 }
6389
6390 ir_function_signature *
_equal(builtin_available_predicate avail,const glsl_type * type)6391 builtin_builder::_equal(builtin_available_predicate avail,
6392 const glsl_type *type)
6393 {
6394 return binop(avail, ir_binop_equal,
6395 glsl_type::bvec(type->vector_elements), type, type);
6396 }
6397
6398 ir_function_signature *
_notEqual(builtin_available_predicate avail,const glsl_type * type)6399 builtin_builder::_notEqual(builtin_available_predicate avail,
6400 const glsl_type *type)
6401 {
6402 return binop(avail, ir_binop_nequal,
6403 glsl_type::bvec(type->vector_elements), type, type);
6404 }
6405
6406 ir_function_signature *
_any(const glsl_type * type)6407 builtin_builder::_any(const glsl_type *type)
6408 {
6409 ir_variable *v = in_var(type, "v");
6410 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
6411
6412 const unsigned vec_elem = v->type->vector_elements;
6413 body.emit(ret(expr(ir_binop_any_nequal, v, imm(false, vec_elem))));
6414
6415 return sig;
6416 }
6417
6418 ir_function_signature *
_all(const glsl_type * type)6419 builtin_builder::_all(const glsl_type *type)
6420 {
6421 ir_variable *v = in_var(type, "v");
6422 MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
6423
6424 const unsigned vec_elem = v->type->vector_elements;
6425 body.emit(ret(expr(ir_binop_all_equal, v, imm(true, vec_elem))));
6426
6427 return sig;
6428 }
6429
UNOP(not,ir_unop_logic_not,always_available)6430 UNOP(not, ir_unop_logic_not, always_available)
6431
6432 static bool
6433 has_lod(const glsl_type *sampler_type)
6434 {
6435 assert(sampler_type->is_sampler());
6436
6437 switch (sampler_type->sampler_dimensionality) {
6438 case GLSL_SAMPLER_DIM_RECT:
6439 case GLSL_SAMPLER_DIM_BUF:
6440 case GLSL_SAMPLER_DIM_MS:
6441 return false;
6442 default:
6443 return true;
6444 }
6445 }
6446
6447 ir_function_signature *
_textureSize(builtin_available_predicate avail,const glsl_type * return_type,const glsl_type * sampler_type)6448 builtin_builder::_textureSize(builtin_available_predicate avail,
6449 const glsl_type *return_type,
6450 const glsl_type *sampler_type)
6451 {
6452 ir_variable *s = in_var(sampler_type, "sampler");
6453 /* The sampler always exists; add optional lod later. */
6454 MAKE_SIG(return_type, avail, 1, s);
6455
6456 ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
6457 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
6458
6459 if (has_lod(sampler_type)) {
6460 ir_variable *lod = in_var(glsl_type::int_type, "lod");
6461 sig->parameters.push_tail(lod);
6462 tex->lod_info.lod = var_ref(lod);
6463 } else {
6464 tex->lod_info.lod = imm(0u);
6465 }
6466
6467 body.emit(ret(tex));
6468
6469 return sig;
6470 }
6471
6472 ir_function_signature *
_textureSamples(builtin_available_predicate avail,const glsl_type * sampler_type)6473 builtin_builder::_textureSamples(builtin_available_predicate avail,
6474 const glsl_type *sampler_type)
6475 {
6476 ir_variable *s = in_var(sampler_type, "sampler");
6477 MAKE_SIG(glsl_type::int_type, avail, 1, s);
6478
6479 ir_texture *tex = new(mem_ctx) ir_texture(ir_texture_samples);
6480 tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), glsl_type::int_type);
6481 body.emit(ret(tex));
6482
6483 return sig;
6484 }
6485
6486 ir_function_signature *
_texture(ir_texture_opcode opcode,builtin_available_predicate avail,const glsl_type * return_type,const glsl_type * sampler_type,const glsl_type * coord_type,int flags)6487 builtin_builder::_texture(ir_texture_opcode opcode,
6488 builtin_available_predicate avail,
6489 const glsl_type *return_type,
6490 const glsl_type *sampler_type,
6491 const glsl_type *coord_type,
6492 int flags)
6493 {
6494 ir_variable *s = in_var(sampler_type, "sampler");
6495 ir_variable *P = in_var(coord_type, "P");
6496 /* The sampler and coordinate always exist; add optional parameters later. */
6497 MAKE_SIG(return_type, avail, 2, s, P);
6498
6499 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
6500 tex->set_sampler(var_ref(s), return_type);
6501
6502 const int coord_size = sampler_type->coordinate_components();
6503
6504 if (coord_size == coord_type->vector_elements) {
6505 tex->coordinate = var_ref(P);
6506 } else {
6507 /* The incoming coordinate also has the projector or shadow comparator,
6508 * so we need to swizzle those away.
6509 */
6510 tex->coordinate = swizzle_for_size(P, coord_size);
6511 }
6512
6513 /* The projector is always in the last component. */
6514 if (flags & TEX_PROJECT)
6515 tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
6516
6517 if (sampler_type->sampler_shadow) {
6518 if (opcode == ir_tg4) {
6519 /* gather has refz as a separate parameter, immediately after the
6520 * coordinate
6521 */
6522 ir_variable *refz = in_var(glsl_type::float_type, "refz");
6523 sig->parameters.push_tail(refz);
6524 tex->shadow_comparator = var_ref(refz);
6525 } else {
6526 /* The shadow comparator is normally in the Z component, but a few types
6527 * have sufficiently large coordinates that it's in W.
6528 */
6529 tex->shadow_comparator = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
6530 }
6531 }
6532
6533 if (opcode == ir_txl) {
6534 ir_variable *lod = in_var(glsl_type::float_type, "lod");
6535 sig->parameters.push_tail(lod);
6536 tex->lod_info.lod = var_ref(lod);
6537 } else if (opcode == ir_txd) {
6538 int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
6539 ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
6540 ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
6541 sig->parameters.push_tail(dPdx);
6542 sig->parameters.push_tail(dPdy);
6543 tex->lod_info.grad.dPdx = var_ref(dPdx);
6544 tex->lod_info.grad.dPdy = var_ref(dPdy);
6545 }
6546
6547 if (flags & (TEX_OFFSET | TEX_OFFSET_NONCONST)) {
6548 int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
6549 ir_variable *offset =
6550 new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset",
6551 (flags & TEX_OFFSET) ? ir_var_const_in : ir_var_function_in);
6552 sig->parameters.push_tail(offset);
6553 tex->offset = var_ref(offset);
6554 }
6555
6556 if (flags & TEX_OFFSET_ARRAY) {
6557 ir_variable *offsets =
6558 new(mem_ctx) ir_variable(glsl_type::get_array_instance(glsl_type::ivec2_type, 4),
6559 "offsets", ir_var_const_in);
6560 sig->parameters.push_tail(offsets);
6561 tex->offset = var_ref(offsets);
6562 }
6563
6564 if (opcode == ir_tg4) {
6565 if (flags & TEX_COMPONENT) {
6566 ir_variable *component =
6567 new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in);
6568 sig->parameters.push_tail(component);
6569 tex->lod_info.component = var_ref(component);
6570 }
6571 else {
6572 tex->lod_info.component = imm(0);
6573 }
6574 }
6575
6576 /* The "bias" parameter comes /after/ the "offset" parameter, which is
6577 * inconsistent with both textureLodOffset and textureGradOffset.
6578 */
6579 if (opcode == ir_txb) {
6580 ir_variable *bias = in_var(glsl_type::float_type, "bias");
6581 sig->parameters.push_tail(bias);
6582 tex->lod_info.bias = var_ref(bias);
6583 }
6584
6585 body.emit(ret(tex));
6586
6587 return sig;
6588 }
6589
6590 ir_function_signature *
_textureCubeArrayShadow(ir_texture_opcode opcode,builtin_available_predicate avail,const glsl_type * sampler_type)6591 builtin_builder::_textureCubeArrayShadow(ir_texture_opcode opcode,
6592 builtin_available_predicate avail,
6593 const glsl_type *sampler_type)
6594 {
6595 ir_variable *s = in_var(sampler_type, "sampler");
6596 ir_variable *P = in_var(glsl_type::vec4_type, "P");
6597 ir_variable *compare = in_var(glsl_type::float_type, "compare");
6598 MAKE_SIG(glsl_type::float_type, avail, 3, s, P, compare);
6599
6600 ir_texture *tex = new(mem_ctx) ir_texture(opcode);
6601 tex->set_sampler(var_ref(s), glsl_type::float_type);
6602
6603 tex->coordinate = var_ref(P);
6604 tex->shadow_comparator = var_ref(compare);
6605
6606 if (opcode == ir_txb) {
6607 ir_variable *bias = in_var(glsl_type::float_type, "bias");
6608 sig->parameters.push_tail(bias);
6609 tex->lod_info.bias = var_ref(bias);
6610 }
6611
6612 if (opcode == ir_txl) {
6613 ir_variable *lod = in_var(glsl_type::float_type, "lod");
6614 sig->parameters.push_tail(lod);
6615 tex->lod_info.lod = var_ref(lod);
6616 }
6617
6618 body.emit(ret(tex));
6619
6620 return sig;
6621 }
6622
6623 ir_function_signature *
_texelFetch(builtin_available_predicate avail,const glsl_type * return_type,const glsl_type * sampler_type,const glsl_type * coord_type,const glsl_type * offset_type)6624 builtin_builder::_texelFetch(builtin_available_predicate avail,
6625 const glsl_type *return_type,
6626 const glsl_type *sampler_type,
6627 const glsl_type *coord_type,
6628 const glsl_type *offset_type)
6629 {
6630 ir_variable *s = in_var(sampler_type, "sampler");
6631 ir_variable *P = in_var(coord_type, "P");
6632 /* The sampler and coordinate always exist; add optional parameters later. */
6633 MAKE_SIG(return_type, avail, 2, s, P);
6634
6635 ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
6636 tex->coordinate = var_ref(P);
6637 tex->set_sampler(var_ref(s), return_type);
6638
6639 if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
6640 ir_variable *sample = in_var(glsl_type::int_type, "sample");
6641 sig->parameters.push_tail(sample);
6642 tex->lod_info.sample_index = var_ref(sample);
6643 tex->op = ir_txf_ms;
6644 } else if (has_lod(sampler_type)) {
6645 ir_variable *lod = in_var(glsl_type::int_type, "lod");
6646 sig->parameters.push_tail(lod);
6647 tex->lod_info.lod = var_ref(lod);
6648 } else {
6649 tex->lod_info.lod = imm(0u);
6650 }
6651
6652 if (offset_type != NULL) {
6653 ir_variable *offset =
6654 new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in);
6655 sig->parameters.push_tail(offset);
6656 tex->offset = var_ref(offset);
6657 }
6658
6659 body.emit(ret(tex));
6660
6661 return sig;
6662 }
6663
6664 ir_function_signature *
_EmitVertex()6665 builtin_builder::_EmitVertex()
6666 {
6667 MAKE_SIG(glsl_type::void_type, gs_only, 0);
6668
6669 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
6670 body.emit(new(mem_ctx) ir_emit_vertex(stream));
6671
6672 return sig;
6673 }
6674
6675 ir_function_signature *
_EmitStreamVertex(builtin_available_predicate avail,const glsl_type * stream_type)6676 builtin_builder::_EmitStreamVertex(builtin_available_predicate avail,
6677 const glsl_type *stream_type)
6678 {
6679 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
6680 *
6681 * "Emit the current values of output variables to the current output
6682 * primitive on stream stream. The argument to stream must be a constant
6683 * integral expression."
6684 */
6685 ir_variable *stream =
6686 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
6687
6688 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
6689
6690 body.emit(new(mem_ctx) ir_emit_vertex(var_ref(stream)));
6691
6692 return sig;
6693 }
6694
6695 ir_function_signature *
_EndPrimitive()6696 builtin_builder::_EndPrimitive()
6697 {
6698 MAKE_SIG(glsl_type::void_type, gs_only, 0);
6699
6700 ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
6701 body.emit(new(mem_ctx) ir_end_primitive(stream));
6702
6703 return sig;
6704 }
6705
6706 ir_function_signature *
_EndStreamPrimitive(builtin_available_predicate avail,const glsl_type * stream_type)6707 builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
6708 const glsl_type *stream_type)
6709 {
6710 /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
6711 *
6712 * "Completes the current output primitive on stream stream and starts
6713 * a new one. The argument to stream must be a constant integral
6714 * expression."
6715 */
6716 ir_variable *stream =
6717 new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in);
6718
6719 MAKE_SIG(glsl_type::void_type, avail, 1, stream);
6720
6721 body.emit(new(mem_ctx) ir_end_primitive(var_ref(stream)));
6722
6723 return sig;
6724 }
6725
6726 ir_function_signature *
_barrier()6727 builtin_builder::_barrier()
6728 {
6729 MAKE_SIG(glsl_type::void_type, barrier_supported, 0);
6730
6731 body.emit(new(mem_ctx) ir_barrier());
6732 return sig;
6733 }
6734
6735 ir_function_signature *
_textureQueryLod(builtin_available_predicate avail,const glsl_type * sampler_type,const glsl_type * coord_type)6736 builtin_builder::_textureQueryLod(builtin_available_predicate avail,
6737 const glsl_type *sampler_type,
6738 const glsl_type *coord_type)
6739 {
6740 ir_variable *s = in_var(sampler_type, "sampler");
6741 ir_variable *coord = in_var(coord_type, "coord");
6742 /* The sampler and coordinate always exist; add optional parameters later. */
6743 MAKE_SIG(glsl_type::vec2_type, avail, 2, s, coord);
6744
6745 ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
6746 tex->coordinate = var_ref(coord);
6747 tex->set_sampler(var_ref(s), glsl_type::vec2_type);
6748
6749 body.emit(ret(tex));
6750
6751 return sig;
6752 }
6753
6754 ir_function_signature *
_textureQueryLevels(builtin_available_predicate avail,const glsl_type * sampler_type)6755 builtin_builder::_textureQueryLevels(builtin_available_predicate avail,
6756 const glsl_type *sampler_type)
6757 {
6758 ir_variable *s = in_var(sampler_type, "sampler");
6759 const glsl_type *return_type = glsl_type::int_type;
6760 MAKE_SIG(return_type, avail, 1, s);
6761
6762 ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
6763 tex->set_sampler(var_ref(s), return_type);
6764
6765 body.emit(ret(tex));
6766
6767 return sig;
6768 }
6769
6770 ir_function_signature *
_textureSamplesIdentical(builtin_available_predicate avail,const glsl_type * sampler_type,const glsl_type * coord_type)6771 builtin_builder::_textureSamplesIdentical(builtin_available_predicate avail,
6772 const glsl_type *sampler_type,
6773 const glsl_type *coord_type)
6774 {
6775 ir_variable *s = in_var(sampler_type, "sampler");
6776 ir_variable *P = in_var(coord_type, "P");
6777 const glsl_type *return_type = glsl_type::bool_type;
6778 MAKE_SIG(return_type, avail, 2, s, P);
6779
6780 ir_texture *tex = new(mem_ctx) ir_texture(ir_samples_identical);
6781 tex->coordinate = var_ref(P);
6782 tex->set_sampler(var_ref(s), return_type);
6783
6784 body.emit(ret(tex));
6785
6786 return sig;
6787 }
6788
UNOP(dFdx,ir_unop_dFdx,derivatives)6789 UNOP(dFdx, ir_unop_dFdx, derivatives)
6790 UNOP(dFdxCoarse, ir_unop_dFdx_coarse, derivative_control)
6791 UNOP(dFdxFine, ir_unop_dFdx_fine, derivative_control)
6792 UNOP(dFdy, ir_unop_dFdy, derivatives)
6793 UNOP(dFdyCoarse, ir_unop_dFdy_coarse, derivative_control)
6794 UNOP(dFdyFine, ir_unop_dFdy_fine, derivative_control)
6795
6796 ir_function_signature *
6797 builtin_builder::_fwidth(const glsl_type *type)
6798 {
6799 ir_variable *p = in_var(type, "p");
6800 MAKE_SIG(type, derivatives, 1, p);
6801
6802 body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
6803
6804 return sig;
6805 }
6806
6807 ir_function_signature *
_fwidthCoarse(const glsl_type * type)6808 builtin_builder::_fwidthCoarse(const glsl_type *type)
6809 {
6810 ir_variable *p = in_var(type, "p");
6811 MAKE_SIG(type, derivative_control, 1, p);
6812
6813 body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
6814 abs(expr(ir_unop_dFdy_coarse, p)))));
6815
6816 return sig;
6817 }
6818
6819 ir_function_signature *
_fwidthFine(const glsl_type * type)6820 builtin_builder::_fwidthFine(const glsl_type *type)
6821 {
6822 ir_variable *p = in_var(type, "p");
6823 MAKE_SIG(type, derivative_control, 1, p);
6824
6825 body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
6826 abs(expr(ir_unop_dFdy_fine, p)))));
6827
6828 return sig;
6829 }
6830
6831 ir_function_signature *
_noise1(const glsl_type * type)6832 builtin_builder::_noise1(const glsl_type *type)
6833 {
6834 /* From the GLSL 4.60 specification:
6835 *
6836 * "The noise functions noise1, noise2, noise3, and noise4 have been
6837 * deprecated starting with version 4.4 of GLSL. When not generating
6838 * SPIR-V they are defined to return the value 0.0 or a vector whose
6839 * components are all 0.0. When generating SPIR-V the noise functions
6840 * are not declared and may not be used."
6841 *
6842 * In earlier versions of the GLSL specification attempt to define some
6843 * sort of statistical noise function. However, the function's
6844 * characteristics have always been such that always returning 0 is
6845 * valid and Mesa has always returned 0 for noise on most drivers.
6846 */
6847 ir_variable *p = in_var(type, "p");
6848 MAKE_SIG(glsl_type::float_type, v110, 1, p);
6849 body.emit(ret(imm(glsl_type::float_type, ir_constant_data())));
6850 return sig;
6851 }
6852
6853 ir_function_signature *
_noise2(const glsl_type * type)6854 builtin_builder::_noise2(const glsl_type *type)
6855 {
6856 /* See builtin_builder::_noise1 */
6857 ir_variable *p = in_var(type, "p");
6858 MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
6859 body.emit(ret(imm(glsl_type::vec2_type, ir_constant_data())));
6860 return sig;
6861 }
6862
6863 ir_function_signature *
_noise3(const glsl_type * type)6864 builtin_builder::_noise3(const glsl_type *type)
6865 {
6866 /* See builtin_builder::_noise1 */
6867 ir_variable *p = in_var(type, "p");
6868 MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
6869 body.emit(ret(imm(glsl_type::vec3_type, ir_constant_data())));
6870 return sig;
6871 }
6872
6873 ir_function_signature *
_noise4(const glsl_type * type)6874 builtin_builder::_noise4(const glsl_type *type)
6875 {
6876 /* See builtin_builder::_noise1 */
6877 ir_variable *p = in_var(type, "p");
6878 MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
6879 body.emit(ret(imm(glsl_type::vec4_type, ir_constant_data())));
6880 return sig;
6881 }
6882
6883 ir_function_signature *
_bitfieldExtract(const glsl_type * type)6884 builtin_builder::_bitfieldExtract(const glsl_type *type)
6885 {
6886 bool is_uint = type->base_type == GLSL_TYPE_UINT;
6887 ir_variable *value = in_var(type, "value");
6888 ir_variable *offset = in_var(glsl_type::int_type, "offset");
6889 ir_variable *bits = in_var(glsl_type::int_type, "bits");
6890 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, value, offset,
6891 bits);
6892
6893 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
6894 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
6895
6896 body.emit(ret(expr(ir_triop_bitfield_extract, value,
6897 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
6898 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
6899
6900 return sig;
6901 }
6902
6903 ir_function_signature *
_bitfieldInsert(const glsl_type * type)6904 builtin_builder::_bitfieldInsert(const glsl_type *type)
6905 {
6906 bool is_uint = type->base_type == GLSL_TYPE_UINT;
6907 ir_variable *base = in_var(type, "base");
6908 ir_variable *insert = in_var(type, "insert");
6909 ir_variable *offset = in_var(glsl_type::int_type, "offset");
6910 ir_variable *bits = in_var(glsl_type::int_type, "bits");
6911 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 4, base, insert,
6912 offset, bits);
6913
6914 operand cast_offset = is_uint ? i2u(offset) : operand(offset);
6915 operand cast_bits = is_uint ? i2u(bits) : operand(bits);
6916
6917 body.emit(ret(bitfield_insert(base, insert,
6918 swizzle(cast_offset, SWIZZLE_XXXX, type->vector_elements),
6919 swizzle(cast_bits, SWIZZLE_XXXX, type->vector_elements))));
6920
6921 return sig;
6922 }
6923
UNOP(bitfieldReverse,ir_unop_bitfield_reverse,gpu_shader5_or_es31_or_integer_functions)6924 UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5_or_es31_or_integer_functions)
6925
6926 ir_function_signature *
6927 builtin_builder::_bitCount(const glsl_type *type)
6928 {
6929 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_bit_count,
6930 glsl_type::ivec(type->vector_elements), type);
6931 }
6932
6933 ir_function_signature *
_findLSB(const glsl_type * type)6934 builtin_builder::_findLSB(const glsl_type *type)
6935 {
6936 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_find_lsb,
6937 glsl_type::ivec(type->vector_elements), type);
6938 }
6939
6940 ir_function_signature *
_findMSB(const glsl_type * type)6941 builtin_builder::_findMSB(const glsl_type *type)
6942 {
6943 return unop(gpu_shader5_or_es31_or_integer_functions, ir_unop_find_msb,
6944 glsl_type::ivec(type->vector_elements), type);
6945 }
6946
6947 ir_function_signature *
_countLeadingZeros(builtin_available_predicate avail,const glsl_type * type)6948 builtin_builder::_countLeadingZeros(builtin_available_predicate avail,
6949 const glsl_type *type)
6950 {
6951 return unop(avail, ir_unop_clz,
6952 glsl_type::uvec(type->vector_elements), type);
6953 }
6954
6955 ir_function_signature *
_countTrailingZeros(builtin_available_predicate avail,const glsl_type * type)6956 builtin_builder::_countTrailingZeros(builtin_available_predicate avail,
6957 const glsl_type *type)
6958 {
6959 ir_variable *a = in_var(type, "a");
6960 MAKE_SIG(glsl_type::uvec(type->vector_elements), avail, 1, a);
6961
6962 body.emit(ret(ir_builder::min2(
6963 ir_builder::i2u(ir_builder::expr(ir_unop_find_lsb, a)),
6964 imm(32u))));
6965
6966 return sig;
6967 }
6968
6969 ir_function_signature *
_fma(builtin_available_predicate avail,const glsl_type * type)6970 builtin_builder::_fma(builtin_available_predicate avail, const glsl_type *type)
6971 {
6972 ir_variable *a = in_var(type, "a");
6973 ir_variable *b = in_var(type, "b");
6974 ir_variable *c = in_var(type, "c");
6975 MAKE_SIG(type, avail, 3, a, b, c);
6976
6977 body.emit(ret(ir_builder::fma(a, b, c)));
6978
6979 return sig;
6980 }
6981
6982 ir_function_signature *
_ldexp(const glsl_type * x_type,const glsl_type * exp_type)6983 builtin_builder::_ldexp(const glsl_type *x_type, const glsl_type *exp_type)
6984 {
6985 return binop(x_type->is_double() ? fp64 : gpu_shader5_or_es31_or_integer_functions,
6986 ir_binop_ldexp, x_type, x_type, exp_type);
6987 }
6988
6989 ir_function_signature *
_dfrexp(const glsl_type * x_type,const glsl_type * exp_type)6990 builtin_builder::_dfrexp(const glsl_type *x_type, const glsl_type *exp_type)
6991 {
6992 ir_variable *x = in_var(x_type, "x");
6993 ir_variable *exponent = out_var(exp_type, "exp");
6994 MAKE_SIG(x_type, fp64, 2, x, exponent);
6995
6996 body.emit(assign(exponent, expr(ir_unop_frexp_exp, x)));
6997
6998 body.emit(ret(expr(ir_unop_frexp_sig, x)));
6999 return sig;
7000 }
7001
7002 ir_function_signature *
_frexp(const glsl_type * x_type,const glsl_type * exp_type)7003 builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
7004 {
7005 ir_variable *x = in_var(x_type, "x");
7006 ir_variable *exponent = out_var(exp_type, "exp");
7007 MAKE_SIG(x_type, gpu_shader5_or_es31_or_integer_functions, 2, x, exponent);
7008
7009 const unsigned vec_elem = x_type->vector_elements;
7010 const glsl_type *bvec = glsl_type::get_instance(GLSL_TYPE_BOOL, vec_elem, 1);
7011 const glsl_type *uvec = glsl_type::get_instance(GLSL_TYPE_UINT, vec_elem, 1);
7012
7013 /* Single-precision floating-point values are stored as
7014 * 1 sign bit;
7015 * 8 exponent bits;
7016 * 23 mantissa bits.
7017 *
7018 * An exponent shift of 23 will shift the mantissa out, leaving only the
7019 * exponent and sign bit (which itself may be zero, if the absolute value
7020 * was taken before the bitcast and shift.
7021 */
7022 ir_constant *exponent_shift = imm(23);
7023 ir_constant *exponent_bias = imm(-126, vec_elem);
7024
7025 ir_constant *sign_mantissa_mask = imm(0x807fffffu, vec_elem);
7026
7027 /* Exponent of floating-point values in the range [0.5, 1.0). */
7028 ir_constant *exponent_value = imm(0x3f000000u, vec_elem);
7029
7030 ir_variable *is_not_zero = body.make_temp(bvec, "is_not_zero");
7031 body.emit(assign(is_not_zero, nequal(abs(x), imm(0.0f, vec_elem))));
7032
7033 /* Since abs(x) ensures that the sign bit is zero, we don't need to bitcast
7034 * to unsigned integers to ensure that 1 bits aren't shifted in.
7035 */
7036 body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
7037 body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
7038 imm(0, vec_elem)))));
7039
7040 ir_variable *bits = body.make_temp(uvec, "bits");
7041 body.emit(assign(bits, bitcast_f2u(x)));
7042 body.emit(assign(bits, bit_and(bits, sign_mantissa_mask)));
7043 body.emit(assign(bits, bit_or(bits, csel(is_not_zero, exponent_value,
7044 imm(0u, vec_elem)))));
7045 body.emit(ret(bitcast_u2f(bits)));
7046
7047 return sig;
7048 }
7049
7050 ir_function_signature *
_uaddCarry(const glsl_type * type)7051 builtin_builder::_uaddCarry(const glsl_type *type)
7052 {
7053 ir_variable *x = in_var(type, "x");
7054 ir_variable *y = in_var(type, "y");
7055 ir_variable *carry = out_var(type, "carry");
7056 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, x, y, carry);
7057
7058 body.emit(assign(carry, ir_builder::carry(x, y)));
7059 body.emit(ret(add(x, y)));
7060
7061 return sig;
7062 }
7063
7064 ir_function_signature *
_addSaturate(builtin_available_predicate avail,const glsl_type * type)7065 builtin_builder::_addSaturate(builtin_available_predicate avail,
7066 const glsl_type *type)
7067 {
7068 return binop(avail, ir_binop_add_sat, type, type, type);
7069 }
7070
7071 ir_function_signature *
_usubBorrow(const glsl_type * type)7072 builtin_builder::_usubBorrow(const glsl_type *type)
7073 {
7074 ir_variable *x = in_var(type, "x");
7075 ir_variable *y = in_var(type, "y");
7076 ir_variable *borrow = out_var(type, "borrow");
7077 MAKE_SIG(type, gpu_shader5_or_es31_or_integer_functions, 3, x, y, borrow);
7078
7079 body.emit(assign(borrow, ir_builder::borrow(x, y)));
7080 body.emit(ret(sub(x, y)));
7081
7082 return sig;
7083 }
7084
7085 ir_function_signature *
_subtractSaturate(builtin_available_predicate avail,const glsl_type * type)7086 builtin_builder::_subtractSaturate(builtin_available_predicate avail,
7087 const glsl_type *type)
7088 {
7089 return binop(avail, ir_binop_sub_sat, type, type, type);
7090 }
7091
7092 ir_function_signature *
_absoluteDifference(builtin_available_predicate avail,const glsl_type * type)7093 builtin_builder::_absoluteDifference(builtin_available_predicate avail,
7094 const glsl_type *type)
7095 {
7096 /* absoluteDifference returns an unsigned type that has the same number of
7097 * bits and number of vector elements as the type of the operands.
7098 */
7099 return binop(avail, ir_binop_abs_sub,
7100 glsl_type::get_instance(glsl_unsigned_base_type_of(type->base_type),
7101 type->vector_elements, 1),
7102 type, type);
7103 }
7104
7105 ir_function_signature *
_average(builtin_available_predicate avail,const glsl_type * type)7106 builtin_builder::_average(builtin_available_predicate avail,
7107 const glsl_type *type)
7108 {
7109 return binop(avail, ir_binop_avg, type, type, type);
7110 }
7111
7112 ir_function_signature *
_averageRounded(builtin_available_predicate avail,const glsl_type * type)7113 builtin_builder::_averageRounded(builtin_available_predicate avail,
7114 const glsl_type *type)
7115 {
7116 return binop(avail, ir_binop_avg_round, type, type, type);
7117 }
7118
7119 /**
7120 * For both imulExtended() and umulExtended() built-ins.
7121 */
7122 ir_function_signature *
_mulExtended(const glsl_type * type)7123 builtin_builder::_mulExtended(const glsl_type *type)
7124 {
7125 const glsl_type *mul_type, *unpack_type;
7126 ir_expression_operation unpack_op;
7127
7128 if (type->base_type == GLSL_TYPE_INT) {
7129 unpack_op = ir_unop_unpack_int_2x32;
7130 mul_type = glsl_type::get_instance(GLSL_TYPE_INT64, type->vector_elements, 1);
7131 unpack_type = glsl_type::ivec2_type;
7132 } else {
7133 unpack_op = ir_unop_unpack_uint_2x32;
7134 mul_type = glsl_type::get_instance(GLSL_TYPE_UINT64, type->vector_elements, 1);
7135 unpack_type = glsl_type::uvec2_type;
7136 }
7137
7138 ir_variable *x = in_var(type, "x");
7139 ir_variable *y = in_var(type, "y");
7140 ir_variable *msb = out_var(type, "msb");
7141 ir_variable *lsb = out_var(type, "lsb");
7142 MAKE_SIG(glsl_type::void_type, gpu_shader5_or_es31_or_integer_functions, 4, x, y, msb, lsb);
7143
7144 ir_variable *unpack_val = body.make_temp(unpack_type, "_unpack_val");
7145
7146 ir_expression *mul_res = new(mem_ctx) ir_expression(ir_binop_mul, mul_type,
7147 new(mem_ctx)ir_dereference_variable(x),
7148 new(mem_ctx)ir_dereference_variable(y));
7149
7150 if (type->vector_elements == 1) {
7151 body.emit(assign(unpack_val, expr(unpack_op, mul_res)));
7152 body.emit(assign(msb, swizzle_y(unpack_val)));
7153 body.emit(assign(lsb, swizzle_x(unpack_val)));
7154 } else {
7155 for (int i = 0; i < type->vector_elements; i++) {
7156 body.emit(assign(unpack_val, expr(unpack_op, swizzle(mul_res, i, 1))));
7157 body.emit(assign(array_ref(msb, i), swizzle_y(unpack_val)));
7158 body.emit(assign(array_ref(lsb, i), swizzle_x(unpack_val)));
7159 }
7160 }
7161
7162 return sig;
7163 }
7164
7165 ir_function_signature *
_multiply32x16(builtin_available_predicate avail,const glsl_type * type)7166 builtin_builder::_multiply32x16(builtin_available_predicate avail,
7167 const glsl_type *type)
7168 {
7169 return binop(avail, ir_binop_mul_32x16, type, type, type);
7170 }
7171
7172 ir_function_signature *
_interpolateAtCentroid(const glsl_type * type)7173 builtin_builder::_interpolateAtCentroid(const glsl_type *type)
7174 {
7175 ir_variable *interpolant = in_var(type, "interpolant");
7176 interpolant->data.must_be_shader_input = 1;
7177 MAKE_SIG(type, fs_interpolate_at, 1, interpolant);
7178
7179 body.emit(ret(interpolate_at_centroid(interpolant)));
7180
7181 return sig;
7182 }
7183
7184 ir_function_signature *
_interpolateAtOffset(const glsl_type * type)7185 builtin_builder::_interpolateAtOffset(const glsl_type *type)
7186 {
7187 ir_variable *interpolant = in_var(type, "interpolant");
7188 interpolant->data.must_be_shader_input = 1;
7189 ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
7190 MAKE_SIG(type, fs_interpolate_at, 2, interpolant, offset);
7191
7192 body.emit(ret(interpolate_at_offset(interpolant, offset)));
7193
7194 return sig;
7195 }
7196
7197 ir_function_signature *
_interpolateAtSample(const glsl_type * type)7198 builtin_builder::_interpolateAtSample(const glsl_type *type)
7199 {
7200 ir_variable *interpolant = in_var(type, "interpolant");
7201 interpolant->data.must_be_shader_input = 1;
7202 ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
7203 MAKE_SIG(type, fs_interpolate_at, 2, interpolant, sample_num);
7204
7205 body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
7206
7207 return sig;
7208 }
7209
7210 ir_function_signature *
_atomic_counter_intrinsic(builtin_available_predicate avail,enum ir_intrinsic_id id)7211 builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail,
7212 enum ir_intrinsic_id id)
7213 {
7214 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
7215 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 1, counter);
7216 return sig;
7217 }
7218
7219 ir_function_signature *
_atomic_counter_intrinsic1(builtin_available_predicate avail,enum ir_intrinsic_id id)7220 builtin_builder::_atomic_counter_intrinsic1(builtin_available_predicate avail,
7221 enum ir_intrinsic_id id)
7222 {
7223 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
7224 ir_variable *data = in_var(glsl_type::uint_type, "data");
7225 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 2, counter, data);
7226 return sig;
7227 }
7228
7229 ir_function_signature *
_atomic_counter_intrinsic2(builtin_available_predicate avail,enum ir_intrinsic_id id)7230 builtin_builder::_atomic_counter_intrinsic2(builtin_available_predicate avail,
7231 enum ir_intrinsic_id id)
7232 {
7233 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
7234 ir_variable *compare = in_var(glsl_type::uint_type, "compare");
7235 ir_variable *data = in_var(glsl_type::uint_type, "data");
7236 MAKE_INTRINSIC(glsl_type::uint_type, id, avail, 3, counter, compare, data);
7237 return sig;
7238 }
7239
7240 ir_function_signature *
_atomic_intrinsic2(builtin_available_predicate avail,const glsl_type * type,enum ir_intrinsic_id id)7241 builtin_builder::_atomic_intrinsic2(builtin_available_predicate avail,
7242 const glsl_type *type,
7243 enum ir_intrinsic_id id)
7244 {
7245 ir_variable *atomic = in_var(type, "atomic");
7246 ir_variable *data = in_var(type, "data");
7247 MAKE_INTRINSIC(type, id, avail, 2, atomic, data);
7248 return sig;
7249 }
7250
7251 ir_function_signature *
_atomic_intrinsic3(builtin_available_predicate avail,const glsl_type * type,enum ir_intrinsic_id id)7252 builtin_builder::_atomic_intrinsic3(builtin_available_predicate avail,
7253 const glsl_type *type,
7254 enum ir_intrinsic_id id)
7255 {
7256 ir_variable *atomic = in_var(type, "atomic");
7257 ir_variable *data1 = in_var(type, "data1");
7258 ir_variable *data2 = in_var(type, "data2");
7259 MAKE_INTRINSIC(type, id, avail, 3, atomic, data1, data2);
7260 return sig;
7261 }
7262
7263 ir_function_signature *
_atomic_counter_op(const char * intrinsic,builtin_available_predicate avail)7264 builtin_builder::_atomic_counter_op(const char *intrinsic,
7265 builtin_available_predicate avail)
7266 {
7267 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
7268 MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
7269
7270 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
7271 body.emit(call(shader->symbols->get_function(intrinsic), retval,
7272 sig->parameters));
7273 body.emit(ret(retval));
7274 return sig;
7275 }
7276
7277 ir_function_signature *
_atomic_counter_op1(const char * intrinsic,builtin_available_predicate avail)7278 builtin_builder::_atomic_counter_op1(const char *intrinsic,
7279 builtin_available_predicate avail)
7280 {
7281 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
7282 ir_variable *data = in_var(glsl_type::uint_type, "data");
7283 MAKE_SIG(glsl_type::uint_type, avail, 2, counter, data);
7284
7285 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
7286
7287 /* Instead of generating an __intrinsic_atomic_sub, generate an
7288 * __intrinsic_atomic_add with the data parameter negated.
7289 */
7290 if (strcmp("__intrinsic_atomic_sub", intrinsic) == 0) {
7291 ir_variable *const neg_data =
7292 body.make_temp(glsl_type::uint_type, "neg_data");
7293
7294 body.emit(assign(neg_data, neg(data)));
7295
7296 exec_list parameters;
7297
7298 parameters.push_tail(new(mem_ctx) ir_dereference_variable(counter));
7299 parameters.push_tail(new(mem_ctx) ir_dereference_variable(neg_data));
7300
7301 ir_function *const func =
7302 shader->symbols->get_function("__intrinsic_atomic_add");
7303 ir_instruction *const c = call(func, retval, parameters);
7304
7305 assert(c != NULL);
7306 assert(parameters.is_empty());
7307
7308 body.emit(c);
7309 } else {
7310 body.emit(call(shader->symbols->get_function(intrinsic), retval,
7311 sig->parameters));
7312 }
7313
7314 body.emit(ret(retval));
7315 return sig;
7316 }
7317
7318 ir_function_signature *
_atomic_counter_op2(const char * intrinsic,builtin_available_predicate avail)7319 builtin_builder::_atomic_counter_op2(const char *intrinsic,
7320 builtin_available_predicate avail)
7321 {
7322 ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
7323 ir_variable *compare = in_var(glsl_type::uint_type, "compare");
7324 ir_variable *data = in_var(glsl_type::uint_type, "data");
7325 MAKE_SIG(glsl_type::uint_type, avail, 3, counter, compare, data);
7326
7327 ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
7328 body.emit(call(shader->symbols->get_function(intrinsic), retval,
7329 sig->parameters));
7330 body.emit(ret(retval));
7331 return sig;
7332 }
7333
7334 ir_function_signature *
_atomic_op2(const char * intrinsic,builtin_available_predicate avail,const glsl_type * type)7335 builtin_builder::_atomic_op2(const char *intrinsic,
7336 builtin_available_predicate avail,
7337 const glsl_type *type)
7338 {
7339 ir_variable *atomic = in_var(type, "atomic_var");
7340 ir_variable *data = in_var(type, "atomic_data");
7341 MAKE_SIG(type, avail, 2, atomic, data);
7342
7343 atomic->data.implicit_conversion_prohibited = true;
7344
7345 ir_variable *retval = body.make_temp(type, "atomic_retval");
7346 body.emit(call(shader->symbols->get_function(intrinsic), retval,
7347 sig->parameters));
7348 body.emit(ret(retval));
7349 return sig;
7350 }
7351
7352 ir_function_signature *
_atomic_op3(const char * intrinsic,builtin_available_predicate avail,const glsl_type * type)7353 builtin_builder::_atomic_op3(const char *intrinsic,
7354 builtin_available_predicate avail,
7355 const glsl_type *type)
7356 {
7357 ir_variable *atomic = in_var(type, "atomic_var");
7358 ir_variable *data1 = in_var(type, "atomic_data1");
7359 ir_variable *data2 = in_var(type, "atomic_data2");
7360 MAKE_SIG(type, avail, 3, atomic, data1, data2);
7361
7362 atomic->data.implicit_conversion_prohibited = true;
7363
7364 ir_variable *retval = body.make_temp(type, "atomic_retval");
7365 body.emit(call(shader->symbols->get_function(intrinsic), retval,
7366 sig->parameters));
7367 body.emit(ret(retval));
7368 return sig;
7369 }
7370
7371 ir_function_signature *
_min3(const glsl_type * type)7372 builtin_builder::_min3(const glsl_type *type)
7373 {
7374 ir_variable *x = in_var(type, "x");
7375 ir_variable *y = in_var(type, "y");
7376 ir_variable *z = in_var(type, "z");
7377 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
7378
7379 ir_expression *min3 = min2(x, min2(y,z));
7380 body.emit(ret(min3));
7381
7382 return sig;
7383 }
7384
7385 ir_function_signature *
_max3(const glsl_type * type)7386 builtin_builder::_max3(const glsl_type *type)
7387 {
7388 ir_variable *x = in_var(type, "x");
7389 ir_variable *y = in_var(type, "y");
7390 ir_variable *z = in_var(type, "z");
7391 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
7392
7393 ir_expression *max3 = max2(x, max2(y,z));
7394 body.emit(ret(max3));
7395
7396 return sig;
7397 }
7398
7399 ir_function_signature *
_mid3(const glsl_type * type)7400 builtin_builder::_mid3(const glsl_type *type)
7401 {
7402 ir_variable *x = in_var(type, "x");
7403 ir_variable *y = in_var(type, "y");
7404 ir_variable *z = in_var(type, "z");
7405 MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
7406
7407 ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
7408 body.emit(ret(mid3));
7409
7410 return sig;
7411 }
7412
7413 static builtin_available_predicate
get_image_available_predicate(const glsl_type * type,unsigned flags)7414 get_image_available_predicate(const glsl_type *type, unsigned flags)
7415 {
7416 if ((flags & IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE) &&
7417 type->sampled_type == GLSL_TYPE_FLOAT)
7418 return shader_image_atomic_exchange_float;
7419
7420 if ((flags & IMAGE_FUNCTION_AVAIL_ATOMIC_ADD) &&
7421 type->sampled_type == GLSL_TYPE_FLOAT)
7422 return shader_image_atomic_add_float;
7423
7424 else if (flags & (IMAGE_FUNCTION_AVAIL_ATOMIC_EXCHANGE |
7425 IMAGE_FUNCTION_AVAIL_ATOMIC_ADD |
7426 IMAGE_FUNCTION_AVAIL_ATOMIC))
7427 return shader_image_atomic;
7428
7429 else if (flags & IMAGE_FUNCTION_EXT_ONLY)
7430 return shader_image_load_store_ext;
7431
7432 else
7433 return shader_image_load_store;
7434 }
7435
7436 ir_function_signature *
_image_prototype(const glsl_type * image_type,unsigned num_arguments,unsigned flags)7437 builtin_builder::_image_prototype(const glsl_type *image_type,
7438 unsigned num_arguments,
7439 unsigned flags)
7440 {
7441 const glsl_type *data_type = glsl_type::get_instance(
7442 image_type->sampled_type,
7443 (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
7444 1);
7445 const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
7446 glsl_type::void_type : data_type);
7447
7448 /* Addressing arguments that are always present. */
7449 ir_variable *image = in_var(image_type, "image");
7450 ir_variable *coord = in_var(
7451 glsl_type::ivec(image_type->coordinate_components()), "coord");
7452
7453 ir_function_signature *sig = new_sig(
7454 ret_type, get_image_available_predicate(image_type, flags),
7455 2, image, coord);
7456
7457 /* Sample index for multisample images. */
7458 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
7459 sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
7460
7461 /* Data arguments. */
7462 for (unsigned i = 0; i < num_arguments; ++i) {
7463 char *arg_name = ralloc_asprintf(NULL, "arg%d", i);
7464 sig->parameters.push_tail(in_var(data_type, arg_name));
7465 ralloc_free(arg_name);
7466 }
7467
7468 /* Set the maximal set of qualifiers allowed for this image
7469 * built-in. Function calls with arguments having fewer
7470 * qualifiers than present in the prototype are allowed by the
7471 * spec, but not with more, i.e. this will make the compiler
7472 * accept everything that needs to be accepted, and reject cases
7473 * like loads from write-only or stores to read-only images.
7474 */
7475 image->data.memory_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
7476 image->data.memory_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
7477 image->data.memory_coherent = true;
7478 image->data.memory_volatile = true;
7479 image->data.memory_restrict = true;
7480
7481 return sig;
7482 }
7483
7484 ir_function_signature *
_image_size_prototype(const glsl_type * image_type,unsigned,unsigned)7485 builtin_builder::_image_size_prototype(const glsl_type *image_type,
7486 unsigned /* num_arguments */,
7487 unsigned /* flags */)
7488 {
7489 const glsl_type *ret_type;
7490 unsigned num_components = image_type->coordinate_components();
7491
7492 /* From the ARB_shader_image_size extension:
7493 * "Cube images return the dimensions of one face."
7494 */
7495 if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE &&
7496 !image_type->sampler_array) {
7497 num_components = 2;
7498 }
7499
7500 /* FIXME: Add the highp precision qualifier for GLES 3.10 when it is
7501 * supported by mesa.
7502 */
7503 ret_type = glsl_type::get_instance(GLSL_TYPE_INT, num_components, 1);
7504
7505 ir_variable *image = in_var(image_type, "image");
7506 ir_function_signature *sig = new_sig(ret_type, shader_image_size, 1, image);
7507
7508 /* Set the maximal set of qualifiers allowed for this image
7509 * built-in. Function calls with arguments having fewer
7510 * qualifiers than present in the prototype are allowed by the
7511 * spec, but not with more, i.e. this will make the compiler
7512 * accept everything that needs to be accepted, and reject cases
7513 * like loads from write-only or stores to read-only images.
7514 */
7515 image->data.memory_read_only = true;
7516 image->data.memory_write_only = true;
7517 image->data.memory_coherent = true;
7518 image->data.memory_volatile = true;
7519 image->data.memory_restrict = true;
7520
7521 return sig;
7522 }
7523
7524 ir_function_signature *
_image_samples_prototype(const glsl_type * image_type,unsigned,unsigned)7525 builtin_builder::_image_samples_prototype(const glsl_type *image_type,
7526 unsigned /* num_arguments */,
7527 unsigned /* flags */)
7528 {
7529 ir_variable *image = in_var(image_type, "image");
7530 ir_function_signature *sig =
7531 new_sig(glsl_type::int_type, shader_samples, 1, image);
7532
7533 /* Set the maximal set of qualifiers allowed for this image
7534 * built-in. Function calls with arguments having fewer
7535 * qualifiers than present in the prototype are allowed by the
7536 * spec, but not with more, i.e. this will make the compiler
7537 * accept everything that needs to be accepted, and reject cases
7538 * like loads from write-only or stores to read-only images.
7539 */
7540 image->data.memory_read_only = true;
7541 image->data.memory_write_only = true;
7542 image->data.memory_coherent = true;
7543 image->data.memory_volatile = true;
7544 image->data.memory_restrict = true;
7545
7546 return sig;
7547 }
7548
7549 ir_function_signature *
_image(image_prototype_ctr prototype,const glsl_type * image_type,const char * intrinsic_name,unsigned num_arguments,unsigned flags,enum ir_intrinsic_id id)7550 builtin_builder::_image(image_prototype_ctr prototype,
7551 const glsl_type *image_type,
7552 const char *intrinsic_name,
7553 unsigned num_arguments,
7554 unsigned flags,
7555 enum ir_intrinsic_id id)
7556 {
7557 ir_function_signature *sig = (this->*prototype)(image_type,
7558 num_arguments, flags);
7559
7560 if (flags & IMAGE_FUNCTION_EMIT_STUB) {
7561 ir_factory body(&sig->body, mem_ctx);
7562 ir_function *f = shader->symbols->get_function(intrinsic_name);
7563
7564 if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
7565 body.emit(call(f, NULL, sig->parameters));
7566 } else {
7567 ir_variable *ret_val =
7568 body.make_temp(sig->return_type, "_ret_val");
7569 body.emit(call(f, ret_val, sig->parameters));
7570 body.emit(ret(ret_val));
7571 }
7572
7573 sig->is_defined = true;
7574
7575 } else {
7576 sig->intrinsic_id = id;
7577 }
7578
7579 return sig;
7580 }
7581
7582 ir_function_signature *
_memory_barrier_intrinsic(builtin_available_predicate avail,enum ir_intrinsic_id id)7583 builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail,
7584 enum ir_intrinsic_id id)
7585 {
7586 MAKE_INTRINSIC(glsl_type::void_type, id, avail, 0);
7587 return sig;
7588 }
7589
7590 ir_function_signature *
_memory_barrier(const char * intrinsic_name,builtin_available_predicate avail)7591 builtin_builder::_memory_barrier(const char *intrinsic_name,
7592 builtin_available_predicate avail)
7593 {
7594 MAKE_SIG(glsl_type::void_type, avail, 0);
7595 body.emit(call(shader->symbols->get_function(intrinsic_name),
7596 NULL, sig->parameters));
7597 return sig;
7598 }
7599
7600 ir_function_signature *
_ballot_intrinsic()7601 builtin_builder::_ballot_intrinsic()
7602 {
7603 ir_variable *value = in_var(glsl_type::bool_type, "value");
7604 MAKE_INTRINSIC(glsl_type::uint64_t_type, ir_intrinsic_ballot, shader_ballot,
7605 1, value);
7606 return sig;
7607 }
7608
7609 ir_function_signature *
_ballot()7610 builtin_builder::_ballot()
7611 {
7612 ir_variable *value = in_var(glsl_type::bool_type, "value");
7613
7614 MAKE_SIG(glsl_type::uint64_t_type, shader_ballot, 1, value);
7615 ir_variable *retval = body.make_temp(glsl_type::uint64_t_type, "retval");
7616
7617 body.emit(call(shader->symbols->get_function("__intrinsic_ballot"),
7618 retval, sig->parameters));
7619 body.emit(ret(retval));
7620 return sig;
7621 }
7622
7623 ir_function_signature *
_read_first_invocation_intrinsic(const glsl_type * type)7624 builtin_builder::_read_first_invocation_intrinsic(const glsl_type *type)
7625 {
7626 ir_variable *value = in_var(type, "value");
7627 MAKE_INTRINSIC(type, ir_intrinsic_read_first_invocation, shader_ballot,
7628 1, value);
7629 return sig;
7630 }
7631
7632 ir_function_signature *
_read_first_invocation(const glsl_type * type)7633 builtin_builder::_read_first_invocation(const glsl_type *type)
7634 {
7635 ir_variable *value = in_var(type, "value");
7636
7637 MAKE_SIG(type, shader_ballot, 1, value);
7638 ir_variable *retval = body.make_temp(type, "retval");
7639
7640 body.emit(call(shader->symbols->get_function("__intrinsic_read_first_invocation"),
7641 retval, sig->parameters));
7642 body.emit(ret(retval));
7643 return sig;
7644 }
7645
7646 ir_function_signature *
_read_invocation_intrinsic(const glsl_type * type)7647 builtin_builder::_read_invocation_intrinsic(const glsl_type *type)
7648 {
7649 ir_variable *value = in_var(type, "value");
7650 ir_variable *invocation = in_var(glsl_type::uint_type, "invocation");
7651 MAKE_INTRINSIC(type, ir_intrinsic_read_invocation, shader_ballot,
7652 2, value, invocation);
7653 return sig;
7654 }
7655
7656 ir_function_signature *
_read_invocation(const glsl_type * type)7657 builtin_builder::_read_invocation(const glsl_type *type)
7658 {
7659 ir_variable *value = in_var(type, "value");
7660 ir_variable *invocation = in_var(glsl_type::uint_type, "invocation");
7661
7662 MAKE_SIG(type, shader_ballot, 2, value, invocation);
7663 ir_variable *retval = body.make_temp(type, "retval");
7664
7665 body.emit(call(shader->symbols->get_function("__intrinsic_read_invocation"),
7666 retval, sig->parameters));
7667 body.emit(ret(retval));
7668 return sig;
7669 }
7670
7671 ir_function_signature *
_invocation_interlock_intrinsic(builtin_available_predicate avail,enum ir_intrinsic_id id)7672 builtin_builder::_invocation_interlock_intrinsic(builtin_available_predicate avail,
7673 enum ir_intrinsic_id id)
7674 {
7675 MAKE_INTRINSIC(glsl_type::void_type, id, avail, 0);
7676 return sig;
7677 }
7678
7679 ir_function_signature *
_invocation_interlock(const char * intrinsic_name,builtin_available_predicate avail)7680 builtin_builder::_invocation_interlock(const char *intrinsic_name,
7681 builtin_available_predicate avail)
7682 {
7683 MAKE_SIG(glsl_type::void_type, avail, 0);
7684 body.emit(call(shader->symbols->get_function(intrinsic_name),
7685 NULL, sig->parameters));
7686 return sig;
7687 }
7688
7689 ir_function_signature *
_shader_clock_intrinsic(builtin_available_predicate avail,const glsl_type * type)7690 builtin_builder::_shader_clock_intrinsic(builtin_available_predicate avail,
7691 const glsl_type *type)
7692 {
7693 MAKE_INTRINSIC(type, ir_intrinsic_shader_clock, avail, 0);
7694 return sig;
7695 }
7696
7697 ir_function_signature *
_shader_clock(builtin_available_predicate avail,const glsl_type * type)7698 builtin_builder::_shader_clock(builtin_available_predicate avail,
7699 const glsl_type *type)
7700 {
7701 MAKE_SIG(type, avail, 0);
7702
7703 ir_variable *retval = body.make_temp(glsl_type::uvec2_type, "clock_retval");
7704
7705 body.emit(call(shader->symbols->get_function("__intrinsic_shader_clock"),
7706 retval, sig->parameters));
7707
7708 if (type == glsl_type::uint64_t_type) {
7709 body.emit(ret(expr(ir_unop_pack_uint_2x32, retval)));
7710 } else {
7711 body.emit(ret(retval));
7712 }
7713
7714 return sig;
7715 }
7716
7717 ir_function_signature *
_vote_intrinsic(builtin_available_predicate avail,enum ir_intrinsic_id id)7718 builtin_builder::_vote_intrinsic(builtin_available_predicate avail,
7719 enum ir_intrinsic_id id)
7720 {
7721 ir_variable *value = in_var(glsl_type::bool_type, "value");
7722 MAKE_INTRINSIC(glsl_type::bool_type, id, avail, 1, value);
7723 return sig;
7724 }
7725
7726 ir_function_signature *
_vote(const char * intrinsic_name,builtin_available_predicate avail)7727 builtin_builder::_vote(const char *intrinsic_name,
7728 builtin_available_predicate avail)
7729 {
7730 ir_variable *value = in_var(glsl_type::bool_type, "value");
7731
7732 MAKE_SIG(glsl_type::bool_type, avail, 1, value);
7733
7734 ir_variable *retval = body.make_temp(glsl_type::bool_type, "retval");
7735
7736 body.emit(call(shader->symbols->get_function(intrinsic_name),
7737 retval, sig->parameters));
7738 body.emit(ret(retval));
7739 return sig;
7740 }
7741
7742 ir_function_signature *
_helper_invocation_intrinsic()7743 builtin_builder::_helper_invocation_intrinsic()
7744 {
7745 MAKE_INTRINSIC(glsl_type::bool_type, ir_intrinsic_helper_invocation,
7746 demote_to_helper_invocation, 0);
7747 return sig;
7748 }
7749
7750 ir_function_signature *
_helper_invocation()7751 builtin_builder::_helper_invocation()
7752 {
7753 MAKE_SIG(glsl_type::bool_type, demote_to_helper_invocation, 0);
7754
7755 ir_variable *retval = body.make_temp(glsl_type::bool_type, "retval");
7756
7757 body.emit(call(shader->symbols->get_function("__intrinsic_helper_invocation"),
7758 retval, sig->parameters));
7759 body.emit(ret(retval));
7760
7761 return sig;
7762 }
7763
7764 /** @} */
7765
7766 /******************************************************************************/
7767
7768 /* The singleton instance of builtin_builder. */
7769 static builtin_builder builtins;
7770 static uint32_t builtin_users = 0;
7771
7772 /**
7773 * External API (exposing the built-in module to the rest of the compiler):
7774 * @{
7775 */
7776 extern "C" void
_mesa_glsl_builtin_functions_init_or_ref()7777 _mesa_glsl_builtin_functions_init_or_ref()
7778 {
7779 mtx_lock(&builtins_lock);
7780 if (builtin_users++ == 0)
7781 builtins.initialize();
7782 mtx_unlock(&builtins_lock);
7783 }
7784
7785 extern "C" void
_mesa_glsl_builtin_functions_decref()7786 _mesa_glsl_builtin_functions_decref()
7787 {
7788 mtx_lock(&builtins_lock);
7789 assert(builtin_users != 0);
7790 if (--builtin_users == 0)
7791 builtins.release();
7792 mtx_unlock(&builtins_lock);
7793 }
7794
7795 ir_function_signature *
_mesa_glsl_find_builtin_function(_mesa_glsl_parse_state * state,const char * name,exec_list * actual_parameters)7796 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
7797 const char *name, exec_list *actual_parameters)
7798 {
7799 ir_function_signature *s;
7800 mtx_lock(&builtins_lock);
7801 s = builtins.find(state, name, actual_parameters);
7802 mtx_unlock(&builtins_lock);
7803
7804 return s;
7805 }
7806
7807 bool
_mesa_glsl_has_builtin_function(_mesa_glsl_parse_state * state,const char * name)7808 _mesa_glsl_has_builtin_function(_mesa_glsl_parse_state *state, const char *name)
7809 {
7810 ir_function *f;
7811 bool ret = false;
7812 mtx_lock(&builtins_lock);
7813 f = builtins.shader->symbols->get_function(name);
7814 if (f != NULL) {
7815 foreach_in_list(ir_function_signature, sig, &f->signatures) {
7816 if (sig->is_builtin_available(state)) {
7817 ret = true;
7818 break;
7819 }
7820 }
7821 }
7822 mtx_unlock(&builtins_lock);
7823
7824 return ret;
7825 }
7826
7827 gl_shader *
_mesa_glsl_get_builtin_function_shader()7828 _mesa_glsl_get_builtin_function_shader()
7829 {
7830 return builtins.shader;
7831 }
7832
7833
7834 /**
7835 * Get the function signature for main from a shader
7836 */
7837 ir_function_signature *
_mesa_get_main_function_signature(glsl_symbol_table * symbols)7838 _mesa_get_main_function_signature(glsl_symbol_table *symbols)
7839 {
7840 ir_function *const f = symbols->get_function("main");
7841 if (f != NULL) {
7842 exec_list void_parameters;
7843
7844 /* Look for the 'void main()' signature and ensure that it's defined.
7845 * This keeps the linker from accidentally pick a shader that just
7846 * contains a prototype for main.
7847 *
7848 * We don't have to check for multiple definitions of main (in multiple
7849 * shaders) because that would have already been caught above.
7850 */
7851 ir_function_signature *sig =
7852 f->matching_signature(NULL, &void_parameters, false);
7853 if ((sig != NULL) && sig->is_defined) {
7854 return sig;
7855 }
7856 }
7857
7858 return NULL;
7859 }
7860
7861 /** @} */
7862