Skip to content

Commit 5165a6c

Browse files
authored
[HLSL] Update DXIL resource metadata code to support resource arrays (#152254)
Closes #145422
1 parent 0036923 commit 5165a6c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,12 @@ void ResourceTypeInfo::print(raw_ostream &OS, const DataLayout &DL) const {
612612

613613
GlobalVariable *ResourceInfo::createSymbol(Module &M, StructType *Ty) {
614614
assert(!Symbol && "Symbol has already been created");
615-
Symbol = new GlobalVariable(M, Ty, /*isConstant=*/true,
615+
Type *ResTy = Ty;
616+
int64_t Size = Binding.Size;
617+
if (Size != 1)
618+
// unbounded arrays are represented as zero-sized arrays in LLVM IR
619+
ResTy = ArrayType::get(Ty, Size == ~0u ? 0 : Size);
620+
Symbol = new GlobalVariable(M, ResTy, /*isConstant=*/true,
616621
GlobalValue::ExternalLinkage,
617622
/*Initializer=*/nullptr, Name);
618623
return Symbol;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
105105
; CHECK: @Four = external constant %ByteAddressBuffer
106106
; CHECK: @Five = external constant %"StructuredBuffer<int16_t>"
107107
; CHECK: @Six = external constant %"Buffer<uint32_t>"
108-
; CHECK: @Array = external constant %"Buffer<float4>"
109-
; CHECK: @Array2 = external constant %"Buffer<double>"
108+
; CHECK: @Array = external constant [100 x %"Buffer<float4>"]
109+
; CHECK: @Array2 = external constant [0 x %"Buffer<double>"]
110110
; CHECK: @Seven = external constant %"Buffer<uint32_t>"
111111

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
128128
; CHECK: @Seven = external constant %"RasterizerOrderedStructuredBuffer<int32_t4>"
129129
; CHECK: @Eight = external constant %RasterizerOrderedByteAddressBuffer
130130
; CHECK: @Nine = external constant %"RWBuffer<uint32_t>"
131-
; CHECK: @Array = external constant %"RWBuffer<float4>"
132-
; CHECK: @Array2 = external constant %"RWBuffer<double>"
131+
; CHECK: @Array = external constant [100 x %"RWBuffer<float4>"]
132+
; CHECK: @Array2 = external constant [0 x %"RWBuffer<double>"]
133133
; CHECK: @Ten = external constant %"RWBuffer<uint32_t>"
134134

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

0 commit comments

Comments
 (0)