Skip to content

Commit

Permalink
Varying inputs and outputs for wgsl (shader-slang#5669)
Browse files Browse the repository at this point in the history
Closes shader-slang#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

Co-authored-by: Yong He <[email protected]>
  • Loading branch information
expipiplus1 and csyonghe authored Dec 2, 2024
1 parent 0586e5a commit 7aaf700
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 19 deletions.
1 change: 1 addition & 0 deletions tests/compute/constexpr.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//TEST(compute):COMPARE_COMPUTE_EX:-slang -gcompute -shaderobj
//DISABLED://TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -gcompute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-mtl -gcompute -shaderobj
//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -gcompute -shaderobj

//TEST_INPUT: Texture2D(size=4, content = one):name tex
//TEST_INPUT: Sampler:name samp
Expand Down
11 changes: 11 additions & 0 deletions tests/metal/nested-struct-fragment-input.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST:SIMPLE(filecheck=METAL): -target metal -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry fragmentMain

// METAL: COARSEVERTEX_7
// METAL: COARSEVERTEX_6
Expand Down Expand Up @@ -63,6 +64,16 @@ float4 fragmentMain(FragmentStageInput input)
// METAL-DAG: {{.*}}->p3{{.*}}->p2{{.*}}->p1{{.*}}=
// METAL-DAG: {{.*}}->p3{{.*}}->p3{{.*}}->p1{{.*}}=

// WGSL-DAG: {{.*}}._S{{.*}}=

// WGSL-DAG: {{.*}}.p2{{.*}}._S{{.*}}=
// WGSL-DAG: {{.*}}.p2{{.*}}.p2{{.*}}._S{{.*}}=
// WGSL-DAG: {{.*}}.p2{{.*}}.p3{{.*}}._S{{.*}}=

// WGSL-DAG: {{.*}}.p3{{.*}}._S{{.*}}=
// WGSL-DAG: {{.*}}.p3{{.*}}.p2{{.*}}._S{{.*}}=
// WGSL-DAG: {{.*}}.p3{{.*}}.p3{{.*}}._S{{.*}}=

outputBuffer[0] = input.coarseVertex.p1 + input.coarseVertex.p2.p1 + +input.coarseVertex.p3.p1;
return float4(0, 0, 0, 0);
}
20 changes: 20 additions & 0 deletions tests/metal/nested-struct-fragment-output.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST:SIMPLE(filecheck=METAL): -target metal -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry fragmentMain

//METAL-DAG: color(0)
//METAL-DAG: color(1)
Expand All @@ -10,6 +11,15 @@
//METAL-DAG: color(6)
//METAL-NOT: color(7)

//WGSL-DAG: location(0)
//WGSL-DAG: location(1)
//WGSL-DAG: location(2)
//WGSL-DAG: location(3)
//WGSL-DAG: location(4)
//WGSL-DAG: location(5)
//WGSL-DAG: location(6)
//WGSL-NOT: location(7)

//METALLIB: @fragmentMain

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

// WGSL-DAG: ={{.*}}._S{{.*}}

// WGSL-DAG: ={{.*}}.p2{{.*}}._S{{.*}}
// WGSL-DAG: ={{.*}}.p2{{.*}}.p2{{.*}}._S{{.*}}
// WGSL-DAG: ={{.*}}.p2{{.*}}.p3{{.*}}._S{{.*}}

// WGSL-DAG: ={{.*}}.p3{{.*}}._S{{.*}}
// WGSL-DAG: ={{.*}}.p3{{.*}}.p2{{.*}}._S{{.*}}
// WGSL-DAG: ={{.*}}.p3{{.*}}.p3{{.*}}._S{{.*}}

outputBuffer[0] = 1;
return output;
}
14 changes: 13 additions & 1 deletion tests/metal/nested-struct-multi-entry-point-vertex.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
//TEST:SIMPLE(filecheck=METALLIB1): -target metallib -stage vertex -entry vertexMain1
//TEST:SIMPLE(filecheck=METAL2): -target metal -stage vertex -entry vertexMain2
//TEST:SIMPLE(filecheck=METALLIB2): -target metallib -stage vertex -entry vertexMain2
//TEST:SIMPLE(filecheck=WGSL1): -target wgsl -stage vertex -entry vertexMain1
//TEST:SIMPLE(filecheck=WGSL2): -target wgsl -stage vertex -entry vertexMain2

//METALLIB1: @vertexMain1
//METAL1-DAG: attribute(0)
//METAL1-DAG: attribute(1)
//METAL1-NOT: attribute(2)

//WGSL1-DAG: fn vertexMain1
//WGSL1-DAG: location(0)
//WGSL1-DAG: location(1)
//WGSL1-NOT: location(2)

//METALLIB2: @vertexMain2
//METAL2-DAG: attribute(0)
//METAL2-DAG: attribute(1)
//METAL2-DAG: attribute(2)

//WGSL2-DAG: fn vertexMain2
//WGSL2-DAG: location(0)
//WGSL2-DAG: location(1)
//WGSL2-DAG: location(2)

struct SharedStruct
{
float4 position;
Expand Down Expand Up @@ -42,4 +54,4 @@ struct VertexStageInput2
float4 vertexMain2(VertexStageInput2 vertex)
{
return vertex.assembledVertex.sharedData.position;
}
}
6 changes: 5 additions & 1 deletion tests/metal/no-struct-vertex-output.slang
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//TEST:SIMPLE(filecheck=METAL): -target metallib -stage vertex -entry vertexMain
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage vertex -entry vertexMain
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry vertexMain

