Skip to content

Commit

Permalink
Varying inputs and outputs for wgsl
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
  • Loading branch information
expipiplus1 committed Nov 25, 2024
1 parent aaca2d2 commit 6a05f1a
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 22 deletions.
1 change: 1 addition & 0 deletions tests/compute/compile-time-loop.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj
//TEST(compute):COMPARE_RENDER_COMPUTE: -mtl -shaderobj
//TEST(compute):COMPARE_RENDER_COMPUTE: -wgsl -shaderobj

//TEST_INPUT: Texture2D(size=4, content = one):name t
//TEST_INPUT: Sampler:name s
Expand Down
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
1 change: 1 addition & 0 deletions tests/compute/discard-stmt.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj
//TEST(compute):COMPARE_RENDER_COMPUTE: -mtl -shaderobj
//TEST(compute):COMPARE_RENDER_COMPUTE: -wgsl -shaderobj
//TEST_INPUT: Texture2D(size=4, content = one):name tex
//TEST_INPUT: Sampler:name samp
//TEST_INPUT: ubuffer(data=[0 0], stride=4):out,name outputBuffer
Expand Down
3 changes: 2 additions & 1 deletion tests/compute/texture-sampling.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type -vk
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type -mtl
//TEST(compute):COMPARE_RENDER_COMPUTE: -shaderobj -output-using-type -wgsl


//TEST_INPUT: Texture1D(size=4, content = one):name=t1D
Expand All @@ -14,7 +15,7 @@
//TEST_INPUT: ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
// There is no texture_1d_array type in WGSL https://github.com/shader-slang/slang/issues/5223
// Not supported in WGSL: 1D array texture not supported in WGSL
//DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -wgpu
DISABLE_TEST(compute):COMPARE_COMPUTE:-slang -shaderobj -wgpu

Texture1D t1D;
Texture2D t2D;
Expand Down
1 change: 0 additions & 1 deletion tests/expected-failure-github.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ tests/language-feature/generics/variadic-0.slang.4 syn (wgpu)
tests/language-feature/shader-params/interface-shader-param-ordinary.slang.4 syn (wgpu)
tests/language-feature/swizzles/matrix-swizzle-write-array.slang.3 syn (wgpu)
tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.3 syn (wgpu)
tests/render/nointerpolation.hlsl (wgpu)
1 change: 1 addition & 0 deletions tests/metal/atomic-intrinsics.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//TEST:SIMPLE(filecheck=LIB):-target metallib -entry computeMain -stage compute -DMETAL
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -dx12 -profile cs_6_0 -use-dxil -shaderobj -output-using-type
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-wgsl -compute -output-using-type

//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj -output-using-type
//DISABLE_TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type
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: {{.*}}.p1{{.*}}=

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

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

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: ={{.*}}.p1

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

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

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) };
}
}
2 changes: 1 addition & 1 deletion tests/render/nointerpolation.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//TEST(smoke):COMPARE_HLSL_RENDER:
// WGSL: nointerpolate doesn't work #5625
//DISABLE_TEST(smoke):COMPARE_HLSL_RENDER: -wgpu
//TEST(smoke):COMPARE_HLSL_RENDER: -wgpu
// TODO: Investigate Metal failure
//DISABLE_TEST(smoke):COMPARE_HLSL_RENDER: -mtl

Expand Down
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 6a05f1a

Please sign in to comment.