diff options
| author | Yong He <yonghe@outlook.com> | 2024-06-08 02:16:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-08 02:16:41 -0700 |
| commit | 65928afe4f94e3c7e5fe33c1428f9d7afc14c7c5 (patch) | |
| tree | 8995b961a95802832fd2e5fdabab1148f5524ee5 /tests | |
| parent | e39ceab5670184ad8b77f5b1aa4bb18b7ab231bc (diff) | |
Metal system value overhaul. (#4308)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/metal/stage-in-2.slang | 70 | ||||
| -rw-r--r-- | tests/metal/stage-in.slang | 8 | ||||
| -rw-r--r-- | tests/metal/system-val-conversion.slang | 29 |
3 files changed, 103 insertions, 4 deletions
diff --git a/tests/metal/stage-in-2.slang b/tests/metal/stage-in-2.slang new file mode 100644 index 000000000..2b1e61306 --- /dev/null +++ b/tests/metal/stage-in-2.slang @@ -0,0 +1,70 @@ +//TEST:SIMPLE(filecheck=CHECK): -target metal +//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib + +// CHECK-ASM: define {{.*}} @vertexMain +// CHECK-ASM: define {{.*}} @fragmentMain + +// Check that we don't flatten stage-input parameters that have user semantics. + +// CHECK: struct pixelInput +// CHECK-NEXT: { +// CHECK-NEXT: CoarseVertex{{.*}} coarseVertex{{.*}} {{\[\[}}user(COARSEVERTEX){{\]\]}}; + +// Uniform data to be passed from application -> shader. +cbuffer Uniforms +{ + float4x4 modelViewProjection; +} + +// Per-vertex attributes to be assembled from bound vertex buffers. +struct AssembledVertex +{ + float3 position : POSITION; + float3 color : COLOR; +}; + +// Output of the vertex shader, and input to the fragment shader. +struct CoarseVertex +{ + float3 color; +}; + +// Output of the fragment shader +struct Fragment +{ + float4 color; +}; + +// Vertex Shader + +struct VertexStageOutput +{ + CoarseVertex coarseVertex : CoarseVertex; + float4 sv_position : SV_Position; +}; + +[shader("vertex")] +VertexStageOutput vertexMain( + AssembledVertex assembledVertex) +{ + VertexStageOutput output; + + float3 position = assembledVertex.position; + float3 color = assembledVertex.color; + + output.coarseVertex.color = color; + output.sv_position = mul(modelViewProjection, float4(position, 1.0)); + + return output; +} + +// Fragment Shader + +[shader("fragment")] +float4 fragmentMain( + CoarseVertex coarseVertex : CoarseVertex) : SV_Target +{ + float3 color = coarseVertex.color; + + return float4(color, 1.0); +}
\ No newline at end of file diff --git a/tests/metal/stage-in.slang b/tests/metal/stage-in.slang index 31d224072..ee586847e 100644 --- a/tests/metal/stage-in.slang +++ b/tests/metal/stage-in.slang @@ -4,8 +4,8 @@ // CHECK: struct VOut{{.*}} // CHECK-NEXT:{ // CHECK-NEXT: float4 position{{.*}} {{\[\[}}position{{\]\]}}; -// CHECK-NEXT: float4 vertexColor{{.*}} {{\[\[}}user(_slang_attr){{\]\]}}; -// CHECK-NEXT: float2 vertexUV{{.*}} {{\[\[}}user(_slang_attr_1){{\]\]}}; +// CHECK-NEXT: float4 vertexColor{{.*}} {{\[\[}}user(_SLANG_ATTR){{\]\]}}; +// CHECK-NEXT: float2 vertexUV{{.*}} {{\[\[}}user(_SLANG_ATTR_1){{\]\]}}; // CHECK-NEXT: float3 vertexNormal{{.*}} {{\[\[}}user(NORMAL){{\]\]}}; // CHECK-NEXT:}; @@ -24,8 +24,8 @@ // CHECK: struct pixelInput{{.*}} // CHECK-NEXT:{ -// CHECK-NEXT: float4 vertexColor{{.*}} {{\[\[}}user(_slang_attr){{\]\]}}; -// CHECK-NEXT: float2 vertexUV{{.*}} {{\[\[}}user(_slang_attr_1){{\]\]}}; +// CHECK-NEXT: float4 vertexColor{{.*}} {{\[\[}}user(_SLANG_ATTR){{\]\]}}; +// CHECK-NEXT: float2 vertexUV{{.*}} {{\[\[}}user(_SLANG_ATTR_1){{\]\]}}; // CHECK-NEXT: float3 vertexNormal{{.*}} {{\[\[}}user(NORMAL){{\]\]}}; // CHECK-NEXT:}; diff --git a/tests/metal/system-val-conversion.slang b/tests/metal/system-val-conversion.slang new file mode 100644 index 000000000..5a208086d --- /dev/null +++ b/tests/metal/system-val-conversion.slang @@ -0,0 +1,29 @@ +//TEST:SIMPLE(filecheck=CHECK-ASM): -target metallib +//TEST:SIMPLE(filecheck=CHECK): -target metal + +// Test that we always emit correct type for system value and insert conversion logic +// if the declared type of the SV is different from the spec-defined type. + +uniform RWStructuredBuffer<float> outputBuffer; + +RWByteAddressBuffer buffer; + +// CHECK-ASM: define void @main_kernel + +struct TestStruct +{ + uint8_t a; + float16_t h; + float b; + float4 c; + float4x3 d; +} + +// CHECK: void main_kernel(uint3 tid{{.*}} +// CHECK: int tid{{.*}} = int(tid{{.*}}.x); + +[numthreads(1,1,1)] +void main_kernel(int tid: SV_DispatchThreadID) +{ + buffer.Store(128, buffer.Load<TestStruct>(tid)); +} |
