From 72016f9201e4d7820f62e7ef78cee98ed1fc4da0 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:29:02 -0700 Subject: 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 --- tests/language-feature/static_assert.slang | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/language-feature/static_assert.slang (limited to 'tests') 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 +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 +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 +extension MyType +{ +}; + +[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(); + + //CHK-NOT:error {{.*}} TEST_specialize + //CHK: error 41400: {{.*}} TEST_specialize T_is_float + //CHK-NOT:error {{.*}} TEST_specialize + TEST_specialize(); + + //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 obj; + + //CHK: ([[#@LINE+1]]): error + static_assert(dispatchThreadID.x == 0, "not constant"); +} + -- cgit v1.2.3