From 3979660d4fe1fd6c1f1d9b8956e96817e17c3f4e Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 13 Dec 2023 15:15:19 -0800 Subject: 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 --- source/slang/slang-lower-to-ir.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') 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 // // if(!isInitialized) { = ; 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. -- cgit v1.2.3