HLSL: Fix #770: implicitly convert bool operands to numeric operators.

This commit is contained in:
John Kessenich
2017-04-12 22:37:32 -06:00
parent a4c64c988c
commit 97366a0df0
5 changed files with 425 additions and 2 deletions

View File

@@ -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.1998"
#define GLSLANG_REVISION "Overload400-PrecQual.2000"
#define GLSLANG_DATE "12-Apr-2017"

View File

@@ -623,7 +623,10 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
node->getType().getBasicType() == EbtUint64))
return node;
else
else if (source == EShSourceHlsl && node->getType().getBasicType() == EbtBool) {
promoteTo = type.getBasicType();
break;
} else
return nullptr;
default:
@@ -1988,6 +1991,42 @@ bool TIntermediate::promoteBinary(TIntermBinary& node)
// We now have only scalars, vectors, and matrices to worry about.
//
// HLSL implicitly promotes bool -> int for numeric operations.
// (Implicit conversions to make the operands match each other's types were already done.)
if (getSource() == EShSourceHlsl &&
(left->getBasicType() == EbtBool || right->getBasicType() == EbtBool)) {
switch (op) {
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
case EOpRightShift:
case EOpLeftShift:
case EOpMod:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
left = addConversion(op, TType(EbtInt, EvqTemporary, left->getVectorSize()), left);
right = addConversion(op, TType(EbtInt, EvqTemporary, right->getVectorSize()), right);
if (left == nullptr || right == nullptr)
return false;
node.setLeft(left);
node.setRight(right);
break;
default:
break;
}
}
// Do general type checks against individual operands (comparing left and right is coming up, checking mixed shapes after that)
switch (op) {
case EOpLessThan: