From 6da1782f34e8022774dce8d253bc5c3ab9b496cc Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 6 Jul 2017 20:47:20 -0700 Subject: Don't emit the `static` keyword when generating GLSL GLSL doesn't support `static` at all, while HLSL uses it for multiple things: - To mark global variables that are "thread local" rather than shader parameters - In the C/C++ style to mark `static` allocation for variables inside a function or type The latter case needs to be handled during lowering (but isn't handled right now). The former case can be solved just by dropping the `static` keyword. --- source/slang/emit.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 08d2218dc..48644cc6f 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -2021,7 +2021,6 @@ static void EmitModifiers(EmitContext* context, RefPtr decl) CASE(HLSLPreciseModifier, precise); CASE(HLSLEffectSharedModifier, shared); CASE(HLSLGroupSharedModifier, groupshared); - CASE(HLSLStaticModifier, static); CASE(HLSLUniformModifier, uniform); CASE(HLSLVolatileModifier, volatile); @@ -2043,6 +2042,27 @@ static void EmitModifiers(EmitContext* context, RefPtr decl) #undef CASE + else if (auto staticModifier = mod.As()) + { + // GLSL does not support the `static` keyword. + // HLSL uses it both to mark global variables as being "thread-local" + // (rather than shader inputs), and also seems to support function-`static` + // variables. + // The latter case needs to be dealt with in lowering anyway, so that + // we only need to deal with globals here, and GLSL variables + // don't need a `static` modifier anyway. + + switch(context->shared->target) + { + default: + Emit(context, "static"); + break; + + case CodeGenTarget::GLSL: + break; + } + } + // TODO: eventually we should be checked these modifiers, but for // now we can emit them unchecked, I guess else if (auto uncheckedAttr = mod.As()) -- cgit v1.2.3