From 1fde51d3fbf32e9d383cf82b512e9efa2d9a75b7 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Mon, 1 Jul 2013 17:56:24 +0000 Subject: [PATCH] 1) Don't propagate precision of built-in function arguments to return type when return type is bool (e.g., isnan). 2) Check an additional path for missing default precision qualification, except allow built-in declarations to pass the check. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22241 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- Test/switch.frag | 2 +- glslang/MachineIndependent/Intermediate.cpp | 2 +- glslang/MachineIndependent/ParseHelper.cpp | 13 +++++++++---- glslang/MachineIndependent/ParseHelper.h | 3 ++- glslang/MachineIndependent/ShaderLang.cpp | 4 ++-- glslang/MachineIndependent/glslang.y | 2 ++ 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Test/switch.frag b/Test/switch.frag index 6924b3e9..05a5a957 100644 --- a/Test/switch.frag +++ b/Test/switch.frag @@ -1,5 +1,5 @@ #version 300 es - +precision highp float; uniform int c, d; in highp float x; diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index df807e8d..6a1e65f2 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -289,7 +289,7 @@ TIntermTyped* TIntermediate::addBuiltInFunctionCall(TOperator op, bool unary, TI node->setType(returnType); // propagate precision up from child - if (returnType.getQualifier().precision == EpqNone && profile == EEsProfile) + if (profile == EEsProfile && returnType.getQualifier().precision == EpqNone && returnType.getBasicType() != EbtBool) node->getQualifier().precision = child->getQualifier().precision; // propagate precision down to child diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index e675ff73..d6ac017a 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -40,11 +40,11 @@ #include #include -TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, int v, EProfile p, EShLanguage L, TInfoSink& is, +TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, bool pb, int v, EProfile p, EShLanguage L, TInfoSink& is, bool fc, EShMessages m) : intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0), linkage(0), numErrors(0), lexAfterType(false), loopNestingLevel(0), - structNestingLevel(0), inTypeParen(false), + structNestingLevel(0), inTypeParen(false), parsingBuiltins(pb), version(v), profile(p), forwardCompatible(fc), messages(m), contextPragma(true, false) { @@ -885,12 +885,17 @@ TPrecisionQualifier TParseContext::getDefaultPrecision(TPublicType& publicType) void TParseContext::precisionQualifierCheck(int line, TPublicType& publicType) { - if (profile != EEsProfile) + // Built-in symbols are allowed some ambiguous precisions, to be pinned down + // later by context. + if (profile != EEsProfile || parsingBuiltins) return; if (publicType.basicType == EbtFloat || publicType.basicType == EbtUint || publicType.basicType == EbtInt || publicType.basicType == EbtSampler) { - if (publicType.qualifier.precision == EpqNone) + if (publicType.qualifier.precision == EpqNone) { error(line, "type requires declaration of default precision qualifier", TType::getBasicString(publicType.basicType), ""); + publicType.qualifier.precision = EpqMedium; + defaultPrecision[publicType.basicType] = EpqMedium; + } } else if (publicType.qualifier.precision != EpqNone) error(line, "type cannot have precision qualifier", TType::getBasicString(publicType.basicType), ""); } diff --git a/glslang/MachineIndependent/ParseHelper.h b/glslang/MachineIndependent/ParseHelper.h index bdb866d5..aa7962d5 100644 --- a/glslang/MachineIndependent/ParseHelper.h +++ b/glslang/MachineIndependent/ParseHelper.h @@ -62,7 +62,7 @@ struct TPragma { // they can be passed to the parser without needing a global. // struct TParseContext { - TParseContext(TSymbolTable&, TIntermediate&, int version, EProfile, EShLanguage, TInfoSink&, + TParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins, int version, EProfile, EShLanguage, TInfoSink&, bool forwardCompatible = false, EShMessages messages = EShMsgDefault); TIntermediate& intermediate; // to hold and build a parse tree TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile @@ -78,6 +78,7 @@ struct TParseContext { bool inTypeParen; // true if in parentheses, looking only for an identifier const TType* currentFunctionType; // the return type of the function that's currently being parsed bool functionReturnsValue; // true if a non-void function has a return + bool parsingBuiltins; // true if parsing built-in symbols/functions int version; // version, updated by #version in the shader EProfile profile; // the declared profile in the shader (core by default) diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index bf5a00f2..20533d33 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -98,7 +98,7 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil else symbolTable = &symbolTables[language]; - TParseContext parseContext(*symbolTable, intermediate, version, profile, language, infoSink); + TParseContext parseContext(*symbolTable, intermediate, true, version, profile, language, infoSink); GlobalParseContext = &parseContext; @@ -411,7 +411,7 @@ int ShCompile( // they get popped again further down. AddContextSpecificSymbols(resources, compiler->infoSink, &symbolTable, version, profile, compiler->getLanguage()); - TParseContext parseContext(symbolTable, intermediate, version, profile, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages); + TParseContext parseContext(symbolTable, intermediate, false, version, profile, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages); if (! goodProfile) parseContext.error(1, "incorrect", "#version", ""); diff --git a/glslang/MachineIndependent/glslang.y b/glslang/MachineIndependent/glslang.y index a176ccf3..a3429563 100644 --- a/glslang/MachineIndependent/glslang.y +++ b/glslang/MachineIndependent/glslang.y @@ -1483,6 +1483,8 @@ fully_specified_type if (parseContext.profile == EEsProfile) parseContext.arraySizeRequiredCheck($1.line, $1.arraySizes->front()); } + + parseContext.precisionQualifierCheck($$.line, $$); } | type_qualifier type_specifier { parseContext.globalQualifierFix($1.line, $1.qualifier, $2);