Diff
Modified: trunk/Source/ThirdParty/ANGLE/ChangeLog (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/ChangeLog 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/ChangeLog 2021-04-12 19:01:07 UTC (rev 275832)
@@ -1,3 +1,22 @@
+2021-04-12 Kyle Piddington <[email protected]>
+
+ Crash in webgl/2.0.y/conformance/glsl/misc/uninitialized-local-global-variables.html ANGLE+METAL
+ https://bugs.webkit.org/show_bug.cgi?id=223923
+
+ Anonymous structs require a name in MSL, add a default name ANGLE__unnamed$id to any structs.
+ Also add a unit test to ensure this works.
+ Reviewed by Kenneth Russell.
+
+ * src/compiler/translator/TranslatorMetalDirect.cpp:
+ (sh::TranslatorMetalDirect::translateImpl):
+ * src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp:
+ (sh::Separator::Separator):
+ (sh::SeparateCompoundStructDeclarations):
+ * src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h:
+ * src/tests/BUILD.gn:
+ * src/tests/angle_unittests.gni:
+ * src/tests/compiler_tests/MSLOutput_Test.cpp:
+
2021-04-08 Kyle Piddington <[email protected]>
[Metal-ANGLE] Support GPU power preferences, select low-power GPU by default.
Modified: trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.cpp 2021-04-12 19:01:07 UTC (rev 275832)
@@ -9,6 +9,7 @@
#include "compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h"
#include "compiler/translator/tree_ops/SeparateDeclarations.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
+#include "compiler/translator/TranslatorMetalDirect/AstHelpers.h"
using namespace sh;
@@ -21,37 +22,55 @@
{
public:
std::unordered_map<int, TIntermSymbol *> replacementMap;
- Separator(TSymbolTable &symbolTable) : TIntermTraverser(false, false, true, &symbolTable) {}
-
+ Separator(TSymbolTable &symbolTable, IdGen &idGen) : TIntermTraverser(false, false, true, &symbolTable),
+ mIdGen(idGen)
+ {}
+ IdGen &mIdGen;
bool visitDeclaration(Visit, TIntermDeclaration *declNode) override
{
ASSERT(declNode->getChildCount() == 1);
- TIntermNode &node = *declNode->getChildNode(0);
+ Declaration declaration = ViewDeclaration(*declNode);
- if (TIntermSymbol *symbolNode = node.getAsSymbolNode())
+ const TVariable &var = declaration.symbol.variable();
+ const TType &type = var.getType();
+ const SymbolType symbolType = var.symbolType();
+ if (type.isStructSpecifier() && symbolType != SymbolType::Empty)
{
- const TVariable &var = symbolNode->variable();
- const TType &type = var.getType();
- const SymbolType symbolType = var.symbolType();
- if (type.isStructSpecifier() && symbolType != SymbolType::Empty)
+ const TStructure *structure = type.getStruct();
+ TVariable *structVar = nullptr;
+ TType * instanceType = nullptr;
+ //Name unnamed inline structs
+ if(structure->symbolType() == SymbolType::Empty)
{
- const TStructure *structure = type.getStruct();
- auto *structVar = new TVariable(mSymbolTable, ImmutableString(""),
+ const TStructure * structDefn = new TStructure(mSymbolTable, mIdGen.createNewName("__unnamed").rawName(), &(structure->fields()) , SymbolType::AngleInternal);
+ structVar = new TVariable(mSymbolTable, ImmutableString(""),
+ new TType(structDefn, true), SymbolType::Empty);
+ instanceType = new TType(structDefn, false);
+ }
+ else
+ {
+ structVar = new TVariable(mSymbolTable, ImmutableString(""),
new TType(structure, true), SymbolType::Empty);
+ instanceType = new TType(structure, false);
+ }
+ instanceType->setQualifier(type.getQualifier());
+ auto *instanceVar = new TVariable(mSymbolTable, var.name(), instanceType,
+ symbolType, var.extension());
- auto *instanceType = new TType(structure, false);
- instanceType->setQualifier(type.getQualifier());
- auto *instanceVar = new TVariable(mSymbolTable, var.name(), instanceType,
- symbolType, var.extension());
+ TIntermSequence replacements;
+ replacements.push_back(new TIntermSymbol(structVar));
- TIntermSequence replacements;
- TIntermSymbol * instanceSymbol = new TIntermSymbol(instanceVar);
- replacements.push_back(new TIntermSymbol(structVar));
- replacements.push_back(instanceSymbol);
- replacementMap[symbolNode->uniqueId().get()] = instanceSymbol;
- mMultiReplacements.push_back(
- NodeReplaceWithMultipleEntry(declNode, symbolNode, std::move(replacements)));
+ TIntermSymbol * instanceSymbol = new TIntermSymbol(instanceVar);
+ TIntermNode * instanceReplacement = instanceSymbol;
+ if(declaration.initExpr)
+ {
+ instanceReplacement = new TIntermBinary(EOpInitialize, instanceSymbol, declaration.initExpr);
}
+ replacements.push_back(instanceReplacement);
+
+ replacementMap[declaration.symbol.uniqueId().get()] = instanceSymbol;
+ mMultiReplacements.push_back(
+ NodeReplaceWithMultipleEntry(declNode, declNode->getChildNode(0), std::move(replacements)));
}
return false;
@@ -71,9 +90,9 @@
////////////////////////////////////////////////////////////////////////////////
-bool sh::SeparateCompoundStructDeclarations(TCompiler &compiler, TIntermBlock &root)
+bool sh::SeparateCompoundStructDeclarations(TCompiler &compiler, IdGen &idGen, TIntermBlock &root)
{
- Separator separator(compiler.getSymbolTable());
+ Separator separator(compiler.getSymbolTable(), idGen);
root.traverse(&separator);
if (!separator.updateTree(&compiler, &root))
{
Modified: trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect/SeparateCompoundStructDeclarations.h 2021-04-12 19:01:07 UTC (rev 275832)
@@ -9,7 +9,7 @@
#include "common/angleutils.h"
#include "compiler/translator/Compiler.h"
-
+#include "compiler/translator/TranslatorMetalDirect/IdGen.h"
namespace sh
{
@@ -17,7 +17,7 @@
// struct Foo { int x; } foo;
// Becomes:
// struct Foo {int x; }; Foo foo;
-ANGLE_NO_DISCARD bool SeparateCompoundStructDeclarations(TCompiler &compiler, TIntermBlock &root);
+ANGLE_NO_DISCARD bool SeparateCompoundStructDeclarations(TCompiler &compiler, IdGen &idGen, TIntermBlock &root);
} // namespace sh
Modified: trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect.cpp (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect.cpp 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/src/compiler/translator/TranslatorMetalDirect.cpp 2021-04-12 19:01:07 UTC (rev 275832)
@@ -1435,7 +1435,7 @@
return false;
}
- if (!SeparateCompoundStructDeclarations(*this, root))
+ if (!SeparateCompoundStructDeclarations(*this, idGen, root))
{
return false;
}
Modified: trunk/Source/ThirdParty/ANGLE/src/tests/BUILD.gn (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/tests/BUILD.gn 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/src/tests/BUILD.gn 2021-04-12 19:01:07 UTC (rev 275832)
@@ -117,6 +117,11 @@
sources += angle_unittests_hlsl_sources
defines = [ "ANGLE_ENABLE_HLSL" ]
}
+
+ if (angle_enable_metal) {
+ sources += angle_unittests_msl_sources
+ defines += [ "ANGLE_ENABLE_METAL", "ANGLE_ENABLE_METAL_SPIRV" ]
+ }
deps = [
":angle_test_expectations",
Modified: trunk/Source/ThirdParty/ANGLE/src/tests/angle_unittests.gni (275831 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/tests/angle_unittests.gni 2021-04-12 18:48:25 UTC (rev 275831)
+++ trunk/Source/ThirdParty/ANGLE/src/tests/angle_unittests.gni 2021-04-12 19:01:07 UTC (rev 275832)
@@ -154,6 +154,8 @@
[ "../tests/compiler_tests/ImmutableString_test_autogen.cpp" ]
}
+angle_unittests_msl_sources = [ "../tests/compiler_tests/MSLOutput_test.cpp" ]
+
if (!is_android && !is_fuchsia) {
angle_unittests_sources +=
[ "../tests/test_utils/runner/TestSuite_unittest.cpp" ]
Added: trunk/Source/ThirdParty/ANGLE/src/tests/compiler_tests/MSLOutput_test.cpp (0 => 275832)
--- trunk/Source/ThirdParty/ANGLE/src/tests/compiler_tests/MSLOutput_test.cpp (rev 0)
+++ trunk/Source/ThirdParty/ANGLE/src/tests/compiler_tests/MSLOutput_test.cpp 2021-04-12 19:01:07 UTC (rev 275832)
@@ -0,0 +1,43 @@
+//
+// Copyright 2017 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.
+//
+// MSLOutput_test.cpp:
+// Tests for MSL output.
+//
+
+#include <regex>
+#include "GLSLANG/ShaderLang.h"
+#include "angle_gl.h"
+#include "gtest/gtest.h"
+#include "tests/test_utils/compiler_test.h"
+
+using namespace sh;
+
+class MSLVertexOutputTest : public MatchOutputCodeTest
+{
+ public:
+ MSLVertexOutputTest() : MatchOutputCodeTest(GL_VERTEX_SHADER, 0, SH_MSL_METAL_OUTPUT) {}
+};
+
+class MSLOutputTest : public MatchOutputCodeTest
+{
+ public:
+ MSLOutputTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_MSL_METAL_OUTPUT) {}
+};
+
+TEST_F(MSLOutputTest, AnonymousStruct)
+{
+ const std::string &shaderString =
+ R"(
+ precision mediump float;
+ struct { vec4 v; } anonStruct;
+ void main() {
+ anonStruct.v = vec4(0.0,1.0,0.0,1.0);
+ gl_FragColor = anonStruct.v;
+ })";
+ compile(shaderString, SH_VARIABLES);
+ ASSERT_TRUE(foundInCode(SH_MSL_METAL_OUTPUT, "__unnamed"));
+}
+