HLSL: fix several issues in mat construction from scalars

This fixes:

1. A compilation error when assigning scalars to matricies

2. A semantic error in matrix construction from scalars.  This was
initializing the diagonal, where HLSL semantics require the scalar be
replicated to every matrix element.

3. Functions accepting mats can be called with scalars, which will
be shape-converted to the matrix type.  This was previously failing
to match the function signature.

NOTE: this does not yet handle complex scalars (a function call,
say) used to construct matricies.  That'll be added when the
node replicator service is available.  For now, there's an assert.

There's one new test (hlsl.scalar2matrix.frag).  An existing test
lsl.type.half.frag changes, because of (2) above, and a negative
test error message changes due to (3) above.

Fixes #923.
This commit is contained in:
LoopDawg
2017-06-09 14:36:46 -06:00
parent f7cd88a2b5
commit e2713125b9
7 changed files with 617 additions and 45 deletions

View File

@@ -6616,6 +6616,7 @@ const TFunction* HlslParseContext::findFunction(const TSourceLoc& loc, TFunction
// shapes have to be convertible
if ((from.isScalarOrVec1() && to.isScalarOrVec1()) ||
(from.isScalarOrVec1() && to.isVector()) ||
(from.isScalarOrVec1() && to.isMatrix()) ||
(from.isVector() && to.isVector() && from.getVectorSize() >= to.getVectorSize()))
return true;
@@ -7393,8 +7394,15 @@ TIntermTyped* HlslParseContext::addConstructor(const TSourceLoc& loc, TIntermTyp
newNode = constructAggregate(node, elementType, 1, node->getLoc());
else if (op == EOpConstructStruct)
newNode = constructAggregate(node, *(*memberTypes).type, 1, node->getLoc());
else
else {
// shape conversion for matrix constructor from scalar. HLSL semantics are: scalar
// is replicated into every element of the matrix (not just the diagnonal), so
// that is handled specially here.
if (type.isMatrix() && node->getType().isScalarOrVec1())
node = intermediate.addShapeConversion(type, node);
newNode = constructBuiltIn(type, op, node, node->getLoc(), false);
}
if (newNode && (type.isArray() || op == EOpConstructStruct))
newNode = intermediate.setAggregateOperator(newNode, EOpConstructStruct, type, loc);