Skip to content

Commit 48a7218

Browse files
committed
Emit errors when seeing a matrix with row/col count of 1
Such matrices aren't well supported except by D3D targets. Therefore, generate an error rather than outputting invalid code for non-D3D targets. This closes shader-slang#5987.
1 parent cb835b9 commit 48a7218

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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+
"matrices with 1 column or row are not supported by the current code generation target")
1666+
16611667
// 38xxx
16621668

16631669
DIAGNOSTIC(

source/slang/slang-emit.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,24 @@ static void unexportNonEmbeddableIR(CodeGenTarget target, IRModule* irModule)
555555
}
556556
}
557557

558+
static void validateMatrixDimensions(DiagnosticSink* sink, IRModule* module)
559+
{
560+
for (auto globalInst : module->getGlobalInsts())
561+
{
562+
if (auto matrixType = as<IRMatrixType>(globalInst))
563+
{
564+
auto colCount = as<IRIntLit>(matrixType->getColumnCount());
565+
auto rowCount = as<IRIntLit>(matrixType->getRowCount());
566+
567+
if ((rowCount && (rowCount->getValue() == 1)) ||
568+
(colCount && (colCount->getValue() == 1)))
569+
{
570+
sink->diagnose(matrixType->sourceLoc, Diagnostics::matrixColumnOrRowCountIsOne);
571+
}
572+
}
573+
}
574+
}
575+
558576
Result linkAndOptimizeIR(
559577
CodeGenContext* codeGenContext,
560578
LinkingAndOptimizationOptions const& options,
@@ -1504,6 +1522,10 @@ Result linkAndOptimizeIR(
15041522
#endif
15051523
validateIRModuleIfEnabled(codeGenContext, irModule);
15061524

1525+
// Make sure there are no matrices with 1 row/column, except for D3D targets where it's allowed.
1526+
if (!isD3DTarget(targetRequest))
1527+
validateMatrixDimensions(sink, irModule);
1528+
15071529
// The resource-based specialization pass above
15081530
// may create specialized versions of functions, but
15091531
// it does not try to completely eliminate the original

0 commit comments

Comments
 (0)