Hash :
119ffd44
        
        Author :
  
        
        Date :
2025-08-13T16:07:52
        
      
Fix -Wreturn-type in ShadowSamplerFunctionsTest::FunctionName Add UNREACHABLE() and a fallback return to ensure the non-void function always returns when switch does not cover all enum values. BUG: angleproject:438226513 Change-Id: I3904dd59b323b90930d9251b060ab7067ff412c7 Signed-off-by: Sungyong Choi <sywow.choi@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6845486 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Yuxin Hu <yuxinhu@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// These tests verify shadow sampler functions and their options.
#include "common/gl_enum_utils.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
enum class FunctionType
{
    Texture,
    TextureBias,
    TextureOffset,
    TextureOffsetBias,
    TextureLod,
    TextureLodOffset,
    TextureGrad,
    TextureGradOffset,
    TextureProj,
    TextureProjBias,
    TextureProjOffset,
    TextureProjOffsetBias,
    TextureProjLod,
    TextureProjLodOffset,
    TextureProjGrad,
    TextureProjGradOffset,
};
const char *FunctionName(FunctionType function)
{
    switch (function)
    {
        case FunctionType::Texture:
        case FunctionType::TextureBias:
            return "texture";
        case FunctionType::TextureOffset:
        case FunctionType::TextureOffsetBias:
            return "textureOffset";
        case FunctionType::TextureLod:
            return "textureLod";
        case FunctionType::TextureLodOffset:
            return "textureLodOffset";
        case FunctionType::TextureGrad:
            return "textureGrad";
        case FunctionType::TextureGradOffset:
            return "textureGradOffset";
        case FunctionType::TextureProj:
        case FunctionType::TextureProjBias:
            return "textureProj";
        case FunctionType::TextureProjOffset:
        case FunctionType::TextureProjOffsetBias:
            return "textureProjOffset";
        case FunctionType::TextureProjLod:
            return "textureProjLod";
        case FunctionType::TextureProjLodOffset:
            return "textureProjLodOffset";
        case FunctionType::TextureProjGrad:
            return "textureProjGrad";
        case FunctionType::TextureProjGradOffset:
            return "textureProjGradOffset";
        default:
            UNREACHABLE();
            return "";
    }
}
constexpr bool IsProj(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureProj:
        case FunctionType::TextureProjBias:
        case FunctionType::TextureProjOffset:
        case FunctionType::TextureProjOffsetBias:
        case FunctionType::TextureProjLod:
        case FunctionType::TextureProjLodOffset:
        case FunctionType::TextureProjGrad:
        case FunctionType::TextureProjGradOffset:
            return true;
        default:
            return false;
    }
}
constexpr bool HasBias(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureBias:
        case FunctionType::TextureOffsetBias:
        case FunctionType::TextureProjBias:
        case FunctionType::TextureProjOffsetBias:
            return true;
        default:
            return false;
    }
}
constexpr bool HasLOD(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureLod:
        case FunctionType::TextureLodOffset:
        case FunctionType::TextureProjLod:
        case FunctionType::TextureProjLodOffset:
            return true;
        default:
            return false;
    }
}
constexpr bool HasGrad(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureGrad:
        case FunctionType::TextureGradOffset:
        case FunctionType::TextureProjGrad:
        case FunctionType::TextureProjGradOffset:
            return true;
        default:
            return false;
    }
}
constexpr bool HasOffset(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureOffset:
        case FunctionType::TextureOffsetBias:
        case FunctionType::TextureLodOffset:
        case FunctionType::TextureGradOffset:
        case FunctionType::TextureProjOffset:
        case FunctionType::TextureProjOffsetBias:
        case FunctionType::TextureProjLodOffset:
        case FunctionType::TextureProjGradOffset:
            return true;
        default:
            return false;
    }
}
constexpr bool RequiresExtensionFor2DArray(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureBias:
        case FunctionType::TextureOffset:
        case FunctionType::TextureOffsetBias:
        case FunctionType::TextureLod:
        case FunctionType::TextureLodOffset:
            return true;
        default:
            return false;
    }
}
constexpr bool RequiresExtensionForCube(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureLod:
            return true;
        default:
            return false;
    }
}
constexpr bool RequiresExtensionForCubeArray(FunctionType function)
{
    switch (function)
    {
        case FunctionType::TextureBias:
        case FunctionType::TextureLod:
            return true;
        default:
            return false;
    }
}
bool Compare(float reference, float sampled, GLenum op)
{
    switch (op)
    {
        case GL_NEVER:
            return false;
        case GL_LESS:
            return reference < sampled;
        case GL_EQUAL:
            return reference == sampled;
        case GL_LEQUAL:
            return reference <= sampled;
        case GL_GREATER:
            return reference > sampled;
        case GL_NOTEQUAL:
            return reference != sampled;
        case GL_GEQUAL:
            return reference >= sampled;
        case GL_ALWAYS:
            return true;
        default:
            UNREACHABLE();
            return false;
    }
}
// Variations corresponding to enums above.
using ShadowSamplerFunctionVariationsTestParams =
    std::tuple<angle::PlatformParameters, FunctionType, bool>;
