Skip to content

Commit

Permalink
Enable WGSP tests that works for Metal related to Semantics
Browse files Browse the repository at this point in the history
This commit enables existing tests for WGSL that are enabled for Metal regarding the Semantics.
  • Loading branch information
jkwak-work committed Dec 10, 2024
1 parent 410ad9c commit 507837e
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 31 deletions.
26 changes: 26 additions & 0 deletions tests/metal/nested-struct-fragment-input.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//TEST:SIMPLE(filecheck=METAL): -target metal -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=WGSL): -target wgsl -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=METALLIB): -target metallib -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm -stage fragment -entry fragmentMain

// METAL: COARSEVERTEX_7
// METAL: COARSEVERTEX_6
Expand All @@ -20,7 +22,19 @@
// METAL-NOT: [[ATTR3]]
// METAL-DAG: [[ATTR4:COARSEVERTEX_(1|2|3|4)]]

// WGSL:struct FragmentStageInput
// WGSL-DAG:@location(0) [[VAR0:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(1) [[VAR1:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(2) [[VAR2:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(3) [[VAR3:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(4) [[VAR4:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(6) [[VAR6:[A-Za-z_0-9]+]]
// WGSL-DAG:@location(7) [[VAR7:[A-Za-z_0-9]+]]
// WGSL-NOT:@location(8)
// WGSL:}

// METALLIB: @fragmentMain
// WGSLSPIRV: %fragmentMain = OpFunction %void None

RWStructuredBuffer<float> outputBuffer;

Expand Down Expand Up @@ -51,6 +65,7 @@ struct FragmentStageInput
TopFragment coarseVertex : CoarseVertex;
};

// WGSL: fn fragmentMain{{[( ]*}}[[InputVar:[A-Za-z_0-9]+]]
float4 fragmentMain(FragmentStageInput input)
{
// METAL-DAG: {{.*}}->p1{{.*}}=
Expand All @@ -63,6 +78,17 @@ float4 fragmentMain(FragmentStageInput input)
// METAL-DAG: {{.*}}->p3{{.*}}->p2{{.*}}->p1{{.*}}=
// METAL-DAG: {{.*}}->p3{{.*}}->p3{{.*}}->p1{{.*}}=

// WGSL: var [[UnpackedInput:[A-Za-z_0-9]+]] : FragmentStageInput
// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR7]];

// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR6]];
// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR1]];
// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR2]];

// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR0]];
// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR3]];
// WGSL-DAG: [[UnpackedInput]].{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}}.{{[A-Za-z_0-9]+}} = [[InputVar]].[[VAR4]];

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

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

//WGSL-DAG:@location(0) [[VAR0:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(1) [[VAR1:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(2) [[VAR2:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(3) [[VAR3:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(4) [[VAR4:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(5) [[VAR5:[A-Za-z_0-9]+]]
//WGSL-DAG:@location(6) [[VAR6:[A-Za-z_0-9]+]]
//WGSL-NOT:@location(7)

//METALLIB: @fragmentMain
//WGSLSPIRV: %fragmentMain = OpFunction %void None

RWStructuredBuffer<float> outputBuffer;

Expand All @@ -31,7 +43,7 @@ struct MiddleFragment1
};
struct TopFragment
{
float p1;
float p1;
MiddleFragment1 p2;
MiddleFragment1 p3;
};
Expand All @@ -46,6 +58,7 @@ struct FragmentStageOutput
TopFragment fragment : SV_Target;
};

//WGSL: fn fragmentMain{{.*}}-> [[ReturnType:FragmentStageOutput[_0-9]+]]
FragmentStageOutput fragmentMain(FragmentStageInput input)
{
FragmentStageOutput output;
Expand All @@ -69,6 +82,15 @@ FragmentStageOutput fragmentMain(FragmentStageInput input)
// METAL-DAG: ={{.*}}.p3{{.*}}.p2{{.*}}.p1
// METAL-DAG: ={{.*}}.p3{{.*}}.p3{{.*}}.p1

outputBuffer[0] = 1;
return output;
// WGSL: var [[ReturnVar:[A-Za-z_0-9]+]] : [[ReturnType]]
// WGSL-DAG: [[ReturnVar]].[[VAR0]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR1]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR2]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR3]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR4]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR5]]{{.*}} = {{.*}};
// WGSL-DAG: [[ReturnVar]].[[VAR6]]{{.*}} = {{.*}};

outputBuffer[0] = 1;
return output;
}
19 changes: 18 additions & 1 deletion tests/metal/nested-struct-multi-entry-point-vertex.slang
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
//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
//TEST:SIMPLE(filecheck=WGSLSPIRV1): -target wgsl-spirv-asm -stage vertex -entry vertexMain1
//TEST:SIMPLE(filecheck=WGSLSPIRV2): -target wgsl-spirv-asm -stage vertex -entry vertexMain2

