Hash :
d193d51b
Author :
Date :
2024-06-17T22:46:08
Replace issue ids post migration to new issue tracker This change replaces anglebug.com/NNNN links. Bug: None Change-Id: I8ac3aec8d2a8a844b3d7b99fc0a6b2be8da31761 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5637912 Reviewed-by: Geoff Lang <geofflang@chromium.org> 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
//
// Copyright 2017 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.
//
// LinkAndRelinkFailureTest:
// Link and relink failure tests for rendering pipeline and compute pipeline.
#include <vector>
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
class LinkAndRelinkTest : public ANGLETest<>
{
protected:
LinkAndRelinkTest() {}
};
class LinkAndRelinkTestES3 : public ANGLETest<>
{
protected:
LinkAndRelinkTestES3() {}
};
class LinkAndRelinkTestES31 : public ANGLETest<>
{
protected:
LinkAndRelinkTestES31() {}
};
// Test destruction of a context with a pending relink of the current in-use
// program.
TEST_P(LinkAndRelinkTest, DestructionWithPendingRelink)
{
constexpr char kVS[] = "void main() {}";
constexpr char kFS[] = "void main() {}";
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
GLuint program = glCreateProgram();
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glUseProgram(program);
glLinkProgram(program);
EXPECT_GL_NO_ERROR();
}
// When a program link or relink fails, if you try to install the unsuccessfully
// linked program (via UseProgram) and start rendering or dispatch compute,
// We can not always report INVALID_OPERATION for rendering/compute pipeline.
// The result depends on the previous state: Whether a valid program is
// installed in current GL state before the link.
// If a program successfully relinks when it is in use, the program might
// change from a rendering program to a compute program in theory,
// or vice versa.
// When program link fails and no valid rendering program is installed in the GL
// state before the link, it should report an error for UseProgram
TEST_P(LinkAndRelinkTest, RenderingProgramFailsWithoutProgramInstalled)
{
glUseProgram(0);
GLuint program = glCreateProgram();
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
glUseProgram(program);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
}
// When program link or relink fails and a valid rendering program is installed
// in the GL state before the link, using the failed program via UseProgram
// should report an error, but starting rendering should succeed.
// However, dispatching compute always fails.
TEST_P(LinkAndRelinkTest, RenderingProgramFailsWithProgramInstalled)
{
// Install a render program in current GL state via UseProgram, then render.
// It should succeed.
constexpr char kVS[] = "void main() {}";
constexpr char kFS[] = "void main() {}";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
glAttachShader(program, vs);
glDeleteShader(vs);
glAttachShader(program, fs);
glDeleteShader(fs);
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Link failure, and a valid program has been installed in the GL state.
GLuint programNull = glCreateProgram();
glLinkProgram(programNull);
glGetProgramiv(programNull, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
// Starting rendering should succeed.
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully linked program should report an error.
glUseProgram(programNull);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully linked program, that program should not
// replace the program binary residing in the GL state. It will not make
// the installed program invalid either, like what UseProgram(0) can do.
// So, starting rendering should succeed.
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// We try to relink the installed program, but make it fail.
// No vertex shader, relink fails.
glDetachShader(program, vs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
EXPECT_GL_NO_ERROR();
// Starting rendering should succeed.
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully relinked program should report an error.
glUseProgram(program);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully relinked program, that program should not
// replace the program binary residing in the GL state. It will not make
// the installed program invalid either, like what UseProgram(0) can do.
// So, starting rendering should succeed.
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Tests uniform default values.
TEST_P(LinkAndRelinkTest, UniformDefaultValues)
{
// TODO(anglebug.com/42262609): Understand why rectangle texture CLs made this fail.
ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
constexpr char kFS[] = R"(precision mediump float;
uniform vec4 u_uniform;
bool isZero(vec4 value) {
return value == vec4(0,0,0,0);
}
void main()
{
gl_FragColor = isZero(u_uniform) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS);
glUseProgram(program);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
GLint loc = glGetUniformLocation(program, "u_uniform");
ASSERT_NE(-1, loc);
glUniform4f(loc, 0.1f, 0.2f, 0.3f, 0.4f);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
glLinkProgram(program);
ASSERT_GL_NO_ERROR();
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// When program link fails and no valid compute program is installed in the GL
// state before the link, it should report an error for UseProgram and
// DispatchCompute.
TEST_P(LinkAndRelinkTestES31, ComputeProgramFailsWithoutProgramInstalled)
{
glUseProgram(0);
GLuint program = glCreateProgram();
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
glUseProgram(program);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// When program link or relink fails and a valid compute program is installed in
// the GL state before the link, using the failed program via UseProgram should
// report an error, but dispatching compute should succeed.
TEST_P(LinkAndRelinkTestES31, ComputeProgramFailsWithProgramInstalled)
{
// Install a compute program in the GL state via UseProgram, then dispatch
// compute. It should succeed.
constexpr char kCS[] =
R"(#version 310 es
layout(local_size_x=1) in;
void main()
{
})";
GLuint program = glCreateProgram();
GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS);
EXPECT_NE(0u, cs);
glAttachShader(program, cs);
glDeleteShader(cs);
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
// Link failure, and a valid program has been installed in the GL state.
GLuint programNull = glCreateProgram();
glLinkProgram(programNull);
glGetProgramiv(programNull, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
// Dispatching compute should succeed.
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
// Using the unsuccessfully linked program should report an error.
glUseProgram(programNull);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully linked program, that program should not
// replace the program binary residing in the GL state. It will not make
// the installed program invalid either, like what UseProgram(0) can do.
// So, dispatching compute should succeed.
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
// We try to relink the installed program, but make it fail.
// No compute shader, relink fails.
glDetachShader(program, cs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
EXPECT_GL_NO_ERROR();
// Dispatching compute should succeed.
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
// Using the unsuccessfully relinked program should report an error.
glUseProgram(program);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
// Using the unsuccessfully relinked program, that program should not
// replace the program binary residing in the GL state. It will not make
// the installed program invalid either, like what UseProgram(0) can do.
// So, dispatching compute should succeed.
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
}
// If you compile and link a compute program successfully and use the program,
// then dispatching compute and rendering can succeed (with undefined behavior).
// If you relink the compute program to a rendering program when it is in use,
// then dispatching compute will fail, but starting rendering can succeed.
TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromComputeToRendering)
{
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=1) in;
void main()
{
})";
GLuint program = glCreateProgram();
GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS);
EXPECT_NE(0u, cs);
glAttachShader(program, cs);
glDeleteShader(cs);
glLinkProgram(program);
glDetachShader(program, cs);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
constexpr char kVS[] = "void main() {}";
constexpr char kFS[] = "void main() {}";
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
glAttachShader(program, vs);
glDeleteShader(vs);
glAttachShader(program, fs);
glDeleteShader(fs);
glLinkProgram(program);
glDetachShader(program, vs);
glDetachShader(program, fs);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// If you compile and link a rendering program successfully and use the program,
// then starting rendering can succeed, while dispatching compute will fail.
// If you relink the rendering program to a compute program when it is in use,
// then starting rendering will fail, but dispatching compute can succeed.
TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromRenderingToCompute)
{
// http://anglebug.com/42263641
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux() && IsOpenGL());
constexpr char kVS[] = "void main() {}";
constexpr char kFS[] = "void main() {}";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
glAttachShader(program, vs);
glDeleteShader(vs);
glAttachShader(program, fs);
glDeleteShader(fs);
glLinkProgram(program);
glDetachShader(program, vs);
glDetachShader(program, fs);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=1) in;
void main()
{
})";
GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS);
EXPECT_NE(0u, cs);
glAttachShader(program, cs);
glDeleteShader(cs);
glLinkProgram(program);
glDetachShader(program, cs);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
glDispatchCompute(8, 4, 2);
EXPECT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, 1);
EXPECT_GL_NO_ERROR();
}
// Parallel link should continue unscathed even if the attached shaders to the program are modified.
TEST_P(LinkAndRelinkTestES31, ReattachShadersWhileParallelLinking)
{
constexpr char kVS[] = R"(#version 300 es
void main()
{
vec2 position = vec2(-1, -1);
if (gl_VertexID == 1)
position = vec2(3, -1);
else if (gl_VertexID == 2)
position = vec2(-1, 3);
gl_Position = vec4(position, 0, 1);
})";
constexpr char kFSGreen[] = R"(#version 300 es
out mediump vec4 color;
void main()
{
color = vec4(0, 1, 0, 1);
})";
constexpr char kFSRed[] = R"(#version 300 es
out mediump vec4 color;
void main()
{
color = vec4(1, 0, 0, 1);
})";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint green = CompileShader(GL_FRAGMENT_SHADER, kFSGreen);
GLuint red = CompileShader(GL_FRAGMENT_SHADER, kFSRed);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, green);
EXPECT_NE(0u, red);
glAttachShader(program, vs);
glAttachShader(program, green);
glLinkProgram(program);
ASSERT_GL_NO_ERROR();
// Immediately reattach another shader
glDetachShader(program, green);
glAttachShader(program, red);
ASSERT_GL_NO_ERROR();
// Make sure the linked program draws with green
glUseProgram(program);
ASSERT_GL_NO_ERROR();
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
glDeleteShader(vs);
glDeleteShader(green);
glDeleteShader(red);
ASSERT_GL_NO_ERROR();
}
// Parallel link should continue unscathed even if new shaders are attached to the program.
TEST_P(LinkAndRelinkTestES31, AttachNewShadersWhileParallelLinking)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_geometry_shader"));
constexpr char kVS[] = R"(#version 310 es
#extension GL_EXT_geometry_shader : require
void main()
{
vec2 position = vec2(-1, -1);
if (gl_VertexID == 1)
position = vec2(3, -1);
else if (gl_VertexID == 2)
position = vec2(-1, 3);
gl_Position = vec4(position, 0, 1);
})";
constexpr char kFS[] = R"(#version 310 es
#extension GL_EXT_geometry_shader : require
out mediump vec4 color;
void main()
{
color = vec4(0, 1, 0, 1);
})";
constexpr char kGS[] = R"(#version 310 es
#extension GL_EXT_geometry_shader : require
layout (invocations = 3, triangles) in;
layout (triangle_strip, max_vertices = 3) out;
void main()
{
})";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS);
GLuint gs = CompileShader(GL_GEOMETRY_SHADER, kGS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
EXPECT_NE(0u, gs);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
ASSERT_GL_NO_ERROR();
// Immediately attach another shader
glAttachShader(program, gs);
ASSERT_GL_NO_ERROR();
// Make sure the linked program draws with green
glUseProgram(program);
ASSERT_GL_NO_ERROR();
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteShader(gs);
ASSERT_GL_NO_ERROR();
}
// Make sure the shader can be compiled in between attach and link
TEST_P(LinkAndRelinkTest, AttachShaderThenCompile)
{
GLuint program = glCreateProgram();
GLShader vs(GL_VERTEX_SHADER);
GLShader fs(GL_FRAGMENT_SHADER);
// Attach the shaders to the program first. This makes sure the program doesn't prematurely
// attempt to look into the shader's compilation result.
glAttachShader(program, vs);
glAttachShader(program, fs);
// Compile the shaders after that.
const char *kVS = essl1_shaders::vs::Simple();
const char *kFS = essl1_shaders::fs::Green();
glShaderSource(vs, 1, &kVS, nullptr);
glShaderSource(fs, 1, &kFS, nullptr);
EXPECT_GL_NO_ERROR();
glCompileShader(vs);
glCompileShader(fs);
// Then link
glLinkProgram(program);
ASSERT_GL_NO_ERROR();
// Make sure it works
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
ASSERT_GL_NO_ERROR();
glDeleteProgram(program);
ASSERT_GL_NO_ERROR();
}
// If a program is linked successfully once, it should retain its executable if a relink fails.
TEST_P(LinkAndRelinkTestES3, SuccessfulLinkThenFailingRelink)
{
// Install a render program in current GL state via UseProgram, then render.
// It should succeed.
constexpr char kVS[] = R"(#version 300 es
out vec4 color;
void main()
{
vec2 position = vec2(-1, -1);
if (gl_VertexID == 1)
position = vec2(3, -1);
else if (gl_VertexID == 2)
position = vec2(-1, 3);
gl_Position = vec4(position, 0, 1);
color = vec4(0, 1, 0, 1);
})";
constexpr char kBadFS[] = R"(#version 300 es
flat in uvec2 color;
out mediump vec4 colorOut;
void main()
{
colorOut = vec4(1, color, 1);
})";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl3_shaders::fs::Green());
GLuint badfs = CompileShader(GL_FRAGMENT_SHADER, kBadFS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
EXPECT_NE(0u, badfs);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
const int w = getWindowWidth();
const int h = getWindowHeight();
glViewport(0, 0, w, h);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w / 2, h / 2);
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
// Cause the program to fail linking
glDetachShader(program, fs);
glAttachShader(program, badfs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
// Link failed, but the program should still be usable.
glScissor(w / 2, h / 2, w / 2, h / 2);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, w / 2, h / 2, GLColor::green);
EXPECT_PIXEL_RECT_EQ(w / 2, 0, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(0, h / 2, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(w / 2, h / 2, w / 2, h / 2, GLColor::green);
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteShader(badfs);
glDeleteProgram(program);
}
// Similar to SuccessfulLinkThenFailingRelink, but with a more complicated mix of resources.
TEST_P(LinkAndRelinkTestES31, SuccessfulLinkThenFailingRelink2)
{
GLint maxFragmentShaderStorageBlocks;
glGetIntegerv(GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &maxFragmentShaderStorageBlocks);
ANGLE_SKIP_TEST_IF(maxFragmentShaderStorageBlocks < 1);
// Install a render program in current GL state via UseProgram, then render.
// It should succeed.
constexpr char kVS[] = R"(#version 310 es
out vec4 color;
void main()
{
vec2 position = vec2(-1, -1);
if (gl_VertexID == 1)
position = vec2(3, -1);
else if (gl_VertexID == 2)
position = vec2(-1, 3);
gl_Position = vec4(position, 0, 1);
color = vec4(0, 1, 0, 1);
})";
constexpr char kGoodFS[] = R"(#version 310 es
in mediump vec4 color;
out mediump vec4 colorOut;
mediump uniform float u; // should be 0.5;
uniform UBO
{
highp float b; // should be 1.75
};
layout(std140, binding = 1) buffer SSBO
{
uint s; // should be 0x12345678
};
void main()
{
if (abs(u - 0.5) > 0.01)
colorOut = vec4(1, 0, 0, 1);
else if (abs(b - 1.75) > 0.01)
colorOut = vec4(0, 0, 1, 1);
else if (s != 0x12345678u)
colorOut = vec4(1, 0, 1, 1);
else
colorOut = color;
})";
constexpr char kBadFS[] = R"(#version 310 es
flat in uvec2 color;
layout(location = 0) out mediump vec4 colorOut;
layout(location = 1) out mediump vec4 colorOut2;
void main()
{
colorOut = vec4(1, color, 1);
colorOut2 = vec4(color, 0, 1);
})";
GLuint program = glCreateProgram();
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kGoodFS);
GLuint badfs = CompileShader(GL_FRAGMENT_SHADER, kBadFS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
EXPECT_NE(0u, badfs);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
GLint linkStatus;
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_TRUE(linkStatus);
EXPECT_GL_NO_ERROR();
constexpr float kUBOValue = 1.75;
GLBuffer ubo;
glBindBuffer(GL_UNIFORM_BUFFER, ubo);
glBufferData(GL_UNIFORM_BUFFER, sizeof(kUBOValue), &kUBOValue, GL_STATIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, ubo);
constexpr uint32_t kSSBOValue = 0x12345678;
GLBuffer ssbo;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(kSSBOValue), &kSSBOValue, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssbo);
EXPECT_GL_NO_ERROR();
const int w = getWindowWidth();
const int h = getWindowHeight();
glViewport(0, 0, w, h);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w / 2, h / 2);
glUseProgram(program);
const GLint uniLoc = glGetUniformLocation(program, "u");
ASSERT_NE(uniLoc, -1);
glUniform1f(uniLoc, 0.5);
const GLint uboIndex = glGetUniformBlockIndex(program, "UBO");
ASSERT_NE(uboIndex, -1);
glUniformBlockBinding(program, uboIndex, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
// Cause the program to fail linking
glDetachShader(program, fs);
glAttachShader(program, badfs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
// Link failed, but the program should still be usable.
glScissor(w / 2, h / 2, w / 2, h / 2);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, w / 2, h / 2, GLColor::green);
EXPECT_PIXEL_RECT_EQ(w / 2, 0, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(0, h / 2, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(w / 2, h / 2, w / 2, h / 2, GLColor::green);
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteShader(badfs);
glDeleteProgram(program);
}
// Same as SuccessfulLinkThenFailingRelink, but with PPOs.
TEST_P(LinkAndRelinkTestES31, SuccessfulLinkThenFailingRelinkWithPPO)
{
// Only the Vulkan backend supports PPOs.
ANGLE_SKIP_TEST_IF(!IsVulkan());
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_geometry_shader"));
// Install a render program in current GL state via UseProgram, then render.
// It should succeed.
constexpr char kVS[] = R"(#version 300 es
void main()
{
vec2 position = vec2(-1, -1);
if (gl_VertexID == 1)
position = vec2(3, -1);
else if (gl_VertexID == 2)
position = vec2(-1, 3);
gl_Position = vec4(position, 0, 1);
})";
constexpr char kBadGS[] = R"(#version 310 es
#extension GL_EXT_geometry_shader : require
layout (invocations = 3, triangles) in;
layout (triangle_strip, max_vertices = 3) out;
void main()
{
})";
GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS);
GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl3_shaders::fs::Green());
GLuint badgs = CompileShader(GL_GEOMETRY_SHADER, kBadGS);
EXPECT_NE(0u, vs);
EXPECT_NE(0u, fs);
EXPECT_NE(0u, badgs);
GLuint vsProg = glCreateProgram();
GLuint fsProg = glCreateProgram();
glProgramParameteri(vsProg, GL_PROGRAM_SEPARABLE, GL_TRUE);
glAttachShader(vsProg, vs);
glLinkProgram(vsProg);
EXPECT_GL_NO_ERROR();
glProgramParameteri(fsProg, GL_PROGRAM_SEPARABLE, GL_TRUE);
glAttachShader(fsProg, fs);
glLinkProgram(fsProg);
EXPECT_GL_NO_ERROR();
GLuint pipeline;
glGenProgramPipelines(1, &pipeline);
glUseProgramStages(pipeline, GL_VERTEX_SHADER_BIT, vsProg);
glUseProgramStages(pipeline, GL_FRAGMENT_SHADER_BIT, fsProg);
EXPECT_GL_NO_ERROR();
const int w = getWindowWidth();
const int h = getWindowHeight();
glViewport(0, 0, w, h);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w / 2, h / 2);
glUseProgram(0);
glBindProgramPipeline(pipeline);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
// Cause the fs program to fail linking
glAttachShader(fsProg, badgs);
glLinkProgram(fsProg);
glUseProgramStages(pipeline, GL_GEOMETRY_SHADER_BIT, fsProg);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
GLint linkStatus;
glGetProgramiv(fsProg, GL_LINK_STATUS, &linkStatus);
EXPECT_GL_FALSE(linkStatus);
// Program link failed, but the program pipeline should still be usable.
glScissor(w / 2, h / 2, w / 2, h / 2);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, w / 2, h / 2, GLColor::green);
EXPECT_PIXEL_RECT_EQ(w / 2, 0, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(0, h / 2, w / 2, h / 2, GLColor::black);
EXPECT_PIXEL_RECT_EQ(w / 2, h / 2, w / 2, h / 2, GLColor::green);
glDeleteShader(vs);
glDeleteShader(fs);
glDeleteShader(badgs);
glDeleteProgram(vsProg);
glDeleteProgram(fsProg);
glDeleteProgramPipelines(1, &pipeline);
}
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(LinkAndRelinkTest);
ANGLE_INSTANTIATE_TEST_ES3(LinkAndRelinkTestES3);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(LinkAndRelinkTestES31);
ANGLE_INSTANTIATE_TEST_ES31(LinkAndRelinkTestES31);
} // namespace