From 9df6aa5361540812ca3a969baaa8312a4ce4795b Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 5 Dec 2016 21:36:48 -0700 Subject: [PATCH] GLSL: Allow desktop shaders to call functions from outside main(). Fixes issue #239. --- Test/baseResults/110scope.vert.out | 3 +-- glslang/Include/revision.h | 4 ++-- glslang/MachineIndependent/ParseHelper.cpp | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Test/baseResults/110scope.vert.out b/Test/baseResults/110scope.vert.out index 5f41b86b..dd532503 100644 --- a/Test/baseResults/110scope.vert.out +++ b/Test/baseResults/110scope.vert.out @@ -1,9 +1,8 @@ 110scope.vert ERROR: 0:5: 'a' : redefinition -ERROR: 0:34: 'f' : can't call user function from global scope ERROR: 0:57: 'z' : undeclared identifier ERROR: 0:57: 'z' : redefinition -ERROR: 4 compilation errors. No code generated. +ERROR: 3 compilation errors. No code generated. Shader version: 110 diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index e4eb266c..c53a14dc 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1674" -#define GLSLANG_DATE "03-Dec-2016" +#define GLSLANG_REVISION "Overload400-PrecQual.1676" +#define GLSLANG_DATE "05-Dec-2016" diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 831e3ac0..ce7fa4be 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1109,9 +1109,10 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction // if builtIn == true, it's definitely a built-in function with EOpNull if (! builtIn) { call->setUserDefined(); - if (symbolTable.atGlobalLevel()) - error(loc, "can't call user function from global scope", fnCandidate->getName().c_str(), ""); - else + if (symbolTable.atGlobalLevel()) { + requireProfile(loc, ~EEsProfile, "calling user function from global scope"); + intermediate.addToCallGraph(infoSink, "main(", fnCandidate->getMangledName()); + } else intermediate.addToCallGraph(infoSink, currentCaller, fnCandidate->getMangledName()); }