Commit 78507c6e by Olli Etuaho Committed by Commit Bot

Fix statements disappearing from switch statements in HLSL

RemoveSwitchFallThrough now correctly records the existence of declaration and swizzle statements inside switch statements. BUG=angleproject:2177 TEST=angle_end2end_tests Change-Id: I1ef83997db7ae510ded002a9568c29272c00c2fe Reviewed-on: https://chromium-review.googlesource.com/709195Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent bd159f06
...@@ -28,9 +28,11 @@ class RemoveSwitchFallThroughTraverser : public TIntermTraverser ...@@ -28,9 +28,11 @@ class RemoveSwitchFallThroughTraverser : public TIntermTraverser
void visitSymbol(TIntermSymbol *node) override; void visitSymbol(TIntermSymbol *node) override;
void visitConstantUnion(TIntermConstantUnion *node) override; void visitConstantUnion(TIntermConstantUnion *node) override;
bool visitDeclaration(Visit, TIntermDeclaration *node) override;
bool visitBinary(Visit, TIntermBinary *node) override; bool visitBinary(Visit, TIntermBinary *node) override;
bool visitUnary(Visit, TIntermUnary *node) override; bool visitUnary(Visit, TIntermUnary *node) override;
bool visitTernary(Visit visit, TIntermTernary *node) override; bool visitTernary(Visit visit, TIntermTernary *node) override;
bool visitSwizzle(Visit, TIntermSwizzle *node) override;
bool visitIfElse(Visit visit, TIntermIfElse *node) override; bool visitIfElse(Visit visit, TIntermIfElse *node) override;
bool visitSwitch(Visit, TIntermSwitch *node) override; bool visitSwitch(Visit, TIntermSwitch *node) override;
bool visitCase(Visit, TIntermCase *node) override; bool visitCase(Visit, TIntermCase *node) override;
...@@ -90,6 +92,13 @@ void RemoveSwitchFallThroughTraverser::visitConstantUnion(TIntermConstantUnion * ...@@ -90,6 +92,13 @@ void RemoveSwitchFallThroughTraverser::visitConstantUnion(TIntermConstantUnion *
mLastStatementWasBreak = false; mLastStatementWasBreak = false;
} }
bool RemoveSwitchFallThroughTraverser::visitDeclaration(Visit, TIntermDeclaration *node)
{
mPreviousCase->getSequence()->push_back(node);
mLastStatementWasBreak = false;
return false;
}
bool RemoveSwitchFallThroughTraverser::visitBinary(Visit, TIntermBinary *node) bool RemoveSwitchFallThroughTraverser::visitBinary(Visit, TIntermBinary *node)
{ {
mPreviousCase->getSequence()->push_back(node); mPreviousCase->getSequence()->push_back(node);
...@@ -111,6 +120,13 @@ bool RemoveSwitchFallThroughTraverser::visitTernary(Visit, TIntermTernary *node) ...@@ -111,6 +120,13 @@ bool RemoveSwitchFallThroughTraverser::visitTernary(Visit, TIntermTernary *node)
return false; return false;
} }
bool RemoveSwitchFallThroughTraverser::visitSwizzle(Visit, TIntermSwizzle *node)
{
mPreviousCase->getSequence()->push_back(node);
mLastStatementWasBreak = false;
return false;
}
bool RemoveSwitchFallThroughTraverser::visitIfElse(Visit, TIntermIfElse *node) bool RemoveSwitchFallThroughTraverser::visitIfElse(Visit, TIntermIfElse *node)
{ {
mPreviousCase->getSequence()->push_back(node); mPreviousCase->getSequence()->push_back(node);
......
...@@ -3477,6 +3477,28 @@ TEST_P(GLSLTest_ES3, NestedArrayLengthMethodsWithSideEffects) ...@@ -3477,6 +3477,28 @@ TEST_P(GLSLTest_ES3, NestedArrayLengthMethodsWithSideEffects)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
} }
// Test that statements inside switch() get translated to correct HLSL.
TEST_P(GLSLTest_ES3, DifferentStatementsInsideSwitch)
{
const std::string &fragmentShader =
R"(#version 300 es
precision highp float;
uniform int u;
void main()
{
switch (u)
{
case 0:
ivec2 i;
i.yx;
}
})";
ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(GLSLTest, ANGLE_INSTANTIATE_TEST(GLSLTest,
ES2_D3D9(), ES2_D3D9(),
......
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