//METAL-DAG: position
//METALLIB: @vertexMain

//WGSL-DAG: @builtin(position)
//WGSL-DAG: @vertex

// Vertex Shader

float4 vertexMain()
{
return float4(1,1,1,1);
}
}
25 changes: 16 additions & 9 deletions tests/metal/sv_target-complex-1.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST:SIMPLE(filecheck=CHECK): -target metal
//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib
//TEST:SIMPLE(filecheck=METAL): -target metal
//TEST:SIMPLE(filecheck=METAL-ASM): -target metallib
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry fragmentMain -stage fragment

struct NestedReturn
{
Expand All @@ -20,15 +21,21 @@ struct Output
NestedReturn2 debug2 : SV_TaRget3;
}

// CHECK-ASM: define {{.*}} @fragmentMain
// CHECK: color(0)
// CHECK-DAG: color(1)
// CHECK-DAG: color(2)
// CHECK-DAG: color(3)
// CHECK-DAG: color(4)
// METAL-ASM: define {{.*}} @fragmentMain
// METAL: color(0)
// METAL-DAG: color(1)
// METAL-DAG: color(2)
// METAL-DAG: color(3)
// METAL-DAG: color(4)

// WGSL: location(0)
// WGSL-DAG: location(1)
// WGSL-DAG: location(2)
// WGSL-DAG: location(3)
// WGSL-DAG: location(4)

[shader("fragment")]
Output fragmentMain()
{
return { float4(1), {float4(2)}, float4(3) };
}
}
22 changes: 14 additions & 8 deletions tests/metal/sv_target-complex-2.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST:SIMPLE(filecheck=CHECK): -target metal
//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib
//TEST:SIMPLE(filecheck=METAL): -target metal
//TEST:SIMPLE(filecheck=METAL-ASM): -target metallib
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -entry fragmentMain -stage fragment

struct NestedReturn
{
Expand All @@ -14,14 +15,19 @@ struct Output
float4 Material : SV_Target2;
}

// CHECK-ASM: define {{.*}} @fragmentMain
// CHECK: color(0)
// CHECK: color(1)
// CHECK-DAG: color(3)
// CHECK-DAG: color(2)
// METAL-ASM: define {{.*}} @fragmentMain
// METAL: color(0)
// METAL: color(1)
// METAL-DAG: color(3)
// METAL-DAG: color(2)

// WGSL-DAG: location(0)
// WGSL-DAG: location(1)
// WGSL-DAG: location(3)
// WGSL-DAG: location(2)

[shader("fragment")]
Output fragmentMain()
{
return { float4(1), {float4(2), float4(2)}, float4(3) };
}
}
16 changes: 16 additions & 0 deletions tests/wgsl/semantic-coverage.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main

//WGSL-DAG: @builtin(sample_mask)
//WGSL-DAG: @fragment

struct Out
{
uint coverage : SV_Coverage;
};

Out main()
{
Out output;
output.coverage = 1;
return output;
}
16 changes: 16 additions & 0 deletions tests/wgsl/semantic-depth.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main

//WGSL-DAG: @builtin(frag_depth)
//WGSL-DAG: @fragment

struct Out
{
float depth : SV_Depth;
};

Out main()
{
Out output;
output.depth = 1.0;
return output;
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-dispatch-thread-id.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main

//WGSL-DAG: @builtin(global_invocation_id)
//WGSL-DAG: @compute

void main(uint3 dtid : SV_DispatchThreadID)
{
// Empty compute shader
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-group-id.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main

//WGSL-DAG: @builtin(workgroup_id)
//WGSL-DAG: @compute

void main(uint3 gid : SV_GroupID)
{
// Empty compute shader
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-group-index.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main

//WGSL-DAG: @builtin(local_invocation_index)
//WGSL-DAG: @compute

void main(uint idx : SV_GroupIndex)
{
// Empty compute shader
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-group-thread-id.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage compute -entry main

//WGSL-DAG: @builtin(local_invocation_id)
//WGSL-DAG: @compute

void main(uint3 gtid : SV_GroupThreadID)
{
// Empty compute shader
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-instance-id.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main

//WGSL-DAG: @builtin(instance_index)
//WGSL-DAG: @vertex

float4 main(uint instanceID : SV_InstanceID) : SV_Position
{
return float4(1,1,1,1);
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-is-front-face.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main

//WGSL-DAG: @builtin(front_facing)
//WGSL-DAG: @fragment

float4 main(bool isFront : SV_IsFrontFace) : SV_Target
{
return float4(1,1,1,1);
}
16 changes: 16 additions & 0 deletions tests/wgsl/semantic-position.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main

//WGSL-DAG: @builtin(position)
//WGSL-DAG: @vertex

struct S
{
float4 position : SV_Position;
};

S main()
{
S output;
output.position = float4(0,0,0,1);
return output;
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-sample-index.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry main

//WGSL-DAG: @builtin(sample_index)
//WGSL-DAG: @fragment

float4 main(uint sampleIndex : SV_SampleIndex) : SV_Target
{
return float4(1,1,1,1);
}
9 changes: 9 additions & 0 deletions tests/wgsl/semantic-vertex-id.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage vertex -entry main

//WGSL-DAG: @builtin(vertex_index)
//WGSL-DAG: @vertex

float4 main(uint vertexID : SV_VertexID) : SV_Position
{
return float4(1,1,1,1);
}

0 comments on commit 7aaf700

Please sign in to comment.