Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "VkConstantsTables.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilFunctionProps.h"
#include "dxc/DXIL/DxilSemantic.h"
#include "dxc/DXIL/DxilShaderModel.h"
#include "dxc/DXIL/DxilUtil.h"
#include "dxc/HLSL/HLOperations.h"
Expand Down Expand Up @@ -11603,7 +11604,6 @@ void hlsl::DiagnoseRegisterType(clang::Sema *self, clang::SourceLocation loc,

// FIXME: DiagnoseSVForLaunchType is wrong in multiple ways:
// - It doesn't handle system values inside structs
// - It doesn't account for the fact that semantics are case-insensitive
// - It doesn't account for optional index at the end of semantic name
// - It permits any `SV_*` for Broadcasting launch, not just the legal ones
// - It doesn't prevent multiple system values with the same semantic
Expand All @@ -11613,15 +11613,19 @@ void hlsl::DiagnoseRegisterType(clang::Sema *self, clang::SourceLocation loc,
static void DiagnoseSVForLaunchType(const FunctionDecl *FD,
DXIL::NodeLaunchType LaunchTy,
DiagnosticsEngine &Diags) {

// 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);
const auto *semantic = hlsl::Semantic::GetByName(sd->SemanticName);
assert(semantic->GetKind() != hlsl::Semantic::Kind::Invalid);

// if the node launch type is Thread, then there are no system values
// allowed
if (LaunchTy == DXIL::NodeLaunchType::Thread) {
if (sd->SemanticName.startswith("SV_")) {
if (semantic->GetKind() != hlsl::Semantic::Kind::Arbitrary) {
// emit diagnostic
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error,
Expand All @@ -11634,8 +11638,8 @@ static void DiagnoseSVForLaunchType(const FunctionDecl *FD,
// if the node launch type is Coalescing, then only
// SV_GroupIndex and SV_GroupThreadID are allowed
else if (LaunchTy == DXIL::NodeLaunchType::Coalescing) {
if (!(sd->SemanticName.equals("SV_GroupIndex") ||
sd->SemanticName.equals("SV_GroupThreadID"))) {
if (semantic->GetKind() != hlsl::Semantic::Kind::GroupIndex &&
semantic->GetKind() != hlsl::Semantic::Kind::GroupThreadID) {
// emit diagnostic
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error,
Expand Down
29 changes: 29 additions & 0 deletions tools/clang/test/SemaHLSL/hlsl/workgraph/node_input_semantic.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %dxc -Tlib_6_8 -verify %s

[Shader("node")]
[NodeLaunch("coalescing")]
[NumThreads(1024, 1, 1)]
[NodeIsProgramEntry]
void foo(uint3 tid : SV_GroupThreadId)
{ }

[Shader("node")]
[NodeLaunch("coalescing")]
[NumThreads(1024, 1, 1)]
[NodeIsProgramEntry]
void bar(uint3 tid : SV_GroupThreadID)
{ }

[Shader("node")]
[NodeLaunch("coalescing")]
[NumThreads(1024, 1, 1)]
[NodeIsProgramEntry]
void baz(uint3 tid : SV_VertexID) // expected-error {{Invalid system value semantic 'SV_VertexID' for launchtype 'Coalescing'}}
{ }

[Shader("node")]
[NodeLaunch("coalescing")]
[NumThreads(1024, 1, 1)]
[NodeIsProgramEntry]
void buz(uint tid : SV_GROUPINDEX)
{ }