Skip to content

Commit 07ec283

Browse files
committed
Remove resource handle from HLSLBufDecl, cleanup tests
1 parent b88886b commit 07ec283

File tree

9 files changed

+96
-176
lines changed

9 files changed

+96
-176
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4967,7 +4967,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
49674967
SourceLocation getRBraceLoc() const { return RBraceLoc; }
49684968
void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
49694969
bool isCBuffer() const { return IsCBuffer; }
4970-
const Type *getResourceHandleType() const;
49714970

49724971
// Implement isa/cast/dyncast/etc.
49734972
static bool classof(const Decl *D) { return classofKind(D->getKind()); }

clang/lib/AST/Decl.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,19 +5693,6 @@ HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C,
56935693
SourceLocation(), SourceLocation());
56945694
}
56955695

5696-
const Type *HLSLBufferDecl::getResourceHandleType() const {
5697-
// Resource handle is the last decl in the HLSLBufferDecl.
5698-
// If it is not present, it probably means the buffer is empty.
5699-
if (VarDecl *VD = llvm::dyn_cast_or_null<VarDecl>(LastDecl)) {
5700-
const Type *Ty = VD->getType().getTypePtr();
5701-
if (Ty->isHLSLAttributedResourceType()) {
5702-
assert(VD->getNameAsString() == "__handle");
5703-
return Ty;
5704-
}
5705-
}
5706-
return nullptr;
5707-
}
5708-
57095696
//===----------------------------------------------------------------------===//
57105697
// ImportDecl Implementation
57115698
//===----------------------------------------------------------------------===//

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,10 @@ void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
159159
CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
160160
}
161161

