Hash :
0d671c9a
Author :
Date :
2017-08-10T16:41:52
Verify occlusion query correctness in a multi-view context The patch adds tests to verify that an occlusion query correctly tracks whether any fragments pass the depth test for any of the views as according to the ANGLE_multiview extension. BUG=angleproject:2062 TEST=angle_end2end_tests Change-Id: Ia85bac4935192554a337c27fad110fbb7f56cf8a Reviewed-on: https://chromium-review.googlesource.com/609961 Commit-Queue: Martin Radev <mradev@nvidia.com> Reviewed-by: Geoff Lang <geofflang@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
//
// 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.
//
// Multiview draw tests:
// Test issuing multiview Draw* commands.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
class MultiviewDrawTest : public ANGLETest
{
protected:
MultiviewDrawTest()
{
setWindowWidth(128);
setWindowHeight(128);
setWebGLCompatibilityEnabled(true);
}
virtual ~MultiviewDrawTest() {}
void SetUp() override
{
ANGLETest::SetUp();
glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
eglGetProcAddress("glRequestExtensionANGLE"));
}
// Requests the ANGLE_multiview extension and returns true if the operation succeeds.
bool requestMultiviewExtension()
{
if (extensionRequestable("GL_ANGLE_multiview"))
{
glRequestExtensionANGLE("GL_ANGLE_multiview");
}
if (!extensionEnabled("GL_ANGLE_multiview"))
{
std::cout << "Test skipped due to missing GL_ANGLE_multiview." << std::endl;
return false;
}
return true;
}
PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
};
class MultiviewDrawValidationTest : public MultiviewDrawTest
{
protected:
MultiviewDrawValidationTest() {}
void SetUp() override
{
MultiviewDrawTest::SetUp();
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
glBindTexture(GL_TEXTURE_2D, mTex2d);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glBindVertexArray(mVao);
const float kVertexData[3] = {0.0f};
glBindBuffer(GL_ARRAY_BUFFER, mVbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3u, &kVertexData[0], GL_STATIC_DRAW);
const unsigned int kIndices[3] = {0u, 1u, 2u};
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 3, &kIndices[0],
GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
}
GLTexture mTex2d;
GLVertexArray mVao;
GLBuffer mVbo;
GLBuffer mIbo;
GLFramebuffer mFramebuffer;
};
class MultiviewSideBySideRenderTest : public MultiviewDrawTest
{
protected:
void createFBO(int width, int height, int numViews)
{
// Assert that width is a multiple of numViews.
ASSERT_TRUE(width % numViews == 0);
const int widthPerView = width / numViews;
// Create color and depth textures.
glBindTexture(GL_TEXTURE_2D, mColorTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
glBindTexture(GL_TEXTURE_2D, mDepthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0, GL_DEPTH_COMPONENT,
GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
ASSERT_GL_NO_ERROR();
// Create draw framebuffer to be used for side-by-side rendering.
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFramebuffer);
std::vector<GLint> viewportOffsets(numViews * 2u);
for (int i = 0u; i < numViews; ++i)
{
viewportOffsets[i * 2] = i * widthPerView;
viewportOffsets[i * 2 + 1] = 0;
}
glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
mColorTexture, 0, numViews,
&viewportOffsets[0]);
glFramebufferTextureMultiviewSideBySideANGLE(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
mDepthTexture, 0, numViews,
&viewportOffsets[0]);
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers);
ASSERT_GL_NO_ERROR();
ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER));
// Create read framebuffer to be used to retrieve the pixel information for testing
// purposes.
glBindFramebuffer(GL_READ_FRAMEBUFFER, mReadFramebuffer);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
mColorTexture, 0);
ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_READ_FRAMEBUFFER));
// Clear the buffers.
glViewport(0, 0, width, height);
glScissor(0, 0, width, height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set viewport and scissor of each view.
glViewport(0, 0, widthPerView, height);
glScissor(0, 0, widthPerView, height);
}
GLTexture mColorTexture;
GLTexture mDepthTexture;
GLFramebuffer mDrawFramebuffer;
GLFramebuffer mReadFramebuffer;
};
class MultiviewSideBySideRenderDualViewTest : public MultiviewSideBySideRenderTest
{
protected:
MultiviewSideBySideRenderDualViewTest() : mProgram(0u) {}
~MultiviewSideBySideRenderDualViewTest()
{
if (mProgram != 0u)
{
glDeleteProgram(mProgram);
}
}
void SetUp() override
{
MultiviewSideBySideRenderTest::SetUp();
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec4 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position.x = (gl_ViewID_OVR == 0u ? vPosition.x*0.5 + 0.5 : vPosition.x*0.5);\n"
" gl_Position.yzw = vPosition.yzw;\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
createFBO(4, 1, 2);
createProgram(vsSource, fsSource);
}
void createProgram(const std::string &vs, const std::string &fs)
{
mProgram = CompileProgram(vs, fs);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
glUseProgram(mProgram);
ASSERT_GL_NO_ERROR();
}
void checkOutput()
{
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 0);
EXPECT_PIXEL_EQ(1, 0, 255, 0, 0, 0);
EXPECT_PIXEL_EQ(2, 0, 255, 0, 0, 0);
EXPECT_PIXEL_EQ(3, 0, 0, 0, 0, 0);
}
GLuint mProgram;
};
class MultiviewSideBySideOcclusionQueryTest : public MultiviewSideBySideRenderTest
{
protected:
MultiviewSideBySideOcclusionQueryTest() {}
GLuint drawAndRetrieveOcclusionQueryResult(GLuint program)
{
GLuint query;
glGenQueries(1, &query);
glBeginQuery(GL_ANY_SAMPLES_PASSED, query);
drawQuad(program, "vPosition", 0.0f, 1.0f, true);
glEndQueryEXT(GL_ANY_SAMPLES_PASSED);
GLuint result = GL_TRUE;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &result);
return result;
}
};
// The test verifies that glDraw*Indirect:
// 1) generates an INVALID_OPERATION error if the number of views in the draw framebuffer is greater
// than 1.
// 2) does not generate any error if the draw framebuffer has exactly 1 view.
TEST_P(MultiviewDrawValidationTest, IndirectDraw)
{
if (!requestMultiviewExtension())
{
return;
}
const GLint viewportOffsets[4] = {0, 0, 2, 0};
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"void main()\n"
"{}\n";
GLBuffer commandBuffer;
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, commandBuffer);
const GLuint commandData[] = {1u, 1u, 0u, 0u, 0u};
glBufferData(GL_DRAW_INDIRECT_BUFFER, sizeof(GLuint) * 5u, &commandData[0], GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
// Check for a GL_INVALID_OPERATION error with the framebuffer having 2 views.
{
const std::string &vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 2, &viewportOffsets[0]);
glDrawArraysIndirect(GL_TRIANGLES, nullptr);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Check that no errors are generated if the number of views is 1.
{
const std::string &vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 1) in;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 1, &viewportOffsets[0]);
glDrawArraysIndirect(GL_TRIANGLES, nullptr);
EXPECT_GL_NO_ERROR();
glDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, nullptr);
EXPECT_GL_NO_ERROR();
}
}
// The test verifies that glDraw*:
// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer and
// program differs.
// 2) does not generate any error if the number of views is the same.
// 3) does not generate any error if the program does not use the multiview extension.
TEST_P(MultiviewDrawValidationTest, NumViewsMismatch)
{
if (!requestMultiviewExtension())
{
return;
}
const GLint viewportOffsets[4] = {0, 0, 2, 0};
const std::string &vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{}\n";
const std::string &fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
// Check for a GL_INVALID_OPERATION error with the framebuffer and program having different
// number of views.
{
// The framebuffer has only 1 view.
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 1, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Check that no errors are generated if the number of views in both program and draw
// framebuffer matches.
{
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 2, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
EXPECT_GL_NO_ERROR();
}
// Check that no errors are generated if the program does not use the multiview extension.
{
const std::string &vsSourceNoMultiview =
"#version 300 es\n"
"void main()\n"
"{}\n";
const std::string &fsSourceNoMultiview =
"#version 300 es\n"
"precision mediump float;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(programNoMultiview, vsSourceNoMultiview, fsSourceNoMultiview);
glUseProgram(programNoMultiview);
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 2, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, nullptr);
EXPECT_GL_NO_ERROR();
}
}
// The test verifies that glDraw*:
// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer is
// greater than 1 and there is an active transform feedback object.
// 2) does not generate any error if the number of views in the draw framebuffer is 1.
TEST_P(MultiviewDrawValidationTest, ActiveTransformFeedback)
{
if (!requestMultiviewExtension())
{
return;
}
const GLint viewportOffsets[4] = {0, 0, 2, 0};
const std::string &vsSource =
"#version 300 es\n"
"void main()\n"
"{}\n";
const std::string &fsSource =
"#version 300 es\n"
"precision mediump float;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
GLBuffer tbo;
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tbo);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(float) * 4u, nullptr, GL_STATIC_DRAW);
GLTransformFeedback transformFeedback;
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, transformFeedback);
glBeginTransformFeedback(GL_TRIANGLES);
ASSERT_GL_NO_ERROR();
// Check that drawArrays generates an error when there is an active transform feedback object
// and the number of views in the draw framebuffer is greater than 1.
{
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 2, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Check that drawArrays does not generate an error when the number of views in the draw
// framebuffer is 1.
{
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 1, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
}
glEndTransformFeedback();
}
// The test verifies that glDraw*:
// 1) generates an INVALID_OPERATION error if the number of views in the active draw framebuffer is
// greater than 1 and there is an active query for target GL_TIME_ELAPSED_EXT.
// 2) does not generate any error if the number of views in the draw framebuffer is 1.
TEST_P(MultiviewDrawValidationTest, ActiveTimeElapsedQuery)
{
if (!requestMultiviewExtension())
{
return;
}
if (!extensionEnabled("GL_EXT_disjoint_timer_query"))
{
std::cout << "Test skipped because GL_EXT_disjoint_timer_query is not available."
<< std::endl;
return;
}
const GLint viewportOffsets[4] = {0, 0, 2, 0};
const std::string &vsSource =
"#version 300 es\n"
"void main()\n"
"{}\n";
const std::string &fsSource =
"#version 300 es\n"
"precision mediump float;\n"
"void main()\n"
"{}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
GLuint query = 0u;
glGenQueriesEXT(1, &query);
glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query);
// Check first case.
{
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 2, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Check second case.
{
glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mTex2d,
0, 1, &viewportOffsets[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_GL_NO_ERROR();
}
glEndQueryEXT(GL_TIME_ELAPSED_EXT);
glDeleteQueries(1, &query);
}
// The test checks that glDrawArrays can be used to render into two views.
TEST_P(MultiviewSideBySideRenderDualViewTest, DrawArrays)
{
if (!requestMultiviewExtension())
{
return;
}
drawQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
checkOutput();
}
// The test checks that glDrawElements can be used to render into two views.
TEST_P(MultiviewSideBySideRenderDualViewTest, DrawElements)
{
if (!requestMultiviewExtension())
{
return;
}
drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
checkOutput();
}
// The test checks that glDrawRangeElements can be used to render into two views.
TEST_P(MultiviewSideBySideRenderDualViewTest, DrawRangeElements)
{
if (!requestMultiviewExtension())
{
return;
}
drawIndexedQuad(mProgram, "vPosition", 0.0f, 1.0f, true, true);
ASSERT_GL_NO_ERROR();
checkOutput();
}
// The test checks that glDrawArrays can be used to render into four views.
TEST_P(MultiviewSideBySideRenderTest, DrawArraysFourViews)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 4) in;\n"
"in vec4 vPosition;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u) {\n"
" gl_Position.x = vPosition.x*0.25 - 0.75;\n"
" } else if (gl_ViewID_OVR == 1u) {\n"
" gl_Position.x = vPosition.x*0.25 - 0.25;\n"
" } else if (gl_ViewID_OVR == 2u) {\n"
" gl_Position.x = vPosition.x*0.25 + 0.25;\n"
" } else {\n"
" gl_Position.x = vPosition.x*0.25 + 0.75;\n"
" }"
" gl_Position.yzw = vPosition.yzw;\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
createFBO(16, 1, 4);
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
drawQuad(program, "vPosition", 0.0f, 1.0f, true);
ASSERT_GL_NO_ERROR();
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
const int arrayIndex = i * 4 + j;
if (i == j)
{
EXPECT_PIXEL_EQ(arrayIndex, 0, 255, 0, 0, 0);
}
else
{
EXPECT_PIXEL_EQ(arrayIndex, 0, 0, 0, 0, 0);
}
}
}
EXPECT_GL_NO_ERROR();
}
// The test checks that glDrawArraysInstanced can be used to render into two views.
TEST_P(MultiviewSideBySideRenderTest, DrawArraysInstanced)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec4 vPosition;\n"
"void main()\n"
"{\n"
" vec4 p = vPosition;\n"
" if (gl_InstanceID == 1){\n"
" p.y = .5*p.y + .5;\n"
" } else {\n"
" p.y = p.y*.5;\n"
" }\n"
" gl_Position.x = (gl_ViewID_OVR == 0u ? p.x*0.5 + 0.5 : p.x*0.5);\n"
" gl_Position.yzw = p.yzw;\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
createFBO(4, 2, 2);
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
drawQuad(program, "vPosition", 0.0f, 1.0f, true, true, 2);
ASSERT_GL_NO_ERROR();
const GLubyte expectedResult[4][8] = {
{0, 255, 255, 0}, {0, 255, 255, 0},
};
for (int row = 0; row < 2; ++row)
{
for (int col = 0; col < 4; ++col)
{
EXPECT_PIXEL_EQ(col, row, expectedResult[row][col], 0, 0, 0);
}
}
}
// The test verifies that the attribute divisor is correctly adjusted when drawing with a multi-view
// program. The test draws 4 instances of a quad each of which covers a single pixel. The x and y
// offset of each quad are passed as separate attributes which are indexed based on the
// corresponding attribute divisors. A divisor of 1 is used for the y offset to have all quads
// drawn vertically next to each other. A divisor of 3 is used for the x offset to have the last
// quad offsetted by one pixel to the right. Note that the number of views is divisible by 1, but
// not by 3.
TEST_P(MultiviewSideBySideRenderTest, AttribDivisor)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string &vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"in float offsetX;\n"
"in float offsetY;\n"
"void main()\n"
"{\n"
" vec4 p = vec4(vPosition, 1.);\n"
" p.xy = p.xy * 0.25 - 0.75 + vec2(offsetX, offsetY);\n"
" gl_Position.x = (gl_ViewID_OVR == 0u ? p.x : p.x + 1.0);\n"
" gl_Position.yzw = p.yzw;\n"
"}\n";
const std::string &fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
createFBO(8, 4, 2);
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
GLBuffer xOffsetVBO;
glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
const GLfloat xOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.0f};
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, xOffsetData, GL_STATIC_DRAW);
GLint xOffsetLoc = glGetAttribLocation(program, "offsetX");
glVertexAttribPointer(xOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribDivisor(xOffsetLoc, 3);
glEnableVertexAttribArray(xOffsetLoc);
GLBuffer yOffsetVBO;
glBindBuffer(GL_ARRAY_BUFFER, yOffsetVBO);
const GLfloat yOffsetData[4] = {0.0f, 0.5f, 1.0f, 1.5f};
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4, yOffsetData, GL_STATIC_DRAW);
GLint yOffsetLoc = glGetAttribLocation(program, "offsetY");
glVertexAttribDivisor(yOffsetLoc, 1);
glVertexAttribPointer(yOffsetLoc, 1, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(yOffsetLoc);
drawQuad(program, "vPosition", 0.0f, 1.0f, true, true, 4);
ASSERT_GL_NO_ERROR();
const GLubyte expectedRedChannel[4][8] = {{255, 0, 0, 0, 0, 0, 255, 0},
{255, 0, 0, 0, 0, 0, 255, 0},
{255, 0, 0, 0, 0, 0, 255, 0},
{0, 255, 0, 0, 0, 0, 0, 255}};
for (int row = 0; row < 4; ++row)
{
for (int col = 0; col < 8; ++col)
{
EXPECT_PIXEL_EQ(col, row, expectedRedChannel[row][col], 0, 0, 0);
}
}
}
// Test that different sequences of vertexAttribDivisor, useProgram and bindVertexArray in a
// multi-view context propagate the correct divisor to the driver.
TEST_P(MultiviewSideBySideRenderTest, DivisorOrderOfOperation)
{
if (!requestMultiviewExtension())
{
return;
}
createFBO(2, 1, 2);
// Create multiview program.
const std::string &vs =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"layout(location = 0) in vec2 vPosition;\n"
"layout(location = 1) in float offsetX;\n"
"void main()\n"
"{\n"
" vec4 p = vec4(vPosition, 0.0, 1.0);\n"
" p.x += offsetX;\n"
" gl_Position = p;\n"
"}\n";
const std::string &fs =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vs, fs);
const std::string &dummyVS =
"#version 300 es\n"
"layout(location = 0) in vec2 vPosition;\n"
"layout(location = 1) in float offsetX;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(vPosition, 0.0, 1.0);\n"
"}\n";
const std::string &dummyFS =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(0,0,0,0);\n"
"}\n";
ANGLE_GL_PROGRAM(dummyProgram, dummyVS, dummyFS);
GLBuffer xOffsetVBO;
glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
const GLfloat xOffsetData[12] = {0.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f,
4.0f, 4.0f, 4.0f, 4.0f, 4.0f, 4.0f};
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 12, xOffsetData, GL_STATIC_DRAW);
GLBuffer vertexVBO;
glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
Vector2 kQuadVertices[6] = {Vector2(-1.f, -1.f), Vector2(1.f, -1.f), Vector2(1.f, 1.f),
Vector2(-1.f, -1.f), Vector2(1.f, 1.f), Vector2(-1.f, 1.f)};
glBufferData(GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
GLVertexArray vao[2];
for (size_t i = 0u; i < 2u; ++i)
{
glBindVertexArray(vao[i]);
glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO);
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);
}
ASSERT_GL_NO_ERROR();
glViewport(0, 0, 1, 1);
glScissor(0, 0, 1, 1);
glClearColor(0, 0, 0, 0);
// Clear the buffers, propagate divisor to the driver, bind the vao and keep it active.
// It is necessary to call draw, so that the divisor is propagated and to guarantee that dirty
// bits are cleared.
glUseProgram(dummyProgram);
glBindVertexArray(vao[0]);
glVertexAttribDivisor(1, 0);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
glUseProgram(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
// Check that vertexAttribDivisor uses the number of views to update the divisor.
glUseProgram(program);
glVertexAttribDivisor(1, 1);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 0);
EXPECT_PIXEL_EQ(1, 0, 255, 0, 0, 0);
// Clear the buffers and propagate divisor to the driver.
// We keep the vao active and propagate the divisor to guarantee that there are no unresolved
// dirty bits when useProgram is called.
glUseProgram(dummyProgram);
glVertexAttribDivisor(1, 1);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
glUseProgram(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
// Check that useProgram uses the number of views to update the divisor.
glUseProgram(program);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 0);
EXPECT_PIXEL_EQ(1, 0, 255, 0, 0, 0);
// We go through similar steps as before.
glUseProgram(dummyProgram);
glVertexAttribDivisor(1, 1);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
glUseProgram(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
// Check that bindVertexArray uses the number of views to update the divisor.
{
// Call useProgram with vao[1] being active to guarantee that useProgram will adjust the
// divisor for vao[1] only.
glBindVertexArray(vao[1]);
glUseProgram(program);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(0);
ASSERT_GL_NO_ERROR();
}
// Bind vao[0] after useProgram is called to ensure that bindVertexArray is the call which
// adjusts the divisor.
glBindVertexArray(vao[0]);
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, 1);
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 0);
EXPECT_PIXEL_EQ(1, 0, 255, 0, 0, 0);
}
// Test that no fragments pass the occlusion query for a multi-view vertex shader which always
// transforms geometry to be outside of the clip region.
TEST_P(MultiviewSideBySideOcclusionQueryTest, OcclusionQueryNothingVisible)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position.x = 2.0;\n"
" gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
createFBO(2, 1, 2);
GLuint result = drawAndRetrieveOcclusionQueryResult(program);
ASSERT_GL_NO_ERROR();
EXPECT_GL_FALSE(result);
}
// Test that there are fragments passing the occlusion query if only view 0 can produce
// output.
TEST_P(MultiviewSideBySideOcclusionQueryTest, OcclusionQueryOnlyLeftVisible)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 0u ? vPosition.x : 2.0;\n"
" gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
createFBO(2, 1, 2);
GLuint result = drawAndRetrieveOcclusionQueryResult(program);
ASSERT_GL_NO_ERROR();
EXPECT_GL_TRUE(result);
}
// Test that there are fragments passing the occlusion query if only view 1 can produce
// output.
TEST_P(MultiviewSideBySideOcclusionQueryTest, OcclusionQueryOnlyRightVisible)
{
if (!requestMultiviewExtension())
{
return;
}
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 1u ? vPosition.x : 2.0;\n"
" gl_Position.yzw = vec3(vPosition.yz, 1.);\n"
"}\n";
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
"{\n"
" col = vec4(1,0,0,0);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vsSource, fsSource);
glUseProgram(program);
createFBO(2, 1, 2);
GLuint result = drawAndRetrieveOcclusionQueryResult(program);
ASSERT_GL_NO_ERROR();
EXPECT_GL_TRUE(result);
}
ANGLE_INSTANTIATE_TEST(MultiviewDrawValidationTest, ES31_OPENGL());
ANGLE_INSTANTIATE_TEST(MultiviewSideBySideRenderDualViewTest, ES3_OPENGL());
ANGLE_INSTANTIATE_TEST(MultiviewSideBySideRenderTest, ES3_OPENGL());
ANGLE_INSTANTIATE_TEST(MultiviewSideBySideOcclusionQueryTest, ES3_OPENGL());