Skip to content

Commit

Permalink
Fixup for the glslang bug workaround
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tangent-vector committed Jul 24, 2017
1 parent 1d4633f commit e7241a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 9 additions & 1 deletion source/slang/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions tests/rewriter/glslang-bug-988-workaround.frag
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ out vec4 result;

void main()
{
result = doIt(foo);
vec4 r = doIt(foo);
result = r;
}

#else
Expand All @@ -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

0 comments on commit e7241a9

Please sign in to comment.