From a3a5e7ea4e2ec15dd385c169578f5770f49b6e1c Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 18 Apr 2024 23:01:45 -0700 Subject: Metal: rewrite global variables as explicit context. (#3981) * Metal: rewrite global variables as explicit context. * Small tweaks. --- source/slang/slang-emit.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index c00c7bfc3..b7227a4f0 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -69,6 +69,7 @@ #include "slang-ir-synthesize-active-mask.h" #include "slang-ir-validate.h" #include "slang-ir-wrap-structured-buffers.h" +#include "slang-ir-wrap-global-context.h" #include "slang-ir-liveness.h" #include "slang-ir-glsl-liveness.h" #include "slang-ir-translate-glsl-global-var.h" @@ -1082,6 +1083,12 @@ Result linkAndOptimizeIR( validateIRModuleIfEnabled(codeGenContext, irModule); } + // Metal does not allow global variables and global parameters, so + // we need to convert them into an explicit global context parameter + // passed around through a function parameter. + if (target == CodeGenTarget::Metal) + wrapGlobalScopeInContextType(irModule); + auto metadata = new ArtifactPostEmitMetadata; outLinkedIR.metadata = metadata; -- cgit v1.2.3