Skip to content

Commit

Permalink
Emit errors when seeing a matrix with row/col count of 1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aleino-nv committed Jan 15, 2025
1 parent cb835b9 commit 48a7218
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,12 @@ DIAGNOSTIC(
overloadedParameterToHigherOrderFunction,
"passing overloaded functions to higher order functions is not supported")

DIAGNOSTIC(
39999,
Error,
matrixColumnOrRowCountIsOne,
"matrices with 1 column or row are not supported by the current code generation target")

// 38xxx

DIAGNOSTIC(
Expand Down
22 changes: 22 additions & 0 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,24 @@ static void unexportNonEmbeddableIR(CodeGenTarget target, IRModule* irModule)
}
}

static void validateMatrixDimensions(DiagnosticSink* sink, IRModule* module)
{
for (auto globalInst : module->getGlobalInsts())
{
if (auto matrixType = as<IRMatrixType>(globalInst))
{
auto colCount = as<IRIntLit>(matrixType->getColumnCount());
auto rowCount = as<IRIntLit>(matrixType->getRowCount());

if ((rowCount && (rowCount->getValue() == 1)) ||
(colCount && (colCount->getValue() == 1)))
{
sink->diagnose(matrixType->sourceLoc, Diagnostics::matrixColumnOrRowCountIsOne);
}
}
}
}

Result linkAndOptimizeIR(
CodeGenContext* codeGenContext,
LinkingAndOptimizationOptions const& options,
Expand Down Expand Up @@ -1504,6 +1522,10 @@ Result linkAndOptimizeIR(
#endif
validateIRModuleIfEnabled(codeGenContext, irModule);

// Make sure there are no matrices with 1 row/column, except for D3D targets where it's allowed.
if (!isD3DTarget(targetRequest))
validateMatrixDimensions(sink, irModule);

// The resource-based specialization pass above
// may create specialized versions of functions, but
// it does not try to completely eliminate the original
Expand Down

0 comments on commit 48a7218

Please sign in to comment.