Skip to content

Commit e6e3717

Browse files
authored
[SM6.10] Linalg Builtin Diag on Bad Stage (#8233)
Some builtins are only allowed in a limited set of shader stages. Raise a Sema Diag when they are improperly used. Fixes #8229
1 parent 8da9786 commit e6e3717

19 files changed

Lines changed: 292 additions & 3077 deletions

File tree

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8055,6 +8055,9 @@ def err_hlsl_linalg_matrix_attribute_on_invalid_type
80558055
def err_hlsl_linalg_attributed_matrix_required
80568056
: Error<"argument must be linear algebra matrix type">;
80578057

8058+
def err_hlsl_linalg_unsupported_stage : Error<
8059+
"builtin unavailable in shader stage '%0' (requires 'compute', 'mesh' or 'amplification')">;
8060+
80588061
def err_hlsl_linalg_mul_muladd_output_vector_size_not_equal_to_matrix_M : Error<
80598062
"output vector length must be equal to Matrix M dimension in a linalg Mul/MulAdd operation">;
80608063
def err_hlsl_linalg_mul_muladd_unpacked_input_vector_size_not_equal_to_matrix_K : Error<

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12896,6 +12896,23 @@ static void DiagnoseReachableSERCall(Sema &S, CallExpr *CE,
1289612896
S.Diag(EntryLoc, diag::note_hlsl_entry_defined_here);
1289712897
}
1289812898

12899+
// Some LinAlg builtins are not available in all shader stages
12900+
// Detect those use cases and raise a Diagnostic
12901+
static void DiagnoseReachableLimitedLinAlgCall(Sema &S, CallExpr *CE,
12902+
DXIL::ShaderKind EntrySK,
12903+
const FunctionDecl *EntryDecl) {
12904+
if (EntrySK == DXIL::ShaderKind::Compute ||
12905+
EntrySK == DXIL::ShaderKind::Mesh ||
12906+
EntrySK == DXIL::ShaderKind::Amplification)
12907+
return;
12908+
12909+
SourceLocation EntryLoc = EntryDecl->getLocation();
12910+
SourceLocation Loc = CE->getExprLoc();
12911+
S.Diag(Loc, diag::err_hlsl_linalg_unsupported_stage)
12912+
<< ShaderModel::FullNameFromKind(EntrySK);
12913+
S.Diag(EntryLoc, diag::note_hlsl_entry_defined_here);
12914+
}
12915+
1289912916
// Check HLSL member call constraints for used functions.
1290012917
// locallyVisited is true if this call has been visited already from any other
1290112918
// entry function. Used to avoid duplicate diagnostics when not dependent on
@@ -12946,6 +12963,21 @@ void Sema::DiagnoseReachableHLSLCall(CallExpr *CE, const hlsl::ShaderModel *SM,
1294612963
case hlsl::IntrinsicOp::IOP_DxMaybeReorderThread:
1294712964
DiagnoseReachableSERCall(*this, CE, EntrySK, EntryDecl, true);
1294812965
break;
12966+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_FillMatrix:
12967+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_CopyConvertMatrix:
12968+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixLength:
12969+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixGetCoordinate:
12970+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixGetElement:
12971+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixSetElement:
12972+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixStoreToDescriptor:
12973+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixLoadFromMemory:
12974+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixStoreToMemory:
12975+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulateToMemory:
12976+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixMatrixMultiply:
12977+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixMatrixMultiplyAccumulate:
12978+
case hlsl::IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulate:
12979+
DiagnoseReachableLimitedLinAlgCall(*this, CE, EntrySK, EntryDecl);
12980+
break;
1294912981
default:
1295012982
break;
1295112983
}

tools/clang/test/SemaHLSL/hlsl/linalg/builtins/copyconvertmatrix/errors.hlsl

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)