Skip to content

Commit 124796f

Browse files
committed
[DirectX] Fix DXIL container invalid PSV0 part if using unbounded resource arrays
1 parent 794f3df commit 124796f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Target/DirectX/DXContainerGlobals.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/Support/MD5.h"
2929
#include "llvm/TargetParser/Triple.h"
3030
#include "llvm/Transforms/Utils/ModuleUtils.h"
31+
#include <cstdint>
3132
#include <optional>
3233

3334
using namespace llvm;
@@ -193,7 +194,12 @@ void DXContainerGlobals::addResourcesForPSV(Module &M, PSVRuntimeInfo &PSV) {
193194
dxbc::PSV::v2::ResourceBindInfo BindInfo;
194195
BindInfo.Type = Type;
195196
BindInfo.LowerBound = Binding.LowerBound;
196-
BindInfo.UpperBound = Binding.LowerBound + Binding.Size - 1;
197+
assert(Binding.Size == UINT32_MAX ||
198+
(uint64_t)Binding.LowerBound + Binding.Size - 1 <= UINT32_MAX &&
199+
"Resource range is too large");
200+
BindInfo.UpperBound = (Binding.Size == UINT32_MAX)
201+
? UINT32_MAX
202+
: Binding.LowerBound + Binding.Size - 1;
197203
BindInfo.Space = Binding.Space;
198204
BindInfo.Kind = static_cast<dxbc::PSV::ResourceKind>(Kind);
199205
BindInfo.Flags = Flags;

llvm/test/CodeGen/DirectX/ContainerData/PSVResources.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ define void @main() #0 {
9494
%uav2_2 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
9595
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0(
9696
i32 4, i32 0, i32 10, i32 5, ptr null)
97+
98+
; RWBuffer<float4> UnboundedArray[] : register(u10, space5)
99+
; CHECK: - Type: UAVTyped
100+
; CHECK: Space: 5
101+
; CHECK: LowerBound: 10
102+
; CHECK: UpperBound: 4294967295
103+
; CHECK: Kind: TypedBuffer
104+
; CHECK: Flags:
105+
; CHECK: UsedByAtomic64: false
106+
; RWBuffer<float4> Buf = BufferArray[100];
107+
%uav3 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
108+
@llvm.dx.resource.handlefrombinding(i32 5, i32 10, i32 -1, i32 100, ptr null)
97109
ret void
98110
}
99111

0 commit comments

Comments
 (0)