Skip to content

Commit cc85030

Browse files
committed
Varying inputs and outputs for wgsl
Closes #5067 New tests, covering what's declared supported in the WGSL support docs - tests/wgsl/semantic-coverage.slang - tests/wgsl/semantic-depth.slang - tests/wgsl/semantic-dispatch-thread-id.slang - tests/wgsl/semantic-group-id.slang - tests/wgsl/semantic-group-index.slang - tests/wgsl/semantic-group-thread-id.slang - tests/wgsl/semantic-instance-id.slang - tests/wgsl/semantic-is-front-face.slang - tests/wgsl/semantic-position.slang - tests/wgsl/semantic-sample-index.slang - tests/wgsl/semantic-vertex-id.slang WGSL enabled existing tests: - tests/compute/compile-time-loop.slang - tests/compute/constexpr.slang - tests/compute/discard-stmt.slang - tests/metal/nested-struct-fragment-input.slang - tests/metal/nested-struct-fragment-output.slang - tests/metal/nested-struct-multi-entry-point-vertex.slang - tests/metal/no-struct-vertex-output.slang - tests/metal/sv_target-complex-1.slang - tests/metal/sv_target-complex-2.slang - tests/bugs/texture2d-gather.hlsl - tests/render/cross-compile-entry-point.slang - tests/render/nointerpolation.hlsl - tests/render/render0.hlsl - tests/render/cross-compile0.hlsl - tests/render/imported-parameters.hlsl - tests/render/unused-discard.hlsl Can't be enabled due to missing wgsl features - tests/compute/texture-sampling.slang
1 parent c005fe9 commit cc85030

18 files changed

+200
-19
lines changed

tests/compute/constexpr.slang

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//TEST(compute):COMPARE_COMPUTE_EX:-slang -gcompute -shaderobj
33
//DISABLED://TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -gcompute -shaderobj
44
//TEST(compute):COMPARE_COMPUTE_EX:-mtl -gcompute -shaderobj
5+
//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -gcompute -shaderobj
56

67
//TEST_INPUT: Texture2D(size=4, content = one):name tex
78
//TEST_INPUT: Sampler:name samp

tests/metal/nested-struct-fragment-input.slang

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//TEST:SIMPLE(filecheck=METAL): -target metal -stage fragment -entry fragmentMain
22
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage fragment -entry fragmentMain
3+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry fragmentMain
34

45
// METAL: COARSEVERTEX_7
56
// METAL: COARSEVERTEX_6
@@ -63,6 +64,16 @@ float4 fragmentMain(FragmentStageInput input)
6364
// METAL-DAG: {{.*}}->p3{{.*}}->p2{{.*}}->p1{{.*}}=
6465
// METAL-DAG: {{.*}}->p3{{.*}}->p3{{.*}}->p1{{.*}}=
6566

67+
// WGSL-DAG: {{.*}}._S{{.*}}=
68+
69+
// WGSL-DAG: {{.*}}.p2{{.*}}._S{{.*}}=
70+
// WGSL-DAG: {{.*}}.p2{{.*}}.p2{{.*}}._S{{.*}}=
71+
// WGSL-DAG: {{.*}}.p2{{.*}}.p3{{.*}}._S{{.*}}=
72+
73+
// WGSL-DAG: {{.*}}.p3{{.*}}._S{{.*}}=
74+
// WGSL-DAG: {{.*}}.p3{{.*}}.p2{{.*}}._S{{.*}}=
75+
// WGSL-DAG: {{.*}}.p3{{.*}}.p3{{.*}}._S{{.*}}=
76+
6677
outputBuffer[0] = input.coarseVertex.p1 + input.coarseVertex.p2.p1 + +input.coarseVertex.p3.p1;
6778
return float4(0, 0, 0, 0);
6879
}

tests/metal/nested-struct-fragment-output.slang

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//TEST:SIMPLE(filecheck=METAL): -target metal -stage fragment -entry fragmentMain
22
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage fragment -entry fragmentMain
3+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry fragmentMain
34

45
//METAL-DAG: color(0)
56
//METAL-DAG: color(1)
@@ -10,6 +11,15 @@
1011
//METAL-DAG: color(6)
1112
//METAL-NOT: color(7)
1213

14+
//WGSL-DAG: location(0)
15+
//WGSL-DAG: location(1)
16+
//WGSL-DAG: location(2)
17+
//WGSL-DAG: location(3)
18+
//WGSL-DAG: location(4)
19+
//WGSL-DAG: location(5)
20+
//WGSL-DAG: location(6)
21+
//WGSL-NOT: location(7)
22+
1323
//METALLIB: @fragmentMain
1424

