Skip to content

Commit c46e1aa

Browse files
committed
Emit errors when seeing a matrix with row/col count of 1
Such matrices aren't well supported by our targets, and we currently don't transform such types to supported ones. Therefore, generate an error rather than outputting invalid target code. This closes shader-slang#5987.
1 parent 46149ee commit c46e1aa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

source/slang/slang-check-decl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -11876,6 +11876,20 @@ void SemanticsDeclAttributesVisitor::checkVarDeclCommon(VarDeclBase* varDecl)
1187611876
getSink()->diagnose(varDecl, Diagnostics::pushOrSpecializationConstantCannotBeStatic);
1187711877
}
1187811878
}
11879+
11880+
if (auto matrixType = as<MatrixExpressionType>(varDecl->getType()))
11881+
{
11882+
auto rowCountVal = matrixType->getRowCount();
11883+
auto colCountVal = matrixType->getColumnCount();
11884+
ConstantIntVal* rowCountConst = as<ConstantIntVal>(rowCountVal);
11885+
ConstantIntVal* colCountConst = as<ConstantIntVal>(colCountVal);
11886+
IntegerLiteralValue rowCount = rowCountConst ? rowCountConst->getValue() : -1;
11887+
IntegerLiteralValue colCount = colCountConst ? colCountConst->getValue() : -1;
11888+
if (rowCount == 1 || colCount == 1)
11889+
{
11890+
getSink()->diagnose(varDecl, Diagnostics::matrixColumnOrRowCountIsOne, matrixType);
11891+
}
11892+
}
1187911893
}
1188011894

1188111895
void SemanticsDeclAttributesVisitor::checkForwardDerivativeOfAttribute(

source/slang/slang-diagnostic-defs.h

+6
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,12 @@ DIAGNOSTIC(
16581658
overloadedParameterToHigherOrderFunction,
16591659
"passing overloaded functions to higher order functions is not supported")
16601660

1661+
DIAGNOSTIC(
1662+
39999,
1663+
Error,
1664+
matrixColumnOrRowCountIsOne,
1665+
"matrix of type '$0' has column or row count of 1")
1666+
16611667
// 38xxx
16621668

16631669
DIAGNOSTIC(

0 commit comments

Comments
 (0)