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
2 changes: 2 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ 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).
- Starting with HLSL 202x, `cbuffer` and `tbuffer` declarations and their
members belong to their enclosing namespace.

#### SPIR-V

Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15446,6 +15446,9 @@ HLSLBufferDecl::Create(ASTContext &C, DeclContext *lexicalParent, bool cbuffer,
std::vector<hlsl::UnusualAnnotation *> &BufferAttributes,
SourceLocation LBrace) {
DeclContext *DC = C.getTranslationUnitDecl();
// In HLSL 202x, buffers and their members belong to the enclosing namespace.
if (C.getLangOpts().HLSLVersion >= hlsl::LangStd::v202x)
DC = lexicalParent;
Comment on lines +15450 to +15451

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is separately fixed in #8935, which disallows cbuffers in cbuffers and namespaces in cbuffers.

HLSLBufferDecl *result = ::new (C) HLSLBufferDecl(
DC, cbuffer, constantbuffer, KwLoc, Id, IdLoc, BufferAttributes, LBrace);
if (DC != lexicalParent) {
Expand Down
23 changes: 23 additions & 0 deletions tools/clang/test/CodeGenDXIL/cbuffer.namespace.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %dxc -T ps_6_0 -E main -HV 202x %s | FileCheck %s

// CHECK: ; cbuffer SceneConstants
// CHECK: ; cbuffer SceneConstants
// CHECK: ; Resource Bindings:
// CHECK-DAG: ; SceneConstants{{ +}}cbuffer{{ +}}NA{{ +}}NA{{ +}}CB0{{ +}}cb3{{ +}}1
// CHECK-DAG: ; SceneConstants{{ +}}cbuffer{{ +}}NA{{ +}}NA{{ +}}CB1{{ +}}cb4{{ +}}1

namespace First {
cbuffer SceneConstants : register(b3) {
float Value;
}
}

namespace Second {
cbuffer SceneConstants : register(b4) {
float Value;
}
}

float4 main() : SV_Target {
return First::Value + Second::Value;
}
22 changes: 22 additions & 0 deletions tools/clang/test/CodeGenSPIRV/cbuffer.namespace.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %dxc -T ps_6_0 -E main -HV 202x -spirv -fcgl %s | FileCheck %s

// CHECK-DAG: OpDecorate [[FIRST:%[^ ]+]] Binding 3
// CHECK-DAG: OpDecorate [[SECOND:%[^ ]+]] Binding 4
// CHECK-DAG: [[FIRST]] = OpVariable {{%[^ ]+}} Uniform
// CHECK-DAG: [[SECOND]] = OpVariable {{%[^ ]+}} Uniform

namespace First {
cbuffer SceneConstants : register(b3) {
float Value;
}
}

namespace Second {
cbuffer SceneConstants : register(b4) {
float Value;
}
}

float4 main() : SV_Target {
return First::Value + Second::Value;
}
35 changes: 35 additions & 0 deletions tools/clang/test/SemaHLSL/v202x/buffer-namespace-decl-context.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %dxc -T lib_6_3 -HV 202x -verify %s
// RUN: %dxc -T lib_6_3 -HV 202x -ast-dump %s 2>&1 | FileCheck %s

// expected-no-diagnostics

namespace First {
// CHECK: NamespaceDecl {{.*}} First
// CHECK-NEXT: {{.*}}HLSLBufferDecl {{0x[0-9a-f]+}} <{{.*}}> {{.*}} cbuffer Constants
cbuffer Constants {
float FirstValue;
}

// CHECK: HLSLBufferDecl {{0x[0-9a-f]+}} <{{.*}}> {{.*}} tbuffer Textures
tbuffer Textures {
float FirstTextureValue;
}
}

namespace Second {
// CHECK: NamespaceDecl {{.*}} Second
// CHECK-NEXT: {{.*}}HLSLBufferDecl {{0x[0-9a-f]+}} <{{.*}}> {{.*}} cbuffer Constants
cbuffer Constants {
float SecondValue;
}

// CHECK: HLSLBufferDecl {{0x[0-9a-f]+}} <{{.*}}> {{.*}} tbuffer Textures
tbuffer Textures {
float SecondTextureValue;
}
}

float4 main() : SV_Target {
return First::FirstValue + First::FirstTextureValue +
Second::SecondValue + Second::SecondTextureValue;
}
Loading