//METALLIB1: @vertexMain1
//METAL1-DAG: attribute(0)
//METAL1-DAG: attribute(1)
Expand All @@ -12,6 +17,18 @@
//METAL2-DAG: attribute(0)
//METAL2-DAG: attribute(1)
//METAL2-DAG: attribute(2)
//METAL2-NOT: attribute(3)

//WGSLSPIRV1: %vertexMain1 = OpFunction %void None
//WGSL1-DAG: @location(0) position
//WGSL1-DAG: @location(1) color
//WGSL1-NOT: @location(2)

//WGSLSPIRV2: %vertexMain2 = OpFunction %void None
//WGSL2-DAG: @location(0) uv
//WGSL2-DAG: @location(1) position
//WGSL2-DAG: @location(2) color
//WGSL2-NOT: @location(3)

struct SharedStruct
{
Expand Down Expand Up @@ -42,4 +59,4 @@ struct VertexStageInput2
float4 vertexMain2(VertexStageInput2 vertex)
{
return vertex.assembledVertex.sharedData.position;
}
}
9 changes: 7 additions & 2 deletions tests/metal/no-struct-vertex-output.slang
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
//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
//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm -stage vertex -entry vertexMain

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

//WGSL: @builtin(position)
//WGSLSPIRV: %vertexMain = OpFunction

// Vertex Shader

float4 vertexMain()
{
return float4(1,1,1,1);
}
return float4(1,1,1,1);
}
26 changes: 18 additions & 8 deletions tests/metal/stage-in-2.slang
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
//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 -stage fragment -entry fragmentMain
//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm

// CHECK-ASM: define {{.*}} @vertexMain
// CHECK-ASM: define {{.*}} @fragmentMain
// METAL_ASM: define {{.*}} @vertexMain
// METAL_ASM: define {{.*}} @fragmentMain

// Check that we don't flatten stage-input parameters that have user semantics.

// CHECK: struct pixelInput
// CHECK-NEXT: {
// CHECK-NEXT: {{\[\[}}user(COARSEVERTEX){{\]\]}};
// METAL: struct pixelInput
// METAL-NEXT: {
// METAL-NEXT: {{\[\[}}user(COARSEVERTEX){{\]\]}};

//WGSLSPIRV: %vertexMain = OpFunction %
//WGSLSPIRV: %fragmentMain = OpFunction %

//WGSL: struct [[CoarseVertex:CoarseVertex[_0-9]*]]
//WGSL-NEXT: {
//WGSL-NEXT: @location(0) color
//WGSL: fn fragmentMain({{.*}}[[CoarseVertex]]

// Uniform data to be passed from application -> shader.
cbuffer Uniforms
Expand Down Expand Up @@ -67,4 +77,4 @@ float4 fragmentMain(
float3 color = coarseVertex.color;

return float4(color, 1.0);
}
}
27 changes: 18 additions & 9 deletions tests/metal/sv_target-complex-1.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//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
//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm

struct NestedReturn
{
Expand All @@ -20,15 +22,22 @@ 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)

// WGSLSPIRV: %fragmentMain = OpFunction
// WGSL: @location(0) Diffuse
// WGSL: @location(1) debug
// WGSL: @location(2) Material
// WGSL: @location(3) debugAux1
// WGSL: @location(4) debugAux2

[shader("fragment")]
Output fragmentMain()
{
return { float4(1), {float4(2)}, float4(3) };
}
}
24 changes: 16 additions & 8 deletions tests/metal/sv_target-complex-2.slang
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//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
//TEST:SIMPLE(filecheck=WGSLSPIRV): -target wgsl-spirv-asm

struct NestedReturn
{
Expand All @@ -14,14 +16,20 @@ 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)

// WGSLSPIRV: %fragmentMain = OpFunction
// WGSL: @location(0) Diffuse
// WGSL: @location(1) debug1
// WGSL-DAG: @location(3) debug2
// WGSL-DAG: @location(2) Material

[shader("fragment")]
Output fragmentMain()
{
return { float4(1), {float4(2), float4(2)}, float4(3) };
}
}

0 comments on commit 507837e

Please sign in to comment.