summaryrefslogtreecommitdiffstats
path: root/tests/language-feature
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-06 22:02:43 -0800
committerGitHub <noreply@github.com>2025-02-06 22:02:43 -0800
commitbae87afb20f95f9f27c64c4955bbc4464c576509 (patch)
tree44d079bd76002d69be20efdbd03ac6ff62ef8caf /tests/language-feature
parent075b10e69055acc6536d74c1cb3399e0fe75338d (diff)
Support stage_switch. (#6311)
* Support stage_switch. * Update proposal status. * Fix gl_InstanceID. * Fix.
Diffstat (limited to 'tests/language-feature')
-rw-r--r--tests/language-feature/stage-switch.slang38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/language-feature/stage-switch.slang b/tests/language-feature/stage-switch.slang
new file mode 100644
index 000000000..1bdd1f85a
--- /dev/null
+++ b/tests/language-feature/stage-switch.slang
@@ -0,0 +1,38 @@
+
+//TEST:SIMPLE(filecheck=CHECK):-target spirv
+
+float ddx_or(float val, float defaultVal)
+{
+ __stage_switch
+ {
+ case fragment:
+ return ddx(val);
+ default:
+ return defaultVal;
+ }
+}
+
+float intermediate(float val)
+{
+ return ddx_or(val, 1.0);
+}
+
+RWStructuredBuffer<float> output;
+
+[numthreads(1,1,1)]
+void computeMain()
+{
+ // CHECK-LABEL: %computeMain = OpFunction
+ // CHECK: OpStore %{{.*}} %float_1
+ // CHECK: OpFunctionEnd
+ output[0] = intermediate(2.0);
+}
+
+[shader("fragment")]
+float4 fragmentMain(float vin) : SV_Target
+{
+ // CHECK-LABEL: %fragmentMain = OpFunction
+ // CHECK: OpDPdx
+ // CHECK: OpFunctionEnd
+ return intermediate(vin);
+} \ No newline at end of file