Skip to content

Commit 1338e44

Browse files
committed
add metadata testing
1 parent 53915ec commit 1338e44

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

clang/test/CodeGenHLSL/semantics/semantic.array.output.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct S0 {
66
float4 color;
77
};
88

9+
// CHECK-SPIRV-DAG: @A0 = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations ![[#METADATA_0:]]
910

1011
[shader("pixel")]
1112
S0 main1(float4 input : A) : B {
@@ -29,3 +30,8 @@ S0 main1(float4 input : A) : B {
2930
output.color = input;
3031
return output;
3132
}
33+
34+
// CHECK-SPIRV-DAG: ![[#METADATA_0]] = !{![[#METADATA_1:]]}
35+
// CHECK-SPIRV-DAG: ![[#METADATA_1]] = !{i32 30, i32 0}
36+
// | `- Location index
37+
// `-> Decoration "Location"
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK-DX,CHECK
2-
// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK-VK,CHECK
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-vertex -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK-DXIL,CHECK
2+
// RUN: %clang_cc1 -triple spirv-linux-vulkan-vertex -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK
33

44

55
struct Input {
6-
float Idx : SV_Position0;
6+
// FIXME: change this once we have a valid system semantic as input for VS.
7+
float Idx : B2;
78
};
89

910
struct Output {
10-
float a : A;
11+
float a : A4;
12+
float b : A2;
1113
};
1214

13-
// Make sure SV_DispatchThreadID translated into dx.thread.id.
14-
15-
// CHECK-DX: define hidden void @_Z3foo5Input(ptr dead_on_unwind noalias writable sret(%struct.Output) align 1 %agg.result, ptr noundef byval(%struct.Input) align 1 %input)
16-
// CHECK-VK: define hidden spir_func void @_Z3foo5Input(ptr dead_on_unwind noalias writable sret(%struct.Output) align 1 %agg.result, ptr noundef byval(%struct.Input) align 1 %input)
15+
// CHECK-SPIRV-DAG: @B2 = external hidden thread_local addrspace(7) externally_initialized constant float, !spirv.Decorations ![[#METADATA_0:]]
16+
// CHECK-SPIRV-DAG: @A4 = external hidden thread_local addrspace(8) global float, !spirv.Decorations ![[#METADATA_0:]]
17+
// CHECK-SPIRV-DAG: @A2 = external hidden thread_local addrspace(8) global float, !spirv.Decorations ![[#METADATA_2:]]
1718

1819
// CHECK: %Idx = getelementptr inbounds nuw %struct.Input, ptr %input, i32 0, i32 0
1920
// CHECK: %[[#tmp:]] = load float, ptr %Idx, align 1
2021
// CHECK: %a = getelementptr inbounds nuw %struct.Output, ptr %agg.result, i32 0, i32 0
2122
// CHECK: store float %[[#tmp]], ptr %a, align 1
2223

23-
Output foo(Input input) {
24+
// CHECK: %Idx1 = getelementptr inbounds nuw %struct.Input, ptr %input, i32 0, i32 0
25+
// CHECK: %[[#tmp:]] = load float, ptr %Idx1, align 1
26+
// CHECK: %b = getelementptr inbounds nuw %struct.Output, ptr %agg.result, i32 0, i32 1
27+
// CHECK: store float %[[#tmp]], ptr %b, align 1
28+
29+
Output main(Input input) {
2430
Output o;
2531
o.a = input.Idx;
32+
o.b = input.Idx;
2633
return o;
2734
}
35+
36+
// Code generated in the entrypoint wrapper:
37+
38+
// CHECK: %[[#OUTPUT:]] = alloca %struct.Output, align 8
39+
40+
// CHECK-SPIRV: call spir_func void @_Z4main5Input(ptr %[[#OUTPUT]], ptr %[[#]])
41+
// CHECK-DXIL: call void @_Z4main5Input(ptr %[[#OUTPUT]], ptr %[[#]])
42+
43+
// CHECK: %[[#TMP:]] = load %struct.Output, ptr %[[#OUTPUT]], align 4
44+
// CHECK: %[[#VAL:]] = extractvalue %struct.Output %[[#TMP]], 0
45+
// CHECK-SPIRV: store float %[[#VAL]], ptr addrspace(8) @A4, align 4
46+
// CHECK-DXIL: call void @llvm.dx.store.output.f32(i32 4, i32 0, i32 0, i8 0, i32 poison, float %[[#VAL]])
47+
// CHECK: %[[#VAL:]] = extractvalue %struct.Output %[[#TMP]], 1
48+
// CHECK-SPIRV: store float %[[#VAL]], ptr addrspace(8) @A2, align 4
49+
// CHECK-DXIL: call void @llvm.dx.store.output.f32(i32 4, i32 0, i32 0, i8 0, i32 poison, float %[[#VAL]])
50+
51+
// CHECK-SPIRV-DAG: ![[#METADATA_0]] = !{![[#METADATA_1:]]}
52+
// CHECK-SPIRV-DAG: ![[#METADATA_2]] = !{![[#METADATA_3:]]}
53+
// CHECK-SPIRV-DAG: ![[#METADATA_1]] = !{i32 30, i32 0}
54+
// CHECK-SPIRV-DAG: ![[#METADATA_3]] = !{i32 30, i32 1}
55+
// | `- Location index
56+
// `-> Decoration "Location"

0 commit comments

Comments
 (0)