Skip to content

[HLSL] Update DXIL resource metadata code to support resource arrays #152254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 11, 2025

Conversation

hekota
Copy link
Member

@hekota hekota commented Aug 6, 2025

Closes #145422

@llvmbot llvmbot added backend:DirectX llvm:analysis Includes value tracking, cost tables and constant folding labels Aug 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)

Changes

Closes #145422

Depends on #152253 and #152250


Full diff: https://github.com/llvm/llvm-project/pull/152254.diff

3 Files Affected:

  • (modified) llvm/lib/Analysis/DXILResource.cpp (+6-1)
  • (modified) llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll (+2-2)
  • (modified) llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll (+2-2)
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index 629fa7cddb9d4..109c0568a6f9e 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -612,7 +612,12 @@ void ResourceTypeInfo::print(raw_ostream &OS, const DataLayout &DL) const {
 
 GlobalVariable *ResourceInfo::createSymbol(Module &M, StructType *Ty) {
   assert(!Symbol && "Symbol has already been created");
-  Symbol = new GlobalVariable(M, Ty, /*isConstant=*/true,
+  Type *ResTy = Ty;
+  int64_t Size = Binding.Size;
+  if (Size != 1)
+    // unbounded arrays are represented as zero-sized arrays in LLVM IR
+    ResTy = ArrayType::get(Ty, Size == ~0u ? 0 : Size);
+  Symbol = new GlobalVariable(M, ResTy, /*isConstant=*/true,
                               GlobalValue::ExternalLinkage,
                               /*Initializer=*/nullptr, Name);
   return Symbol;
diff --git a/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll b/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
index b27020633e3a2..86d69abc75760 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
@@ -105,8 +105,8 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
 ; CHECK: @Four = external constant %ByteAddressBuffer
 ; CHECK: @Five = external constant %"StructuredBuffer<int16_t>"
 ; CHECK: @Six = external constant %"Buffer<uint32_t>"
-; CHECK: @Array = external constant %"Buffer<float4>"
-; CHECK: @Array2 = external constant %"Buffer<double>"
+; CHECK: @Array = external constant [100 x %"Buffer<float4>"]
+; CHECK: @Array2 = external constant [0 x %"Buffer<double>"]
 ; CHECK: @Seven = external constant %"Buffer<uint32_t>"
 
 ; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
diff --git a/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll b/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
index 77f36dd40fd7c..4928b1d0bab97 100644
--- a/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
+++ b/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
@@ -128,8 +128,8 @@ attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
 ; CHECK: @Seven = external constant %"RasterizerOrderedStructuredBuffer<int32_t4>"
 ; CHECK: @Eight = external constant %RasterizerOrderedByteAddressBuffer
 ; CHECK: @Nine = external constant %"RWBuffer<uint32_t>"
-; CHECK: @Array = external constant %"RWBuffer<float4>"
-; CHECK: @Array2 = external constant %"RWBuffer<double>"
+; CHECK: @Array = external constant [100 x %"RWBuffer<float4>"]
+; CHECK: @Array2 = external constant [0 x %"RWBuffer<double>"]
 ; CHECK: @Ten = external constant %"RWBuffer<uint32_t>"
 
 ; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}

@hekota hekota changed the base branch from users/hekota/pr152253-fix-resource-binding-unique-error to main August 11, 2025 20:18
@hekota hekota merged commit 5165a6c into llvm:main Aug 11, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX llvm:analysis Includes value tracking, cost tables and constant folding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DirectX] Add support for resource arrays to DXIL resource metadata
5 participants