Commit 65c56dd9 by Jiawei Shao Committed by Commit Bot

Fix incorrect hashing on built-in interface block fields

This patch intends to fix an error in translating built-in interface block fields. Any field of a built-in interface block should be kept and cannot be hashed. This patch can fix a bug in handling the interface block gl_in when we try to output the translated geometry shader string. BUG=angleproject:1941 TEST=angle_unittest Change-Id: Iebfba4b6a30c8942ed0f66131ad30d12ad96c62a Reviewed-on: https://chromium-review.googlesource.com/719454 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 2a35741b
......@@ -582,9 +582,14 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
const TField *field = interfaceBlock->fields()[index->getIConst(0)];
TString fieldName = field->name();
ASSERT(!mSymbolTable->findBuiltIn(interfaceBlock->name(), mShaderVersion) ||
interfaceBlock->name() == "gl_PerVertex");
fieldName = hashName(TName(fieldName));
if (!mSymbolTable->findBuiltIn(interfaceBlock->name(), mShaderVersion))
{
fieldName = hashName(TName(fieldName));
}
else
{
ASSERT(interfaceBlock->name() == "gl_PerVertex");
}
out << fieldName;
visitChildren = false;
......
......@@ -12,38 +12,25 @@
#include "compiler/translator/BaseTypes.h"
#include "compiler/translator/TranslatorESSL.h"
#include "gtest/gtest.h"
#include "tests/test_utils/ShaderCompileTreeTest.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
class GeometryShaderTest : public testing::Test
class GeometryShaderTest : public ShaderCompileTreeTest
{
public:
GeometryShaderTest() {}
protected:
void SetUp() override
void initResources(ShBuiltInResources *resources) override
{
ShBuiltInResources resources;
InitBuiltInResources(&resources);
resources.OES_geometry_shader = 1;
mTranslator = new TranslatorESSL(GL_GEOMETRY_SHADER_OES, SH_GLES3_1_SPEC);
ASSERT_TRUE(mTranslator->Init(resources));
resources->OES_geometry_shader = 1;
}
void TearDown() override { SafeDelete(mTranslator); }
// Return true when compilation succeeds
bool compile(const std::string &shaderString)
{
const char *shaderStrings[] = {shaderString.c_str()};
GLenum getShaderType() const override { return GL_GEOMETRY_SHADER_OES; }
bool status = mTranslator->compile(shaderStrings, 1, SH_OBJECT_CODE | SH_VARIABLES);
TInfoSink &infoSink = mTranslator->getInfoSink();
mInfoLog = infoSink.info.c_str();
return status;
}
ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
bool compileGeometryShader(const std::string &statement1, const std::string &statement2)
{
......@@ -121,9 +108,16 @@ class GeometryShaderTest : public testing::Test
{"lines_adjacency", 4},
{"triangles", 3},
{"triangles_adjacency", 6}};
};
std::string mInfoLog;
TranslatorESSL *mTranslator = nullptr;
class GeometryShaderOutputCodeTest : public MatchOutputCodeTest
{
public:
GeometryShaderOutputCodeTest()
: MatchOutputCodeTest(GL_GEOMETRY_SHADER_OES, SH_OBJECT_CODE, SH_ESSL_OUTPUT)
{
getResources()->OES_geometry_shader = 1;
}
};
// Geometry Shaders are not supported in GLSL ES shaders version lower than 310.
......@@ -1535,3 +1529,38 @@ TEST_F(GeometryShaderTest, InvariantOutput)
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
}
}
// Verify that the member of gl_in won't be incorrectly changed in the output shader string.
TEST_F(GeometryShaderOutputCodeTest, ValidateGLInMembersInOutputShaderString)
{
const std::string &shaderString1 =
R"(#version 310 es
#extension GL_OES_geometry_shader : require
layout (lines) in;
layout (points, max_vertices = 2) out;
void main()
{
vec4 position;
for (int i = 0; i < 2; i++)
{
position = gl_in[i].gl_Position;
}
})";
compile(shaderString1);
EXPECT_TRUE(foundInESSLCode("].gl_Position"));
const std::string &shaderString2 =
R"(#version 310 es
#extension GL_OES_geometry_shader : require
layout (points) in;
layout (points, max_vertices = 2) out;
void main()
{
vec4 position;
position = gl_in[0].gl_Position;
})";
compile(shaderString2);
EXPECT_TRUE(foundInESSLCode("].gl_Position"));
}
\ No newline at end of file
......@@ -134,7 +134,7 @@ bool MatchOutputCodeTest::compileWithSettings(ShShaderOutput output,
std::string *translatedCode,
std::string *infoLog)
{
return compileTestShader(mShaderType, SH_GLES3_SPEC, output, shaderString, &mResources,
return compileTestShader(mShaderType, SH_GLES3_1_SPEC, output, shaderString, &mResources,
compileOptions, translatedCode, infoLog);
}
......
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