Skip to content

Commit 9953925

Browse files
committed
[HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations
1 parent 1b75b9e commit 9953925

File tree

10 files changed

+394
-299
lines changed

10 files changed

+394
-299
lines changed

clang/test/CodeGenHLSL/cbuffer.hlsl

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
// CHECK: %anon = type <{ float }>
2121
// CHECK: %anon.0 = type <{ <2 x i32> }>
2222

23+
// CHECK: %__cblayout_CB_A = type <{ [2 x double], [3 x <3 x float>], float, [3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }>
24+
// CHECK: %__cblayout_CB_B = type <{ [3 x <3 x double>], <3 x half> }>
25+
// CHECK: %__cblayout_CB_C = type <{ i32, target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90), half, target("dx.Layout", %G, 258, 0, 48, 64, 256), double }>
26+
27+
// CHECK: %F = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
28+
// CHECK: %G = type <{ target("dx.Layout", %E, 36, 0, 8, 16, 20, 22, 24, 32), [1 x float], [2 x target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)], half }>
29+
// CHECK: %E = type <{ float, double, float, half, i16, i64, i32 }>
30+
2331
cbuffer CBScalars : register(b1, space5) {
2432
float a1;
2533
double a2;
@@ -155,6 +163,64 @@ cbuffer CBMix {
155163
uint16_t f9;
156164
};
157165

166+
// CHECK: @CB_A.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_A, 188, 0, 32, 76, 80, 120, 128, 144, 160, 182))
167+
168+
cbuffer CB_A {
169+
double B0[2];
170+
float3 B1[3];
171+
float B2;
172+
double B3[3];
173+
half B4;
174+
double2 B5[1];
175+
float B6;
176+
half3 B7[2];
177+
half3 B8;
178+
}
179+
180+
// CHECK: @CB_B.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_B, 94, 0, 88))
181+
cbuffer CB_B {
182+
double3 B9[3];
183+
half3 B10;
184+
}
185+
186+
struct E {
187+
float A0;
188+
double A1;
189+
float A2;
190+
half A3;
191+
int16_t A4;
192+
int64_t A5;
193+
int A6;
194+
};
195+
196+
struct F {
197+
double B0;
198+
float3 B1;
199+
float B2;
200+
double3 B3;
201+
half B4;
202+
double2 B5;
203+
float B6;
204+
half3 B7;
205+
half3 B8;
206+
};
207+
208+
struct G {
209+
E C0;
210+
float C1[1];
211+
F C2[2];
212+
half C3;
213+
};
214+
215+
// CHECK: @CB_C.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_C, 400, 0, 16, 112, 128, 392))
216+
cbuffer CB_C {
217+
int D0;
218+
F D1;
219+
half D2;
220+
G D3;
221+
double D4;
222+
}
223+
158224
// CHECK: define internal void @_init_resource_CBScalars.cb()
159225
// CHECK-NEXT: entry:
160226
// CHECK-NEXT: %[[HANDLE1:.*]] = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CBScalars, 56, 0, 8, 16, 24, 32, 36, 40, 48))
@@ -171,15 +237,16 @@ RWBuffer<float> Buf;
171237

172238
[numthreads(4,1,1)]
173239
void main() {
174-
Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1;
240+
Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1 + B1[0].x + B10.z + D1.B2;
175241
}
176242

177243
// CHECK: define internal void @_GLOBAL__sub_I_cbuffer.hlsl()
178244
// CHECK-NEXT: entry:
179245
// CHECK-NEXT: call void @_init_resource_CBScalars.cb()
180246
// CHECK-NEXT: call void @_init_resource_CBArrays.cb()
181247

182-
// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]]}
248+
// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]],
249+
// CHECK-SAME: ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}
183250

184251
// CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
185252
// CHECK-SAME: ptr addrspace(2) @a5, ptr addrspace(2) @a6, ptr addrspace(2) @a7, ptr addrspace(2) @a8}
@@ -195,3 +262,10 @@ void main() {
195262

196263
// CHECK: ![[CBMIX]] = !{ptr @CBMix.cb, ptr addrspace(2) @test, ptr addrspace(2) @f1, ptr addrspace(2) @f2, ptr addrspace(2) @f3,
197264
// CHECK-SAME: ptr addrspace(2) @f4, ptr addrspace(2) @f5, ptr addrspace(2) @f6, ptr addrspace(2) @f7, ptr addrspace(2) @f8, ptr addrspace(2) @f9}
265+
266+
// CHECK: ![[CB_A]] = !{ptr @CB_A.cb, ptr addrspace(2) @B0, ptr addrspace(2) @B1, ptr addrspace(2) @B2, ptr addrspace(2) @B3, ptr addrspace(2) @B4,
267+
// CHECK-SAME: ptr addrspace(2) @B5, ptr addrspace(2) @B6, ptr addrspace(2) @B7, ptr addrspace(2) @B8}
268+
269+
// CHECK: ![[CB_B]] = !{ptr @CB_B.cb, ptr addrspace(2) @B9, ptr addrspace(2) @B10}
270+
271+
// CHECK: ![[CB_C]] = !{ptr @CB_C.cb, ptr addrspace(2) @D0, ptr addrspace(2) @D1, ptr addrspace(2) @D2, ptr addrspace(2) @D3, ptr addrspace(2) @D4}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
2+
; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
3+
; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
4+
5+
target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
6+
target triple = "dxil-pc-shadermodel6.6-compute"
7+
8+
%__cblayout_CB1 = type <{ float, i32, double, <2 x i32> }>
9+
@CB1.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16))
10+
11+
%__cblayout_CB2 = type <{ float, double, float, half, i16, i64, i32 }>
12+
@CB2.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
13+
14+
%__cblayout_CB3 = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
15+
@CB3.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
16+
17+
; PRINT:; Resource Bindings:
18+
; PRINT-NEXT:;
19+
; PRINT-NEXT:; Name Type Format Dim ID HLSL Bind Count
20+
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
21+
; PRINT-NEXT:; cbuffer NA NA CB0 cb0 1
22+
; PRINT-NEXT:; cbuffer NA NA CB1 cb1 1
23+
; PRINT-NEXT:; cbuffer NA NA CB2 cb5,space15 1
24+
25+
define void @test() #0 {
26+
27+
; cbuffer CB1 : register(b0) {
28+
; float a;
29+
; int b;
30+
; double c;
31+
; int2 d;
32+
; }
33+
%CB1.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16))
34+
@llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB1s_24_0_4_8_16tt(
35+
i32 0, i32 0, i32 1, i32 0, i1 false)
36+
store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16)) %CB1.cb_h, ptr @CB1.cb, align 4
37+
38+
; cbuffer CB2 : register(b0) {
39+
; float a;
40+
; double b;
41+
; float c;
42+
; half d;
43+
; uint16_t e;
44+
; int64_t f;
45+
; int g;
46+
;}
47+
48+
%CB2.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
49+
@llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB2s_36_0_8_16_20_22_24_32tt(
50+
i32 0, i32 1, i32 1, i32 0, i1 false)
51+
store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32)) %CB2.cb_h, ptr @CB2.cb, align 4
52+
53+
; cbuffer CB3 : register(b5) {
54+
; double B0;
55+
; float3 B1;
56+
; float B2;
57+
; double3 B3;
58+
; half B4;
59+
; double2 B5;
60+
; float B6;
61+
; half3 B7;
62+
; half3 B8;
63+
; }
64+
%CB3.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
65+
@llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB3s_96_0_16_28_32_56_64_80_84_90tt(
66+
i32 15, i32 5, i32 1, i32 0, i1 false)
67+
store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)) %CB3.cb_h, ptr @CB3.cb, align 4
68+
69+
ret void
70+
}
71+
72+
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
73+
74+
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
75+
76+
; CHECK: [[ResList]] = !{null, null, [[CBList:[!][0-9]+]], null}
77+
; CHECK: [[CBList]] = !{![[CB1:[0-9]+]], ![[CB2:[0-9]+]], ![[CB3:[0-9]+]]}
78+
; CHECK: ![[CB1]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 24, null}
79+
; CHECK: ![[CB2]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 36, null}
80+
; CHECK: ![[CB3]] = !{i32 2, ptr @2, !"", i32 15, i32 5, i32 1, i32 96, null}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
2+
; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
3+
; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
4+
5+
target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
6+
target triple = "dxil-pc-shadermodel6.6-compute"
7+
8+
%"class.hlsl::Buffer" = type { target("dx.TypedBuffer", <4 x half>, 0, 0, 0) }
9+
%"class.hlsl::Buffer.1" = type { target("dx.TypedBuffer", <2 x float>, 0, 0, 0) }
10+
%"class.hlsl::Buffer.2" = type { target("dx.TypedBuffer", double, 0, 0, 0) }
11+
%"class.hlsl::Buffer.3" = type { target("dx.TypedBuffer", i32, 0, 0, 1) }
12+
%"class.hlsl::ByteAddressBuffer" = type { target("dx.RawBuffer", i8, 0, 0) }
13+
%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", i16, 0, 0) }
14+
%"class.hlsl::Buffer.4" = type { target("dx.TypedBuffer", i64, 0, 0, 0) }
15+
16+
@Zero = internal global %"class.hlsl::Buffer" poison, align 4
17+
@One = internal global %"class.hlsl::Buffer.1" poison, align 4
18+
@Two = internal global %"class.hlsl::Buffer.2" poison, align 4
19+
@Three = internal global %"class.hlsl::Buffer.3" poison, align 4
20+
@Four = internal global %"class.hlsl::ByteAddressBuffer" poison, align 4
21+
@Five = internal global %"class.hlsl::StructuredBuffer" poison, align 4
22+
@Six = internal global %"class.hlsl::Buffer.4" poison, align 4
23+
24+
; PRINT:; Resource Bindings:
25+
; PRINT-NEXT:;
26+
; PRINT-NEXT:; Name Type Format Dim ID HLSL Bind Count
27+
; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
28+
; PRINT-NEXT:; SRV f16 buf T0 t0 1
29+
; PRINT-NEXT:; SRV f32 buf T1 t1 1
30+
; PRINT-NEXT:; SRV f64 buf T2 t2 1
31+
; PRINT-NEXT:; SRV i32 buf T3 t3 1
32+
; PRINT-NEXT:; SRV byte r/o T4 t5 1
33+
; PRINT-NEXT:; SRV struct r/o T5 t6 1
34+
; PRINT-NEXT:; SRV u64 buf T6 t10,space2 1
35+
36+
define void @test() #0 {
37+
; RWBuffer<half4> Buf : register(u0)
38+
%Zero_h = call target("dx.TypedBuffer", <4 x half>, 0, 0, 0)
39+
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f16_0_0_0t(
40+
i32 0, i32 0, i32 1, i32 0, i1 false)
41+
store target("dx.TypedBuffer", <4 x half>, 0, 0, 0) %Zero_h, ptr @Zero, align 4
42+
43+
; RWBuffer<float4> Buf : register(u1)
44+
%One_h = call target("dx.TypedBuffer", <2 x float>, 0, 0, 0)
45+
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v2f32_0_0_0t(
46+
i32 0, i32 1, i32 1, i32 0, i1 false)
47+
store target("dx.TypedBuffer", <2 x float>, 0, 0, 0) %One_h, ptr @One, align 4
48+
49+
; RWBuffer<double> Two : register(u2);
50+
%Two_h = call target("dx.TypedBuffer", double, 0, 0, 0)
51+
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_0_0_0t(
52+
i32 0, i32 2, i32 1, i32 0, i1 false)
53+
store target("dx.TypedBuffer", double, 0, 0, 0) %Two_h, ptr @Two, align 4
54+
55+
; RWBuffer<int4> Three : register(u3);
56+
%Three_h = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 1)
57+
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_0_0_1t(
58+
i32 0, i32 3, i32 1, i32 0, i1 false)
59+
store target("dx.TypedBuffer", <4 x i32>, 0, 0, 1) %Three_h, ptr @Three, align 4
60+
61+
; ByteAddressBuffer Four : register(u4)
62+
%Four_h = call target("dx.RawBuffer", i8, 0, 0)
63+
@llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t(
64+
i32 0, i32 5, i32 1, i32 0, i1 false)
65+
store target("dx.RawBuffer", i8, 0, 0) %Four_h, ptr @Four, align 4
66+
67+
; StructuredBuffer<int16_t> Five : register(u6);
68+
%Five_h = call target("dx.RawBuffer", i16, 0, 0)
69+
@llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i16_0_0t(
70+
i32 0, i32 6, i32 1, i32 0, i1 false)
71+
store target("dx.RawBuffer", i16, 0, 0) %Five_h, ptr @Five, align 4
72+
73+
; RWBuffer<double> Two : register(u2);
74+
%Six_h = call target("dx.TypedBuffer", i64, 0, 0, 0)
75+
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_0_0_0t(
76+
i32 2, i32 10, i32 1, i32 0, i1 false)
77+
store target("dx.TypedBuffer", i64, 0, 0, 0) %Six_h, ptr @Six, align 4
78+
79+
ret void
80+
}
81+
82+
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
83+
84+
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
85+
86+
; CHECK: [[ResList]] = !{[[SRVList:[!][0-9]+]], null, null, null}
87+
; CHECK: [[SRVList]] = !{![[Zero:[0-9]+]], ![[One:[0-9]+]], ![[Two:[0-9]+]],
88+
; CHECK-SAME: ![[Three:[0-9]+]], ![[Four:[0-9]+]], ![[Five:[0-9]+]],
89+
; CHECK-SAME: ![[Six:[0-9]+]]}
90+
91+
; CHECK: ![[Zero]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 10, i32 0, ![[Half:[0-9]+]]}
92+
; CHECK: ![[Half]] = !{i32 0, i32 8}
93+
; CHECK: ![[One]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 10, i32 0, ![[Float:[0-9]+]]}
94+
; CHECK: ![[Float]] = !{i32 0, i32 9}
95+
; CHECK: ![[Two]] = !{i32 2, ptr @2, !"", i32 0, i32 2, i32 1, i32 10, i32 0, ![[Double:[0-9]+]]}
96+
; CHECK: ![[Double]] = !{i32 0, i32 10}
97+
; CHECK: ![[Three]] = !{i32 3, ptr @3, !"", i32 0, i32 3, i32 1, i32 10, i32 0, ![[I32:[0-9]+]]}
98+
; CHECK: ![[I32]] = !{i32 0, i32 4}
99+
; CHECK: ![[Four]] = !{i32 4, ptr @4, !"", i32 0, i32 5, i32 1, i32 11, i32 0, null}
100+
; CHECK: ![[Five]] = !{i32 5, ptr @5, !"", i32 0, i32 6, i32 1, i32 12, i32 0, ![[FiveStride:[0-9]+]]}
101+
; CHECK: ![[FiveStride]] = !{i32 1, i32 2}
102+
; CHECK: ![[Six]] = !{i32 6, ptr @6, !"", i32 2, i32 10, i32 1, i32 10, i32 0, ![[U64:[0-9]+]]}
103+
; CHECK: ![[U64]] = !{i32 0, i32 7}

0 commit comments

Comments
 (0)