Skip to content

Commit

Permalink
add diags for incompatible sv values
Browse files Browse the repository at this point in the history
  • Loading branch information
bob80905 committed Dec 1, 2023
1 parent 8b24477 commit a5ab095
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tools/clang/lib/CodeGen/CGHLSLMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,50 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
funcProps->numThreads[1] = 1;
funcProps->numThreads[2] = 1;
}

// Validate Compute Shader system value inputs per launch mode
for (ParmVarDecl *param : FD->parameters()) {
for (const hlsl::UnusualAnnotation *it : param->getUnusualAnnotations()) {
if (it->getKind() == hlsl::UnusualAnnotation::UA_SemanticDecl) {
const hlsl::SemanticDecl *sd = cast<hlsl::SemanticDecl>(it);
// if the node launch type is Thread, then there are no system values
// allowed
if (funcProps->Node.LaunchType == DXIL::NodeLaunchType::Thread) {
if (sd->SemanticName.equals("SV_GroupThreadID") ||
sd->SemanticName.equals("SV_GroupIndex") ||
sd->SemanticName.equals("SV_GroupID") ||
sd->SemanticName.equals("SV_DispatchThreadID")) {
// emit diagnostic
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error,
"Invalid system value semantic '%0' for launchtype '%1'");
Diags.Report(param->getLocation(), DiagID)
<< sd->SemanticName << "Thread";
}
}

// if the node launch type is Coalescing, then
// SV_GroupIndex and SV_GroupThreadID are allowed
else if (funcProps->Node.LaunchType ==
DXIL::NodeLaunchType::Coalescing) {
if (sd->SemanticName.equals("SV_GroupID") ||
sd->SemanticName.equals("SV_DispatchThreadID")) {
// emit diagnostic
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error,
"Invalid system value semantic '%0' for launchtype '%1'");
Diags.Report(param->getLocation(), DiagID)
<< sd->SemanticName << "Coalescing";
}
}
// Broadcasting nodes allow all node shader system value semantics
else if (funcProps->Node.LaunchType ==
DXIL::NodeLaunchType::Broadcasting) {
continue;
}
}
}
}
}

const unsigned profileAttributes =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %dxc -T lib_6_3 -D e1 %s | FileCheck -check-prefix=CHECK_ENTRY1 %s
// RUN: %dxc -T lib_6_3 -D e2 %s
// RUN: %dxc -T lib_6_3 -D e3 %s | FileCheck -check-prefix=CHECK_ENTRY3 %s


#ifdef e1
// CHECK_ENTRY1: error: Invalid system value semantic 'SV_DispatchThreadID' for launchtype 'Thread'
// CHECK_ENTRY1: error: Invalid system value semantic 'SV_GroupID' for launchtype 'Thread'
// CHECK_ENTRY1: error: Invalid system value semantic 'SV_GroupThreadID' for launchtype 'Thread'
// CHECK_ENTRY1: error: Invalid system value semantic 'SV_GroupIndex' for launchtype 'Thread'
[shader("node")]
[NodeLaunch("thread")]
[numthreads(1,1,1)]
void entry( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
{
}
#endif

#ifdef e2
// no expected errors
[shader("node")]
[NodeDispatchGrid(1,1,1)]
[NodeLaunch("broadcasting")]
[numthreads(1,1,1)]
void entry2( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
{
}
#endif

#ifdef e3
// CHECK_ENTRY3: error: Invalid system value semantic 'SV_DispatchThreadID' for launchtype 'Coalescing'
// CHECK_ENTRY3: error: Invalid system value semantic 'SV_GroupID' for launchtype 'Coalescing'
[shader("node")]
[NodeLaunch("coalescing")]
[numthreads(1,1,1)]
void entry3( uint2 tid : SV_DispatchThreadID, uint2 gid : SV_GroupID, uint2 gtid : SV_GroupThreadID, uint gidx : SV_GroupIndex )
{
}
#endif

0 comments on commit a5ab095

Please sign in to comment.