diff options
| author | Yong He <yonghe@outlook.com> | 2017-11-21 19:55:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-21 19:55:23 -0500 |
| commit | cd2d64657e3e07fba0a2021d5e47b7a55bd293e6 (patch) | |
| tree | c2ed83c02ddb8587f7f5f6ee26e004baafec315c /source/slang/emit.cpp | |
| parent | 43434bf993870ac19722d3a00df704df130619c1 (diff) | |
| parent | 37315c96ea48045fae60f0e1cb1a3293f3ddd962 (diff) | |
Merge branch 'master' into generic-param-fix
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 383442236..4cad7b28d 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -6461,7 +6461,23 @@ emitDeclImpl(decl, nullptr); { auto allocatedType = varDecl->getType(); auto varType = allocatedType->getValueType(); -// auto addressSpace = allocatedType->getAddressSpace(); + + String initFuncName; + if (varDecl->firstBlock) + { + // A global variable with code means it has an initializer + // associated with it. Eventually we'd like to emit that + // initializer directly as an expression here, but for + // now we'll emit it as a separate function. + + initFuncName = getIRName(varDecl); + initFuncName.append("_init"); + emitIRType(ctx, varType, initFuncName); + Emit("()\n{\n"); + emitIRStmtsForBlocks(ctx, varDecl->firstBlock, nullptr); + Emit("}\n"); + } + if (auto paramBlockType = varType->As<UniformParameterGroupType>()) { @@ -6475,20 +6491,27 @@ emitDeclImpl(decl, nullptr); // Need to emit appropriate modifiers here. auto layout = getVarLayout(ctx, varDecl); - - emitIRVarModifiers(ctx, layout); -#if 0 - switch (addressSpace) + if (!layout) { - default: - break; + // A global variable without a layout is just an + // ordinary global variable, and may need special + // modifiers to indicate it as such. + switch (getTarget(ctx)) + { + case CodeGenTarget::HLSL: + // HLSL requires the `static` modifier on any + // global variables; otherwise they are assumed + // to be uniforms. + Emit("static "); + break; - case kIRAddressSpace_GroupShared: - emit("groupshared "); - break; + default: + break; + } } -#endif + + emitIRVarModifiers(ctx, layout); emitIRType(ctx, varType, getIRName(varDecl)); @@ -6496,6 +6519,13 @@ emitDeclImpl(decl, nullptr); emitIRLayoutSemantics(ctx, varDecl); + if (varDecl->firstBlock) + { + Emit(" = "); + emit(initFuncName); + Emit("()"); + } + emit(";\n"); } |
