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
3 changes: 3 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ line upon naming the release. Refer to previous for appropriate section names.
- The `shared` and `uniform` keywords are removed in HLSL 202x, with
compatibility warnings available for earlier language versions
[#8482](https://github.com/microsoft/DirectXShaderCompiler/issues/8482).
- HLSL 202x disallows putting cbuffer, tbuffer, or namespace declarations inside
a cbuffer or tbuffer
[#8484](https://github.com/microsoft/DirectXShaderCompiler/issues/8484).

#### SPIR-V

Expand Down
2 changes: 2 additions & 0 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7926,6 +7926,8 @@ def err_hlsl_unsupported_object_context
"entry function parameters|entry function return type|"
"patch constant function parameters|patch constant function return type|"
"payload parameters|attributes|builtin template parameters|structured buffers|global variables|groupshared variables}1">;
def err_hlsl_unsupported_declaration_in_buffer : Error<
"unsupported declaration %0 in %select{tbuffer|cbuffer}1 declaration">;
def err_hlsl_logical_binop_scalar : Error<
"operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '%select{and|or}0'">;
def err_hlsl_ternary_scalar : Error<
Expand Down
13 changes: 13 additions & 0 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15363,6 +15363,19 @@ void Sema::ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace) {
bool HasPackOffset = false;
bool HasNonPackOffset = false;
for (auto *Field : BufDecl->decls()) {
// HLSL 202x 0005 Cbuffer Contexts proposal restricts the contents of a
// cbuffer to classes (records), functions, variables, and empty
// declarations (see: https://hlsl-tc57.github.io/tc57/proposal/0005/)
if (getLangOpts().HLSLVersion >= hlsl::LangStd::v202x &&
Comment thread
llvm-beanz marked this conversation as resolved.
(isa<HLSLBufferDecl>(Field) || isa<NamespaceDecl>(Field))) {
Comment on lines +15369 to +15370
NamedDecl *ND = cast<NamedDecl>(Field);
Diag(Field->getLocation(),
diag::err_hlsl_unsupported_declaration_in_buffer)
<< ND << BufDecl->isCBuffer();
Diag(Dcl->getLocation(), diag::note_declared_at);
Dcl->setInvalidDecl();
}

VarDecl *Var = dyn_cast<VarDecl>(Field);
if (!Var)
continue;
Expand Down
57 changes: 57 additions & 0 deletions tools/clang/test/SemaHLSL/hlsl/202x-cbuffer-contexts.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// RUN: %dxc -T lib_6_9 -verify -HV 202x %s

cbuffer A { // expected-note{{declared here}}
int Y;
// expected-error@+1 {{unsupported declaration 'N' in cbuffer declaration}}
namespace N {
}
float4 F5;
}

cbuffer A { // expected-note{{declared here}}
// expected-error@+1 {{unsupported declaration 'Nested' in cbuffer declaration}}
cbuffer Nested {
}
}

tbuffer TB { // expected-note{{declared here}}
// expected-error@+1 {{unsupported declaration 'NS' in tbuffer declaration}}
namespace NS {}
}

tbuffer TB2 { // expected-note{{declared here}}
// expected-error@+1{{unsupported declaration 'CB2' in tbuffer declaration}}
cbuffer CB2 {
int X;
}
}

namespace Valid {
cbuffer CBValid {
int CompletelyFine;
}

tbuffer TBValid {
float StillFine;
}

cbuffer GoingOffTheRails { // expected-note{{declared here}}
// expected-error@+1{{unsupported declaration 'NotCool' in cbuffer declaration}}
tbuffer NotCool {
; // even if it is empty...
}
}

cbuffer GoingOffTheRailsAgain { // expected-note{{declared here}}
// expected-error@+1{{unsupported declaration 'StillNotCool' in cbuffer declaration}}
tbuffer StillNotCool { // expected-note{{declared here}}
// expected-error@+1{{unsupported declaration 'Turtles' in tbuffer declaration}}
cbuffer Turtles { // expected-note{{declared here}}
// expected-error@+1{{unsupported declaration 'AllTheWayDown' in cbuffer declaration}}
tbuffer AllTheWayDown {
;
}
}
}
}
}
Loading