From ca68ef22e19dd2ba07d4f7f4624da7fcc05af09c Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Thu, 16 Jul 2020 11:45:38 -0700 Subject: [PATCH] update glslang to latest glslang repo SHA: f3cb1896971f449706bb1df5053d0e8fad6b0675 This fixes another highp bug. --- .../glslang/glslang/Include/intermediate.h | 1 + .../MachineIndependent/Intermediate.cpp | 32 +++++++++++++++++-- .../MachineIndependent/ParseHelper.cpp | 15 ++++++--- third_party/glslang/tnt/README.md | 17 +++++----- 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/third_party/glslang/glslang/Include/intermediate.h b/third_party/glslang/glslang/Include/intermediate.h index bf12fcf8f7..30cb6fb171 100644 --- a/third_party/glslang/glslang/Include/intermediate.h +++ b/third_party/glslang/glslang/Include/intermediate.h @@ -1231,6 +1231,7 @@ public: TOperator getFlowOp() const { return flowOp; } TIntermTyped* getExpression() const { return expression; } void setExpression(TIntermTyped* pExpression) { expression = pExpression; } + void updatePrecision(TPrecisionQualifier parentPrecision); protected: TOperator flowOp; TIntermTyped* expression; diff --git a/third_party/glslang/glslang/MachineIndependent/Intermediate.cpp b/third_party/glslang/glslang/MachineIndependent/Intermediate.cpp index 52ec6115f8..bb03aa0a15 100755 --- a/third_party/glslang/glslang/MachineIndependent/Intermediate.cpp +++ b/third_party/glslang/glslang/MachineIndependent/Intermediate.cpp @@ -2777,6 +2777,22 @@ TIntermBranch* TIntermediate::addBranch(TOperator branchOp, TIntermTyped* expres return node; } +// Propagate precision from formal function return type to actual return type, +// and on to its subtree. +void TIntermBranch::updatePrecision(TPrecisionQualifier parentPrecision) +{ + TIntermTyped* exp = getExpression(); + if (exp == nullptr) + return; + + if (exp->getBasicType() == EbtInt || exp->getBasicType() == EbtUint || + exp->getBasicType() == EbtFloat || exp->getBasicType() == EbtFloat16) { + if (parentPrecision != EpqNone && exp->getQualifier().precision == EpqNone) { + exp->propagatePrecision(parentPrecision); + } + } +} + // // This is to be executed after the final root is put on top by the parsing // process. @@ -3284,9 +3300,11 @@ bool TIntermediate::promoteUnary(TIntermUnary& node) return true; } +// Propagate precision qualifiers *up* from children to parent. void TIntermUnary::updatePrecision() { - if (getBasicType() == EbtInt || getBasicType() == EbtUint || getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + if (getBasicType() == EbtInt || getBasicType() == EbtUint || + getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { if (operand->getQualifier().precision > getQualifier().precision) getQualifier().precision = operand->getQualifier().precision; } @@ -3782,9 +3800,12 @@ bool TIntermediate::promoteAggregate(TIntermAggregate& node) return false; } +// Propagate precision qualifiers *up* from children to parent, and then +// back *down* again to the children's subtrees. void TIntermBinary::updatePrecision() { - if (getBasicType() == EbtInt || getBasicType() == EbtUint || getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { + if (getBasicType() == EbtInt || getBasicType() == EbtUint || + getBasicType() == EbtFloat || getBasicType() == EbtFloat16) { getQualifier().precision = std::max(right->getQualifier().precision, left->getQualifier().precision); if (getQualifier().precision != EpqNone) { left->propagatePrecision(getQualifier().precision); @@ -3793,9 +3814,14 @@ void TIntermBinary::updatePrecision() } } +// Recursively propagate precision qualifiers *down* the subtree of the current node, +// until reaching a node that already has a precision qualifier or otherwise does +// not participate in precision propagation. void TIntermTyped::propagatePrecision(TPrecisionQualifier newPrecision) { - if (getQualifier().precision != EpqNone || (getBasicType() != EbtInt && getBasicType() != EbtUint && getBasicType() != EbtFloat && getBasicType() != EbtFloat16)) + if (getQualifier().precision != EpqNone || + (getBasicType() != EbtInt && getBasicType() != EbtUint && + getBasicType() != EbtFloat && getBasicType() != EbtFloat16)) return; getQualifier().precision = newPrecision; diff --git a/third_party/glslang/glslang/MachineIndependent/ParseHelper.cpp b/third_party/glslang/glslang/MachineIndependent/ParseHelper.cpp index acdb0a4bcb..3d0f3293c4 100644 --- a/third_party/glslang/glslang/MachineIndependent/ParseHelper.cpp +++ b/third_party/glslang/glslang/MachineIndependent/ParseHelper.cpp @@ -1415,23 +1415,28 @@ TIntermNode* TParseContext::handleReturnValue(const TSourceLoc& loc, TIntermType #endif functionReturnsValue = true; + TIntermBranch* branch = nullptr; if (currentFunctionType->getBasicType() == EbtVoid) { error(loc, "void function cannot return a value", "return", ""); - return intermediate.addBranch(EOpReturn, loc); + branch = intermediate.addBranch(EOpReturn, loc); } else if (*currentFunctionType != value->getType()) { TIntermTyped* converted = intermediate.addConversion(EOpReturn, *currentFunctionType, value); if (converted) { if (*currentFunctionType != converted->getType()) error(loc, "cannot convert return value to function return type", "return", ""); if (version < 420) - warn(loc, "type conversion on return values was not explicitly allowed until version 420", "return", ""); - return intermediate.addBranch(EOpReturn, converted, loc); + warn(loc, "type conversion on return values was not explicitly allowed until version 420", + "return", ""); + branch = intermediate.addBranch(EOpReturn, converted, loc); } else { error(loc, "type does not match, or is not convertible to, the function's return type", "return", ""); - return intermediate.addBranch(EOpReturn, value, loc); + branch = intermediate.addBranch(EOpReturn, value, loc); } } else - return intermediate.addBranch(EOpReturn, value, loc); + branch = intermediate.addBranch(EOpReturn, value, loc); + + branch->updatePrecision(currentFunctionType->getQualifier().precision); + return branch; } // See if the operation is being done in an illegal location. diff --git a/third_party/glslang/tnt/README.md b/third_party/glslang/tnt/README.md index de4ec25fcf..7514cab466 100644 --- a/third_party/glslang/tnt/README.md +++ b/third_party/glslang/tnt/README.md @@ -4,16 +4,15 @@ To update glslang use the following steps: - Run the following commands (on Mac) to unzip and copy the new source files: ``` -cd third_party/glslang -unzip glslang-master.zip -rsync --remove-source-files -ra glslang-master/ ./ -rm -r glslang-master.zip glslang-master -``` - -The `Test` folder can be removed, as it is not needed: - -``` +cd third_party +curl -L https://github.com/KhronosGroup/glslang/archive/master.zip > main.zip +unzip main.zip +rsync -r glslang-master/ glslang/ --delete +rm -r main.zip glslang-master rm -rf glslang/Test/ +git checkout glslang/*/tnt/* +git restore glslang/LICENSE +git add glslang ``` - If necessary, update the `DefaultTBuiltInResource` definition inside `libs/filamat/src/sca/builtinResource.h` to glslang's located at