Merge pull request #1289 from Igalia/igalia/dmat-scalar-division

Use the correct type for the constant for matrix/scalar division
This commit is contained in:
John Kessenich 2018-03-15 23:49:59 -06:00 committed by GitHub
commit cb32c54466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -4137,7 +4137,8 @@ spv::Id TGlslangToSpvTraverser::createBinaryMatrixOperation(spv::Op op, spv::Dec
case spv::OpFDiv:
if (builder.isMatrix(left) && builder.isScalar(right)) {
// turn matrix / scalar into a multiply...
right = builder.createBinOp(spv::OpFDiv, builder.getTypeId(right), builder.makeFloatConstant(1.0F), right);
spv::Id resultType = builder.getTypeId(right);
right = builder.createBinOp(spv::OpFDiv, resultType, builder.makeFpConstant(resultType, 1.0), right);
op = spv::OpMatrixTimesScalar;
} else
firstClass = false;

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;

View File

@ -226,6 +226,7 @@ public:
Id makeFloatConstant(float f, bool specConstant = false);
Id makeDoubleConstant(double d, bool specConstant = false);
Id makeFloat16Constant(float f16, bool specConstant = false);
Id makeFpConstant(Id type, double d, bool specConstant = false);
// Turn the array of constants into a proper spv constant of the requested type.
Id makeCompositeConstant(Id type, const std::vector<Id>& comps, bool specConst = false);