Skip to content

Commit c6d931a

Browse files
hekotabogner
authored andcommitted
Cherry-pick #150547: [HLSL] Fix detection of overlapping binding with unbounded array
Fixes #150534
1 parent 1bd7ccd commit c6d931a

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ class ResourceInfo {
359359
std::tie(RHS.RecordID, RHS.Space, RHS.LowerBound, RHS.Size);
360360
}
361361
bool overlapsWith(const ResourceBinding &RHS) const {
362+
if (Size == UINT32_MAX)
363+
return LowerBound < RHS.LowerBound;
362364
return Space == RHS.Space && LowerBound + Size - 1 >= RHS.LowerBound;
363365
}
364366
};

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,15 +1079,16 @@ void DXILResourceBindingInfo::populate(Module &M, DXILResourceTypeMap &DRTM) {
10791079
// add new space
10801080
S = &BS->Spaces.emplace_back(B.Space);
10811081

1082-
// the space is full - set flag to report overlapping binding later
1083-
if (S->FreeRanges.empty()) {
1082+
// The space is full - there are no free slots left, or the rest of the
1083+
// slots are taken by an unbouded array. Set flag to report overlapping
1084+
// binding later.
1085+
if (S->FreeRanges.empty() || S->FreeRanges.back().UpperBound < UINT32_MAX) {
10841086
OverlappingBinding = true;
10851087
continue;
10861088
}
10871089

10881090
// adjust the last free range lower bound, split it in two, or remove it
10891091
BindingRange &LastFreeRange = S->FreeRanges.back();
1090-
assert(LastFreeRange.UpperBound == UINT32_MAX);
10911092
if (LastFreeRange.LowerBound == B.LowerBound) {
10921093
if (B.UpperBound < UINT32_MAX)
10931094
LastFreeRange.LowerBound = B.UpperBound + 1;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: not opt -S -passes='dxil-post-optimization-validation' -mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
2+
3+
; Check overlap with unbounded array
4+
5+
; A overlaps with B
6+
; RWBuffer<float> A[3] : register(u0);
7+
; RWBuffer<float> B[] : register(u4);
8+
; RWBuffer<float> C : register(u17);
9+
10+
; CHECK: error: resource B at register 4 overlaps with resource C at register 17 in space 0
11+
12+
target triple = "dxil-pc-shadermodel6.3-library"
13+
14+
@A.str = private unnamed_addr constant [2 x i8] c"A\00", align 1
15+
@B.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
16+
@C.str = private unnamed_addr constant [2 x i8] c"C\00", align 1
17+
18+
define void @test_overlapping() {
19+
entry:
20+
%h1 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 3, i32 0, i1 false, ptr @A.str)
21+
%h2 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 4, i32 -1, i32 0, i1 false, ptr @B.str)
22+
%h3 = call target("dx.TypedBuffer", float, 1, 0, 0) @llvm.dx.resource.handlefrombinding(i32 0, i32 17, i32 1, i32 0, i1 false, ptr @C.str)
23+
ret void
24+
}

0 commit comments

Comments
 (0)