Hash :
3b7528e1
Author :
Date :
2025-05-20T12:31:28
Support running the full end2end suite against the System EGL Update the end2end test instantiation to either fully target the packaged ANGLE libraries or the system EGL, but not a combination of both simultaneously. The GN argument |angle_test_enable_system_egl| controls which driver is being tested by all the instantiated tests. It's default value is "false", which means the tests target the ANGLE libraries by default: kDefaultGLESDriver = GLESDriverType::AngleEGL When |angle_test_enable_system_egl = true|: kDefaultGLESDriver = GLESDriverType::SystemEGL This allows for testing the system EGL with the full end2end test suite, which is useful on devices where ANGLE is the system EGL (e.g., Android). It also allows for specifying which backend to use (or all) during system EGL testing, when ANGLE is the EGL driver. This also includes removing the various ESx_EGL() functions, because the end2end tests must now fully commit to testing either the ANGLE driver or system driver, rather than a combination of both. This is similar to many other test suites, such as the Khronos CTS (dEQP), which only test validate a single driver per invocation. Bug: b/279980674 Test: angle_end2end_tests Change-Id: I4f7dc2ccb4f26b3bd02767d0a0d2876f8612f2ae Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6580876 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Tim Van Patten <timvp@google.com> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com>
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
//
// 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.
//
// RobustBufferAccessBehaviorTest:
// Various tests related for GL_KHR_robust_buffer_access_behavior.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
#include "util/OSWindow.h"
#include <array>
using namespace angle;
namespace
{
class RobustBufferAccessBehaviorTest : public ANGLETest<>
{
protected:
RobustBufferAccessBehaviorTest()
{
setWindowWidth(128);
setWindowHeight(128);
}
void testTearDown() override
{
glDeleteProgram(mProgram);
EGLWindow::Delete(&mEGLWindow);
OSWindow::Delete(&mOSWindow);
}
bool initExtension()
{
mOSWindow = OSWindow::New();
if (!mOSWindow->initialize("RobustBufferAccessBehaviorTest", getWindowWidth(),
getWindowHeight()))
{
return false;
}
setWindowVisible(mOSWindow, true);
Library *driverLib = ANGLETestEnvironment::GetDriverLibrary(getDriverType());
if (!driverLib)
{
std::cout << "Error: Failed to load driver library!";
return false;
}
const PlatformParameters ¶ms = GetParam();
mEGLWindow = EGLWindow::New(params.majorVersion, params.minorVersion);
if (!mEGLWindow->initializeDisplay(mOSWindow, driverLib, GLESDriverType::AngleEGL,
GetParam().eglParameters))
{
return false;
}
EGLDisplay display = mEGLWindow->getDisplay();
if (!IsEGLDisplayExtensionEnabled(display, "EGL_EXT_create_context_robustness"))
{
return false;
}
ConfigParameters configParams;
configParams.redBits = 8;
configParams.greenBits = 8;
configParams.blueBits = 8;
configParams.alphaBits = 8;
configParams.robustAccess = true;
if (mEGLWindow->initializeSurface(mOSWindow, driverLib, configParams) !=
GLWindowResult::NoError)
{
return false;
}
if (!mEGLWindow->initializeContext())
{
return false;
}
if (!mEGLWindow->makeCurrent())
{
return false;
}
if (!IsGLExtensionEnabled("GL_KHR_robust_buffer_access_behavior"))
{
return false;
}
return true;
}
void initBasicProgram()
{
constexpr char kVS[] =
"precision mediump float;\n"
"attribute vec4 position;\n"
"attribute vec4 vecRandom;\n"
"varying vec4 v_color;\n"
"bool testFloatComponent(float component) {\n"
" return (component == 0.2 || component == 0.0);\n"
"}\n"
"bool testLastFloatComponent(float component) {\n"
" return testFloatComponent(component) || component == 1.0;\n"
"}\n"
"void main() {\n"
" if (testFloatComponent(vecRandom.x) &&\n"
" testFloatComponent(vecRandom.y) &&\n"
" testFloatComponent(vecRandom.z) &&\n"
" testLastFloatComponent(vecRandom.w)) {\n"
" v_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
" } else {\n"
" v_color = vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
" gl_Position = position;\n"
"}\n";
constexpr char kFS[] =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_FragColor = v_color;\n"
"}\n";
mProgram = CompileProgram(kVS, kFS);
ASSERT_NE(0u, mProgram);
mTestAttrib = glGetAttribLocation(mProgram, "vecRandom");
ASSERT_NE(-1, mTestAttrib);
glUseProgram(mProgram);
}
void runIndexOutOfRangeTests(GLenum drawType)
{
if (mProgram == 0)
{
initBasicProgram();
}
GLBuffer bufferIncomplete;
glBindBuffer(GL_ARRAY_BUFFER, bufferIncomplete);
std::array<GLfloat, 12> randomData = {
{0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f}};
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * randomData.size(), randomData.data(),
drawType);
glEnableVertexAttribArray(mTestAttrib);
glVertexAttribPointer(mTestAttrib, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawIndexedQuad(mProgram, "position", 0.5f);
int width = getWindowWidth();
int height = getWindowHeight();
GLenum result = glGetError();
// For D3D dynamic draw, we still return invalid operation. Once we force the index buffer
// to clamp any out of range indices instead of invalid operation, this part can be removed.
// We can always get GL_NO_ERROR.
if (result == GL_INVALID_OPERATION)
{
EXPECT_PIXEL_COLOR_EQ(width * 1 / 4, height * 1 / 4, GLColor::blue);
EXPECT_PIXEL_COLOR_EQ(width * 1 / 4, height * 3 / 4, GLColor::blue);
EXPECT_PIXEL_COLOR_EQ(width * 3 / 4, height * 1 / 4, GLColor::blue);
EXPECT_PIXEL_COLOR_EQ(width * 3 / 4, height * 3 / 4, GLColor::blue);
}
else
{
EXPECT_GLENUM_EQ(GL_NO_ERROR, result);
EXPECT_PIXEL_COLOR_EQ(width * 1 / 4, height * 1 / 4, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(width * 1 / 4, height * 3 / 4, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(width * 3 / 4, height * 1 / 4, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(width * 3 / 4, height * 3 / 4, GLColor::green);
}
}
OSWindow *mOSWindow = nullptr;
EGLWindow *mEGLWindow = nullptr;
GLuint mProgram = 0;
GLint mTestAttrib = 0;
};
// Test that static draw with out-of-bounds reads will not read outside of the data store of the
// buffer object and will not result in GL interruption or termination when
// GL_KHR_robust_buffer_access_behavior is supported.
TEST_P(RobustBufferAccessBehaviorTest, DrawElementsIndexOutOfRangeWithStaticDraw)
{
ANGLE_SKIP_TEST_IF(!initExtension());
runIndexOutOfRangeTests(GL_STATIC_DRAW);
}
// Test that dynamic draw with out-of-bounds reads will not read outside of the data store of the
// buffer object and will not result in GL interruption or termination when
// GL_KHR_robust_buffer_access_behavior is supported.
TEST_P(RobustBufferAccessBehaviorTest, DrawElementsIndexOutOfRangeWithDynamicDraw)
{
ANGLE_SKIP_TEST_IF(!initExtension());
runIndexOutOfRangeTests(GL_DYNAMIC_DRAW);
}
// Test that vertex buffers are rebound with the correct offsets in subsequent calls in the D3D11
// backend. http://crbug.com/837002
TEST_P(RobustBufferAccessBehaviorTest, D3D11StateSynchronizationOrderBug)
{
ANGLE_SKIP_TEST_IF(!initExtension());
glDisable(GL_DEPTH_TEST);
// 2 quads, the first one red, the second one green
const std::array<angle::Vector4, 16> vertices{
angle::Vector4(-1.0f, 1.0f, 0.5f, 1.0f), // v0
angle::Vector4(1.0f, 0.0f, 0.0f, 1.0f), // c0
angle::Vector4(-1.0f, -1.0f, 0.5f, 1.0f), // v1
angle::Vector4(1.0f, 0.0f, 0.0f, 1.0f), // c1
angle::Vector4(1.0f, -1.0f, 0.5f, 1.0f), // v2
angle::Vector4(1.0f, 0.0f, 0.0f, 1.0f), // c2
angle::Vector4(1.0f, 1.0f, 0.5f, 1.0f), // v3
angle::Vector4(1.0f, 0.0f, 0.0f, 1.0f), // c3
angle::Vector4(-1.0f, 1.0f, 0.5f, 1.0f), // v4
angle::Vector4(0.0f, 1.0f, 0.0f, 1.0f), // c4
angle::Vector4(-1.0f, -1.0f, 0.5f, 1.0f), // v5
angle::Vector4(0.0f, 1.0f, 0.0f, 1.0f), // c5
angle::Vector4(1.0f, -1.0f, 0.5f, 1.0f), // v6
angle::Vector4(0.0f, 1.0f, 0.0f, 1.0f), // c6
angle::Vector4(1.0f, 1.0f, 0.5f, 1.0f), // v7
angle::Vector4(0.0f, 1.0f, 0.0f, 1.0f), // c7
};
GLBuffer vb;
glBindBuffer(GL_ARRAY_BUFFER, vb);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices.data(), GL_STATIC_DRAW);
const std::array<GLushort, 12> indicies{
0, 1, 2, 0, 2, 3, // quad0
4, 5, 6, 4, 6, 7, // quad1
};
GLBuffer ib;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indicies), indicies.data(), GL_STATIC_DRAW);
constexpr char kVS[] = R"(
precision highp float;
attribute vec4 a_position;
attribute vec4 a_color;
varying vec4 v_color;
void main()
{
gl_Position = a_position;
v_color = a_color;
})";
constexpr char kFS[] = R"(
precision highp float;
varying vec4 v_color;
void main()
{
gl_FragColor = v_color;
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
GLint positionLocation = glGetAttribLocation(program, "a_position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 4, GL_FLOAT, GL_FALSE, sizeof(angle::Vector4) * 2, 0);
GLint colorLocation = glGetAttribLocation(program, "a_color");
glEnableVertexAttribArray(colorLocation);
glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, sizeof(angle::Vector4) * 2,
reinterpret_cast<const void *>(sizeof(angle::Vector4)));
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
reinterpret_cast<const void *>(sizeof(GLshort) * 6));
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
reinterpret_cast<const void *>(sizeof(GLshort) * 6));
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Covers drawing with a very large vertex range which overflows GLsizei. http://crbug.com/842028
TEST_P(RobustBufferAccessBehaviorTest, VeryLargeVertexCountWithDynamicVertexData)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_element_index_uint"));
constexpr GLsizei kIndexCount = 32;
std::array<GLuint, kIndexCount> indices = {{}};
for (GLsizei index = 0; index < kIndexCount; ++index)
{
indices[index] = ((std::numeric_limits<GLuint>::max() - 2) / kIndexCount) * index;
}
GLBuffer indexBuffer;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(),
GL_STATIC_DRAW);
std::array<GLfloat, 256> vertexData = {{}};
GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, vertexData.size() * sizeof(GLfloat), vertexData.data(),
GL_DYNAMIC_DRAW);
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
glUseProgram(program);
GLint attribLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
ASSERT_NE(-1, attribLoc);
glVertexAttribPointer(attribLoc, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(attribLoc);
ASSERT_GL_NO_ERROR();
glDrawElements(GL_TRIANGLES, kIndexCount, GL_UNSIGNED_INT, nullptr);
// This may or may not generate an error, but it should not crash.
}
// Test that robust access works even if there's no data uploaded to the vertex buffer at all.
TEST_P(RobustBufferAccessBehaviorTest, NoBufferData)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
glUseProgram(program);
glEnableVertexAttribArray(0);
GLBuffer buf;
glBindBuffer(GL_ARRAY_BUFFER, buf);
glVertexAttribPointer(0, 1, GL_FLOAT, false, 0, nullptr);
ASSERT_GL_NO_ERROR();
std::array<GLubyte, 1u> indices = {0};
glDrawElements(GL_POINTS, indices.size(), GL_UNSIGNED_BYTE, indices.data());
ASSERT_GL_NO_ERROR();
}
constexpr char kWebGLVS[] = R"(attribute vec2 position;
attribute vec4 aOne;
attribute vec4 aTwo;
varying vec4 v;
uniform vec2 comparison;
bool isRobust(vec4 value) {
// The valid buffer range is filled with this value.
if (value.xy == comparison)
return true;
// Checking the w value is a bit complex.
return (value.xyz == vec3(0, 0, 0));
}
void main() {
gl_Position = vec4(position, 0, 1);
if (isRobust(aOne) && isRobust(aTwo)) {
v = vec4(0, 1, 0, 1);
} else {
v = vec4(1, 0, 0, 1);
}
})";
constexpr char kWebGLFS[] = R"(precision mediump float;
varying vec4 v;
void main() {
gl_FragColor = v;
})";
// Test buffer with interleaved (3+2) float vectors. Adapted from WebGL test
// conformance/rendering/draw-arrays-out-of-bounds.html
TEST_P(RobustBufferAccessBehaviorTest, InterleavedAttributes)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(program, kWebGLVS, kWebGLFS);
glUseProgram(program);
constexpr GLint kPosLoc = 0;
constexpr GLint kOneLoc = 1;
constexpr GLint kTwoLoc = 2;
ASSERT_EQ(kPosLoc, glGetAttribLocation(program, "position"));
ASSERT_EQ(kOneLoc, glGetAttribLocation(program, "aOne"));
ASSERT_EQ(kTwoLoc, glGetAttribLocation(program, "aTwo"));
// Create a buffer of 200 valid sets of quad lists.
constexpr size_t kNumQuads = 200;
using QuadVerts = std::array<Vector3, 6>;
std::vector<QuadVerts> quadVerts(kNumQuads, GetQuadVertices());
GLBuffer positionBuf;
glBindBuffer(GL_ARRAY_BUFFER, positionBuf);
glBufferData(GL_ARRAY_BUFFER, kNumQuads * sizeof(QuadVerts), quadVerts.data(), GL_STATIC_DRAW);
glVertexAttribPointer(kPosLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(kPosLoc);
constexpr GLfloat kDefaultFloat = 0.2f;
std::vector<Vector4> defaultFloats(kNumQuads * 2, Vector4(kDefaultFloat));
GLBuffer vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
// enough for 9 vertices, so 3 triangles
glBufferData(GL_ARRAY_BUFFER, 9 * 5 * sizeof(GLfloat), defaultFloats.data(), GL_STATIC_DRAW);
// bind first 3 elements, with a stride of 5 float elements
glVertexAttribPointer(kOneLoc, 3, GL_FLOAT, GL_FALSE, 5 * 4, 0);
// bind 2 elements, starting after the first 3; same stride of 5 float elements
glVertexAttribPointer(kTwoLoc, 2, GL_FLOAT, GL_FALSE, 5 * 4,
reinterpret_cast<const GLvoid *>(3 * 4));
glEnableVertexAttribArray(kOneLoc);
glEnableVertexAttribArray(kTwoLoc);
// set test uniform
GLint uniLoc = glGetUniformLocation(program, "comparison");
ASSERT_NE(-1, uniLoc);
glUniform2f(uniLoc, kDefaultFloat, kDefaultFloat);
// Draw out of bounds.
glDrawArrays(GL_TRIANGLES, 0, 10000);
GLenum err = glGetError();
if (err == GL_NO_ERROR)
{
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
else
{
EXPECT_GLENUM_EQ(GL_INVALID_OPERATION, err);
}
glDrawArrays(GL_TRIANGLES, (kNumQuads - 1) * 6, 6);
err = glGetError();
if (err == GL_NO_ERROR)
{
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
else
{
EXPECT_GLENUM_EQ(GL_INVALID_OPERATION, err);
}
}
// Tests redefining an empty buffer. Adapted from WebGL test
// conformance/rendering/draw-arrays-out-of-bounds.html
TEST_P(RobustBufferAccessBehaviorTest, EmptyBuffer)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(program, kWebGLVS, kWebGLFS);
glUseProgram(program);
constexpr GLint kPosLoc = 0;
constexpr GLint kOneLoc = 1;
constexpr GLint kTwoLoc = 2;
ASSERT_EQ(kPosLoc, glGetAttribLocation(program, "position"));
ASSERT_EQ(kOneLoc, glGetAttribLocation(program, "aOne"));
ASSERT_EQ(kTwoLoc, glGetAttribLocation(program, "aTwo"));
// Create a buffer of 200 valid sets of quad lists.
constexpr size_t kNumQuads = 200;
using QuadVerts = std::array<Vector3, 6>;
std::vector<QuadVerts> quadVerts(kNumQuads, GetQuadVertices());
GLBuffer positionBuf;
glBindBuffer(GL_ARRAY_BUFFER, positionBuf);
glBufferData(GL_ARRAY_BUFFER, kNumQuads * sizeof(QuadVerts), quadVerts.data(), GL_STATIC_DRAW);
glVertexAttribPointer(kPosLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(kPosLoc);
// set test uniform
GLint uniLoc = glGetUniformLocation(program, "comparison");
ASSERT_NE(-1, uniLoc);
glUniform2f(uniLoc, 0, 0);
// Define empty buffer.
GLBuffer buffer;
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_STATIC_DRAW);
glVertexAttribPointer(kOneLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(kOneLoc);
glDrawArrays(GL_TRIANGLES, 0, 3);
GLenum err = glGetError();
if (err == GL_NO_ERROR)
{
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
else
{
EXPECT_GLENUM_EQ(GL_INVALID_OPERATION, err);
}
// Redefine buffer with 3 float vectors.
constexpr GLfloat kFloats[] = {0, 0.5, 0, -0.5, -0.5, 0, 0.5, -0.5, 0};
glBufferData(GL_ARRAY_BUFFER, sizeof(kFloats), kFloats, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLES, 0, 3);
ASSERT_GL_NO_ERROR();
}
// Tests robust buffer access with dynamic buffer usage.
TEST_P(RobustBufferAccessBehaviorTest, DynamicBuffer)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(program, kWebGLVS, kWebGLFS);
glUseProgram(program);
constexpr GLint kPosLoc = 0;
constexpr GLint kOneLoc = 1;
constexpr GLint kTwoLoc = 2;
ASSERT_EQ(kPosLoc, glGetAttribLocation(program, "position"));
ASSERT_EQ(kOneLoc, glGetAttribLocation(program, "aOne"));
ASSERT_EQ(kTwoLoc, glGetAttribLocation(program, "aTwo"));
// Create a buffer of 200 valid sets of quad lists.
constexpr size_t kNumQuads = 200;
using QuadVerts = std::array<Vector3, 6>;
std::vector<QuadVerts> quadVerts(kNumQuads, GetQuadVertices());
GLBuffer positionBuf;
glBindBuffer(GL_ARRAY_BUFFER, positionBuf);
glBufferData(GL_ARRAY_BUFFER, kNumQuads * sizeof(QuadVerts), quadVerts.data(), GL_STATIC_DRAW);
glVertexAttribPointer(kPosLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
glEnableVertexAttribArray(kPosLoc);
constexpr GLfloat kDefaultFloat = 0.2f;
std::vector<Vector4> defaultFloats(kNumQuads * 2, Vector4(kDefaultFloat));
GLBuffer vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
// enough for 9 vertices, so 3 triangles
glBufferData(GL_ARRAY_BUFFER, 9 * 5 * sizeof(GLfloat), defaultFloats.data(), GL_DYNAMIC_DRAW);
// bind first 3 elements, with a stride of 5 float elements
glVertexAttribPointer(kOneLoc, 3, GL_FLOAT, GL_FALSE, 5 * 4, 0);
// bind 2 elements, starting after the first 3; same stride of 5 float elements
glVertexAttribPointer(kTwoLoc, 2, GL_FLOAT, GL_FALSE, 5 * 4,
reinterpret_cast<const GLvoid *>(3 * 4));
glEnableVertexAttribArray(kOneLoc);
glEnableVertexAttribArray(kTwoLoc);
// set test uniform
GLint uniLoc = glGetUniformLocation(program, "comparison");
ASSERT_NE(-1, uniLoc);
glUniform2f(uniLoc, kDefaultFloat, kDefaultFloat);
// Draw out of bounds.
glDrawArrays(GL_TRIANGLES, 0, 10000);
GLenum err = glGetError();
if (err == GL_NO_ERROR)
{
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
else
{
EXPECT_GLENUM_EQ(GL_INVALID_OPERATION, err);
}
glDrawArrays(GL_TRIANGLES, (kNumQuads - 1) * 6, 6);
err = glGetError();
if (err == GL_NO_ERROR)
{
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
else
{
EXPECT_GLENUM_EQ(GL_INVALID_OPERATION, err);
}
}
// Tests out of bounds read by divisor emulation due to a user-provided offset.
// Adapted from https://crbug.com/1285885.
TEST_P(RobustBufferAccessBehaviorTest, IndexOutOfBounds)
{
ANGLE_SKIP_TEST_IF(!initExtension());
constexpr char kVS[] = R"(precision highp float;
attribute vec4 a_position;
void main(void) {
gl_Position = a_position;
})";
constexpr char kFS[] = R"(precision highp float;
uniform sampler2D oTexture;
uniform float oColor[3];
void main(void) {
gl_FragData[0] = texture2DProj(oTexture, vec3(0.1,0.1,0.1));
})";
GLfloat singleFloat = 1.0f;
GLBuffer buf;
glBindBuffer(GL_ARRAY_BUFFER, buf);
glBufferData(GL_ARRAY_BUFFER, 4, &singleFloat, GL_STATIC_DRAW);
ANGLE_GL_PROGRAM(program, kVS, kFS);
glBindAttribLocation(program, 0, "a_position");
glLinkProgram(program);
ASSERT_TRUE(CheckLinkStatusAndReturnProgram(program, true));
glEnableVertexAttribArray(0);
// Trying to exceed renderer->getMaxVertexAttribDivisor()
GLuint constexpr kDivisor = 4096;
glVertexAttribDivisor(0, kDivisor);
size_t outOfBoundsOffset = 0x50000000;
glVertexAttribPointer(0, 1, GL_FLOAT, false, 8, reinterpret_cast<void *>(outOfBoundsOffset));
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 32);
// No assertions, just checking for crashes.
}
// Similar to the test above but index is first within bounds then goes out of bounds.
TEST_P(RobustBufferAccessBehaviorTest, IndexGoingOutOfBounds)
{
ANGLE_SKIP_TEST_IF(!initExtension());
constexpr char kVS[] = R"(precision highp float;
attribute vec4 a_position;
void main(void) {
gl_Position = a_position;
})";
constexpr char kFS[] = R"(precision highp float;
uniform sampler2D oTexture;
uniform float oColor[3];
void main(void) {
gl_FragData[0] = texture2DProj(oTexture, vec3(0.1,0.1,0.1));
})";
GLBuffer buf;
glBindBuffer(GL_ARRAY_BUFFER, buf);
std::array<GLfloat, 2> buffer = {{0.2f, 0.2f}};
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * buffer.size(), buffer.data(), GL_STATIC_DRAW);
ANGLE_GL_PROGRAM(program, kVS, kFS);
glBindAttribLocation(program, 0, "a_position");
glLinkProgram(program);
ASSERT_TRUE(CheckLinkStatusAndReturnProgram(program, true));
glEnableVertexAttribArray(0);
// Trying to exceed renderer->getMaxVertexAttribDivisor()
GLuint constexpr kDivisor = 4096;
glVertexAttribDivisor(0, kDivisor);
// 6 bytes remaining in the buffer from offset so only a single vertex can be read
glVertexAttribPointer(0, 1, GL_FLOAT, false, 8, reinterpret_cast<void *>(2));
glUseProgram(program);
// Each vertex is read `kDivisor` times so the last read goes out of bounds
GLsizei instanceCount = kDivisor + 1;
glDrawArraysInstanced(GL_TRIANGLES, 0, 32, instanceCount);
// No assertions, just checking for crashes.
}
// Draw out-of-bounds beginning with the start offset passed in.
// Ensure that drawArrays flags either no error or INVALID_OPERATION. In the case of
// INVALID_OPERATION, no canvas pixels can be touched. In the case of NO_ERROR, all written values
// must either be the zero vertex or a value in the vertex buffer. See vsCheckOutOfBounds shader.
void DrawAndVerifyOutOfBoundsArrays(int first, int count)
{
glClearColor(0.0, 0.0, 1.0, 1.0); // Start with blue to indicate no pixels touched.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, first, count);
GLenum error = glGetError();
if (error == GL_INVALID_OPERATION)
{
// testPassed. drawArrays flagged INVALID_OPERATION, which is valid so long as all canvas
// pixels were not touched.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
}
else
{
ASSERT_GL_NO_ERROR();
// testPassed. drawArrays flagged NO_ERROR, which is valid so long as all canvas pixels are
// green.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
}
// Adapted from WebGL test
// conformance/rendering/out-of-bounds-array-buffers.html
// This test verifies that out-of-bounds array buffers behave according to spec.
TEST_P(RobustBufferAccessBehaviorTest, OutOfBoundsArrayBuffers)
{
ANGLE_SKIP_TEST_IF(!initExtension());
constexpr char vsCheckOutOfBounds[] =
"precision mediump float;\n"
"attribute vec2 position;\n"
"attribute vec4 vecRandom;\n"
"varying vec4 v_color;\n"
"\n"
"// Per the spec, each component can either contain existing contents\n"
"// of the buffer or 0.\n"
"bool testFloatComponent(float component) {\n"
" return (component == 0.2 || component == 0.0);\n"
"}\n"
"" // The last component is additionally allowed to be 1.0.\n"
"bool testLastFloatComponent(float component) {\n"
" return testFloatComponent(component) || component == 1.0;\n"
"}\n"
"\n"
"void main() {\n"
" if (testFloatComponent(vecRandom.x) &&\n"
" testFloatComponent(vecRandom.y) &&\n"
" testFloatComponent(vecRandom.z) &&\n"
" testLastFloatComponent(vecRandom.w)) {\n"
" v_color = vec4(0.0, 1.0, 0.0, 1.0); // green -- We're good\n"
" } else {\n"
" v_color = vec4(1.0, 0.0, 0.0, 1.0); // red -- Unexpected value\n"
" }\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n";
constexpr char simpleVertexColorFragmentShader[] =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_FragColor = v_color;\n"
"}";
// Setup the verification program.
ANGLE_GL_PROGRAM(program, vsCheckOutOfBounds, simpleVertexColorFragmentShader);
glUseProgram(program);
GLint kPosLoc = glGetAttribLocation(program, "position");
ASSERT_NE(kPosLoc, -1);
GLint kRandomLoc = glGetAttribLocation(program, "vecRandom");
ASSERT_NE(kRandomLoc, -1);
// Create a buffer of 200 valid sets of quad lists.
constexpr size_t numberOfQuads = 200;
// Create a vertex buffer with 200 properly formed triangle quads. These quads will cover the
// canvas texture such that every single pixel is touched by the fragment shader.
GLBuffer glQuadBuffer;
glBindBuffer(GL_ARRAY_BUFFER, glQuadBuffer);
std::array<float, numberOfQuads * 2 * 6> quadPositions;
for (unsigned int i = 0; i < quadPositions.size(); i += 2 * 6)
{
quadPositions[i + 0] = -1.0; // upper left
quadPositions[i + 1] = 1.0;
quadPositions[i + 2] = 1.0; // upper right
quadPositions[i + 3] = 1.0;
quadPositions[i + 4] = -1.0; // lower left
quadPositions[i + 5] = -1.0;
quadPositions[i + 6] = 1.0; // upper right
quadPositions[i + 7] = 1.0;
quadPositions[i + 8] = 1.0; // lower right
quadPositions[i + 9] = -1.0;
quadPositions[i + 10] = -1.0; // lower left
quadPositions[i + 11] = -1.0;
}
glBufferData(GL_ARRAY_BUFFER, quadPositions.size() * sizeof(float), quadPositions.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(kPosLoc);
glVertexAttribPointer(kPosLoc, 2, GL_FLOAT, false, 0, 0);
// Create a small vertex buffer with determined-ahead-of-time "random" values (0.2). This buffer
// will be the one read past the end.
GLBuffer glVertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, glVertexBuffer);
std::array<float, 6> vertexData = {0.2, 0.2, 0.2, 0.2, 0.2, 0.2};
glBufferData(GL_ARRAY_BUFFER, vertexData.size() * sizeof(float), vertexData.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(kRandomLoc);
glVertexAttribPointer(kRandomLoc, 4, GL_FLOAT, false, 0, 0);
// Test -- Draw off the end of the vertex buffer near the beginning of the out of bounds area.
DrawAndVerifyOutOfBoundsArrays(/*first*/ 6, /*count*/ 6);
// Test -- Draw off the end of the vertex buffer near the end of the out of bounds area.
DrawAndVerifyOutOfBoundsArrays(/*first*/ (numberOfQuads - 1) * 6, /*count*/ 6);
}
// Regression test for glBufferData with slightly increased size. Implementation may decided to
// reuse the buffer storage if underline storage is big enough (due to alignment, implementation may
// allocate more storage than data size.) This tests ensure it works correctly when this reuse
// happens.
TEST_P(RobustBufferAccessBehaviorTest, BufferDataWithIncreasedSize)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
// Clear to red and draw one triangle on the bottom left with green. The right top half should
// be red.
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
std::array<float, 2 * 3> quadVertices = {-1, 1, -1, -1, 1, -1};
constexpr size_t kBufferSize = sizeof(quadVertices[0]) * quadVertices.size();
GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, kBufferSize, quadVertices.data(), GL_STATIC_DRAW);
glUseProgram(drawGreen);
const GLint positionLocation = glGetAttribLocation(drawGreen, essl1_shaders::PositionAttrib());
ASSERT_NE(-1, positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
EXPECT_GL_NO_ERROR();
// Clear to blue and call glBufferData with two triangles and draw the entire window with green.
// Both bottom left and top right should be green.
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
std::array<float, 2 * 3 * 2> twoQuadVertices = {-1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1};
glBufferData(GL_ARRAY_BUFFER, kBufferSize * 2, twoQuadVertices.data(), GL_STATIC_DRAW);
glUseProgram(drawGreen);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
EXPECT_GL_NO_ERROR();
}
// Similar to BufferDataWithIncreasedSize. But this time the buffer is bound to two VAOs. The change
// in the buffer should be picked up by both VAOs.
TEST_P(RobustBufferAccessBehaviorTest, BufferDataWithIncreasedSizeAndUseWithVAOs)
{
ANGLE_SKIP_TEST_IF(!initExtension());
ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
// Clear to red and draw one triangle with VAO1 on the bottom left with green. The right top
// half should be red.
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
std::array<float, 2 * 3> quadVertices = {-1, 1, -1, -1, 1, -1};
constexpr size_t kBufferSize = sizeof(quadVertices[0]) * quadVertices.size();
GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, kBufferSize, quadVertices.data(), GL_STATIC_DRAW);
glUseProgram(drawGreen);
const GLint positionLocation = glGetAttribLocation(drawGreen, essl1_shaders::PositionAttrib());
ASSERT_NE(-1, positionLocation);
GLVertexArray vao1;
glBindVertexArray(vao1);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::red);
EXPECT_GL_NO_ERROR();
// Now use the same buffer on VAO2
GLVertexArray vao2;
glBindVertexArray(vao2);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
// Clear to blue and call glBufferData with two triangles and draw the entire window with green.
// Both bottom left and top right should be green.
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
std::array<float, 2 * 3 * 2> twoQuadVertices = {-1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1};
glBufferData(GL_ARRAY_BUFFER, kBufferSize * 2, twoQuadVertices.data(), GL_STATIC_DRAW);
glUseProgram(drawGreen);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 6);
EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
EXPECT_GL_NO_ERROR();
// Buffer's change should be piked by VAO1 as well. If not, then we should get validation error.
glBindVertexArray(vao1);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(2, 2, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() - 1, getWindowHeight() - 1, GLColor::green);
EXPECT_GL_NO_ERROR();
}
// Prepare an element array buffer that indexes out-of-bounds beginning with the start index passed
// in. Ensure that drawElements flags either no error or INVALID_OPERATION. In the case of
// INVALID_OPERATION, no canvas pixels can be touched. In the case of NO_ERROR, all written values
// must either be the zero vertex or a value in the vertex buffer. See vsCheckOutOfBounds shader.
void DrawAndVerifyOutOfBoundsIndex(int startIndex)
{
glClearColor(0.0, 0.0, 1.0, 1.0); // Start with blue to indicate no pixels touched.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Create an element array buffer with a tri-strip that starts at startIndex and make
// it the active element array buffer.
GLBuffer glElementArrayBuffer;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glElementArrayBuffer);
std::array<uint16_t, 4> quadIndices;
for (unsigned int i = 0; i < quadIndices.size(); i++)
{
quadIndices[i] = startIndex + i;
}
glBufferData(GL_ELEMENT_ARRAY_BUFFER, quadIndices.size() * sizeof(uint16_t), quadIndices.data(),
GL_STATIC_DRAW);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, /*offset*/ 0);
GLenum error = glGetError();
if (error == GL_INVALID_OPERATION)
{
// testPassed. drawElements flagged INVALID_OPERATION, which is valid so long as all canvas
// pixels were not touched.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
}
else
{
ASSERT_GL_NO_ERROR();
// testPassed. drawElements flagged NO_ERROR, which is valid so long as all canvas pixels
// are green.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
}
// Adapted from WebGL test
// conformance/rendering/out-of-bounds-index-buffers.html
// This test verifies that out-of-bounds index buffers behave according to spec.
TEST_P(RobustBufferAccessBehaviorTest, OutOfBoundsIndexBuffers)
{
ANGLE_SKIP_TEST_IF(!initExtension());
constexpr char vsCheckOutOfBounds[] =
"precision mediump float;\n"
"attribute vec2 position;\n"
"attribute vec4 vecRandom;\n"
"varying vec4 v_color;\n"
"\n"
"// Per the spec, each component can either contain existing contents\n"
"// of the buffer or 0.\n"
"bool testFloatComponent(float component) {\n"
" return (component == 0.2 || component == 0.0);\n"
"}\n"
"" // The last component is additionally allowed to be 1.0.\n"
"bool testLastFloatComponent(float component) {\n"
" return testFloatComponent(component) || component == 1.0;\n"
"}\n"
"\n"
"void main() {\n"
" if (testFloatComponent(vecRandom.x) &&\n"
" testFloatComponent(vecRandom.y) &&\n"
" testFloatComponent(vecRandom.z) &&\n"
" testLastFloatComponent(vecRandom.w)) {\n"
" v_color = vec4(0.0, 1.0, 0.0, 1.0); // green -- We're good\n"
" } else {\n"
" v_color = vec4(1.0, 0.0, 0.0, 1.0); // red -- Unexpected value\n"
" }\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n";
constexpr char simpleVertexColorFragmentShader[] =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_FragColor = v_color;\n"
"}";
// Setup the verification program.
ANGLE_GL_PROGRAM(program, vsCheckOutOfBounds, simpleVertexColorFragmentShader);
glUseProgram(program);
GLint kPosLoc = glGetAttribLocation(program, "position");
ASSERT_NE(kPosLoc, -1);
GLint kRandomLoc = glGetAttribLocation(program, "vecRandom");
ASSERT_NE(kRandomLoc, -1);
// Create a buffer of 200 valid sets of quad lists.
constexpr size_t numberOfQuads = 200;
// Create a vertex buffer with 200 properly formed tri-strip quads. These quads will cover the
// canvas texture such that every single pixel is touched by the fragment shader.
GLBuffer glQuadBuffer;
glBindBuffer(GL_ARRAY_BUFFER, glQuadBuffer);
std::array<float, numberOfQuads * 2 * 4> quadPositions;
for (unsigned int i = 0; i < quadPositions.size(); i += 2 * 4)
{
quadPositions[i + 0] = -1.0; // upper left
quadPositions[i + 1] = 1.0;
quadPositions[i + 2] = 1.0; // upper right
quadPositions[i + 3] = 1.0;
quadPositions[i + 4] = -1.0; // lower left
quadPositions[i + 5] = -1.0;
quadPositions[i + 6] = 1.0; // lower right
quadPositions[i + 7] = -1.0;
}
glBufferData(GL_ARRAY_BUFFER, quadPositions.size() * sizeof(float), quadPositions.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(kPosLoc);
glVertexAttribPointer(kPosLoc, 2, GL_FLOAT, false, 0, 0);
// Create a small vertex buffer with determined-ahead-of-time "random" values (0.2). This buffer
// will be the one indexed off the end.
GLBuffer glVertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, glVertexBuffer);
std::array<float, 4> vertexData = {0.2, 0.2, 0.2, 0.2};
glBufferData(GL_ARRAY_BUFFER, vertexData.size() * sizeof(float), vertexData.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(kRandomLoc);
glVertexAttribPointer(kRandomLoc, 4, GL_FLOAT, false, 0, 0);
// Test -- Index off the end of the vertex buffer near the beginning of the out of bounds area.
DrawAndVerifyOutOfBoundsIndex(/*StartIndex*/ 4);
// Test -- Index off the end of the vertex buffer near the end of the out of bounds area.
DrawAndVerifyOutOfBoundsIndex(/*StartIndex*/ numberOfQuads - 4);
}
ANGLE_INSTANTIATE_TEST(RobustBufferAccessBehaviorTest,
WithNoFixture(ES3_VULKAN()),
WithNoFixture(ES3_OPENGL()),
WithNoFixture(ES3_OPENGLES()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES3_METAL()));
} // namespace