1525
RWStructuredBuffer<float> outputBuffer;
@@ -69,6 +79,16 @@ FragmentStageOutput fragmentMain(FragmentStageInput input)
6979
// METAL-DAG: ={{.*}}.p3{{.*}}.p2{{.*}}.p1
7080
// METAL-DAG: ={{.*}}.p3{{.*}}.p3{{.*}}.p1
7181

82+
// WGSL-DAG: ={{.*}}._S{{.*}}
83+
84+
// WGSL-DAG: ={{.*}}.p2{{.*}}._S{{.*}}
85+
// WGSL-DAG: ={{.*}}.p2{{.*}}.p2{{.*}}._S{{.*}}
86+
// WGSL-DAG: ={{.*}}.p2{{.*}}.p3{{.*}}._S{{.*}}
87+
88+
// WGSL-DAG: ={{.*}}.p3{{.*}}._S{{.*}}
89+
// WGSL-DAG: ={{.*}}.p3{{.*}}.p2{{.*}}._S{{.*}}
90+
// WGSL-DAG: ={{.*}}.p3{{.*}}.p3{{.*}}._S{{.*}}
91+
7292
outputBuffer[0] = 1;
7393
return output;
7494
}

tests/metal/nested-struct-multi-entry-point-vertex.slang

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22
//TEST:SIMPLE(filecheck=METALLIB1): -target metallib -stage vertex -entry vertexMain1
33
//TEST:SIMPLE(filecheck=METAL2): -target metal -stage vertex -entry vertexMain2
44
//TEST:SIMPLE(filecheck=METALLIB2): -target metallib -stage vertex -entry vertexMain2
5+
//TEST:SIMPLE(filecheck=WGSL1): -target wgsl -stage vertex -entry vertexMain1
6+
//TEST:SIMPLE(filecheck=WGSL2): -target wgsl -stage vertex -entry vertexMain2
57

68
//METALLIB1: @vertexMain1
79
//METAL1-DAG: attribute(0)
810
//METAL1-DAG: attribute(1)
911
//METAL1-NOT: attribute(2)
1012

13+
//WGSL1-DAG: fn vertexMain1
14+
//WGSL1-DAG: location(0)
15+
//WGSL1-DAG: location(1)
16+
//WGSL1-NOT: location(2)
17+
1118
//METALLIB2: @vertexMain2
1219
//METAL2-DAG: attribute(0)
1320
//METAL2-DAG: attribute(1)
1421
//METAL2-DAG: attribute(2)
1522

23+
//WGSL2-DAG: fn vertexMain2
24+
//WGSL2-DAG: location(0)
25+
//WGSL2-DAG: location(1)
26+
//WGSL2-DAG: location(2)
27+
1628
struct SharedStruct
1729
{
1830
float4 position;
@@ -42,4 +54,4 @@ struct VertexStageInput2
4254
float4 vertexMain2(VertexStageInput2 vertex)
4355
{
4456
return vertex.assembledVertex.sharedData.position;
45-
}
57+
}
+5-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
//TEST:SIMPLE(filecheck=METAL): -target metallib -stage vertex -entry vertexMain
22
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage vertex -entry vertexMain
3+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry vertexMain
34

45
//METAL-DAG: position
56
//METALLIB: @vertexMain
67

8+
//WGSL-DAG: @builtin(position)
9+
//WGSL-DAG: @vertex
10+
711
// Vertex Shader
812

913
float4 vertexMain()
1014
{
1115
return float4(1,1,1,1);
12-
}
16+
}

tests/metal/sv_target-complex-1.slang

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//TEST:SIMPLE(filecheck=CHECK): -target metal
2-
//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib
1+
//TEST:SIMPLE(filecheck=METAL): -target metal
2+
//TEST:SIMPLE(filecheck=METAL-ASM): -target metallib
3+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry fragmentMain -stage fragment
34

45
struct NestedReturn
56
{
@@ -20,15 +21,21 @@ struct Output
2021
NestedReturn2 debug2 : SV_TaRget3;
2122
}
2223

23-
// CHECK-ASM: define {{.*}} @fragmentMain
24-
// CHECK: color(0)
25-
// CHECK-DAG: color(1)
26-
// CHECK-DAG: color(2)
27-
// CHECK-DAG: color(3)
28-
// CHECK-DAG: color(4)
24+
// METAL-ASM: define {{.*}} @fragmentMain
25+
// METAL: color(0)
26+
// METAL-DAG: color(1)
27+
// METAL-DAG: color(2)
28+
// METAL-DAG: color(3)
29+
// METAL-DAG: color(4)
30+
31+
// WGSL: location(0)
32+
// WGSL-DAG: location(1)
33+
// WGSL-DAG: location(2)
34+
// WGSL-DAG: location(3)
35+
// WGSL-DAG: location(4)
2936

3037
[shader("fragment")]
3138
Output fragmentMain()
3239
{
3340
return { float4(1), {float4(2)}, float4(3) };
34-
}
41+
}

