summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-23 19:52:14 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-23 19:52:14 -0700
commite7241a921407ae79e0767956127f7ed501c5eeb1 (patch)
treebe9330c4519a33e76b93819e5676d1b0c137880b
parent1d4633fe67d23767ca41fe71b90687df1ab5e402 (diff)
Fixup for the glslang bug workaround
There was a bug where the intialization expression for a variable was being lowered after the declaration was added to the output code, so that any sub-expressions that get hoisted out actually get computed *after* the original variable. This obviously led to downstream compilation failure. I've updated the test case to stress this scenario.
-rw-r--r--source/slang/lower.cpp10
-rw-r--r--tests/rewriter/glslang-bug-988-workaround.frag6
2 files changed, 13 insertions, 3 deletions
diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp
index d634b114b..ba6b48509 100644
--- a/source/slang/lower.cpp
+++ b/source/slang/lower.cpp
@@ -3006,8 +3006,16 @@ return loweredExpr;
}
RefPtr<VarDeclBase> loweredDecl = loweredDeclClass.createInstance();
+
+ // Note: we lower the declaration (including its initialization expression, if any)
+ // *before* we add the declaration to the current context (e.g., a statement being
+ // built), so that any operations inside the initialization expression that
+ // might need to inject statements/temporaries/whatever happen *before*
+ // the declaration of this variable.
+ auto result = lowerSimpleVarDeclCommon(loweredDecl, decl, loweredType);
addDecl(loweredDecl);
- return lowerSimpleVarDeclCommon(loweredDecl, decl, loweredType);
+
+ return result;
}
RefPtr<VarDeclBase> lowerVarDeclCommon(
diff --git a/tests/rewriter/glslang-bug-988-workaround.frag b/tests/rewriter/glslang-bug-988-workaround.frag
index 8c9692aed..578b49236 100644
--- a/tests/rewriter/glslang-bug-988-workaround.frag
+++ b/tests/rewriter/glslang-bug-988-workaround.frag
@@ -25,7 +25,8 @@ out vec4 result;
void main()
{
- result = doIt(foo);
+ vec4 r = doIt(foo);
+ result = r;
}
#else
@@ -52,7 +53,8 @@ out vec4 result;
void main()
{
Foo SLANG_tmp_0 = foo;
- result = doIt(SLANG_tmp_0);
+ vec4 r = doIt(SLANG_tmp_0);
+ result = r;
}
#endif