Commit ec3a9cbb by Olli Etuaho Committed by Commit Bot

Only support GL_OVR_multiview extension variant

The WebGL spec proposal was changed so that only GL_OVR_multiview extension name is supported, instead of having two variants OVR_multiview and OVR_multiview2. We're only supporting the WebGL version of the shader extension, so we drop compiler support for GL_OVR_multiview2. Shader restrictions were also removed from the WebGL spec, so no special validation for how ViewID_OVR gets used is needed. Tests that were testing for the shader restrictions are either removed or changed from negative tests to positive tests. BUG=angleproject:1669 TEST=angle_unittests Change-Id: I83f92b879376d41b727b5aca419fd75fb6f53477 Reviewed-on: https://chromium-review.googlesource.com/654608Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 15c3406a
......@@ -145,8 +145,6 @@
'compiler/translator/ValidateLimitations.h',
'compiler/translator/ValidateMaxParameters.h',
'compiler/translator/ValidateMaxParameters.cpp',
'compiler/translator/ValidateMultiviewWebGL.cpp',
'compiler/translator/ValidateMultiviewWebGL.h',
'compiler/translator/ValidateOutputs.cpp',
'compiler/translator/ValidateOutputs.h',
'compiler/translator/ValidateSwitch.cpp',
......
......@@ -527,8 +527,7 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol)
else
{
ASSERT(mShaderType == GL_VERTEX_SHADER &&
(IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview") ||
IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview2")));
IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview"));
}
break;
default:
......
......@@ -37,7 +37,6 @@
#include "compiler/translator/UseInterfaceBlockFields.h"
#include "compiler/translator/ValidateLimitations.h"
#include "compiler/translator/ValidateMaxParameters.h"
#include "compiler/translator/ValidateMultiviewWebGL.h"
#include "compiler/translator/ValidateOutputs.h"
#include "compiler/translator/VariablePacker.h"
#include "third_party/compiler/ArrayBoundsClamper.h"
......@@ -359,15 +358,6 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
// Highp might have been auto-enabled based on shader version
fragmentPrecisionHigh = parseContext.getFragmentPrecisionHigh();
if (success && (IsWebGLBasedSpec(shaderSpec) &&
IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") &&
IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2")))
{
// Can't enable both extensions at the same time.
mDiagnostics.globalError("Can't enable both OVR_multiview and OVR_multiview2");
success = false;
}
if (success && shaderType == GL_GEOMETRY_SHADER_OES)
{
mGeometryShaderInputPrimitiveType = parseContext.getGeometryShaderInputPrimitiveType();
......@@ -414,12 +404,6 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
success =
ValidateLimitations(root, shaderType, &symbolTable, shaderVersion, &mDiagnostics);
bool multiview2 = IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview2");
if (success && compileResources.OVR_multiview && IsWebGLBasedSpec(shaderSpec) &&
(IsExtensionEnabled(extensionBehavior, "GL_OVR_multiview") || multiview2))
success = ValidateMultiviewWebGL(root, shaderType, symbolTable, shaderVersion,
multiview2, &mDiagnostics);
// Fail compilation if precision emulation not supported.
if (success && getResources().WEBGL_debug_shader_precision &&
getPragma().debugShaderPrecision)
......
......@@ -1021,8 +1021,7 @@ void InitExtensionBehavior(const ShBuiltInResources &resources, TExtensionBehavi
extBehavior["GL_ARM_shader_framebuffer_fetch"] = EBhUndefined;
if (resources.OVR_multiview)
{
extBehavior["GL_OVR_multiview"] = EBhUndefined;
extBehavior["GL_OVR_multiview2"] = EBhUndefined;
extBehavior["GL_OVR_multiview"] = EBhUndefined;
}
if (resources.EXT_YUV_target)
{
......
......@@ -130,8 +130,7 @@ OutputHLSL::OutputHLSL(sh::GLenum shaderType,
mUsesFrontFacing = false;
mUsesPointSize = false;
mUsesInstanceID = false;
mHasMultiviewExtensionEnabled = IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview") ||
IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview2");
mHasMultiviewExtensionEnabled = IsExtensionEnabled(mExtensionBehavior, "GL_OVR_multiview");
mUsesViewID = false;
mUsesVertexID = false;
mUsesFragDepth = false;
......
......@@ -1158,12 +1158,6 @@ bool TParseContext::checkCanUseExtension(const TSourceLoc &line, const TString &
// In GLSL ES, an extension's default behavior is "disable".
if (iter->second == EBhDisable || iter->second == EBhUndefined)
{
// TODO(oetuaho@nvidia.com): This is slightly hacky. Might be better if symbols could be
// associated with more than one extension.
if (extension == "GL_OVR_multiview")
{
return checkCanUseExtension(line, "GL_OVR_multiview2");
}
error(line, "extension is disabled", extension.c_str());
return false;
}
......@@ -1776,14 +1770,6 @@ TIntermTyped *TParseContext::parseVariableIdentifier(const TSourceLoc &location,
return node;
}
if (variable->getType().getQualifier() == EvqViewIDOVR && IsWebGLBasedSpec(mShaderSpec) &&
mShaderType == GL_FRAGMENT_SHADER && !isExtensionEnabled("GL_OVR_multiview2"))
{
// WEBGL_multiview spec
error(location, "Need to enable OVR_multiview2 to use gl_ViewID_OVR in fragment shader",
"gl_ViewID_OVR");
}
TIntermTyped *node = nullptr;
if (variable->getConstPointer())
......
......@@ -172,8 +172,7 @@ class TParseContext : angle::NonCopyable
bool isExtensionEnabled(const char *extension) const;
bool isMultiviewExtensionEnabled() const
{
return mMultiviewAvailable &&
(isExtensionEnabled("GL_OVR_multiview") || isExtensionEnabled("GL_OVR_multiview2"));
return mMultiviewAvailable && isExtensionEnabled("GL_OVR_multiview");
}
void handleExtensionDirective(const TSourceLoc &loc, const char *extName, const char *behavior);
void handlePragmaDirective(const TSourceLoc &loc,
......
......@@ -136,8 +136,7 @@ void TranslatorESSL::writeExtensionBehavior(ShCompileOptions compileOptions)
{
if (iter->second != EBhUndefined)
{
const bool isMultiview =
iter->first == "GL_OVR_multiview" || iter->first == "GL_OVR_multiview2";
const bool isMultiview = (iter->first == "GL_OVR_multiview");
if (getResources().NV_shader_framebuffer_fetch &&
iter->first == "GL_EXT_shader_framebuffer_fetch")
{
......
......@@ -283,8 +283,7 @@ void TranslatorGLSL::writeExtensionBehavior(TIntermNode *root, ShCompileOptions
}
}
const bool isMultiview =
iter.first == "GL_OVR_multiview" || iter.first == "GL_OVR_multiview2";
const bool isMultiview = (iter.first == "GL_OVR_multiview");
if (isMultiview && getShaderType() == GL_VERTEX_SHADER &&
(compileOptions & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER) != 0u)
{
......
//
// Copyright (c) 2002-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.
//
// ValidateMultiviewWebGL.cpp:
// Validate the AST according to rules in the WEBGL_multiview extension spec. Only covers those
// rules not already covered in ParseContext.
//
#include "compiler/translator/ValidateMultiviewWebGL.h"
#include <array>
#include "angle_gl.h"
#include "compiler/translator/Diagnostics.h"
#include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
namespace
{
class ValidateMultiviewTraverser : public TIntermTraverser
{
public:
// Check for errors and write error messages to diagnostics. Returns true if there are no
// errors.
static bool validate(TIntermBlock *root,
GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics);
bool isValid() { return mValid; }
protected:
void visitSymbol(TIntermSymbol *node) override;
bool visitBinary(Visit visit, TIntermBinary *node) override;
bool visitUnary(Visit visit, TIntermUnary *node) override;
bool visitIfElse(Visit visit, TIntermIfElse *node) override;
bool visitAggregate(Visit visit, TIntermAggregate *node) override;
private:
ValidateMultiviewTraverser(GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics);
static bool IsGLPosition(TIntermNode *node);
static bool IsGLViewIDOVR(TIntermNode *node);
static bool IsSimpleAssignmentToGLPositionX(TIntermBinary *node);
static bool IsSimpleAssignmentToGLPosition(TIntermBinary *node);
void validateAndTraverseViewIDConditionalBlock(TIntermBlock *block, const char *token);
bool mValid;
bool mMultiview2;
GLenum mShaderType;
const TSymbolTable &mSymbolTable;
const int mShaderVersion;
bool mInsideViewIDConditional; // Only set if mMultiview2 is false.
bool mInsideRestrictedAssignment;
bool mGLPositionAllowed;
bool mViewIDOVRAllowed;
TDiagnostics *mDiagnostics;
};
bool ValidateMultiviewTraverser::validate(TIntermBlock *root,
GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics)
{
ValidateMultiviewTraverser validate(shaderType, symbolTable, shaderVersion, multiview2,
diagnostics);
ASSERT(root);
root->traverse(&validate);
return validate.isValid();
}
ValidateMultiviewTraverser::ValidateMultiviewTraverser(GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics)
: TIntermTraverser(true, true, true),
mValid(true),
mMultiview2(multiview2),
mShaderType(shaderType),
mSymbolTable(symbolTable),
mShaderVersion(shaderVersion),
mInsideViewIDConditional(false),
mInsideRestrictedAssignment(false),
mGLPositionAllowed(multiview2),
mViewIDOVRAllowed(multiview2),
mDiagnostics(diagnostics)
{
}
bool ValidateMultiviewTraverser::IsGLPosition(TIntermNode *node)
{
TIntermSymbol *symbolNode = node->getAsSymbolNode();
return (symbolNode && symbolNode->getName().getString() == "gl_Position");
}
bool ValidateMultiviewTraverser::IsGLViewIDOVR(TIntermNode *node)
{
TIntermSymbol *symbolNode = node->getAsSymbolNode();
return (symbolNode && symbolNode->getName().getString() == "gl_ViewID_OVR");
}
bool ValidateMultiviewTraverser::IsSimpleAssignmentToGLPositionX(TIntermBinary *node)
{
if (node->getOp() == EOpAssign)
{
TIntermSwizzle *leftAsSwizzle = node->getLeft()->getAsSwizzleNode();
if (leftAsSwizzle && IsGLPosition(leftAsSwizzle->getOperand()) &&
leftAsSwizzle->offsetsMatch(0))
{
return true;
}
TIntermBinary *leftAsBinary = node->getLeft()->getAsBinaryNode();
if (leftAsBinary && leftAsBinary->getOp() == EOpIndexDirect &&
IsGLPosition(leftAsBinary->getLeft()) &&
leftAsBinary->getRight()->getAsConstantUnion()->getIConst(0) == 0)
{
return true;
}
}
return false;
}
bool ValidateMultiviewTraverser::IsSimpleAssignmentToGLPosition(TIntermBinary *node)
{
if (node->getOp() == EOpAssign)
{
if (IsGLPosition(node->getLeft()))
{
return true;
}
TIntermSwizzle *leftAsSwizzle = node->getLeft()->getAsSwizzleNode();
if (leftAsSwizzle && IsGLPosition(leftAsSwizzle->getOperand()))
{
return true;
}
TIntermBinary *leftAsBinary = node->getLeft()->getAsBinaryNode();
if (leftAsBinary && leftAsBinary->getOp() == EOpIndexDirect &&
IsGLPosition(leftAsBinary->getLeft()))
{
return true;
}
}
return false;
}
void ValidateMultiviewTraverser::visitSymbol(TIntermSymbol *node)
{
if (IsGLPosition(node) && !mGLPositionAllowed)
{
ASSERT(!mMultiview2);
mDiagnostics->error(node->getLine(),
"Disallowed use of gl_Position when using OVR_multiview",
"gl_Position");
mValid = false;
}
else if (IsGLViewIDOVR(node) && !mViewIDOVRAllowed)
{
ASSERT(!mMultiview2);
mDiagnostics->error(node->getLine(),
"Disallowed use of gl_ViewID_OVR when using OVR_multiview",
"gl_ViewID_OVR");
mValid = false;
}
else if (!mMultiview2 && mShaderType == GL_FRAGMENT_SHADER)
{
std::array<const char *, 3> disallowedFragmentShaderSymbols{
{"gl_FragCoord", "gl_PointCoord", "gl_FrontFacing"}};
for (auto disallowedSymbol : disallowedFragmentShaderSymbols)
{
if (node->getSymbol() == disallowedSymbol)
{
mDiagnostics->error(
node->getLine(),
"Disallowed use of a built-in variable when using OVR_multiview",
disallowedSymbol);
mValid = false;
}
}
}
}
bool ValidateMultiviewTraverser::visitBinary(Visit visit, TIntermBinary *node)
{
if (!mMultiview2 && mShaderType == GL_VERTEX_SHADER)
{
if (visit == PreVisit)
{
ASSERT(!mInsideViewIDConditional || mInsideRestrictedAssignment);
if (node->isAssignment())
{
if (mInsideRestrictedAssignment)
{
mDiagnostics->error(node->getLine(),
"Disallowed assignment inside assignment to gl_Position.x "
"when using OVR_multiview",
GetOperatorString(node->getOp()));
mValid = false;
}
else if (IsSimpleAssignmentToGLPositionX(node) &&
FindSymbolNode(node->getRight(), "gl_ViewID_OVR", EbtUInt))
{
if (!getParentNode()->getAsBlock())
{
mDiagnostics->error(node->getLine(),
"Disallowed use of assignment to gl_Position.x "
"when using OVR_multiview",
"=");
mValid = false;
}
mInsideRestrictedAssignment = true;
mViewIDOVRAllowed = true;
node->getRight()->traverse(this);
mInsideRestrictedAssignment = false;
mViewIDOVRAllowed = false;
return false;
}
else if (IsSimpleAssignmentToGLPosition(node))
{
node->getRight()->traverse(this);
return false;
}
}
}
}
return true;
}
bool ValidateMultiviewTraverser::visitUnary(Visit visit, TIntermUnary *node)
{
if (visit == PreVisit && !mMultiview2 && mInsideRestrictedAssignment)
{
if (node->isAssignment())
{
mDiagnostics->error(node->getLine(),
"Disallowed unary operator inside assignment to gl_Position.x when "
"using OVR_multiview",
GetOperatorString(node->getOp()));
mValid = false;
}
}
return true;
}
void ValidateMultiviewTraverser::validateAndTraverseViewIDConditionalBlock(TIntermBlock *block,
const char *token)
{
if (block->getSequence()->size() > 1)
{
mDiagnostics->error(block->getLine(),
"Only one assignment to gl_Position allowed inside if block dependent "
"on gl_ViewID_OVR when using OVR_multiview",
token);
mValid = false;
}
else if (block->getSequence()->size() == 1)
{
TIntermBinary *assignment = block->getSequence()->at(0)->getAsBinaryNode();
if (assignment && IsSimpleAssignmentToGLPositionX(assignment))
{
mInsideRestrictedAssignment = true;
assignment->getRight()->traverse(this);
mInsideRestrictedAssignment = false;
}
else
{
mDiagnostics->error(block->getLine(),
"Only one assignment to gl_Position.x allowed inside if block "
"dependent on gl_ViewID_OVR when using OVR_multiview",
token);
mValid = false;
}
}
}
bool ValidateMultiviewTraverser::visitIfElse(Visit visit, TIntermIfElse *node)
{
if (!mMultiview2 && mShaderType == GL_VERTEX_SHADER)
{
ASSERT(visit == PreVisit);
// Check if the if statement refers to gl_ViewID_OVR and if it does so correctly
TIntermBinary *binaryCondition = node->getCondition()->getAsBinaryNode();
bool conditionIsAllowedComparisonWithViewID = false;
if (binaryCondition && binaryCondition->getOp() == EOpEqual)
{
conditionIsAllowedComparisonWithViewID =
IsGLViewIDOVR(binaryCondition->getLeft()) &&
binaryCondition->getRight()->getAsConstantUnion() &&
binaryCondition->getRight()->getQualifier() == EvqConst;
if (!conditionIsAllowedComparisonWithViewID)
{
conditionIsAllowedComparisonWithViewID =
IsGLViewIDOVR(binaryCondition->getRight()) &&
binaryCondition->getLeft()->getAsConstantUnion() &&
binaryCondition->getLeft()->getQualifier() == EvqConst;
}
}
if (conditionIsAllowedComparisonWithViewID)
{
mInsideViewIDConditional = true;
if (node->getTrueBlock())
{
validateAndTraverseViewIDConditionalBlock(node->getTrueBlock(), "if");
}
else
{
mDiagnostics->error(node->getLine(), "Expected assignment to gl_Position.x", "if");
}
if (node->getFalseBlock())
{
validateAndTraverseViewIDConditionalBlock(node->getFalseBlock(), "else");
}
mInsideViewIDConditional = false;
}
else
{
node->getCondition()->traverse(this);
if (node->getTrueBlock())
{
node->getTrueBlock()->traverse(this);
}
if (node->getFalseBlock())
{
node->getFalseBlock()->traverse(this);
}
}
return false;
}
return true;
}
bool ValidateMultiviewTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
if (visit == PreVisit && !mMultiview2 && mInsideRestrictedAssignment)
{
// Check if the node is an user-defined function call or if an l-value is required, or if
// there are possible visible side effects, such as image writes.
if (node->getOp() == EOpCallFunctionInAST)
{
mDiagnostics->error(node->getLine(),
"Disallowed user defined function call inside assignment to "
"gl_Position.x when using OVR_multiview",
GetOperatorString(node->getOp()));
mValid = false;
}
else if (node->getOp() == EOpCallBuiltInFunction &&
node->getFunctionSymbolInfo()->getName() == "imageStore")
{
// TODO(oetuaho@nvidia.com): Record which built-in functions have side effects in
// the symbol info instead.
mDiagnostics->error(node->getLine(),
"Disallowed function call with side effects inside assignment "
"to gl_Position.x when using OVR_multiview",
GetOperatorString(node->getOp()));
mValid = false;
}
else if (!node->isConstructor())
{
TFunction *builtInFunc = static_cast<TFunction *>(
mSymbolTable.findBuiltIn(node->getSymbolTableMangledName(), mShaderVersion));
for (size_t paramIndex = 0u; paramIndex < builtInFunc->getParamCount(); ++paramIndex)
{
TQualifier qualifier = builtInFunc->getParam(paramIndex).type->getQualifier();
if (qualifier == EvqOut || qualifier == EvqInOut)
{
mDiagnostics->error(node->getLine(),
"Disallowed use of a function with an out parameter inside "
"assignment to gl_Position.x when using OVR_multiview",
GetOperatorString(node->getOp()));
mValid = false;
}
}
}
}
return true;
}
} // anonymous namespace
bool ValidateMultiviewWebGL(TIntermBlock *root,
GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics)
{
if (shaderType == GL_VERTEX_SHADER && !FindSymbolNode(root, "gl_ViewID_OVR", EbtUInt))
{
return true;
}
return ValidateMultiviewTraverser::validate(root, shaderType, symbolTable, shaderVersion,
multiview2, diagnostics);
}
} // namespace sh
//
// Copyright (c) 2002-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.
//
// ValidateMultiviewWebGL.h:
// Validate the AST according to rules in the WEBGL_multiview extension spec. Only covers those
// rules not already covered in ParseContext.
//
#ifndef COMPILER_TRANSLATOR_VALIDATEMULTIVIEWWEBGL_H_
#define COMPILER_TRANSLATOR_VALIDATEMULTIVIEWWEBGL_H_
#include "GLSLANG/ShaderVars.h"
namespace sh
{
class TDiagnostics;
class TIntermBlock;
class TSymbolTable;
// Check for errors and output error messages with diagnostics.
// Returns true if there are no errors.
bool ValidateMultiviewWebGL(TIntermBlock *root,
sh::GLenum shaderType,
const TSymbolTable &symbolTable,
int shaderVersion,
bool multiview2,
TDiagnostics *diagnostics);
} // namespace sh
#endif // COMPILER_TRANSLATOR_VALIDATEMULTIVIEWWEBGL_H_
......@@ -188,13 +188,13 @@ void VariableOccursNTimes(TIntermBlock *root,
EXPECT_EQ(n, viewIDByName.getNumberOfOccurrences());
}
// Invalid combination of extensions (restricted in the WEBGL_multiview spec).
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidBothMultiviewAndMultiview2)
// Unsupported GL_OVR_multiview2 extension directive (WEBGL_multiview spec only exposes
// GL_OVR_multiview).
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidMultiview2)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"#extension GL_OVR_multiview2 : enable\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
......@@ -212,7 +212,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, InvalidNumViewsMismatch)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"layout(num_views = 1) in;\n"
"void main()\n"
......@@ -231,7 +231,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, InvalidNumViewsZero)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 0) in;\n"
"void main()\n"
"{\n"
......@@ -249,7 +249,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, InvalidNumViewsGreaterThanMax)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 5) in;\n"
"void main()\n"
"{\n"
......@@ -262,163 +262,29 @@ TEST_F(WEBGLMultiviewVertexShaderTest, InvalidNumViewsGreaterThanMax)
}
}
// Valid use of gl_ViewID_OVR in a ternary operator.
TEST_F(WEBGLMultiviewVertexShaderTest, ValidViewIDInTernary)
// Valid use of gl_ViewID_OVR.
TEST_F(WEBGLMultiviewVertexShaderTest, ViewIDUsed)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"layout(num_views = 2) in; // Duplicated on purpose\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 failed, expecting success:\n" << mInfoLog;
}
}
// Valid use of gl_ViewID_OVR in an if statement.
TEST_F(WEBGLMultiviewVertexShaderTest, ValidViewIDInIf)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"precision highp float;\n"
"in vec4 pos;\n"
"out float myOutput;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u)\n"
" {\n"
" gl_Position.x = pos.x;\n"
" gl_Position = pos;\n"
" myOutput = 1.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position.x = 1.0;\n"
" gl_Position = pos + vec4(1.0, 0.0, 0.0, 0.0);\n"
" myOutput = 2.0;\n"
" }\n"
" gl_Position.yzw = pos.yzw;\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Valid normal write of gl_Position in addition to the write that's dependent on gl_ViewID_OVR.
TEST_F(WEBGLMultiviewVertexShaderTest, ValidWriteOfGlPosition)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" if (0u == gl_ViewID_OVR)\n"
" {\n"
" gl_Position.x = 1.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position.x = 1.0;\n"
" }\n"
" gl_Position = vec4(1, 1, 1, 1);\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Invalid assignment to gl_Position.y inside if dependent on gl_ViewID_OVR.
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidGlPositionAssignmentInIf)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u)\n"
" {\n"
" gl_Position.y = 1.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position.y = 1.0;\n"
" }\n"
" gl_Position.xzw = vec3(0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Invalid multiple assignments inside if dependent on gl_ViewID_OVR.
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidMultipleGlPositionXAssignmentsInIf)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u)\n"
" {\n"
" gl_Position.x = 1.0;\n"
" gl_Position.x = 2.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position.x = 1.0;\n"
" }\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Invalid read of gl_Position
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidReadOfGlPosition)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u) {\n"
" gl_Position.x = 1.0;\n"
" } else {\n"
" gl_Position.x = 1.0;\n"
" }\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
" float f = gl_Position.y;\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Read gl_Position when the shader does not refer to gl_ViewID_OVR.
TEST_F(WEBGLMultiviewVertexShaderTest, ValidReadOfGlPosition)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"uniform float u;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(0, 0, 0, 1);\n"
" gl_Position.y = gl_Position.x * u;\n"
" gl_Position += (gl_ViewID_OVR == 0u) ? 1.0 : 0.0;\n"
"}\n";
if (!compile(shaderString))
{
......@@ -427,7 +293,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ValidReadOfGlPosition)
}
// Read gl_FragCoord in a OVR_multiview fragment shader.
TEST_F(WEBGLMultiviewFragmentShaderTest, InvalidReadOfFragCoord)
TEST_F(WEBGLMultiviewFragmentShaderTest, ReadOfFragCoord)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -438,14 +304,14 @@ TEST_F(WEBGLMultiviewFragmentShaderTest, InvalidReadOfFragCoord)
"{\n"
" outColor = vec4(gl_FragCoord.xy, 0, 1);\n"
"}\n";
if (compile(shaderString))
if (!compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Read gl_ViewID_OVR in an OVR_multiview fragment shader.
TEST_F(WEBGLMultiviewFragmentShaderTest, InvalidReadOfViewID)
TEST_F(WEBGLMultiviewFragmentShaderTest, ReadOfViewID)
{
const std::string &shaderString =
"#version 300 es\n"
......@@ -456,73 +322,24 @@ TEST_F(WEBGLMultiviewFragmentShaderTest, InvalidReadOfViewID)
"{\n"
" outColor = vec4(gl_ViewID_OVR, 0, 0, 1);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Tricky invalid read of view ID.
TEST_F(WEBGLMultiviewVertexShaderTest, InvalidConsumingExpressionForAssignGLPositionX)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" float f = (gl_Position.x = (gl_ViewID_OVR == 0u) ? 1.0 : 0.0);\n"
" gl_Position.yzw = vec3(f, f, f);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Using the OVR_multiview2 extension directive lifts restrictions of OVR_multiview.
TEST_F(WEBGLMultiviewVertexShaderTest, RestrictionsLiftedMultiview2)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"out float out_f;\n"
"void main()\n"
"{\n"
" if (gl_ViewID_OVR == 0u)\n"
" {\n"
" gl_Position.x = 1.0;\n"
" gl_Position.x = 2.0;\n"
" }\n"
" else\n"
" {\n"
" gl_Position.x = 1.0;\n"
" }\n"
" gl_Position.yzw = vec3(0, 0, 1);\n"
" gl_Position += vec4(1, 0, 0, 1);\n"
" out_f = float(gl_ViewID_OVR * 2u);\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Correct use of GL_OVR_multiview macros.
TEST_F(WEBGLMultiviewVertexShaderTest, ValidUseOfExtensionMacros)
// Correct use of GL_OVR_multiview macro.
TEST_F(WEBGLMultiviewVertexShaderTest, UseOfExtensionMacro)
{
const std::string &shaderString =
"#version 300 es\n"
"#ifdef GL_OVR_multiview\n"
"#ifdef GL_OVR_multiview2\n"
"#if (GL_OVR_multiview == 1) && (GL_OVR_multiview2 == 1)\n"
"#if (GL_OVR_multiview == 1)\n"
"void main()\n"
"{\n"
" gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
"}\n"
"#endif\n"
"#endif\n"
"#endif\n";
if (!compile(shaderString))
{
......@@ -530,29 +347,12 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ValidUseOfExtensionMacros)
}
}
// Test that the parent node is tracked correctly when validating assignment to gl_Position.
TEST_F(WEBGLMultiviewVertexShaderTest, AssignmentWithViewIDInsideAssignment)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" gl_Position.y = (gl_Position.x = (gl_ViewID_OVR == 0u) ? 1.0 : 0.0);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that gl_ViewID_OVR can't be used as an l-value.
TEST_F(WEBGLMultiviewVertexShaderTest, ViewIdAsLValue)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void foo(out uint u)\n"
"{\n"
......@@ -573,7 +373,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ViewIdAsLValue)
TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1Shader)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
......@@ -596,7 +396,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1Shader)
TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1ShaderUnsupportedGlobalLayoutQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"layout(std140) uniform;\n"
"void main()\n"
......@@ -620,7 +420,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1ShaderUnsupportedGlobalLayoutQualifi
TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1ShaderUnsupportedInputStorageQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec4 pos;\n"
"void main()\n"
......@@ -645,7 +445,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, ESSL1ShaderUnsupportedInputStorageQualifi
TEST_F(WEBGLMultiviewFragmentShaderTest, ESSL1ShaderUnsupportedInStorageQualifier)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision highp float;\n"
"in vec4 color;\n"
"void main()\n"
......@@ -709,7 +509,7 @@ TEST_F(WEBGLMultiviewVertexShaderTest, GLViewIDIsRenamed)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"flat out uint a;\n"
"void main()\n"
......@@ -790,7 +590,7 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, StrippedOVRMultiviewDirective)
TEST_F(WEBGLMultiviewVertexShaderTest, InstaceIDCollectedESSL1)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
......@@ -815,7 +615,7 @@ TEST_F(WEBGLMultiviewFragmentShaderTest, ViewIDDeclaredAsFlatInput)
{
const std::string &shaderString =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"void main()\n"
"{\n"
"}\n";
......@@ -828,7 +628,7 @@ TEST_F(WEBGLMultiviewFragmentShaderTest, ViewIDDeclaredAsFlatInput)
TEST_F(WEBGLMultiviewVertexShaderTest, ViewIDDeclaredAsFlatOutput)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"void main()\n"
"{\n"
"}\n";
......
......@@ -830,7 +830,7 @@ TEST_P(MultiviewRenderTest, DrawArraysFourViews)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 4) in;\n"
"in vec4 vPosition;\n"
"void main()\n"
......@@ -849,7 +849,7 @@ TEST_P(MultiviewRenderTest, DrawArraysFourViews)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -958,7 +958,7 @@ TEST_P(MultiviewRenderTest, AttribDivisor)
const std::string &vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"in float offsetX;\n"
......@@ -973,7 +973,7 @@ TEST_P(MultiviewRenderTest, AttribDivisor)
const std::string &fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -1039,7 +1039,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation)
// Create multiview program.
const std::string &vs =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"layout(location = 0) in vec2 vPosition;\n"
"layout(location = 1) in float offsetX;\n"
......@@ -1052,7 +1052,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation)
const std::string &fs =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -1331,7 +1331,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
......@@ -1344,7 +1344,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"void main()\n"
"{\n"
......@@ -1367,7 +1367,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
......@@ -1375,7 +1375,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -1639,7 +1639,7 @@ TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"layout(location=0) in vec2 vPosition;\n"
"void main()\n"
......@@ -1650,7 +1650,7 @@ TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -1713,7 +1713,7 @@ TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor)
const std::string &fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"in vec4 oColor;\n"
"out vec4 col;\n"
......@@ -1725,7 +1725,7 @@ TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor)
auto generateVertexShaderSource = [](int numViews) -> std::string {
std::string source =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = " +
ToString(numViews) +
") in;\n"
......@@ -1895,7 +1895,7 @@ TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 3) in;\n"
"in vec3 vPosition;\n"
"void main()\n"
......@@ -1905,7 +1905,7 @@ TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"out vec4 col;\n"
"void main()\n"
......@@ -1994,7 +1994,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation)
const std::string vsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"layout(num_views = 2) in;\n"
"in vec3 vPosition;\n"
"flat out int oInstanceID;\n"
......@@ -2006,7 +2006,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation)
const std::string fsSource =
"#version 300 es\n"
"#extension GL_OVR_multiview2 : require\n"
"#extension GL_OVR_multiview : require\n"
"precision mediump float;\n"
"flat in int oInstanceID;\n"
"out vec4 col;\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment