Commit 115fc55e by Martin Radev Committed by Commit Bot

Populate gl_InstanceID attribute information explicitly

While compiling ESSL1 shaders, with the compiler having both SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW and SH_VARIABLES set, variable collection terminates with an assertion failure. The reason behind this is that SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW adds gl_InstanceID to the AST to initialize the multiview builtins, but the variable collection pass cannot find gl_InstanceID information in the symbol table because the builtin is only available in ESSL 3.00 and greater. To address this the patch populates the gl_InstanceID attribute information explicitly in the variable collection pass instead of retrieving it from the symbol table. BUG=angleproject:2062 TEST=angle_unittests Change-Id: I5ecb9967ebe6658e956d17a2637090f9b685ef33 Reviewed-on: https://chromium-review.googlesource.com/559669Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 4dd06d5d
...@@ -336,7 +336,25 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol) ...@@ -336,7 +336,25 @@ void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol)
recordBuiltInVaryingUsed("gl_PointCoord", &mPointCoordAdded); recordBuiltInVaryingUsed("gl_PointCoord", &mPointCoordAdded);
return; return;
case EvqInstanceID: case EvqInstanceID:
recordBuiltInAttributeUsed("gl_InstanceID", &mInstanceIDAdded); // Whenever the SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW option is set,
// gl_InstanceID is added inside expressions to initialize ViewID_OVR and
// InstanceID. gl_InstanceID is not added to the symbol table for ESSL1 shaders
// which makes it necessary to populate the type information explicitly instead of
// extracting it from the symbol table.
if (!mInstanceIDAdded)
{
Attribute info;
const char kName[] = "gl_InstanceID";
info.name = kName;
info.mappedName = kName;
info.type = GL_INT;
info.arraySize = 0;
info.precision = GL_HIGH_INT; // Defined by spec.
info.staticUse = true;
info.location = -1;
mAttribs->push_back(info);
mInstanceIDAdded = true;
}
return; return;
case EvqVertexID: case EvqVertexID:
recordBuiltInAttributeUsed("gl_VertexID", &mVertexIDAdded); recordBuiltInAttributeUsed("gl_VertexID", &mVertexIDAdded);
......
...@@ -717,3 +717,28 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, StrippedOVRMultiviewDirective) ...@@ -717,3 +717,28 @@ TEST_F(WEBGLMultiviewVertexShaderOutputCodeTest, StrippedOVRMultiviewDirective)
compile(shaderString); compile(shaderString);
EXPECT_TRUE(foundInESSLCode("GL_OVR_multiview")); EXPECT_TRUE(foundInESSLCode("GL_OVR_multiview"));
} }
// Test that gl_InstanceID is collected in an ESSL1 shader if the
// SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW option is set.
TEST_F(WEBGLMultiviewVertexShaderTest, InstaceIDCollectedESSL1)
{
const std::string &shaderString =
"#extension GL_OVR_multiview2 : require\n"
"layout(num_views = 2) in;\n"
"void main()\n"
"{\n"
" gl_Position.x = gl_ViewID_OVR == 0 ? 0. : 1.;\n"
" gl_Position.yzw = vec3(0., 0., 1.);\n"
"}\n";
mExtraCompileOptions |= SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW;
mExtraCompileOptions |= SH_VARIABLES;
compileAssumeSuccess(shaderString);
const std::vector<Attribute> &attributes = getAttributes();
bool isGLInstanceIDFound = false;
for (size_t i = 0u; i < attributes.size() && !isGLInstanceIDFound; ++i)
{
isGLInstanceIDFound = (attributes[i].name == "gl_InstanceID");
}
EXPECT_TRUE(isGLInstanceIDFound);
}
\ No newline at end of file
...@@ -153,12 +153,18 @@ bool ShaderCompileTreeTest::hasWarning() const ...@@ -153,12 +153,18 @@ bool ShaderCompileTreeTest::hasWarning() const
return mInfoLog.find("WARNING: ") != std::string::npos; return mInfoLog.find("WARNING: ") != std::string::npos;
} }
const std::vector<sh::Uniform> ShaderCompileTreeTest::getUniforms() const std::vector<sh::Uniform> &ShaderCompileTreeTest::getUniforms() const
{ {
ASSERT(mExtraCompileOptions & SH_VARIABLES); ASSERT(mExtraCompileOptions & SH_VARIABLES);
return mTranslator->getUniforms(); return mTranslator->getUniforms();
} }
const std::vector<sh::Attribute> &ShaderCompileTreeTest::getAttributes() const
{
ASSERT(mExtraCompileOptions & SH_VARIABLES);
return mTranslator->getAttributes();
}
bool IsZero(TIntermNode *node) bool IsZero(TIntermNode *node)
{ {
if (!node->getAsTyped()) if (!node->getAsTyped())
......
...@@ -38,7 +38,8 @@ class ShaderCompileTreeTest : public testing::Test ...@@ -38,7 +38,8 @@ class ShaderCompileTreeTest : public testing::Test
bool hasWarning() const; bool hasWarning() const;
const std::vector<sh::Uniform> getUniforms(); const std::vector<sh::Uniform> &getUniforms() const;
const std::vector<sh::Attribute> &getAttributes() const;
virtual void initResources(ShBuiltInResources *resources) {} virtual void initResources(ShBuiltInResources *resources) {}
virtual ::GLenum getShaderType() const = 0; virtual ::GLenum getShaderType() const = 0;
......
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