162-
void CGHLSLRuntime::addBufferDecls(const HLSLBufferDecl *D, Buffer &CB) {
163-
for (Decl *it : D->decls()) {
162+
void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
163+
for (Decl *it : DC->decls()) {
164164
if (auto *ConstDecl = dyn_cast<VarDecl>(it)) {
165-
if (ConstDecl->getType().getTypePtr() != D->getResourceHandleType()) {
166-
addConstant(ConstDecl, CB);
167-
}
165+
addConstant(ConstDecl, CB);
168166
} else if (isa<CXXRecordDecl, EmptyDecl>(it)) {
169167
// Nothing to do for this declaration.
170168
} else if (isa<FunctionDecl>(it)) {

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class CGHLSLRuntime {
169169
llvm::hlsl::ElementType ET,
170170
BufferResBinding &Binding);
171171
void addConstant(VarDecl *D, Buffer &CB);
172-
void addBufferDecls(const HLSLBufferDecl *D, Buffer &CB);
172+
void addBufferDecls(const DeclContext *D, Buffer &CB);
173173
llvm::Triple::ArchType getArch();
174174
llvm::SmallVector<Buffer> Buffers;
175175

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -469,27 +469,6 @@ static CXXRecordDecl *createHostLayoutStructForBuffer(Sema &S,
469469
return LS;
470470
}
471471

472-
// Creates a "__handle" declaration for the HLSL Buffer type
473-
// with the corresponding HLSL resource type and adds it to the HLSLBufferDecl
474-
static void createHLSLBufferHandle(Sema &S, HLSLBufferDecl *BufDecl,
475-
CXXRecordDecl *LayoutStruct) {
476-
ASTContext &AST = S.getASTContext();
477-
478-
HLSLAttributedResourceType::Attributes ResAttrs(
479-
BufDecl->isCBuffer() ? ResourceClass::CBuffer : ResourceClass::SRV, false,
480-
false);
481-
QualType ResHandleTy = AST.getHLSLAttributedResourceType(
482-
AST.HLSLResourceTy, QualType(LayoutStruct->getTypeForDecl(), 0),
483-
ResAttrs);
484-
485-
IdentifierInfo *II = &AST.Idents.get("__handle", tok::TokenKind::identifier);
486-
VarDecl *VD = VarDecl::Create(
487-
BufDecl->getASTContext(), BufDecl, SourceLocation(), SourceLocation(), II,
488-
ResHandleTy, AST.getTrivialTypeSourceInfo(ResHandleTy, SourceLocation()),
489-
SC_None);
490-
BufDecl->addDecl(VD);
491-
}
492-
493472
// Handle end of cbuffer/tbuffer declaration
494473
void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
495474
auto *BufDecl = cast<HLSLBufferDecl>(Dcl);
@@ -501,9 +480,6 @@ void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
501480
CXXRecordDecl *LayoutStruct =
502481
createHostLayoutStructForBuffer(SemaRef, BufDecl);
503482

504-
// create buffer resource handle
505-
createHLSLBufferHandle(SemaRef, BufDecl, LayoutStruct);
506-
507483
SemaRef.PopDeclContext();
508484
}
509485

clang/test/AST/HLSL/ast-dump-comment-cbuffe-tbufferr.hlsl

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: %clang_cc1 -Wdocumentation -ast-dump=json -x hlsl -triple dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefix=JSON
2+
// RUN: %clang_cc1 -Wdocumentation -ast-dump -x hlsl -triple dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefix=AST
3+
4+
// JSON:"kind": "HLSLBufferDecl",
5+
// JSON:"name": "A",
6+
// JSON-NEXT:"bufferKind": "cbuffer",
7+
// JSON:"kind": "TextComment",
8+
// JSON:"text": " CBuffer decl."
9+
10+
/// CBuffer decl.
11+
cbuffer A {
12+
// JSON: "kind": "VarDecl",
13+
// JSON: "name": "a",
14+
// JSON: "qualType": "float"
15+
float a;
16+
// JSON: "kind": "VarDecl",
17+
// JSON: "name": "b",
18+
// JSON: "qualType": "int"
19+
int b;
20+
}
21+
22+
// JSON:"kind": "HLSLBufferDecl",
23+
// JSON:"name": "B",
24+
// JSON-NEXT:"bufferKind": "tbuffer",
25+
// JSON:"kind": "TextComment",
26+
// JSON:"text": " TBuffer decl."
27+
28+
/// TBuffer decl.
29+
tbuffer B {
30+
// JSON: "kind": "VarDecl",
31+
// JSON: "name": "c",
32+
// JSON: "qualType": "float"
33+
float c;
34+
// JSON: "kind": "VarDecl",
35+
// JSON: "name": "d",
36+
// JSON: "qualType": "int"
37+
int d;
38+
}
39+
40+
// AST: HLSLBufferDecl {{.*}} line:11:9 cbuffer A
41+
// AST-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
42+
// AST-NEXT: HLSLResourceAttr {{.*}} Implicit CBuffer
43+
// AST-NEXT: FullComment
44+
// AST-NEXT: ParagraphComment
45+
// AST-NEXT: TextComment {{.*}} Text=" CBuffer decl."
46+
// AST-NEXT: VarDecl {{.*}} a 'float'
47+
// AST-NEXT: VarDecl {{.*}} b 'int'
48+
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.A definition
49+
// AST: FieldDecl {{.*}} a 'float'
50+
// AST-NEXT: FieldDecl {{.*}} b 'int'
51+
52+
// AST-NEXT: HLSLBufferDecl {{.*}} line:29:9 tbuffer B
53+
// AST-NEXT: HLSLResourceClassAttr {{.*}} Implicit SRV
54+
// AST-NEXT: HLSLResourceAttr {{.*}} Implicit TBuffer
55+
// AST-NEXT: FullComment
56+
// AST-NEXT: ParagraphComment
57+
// AST-NEXT: TextComment {{.*}} Text=" TBuffer decl."
58+
// AST-NEXT: VarDecl {{.*}} c 'float'
59+
// AST-NEXT: VarDecl {{.*}} d 'int'
60+
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
61+
// AST: FieldDecl {{.*}} c 'float'
62+
// AST-NEXT: FieldDecl {{.*}} d 'int'

clang/test/AST/HLSL/cbuffer.hlsl

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@ typedef float EmptyArrayTypedef[10][0];
4141
cbuffer CB {
4242
// CHECK: VarDecl {{.*}} col:9 used a1 'float'
4343
float a1;
44-
4544
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB definition
4645
// CHECK: FieldDecl {{.*}} a1 'float'
47-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
48-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB)]]'
4946
}
5047

