Commit 8279f072 by t.jung

Updated type conversion rules for HLSL frontend

parent 7274bbc2
#define zeros 0
#define zeros1 0
#define zeros2 0, 0
#define zeros3 0, 0, 0
#define zeros4 0, 0, 0, 0
#define zeros5 0, 0, 0, 0, 0
#define zeros6 0, 0, 0, 0, 0, 0
#define zeros7 0, 0, 0, 0, 0, 0, 0
#define zeros8 0, 0, 0, 0, 0, 0, 0, 0
#define zeros9 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros10 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros11 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros12 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros13 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros14 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros15 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define zeros16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
float4 main() : SV_Target {
float var0 = float(zeros1);
float2 var13 = float(zeros1);
float2 var14 = float2(zeros2);
float3 var26 = float(zeros1);
float3 var28 = float3(zeros3);
float4 var39 = float(zeros1);
float4 var42 = float4(zeros4);
float4 var43 = float2x2(zeros4);
float2x2 var52 = float(zeros1);
float2x2 var55 = float4(zeros4);
float2x2 var56 = float2x2(zeros4);
float2x3 var65 = float(zeros1);
float2x3 var70 = float2x3(zeros6);
float2x4 var78 = float(zeros1);
float2x4 var84 = float2x4(zeros8);
float3x2 var91 = float(zeros1);
float3x2 var98 = float3x2(zeros6);
float3x3 var104 = float(zeros1);
float3x3 var112 = float3x3(zeros9);
float3x4 var117 = float(zeros1);
float3x4 var126 = float3x4(zeros12);
float4x2 var130 = float(zeros1);
float4x2 var140 = float4x2(zeros8);
float4x3 var143 = float(zeros1);
float4x3 var154 = float4x3(zeros12);
float4x4 var156 = float(zeros1);
float4x4 var168 = float4x4(zeros16);
float var1 = float2(zeros2);// warning X3206: implicit truncation of vector type
float var2 = float3(zeros3);// warning X3206: implicit truncation of vector type
float var3 = float4(zeros4);// warning X3206: implicit truncation of vector type
float var4 = float2x2(zeros4);// warning X3206: implicit truncation of vector type
float var5 = float2x3(zeros6);// warning X3206: implicit truncation of vector type
float var6 = float2x4(zeros8);// warning X3206: implicit truncation of vector type
float var7 = float3x2(zeros6);// warning X3206: implicit truncation of vector type
float var8 = float3x3(zeros9);// warning X3206: implicit truncation of vector type
float var9 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float var10 = float4x2(zeros8);// warning X3206: implicit truncation of vector type
float var11 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float var12 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float2 var15 = float3(zeros3);// warning X3206: implicit truncation of vector type
float2 var16 = float4(zeros4);// warning X3206: implicit truncation of vector type
float3 var29 = float4(zeros4);// warning X3206: implicit truncation of vector type
float2x2 var57 = float2x3(zeros6);// warning X3206: implicit truncation of vector type
float2x2 var58 = float2x4(zeros8);// warning X3206: implicit truncation of vector type
float2x2 var59 = float3x2(zeros6);// warning X3206: implicit truncation of vector type
float2x2 var60 = float3x3(zeros9);// warning X3206: implicit truncation of vector type
float2x2 var61 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float2x2 var62 = float4x2(zeros8);// warning X3206: implicit truncation of vector type
float2x2 var63 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float2x2 var64 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float2x3 var71 = float2x4(zeros8);// warning X3206: implicit truncation of vector type
float2x3 var73 = float3x3(zeros9);// warning X3206: implicit truncation of vector type
float2x3 var74 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float2x3 var76 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float2x3 var77 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float2x4 var87 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float2x4 var90 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float3x2 var99 = float3x3(zeros9);// warning X3206: implicit truncation of vector type
float3x2 var100 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float3x2 var101 = float4x2(zeros8);// warning X3206: implicit truncation of vector type
float3x2 var102 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float3x2 var103 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float3x3 var113 = float3x4(zeros12);// warning X3206: implicit truncation of vector type
float3x3 var115 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float3x3 var116 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float3x4 var129 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float4x2 var141 = float4x3(zeros12);// warning X3206: implicit truncation of vector type
float4x2 var142 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
float4x3 var155 = float4x4(zeros16);// warning X3206: implicit truncation of vector type
return 0;
}
......@@ -1119,9 +1119,12 @@ void TIntermediate::addBiShapeConversion(TOperator op, TIntermTyped*& lhsNode, T
rhsNode = addUniShapeConversion(op, lhsNode->getType(), rhsNode);
return;
case EOpMul:
// matrix multiply does not change shapes
if (lhsNode->isMatrix() && rhsNode->isMatrix())
return;
case EOpAdd:
case EOpSub:
case EOpMul:
case EOpDiv:
// want to support vector * scalar native ops in AST and lower, not smear, similarly for
// matrix * vector, etc.
......@@ -1194,9 +1197,19 @@ TIntermTyped* TIntermediate::addShapeConversion(const TType& type, TIntermTyped*
// The new node that handles the conversion
TOperator constructorOp = mapTypeToConstructorOp(type);
// HLSL has custom semantics for scalar->mat shape conversions.
if (source == EShSourceHlsl) {
if (node->getType().isScalarOrVec1() && type.isMatrix()) {
// HLSL rules for scalar, vector and matrix conversions:
// 1) scalar can become anything, initializing every component with its value
// 2) vector and matrix can become scalar, first element is used (warning: truncation)
// 3) matrix can become matrix with less rows and/or columns (warning: truncation)
// 4) vector can become vector with less rows size (warning: truncation)
// 5a) vector 4 can become 2x2 matrix (special case) (same packing layout, its a reinterpret)
// 5b) 2x2 matrix can become vector 4 (special case) (same packing layout, its a reinterpret)
const TType &sourceType = node->getType();
// rule 1 for scalar to matrix is special
if (sourceType.isScalarOrVec1() && type.isMatrix()) {
// HLSL semantics: the scalar (or vec1) is replicated to every component of the matrix. Left to its
// own devices, the constructor from a scalar would populate the diagonal. This forces replication
......@@ -1204,7 +1217,7 @@ TIntermTyped* TIntermediate::addShapeConversion(const TType& type, TIntermTyped*
// Note that if the node is complex (e.g, a function call), we don't want to duplicate it here
// repeatedly, so we copy it to a temp, then use the temp.
const int matSize = type.getMatrixRows() * type.getMatrixCols();
const int matSize = type.computeNumComponents();
TIntermAggregate* rhsAggregate = new TIntermAggregate();
const bool isSimple = (node->getAsSymbolNode() != nullptr) || (node->getAsConstantUnion() != nullptr);
......@@ -1213,11 +1226,43 @@ TIntermTyped* TIntermediate::addShapeConversion(const TType& type, TIntermTyped*
assert(0); // TODO: use node replicator service when available.
}
for (int x=0; x<matSize; ++x)
for (int x = 0; x < matSize; ++x)
rhsAggregate->getSequence().push_back(node);
return setAggregateOperator(rhsAggregate, constructorOp, type, node->getLoc());
}
// rule 1 and 2
if ((sourceType.isScalar() && !type.isScalar()) || (!sourceType.isScalar() && type.isScalar()))
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 3 and 5b
if (sourceType.isMatrix()) {
// rule 3
if (type.isMatrix()) {
if ((sourceType.getMatrixCols() != type.getMatrixCols() || sourceType.getMatrixRows() != type.getMatrixRows()) &&
sourceType.getMatrixCols() >= type.getMatrixCols() && sourceType.getMatrixRows() >= type.getMatrixRows())
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 5b
} else if (type.isVector()) {
if (type.getVectorSize() == 4 && sourceType.getMatrixCols() == 2 && sourceType.getMatrixRows() == 2)
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
}
}
// rule 4 and 5a
if (sourceType.isVector()) {
// rule 4
if (type.isVector())
{
if (sourceType.getVectorSize() > type.getVectorSize())
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
// rule 5a
} else if (type.isMatrix()) {
if (sourceType.getVectorSize() == 4 && type.getMatrixCols() == 2 && type.getMatrixRows() == 2)
return setAggregateOperator(makeAggregate(node), constructorOp, type, node->getLoc());
}
}
}
// scalar -> vector or vec1 -> vector or
......
......@@ -382,7 +382,8 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.typeGraphCopy.vert", "main"},
{"hlsl.typedef.frag", "PixelShaderFunction"},
{"hlsl.whileLoop.frag", "PixelShaderFunction"},
{"hlsl.void.frag", "PixelShaderFunction"}
{"hlsl.void.frag", "PixelShaderFunction"},
{"hlsl.type.type.conversion.all.frag", "main"}
}),
FileNameAsCustomTestSuffix
);
......@@ -399,6 +400,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.wavequery.frag", "PixelShaderFunction"},
{"hlsl.wavereduction.comp", "CSMain"},
{"hlsl.wavevote.comp", "CSMain"},
{ "hlsl.type.type.conversion.valid.frag", "main" }
}),
FileNameAsCustomTestSuffix
);
......
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