summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2024-06-10 13:29:02 -0700
committerGitHub <noreply@github.com>2024-06-10 13:29:02 -0700
commit72016f9201e4d7820f62e7ef78cee98ed1fc4da0 (patch)
treeb8d78b954791afd8ad409074cfd6cca96a6d6c79 /tests
parent712ce653d4c3d7284dd71389f31540d0da7f144e (diff)
Partial implementation of static_assert (#4294)
* Error out for types not supported by texture sample functions This commit prints errors with a new keyword, `static_assert`, when the given texture type is not supported for the target. * Moving the check to linkAndOptimizeIR after specialization is done * Remove unnecessary change * Adding test * Remove kIROp_StaticAssert once processed * Do not remove StaticAssert because it is needed for the next specialization * Remove after iteration of child is done --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/static_assert.slang93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/language-feature/static_assert.slang b/tests/language-feature/static_assert.slang
new file mode 100644
index 000000000..55bfa0abb
--- /dev/null
+++ b/tests/language-feature/static_assert.slang
@@ -0,0 +1,93 @@
+//TEST:SIMPLE(filecheck=CHK):-target hlsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHK):-target glsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHK):-target spirv -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=HLSL):-target hlsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=GLSL):-target glsl -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=SPV):-target spirv -stage compute -entry computeMain
+
+// TODO: requires changes in parser
+//static_assert(true, "PASS_global");
+//static_assert(false, "FAIL_global");
+
+__generic<T:IArithmetic>
+void TEST_specialize()
+{
+ static_assert(true, "TEST_specialize true");
+ static_assert(T is float, "TEST_specialize T_is_float");
+ static_assert(T is int, "TEST_specialize T_is_int");
+}
+
+void TEST_target_switch()
+{
+ static_assert(false, "TEST_target_switch all");
+ __target_switch
+ {
+ case hlsl:
+ static_assert(false, "TEST_target_switch hlsl");
+ return;
+ case glsl:
+ static_assert(false, "TEST_target_switch glsl");
+ return;
+ default:
+ static_assert(false, "TEST_target_switch default");
+ return;
+ }
+}
+
+__generic<T:IArithmetic>
+struct MyType
+{
+ // TODO: requires changes in parser
+ //static_assert(true, "PASS_struct");
+ //static_assert(false, "FAIL_struct");
+
+ __init()
+ {
+ static_assert(true, "MyType init true");
+ static_assert(false, "MyType init false");
+ }
+};
+
+__generic<T:IFloat>
+extension MyType<T>
+{
+};
+
+[numthreads(1,1,1)]
+void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
+{
+ //CHK-NOT:error {{.*}} TEST_specialize
+ //CHK: error {{.*}} TEST_specialize T_is_int
+ //CHK-NOT:error {{.*}} TEST_specialize
+ TEST_specialize<float>();
+
+ //CHK-NOT:error {{.*}} TEST_specialize
+ //CHK: error 41400: {{.*}} TEST_specialize T_is_float
+ //CHK-NOT:error {{.*}} TEST_specialize
+ TEST_specialize<int>();
+
+ //HLSL: error {{.*}} TEST_target_switch all
+ //HLSL: error {{.*}} TEST_target_switch hlsl
+ //HLSL-NOT: error {{.*}} TEST_target_switch glsl
+ //HLSL-NOT: error {{.*}} TEST_target_switch default
+ //
+ //GLSL: error {{.*}} TEST_target_switch all
+ //GLSL-NOT: error {{.*}} TEST_target_switch hlsl
+ //GLSL: error {{.*}} TEST_target_switch glsl
+ //GLSL-NOT: error {{.*}} TEST_target_switch default
+ //
+ //SPV: error {{.*}} TEST_target_switch all
+ //SPV-NOT: error {{.*}} TEST_target_switch hlsl
+ //SPV-NOT: error {{.*}} TEST_target_switch glsl
+ //SPV: error {{.*}} TEST_target_switch default
+ //
+ TEST_target_switch();
+
+ //CHK-NOT: error {{.*}} MyType init true
+ //CHK: error {{.*}} MyType init false
+ MyType<float> obj;
+
+ //CHK: ([[#@LINE+1]]): error
+ static_assert(dispatchThreadID.x == 0, "not constant");
+}
+