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