Commit 97366a0d by John Kessenich

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

parent a4c64c98
static bool a, b = true;
float4 main() : SV_Position
{
int r = 0;
r += a + b;
r += a - b;
r += a * b;
r += a / b;
r += a % b;
r += a & b;
r += a | b;
r += a ^ b;
r += a << b;
r += a >> b;
return r;
}
\ No newline at end of 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"
......@@ -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:
......
......@@ -89,6 +89,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.attribute.expression.comp", "main"},
{"hlsl.basic.comp", "main"},
{"hlsl.basic.geom", "main"},
{"hlsl.boolConv.vert", "main"},
{"hlsl.buffer.frag", "PixelShaderFunction"},
{"hlsl.calculatelod.dx10.frag", "main"},
{"hlsl.calculatelodunclamped.dx10.frag", "main"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment