Merge pull request #505 from steve-lunarg/rowmajor-fix-2a

HLSL: alias HLSL matrix-row-column onto AST matrix-column-row
This commit is contained in:
John Kessenich
2016-09-09 14:00:27 -06:00
committed by GitHub
12 changed files with 3525 additions and 3027 deletions

View File

@@ -711,8 +711,8 @@ bool HlslGrammar::acceptMatrixTemplateType(TType& type)
return false;
new(&type) TType(basicType, EvqTemporary, 0,
cols->getAsConstantUnion()->getConstArray()[0].getIConst(),
rows->getAsConstantUnion()->getConstArray()[0].getIConst());
rows->getAsConstantUnion()->getConstArray()[0].getIConst(),
cols->getAsConstantUnion()->getConstArray()[0].getIConst());
if (!acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
@@ -1031,46 +1031,46 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 1);
break;
case EHTokInt1x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 1);
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 2);
break;
case EHTokInt1x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 1);
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 3);
break;
case EHTokInt1x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 1);
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 4);
break;
case EHTokInt2x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 2);
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 1);
break;
case EHTokInt2x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 2);
break;
case EHTokInt2x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 2);
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 3);
break;
case EHTokInt2x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 2);
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 4);
break;
case EHTokInt3x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 3);
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 1);
break;
case EHTokInt3x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 3);
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 2);
break;
case EHTokInt3x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 3);
break;
case EHTokInt3x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 3);
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 4);
break;
case EHTokInt4x1:
new(&type) TType(EbtInt, EvqTemporary, 0, 1, 4);
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 1);
break;
case EHTokInt4x2:
new(&type) TType(EbtInt, EvqTemporary, 0, 2, 4);
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 2);
break;
case EHTokInt4x3:
new(&type) TType(EbtInt, EvqTemporary, 0, 3, 4);
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 3);
break;
case EHTokInt4x4:
new(&type) TType(EbtInt, EvqTemporary, 0, 4, 4);
@@ -1080,46 +1080,46 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 1);
break;
case EHTokUint1x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 1);
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 2);
break;
case EHTokUint1x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 1);
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 3);
break;
case EHTokUint1x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 1);
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 4);
break;
case EHTokUint2x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 2);
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 1);
break;
case EHTokUint2x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 2);
break;
case EHTokUint2x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 2);
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 3);
break;
case EHTokUint2x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 2);
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 4);
break;
case EHTokUint3x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 3);
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 1);
break;
case EHTokUint3x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 3);
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 2);
break;
case EHTokUint3x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 3);
break;
case EHTokUint3x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 3);
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 4);
break;
case EHTokUint4x1:
new(&type) TType(EbtUint, EvqTemporary, 0, 1, 4);
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 1);
break;
case EHTokUint4x2:
new(&type) TType(EbtUint, EvqTemporary, 0, 2, 4);
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 2);
break;
case EHTokUint4x3:
new(&type) TType(EbtUint, EvqTemporary, 0, 3, 4);
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 3);
break;
case EHTokUint4x4:
new(&type) TType(EbtUint, EvqTemporary, 0, 4, 4);
@@ -1129,46 +1129,46 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 1);
break;
case EHTokBool1x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 1);
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 2);
break;
case EHTokBool1x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 1);
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 3);
break;
case EHTokBool1x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 1);
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 4);
break;
case EHTokBool2x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 2);
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 1);
break;
case EHTokBool2x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 2);
break;
case EHTokBool2x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 2);
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 3);
break;
case EHTokBool2x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 2);
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 4);
break;
case EHTokBool3x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 3);
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 1);
break;
case EHTokBool3x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 3);
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 2);
break;
case EHTokBool3x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 3);
break;
case EHTokBool3x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 3);
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 4);
break;
case EHTokBool4x1:
new(&type) TType(EbtBool, EvqTemporary, 0, 1, 4);
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 1);
break;
case EHTokBool4x2:
new(&type) TType(EbtBool, EvqTemporary, 0, 2, 4);
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 2);
break;
case EHTokBool4x3:
new(&type) TType(EbtBool, EvqTemporary, 0, 3, 4);
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 3);
break;
case EHTokBool4x4:
new(&type) TType(EbtBool, EvqTemporary, 0, 4, 4);
@@ -1178,46 +1178,46 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 1);
break;
case EHTokFloat1x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 1);
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 2);
break;
case EHTokFloat1x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 1);
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 3);
break;
case EHTokFloat1x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 1);
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 4);
break;
case EHTokFloat2x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 2);
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 1);
break;
case EHTokFloat2x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 2);
break;
case EHTokFloat2x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 2);
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 3);
break;
case EHTokFloat2x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 2);
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 4);
break;
case EHTokFloat3x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 3);
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 1);
break;
case EHTokFloat3x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 3);
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 2);
break;
case EHTokFloat3x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 3);
break;
case EHTokFloat3x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 3);
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 4);
break;
case EHTokFloat4x1:
new(&type) TType(EbtFloat, EvqTemporary, 0, 1, 4);
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 1);
break;
case EHTokFloat4x2:
new(&type) TType(EbtFloat, EvqTemporary, 0, 2, 4);
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 2);
break;
case EHTokFloat4x3:
new(&type) TType(EbtFloat, EvqTemporary, 0, 3, 4);
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 3);
break;
case EHTokFloat4x4:
new(&type) TType(EbtFloat, EvqTemporary, 0, 4, 4);
@@ -1227,46 +1227,46 @@ bool HlslGrammar::acceptType(TType& type)
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 1);
break;
case EHTokDouble1x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 1);
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 2);
break;
case EHTokDouble1x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 1);
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 3);
break;
case EHTokDouble1x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 1);
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 4);
break;
case EHTokDouble2x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 2);
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 1);
break;
case EHTokDouble2x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 2);
break;
case EHTokDouble2x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 2);
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 3);
break;
case EHTokDouble2x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 2);
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 4);
break;
case EHTokDouble3x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 3);
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 1);
break;
case EHTokDouble3x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 3);
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 2);
break;
case EHTokDouble3x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 3);
break;
case EHTokDouble3x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 3);
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 4);
break;
case EHTokDouble4x1:
new(&type) TType(EbtDouble, EvqTemporary, 0, 1, 4);
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 1);
break;
case EHTokDouble4x2:
new(&type) TType(EbtDouble, EvqTemporary, 0, 2, 4);
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 2);
break;
case EHTokDouble4x3:
new(&type) TType(EbtDouble, EvqTemporary, 0, 3, 4);
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 3);
break;
case EHTokDouble4x4:
new(&type) TType(EbtDouble, EvqTemporary, 0, 4, 4);

View File

@@ -1600,8 +1600,10 @@ void HlslParseContext::decomposeIntrinsic(const TSourceLoc& loc, TIntermTyped*&
case EOpGenMul:
{
// mul(a,b) -> MatrixTimesMatrix, MatrixTimesVector, MatrixTimesScalar, VectorTimesScalar, Dot, Mul
TIntermTyped* arg0 = argAggregate->getSequence()[0]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[1]->getAsTyped();
// Since we are treating HLSL rows like GLSL columns (the first matrix indirection),
// we must reverse the operand order here. Hence, arg0 gets sequence[1], etc.
TIntermTyped* arg0 = argAggregate->getSequence()[1]->getAsTyped();
TIntermTyped* arg1 = argAggregate->getSequence()[0]->getAsTyped();
if (arg0->isVector() && arg1->isVector()) { // vec * vec
node->getAsAggregate()->setOperator(EOpDot);
@@ -4147,15 +4149,21 @@ TIntermTyped* HlslParseContext::convertInitializerList(const TSourceLoc& loc, co
return nullptr;
}
} else if (type.isMatrix()) {
if (type.getMatrixCols() != (int)initList->getSequence().size()) {
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
TType vectorType(type, 0); // dereferenced type
for (int i = 0; i < type.getMatrixCols(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
if (type.computeNumComponents() == (int)initList->getSequence().size()) {
// This means the matrix is initialized component-wise, rather than as
// a series of rows and columns. We can just use the list directly as
// a constructor; no further processing needed.
} else {
if (type.getMatrixCols() != (int)initList->getSequence().size()) {
error(loc, "wrong number of matrix columns:", "initializer list", type.getCompleteString().c_str());
return nullptr;
}
TType vectorType(type, 0); // dereferenced type
for (int i = 0; i < type.getMatrixCols(); ++i) {
initList->getSequence()[i] = convertInitializerList(loc, vectorType, initList->getSequence()[i]->getAsTyped());
if (initList->getSequence()[i] == nullptr)
return nullptr;
}
}
} else if (type.isVector()) {
if (type.getVectorSize() != (int)initList->getSequence().size()) {

View File

@@ -218,7 +218,6 @@ int FixedVecSize(const char* arg)
glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, const char* argType, int dim0, int dim1)
{
const bool isTranspose = (argOrder[0] == '^');
const bool isMatMul = (argOrder[0] == '#');
const bool isTexture = IsTextureType(argOrder[0]);
const bool isArrayed = IsTextureArrayed(argOrder[0]);
const bool isSampler = IsSamplerType(argType[0]);
@@ -229,8 +228,6 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
if (isTranspose) { // Take transpose of matrix dimensions
std::swap(dim0, dim1);
} else if (isMatMul) {
dim0 = dim1; // set vector dimension to mat col
} else if (isTexture) {
if (type == 'F') // map base type to texture of that type.
type = 'T'; // e.g, int -> itexture, uint -> utexture, etc.
@@ -240,7 +237,7 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
type = 'u';
}
if (isTranspose || isMatMul)
if (isTranspose)
++argOrder;
char order = *argOrder;
@@ -312,16 +309,14 @@ glslang::TString& AppendTypeName(glslang::TString& s, const char* argOrder, cons
switch (order) {
case '-': break; // no dimensions for voids
case 'S': break; // no dimensions on scalars
case 'V': s += ('0' + char(dim0)); break;
case 'V':
s += ('0' + char(dim0));
break;
case 'M':
{
if (!UseHlslTypes) // GLSL has column first for mat types
std::swap(dim0, dim1);
s += ('0' + char(dim0));
s += 'x';
s += ('0' + char(dim1));
break;
}
s += ('0' + char(dim0));
s += 'x';
s += ('0' + char(dim1));
break;
default:
break;
}
@@ -427,6 +422,7 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
const int retRows = xRows;
const int retCols = yCols;
// Create a mat * mat of the appropriate dimensions
AppendTypeName(s, "M", "F", retRows, retCols); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
@@ -438,6 +434,31 @@ void TBuiltInParseablesHlsl::createMatTimesMat()
s.append(");\n"); // close paren
}
// Create M*V
AppendTypeName(s, "V", "F", xRows, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(", ");
AppendTypeName(s, "V", "F", xCols, 1); // add Y input
s.append(");\n"); // close paren
// Create V*M
AppendTypeName(s, "V", "F", xCols, 1); // add return type
s.append(" "); // space between type and name
s.append("mul"); // intrinsic name
s.append("("); // open paren
AppendTypeName(s, "V", "F", xRows, 1); // add Y input
s.append(", ");
AppendTypeName(s, "M", "F", xRows, xCols); // add X input
s.append(");\n"); // close paren
}
}
}
@@ -482,7 +503,6 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
// '>' as first letter of order creates an output parameter
// '<' as first letter of order creates an input parameter
// '^' as first letter of order takes transpose dimensions
// '#' as first letter of order sets rows=cols for mats
// '%' as first letter of order creates texture of given F/I/U type (texture, itexture, etc)
// '@' as first letter of order creates arrayed texture of given type
// '$' / '&' as first letter of order creates 2DMS / 2DMSArray textures
@@ -592,9 +612,7 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
{ "mul", "M", nullptr, "S,M", "FI,", EShLangAll },
{ "mul", "V", nullptr, "V,S", "FI,", EShLangAll },
{ "mul", "S", nullptr, "V,V", "FI,", EShLangAll },
{ "mul", "#V", nullptr, "V,M", "FI,", EShLangAll },
{ "mul", "M", nullptr, "M,S", "FI,", EShLangAll },
{ "mul", "V", nullptr, "M,#V", "FI,", EShLangAll },
// mat*mat form of mul is handled in createMatTimesMat()
{ "noise", "S", "F", "V", "F", EShLangPS },
{ "normalize", nullptr, nullptr, "V", "F", EShLangAll },