xref: /llvm-project/llvm/test/Analysis/DXILResource/buffer-frombinding.ll (revision 28d577ecefa1557f5dea5566bf33b885c563d14b)
1; RUN: opt -S -disable-output -passes="print<dxil-resource>" < %s 2>&1 | FileCheck %s
2
3@G = external constant <4 x float>, align 4
4
5define void @test_typedbuffer() {
6  ; RWBuffer<float4> Buf : register(u5, space3)
7  %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
8              @llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0(
9                  i32 3, i32 5, i32 1, i32 0, i1 false)
10  ; CHECK: Binding for %typed0
11  ; CHECK:   Symbol: ptr undef
12  ; CHECK:   Name: ""
13  ; CHECK:   Binding:
14  ; CHECK:     Record ID: 0
15  ; CHECK:     Space: 3
16  ; CHECK:     Lower Bound: 5
17  ; CHECK:     Size: 1
18  ; CHECK:   Class: UAV
19  ; CHECK:   Kind: TypedBuffer
20  ; CHECK:   Globally Coherent: 0
21  ; CHECK:   HasCounter: 0
22  ; CHECK:   IsROV: 0
23  ; CHECK:   Element Type: f32
24  ; CHECK:   Element Count: 4
25
26  ; RWBuffer<int> Buf : register(u7, space2)
27  %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1)
28      @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0t(
29          i32 2, i32 7, i32 1, i32 0, i1 false)
30  ; CHECK: Binding for %typed1
31  ; CHECK:   Symbol: ptr undef
32  ; CHECK:   Name: ""
33  ; CHECK:   Binding:
34  ; CHECK:     Record ID: 1
35  ; CHECK:     Space: 2
36  ; CHECK:     Lower Bound: 7
37  ; CHECK:     Size: 1
38  ; CHECK:   Class: UAV
39  ; CHECK:   Kind: TypedBuffer
40  ; CHECK:   Globally Coherent: 0
41  ; CHECK:   HasCounter: 0
42  ; CHECK:   IsROV: 0
43  ; CHECK:   Element Type: i32
44  ; CHECK:   Element Count: 1
45
46  ; Buffer<uint4> Buf[24] : register(t3, space5)
47  %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
48      @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_0_0t(
49          i32 2, i32 7, i32 24, i32 0, i1 false)
50  ; CHECK: Binding for %typed2
51  ; CHECK:   Symbol: ptr undef
52  ; CHECK:   Name: ""
53  ; CHECK:   Binding:
54  ; CHECK:     Record ID: 0
55  ; CHECK:     Space: 2
56  ; CHECK:     Lower Bound: 7
57  ; CHECK:     Size: 24
58  ; CHECK:   Class: SRV
59  ; CHECK:   Kind: TypedBuffer
60  ; CHECK:   Element Type: u32
61  ; CHECK:   Element Count: 4
62
63  ret void
64}
65
66define void @test_structbuffer() {
67  ; struct S { float4 a; uint4 b; };
68  ; StructuredBuffer<S> Buf : register(t2, space4)
69  %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
70      @llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
71          i32 4, i32 2, i32 1, i32 0, i1 false)
72  ; CHECK: Binding for %struct0
73  ; CHECK:   Symbol: ptr undef
74  ; CHECK:   Name: ""
75  ; CHECK:   Binding:
76  ; CHECK:     Record ID: 1
77  ; CHECK:     Space: 4
78  ; CHECK:     Lower Bound: 2
79  ; CHECK:     Size: 1
80  ; CHECK:   Class: SRV
81  ; CHECK:   Kind: StructuredBuffer
82  ; CHECK:   Buffer Stride: 32
83  ; CHECK:   Alignment: 4
84
85  ret void
86}
87
88define void @test_bytebuffer() {
89  ; ByteAddressBuffer Buf : register(t8, space1)
90  %byteaddr0 = call target("dx.RawBuffer", i8, 0, 0)
91      @llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
92          i32 1, i32 8, i32 1, i32 0, i1 false)
93  ; CHECK: Binding for %byteaddr0
94  ; CHECK:   Symbol: ptr undef
95  ; CHECK:   Name: ""
96  ; CHECK:   Binding:
97  ; CHECK:     Record ID: 2
98  ; CHECK:     Space: 1
99  ; CHECK:     Lower Bound: 8
100  ; CHECK:     Size: 1
101  ; CHECK:   Class: SRV
102  ; CHECK:   Kind: RawBuffer
103
104  ret void
105}
106
107; Note: We need declarations for each handle.fromBinding in the same
108; order as they appear in source to ensure that we can put our CHECK
109; lines along side the thing they're checking.
110declare target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
111        @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0t(
112        i32, i32, i32, i32, i1) #0
113declare target("dx.TypedBuffer", i32, 1, 0, 1)
114        @llvm.dx.handle.fromBinding.tdx.TypedBuffer_i32_1_0_1t(
115            i32, i32, i32, i32, i1) #0
116declare target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
117        @llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4i32_0_0_0t(
118            i32, i32, i32, i32, i1) #0
119declare target("dx.RawBuffer", { <4 x float>, <4 x i32> }, 0, 0)
120        @llvm.dx.handle.fromBinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
121            i32, i32, i32, i32, i1) #0
122declare target("dx.RawBuffer", i8, 0, 0)
123        @llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
124            i32, i32, i32, i32, i1) #0
125
126attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
127