Commit 474a08c0 by Olli Etuaho Committed by Commit Bot

Remove qualifiers from empty struct declarations in output

Empty struct declarations with qualifiers are rejected by NVIDIA GL driver version 367.27. For example this kind of construct that is expected to be accepted by the WebGL conformance tests is rejected: const struct a { int i; }; Since qualifiers do not carry meaning unless a struct declaration has declarators, they can be simply omitted from the translator output in this kind of cases to work around this driver issue. New unit test is added to check that pruning empty declarations works correctly. BUG=angleproject:1430 BUG=622492 TEST=WebGL conformance tests, angle_unittests Change-Id: Id83f83124ae597fcdfa15100d336c2c207d9449c Reviewed-on: https://chromium-review.googlesource.com/356362Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent a8873ef5
...@@ -66,6 +66,27 @@ bool PruneEmptyDeclarationsTraverser::visitAggregate(Visit, TIntermAggregate *no ...@@ -66,6 +66,27 @@ bool PruneEmptyDeclarationsTraverser::visitAggregate(Visit, TIntermAggregate *no
ASSERT(parentAgg != nullptr); ASSERT(parentAgg != nullptr);
mMultiReplacements.push_back(NodeReplaceWithMultipleEntry(parentAgg, node, emptyReplacement)); mMultiReplacements.push_back(NodeReplaceWithMultipleEntry(parentAgg, node, emptyReplacement));
} }
else if (sym->getType().getQualifier() != EvqGlobal &&
sym->getType().getQualifier() != EvqTemporary)
{
// We've hit an empty struct declaration with a qualifier, for example like
// this:
// const struct a { int i; };
// NVIDIA GL driver version 367.27 doesn't accept this kind of declarations, so
// we convert the declaration to a regular struct declaration. This is okay,
// since ESSL 1.00 spec section 4.1.8 says about structs that "The optional
// qualifiers only apply to any declarators, and are not part of the type being
// defined for name."
if (mInGlobalScope)
{
sym->getTypePointer()->setQualifier(EvqGlobal);
}
else
{
sym->getTypePointer()->setQualifier(EvqTemporary);
}
}
} }
} }
return false; return false;
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
'<(angle_path)/src/tests/compiler_tests/MalformedShader_test.cpp', '<(angle_path)/src/tests/compiler_tests/MalformedShader_test.cpp',
'<(angle_path)/src/tests/compiler_tests/NV_draw_buffers_test.cpp', '<(angle_path)/src/tests/compiler_tests/NV_draw_buffers_test.cpp',
'<(angle_path)/src/tests/compiler_tests/Pack_Unpack_test.cpp', '<(angle_path)/src/tests/compiler_tests/Pack_Unpack_test.cpp',
'<(angle_path)/src/tests/compiler_tests/PruneEmptyDeclarations_test.cpp',
'<(angle_path)/src/tests/compiler_tests/PruneUnusedFunctions_test.cpp', '<(angle_path)/src/tests/compiler_tests/PruneUnusedFunctions_test.cpp',
'<(angle_path)/src/tests/compiler_tests/RecordConstantPrecision_test.cpp', '<(angle_path)/src/tests/compiler_tests/RecordConstantPrecision_test.cpp',
'<(angle_path)/src/tests/compiler_tests/RemovePow_test.cpp', '<(angle_path)/src/tests/compiler_tests/RemovePow_test.cpp',
......
//
// Copyright (c) 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.
//
// PruneEmptyDeclarations_test.cpp:
// Tests for pruning empty declarations.
//
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "GLSLANG/ShaderLang.h"
#include "tests/test_utils/compiler_test.h"
namespace
{
class PruneEmptyDeclarationsTest : public MatchOutputCodeTest
{
public:
PruneEmptyDeclarationsTest()
: MatchOutputCodeTest(GL_VERTEX_SHADER, 0, SH_GLSL_COMPATIBILITY_OUTPUT)
{
}
};
TEST_F(PruneEmptyDeclarationsTest, EmptyDeclarationStartsDeclaratorList)
{
const std::string shaderString =
"precision mediump float;\n"
"uniform float u;\n"
"void main()\n"
"{\n"
" float, f;\n"
" gl_Position = vec4(u * f);\n"
"}\n";
compile(shaderString);
ASSERT_TRUE(foundInCode("float f"));
ASSERT_TRUE(notFoundInCode("float, f"));
}
TEST_F(PruneEmptyDeclarationsTest, EmptyStructDeclarationWithQualifiers)
{
const std::string shaderString =
"precision mediump float;\n"
"const struct S { float f; };\n"
"uniform S s;"
"void main()\n"
"{\n"
" gl_Position = vec4(s.f);\n"
"}\n";
compile(shaderString);
ASSERT_TRUE(foundInCode("struct S"));
ASSERT_TRUE(foundInCode("uniform S"));
ASSERT_TRUE(notFoundInCode("const struct S"));
}
} // namespace
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