Hash :
b57d5638
Author :
Date :
2023-06-29T00:00:00
Reland "Cleanup multiview support" This is a reland of commit 9a7c0b88ba68e328d3f5f7991a6df0ab5de92311 Original change's description: > Cleanup multiview support > > * Removed remaining mentions of ANGLE_multiview > > * Removed AST transformations used only in > the side-by-side multiview implementation > > * Changed the type of the internal ViewID_OVR > variable to use the dedicated qualifier > > * Removed side-by-side multiview support > from the D3D11 renderer > > * Removed an unused helper for side-by-side > multiview support from the OpenGL renderer > > * Removed obsoleted test suppressions Fixed: angleproject:3341 Change-Id: I3ce9304c79c0873462c73e8cf02b85f7a1aaf874 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4669604 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.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
//
// Copyright 2016 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.
//
// OVR_multiview2_test.cpp:
// Test that shaders with gl_ViewID_OVR are validated correctly.
//
#include "GLSLANG/ShaderLang.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
namespace
{
class SymbolOccurrenceCounter : public TIntermTraverser
{
public:
SymbolOccurrenceCounter() : TIntermTraverser(true, false, false), mNumberOfOccurrences(0u) {}
void visitSymbol(TIntermSymbol *node) override
{
if (shouldCountSymbol(node))
{
++mNumberOfOccurrences;
}
}
virtual bool shouldCountSymbol(const TIntermSymbol *node) const = 0;
unsigned getNumberOfOccurrences() const { return mNumberOfOccurrences; }
private:
unsigned mNumberOfOccurrences;
};
class SymbolOccurrenceCounterByQualifier : public SymbolOccurrenceCounter
{
public:
SymbolOccurrenceCounterByQualifier(TQualifier symbolQualifier)
: mSymbolQualifier(symbolQualifier)
{}
bool shouldCountSymbol(const TIntermSymbol *node) const override
{
return node->getQualifier() == mSymbolQualifier;
}
private:
TQualifier mSymbolQualifier;
};
class SymbolOccurrenceCounterByName : public SymbolOccurrenceCounter
{
public:
SymbolOccurrenceCounterByName(const ImmutableString &symbolName) : mSymbolName(symbolName) {}
bool shouldCountSymbol(const TIntermSymbol *node) const override
{
return node->variable().symbolType() != SymbolType::Empty && node->getName() == mSymbolName;
}
private:
ImmutableString mSymbolName;
};
class SymbolOccurrenceCounterByNameAndQualifier : public SymbolOccurrenceCounter
{
public:
SymbolOccurrenceCounterByNameAndQualifier(const ImmutableString &symbolName,
TQualifier qualifier)
: mSymbolName(symbolName), mSymbolQualifier(qualifier)
{}
bool shouldCountSymbol(const TIntermSymbol *node) const override
{
return node->variable().symbolType() != SymbolType::Empty &&
node->getName() == mSymbolName && node->getQualifier() == mSymbolQualifier;
}
private:
ImmutableString mSymbolName;
TQualifier mSymbolQualifier;
};
class OVRMultiview2VertexShaderTest : public ShaderCompileTreeTest
{
public:
OVRMultiview2VertexShaderTest() {}
protected:
::GLenum getShaderType() const override { return GL_VERTEX_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL3_SPEC; }
void initResources(ShBuiltInResources *resources) override
{
resources->OVR_multiview = 1;
resources->OVR_multiview2 = 1;
resources->MaxViewsOVR = 4;
}
};
class OVRMultiview2FragmentShaderTest : public ShaderCompileTreeTest
{
public:
OVRMultiview2FragmentShaderTest() {}
protected:
::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
ShShaderSpec getShaderSpec() const override { return SH_WEBGL3_SPEC; }
void initResources(ShBuiltInResources *resources) override
{
resources->OVR_multiview = 1;
resources->OVR_multiview2 = 1;
resources->MaxViewsOVR = 4;
}
};
class OVRMultiview2OutputCodeTest : public MatchOutputCodeTest
{
public:
OVRMultiview2OutputCodeTest(sh::GLenum shaderType)
: MatchOutputCodeTest(shaderType, SH_ESSL_OUTPUT), mMultiviewCompileOptions{}
{
addOutputType(SH_GLSL_COMPATIBILITY_OUTPUT);
getResources()->OVR_multiview = 1;
getResources()->OVR_multiview2 = 1;
getResources()->MaxViewsOVR = 4;
mMultiviewCompileOptions.initializeBuiltinsForInstancedMultiview = true;
mMultiviewCompileOptions.selectViewInNvGLSLVertexShader = true;
}
void requestHLSLOutput()
{
#if defined(ANGLE_ENABLE_HLSL)
addOutputType(SH_HLSL_4_1_OUTPUT);
#endif
}
bool foundInAllGLSLCode(const char *str)
{
return foundInGLSLCode(str) && foundInESSLCode(str);
}
bool foundInHLSLCode(const char *stringToFind) const
{
#if defined(ANGLE_ENABLE_HLSL)
return foundInCode(SH_HLSL_4_1_OUTPUT, stringToFind);
#else
return true;
#endif
}
protected:
ShCompileOptions mMultiviewCompileOptions;
};
class OVRMultiview2VertexShaderOutputCodeTest : public OVRMultiview2OutputCodeTest
{
public:
OVRMultiview2VertexShaderOutputCodeTest() : OVRMultiview2OutputCodeTest(GL_VERTEX_SHADER) {}
};
class OVRMultiview2FragmentShaderOutputCodeTest : public OVRMultiview2OutputCodeTest
{
public:
OVRMultiview2FragmentShaderOutputCodeTest() : OVRMultiview2OutputCodeTest(GL_FRAGMENT_SHADER) {}
};
class OVRMultiview2ComputeShaderOutputCodeTest : public OVRMultiview2OutputCodeTest
{
public:
OVRMultiview2ComputeShaderOutputCodeTest() : OVRMultiview2OutputCodeTest(GL_COMPUTE_SHADER) {}
};
void VariableOccursNTimes(TIntermBlock *root,
const ImmutableString &varName,
const TQualifier varQualifier,
unsigned n)
{
// Check that there are n occurrences of the variable with the given name and qualifier.
SymbolOccurrenceCounterByNameAndQualifier viewIDByNameAndQualifier(varName, varQualifier);
root->traverse(&viewIDByNameAndQualifier);
EXPECT_EQ(n, viewIDByNameAndQualifier.getNumberOfOccurrences());
// Check that there are n occurrences of the variable with the given name. By this we guarantee
// that there are no other occurrences of the variable with the same name but different
// qualifier.
SymbolOccurrenceCounterByName viewIDByName(varName);
root->traverse(&viewIDByName);
EXPECT_EQ(n, viewIDByName.getNumberOfOccurrences());
}
// Invalid combination of non-matching num_views declarations.
TEST_F(OVRMultiview2VertexShaderTest, InvalidNumViewsMismatch)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"layout(num_views = 1) in;\n"
"void main()\n"
"{\n"
" gl_Position.x = (gl_ViewID_OVR == 0u) ? 1.0 : 0.0;\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Invalid value zero for num_views.
TEST_F(OVRMultiview2VertexShaderTest, InvalidNumViewsZero)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 0) in;\n"
"void main()\n"
"{\n"
" gl_Position.x = (gl_ViewID_OVR == 0u) ? 1.0 : 0.0;\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Too large value for num_views.
TEST_F(OVRMultiview2VertexShaderTest, InvalidNumViewsGreaterThanMax)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 5) in;\n"
"void main()\n"
"{\n"
" gl_Position.x = (gl_ViewID_OVR == 0u) ? 1.0 : 0.0;\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that GL_OVR_multiview2 cannot be used in an ESSL 1.00 vertex shader.
TEST_F(OVRMultiview2VertexShaderTest, InvalidShaderVersion)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"void main()\n"
"{\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Valid use of gl_ViewID_OVR.
TEST_F(OVRMultiview2VertexShaderTest, ViewIDUsed)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"layout(num_views = 2) in; // Duplicated on purpose\n"
"in vec4 pos;\n"
"out float myOutput;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u)\n"
" {\n"
" gl_Position = pos;\n"
" myOutput = 1.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position = pos + vec4(1.0, 0.0, 0.0, 0.0);\n"
" myOutput = 2.0;\n"
" }\n"
" gl_Position += (gl_ViewID_OVR == 0u) ? 1.0 : 0.0;\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Read gl_FragCoord in a OVR_multiview2 fragment shader.
TEST_F(OVRMultiview2FragmentShaderTest, ReadOfFragCoord)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"precision highp float;\n"
"out vec4 outColor;\n"
"void main()\n"
"{\n"
" outColor = vec4(gl_FragCoord.xy, 0, 1);\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Read gl_ViewID_OVR in an OVR_multiview2 fragment shader.
TEST_F(OVRMultiview2FragmentShaderTest, ReadOfViewID)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"precision highp float;\n"
"out vec4 outColor;\n"
"void main()\n"
"{\n"
" outColor = vec4(gl_ViewID_OVR, 0, 0, 1);\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Correct use of GL_OVR_multiview2 macro.
TEST_F(OVRMultiview2VertexShaderTest, UseOfExtensionMacro)
{
const std::string &shaderString =
"#version 300 es\n"
"#ifdef GL_OVR_multiview2\n"
"#if (GL_OVR_multiview2 == 1)\n"
"void main()\n"
"{\n"
" gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
"}\n"
"#endif\n"
"#endif\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Test that gl_ViewID_OVR can't be used as an l-value.
TEST_F(OVRMultiview2VertexShaderTest, ViewIdAsLValue)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"void foo(out uint u)\n"
"{\n"
" u = 3u;\n"
"}\n"
"void main()\n"
"{\n"
" foo(gl_ViewID_OVR);\n"
" gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that compiling an ESSL 1.00 shader with multiview support fails.
TEST_F(OVRMultiview2VertexShaderTest, ESSL1Shader)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0)\n"
" {\n"
" gl_Position = vec4(-1.0, 0.0, 0.0, 1.0);\n"
" }\n"
" else\n"
" {\n"
" gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that compiling an ESSL 1.00 shader with an unsupported global layout qualifier fails.
TEST_F(OVRMultiview2VertexShaderTest, ESSL1ShaderUnsupportedGlobalLayoutQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"layout(std140) uniform;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0)\n"
" {\n"
" gl_Position = vec4(-1.0, 0.0, 0.0, 1.0);\n"
" }\n"
" else\n"
" {\n"
" gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that compiling an ESSL 1.00 vertex shader with an unsupported input storage qualifier fails.
TEST_F(OVRMultiview2VertexShaderTest, ESSL1ShaderUnsupportedInputStorageQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"in vec4 pos;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0)\n"
" {\n"
" gl_Position = vec4(-1.0, 0.0, 0.0, 1.0);\n"
" }\n"
" else\n"
" {\n"
" gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that compiling an ESSL 1.00 fragment shader with an unsupported input storage qualifier
// fails.
TEST_F(OVRMultiview2FragmentShaderTest, ESSL1ShaderUnsupportedInStorageQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"precision highp float;\n"
"in vec4 color;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0)\n"
" {\n"
" gl_FragColor = color;\n"
" }\n"
" else\n"
" {\n"
" gl_FragColor = color + vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that gl_InstanceID gets correctly replaced by InstanceID. gl_InstanceID should only be used
// twice: once to initialize ViewID_OVR and once for InstanceID. The number of occurrences of
// InstanceID in the AST should be the sum of two and the number of occurrences of gl_InstanceID
// before any renaming.
TEST_F(OVRMultiview2VertexShaderTest, GLInstanceIDIsRenamed)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"flat out int myInstance;\n"
"out float myInstanceF;\n"
"out float myInstanceF2;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 0u ? 0. : 1.;\n"
" gl_Position.yzw = vec3(0., 0., 1.);\n"
" myInstance = gl_InstanceID;\n"
" myInstanceF = float(gl_InstanceID) + .5;\n"
" myInstanceF2 = float(gl_InstanceID) + .1;\n"
"}\n";
mCompileOptions.initializeBuiltinsForInstancedMultiview = true;
compileAssumeSuccess(shaderString);
SymbolOccurrenceCounterByName glInstanceIDByName(ImmutableString("gl_InstanceID"));
mASTRoot->traverse(&glInstanceIDByName);
EXPECT_EQ(2u, glInstanceIDByName.getNumberOfOccurrences());
SymbolOccurrenceCounterByQualifier glInstanceIDByQualifier(EvqInstanceID);
mASTRoot->traverse(&glInstanceIDByQualifier);
EXPECT_EQ(2u, glInstanceIDByQualifier.getNumberOfOccurrences());
SymbolOccurrenceCounterByName instanceIDByName(ImmutableString("InstanceID"));
mASTRoot->traverse(&instanceIDByName);
EXPECT_EQ(5u, instanceIDByName.getNumberOfOccurrences());
}
// Test that gl_ViewID_OVR gets correctly replaced by ViewID_OVR. gl_ViewID_OVR should not be found
// by the name. The number of occurrences of ViewID_OVR in the AST should be the sum
// of two and the number of occurrences of gl_ViewID_OVR before any renaming.
TEST_F(OVRMultiview2VertexShaderTest, GLViewIDIsRenamed)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"flat out uint a;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 0u ? 0. : 1.;\n"
" gl_Position.yzw = vec3(0., 0., 1.);\n"
" a = gl_ViewID_OVR == 0u ? (gl_ViewID_OVR+2u) : gl_ViewID_OVR;\n"
"}\n";
mCompileOptions.initializeBuiltinsForInstancedMultiview = true;
compileAssumeSuccess(shaderString);
SymbolOccurrenceCounterByName glViewIDOVRByName(ImmutableString("gl_ViewID_OVR"));
mASTRoot->traverse(&glViewIDOVRByName);
EXPECT_EQ(0u, glViewIDOVRByName.getNumberOfOccurrences());
SymbolOccurrenceCounterByNameAndQualifier viewIDByNameAndQualifier(
ImmutableString("ViewID_OVR"), EvqViewIDOVR);
mASTRoot->traverse(&viewIDByNameAndQualifier);
EXPECT_EQ(6u, viewIDByNameAndQualifier.getNumberOfOccurrences());
}
// The test checks that ViewID_OVR and InstanceID have the correct initializers based on the
// number of views.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, ViewIDAndInstanceIDHaveCorrectValues)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"flat out int myInstance;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 0u ? 0. : 1.;\n"
" gl_Position.yzw = vec3(0., 0., 1.);\n"
" myInstance = gl_InstanceID;\n"
"}\n";
requestHLSLOutput();
ShCompileOptions compileOptions = {};
compileOptions.initializeBuiltinsForInstancedMultiview = true;
compile(shaderString, compileOptions);
EXPECT_TRUE(foundInAllGLSLCode("ViewID_OVR = (uint(gl_InstanceID) % 3u)"));
EXPECT_TRUE(foundInAllGLSLCode("InstanceID = int((uint(gl_InstanceID) / 3u))"));
EXPECT_TRUE(foundInHLSLCode("ViewID_OVR = (uint_ctor_int(gl_InstanceID) % 3)"));
#if defined(ANGLE_ENABLE_HLSL)
EXPECT_FALSE(foundInHLSLCode("_ViewID_OVR = (uint_ctor_int(gl_InstanceID) % 3)"));
#endif
EXPECT_TRUE(foundInHLSLCode("InstanceID = int_ctor_uint((uint_ctor_int(gl_InstanceID) / 3))"));
}
// The test checks that the directive enabling GL_OVR_multiview2 is not outputted if the extension
// is emulated.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, StrippedOVRMultiviewDirective)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"void main()\n"
"{\n"
"}\n";
// The directive must not be present if any of the multiview emulation options are set.
ShCompileOptions compileOptions = {};
compileOptions.initializeBuiltinsForInstancedMultiview = true;
compile(shaderString, compileOptions);
EXPECT_FALSE(foundInESSLCode("GL_OVR_multiview2"));
EXPECT_FALSE(foundInGLSLCode("GL_OVR_multiview2"));
// The directive should be outputted from the ESSL translator with none of the options being
// set.
compile(shaderString);
EXPECT_TRUE(foundInESSLCode("GL_OVR_multiview2"));
}
// Test that ViewID_OVR has a proper qualifier in an ESSL 3.00 fragment shader.
TEST_F(OVRMultiview2FragmentShaderTest, ViewIDDeclaredAsViewID)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"void main()\n"
"{\n"
"}\n";
mCompileOptions.initializeBuiltinsForInstancedMultiview = true;
compileAssumeSuccess(shaderString);
VariableOccursNTimes(mASTRoot, ImmutableString("ViewID_OVR"), EvqViewIDOVR, 1u);
}
// Test that GL_OVR_multiview is not defined by the preprocessor for WebGL spec shader;
// Test that GL_OVR_multiview2 is defined by the preprocessor for WebGL spec shader.
TEST_F(OVRMultiview2FragmentShaderTest, PreprocessorOutput)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#ifdef GL_OVR_multiview\n"
" #error legacy GL_OVR_multiview support must be forbidden\n"
"#endif\n"
"#ifndef GL_OVR_multiview2\n"
" #error GL_OVR_multiview2 support must be enabled\n"
"#endif\n"
"void main()\n"
"{\n"
"}\n";
compileAssumeSuccess(shaderString);
}
// Test that GL_OVR_multiview is not defined by the preprocessor for WebGL spec shader;
// Test that GL_OVR_multiview2 is defined by the preprocessor for WebGL spec shader.
TEST_F(OVRMultiview2VertexShaderTest, PreprocessorOutput)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#ifdef GL_OVR_multiview\n"
" #error legacy GL_OVR_multiview support must be forbidden\n"
"#endif\n"
"#ifndef GL_OVR_multiview2\n"
" #error GL_OVR_multiview2 support must be enabled\n"
"#endif\n"
"void main()\n"
"{\n"
"}\n";
compileAssumeSuccess(shaderString);
}
// The test checks that the GL_NV_viewport_array2 extension is emitted in a vertex shader if the
// selectViewInNvGLSLVertexShader option is set.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, ViewportArray2IsEmitted)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString, mMultiviewCompileOptions);
EXPECT_TRUE(foundInAllGLSLCode("#extension GL_NV_viewport_array2 : require"));
}
// The test checks that the GL_NV_viewport_array2 extension is not emitted in a vertex shader if the
// OVR_multiview2 extension is not requested in the shader source even if the
// selectViewInNvGLSLVertexShader option is set.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, ViewportArray2IsNotEmitted)
{
const std::string &shaderString =
"#version 300 es\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString, mMultiviewCompileOptions);
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
}
// The test checks that the GL_NV_viewport_array2 extension is not emitted in a fragment shader if
// the selectViewInNvGLSLVertexShader option is set.
TEST_F(OVRMultiview2FragmentShaderOutputCodeTest, ViewportArray2IsNotEmitted)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString, mMultiviewCompileOptions);
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
}
// The test checks if OVR_multiview2 is emitted only once and no other
// multiview extensions are emitted.
TEST_F(OVRMultiview2FragmentShaderOutputCodeTest, NativeOvrMultiview2Output)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString);
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
EXPECT_TRUE(foundInESSLCode("#extension GL_OVR_multiview2"));
EXPECT_TRUE(foundInGLSLCode("#extension GL_OVR_multiview2"));
// no double extension
std::vector<const char *> notExpectedStrings1 = {"#extension GL_OVR_multiview",
"#extension GL_OVR_multiview"};
EXPECT_FALSE(foundInCodeInOrder(SH_ESSL_OUTPUT, notExpectedStrings1));
EXPECT_FALSE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, notExpectedStrings1));
}
// The test checks that the GL_NV_viewport_array2 extension is not emitted in a compute shader if
// the selectViewInNvGLSLVertexShader option is set.
TEST_F(OVRMultiview2ComputeShaderOutputCodeTest, ViewportArray2IsNotEmitted)
{
const std::string &shaderString =
R"(#version 310 es
#extension GL_OVR_multiview2 : require
void main()
{
})";
compile(shaderString, mMultiviewCompileOptions);
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
}
// The test checks that the layer is selected after the initialization of ViewID_OVR for
// GLSL and ESSL ouputs.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, GlLayerIsSet)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString, mMultiviewCompileOptions);
std::vector<const char *> expectedStrings = {
"ViewID_OVR = (uint(gl_InstanceID) % 3u)",
"gl_Layer = (int(ViewID_OVR) + multiviewBaseViewLayerIndex)"};
EXPECT_TRUE(foundInCodeInOrder(SH_ESSL_OUTPUT, expectedStrings));
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
}
// Test that the OVR_multiview2 without emulation emits OVR_multiview2 output.
// It also tests that the GL_OVR_multiview2 is emitted only once and no other
// multiview extensions are emitted.
TEST_F(OVRMultiview2VertexShaderOutputCodeTest, NativeOvrMultiview2Output)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 3) in;\n"
"void main()\n"
"{\n"
"}\n";
compile(shaderString);
std::vector<const char *> expectedStrings = {"#extension GL_OVR_multiview2",
"layout(num_views"};
EXPECT_TRUE(foundInCodeInOrder(SH_ESSL_OUTPUT, expectedStrings));
EXPECT_TRUE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, expectedStrings));
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInESSLCode("#extension GL_NV_viewport_array2"));
EXPECT_FALSE(foundInGLSLCode("gl_ViewportIndex"));
EXPECT_FALSE(foundInESSLCode("gl_ViewportIndex"));
// no double extension
std::vector<const char *> notExpectedStrings1 = {"#extension GL_OVR_multiview",
"#extension GL_OVR_multiview"};
EXPECT_FALSE(foundInCodeInOrder(SH_ESSL_OUTPUT, notExpectedStrings1));
EXPECT_FALSE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, notExpectedStrings1));
// no double num_views
std::vector<const char *> notExpectedStrings2 = {"layout(num_views", "layout(num_views"};
EXPECT_FALSE(foundInCodeInOrder(SH_ESSL_OUTPUT, notExpectedStrings2));
EXPECT_FALSE(foundInCodeInOrder(SH_GLSL_COMPATIBILITY_OUTPUT, notExpectedStrings2));
}
} // namespace