diff --git a/tests/SkVMTest.cpp b/tests/SkVMTest.cpp index 87385d4eeb..24bca862c3 100644 --- a/tests/SkVMTest.cpp +++ b/tests/SkVMTest.cpp @@ -30,13 +30,26 @@ static void dump(skvm::Builder& builder, SkWStream* o) { o->writeText("\n"); } +// TODO: I'd like this to go away and have every test in here run both JIT and interpreter. template -static void test_jit_and_interpreter(skvm::Program&& program, Fn&& test) { - test((const skvm::Program&) program); - program.dropJIT(); +static void test_interpreter_only(skiatest::Reporter* r, skvm::Program&& program, Fn&& test) { +#if defined(SKVM_JIT) + REPORTER_ASSERT(r, !program.hasJIT()); +#endif test((const skvm::Program&) program); } +template +static void test_jit_and_interpreter(skiatest::Reporter* r, skvm::Program&& program, Fn&& test) { +#if defined(SKVM_JIT) + REPORTER_ASSERT(r, program.hasJIT()); + test((const skvm::Program&) program); + program.dropJIT(); +#endif + test_interpreter_only(r, std::move(program), std::move(test)); +} + + DEF_TEST(SkVM, r) { SkDynamicMemoryWStream buf; @@ -95,7 +108,7 @@ DEF_TEST(SkVM, r) { dump(b, &buf); - test_jit_and_interpreter(std::move(program), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, std::move(program), [&](const skvm::Program& program) { int arg[] = {0,1,2,3,4,5,6,7,8,9}; program.eval(SK_ARRAY_COUNT(arg), arg); @@ -131,7 +144,7 @@ DEF_TEST(SkVM, r) { uint32_t src[9]; uint32_t dst[SK_ARRAY_COUNT(src)]; - test_jit_and_interpreter(std::move(program), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, std::move(program), [&](const skvm::Program& program) { for (int i = 0; i < (int)SK_ARRAY_COUNT(src); i++) { src[i] = 0xbb007733; dst[i] = 0xffaaccee; @@ -163,7 +176,7 @@ DEF_TEST(SkVM, r) { test_8888(SrcoverBuilder_I32{}.done("srcover_i32")); test_8888(SrcoverBuilder_I32_SWAR{}.done("srcover_i32_SWAR")); - test_jit_and_interpreter(SrcoverBuilder_F32{Fmt::RGBA_8888, Fmt::G8}.done(), + test_jit_and_interpreter(r, SrcoverBuilder_F32{Fmt::RGBA_8888, Fmt::G8}.done(), [&](const skvm::Program& program) { uint32_t src[9]; uint8_t dst[SK_ARRAY_COUNT(src)]; @@ -186,7 +199,7 @@ DEF_TEST(SkVM, r) { } }); - test_jit_and_interpreter(SrcoverBuilder_F32{Fmt::A8, Fmt::A8}.done(), + test_jit_and_interpreter(r, SrcoverBuilder_F32{Fmt::A8, Fmt::A8}.done(), [&](const skvm::Program& program) { uint8_t src[256], dst[256]; @@ -214,7 +227,7 @@ DEF_TEST(SkVM_Pointless, r) { b.splat(4.0f)); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { for (int N = 0; N < 64; N++) { program.eval(N); } @@ -235,7 +248,7 @@ DEF_TEST(SkVM_LoopCounts, r) { b.add(b.splat(1), b.load32(arg))); - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { int buf[64]; for (int N = 0; N <= (int)SK_ARRAY_COUNT(buf); N++) { for (int i = 0; i < (int)SK_ARRAY_COUNT(buf); i++) { @@ -268,7 +281,7 @@ DEF_TEST(SkVM_gathers, r) { b.store8 (buf8 , b.gather8 (img, b.bit_and(x, b.splat(31)))); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { const int img[] = {12,34,56,78, 90,98,76,54}; constexpr int N = 20; @@ -326,7 +339,7 @@ DEF_TEST(SkVM_bitops, r) { b.store32(ptr, x); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { int x = 0x42; program.eval(1, &x); REPORTER_ASSERT(r, x == 0x7fff'ffff); @@ -345,7 +358,7 @@ DEF_TEST(SkVM_f32, r) { b.store32(arg, b.bit_cast(w)); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { float buf[] = { 1,2,3,4,5,6,7,8,9 }; program.eval(SK_ARRAY_COUNT(buf), buf); for (float v : buf) { @@ -374,7 +387,7 @@ DEF_TEST(SkVM_cmp_i32, r) { b.store32(b.varying(), m); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { int in[] = { 0,1,2,3,4,5,6,7,8,9 }; int out[SK_ARRAY_COUNT(in)]; @@ -411,7 +424,7 @@ DEF_TEST(SkVM_cmp_f32, r) { b.store32(b.varying(), m); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { float in[] = { 0,1,2,3,4,5,6,7,8,9 }; int out[SK_ARRAY_COUNT(in)]; @@ -442,7 +455,7 @@ DEF_TEST(SkVM_i16x2, r) { b.store32(buf, u); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { uint16_t buf[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13 }; program.eval(SK_ARRAY_COUNT(buf)/2, buf); @@ -475,7 +488,7 @@ DEF_TEST(SkVM_cmp_i16, r) { b.store32(buf, m); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { int16_t buf[] = { 0,1, 2,3, 4,5, 6,7, 8,9 }; program.eval(SK_ARRAY_COUNT(buf)/2, buf); @@ -508,7 +521,7 @@ DEF_TEST(SkVM_mad, r) { b.store32(arg, b.to_i32(v)); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { int x = 2; program.eval(1, &x); // x = 2 @@ -532,7 +545,7 @@ DEF_TEST(SkVM_madder, r) { b.store32(arg, b.bit_cast(w)); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { float x = 2.0f; // y = 2*2 + 2 = 6 // z = 6*2 + 6 = 18 @@ -555,7 +568,9 @@ DEF_TEST(SkVM_hoist, r) { b.store32(arg, x); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + // TODO: this really should JIT... a bug slipped in making it fail to. + // See https://skia-review.googlesource.com/c/skia/+/242591. + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { int x = 4; program.eval(1, &x); // x += 0 + 1 + 2 + 3 + ... + 30 + 31 @@ -576,7 +591,7 @@ DEF_TEST(SkVM_select, r) { b.store32(buf, x); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_jit_and_interpreter(r, b.done(), [&](const skvm::Program& program) { int buf[] = { 0,1,2,3,4,5,6,7,8 }; program.eval(SK_ARRAY_COUNT(buf), buf); for (int i = 0; i < (int)SK_ARRAY_COUNT(buf); i++) { @@ -615,7 +630,7 @@ DEF_TEST(SkVM_NewOps, r) { SkDebugf("%.*s\n", blob->size(), blob->data()); } - test_jit_and_interpreter(b.done(), [&](const skvm::Program& program) { + test_interpreter_only(r, b.done(), [&](const skvm::Program& program) { const int N = 31; int16_t buf[N]; for (int i = 0; i < N; i++) {