Skip to content

Commit 499bf9b

Browse files
committed
[DXIL][Analysis] Make sure resource accessors are contiguous
When some resource types were present, but not all of them, we were ending up in a situation where we would fail to initialize the `FirstX` variables and get incorrect iterators. Fixes #128560.
1 parent f404047 commit 499bf9b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,11 @@ void DXILBindingMap::populate(Module &M, DXILResourceTypeMap &DRTM) {
749749
NextID = 0;
750750
}
751751

752+
// We need to make sure the types of resource are ordered even if some are
753+
// missing.
754+
FirstCBuffer = std::min({FirstCBuffer, FirstSampler});
755+
FirstUAV = std::min({FirstUAV, FirstCBuffer});
756+
752757
// Adjust the resource binding to use the next ID.
753758
RBI.setBindingID(NextID++);
754759
}

llvm/test/Analysis/DXILResource/buffer-frombinding.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ define void @test_typedbuffer() {
106106
; CHECK: Element Type: f32
107107
; CHECK: Element Count: 4
108108

109+
%cb0 = call target("dx.CBuffer", target("dx.Layout", {float}, 4, 0))
110+
@llvm.dx.resource.handlefrombinding(i32 1, i32 8, i32 1, i32 0, i1 false)
111+
; CHECK: Binding [[CB0:[0-9]+]]:
112+
; CHECK: Binding:
113+
; CHECK: Record ID: 0
114+
; CHECK: Space: 1
115+
; CHECK: Lower Bound: 8
116+
; CHECK: Size: 1
117+
; CHECK: Class: CBuffer
118+
; CHECK: Kind: CBuffer
119+
109120
; CHECK-NOT: Binding {{[0-9]+}}:
110121

111122
ret void
@@ -118,5 +129,6 @@ define void @test_typedbuffer() {
118129
; CHECK-DAG: Call bound to [[UAV1]]: %uav1 =
119130
; CHECK-DAG: Call bound to [[UAV2]]: %uav2_1 =
120131
; CHECK-DAG: Call bound to [[UAV2]]: %uav2_2 =
132+
; CHECK-DAG: Call bound to [[CB0]]: %cb0 =
121133

122134
attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Regression test for https://github.com/llvm/llvm-project/issues/128560 -
2+
; check that cbuffers are populated correctly when there aren't any other kinds
3+
; of resource.
4+
5+
; RUN: opt -S -passes=dxil-translate-metadata %s | FileCheck %s
6+
7+
target triple = "dxil-pc-shadermodel6.6-compute"
8+
9+
define void @cbuffer_is_only_binding() {
10+
%cbuf = call target("dx.CBuffer", target("dx.Layout", {float}, 4, 0))
11+
@llvm.dx.resource.handlefrombinding(i32 1, i32 8, i32 1, i32 0, i1 false)
12+
; CHECK: %cbuffer = type
13+
14+
ret void
15+
}
16+
17+
; CHECK: @[[CB0:.*]] = external constant %cbuffer
18+
19+
; CHECK: !{i32 0, ptr @[[CB0]], !""

0 commit comments

Comments
 (0)