Add conversion folding when the source is a constant.

This change adds unary conversion folding when the source is a constant.
This fixes an ISV issue whereby:

```
const float16_t f = float16_t(42.0);
```

Wouldn't compile because the conversion operator would always produce an
EvqTemporary when it could have produced an EvqConst.

I've also added a test case that proves out that all basic-type to
basic-type conversions work.
This commit is contained in:
Neil Henning 2018-11-26 10:17:33 +00:00
parent 0e6c82ce93
commit 81a63f1de0
11 changed files with 1012 additions and 40 deletions

View file

@ -489,7 +489,7 @@ bool TIntermediate::isConversionAllowed(TOperator op, TIntermTyped* node) const
// This is 'mechanism' here, it does any conversion told.
// It is about basic type, not about shape.
// The policy comes from the shader or the calling code.
TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const
TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped* node) const
{
//
// Add a new newNode for the conversion.
@ -712,7 +712,11 @@ TIntermUnary* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
TType newType(convertTo, EvqTemporary, node->getVectorSize(), node->getMatrixCols(), node->getMatrixRows());
newNode = addUnaryNode(newOp, node, node->getLoc(), newType);
// TODO: it seems that some unary folding operations should occur here, but are not
if (node->getAsConstantUnion()) {
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType);
if (folded)
return folded;
}
// Propagate specialization-constant-ness, if allowed
if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode))
@ -1021,7 +1025,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
//
// Add a new newNode for the conversion.
//
TIntermUnary* newNode = createConversion(promoteTo, node);
TIntermTyped* newNode = createConversion(promoteTo, node);
return newNode;
}