summaryrefslogtreecommitdiffstats
path: root/tests/wgsl
diff options
context:
space:
mode:
authorSwoorup Joshi <swoorupj@gmail.com>2025-06-25 17:35:12 +1000
committerGitHub <noreply@github.com>2025-06-25 07:35:12 +0000
commit7e8c85e85440c1fea42236a8ef8286e1ce1638ce (patch)
tree17a6b34dacfa3412e6a234779ea44cf1a4b59c9f /tests/wgsl
parent47475114d036a391bacdb53a9a1c60e5d35b61bc (diff)
Fix generation of wgsl case arms (#7374)
* Fix generation of wgsl case arms * Added test case to test generation of switch case --------- Co-authored-by: Harsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com>
Diffstat (limited to 'tests/wgsl')
-rw-r--r--tests/wgsl/switch-case.slang86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/wgsl/switch-case.slang b/tests/wgsl/switch-case.slang
new file mode 100644
index 000000000..c4ff0996e
--- /dev/null
+++ b/tests/wgsl/switch-case.slang
@@ -0,0 +1,86 @@
+//TEST:SIMPLE(filecheck=WGSL): -target wgsl -conformance "Circle:IShape=0" -conformance "Rectangle:IShape=1"
+
+[anyValueSize(16)]
+interface IShape
+{
+ float getArea();
+}
+
+struct Circle : IShape
+{
+ float radius;
+
+ float getArea() { return 3.14159 * radius * radius; }
+}
+
+struct Rectangle : IShape
+{
+ float width;
+ float height;
+
+ float getArea() { return width * height; }
+}
+
+struct ShapeDataBlob { uint type; uint payload[16]; }
+
+struct ShapeBuffer
+{
+ StructuredBuffer<ShapeDataBlob> shapes;
+ IShape getShape(uint index)
+ {
+ uint type = shapes[index].type;
+ return createDynamicObject<IShape, ShapeDataBlob>(type, shapes[index]);
+ }
+}
+
+struct VertexInput
+{
+ float2 position;
+ float3 color;
+}
+
+struct VertexOutput
+{
+ float4 position : SV_POSITION;
+ float3 color : TEXCOORD0;
+ float area : TEXCOORD1;
+}
+
+
+[shader("vertex")]
+func vs_main( input: VertexInput, shapes: ShapeBuffer)->VertexOutput
+{
+ VertexOutput output;
+ output.position = float4(input.position, 0.0, 1.0);
+ output.color = input.color;
+ output.area = shapes.getShape(0).getArea();
+ return output;
+}
+
+struct FragmentOutput
+{
+ float4 color : SV_TARGET;
+}
+
+[shader("fragment")]
+func fs_main(VertexOutput input)->FragmentOutput
+{
+ FragmentOutput output;
+ output.color = float4(input.color * input.area, 1.0);
+ return output;
+}
+
+//WGSL: fn _S9( _S10 : Tuple_0) -> f32
+//WGSL-NEXT: {
+//WGSL-NEXT: switch(_S10.value1_0.x)
+//WGSL-NEXT: {
+//WGSL-NEXT: case u32(0):
+//WGSL-NEXT: {
+//WGSL-NEXT: return Circle_getArea_0(unpackAnyValue16_0(_S10.value2_0));
+//WGSL-NEXT: }
+//WGSL-NEXT: default :
+//WGSL-NEXT: {
+//WGSL-NEXT: return Rectangle_getArea_0(unpackAnyValue16_1(_S10.value2_0));
+//WGSL-NEXT: }
+//WGSL-NEXT: }
+//WGSL-NEXT: }