Skip to content

Commit e661673

Browse files
authored
[HLSL] fix case-sensitive semantics for workgraphs (microsoft#8029)
The function handling semantics for work graphs were case sensitive, but shouldn't. This commit addresses that. Fixes microsoft#8014
1 parent de4f235 commit e661673

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ line upon naming the release. Refer to previous for appropriate section names.
3737
- `dx::IsDebuggerPresent()` returns true if a debugger is attached.
3838
- SPIR-V: `DebugBreak()` emits `NonSemantic.DebugBreak` extended instruction; `IsDebuggerPresent()` is not supported.
3939

40+
#### Other Changes
41+
- Fixed mesh shader semantics that were incorrectly case sensitive.
42+
4043
### Version 1.9.2602
4144

4245
#### Shader Model 6.9 Release

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "VkConstantsTables.h"
1515
#include "dxc/DXIL/DxilConstants.h"
1616
#include "dxc/DXIL/DxilFunctionProps.h"
17+
#include "dxc/DXIL/DxilSemantic.h"
1718
#include "dxc/DXIL/DxilShaderModel.h"
1819
#include "dxc/DXIL/DxilUtil.h"
1920
#include "dxc/HLSL/HLOperations.h"
@@ -11721,7 +11722,6 @@ void hlsl::DiagnoseRegisterType(clang::Sema *self, clang::SourceLocation loc,
1172111722

1172211723
// FIXME: DiagnoseSVForLaunchType is wrong in multiple ways:
1172311724
// - It doesn't handle system values inside structs
11724-
// - It doesn't account for the fact that semantics are case-insensitive
1172511725
// - It doesn't account for optional index at the end of semantic name
1172611726
// - It permits any `SV_*` for Broadcasting launch, not just the legal ones
1172711727
// - It doesn't prevent multiple system values with the same semantic
@@ -11731,15 +11731,19 @@ void hlsl::DiagnoseRegisterType(clang::Sema *self, clang::SourceLocation loc,
1173111731
static void DiagnoseSVForLaunchType(const FunctionDecl *FD,
1173211732
DXIL::NodeLaunchType LaunchTy,
1173311733
DiagnosticsEngine &Diags) {
11734+
1173411735
// Validate Compute Shader system value inputs per launch mode
1173511736
for (ParmVarDecl *param : FD->parameters()) {
1173611737
for (const hlsl::UnusualAnnotation *it : param->getUnusualAnnotations()) {
1173711738
if (it->getKind() == hlsl::UnusualAnnotation::UA_SemanticDecl) {
1173811739
const hlsl::SemanticDecl *sd = cast<hlsl::SemanticDecl>(it);
11740+
const auto *semantic = hlsl::Semantic::GetByName(sd->SemanticName);
11741+
assert(semantic->GetKind() != hlsl::Semantic::Kind::Invalid);
11742+
1173911743
// if the node launch type is Thread, then there are no system values
1174011744
// allowed
1174111745
if (LaunchTy == DXIL::NodeLaunchType::Thread) {
11742-
if (sd->SemanticName.startswith("SV_")) {
11746+
if (semantic->GetKind() != hlsl::Semantic::Kind::Arbitrary) {
1174311747
// emit diagnostic
1174411748
unsigned DiagID = Diags.getCustomDiagID(
1174511749
DiagnosticsEngine::Error,
@@ -11752,8 +11756,8 @@ static void DiagnoseSVForLaunchType(const FunctionDecl *FD,
1175211756
// if the node launch type is Coalescing, then only
1175311757
// SV_GroupIndex and SV_GroupThreadID are allowed
1175411758
else if (LaunchTy == DXIL::NodeLaunchType::Coalescing) {
11755-
if (!(sd->SemanticName.equals("SV_GroupIndex") ||
11756-
sd->SemanticName.equals("SV_GroupThreadID"))) {
11759+
if (semantic->GetKind() != hlsl::Semantic::Kind::GroupIndex &&
11760+
semantic->GetKind() != hlsl::Semantic::Kind::GroupThreadID) {
1175711761
// emit diagnostic
1175811762
unsigned DiagID = Diags.getCustomDiagID(
1175911763
DiagnosticsEngine::Error,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %dxc -Tlib_6_8 -verify %s
2+
3+
[Shader("node")]
4+
[NodeLaunch("coalescing")]
5+
[NumThreads(1024, 1, 1)]
6+
[NodeIsProgramEntry]
7+
void foo(uint3 tid : SV_GroupThreadId)
8+
{ }
9+
10+
[Shader("node")]
11+
[NodeLaunch("coalescing")]
12+
[NumThreads(1024, 1, 1)]
13+
[NodeIsProgramEntry]
14+
void bar(uint3 tid : SV_GroupThreadID)
15+
{ }
16+
17+
[Shader("node")]
18+
[NodeLaunch("coalescing")]
19+
[NumThreads(1024, 1, 1)]
20+
[NodeIsProgramEntry]
21+
void baz(uint3 tid : SV_VertexID) // expected-error {{Invalid system value semantic 'SV_VertexID' for launchtype 'Coalescing'}}
22+
{ }
23+
24+
[Shader("node")]
25+
[NodeLaunch("coalescing")]
26+
[NumThreads(1024, 1, 1)]
27+
[NodeIsProgramEntry]
28+
void buz(uint tid : SV_GROUPINDEX)
29+
{ }

0 commit comments

Comments
 (0)