5148
// Check that buffer layout struct does not include resources or empty types
52-
// CHECK: HLSLBufferDecl {{.*}} line:55:9 cbuffer CB
49+
// CHECK: HLSLBufferDecl {{.*}} line:52:9 cbuffer CB
5350
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
5451
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
5552
cbuffer CB {
@@ -63,16 +60,13 @@ cbuffer CB {
6360
float d2[0];
6461
// CHECK: VarDecl {{.*}} col:9 e2 'float'
6562
float e2;
66-
6763
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.1 definition
6864
// CHECK: FieldDecl {{.*}} a2 'float'
6965
// CHECK-NEXT: FieldDecl {{.*}} e2 'float'
70-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
71-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.1)]]'
7266
}
7367

7468
// Check that layout struct is created for B and the empty struct C is removed
75-
// CHECK: HLSLBufferDecl {{.*}} line:78:9 cbuffer CB
69+
// CHECK: HLSLBufferDecl {{.*}} line:72:9 cbuffer CB
7670
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
7771
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
7872
cbuffer CB {
@@ -82,60 +76,47 @@ cbuffer CB {
8276
B s2;
8377
// CHECK: VarDecl {{.*}} col:12 s3 'CTypedef':'C
8478
CTypedef s3;
85-
8679
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
8780
// CHECK: FieldDecl {{.*}} a 'float'
88-
8981
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.2 definition
9082
// CHECK: FieldDecl {{.*}} s1 'A'
9183
// CHECK: FieldDecl {{.*}} s2 '__hostlayout.struct.B'
92-
// CHECK-NEXT: VarDecl {{.*}} __handle '__hlsl_resource_t
93-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.2)]]'
9484
}
9585

9686
// check that layout struct is created for D because of its base struct
97-
// CHECK: HLSLBufferDecl {{.*}} line:100:9 cbuffer CB
87+
// CHECK: HLSLBufferDecl {{.*}} line:90:9 cbuffer CB
9888
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
9989
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
10090
cbuffer CB {
10191
// CHECK: VarDecl {{.*}} s4 'D'
10292
D s4;
103-
10493
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.D definition
10594
// CHECK: FieldDecl {{.*}} b 'float'
106-
10795
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.3 definition
10896
// CHECK: FieldDecl {{.*}} s4 '__hostlayout.struct.D'
109-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
110-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.3)]]'
11197
}
11298

11399
// check that layout struct is created for E because because its base struct
114100
// is empty and should be eliminated, and BTypedef should reuse the previously
115101
// defined '__hostlayout.struct.B'
116-
// CHECK: HLSLBufferDecl {{.*}} line:119:9 cbuffer CB
102+
// CHECK: HLSLBufferDecl {{.*}} line:105:9 cbuffer CB
117103
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
118104
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
119105
cbuffer CB {
120106
// CHECK: VarDecl {{.*}} s5 'E'
121107
E s5;
122108
// CHECK: VarDecl {{.*}} s6 'BTypedef':'B'
123109
BTypedef s6;
124-
125110
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.E definition
126111
// CHECK: FieldDecl {{.*}} c 'float'
127-
128112
// CHECK-NOT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
129-
130113
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.4 definition
131114
// CHECK: FieldDecl {{.*}} s5 '__hostlayout.struct.E'
132115
// CHECK: FieldDecl {{.*}} s6 '__hostlayout.struct.B'
133-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
134-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.4)]]'
135116
}
136117

