Skip to content

Commit 441759d

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 c79e867 commit 441759d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Analysis/DXILResource.cpp

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

759+
// We need to make sure the types of resource are ordered even if some are
760+
// missing.
761+
FirstCBuffer = std::min({FirstCBuffer, FirstSampler});
762+
FirstUAV = std::min({FirstUAV, FirstCBuffer});
763+
759764
// Adjust the resource binding to use the next ID.
760765
RBI.setBindingID(NextID++);
761766
}
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)