From dc0e9d7bca21d8a67ec9f044c0d390bda6ebfcbf Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 17 Jul 2017 10:51:18 -0700 Subject: Pick correct GLSL version when `gl_Layer` used `gl_Layer` as a fragment input requires at least version 4.30 of GLSL, so we try to track that information when we see the name used. Note that this does *not* override a user-specified `#version` line. This required re-ordering when lowering happens relative to emitting the `#version` directive, since this code works by actually modifying the chosen profile for the entry point. Yes, that is kind of gross and we should do something cleaner in the long term. --- source/slang/lower.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'source/slang/lower.cpp') diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index 856da9b6c..98f6d8273 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -221,7 +221,8 @@ public: struct SharedLoweringContext { - CompileRequest* compileRequest; + CompileRequest* compileRequest; + EntryPointRequest* entryPointRequest; ProgramLayout* programLayout; EntryPointLayout* entryPointLayout; @@ -2329,6 +2330,31 @@ struct LoweringVisitor return false; } + void requireGLSLVersion(ProfileVersion version) + { + if (shared->target != CodeGenTarget::GLSL) + return; + + auto entryPoint = shared->entryPointRequest; + auto profile = entryPoint->profile; + auto currentVersion = profile.GetVersion(); + if (profile.getFamily() == ProfileFamily::GLSL) + { + // Check if this profile is newer + if ((UInt)version > (UInt)profile.GetVersion()) + { + profile.setVersion(version); + entryPoint->profile = profile; + } + } + else + { + // Non-GLSL target? Set it to a GLSL one. + profile.setVersion(version); + entryPoint->profile = profile; + } + } + void lowerSimpleShaderParameterToGLSLGlobal( VaryingParameterInfo const& info, RefPtr varType, @@ -2460,6 +2486,10 @@ struct LoweringVisitor } else if (ns == "sv_rendertargetarrayindex") { + if (info.direction == VaryingParameterDirection::Input) + { + requireGLSLVersion(ProfileVersion::GLSL_430); + } globalVarExpr = createGLSLBuiltinRef("gl_Layer"); } else if (ns == "sv_sampleindex") @@ -3040,6 +3070,7 @@ LoweredEntryPoint lowerEntryPoint( { SharedLoweringContext sharedContext; sharedContext.compileRequest = entryPoint->compileRequest; + sharedContext.entryPointRequest = entryPoint; sharedContext.programLayout = programLayout; sharedContext.target = target; -- cgit v1.2.3