137118
// check that this produces empty layout struct
138-
// CHECK: HLSLBufferDecl {{.*}} line:141:9 cbuffer CB
119+
// CHECK: HLSLBufferDecl {{.*}} line:122:9 cbuffer CB
139120
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
140121
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
141122
cbuffer CB {
@@ -149,32 +130,25 @@ cbuffer CB {
149130
RWBuffer<float> Buf;
150131
// CHECK: VarDecl {{.*}} ea 'EmptyArrayTypedef':'float[10][0]'
151132
EmptyArrayTypedef ea;
152-
153133
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.5 definition
154134
// CHECK-NOT: FieldDecl
155-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
156-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.5)]]'
157135
}
158136

159137
// check host layout struct with compatible base struct
160-
// CHECK: HLSLBufferDecl {{.*}} line:163:9 cbuffer CB
138+
// CHECK: HLSLBufferDecl {{.*}} line:141:9 cbuffer CB
161139
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
162140
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
163141
cbuffer CB {
164142
// CHECK: VarDecl {{.*}} s8 'F'
165143
F s8;
166-
167144
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.F definition
168145
// CHECK: public 'A'
169-
170146
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.6 definition
171147
// CHECK: FieldDecl {{.*}} s8 '__hostlayout.struct.F'
172-
// CHECK: VarDecl {{.*}} __handle '__hlsl_resource_t
173-
// CHECK-SAME{LITERAL}: [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.6)]]'
174148
}
175149

176150
// anonymous structs
177-
// CHECK: HLSLBufferDecl {{.*}} line:180:9 cbuffer CB
151+
// CHECK: HLSLBufferDecl {{.*}} line:154:9 cbuffer CB
178152
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
179153
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
180154
cbuffer CB {
@@ -187,31 +161,25 @@ cbuffer CB {
187161
// CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>'
188162
RWBuffer<float> f;
189163
} s9;
190-
// CHECK: VarDecl {{.*}} s9 'struct (unnamed struct at {{.*}}cbuffer.hlsl:182:3
191-
164+
// CHECK: VarDecl {{.*}} s9 'struct (unnamed struct at {{.*}}cbuffer.hlsl:156:3
192165
// CHECK: CXXRecordDecl {{.*}} struct definition
193166
struct {
194167
// CHECK: FieldDecl {{.*}} g 'int'
195168
int g;
196169
// CHECK: FieldDecl {{.*}} f 'RWBuffer<float>':'hlsl::RWBuffer<float>'
197170
RWBuffer<float> f;
198171
} s10;
199-
// CHECK: VarDecl {{.*}} s10 'struct (unnamed struct at {{.*}}cbuffer.hlsl:193:3
200-
172+
// CHECK: VarDecl {{.*}} s10 'struct (unnamed struct at {{.*}}cbuffer.hlsl:166:3
201173
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.anon definition
202174
// CHECK: FieldDecl {{.*}} e 'float'
203-
204175
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.anon.1 definition
205176
// CHECK: FieldDecl {{.*}} g 'int'
206-
207177
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.7 definition
208178
// CHECK: FieldDecl {{.*}} s9 '__hostlayout.struct.anon'
209179
// CHECK: FieldDecl {{.*}} s10 '__hostlayout.struct.anon.1'
210-
// CHECK-NEXT: VarDecl {{.*}} __handle '__hlsl_resource_t
211-
// CHECK-SAME{LITERAL} [[hlsl::resource_class(CBuffer)]] [[hlsl::contained_type(__hostlayout.struct.CB.7)]]'
212180
}
213181

214-
// Add uses for the constant buffer declarations so they are not optimized awayexport
182+
// Add uses for the constant buffer declarations so they are not optimized away
215183
export float foo() {
216184
return a1 + a2 + s1.a + s4.b + s5.c + s8.a + s9.e;
217185
}

0 commit comments

Comments
 (0)