xref: /llvm-project/llvm/test/CodeGen/DirectX/CreateHandle.ll (revision 011b618644113996e2c0a8e57db40f89d20878e3)
1bfd05102SJustin Bogner; RUN: opt -S -passes=dxil-translate-metadata,dxil-op-lower %s | FileCheck %s
287157ab0SJustin Bogner; RUN: opt -S -passes=dxil-pretty-printer %s 2>&1 >/dev/null | FileCheck --check-prefix=CHECK-PRETTY %s
387157ab0SJustin Bogner
487157ab0SJustin Bogner; CHECK-PRETTY:       Type  Format         Dim      ID      HLSL Bind     Count
587157ab0SJustin Bogner; CHECK-PRETTY: ---------- ------- ----------- ------- -------------- ---------
6bb88fd17SJustin Bogner; CHECK-PRETTY:        SRV     f32         buf      T0      t7        unbounded
787157ab0SJustin Bogner; CHECK-PRETTY:        SRV    byte         r/o      T1      t8,space1         1
887157ab0SJustin Bogner; CHECK-PRETTY:        SRV  struct         r/o      T2      t2,space4         1
987157ab0SJustin Bogner; CHECK-PRETTY:        SRV     u32         buf      T3      t3,space5        24
1087157ab0SJustin Bogner; CHECK-PRETTY:        UAV     i32         buf      U0      u7,space2         1
1187157ab0SJustin Bogner; CHECK-PRETTY:        UAV     f32         buf      U1      u5,space3         1
12aa61925eSJustin Bogner
13aa61925eSJustin Bognertarget triple = "dxil-pc-shadermodel6.0-compute"
14aa61925eSJustin Bogner
15aa61925eSJustin Bognerdeclare i32 @some_val();
16aa61925eSJustin Bogner
17aa61925eSJustin Bognerdefine void @test_buffers() {
18aa61925eSJustin Bogner  ; RWBuffer<float4> Buf : register(u5, space3)
19aa61925eSJustin Bogner  %typed0 = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
20aa07f922SJustin Bogner              @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f32_1_0_0(
21bb88fd17SJustin Bogner                  i32 3, i32 5, i32 1, i32 0, i1 false)
22*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 1, i32 5, i1 false) #[[#ATTR:]]
23aa61925eSJustin Bogner  ; CHECK-NOT: @llvm.dx.cast.handle
24aa61925eSJustin Bogner
25aa61925eSJustin Bogner  ; RWBuffer<int> Buf : register(u7, space2)
26aa61925eSJustin Bogner  %typed1 = call target("dx.TypedBuffer", i32, 1, 0, 1)
27aa07f922SJustin Bogner      @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_1_0_1t(
28bb88fd17SJustin Bogner          i32 2, i32 7, i32 1, i32 0, i1 false)
29*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1, i32 0, i32 7, i1 false) #[[#ATTR]]
30aa61925eSJustin Bogner
31aa61925eSJustin Bogner  ; Buffer<uint4> Buf[24] : register(t3, space5)
32aa61925eSJustin Bogner  ; Buffer<uint4> typed2 = Buf[4]
33aa61925eSJustin Bogner  ; Note that the index below is 3 + 4 = 7
34aa61925eSJustin Bogner  %typed2 = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 0)
35aa07f922SJustin Bogner      @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_0_0_0t(
36bb88fd17SJustin Bogner          i32 5, i32 3, i32 24, i32 4, i1 false)
37*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 3, i32 7, i1 false) #[[#ATTR]]
38aa61925eSJustin Bogner
39aa61925eSJustin Bogner  ; struct S { float4 a; uint4 b; };
40aa61925eSJustin Bogner  ; StructuredBuffer<S> Buf : register(t2, space4)
41aa61925eSJustin Bogner  %struct0 = call target("dx.RawBuffer", {<4 x float>, <4 x i32>}, 0, 0)
42aa07f922SJustin Bogner      @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_sl_v4f32v4i32s_0_0t(
43bb88fd17SJustin Bogner          i32 4, i32 2, i32 1, i32 0, i1 true)
44*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 2, i32 2, i1 true) #[[#ATTR]]
45aa61925eSJustin Bogner
46aa61925eSJustin Bogner  ; ByteAddressBuffer Buf : register(t8, space1)
47aa61925eSJustin Bogner  %byteaddr0 = call target("dx.RawBuffer", i8, 0, 0)
48aa07f922SJustin Bogner      @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t(
49bb88fd17SJustin Bogner          i32 1, i32 8, i32 1, i32 0, i1 false)
50*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 1, i32 8, i1 false) #[[#ATTR]]
51aa61925eSJustin Bogner
52bb88fd17SJustin Bogner  ; Buffer<float4> Buf[] : register(t7)
53aa61925eSJustin Bogner  ; Buffer<float4> typed3 = Buf[ix]
54aa61925eSJustin Bogner  %typed3_ix = call i32 @some_val()
55aa61925eSJustin Bogner  %typed3 = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0)
56aa07f922SJustin Bogner      @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f32_0_0_0t(
57bb88fd17SJustin Bogner          i32 0, i32 7, i32 -1, i32 %typed3_ix, i1 false)
58bb88fd17SJustin Bogner  ; CHECK: %[[IX:.*]] = add i32 %typed3_ix, 7
59*011b6186SFinn Plummer  ; CHECK: call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 %[[IX]], i1 false) #[[#ATTR]]
60aa61925eSJustin Bogner
61aa61925eSJustin Bogner  ret void
62aa61925eSJustin Bogner}
63aa61925eSJustin Bogner
64*011b6186SFinn Plummer; CHECK: attributes #[[#ATTR]] = {{{.*}} memory(read) {{.*}}}
65*011b6186SFinn Plummer
66daa79232SJustin Bogner; Just check that we have the right types and number of metadata nodes, the
67daa79232SJustin Bogner; contents of the metadata are tested elsewhere.
68daa79232SJustin Bogner;
69daa79232SJustin Bogner; CHECK: !dx.resources = !{[[RESMD:![0-9]+]]}
70daa79232SJustin Bogner; CHECK: [[RESMD]] = !{[[SRVMD:![0-9]+]], [[UAVMD:![0-9]+]], null, null}
71daa79232SJustin Bogner; CHECK-DAG: [[SRVMD]] = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
72daa79232SJustin Bogner; CHECK-DAG: [[UAVMD]] = !{!{{[0-9]+}}, !{{[0-9]+}}}
73daa79232SJustin Bogner
74aa61925eSJustin Bognerattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
75