* 1.) Match * 2.) Scalar dimension promotion (scalar -> vector/matrix) * 3.) Conversion * 4.) Conversion + scalar dimension promotion * 5.) Truncation (vector -> scalar or lower component vector, matrix -> scalar or lower component matrix) * 6.) Conversion + truncation */
| 1663 | * 6.) Conversion + truncation |
| 1664 | */ |
| 1665 | static int GetTypeCastRank(HLSLTree* tree, const HLSLType& srcType, const HLSLType& dstType) |
| 1666 | { |
| 1667 | /*if (srcType.array != dstType.array || srcType.arraySize != dstType.arraySize) |
| 1668 | { |
| 1669 | return -1; |
| 1670 | }*/ |
| 1671 | |
| 1672 | if (srcType.array != dstType.array) { |
| 1673 | return -1; |
| 1674 | } |
| 1675 | |
| 1676 | if (srcType.array == true) { |
| 1677 | ASSERT(dstType.array == true); |
| 1678 | int srcArraySize = -1; |
| 1679 | int dstArraySize = -1; |
| 1680 | |
| 1681 | tree->GetExpressionValue(srcType.arraySize, srcArraySize); |
| 1682 | tree->GetExpressionValue(dstType.arraySize, dstArraySize); |
| 1683 | |
| 1684 | if (srcArraySize != dstArraySize) { |
| 1685 | return -1; |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | if (srcType.baseType == HLSLBaseType_UserDefined && dstType.baseType == HLSLBaseType_UserDefined) { |
| 1690 | return String_Equal(srcType.typeName, dstType.typeName) ? 0 : -1; |
| 1691 | } |
| 1692 | |
| 1693 | if (srcType.baseType == dstType.baseType) { |
| 1694 | // This only works if textures are half or float, but not hwne |
| 1695 | // there are more varied texture that can be cast. |
| 1696 | if (IsTextureType(srcType.baseType)) { |
| 1697 | return srcType.formatType == dstType.formatType ? 0 : -1; |
| 1698 | } |
| 1699 | |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | const BaseTypeDescription& srcDesc = baseTypeDescriptions[srcType.baseType]; |
| 1704 | const BaseTypeDescription& dstDesc = baseTypeDescriptions[dstType.baseType]; |
| 1705 | if (srcDesc.numericType == NumericType_NaN || dstDesc.numericType == NumericType_NaN) { |
| 1706 | return -1; |
| 1707 | } |
| 1708 | |
| 1709 | // Result bits: T R R R P (T = truncation, R = conversion rank, P = dimension promotion) |
| 1710 | int result = _numberTypeRank[srcDesc.numericType][dstDesc.numericType] << 1; |
| 1711 | |
| 1712 | if (srcDesc.numDimensions == 0 && dstDesc.numDimensions > 0) { |
| 1713 | // Scalar dimension promotion |
| 1714 | result |= (1 << 0); |
| 1715 | } |
| 1716 | else if ((srcDesc.numDimensions == dstDesc.numDimensions && (srcDesc.numComponents > dstDesc.numComponents || srcDesc.height > dstDesc.height)) || |
| 1717 | (srcDesc.numDimensions > 0 && dstDesc.numDimensions == 0)) { |
| 1718 | // Truncation |
| 1719 | result |= (1 << 4); |
| 1720 | } |
| 1721 | else if (srcDesc.numDimensions != dstDesc.numDimensions || |
| 1722 | srcDesc.numComponents != dstDesc.numComponents || |
no test coverage detected