std::ostream &operator<<(std::ostream &out, FunctionType function)
{
    switch (function)
    {
        case FunctionType::Texture:
            out << "Texture";
            break;
        case FunctionType::TextureBias:
            out << "TextureBias";
            break;
        case FunctionType::TextureOffset:
            out << "TextureOffset";
            break;
        case FunctionType::TextureOffsetBias:
            out << "TextureOffsetBias";
            break;
        case FunctionType::TextureLod:
            out << "TextureLod";
            break;
        case FunctionType::TextureLodOffset:
            out << "TextureLodOffset";
            break;
        case FunctionType::TextureGrad:
            out << "TextureGrad";
            break;
        case FunctionType::TextureGradOffset:
            out << "TextureGradOffset";
            break;
        case FunctionType::TextureProj:
            out << "TextureProj";
            break;
        case FunctionType::TextureProjBias:
            out << "TextureProjBias";
            break;
        case FunctionType::TextureProjOffset:
            out << "TextureProjOffset";
            break;
        case FunctionType::TextureProjOffsetBias:
            out << "TextureProjOffsetBias";
            break;
        case FunctionType::TextureProjLod:
            out << "TextureProjLod";
            break;
        case FunctionType::TextureProjLodOffset:
            out << "TextureProjLodOffset";
            break;
        case FunctionType::TextureProjGrad:
            out << "TextureProjGrad";
            break;
        case FunctionType::TextureProjGradOffset:
            out << "TextureProjGradOffset";
            break;
    }
    return out;
}
void ParseShadowSamplerFunctionVariationsTestParams(
    const ShadowSamplerFunctionVariationsTestParams ¶ms,
    FunctionType *functionOut,
    bool *mipmappedOut)
{
    *functionOut  = std::get<1>(params);
    *mipmappedOut = std::get<2>(params);
}
std::string ShadowSamplerFunctionVariationsTestPrint(
    const ::testing::TestParamInfo<ShadowSamplerFunctionVariationsTestParams> ¶msInfo)
{
    const ShadowSamplerFunctionVariationsTestParams ¶ms = paramsInfo.param;
    std::ostringstream out;
    out << std::get<0>(params);
    FunctionType function;
    bool mipmapped;
    ParseShadowSamplerFunctionVariationsTestParams(params, &function, &mipmapped);
    out << "__" << function << "_" << (mipmapped ? "Mipmapped" : "NonMipmapped");
    return out.str();
}
class ShadowSamplerFunctionTestBase : public ANGLETest<ShadowSamplerFunctionVariationsTestParams>
{
  protected:
    ShadowSamplerFunctionTestBase()
    {
        setWindowWidth(16);
        setWindowHeight(16);
        setConfigRedBits(8);
        setConfigGreenBits(8);
        setConfigBlueBits(8);
        setConfigAlphaBits(8);
    }
    GLuint mPrg = 0;
};
class ShadowSamplerFunctionTexture2DTest : public ShadowSamplerFunctionTestBase
{
  protected:
    void setupProgram2D(FunctionType function, bool useShadowSampler)
    {
        std::stringstream fragmentSource;
        fragmentSource << "#version 300 es\n"
                       << "precision mediump float;\n"
                       << "precision mediump sampler2D;\n"
                       << "precision mediump sampler2DShadow;\n"
                       << "uniform float dRef;\n"
                       << "uniform sampler2D" << (useShadowSampler ? "Shadow" : "") << " tex;\n"
                       << "in vec4 v_position;\n"
                       << "out vec4 my_FragColor;\n"
                       << "void main()\n"
                       << "{\n"
                       << "    vec2 texcoord = v_position.xy * 0.5 + 0.5;\n"
                       << "    float r = " << FunctionName(function) << "(tex, ";
        if (IsProj(function))
        {
            if (useShadowSampler)
            {
                fragmentSource << "vec4(texcoord * 2.0, dRef * 2.0, 2.0)";
            }
            else
            {
                fragmentSource << "vec3(texcoord * 2.0, 2.0)";
            }
        }
        else
        {
            if (useShadowSampler)
            {
                fragmentSource << "vec3(texcoord, dRef)";
            }
            else
            {
                fragmentSource << "vec2(texcoord)";
            }
        }
        if (HasLOD(function))
        {
            fragmentSource << ", 2.0";
        }
        else if (HasGrad(function))
        {
            fragmentSource << ", vec2(0.17), vec2(0.17)";
        }
        if (HasOffset(function))
        {
            // Does not affect LOD selection, added to try all overloads.
            fragmentSource << ", ivec2(1, 1)";
        }
        if (HasBias(function))
        {
            fragmentSource << ", 3.0";
        }
        fragmentSource << ")" << (useShadowSampler ? "" : ".r") << ";\n";
        if (useShadowSampler)
        {
            fragmentSource << "    my_FragColor = vec4(0.0, r, 1.0 - r, 1.0);\n";
        }
        else
        {
            fragmentSource << "    my_FragColor = vec4(r, 0.0, 0.0, 1.0);\n";
        }
        fragmentSource << "}";
        ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Passthrough(), fragmentSource.str().c_str());
        glUseProgram(program);
        mPrg = program;
    }
};
class ShadowSamplerFunctionTexture2DArrayTest : public ShadowSamplerFunctionTestBase
{
  protected:
    void setupProgram2DArray(FunctionType function, bool useShadowSampler)
    {
        ASSERT_FALSE(IsProj(function));
        std::stringstream fragmentSource;
        fragmentSource << "#version 300 es\n"
                       << "#extension GL_EXT_texture_shadow_lod : enable\n"
                       << "precision mediump float;\n"
                       << "precision mediump sampler2DArray;\n"
                       << "precision mediump sampler2DArrayShadow;\n"
                       << "uniform float dRef;\n"
                       << "uniform sampler2DArray" << (useShadowSampler ? "Shadow" : "")
                       << " tex;\n"
                       << "in vec4 v_position;\n"
                       << "out vec4 my_FragColor;\n"
                       << "void main()\n"
                       << "{\n"
                       << "    vec2 texcoord = v_position.xy * 0.5 + 0.5;\n"
                       << "    float r = " << FunctionName(function) << "(tex, ";
        if (useShadowSampler)
        {
            fragmentSource << "vec4(texcoord, 1.0, dRef)";
        }
        else
        {
            fragmentSource << "vec3(texcoord, 1.0)";
        }
        if (HasLOD(function))
        {
            fragmentSource << ", 2.0";
        }
        else if (HasGrad(function))
        {
            fragmentSource << ", vec2(0.17), vec2(0.17)";
        }
        if (HasOffset(function))
        {
            // Does not affect LOD selection, added to try all overloads.
            fragmentSource << ", ivec2(1, 1)";
        }
        if (HasBias(function))
        {
            fragmentSource << ", 3.0";
        }
        fragmentSource << ")" << (useShadowSampler ? "" : ".r") << ";\n";
        if (useShadowSampler)
        {
            fragmentSource << "    my_FragColor = vec4(0.0, r, 1.0 - r, 1.0);\n";
        }
        else
        {
            fragmentSource << "    my_FragColor = vec4(r, 0.0, 0.0, 1.0);\n";
        }
        fragmentSource << "}";
        ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Passthrough(), fragmentSource.str().c_str());
        glUseProgram(program);
        mPrg = program;
    }
};
class ShadowSamplerFunctionTextureCubeTest : public ShadowSamplerFunctionTestBase
{
  protected:
    void setupProgramCube(FunctionType function, bool useShadowSampler)
    {
        ASSERT_FALSE(IsProj(function));
        ASSERT_FALSE(HasOffset(function));
        std::stringstream fragmentSource;
        fragmentSource << "#version 300 es\n"
                       << "#extension GL_EXT_texture_shadow_lod : enable\n"
                       << "precision mediump float;\n"
                       << "precision mediump samplerCube;\n"
                       << "precision mediump samplerCubeShadow;\n"
                       << "uniform float dRef;\n"
                       << "uniform samplerCube" << (useShadowSampler ? "Shadow" : "") << " tex;\n"
                       << "in vec4 v_position;\n"
                       << "out vec4 my_FragColor;\n"
                       << "void main()\n"
                       << "{\n"
                       << "    vec3 texcoord = vec3(1.0, v_position.xy);\n"
                       << "    float r = " << FunctionName(function) << "(tex, ";
        if (useShadowSampler)
        {
            fragmentSource << "vec4(texcoord, dRef)";
        }
        else
        {
            fragmentSource << "vec3(texcoord)";
        }
        if (HasLOD(function))
        {
            fragmentSource << ", 2.0";
        }
        else if (HasGrad(function))
        {
            fragmentSource << ", vec3(0.0, 0.34, 0.34), vec3(0.0)";
        }
        if (HasBias(function))
        {
            fragmentSource << ", 3.0";
        }
        fragmentSource << ")" << (useShadowSampler ? "" : ".r") << ";\n";
        if (useShadowSampler)
        {
            fragmentSource << "    my_FragColor = vec4(0.0, r, 1.0 - r, 1.0);\n";
        }
        else
        {
            fragmentSource << "    my_FragColor = vec4(r, 0.0, 0.0, 1.0);\n";
        }
        fragmentSource << "}";
        ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Passthrough(), fragmentSource.str().c_str());
        glUseProgram(program);
        mPrg = program;
    }
};
class ShadowSamplerFunctionTextureCubeArrayTest : public ShadowSamplerFunctionTestBase
{
  protected:
    void setupProgramCubeArray(FunctionType function, bool useShadowSampler)
    {
        ASSERT_FALSE(IsProj(function));
        ASSERT_FALSE(HasOffset(function));
        ASSERT_FALSE(HasGrad(function));
        std::stringstream fragmentSource;
        fragmentSource << "#version 310 es\n"
                       << "#extension GL_EXT_texture_cube_map_array : require\n"
                       << "#extension GL_EXT_texture_shadow_lod : enable\n"
                       << "precision mediump float;\n"
                       << "precision mediump samplerCubeArray;\n"
                       << "precision mediump samplerCubeArrayShadow;\n"
                       << "uniform float dRef;\n"
                       << "uniform samplerCubeArray" << (useShadowSampler ? "Shadow" : "")
                       << " tex;\n"
                       << "in vec4 v_position;\n"
                       << "out vec4 my_FragColor;\n"
                       << "void main()\n"
                       << "{\n"
                       << "    vec4 texcoord = vec4(1.0, v_position.xy, 1.0);\n"
                       << "    float r = " << FunctionName(function) << "(tex, texcoord";
        if (useShadowSampler)
        {
            fragmentSource << ", dRef";
        }
        if (HasLOD(function))
        {
            fragmentSource << ", 2.0";
        }
        else if (HasBias(function))
        {
            fragmentSource << ", 3.0";
        }
        fragmentSource << ")" << (useShadowSampler ? "" : ".r") << ";\n";
        if (useShadowSampler)
        {
            fragmentSource << "    my_FragColor = vec4(0.0, r, 1.0 - r, 1.0);\n";
        }
        else
        {
            fragmentSource << "    my_FragColor = vec4(r, 0.0, 0.0, 1.0);\n";
        }
        fragmentSource << "}";
        ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Passthrough(), fragmentSource.str().c_str());
        glUseProgram(program);
        mPrg = program;
    }
};
constexpr GLenum kCompareFuncs[] = {
    GL_LEQUAL, GL_GEQUAL, GL_LESS, GL_GREATER, GL_EQUAL, GL_NOTEQUAL, GL_ALWAYS, GL_NEVER,
};
constexpr float kRefValues[] = {
    0.0f, 0.25f, 0.5f, 0.75f, 1.0f,
};
// Test TEXTURE_2D with shadow samplers
TEST_P(ShadowSamplerFunctionTexture2DTest, Test)
{
    FunctionType function;
    bool mipmapped;
    ParseShadowSamplerFunctionVariationsTestParams(GetParam(), &function, &mipmapped);
    GLTexture tex;
    const std::vector<GLfloat> level0(64, 0.125f);
    const std::vector<GLfloat> level1(16, 0.5f);
    const std::vector<GLfloat> level2(4, 0.25f);
    const std::vector<GLfloat> level3(1, 0.75f);
    glBindTexture(GL_TEXTURE_2D, tex);
    glTexStorage2D(GL_TEXTURE_2D, 4, GL_DEPTH_COMPONENT32F, 8, 8);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_DEPTH_COMPONENT, GL_FLOAT, level0.data());
    glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 4, 4, GL_DEPTH_COMPONENT, GL_FLOAT, level1.data());
    glTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 2, 2, GL_DEPTH_COMPONENT, GL_FLOAT, level2.data());
    glTexSubImage2D(GL_TEXTURE_2D, 3, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, level3.data());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                    mipmapped ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
    ASSERT_GL_NO_ERROR();
    float expectedSample;
    if (mipmapped)
    {
        if (HasBias(function))
        {
            // Base level 8x8, viewport 8x8, bias 3.0
            expectedSample = level3[0];
        }
        else if (HasLOD(function))
        {
            // Explicitly requested level 2
            expectedSample = level2[0];
        }
        else if (HasGrad(function))
        {
            // Screen space derivatives of 0.17 for a 8x8 texture should resolve to level 1
            expectedSample = level1[0];
        }
        else  // implicit LOD
        {
            // Base level 8x8, viewport 8x8, no bias
            expectedSample = level0[0];
        }
    }
    else
    {
        // LOD options must have no effect when the texture is not mipmapped.
        expectedSample = level0[0];
    }
    glViewport(0, 0, 8, 8);
    glClearColor(1.0, 0.0, 1.0, 1.0);
    // First sample the texture directly for easier debugging
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    setupProgram2D(function, false);
    ASSERT_GL_NO_ERROR();
    glClear(GL_COLOR_BUFFER_BIT);
    drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
    EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(expectedSample * 255.0, 0, 0, 255), 1);
    // Try shadow samplers
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
    setupProgram2D(function, true);
    const GLint loc = glGetUniformLocation(mPrg, "dRef");
    for (const float refValue : kRefValues)
    {
        glUniform1f(loc, refValue);
        for (const GLenum compareFunc : kCompareFuncs)
        {
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, compareFunc);
            ASSERT_GL_NO_ERROR();
            glClear(GL_COLOR_BUFFER_BIT);
            drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
            if (Compare(refValue, expectedSample, compareFunc))
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::green)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
            else
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::blue)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
        }
    }
}
// Test TEXTURE_2D_ARRAY with shadow samplers
TEST_P(ShadowSamplerFunctionTexture2DArrayTest, Test)
{
    FunctionType function;
    bool mipmapped;
    ParseShadowSamplerFunctionVariationsTestParams(GetParam(), &function, &mipmapped);
    if (RequiresExtensionFor2DArray(function))
    {
        ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_shadow_lod"));
    }
    GLTexture tex;
    const std::vector<GLfloat> unused(64, 0.875);
    const std::vector<GLfloat> level0(64, 0.125f);
    const std::vector<GLfloat> level1(16, 0.5f);
    const std::vector<GLfloat> level2(4, 0.25f);
    const std::vector<GLfloat> level3(1, 0.75f);
    glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
    glTexStorage3D(GL_TEXTURE_2D_ARRAY, 4, GL_DEPTH_COMPONENT32F, 8, 8, 2);
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 8, 8, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    unused.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 1, 0, 0, 0, 4, 4, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    unused.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 2, 0, 0, 0, 2, 2, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    unused.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 3, 0, 0, 0, 1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    unused.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 1, 8, 8, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    level0.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 1, 0, 0, 1, 4, 4, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    level1.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 2, 0, 0, 1, 2, 2, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    level2.data());
    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 3, 0, 0, 1, 1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT,
                    level3.data());
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
                    mipmapped ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
    ASSERT_GL_NO_ERROR();
    float expectedSample;
    if (mipmapped)
    {
        if (HasBias(function))
        {
            // Base level 8x8, viewport 8x8, bias 3.0
            expectedSample = level3[0];
        }
        else if (HasLOD(function))
        {
            // Explicitly requested level 2
            expectedSample = level2[0];
        }
        else if (HasGrad(function))
        {
            // Screen space derivatives of 0.17 for a 8x8 texture should resolve to level 1
            expectedSample = level1[0];
        }
        else  // implicit LOD
        {
            // Base level 8x8, viewport 8x8, no bias
            expectedSample = level0[0];
        }
    }
    else
    {
        // LOD options must have no effect when the texture is not mipmapped.
        expectedSample = level0[0];
    }
    glViewport(0, 0, 8, 8);
    glClearColor(1.0, 0.0, 1.0, 1.0);
    // First sample the texture directly for easier debugging
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    setupProgram2DArray(function, false);
    ASSERT_GL_NO_ERROR();
    glClear(GL_COLOR_BUFFER_BIT);
    drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
    EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(expectedSample * 255.0, 0, 0, 255), 1);
    // Try shadow samplers
    glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
    setupProgram2DArray(function, true);
    const GLint loc = glGetUniformLocation(mPrg, "dRef");
    for (const float refValue : kRefValues)
    {
        glUniform1f(loc, refValue);
        for (const GLenum compareFunc : kCompareFuncs)
        {
            glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_COMPARE_FUNC, compareFunc);
            ASSERT_GL_NO_ERROR();
            glClear(GL_COLOR_BUFFER_BIT);
            drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
            if (Compare(refValue, expectedSample, compareFunc))
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::green)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
            else
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::blue)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
        }
    }
}
// Test TEXTURE_CUBE_MAP with shadow samplers
TEST_P(ShadowSamplerFunctionTextureCubeTest, Test)
{
    FunctionType function;
    bool mipmapped;
    ParseShadowSamplerFunctionVariationsTestParams(GetParam(), &function, &mipmapped);
    if (RequiresExtensionForCube(function))
    {
        ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_shadow_lod"));
    }
    GLTexture tex;
    const std::vector<GLfloat> level0(64, 0.125f);
    const std::vector<GLfloat> level1(16, 0.5f);
    const std::vector<GLfloat> level2(4, 0.25f);
    const std::vector<GLfloat> level3(1, 0.75f);
    glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
    glTexStorage2D(GL_TEXTURE_CUBE_MAP, 4, GL_DEPTH_COMPONENT32F, 8, 8);
    for (const GLenum face : {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                              GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
                              GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z})
    {
        glTexSubImage2D(face, 0, 0, 0, 8, 8, GL_DEPTH_COMPONENT, GL_FLOAT, level0.data());
        glTexSubImage2D(face, 1, 0, 0, 4, 4, GL_DEPTH_COMPONENT, GL_FLOAT, level1.data());
        glTexSubImage2D(face, 2, 0, 0, 2, 2, GL_DEPTH_COMPONENT, GL_FLOAT, level2.data());
        glTexSubImage2D(face, 3, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, level3.data());
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
                    mipmapped ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
    ASSERT_GL_NO_ERROR();
    float expectedSample;
    if (mipmapped)
    {
        if (HasBias(function))
        {
            // Base level 8x8, viewport 8x8, bias 3.0
            expectedSample = level3[0];
        }
        else if (HasLOD(function))
        {
            // Explicitly requested level 2
            expectedSample = level2[0];
        }
        else if (HasGrad(function))
        {
            // Cube screen space derivatives should be projected as 0.17
            // on the +X face and resolved to level 1 for a 8x8 texture
            expectedSample = level1[0];
        }
        else  // implicit LOD
        {
            // Base level 8x8, viewport 8x8, no bias
            expectedSample = level0[0];
        }
    }
    else
    {
        // LOD options must have no effect when the texture is not mipmapped.
        expectedSample = level0[0];
    }
    glViewport(0, 0, 8, 8);
    glClearColor(1.0, 0.0, 1.0, 1.0);
    // First sample the texture directly for easier debugging
    // This step is skipped on Apple GPUs when the PreTransformTextureCubeGradDerivatives feature
    // is disabled for testing because native cubemap sampling with explicit derivatives does not
    // work on that platform without this feature.
    // Since the AllowSamplerCompareGradient feature is also disabled in this case, the next steps,
    // which use shadow samplers, rely on emulation and thus they are not affected.
    const auto &disabledFeatures = std::get<0>(GetParam()).eglParameters.disabledFeatureOverrides;
    if (!IsAppleGPU() ||
        std::find(disabledFeatures.begin(), disabledFeatures.end(),
                  Feature::PreTransformTextureCubeGradDerivatives) == disabledFeatures.end())
    {
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_NONE);
        setupProgramCube(function, false);
        ASSERT_GL_NO_ERROR();
        glClear(GL_COLOR_BUFFER_BIT);
        drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
        EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(expectedSample * 255.0, 0, 0, 255), 1);
    }
    // Try shadow samplers
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
    setupProgramCube(function, true);
    const GLint loc = glGetUniformLocation(mPrg, "dRef");
    for (const float refValue : kRefValues)
    {
        glUniform1f(loc, refValue);
        for (const GLenum compareFunc : kCompareFuncs)
        {
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_FUNC, compareFunc);
            ASSERT_GL_NO_ERROR();
            glClear(GL_COLOR_BUFFER_BIT);
            drawQuad(mPrg, essl3_shaders::PositionAttrib(), 0.0f);
            if (Compare(refValue, expectedSample, compareFunc))
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::green)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
            else
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::blue)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
        }
    }
}
// Test TEXTURE_CUBE_MAP_ARRAY with shadow samplers
TEST_P(ShadowSamplerFunctionTextureCubeArrayTest, Test)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_cube_map_array"));
    FunctionType function;
    bool mipmapped;
    ParseShadowSamplerFunctionVariationsTestParams(GetParam(), &function, &mipmapped);
    if (RequiresExtensionForCubeArray(function))
    {
        ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_texture_shadow_lod"));
    }
    GLTexture tex;
    const std::vector<GLfloat> unused(64, 0.875);
    const std::vector<GLfloat> level0(64, 0.125f);
    const std::vector<GLfloat> level1(16, 0.5f);
    const std::vector<GLfloat> level2(4, 0.25f);
    const std::vector<GLfloat> level3(1, 0.75f);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, tex);
    glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 4, GL_DEPTH_COMPONENT32F, 8, 8, 12);
    for (size_t k = 0; k < 6 * 2; ++k)
    {
        glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 0, 0, 0, k, 8, 8, 1, GL_DEPTH_COMPONENT,
                        GL_FLOAT, k > 5 ? level0.data() : unused.data());
        glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 1, 0, 0, k, 4, 4, 1, GL_DEPTH_COMPONENT,
                        GL_FLOAT, k > 5 ? level1.data() : unused.data());
        glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 2, 0, 0, k, 2, 2, 1, GL_DEPTH_COMPONENT,
                        GL_FLOAT, k > 5 ? level2.data() : unused.data());
        glTexSubImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 3, 0, 0, k, 1, 1, 1, GL_DEPTH_COMPONENT,
                        GL_FLOAT, k > 5 ? level3.data() : unused.data());
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, GL_TEXTURE_MIN_FILTER,
                    mipmapped ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST);
    ASSERT_GL_NO_ERROR();
    float expectedSample;
    if (mipmapped)
    {
        if (HasBias(function))
        {
            // Base level 8x8, viewport 8x8, bias 3.0
            expectedSample = level3[0];
        }
        else if (HasLOD(function))
        {
            // Explicitly requested level 2
            expectedSample = level2[0];
        }
        else  // implicit LOD
        {
            // Base level 8x8, viewport 8x8, no bias
            expectedSample = level0[0];
        }
    }
    else
    {
        // LOD options must have no effect when the texture is not mipmapped.
        expectedSample = level0[0];
    }
    glViewport(0, 0, 8, 8);
    glClearColor(1.0, 0.0, 1.0, 1.0);
    // First sample the texture directly for easier debugging
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    setupProgramCubeArray(function, false);
    ASSERT_GL_NO_ERROR();
    glClear(GL_COLOR_BUFFER_BIT);
    drawQuad(mPrg, essl31_shaders::PositionAttrib(), 0.0f);
    EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(expectedSample * 255.0, 0, 0, 255), 1);
    // Try shadow samplers
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, GL_TEXTURE_COMPARE_MODE,
                    GL_COMPARE_REF_TO_TEXTURE);
    setupProgramCubeArray(function, true);
    const GLint loc = glGetUniformLocation(mPrg, "dRef");
    for (const float refValue : kRefValues)
    {
        glUniform1f(loc, refValue);
        for (const GLenum compareFunc : kCompareFuncs)
        {
            glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, GL_TEXTURE_COMPARE_FUNC, compareFunc);
            ASSERT_GL_NO_ERROR();
            glClear(GL_COLOR_BUFFER_BIT);
            drawQuad(mPrg, essl31_shaders::PositionAttrib(), 0.0f);
            if (Compare(refValue, expectedSample, compareFunc))
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::green)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
            else
            {
                EXPECT_PIXEL_COLOR_EQ(4, 4, GLColor::blue)
                    << gl::GLenumToString(gl::GLESEnum::DepthFunction, compareFunc)
                    << ", reference " << refValue << ", expected sample " << expectedSample;
            }
        }
    }
}
constexpr FunctionType kTexture2DFunctionTypes[] = {
    FunctionType::Texture,           FunctionType::TextureBias,
    FunctionType::TextureOffset,     FunctionType::TextureOffsetBias,
    FunctionType::TextureLod,        FunctionType::TextureLodOffset,
    FunctionType::TextureGrad,       FunctionType::TextureGradOffset,
    FunctionType::TextureProj,       FunctionType::TextureProjBias,
    FunctionType::TextureProjOffset, FunctionType::TextureProjOffsetBias,
    FunctionType::TextureProjLod,    FunctionType::TextureProjLodOffset,
    FunctionType::TextureProjGrad,   FunctionType::TextureProjGradOffset,
};
constexpr FunctionType kTexture2DArrayFunctionTypes[] = {
    FunctionType::Texture,       FunctionType::TextureBias,
    FunctionType::TextureOffset, FunctionType::TextureOffsetBias,
    FunctionType::TextureLod,    FunctionType::TextureLodOffset,
    FunctionType::TextureGrad,   FunctionType::TextureGradOffset,
};
constexpr FunctionType kTextureCubeFunctionTypes[] = {
    FunctionType::Texture,
    FunctionType::TextureBias,
    FunctionType::TextureLod,
    FunctionType::TextureGrad,
};
constexpr FunctionType kTextureCubeArrayFunctionTypes[] = {
    FunctionType::Texture,
    FunctionType::TextureBias,
    FunctionType::TextureLod,
};
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShadowSamplerFunctionTexture2DTest);
ANGLE_INSTANTIATE_TEST_COMBINE_2(ShadowSamplerFunctionTexture2DTest,
                                 ShadowSamplerFunctionVariationsTestPrint,
                                 testing::ValuesIn(kTexture2DFunctionTypes),
                                 testing::Bool(),
                                 ANGLE_ALL_TEST_PLATFORMS_ES3,
                                 ES3_METAL()
                                     .disable(Feature::AllowSamplerCompareGradient)
                                     .disable(Feature::PreTransformTextureCubeGradDerivatives));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShadowSamplerFunctionTexture2DArrayTest);
