Use the correct type for the constant for matrix/scalar division

When a matrix is divided by a scalar it tries to take the reciprocal
of the scalar to convert the operation into a multiply. However it was
always doing this by making a 32-bit constant. If the scalar is a
double then this would end up making an FDiv instruction with
different types in the operands.

This patch adds a helper method called makeFpConstant which makes a
floating-point constant of the given type. The code to take the
reciprocal now uses it to make the same type as the result.

Fixes https://github.com/KhronosGroup/glslang/issues/1278
This commit is contained in:
Neil Roberts 2018-03-13 10:57:59 +01:00
parent 2ad4737dc2
commit eddb1318ae
3 changed files with 20 additions and 1 deletions

View file

@ -848,6 +848,23 @@ Id Builder::makeFloat16Constant(float f16, bool specConstant)
return c->getResultId();
}
Id Builder::makeFpConstant(Id type, double d, bool specConstant)
{
assert(isFloatType(type));
switch (getScalarTypeWidth(type)) {
case 16:
return makeFloat16Constant(d, specConstant);
case 32:
return makeFloatConstant(d, specConstant);
case 64:
return makeDoubleConstant(d, specConstant);
}
assert(false);
}
Id Builder::findCompositeConstant(Op typeClass, const std::vector<Id>& comps)
{
Instruction* constant = 0;