Skip to content

Commit f4072fc

Browse files
committed
Add cbuffer name to cbuffer type, it's a unique type
1 parent 3a10a5c commit f4072fc

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class ResourceTypeInfo {
300300
: ResourceTypeInfo(HandleTy, {}, dxil::ResourceKind::Invalid) {}
301301

302302
TargetExtType *getHandleTy() const { return HandleTy; }
303-
LLVM_ABI StructType *createElementStruct();
303+
LLVM_ABI StructType *createElementStruct(StringRef CBufferName = "");
304304

305305
// Conditions to check before accessing specific views.
306306
LLVM_ABI bool isUAV() const;

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static StructType *getOrCreateElementStruct(Type *ElemType, StringRef Name) {
297297
return StructType::create(ElemType, Name);
298298
}
299299

300-
StructType *ResourceTypeInfo::createElementStruct() {
300+
StructType *ResourceTypeInfo::createElementStruct(StringRef CBufferName) {
301301
SmallString<64> TypeName;
302302

303303
switch (Kind) {
@@ -352,7 +352,12 @@ StructType *ResourceTypeInfo::createElementStruct() {
352352
auto *RTy = cast<CBufferExtType>(HandleTy);
353353
LayoutExtType *LayoutType = cast<LayoutExtType>(RTy->getResourceType());
354354
StructType *Ty = cast<StructType>(LayoutType->getWrappedType());
355-
return StructType::create(Ty->elements(), getResourceKindName(Kind));
355+
SmallString<64> Name = getResourceKindName(Kind);
356+
if (!CBufferName.empty()) {
357+
Name.append(".");
358+
Name.append(CBufferName);
359+
}
360+
return StructType::create(Ty->elements(), Name);
356361
}
357362
case ResourceKind::Sampler: {
358363
auto *RTy = cast<SamplerExtType>(HandleTy);

llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static NamedMDNode *emitResourceMetadata(Module &M, DXILResourceMap &DRM,
7979

8080
for (ResourceInfo &RI : DRM)
8181
if (!RI.hasSymbol())
82-
RI.createSymbol(M, DRTM[RI.getHandleTy()].createElementStruct());
82+
RI.createSymbol(M,
83+
DRTM[RI.getHandleTy()].createElementStruct(RI.getName()));
8384

8485
SmallVector<Metadata *> SRVs, UAVs, CBufs, Smps;
8586
for (const ResourceInfo &RI : DRM.srvs())

llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ target triple = "dxil-pc-shadermodel6.6-compute"
1111

1212
%__cblayout_CB2 = type <{ float, double, float, half, i16, i64, i32 }>
1313
@CB2.cb = global target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32)) poison
14-
@CB2.str = private unnamed_addr constant [4 x i8] c"CB2\00", align 1
1514

1615
%__cblayout_MyConstants = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
1716
@MyConstants.cb = global target("dx.CBuffer", target("dx.Layout", %__cblayout_MyConstants, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)) poison
@@ -22,7 +21,7 @@ target triple = "dxil-pc-shadermodel6.6-compute"
2221
; PRINT-NEXT:; Name Type Format Dim ID HLSL Bind Count
2322
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
2423
; PRINT-NEXT:; CB1 cbuffer NA NA CB0 cb0 1
25-
; PRINT-NEXT:; CB2 cbuffer NA NA CB1 cb1 1
24+
; PRINT-NEXT:; cbuffer NA NA CB1 cb1 1
2625
; PRINT-NEXT:; MyConstants cbuffer NA NA CB2 cb5,space15 1
2726

2827
define void @test() #0 {
@@ -46,7 +45,7 @@ define void @test() #0 {
4645
;}
4746

4847
%CB2.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
49-
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false, ptr @CB2.str)
48+
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false, ptr null)
5049
; cbuffer CB3 : register(b5) {
5150
; double B0;
5251
; float3 B1;
@@ -66,14 +65,14 @@ define void @test() #0 {
6665

6766
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
6867

69-
; CHECK: @CB1 = external constant %CBuffer
70-
; CHECK: @CB2 = external constant %CBuffer.0
71-
; CHECK: @MyConstants = external constant %CBuffer.1
68+
; CHECK: @CB1 = external constant %CBuffer.CB1
69+
; CHECK: @0 = external constant %CBuffer
70+
; CHECK: @MyConstants = external constant %CBuffer.MyConstants
7271

7372
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
7473

7574
; CHECK: [[ResList]] = !{null, null, [[CBList:[!][0-9]+]], null}
7675
; CHECK: [[CBList]] = !{![[CB1:[0-9]+]], ![[CB2:[0-9]+]], ![[MYCONSTANTS:[0-9]+]]}
7776
; CHECK: ![[CB1]] = !{i32 0, ptr @CB1, !"CB1", i32 0, i32 0, i32 1, i32 24, null}
78-
; CHECK: ![[CB2]] = !{i32 1, ptr @CB2, !"CB2", i32 0, i32 1, i32 1, i32 36, null}
77+
; CHECK: ![[CB2]] = !{i32 1, ptr @0, !"", i32 0, i32 1, i32 1, i32 36, null}
7978
; CHECK: ![[MYCONSTANTS]] = !{i32 2, ptr @MyConstants, !"MyConstants", i32 15, i32 5, i32 1, i32 96, null}

0 commit comments

Comments
 (0)