ANGLE_INSTANTIATE_TEST_COMBINE_2(ShadowSamplerFunctionTexture2DArrayTest,
                                 ShadowSamplerFunctionVariationsTestPrint,
                                 testing::ValuesIn(kTexture2DArrayFunctionTypes),
                                 testing::Bool(),
                                 ANGLE_ALL_TEST_PLATFORMS_ES3,
                                 ES3_METAL()
                                     .disable(Feature::AllowSamplerCompareGradient)
                                     .disable(Feature::PreTransformTextureCubeGradDerivatives));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShadowSamplerFunctionTextureCubeTest);
ANGLE_INSTANTIATE_TEST_COMBINE_2(ShadowSamplerFunctionTextureCubeTest,
                                 ShadowSamplerFunctionVariationsTestPrint,
                                 testing::ValuesIn(kTextureCubeFunctionTypes),
                                 testing::Bool(),
                                 ANGLE_ALL_TEST_PLATFORMS_ES3,
                                 ES3_METAL()
                                     .disable(Feature::AllowSamplerCompareGradient)
                                     .disable(Feature::PreTransformTextureCubeGradDerivatives));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ShadowSamplerFunctionTextureCubeArrayTest);
ANGLE_INSTANTIATE_TEST_COMBINE_2(ShadowSamplerFunctionTextureCubeArrayTest,
                                 ShadowSamplerFunctionVariationsTestPrint,
                                 testing::ValuesIn(kTextureCubeArrayFunctionTypes),
                                 testing::Bool(),
                                 ANGLE_ALL_TEST_PLATFORMS_ES31);
}  // anonymous namespace