tests/metal/sv_target-complex-2.slang

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//TEST:SIMPLE(filecheck=CHECK): -target metal
2-
//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib
1+
//TEST:SIMPLE(filecheck=METAL): -target metal
2+
//TEST:SIMPLE(filecheck=METAL-ASM): -target metallib
3+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry fragmentMain -stage fragment
34

45
struct NestedReturn
56
{
@@ -14,14 +15,19 @@ struct Output
1415
float4 Material : SV_Target2;
1516
}
1617

17-
// CHECK-ASM: define {{.*}} @fragmentMain
18-
// CHECK: color(0)
19-
// CHECK: color(1)
20-
// CHECK-DAG: color(3)
21-
// CHECK-DAG: color(2)
18+
// METAL-ASM: define {{.*}} @fragmentMain
19+
// METAL: color(0)
20+
// METAL: color(1)
21+
// METAL-DAG: color(3)
22+
// METAL-DAG: color(2)
23+
24+
// WGSL-DAG: location(0)
25+
// WGSL-DAG: location(1)
26+
// WGSL-DAG: location(3)
27+
// WGSL-DAG: location(2)
2228

2329
[shader("fragment")]
2430
Output fragmentMain()
2531
{
2632
return { float4(1), {float4(2), float4(2)}, float4(3) };
27-
}
33+
}

tests/wgsl/semantic-coverage.slang

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main
2+
3+
//WGSL-DAG: @builtin(sample_mask)
4+
//WGSL-DAG: @fragment
5+
6+
struct Out
7+
{
8+
uint coverage : SV_Coverage;
9+
};
10+
11+
Out main()
12+
{
13+
Out output;
14+
output.coverage = 1;
15+
return output;
16+
}

tests/wgsl/semantic-depth.slang

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main
2+
3+
//WGSL-DAG: @builtin(frag_depth)
4+
//WGSL-DAG: @fragment
5+
6+
struct Out
7+
{
8+
float depth : SV_Depth;
9+
};
10+
11+
Out main()
12+
{
13+
Out output;
14+
output.depth = 1.0;
15+
return output;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main
2+
3+
//WGSL-DAG: @builtin(global_invocation_id)
4+
//WGSL-DAG: @compute
5+
6+
void main(uint3 dtid : SV_DispatchThreadID)
7+
{
8+
// Empty compute shader
9+
}

tests/wgsl/semantic-group-id.slang

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main
2+
3+
//WGSL-DAG: @builtin(workgroup_id)
4+
//WGSL-DAG: @compute
5+
6+
void main(uint3 gid : SV_GroupID)
7+
{
8+
// Empty compute shader
9+
}

tests/wgsl/semantic-group-index.slang

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main
2+
3+
//WGSL-DAG: @builtin(local_invocation_index)
4+
//WGSL-DAG: @compute
5+
6+
void main(uint idx : SV_GroupIndex)
7+
{
8+
// Empty compute shader
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main
2+
3+
//WGSL-DAG: @builtin(local_invocation_id)
4+
//WGSL-DAG: @compute
5+
6+
void main(uint3 gtid : SV_GroupThreadID)
7+
{
8+
// Empty compute shader
9+
}

tests/wgsl/semantic-instance-id.slang

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main
2+
3+
//WGSL-DAG: @builtin(instance_index)
4+
//WGSL-DAG: @vertex
5+
6+
float4 main(uint instanceID : SV_InstanceID) : SV_Position
7+
{
8+
return float4(1,1,1,1);
9+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main
2+
3+
//WGSL-DAG: @builtin(front_facing)
4+
//WGSL-DAG: @fragment
5+
6+
float4 main(bool isFront : SV_IsFrontFace) : SV_Target
7+
{
8+
return float4(1,1,1,1);
9+
}

tests/wgsl/semantic-position.slang

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main
2+
3+
//WGSL-DAG: @builtin(position)
4+
//WGSL-DAG: @vertex
5+
6+
struct S
7+
{
8+
float4 position : SV_Position;
9+
};
10+
11+
S main()
12+
{
13+
S output;
14+
output.position = float4(0,0,0,1);
15+
return output;
16+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main
2+
3+
//WGSL-DAG: @builtin(sample_index)
4+
//WGSL-DAG: @fragment
5+
6+
float4 main(uint sampleIndex : SV_SampleIndex) : SV_Target
7+
{
8+
return float4(1,1,1,1);
9+
}

tests/wgsl/semantic-vertex-id.slang

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main
2+
3+
//WGSL-DAG: @builtin(vertex_index)
4+
//WGSL-DAG: @vertex
5+
6+
float4 main(uint vertexID : SV_VertexID) : SV_Position
7+
{
8+
return float4(1,1,1,1);
9+
}

0 commit comments

Comments
 (0)