Skip to content

Commit 8d7cb5d

Browse files
authored
[HLSL][NFC] Update resource metadata tests to not use obsolete annotations (#130222)
Update resource metadata tests to generate metadata based on `llvm.dx.resource.handlefrombinding` data collected in `DXILResourceBindingAnalysis`. - `UAVMetadata.ll` is updated, renamed to `uav_metadata.ll`, and placed under `Metadata` directory in `llvm/test/CodeGen/DirectX` - `srv_metadata.ll` is a new test for SRV resource metadata - `cbuf.ll` and `legacy_cb_layout_{0|1}.ll` tests were merged into `cbuffer_metadata.ll` - `legacy_cb_layout_{2|3}.ll` tests we moved to `cbuffer.hlsl` in Clang CodeGen because there were more of a layout than metadata tests Related to [#114126](#114126)
1 parent bde140c commit 8d7cb5d

File tree

10 files changed

+396
-299
lines changed

10 files changed

+396
-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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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(i32 0, i32 0, i32 1, i32 0, i1 false)
35+
store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16)) %CB1.cb_h, ptr @CB1.cb, align 4
36+
37+
; cbuffer CB2 : register(b0) {
38+
; float a;
39+
; double b;
40+
; float c;
41+
; half d;
42+
; uint16_t e;
43+
; int64_t f;
44+
; int g;
45+
;}
46+
47+
%CB2.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
48+
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false)
49+
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
50+
51+
; cbuffer CB3 : register(b5) {
52+
; double B0;
53+
; float3 B1;
54+
; float B2;
55+
; double3 B3;
56+
; half B4;
57+
; double2 B5;
58+
; float B6;
59+
; half3 B7;
60+
; half3 B8;
61+
; }
62+
%CB3.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
63+
@llvm.dx.resource.handlefrombinding(i32 15, i32 5, i32 1, i32 0, i1 false)
64+
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
65+
66+
ret void
67+
}
68+
69+
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
70+
71+
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
72+
73+
; CHECK: [[ResList]] = !{null, null, [[CBList:[!][0-9]+]], null}
74+
; CHECK: [[CBList]] = !{![[CB1:[0-9]+]], ![[CB2:[0-9]+]], ![[CB3:[0-9]+]]}
75+
; CHECK: ![[CB1]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 24, null}
76+
; CHECK: ![[CB2]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 36, null}
77+
; CHECK: ![[CB3]] = !{i32 2, ptr @2, !"", i32 15, i32 5, i32 1, i32 96, null}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
; PRINT-NEXT:; SRV f32 buf T7 t4,space3 100
36+
37+
define void @test() #0 {
38+
; Buffer<half4> Buf : register(t0)
39+
%Zero_h = call target("dx.TypedBuffer", <4 x half>, 0, 0, 0)
40+
@llvm.dx.resource.handlefrombinding(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+
; Buffer<float4> Buf : register(t1)
44+
%One_h = call target("dx.TypedBuffer", <2 x float>, 0, 0, 0)
45+
@llvm.dx.resource.handlefrombinding(i32 0, i32 1, i32 1, i32 0, i1 false)
46+
store target("dx.TypedBuffer", <2 x float>, 0, 0, 0) %One_h, ptr @One, align 4
47+
48+
; Buffer<double> Two : register(t2);
49+
%Two_h = call target("dx.TypedBuffer", double, 0, 0, 0)
50+
@llvm.dx.resource.handlefrombinding(i32 0, i32 2, i32 1, i32 0, i1 false)
51+
store target("dx.TypedBuffer", double, 0, 0, 0) %Two_h, ptr @Two, align 4
52+
53+
; Buffer<int4> Three : register(t3);
54+
%Three_h = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 1)
55+
@llvm.dx.resource.handlefrombinding(i32 0, i32 3, i32 1, i32 0, i1 false)
56+
store target("dx.TypedBuffer", <4 x i32>, 0, 0, 1) %Three_h, ptr @Three, align 4
57+
58+
; ByteAddressBuffer Four : register(t4)
59+
%Four_h = call target("dx.RawBuffer", i8, 0, 0)
60+
@llvm.dx.resource.handlefrombinding(i32 0, i32 5, i32 1, i32 0, i1 false)
61+
store target("dx.RawBuffer", i8, 0, 0) %Four_h, ptr @Four, align 4
62+
63+
; StructuredBuffer<int16_t> Five : register(t6);
64+
%Five_h = call target("dx.RawBuffer", i16, 0, 0)
65+
@llvm.dx.resource.handlefrombinding(i32 0, i32 6, i32 1, i32 0, i1 false)
66+
store target("dx.RawBuffer", i16, 0, 0) %Five_h, ptr @Five, align 4
67+
68+
; Buffer<double> Six : register(t10, space2);
69+
%Six_h = call target("dx.TypedBuffer", i64, 0, 0, 0)
70+
@llvm.dx.resource.handlefrombinding(i32 2, i32 10, i32 1, i32 0, i1 false)
71+
store target("dx.TypedBuffer", i64, 0, 0, 0) %Six_h, ptr @Six, align 4
72+
73+
; Buffer<float4> Array[100] : register(t4, space3);
74+
; Buffer<float4> B1 = Array[30];
75+
; Buffer<float4> B1 = Array[42];
76+
; resource array accesses should produce one metadata entry
77+
%Array_30_h = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0)
78+
@llvm.dx.resource.handlefrombinding(i32 3, i32 4, i32 100, i32 30, i1 false)
79+
%Array_42_h = call target("dx.TypedBuffer", <4 x float>, 0, 0, 0)
80+
@llvm.dx.resource.handlefrombinding(i32 3, i32 4, i32 100, i32 42, i1 false)
81+
82+
ret void
83+
}
84+
85+
attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
86+
87+
; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
88+
89+
; CHECK: [[ResList]] = !{[[SRVList:[!][0-9]+]], null, null, null}
90+
; CHECK: [[SRVList]] = !{![[Zero:[0-9]+]], ![[One:[0-9]+]], ![[Two:[0-9]+]],
91+
; CHECK-SAME: ![[Three:[0-9]+]], ![[Four:[0-9]+]], ![[Five:[0-9]+]],
92+
; CHECK-SAME: ![[Six:[0-9]+]], ![[Array:[0-9]+]]}
93+
94+
; CHECK: ![[Zero]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 10, i32 0, ![[Half:[0-9]+]]}
95+
; CHECK: ![[Half]] = !{i32 0, i32 8}
96+
; CHECK: ![[One]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 10, i32 0, ![[Float:[0-9]+]]}
97+
; CHECK: ![[Float]] = !{i32 0, i32 9}
98+
; CHECK: ![[Two]] = !{i32 2, ptr @2, !"", i32 0, i32 2, i32 1, i32 10, i32 0, ![[Double:[0-9]+]]}
99+
; CHECK: ![[Double]] = !{i32 0, i32 10}
100+
; CHECK: ![[Three]] = !{i32 3, ptr @3, !"", i32 0, i32 3, i32 1, i32 10, i32 0, ![[I32:[0-9]+]]}
101+
; CHECK: ![[I32]] = !{i32 0, i32 4}
102+
; CHECK: ![[Four]] = !{i32 4, ptr @4, !"", i32 0, i32 5, i32 1, i32 11, i32 0, null}
103+
; CHECK: ![[Five]] = !{i32 5, ptr @5, !"", i32 0, i32 6, i32 1, i32 12, i32 0, ![[FiveStride:[0-9]+]]}
104+
; CHECK: ![[FiveStride]] = !{i32 1, i32 2}
105+
; CHECK: ![[Six]] = !{i32 6, ptr @6, !"", i32 2, i32 10, i32 1, i32 10, i32 0, ![[U64:[0-9]+]]}
106+
; CHECK: ![[U64]] = !{i32 0, i32 7}
107+
; CHECK: ![[Array]] = !{i32 7, ptr @7, !"", i32 3, i32 4, i32 100, i32 10, i32 0, ![[Float]]}

0 commit comments

Comments
 (0)