diff options
| author | Yong He <yonghe@outlook.com> | 2023-12-13 15:15:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-13 15:15:19 -0800 |
| commit | 3979660d4fe1fd6c1f1d9b8956e96817e17c3f4e (patch) | |
| tree | a1777fc23e2983c5dbe630d39e529c798953484c /source/slang/slang-lower-to-ir.cpp | |
| parent | 1406aa2bc9e398e5e5565ba9c6adbb780c29fee1 (diff) | |
Fix GLSL static initialization bug. (#3409)
* Fix GLSL static initialization bug.
Fixes #3408.
* Update comment.
* Fold global var initializer as an expression if possible.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 146f54932..7621f3080 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -7661,23 +7661,20 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // // if(!isInitialized) { <globalVal> = <initExpr>; isInitialized = true; } // - // TODO: we could conceivably optimize this by detecting - // when the `initExpr` lowers to just a reference to a constant, - // and then either deleting the extra code structure there, - // or not generating it in the first place. That is a bit - // more complexity than I'm ready for at the moment. + // This will generate a lot of boilterplate code, but we optimize out the + // boilerplate functions later during `moveGlobalVarInitializationToEntryPoints` + // if we see the init function is just returning a global constant. // auto boolBuilder = subBuilder; auto irBoolType = boolBuilder->getBoolType(); auto irBool = boolBuilder->createGlobalVar(irBoolType); boolBuilder->setInsertInto(irBool); - boolBuilder->setInsertInto(boolBuilder->createBlock()); + boolBuilder->emitBlock(); boolBuilder->emitReturn(boolBuilder->getBoolValue(false)); auto boolVal = LoweredValInfo::ptr(irBool); - // Okay, with our global Boolean created, we can move on to // generating the code we actually care about, back in the original function. |
