diff --git a/BUILD.gn b/BUILD.gn index 7a43e55526..fc20ab01d1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -783,6 +783,15 @@ if (skia_compile_sksl_tests) { lang = "--metal" settings = "--settings" } + compile_sksl("skvm_tests") { + sources = sksl_skvm_tests_sources + outputPatterns = [ [ + "/golden", + ".skvm", + ] ] + lang = "--skvm" + settings = "--settings" + } compile_sksl("spirv_tests") { sources = sksl_spirv_tests_sources outputPatterns = [ [ @@ -801,6 +810,8 @@ if (skia_compile_sksl_tests) { } group("compile_sksl_metal_tests") { } + group("compile_sksl_skvm_tests") { + } group("compile_sksl_spirv_tests") { } } @@ -813,6 +824,7 @@ optional("gpu") { ":compile_sksl_glsl_nosettings_tests", ":compile_sksl_glsl_tests", ":compile_sksl_metal_tests", + ":compile_sksl_skvm_tests", ":compile_sksl_spirv_tests", ":dehydrate_sksl", ":run_sksllex", diff --git a/gn/compile_sksl_tests.py b/gn/compile_sksl_tests.py index 1709c7db24..96157241fa 100755 --- a/gn/compile_sksl_tests.py +++ b/gn/compile_sksl_tests.py @@ -63,8 +63,12 @@ for input in inputs: worklist.write(input + "\n") worklist.write(target + ".asm" + extensionForSpirvAsm(ext) + "\n") worklist.write(settings + "\n\n") + elif lang == "--skvm": + worklist.write(input + "\n") + worklist.write(target + ".skvm\n") + worklist.write(settings + "\n\n") else: - sys.exit("### Expected one of: --fp --glsl --metal --spirv, got " + lang) + sys.exit("### Expected one of: --fp --glsl --metal --spirv --skvm, got " + lang) # Invoke skslc, passing in the worklist. worklist.close() diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index 267fcf4ea3..9c59bc4ae8 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -467,6 +467,19 @@ sksl_settings_tests = [ "$_tests/sksl/workarounds/TernaryShortCircuit.sksl", ] +sksl_rte_tests = [ + "$_tests/sksl/runtime/SampleWithConstantMatrix.rte", + "$_tests/sksl/runtime/SampleWithExplicitCoord.rte", + "$_tests/sksl/runtime/SampleWithUniformMatrix.rte", + "$_tests/sksl/runtime/SampleWithVariableMatrix.rte", +] + +sksl_rte_error_tests = [ + "$_tests/sksl/errors/Discard.rte", + "$_tests/sksl/errors/UnsupportedTypeSampler.rte", + "$_tests/sksl/errors/UnsupportedTypeTexture.rte", +] + # Tests in sksl_fp_tests_sources will be compiled with --settings on, and are expected to generate # a .cpp and a .h output file. sksl_fp_tests_sources = sksl_fp_error_tests + sksl_fp_tests @@ -489,3 +502,7 @@ sksl_metal_tests_sources = # generate a .asm.(frag|vert|geom) output file. sksl_spirv_tests_sources = sksl_blend_tests + sksl_shared_tests + sksl_spirv_tests + +## Tests in sksl_skvm_tests_sources will be compiled with --settings on, and are expected to +## generate a .skvm output file. +sksl_skvm_tests_sources = sksl_rte_tests + sksl_rte_error_tests diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp index c7312c3e45..f443d9d5ad 100644 --- a/tests/SkRuntimeEffectTest.cpp +++ b/tests/SkRuntimeEffectTest.cpp @@ -39,10 +39,6 @@ DEF_TEST(SkRuntimeEffectInvalid, r) { test("in bool Flag; layout(when=Flag) uniform float Input;" EMPTY_MAIN, "when"); test("layout(tracked) uniform float Input;" EMPTY_MAIN, "tracked"); - // GLSL types like sampler2D and texture2D are not allowed anywhere: - test("uniform sampler2D s;" EMPTY_MAIN, "no type named 'sampler2D'"); - test("uniform texture2D s;" EMPTY_MAIN, "no type named 'texture2D'"); - // Runtime SkSL supports a limited set of uniform types. No bool, or int, for example: test("uniform bool b;" EMPTY_MAIN, "uniform"); test("uniform int i;" EMPTY_MAIN, "uniform"); @@ -58,9 +54,6 @@ DEF_TEST(SkRuntimeEffectInvalid, r) { test("half4 missing(); half4 main() { return missing(); }", "undefined function"); - // No use of 'discard' is permitted - test("half4 main() { discard; }", "discard"); - // Shouldn't be possible to create an SkRuntimeEffect without "main" test("", "main"); diff --git a/tests/sksl/errors/Discard.rte b/tests/sksl/errors/Discard.rte new file mode 100644 index 0000000000..f1e1bfb38a --- /dev/null +++ b/tests/sksl/errors/Discard.rte @@ -0,0 +1,3 @@ +half4 main() { + discard; +} diff --git a/tests/sksl/errors/UnsupportedTypeSampler.rte b/tests/sksl/errors/UnsupportedTypeSampler.rte new file mode 100644 index 0000000000..acaba6275a --- /dev/null +++ b/tests/sksl/errors/UnsupportedTypeSampler.rte @@ -0,0 +1,5 @@ +uniform sampler2D s; + +half4 main() { + return half4(0); +} diff --git a/tests/sksl/errors/UnsupportedTypeTexture.rte b/tests/sksl/errors/UnsupportedTypeTexture.rte new file mode 100644 index 0000000000..05711f14a3 --- /dev/null +++ b/tests/sksl/errors/UnsupportedTypeTexture.rte @@ -0,0 +1,5 @@ +uniform texture2D s; + +half4 main() { + return half4(0); +} diff --git a/tests/sksl/errors/golden/Discard.skvm b/tests/sksl/errors/golden/Discard.skvm new file mode 100644 index 0000000000..dff69637ff --- /dev/null +++ b/tests/sksl/errors/golden/Discard.skvm @@ -0,0 +1,4 @@ +### Compilation failed: + +error: 2: discard statement is only permitted in fragment shaders +1 error diff --git a/tests/sksl/errors/golden/UnsupportedTypeSampler.skvm b/tests/sksl/errors/golden/UnsupportedTypeSampler.skvm new file mode 100644 index 0000000000..6f6f9f7125 --- /dev/null +++ b/tests/sksl/errors/golden/UnsupportedTypeSampler.skvm @@ -0,0 +1,4 @@ +### Compilation failed: + +error: 1: no type named 'sampler2D' +1 error diff --git a/tests/sksl/errors/golden/UnsupportedTypeTexture.skvm b/tests/sksl/errors/golden/UnsupportedTypeTexture.skvm new file mode 100644 index 0000000000..b66f94294e --- /dev/null +++ b/tests/sksl/errors/golden/UnsupportedTypeTexture.skvm @@ -0,0 +1,4 @@ +### Compilation failed: + +error: 1: no type named 'texture2D' +1 error diff --git a/tests/sksl/runtime/SampleWithConstantMatrix.rte b/tests/sksl/runtime/SampleWithConstantMatrix.rte new file mode 100644 index 0000000000..ec826a121c --- /dev/null +++ b/tests/sksl/runtime/SampleWithConstantMatrix.rte @@ -0,0 +1,6 @@ +uniform shader child; +half4 main() { + return sample(child, float3x3(2, 0, 0, + 0, 1, 0, + 0, 0, 1)); +} diff --git a/tests/sksl/runtime/SampleWithExplicitCoord.rte b/tests/sksl/runtime/SampleWithExplicitCoord.rte new file mode 100644 index 0000000000..6d3a6be953 --- /dev/null +++ b/tests/sksl/runtime/SampleWithExplicitCoord.rte @@ -0,0 +1,4 @@ +uniform shader child; +half4 main(float2 p) { + return sample(child, p.yx); +} diff --git a/tests/sksl/runtime/SampleWithUniformMatrix.rte b/tests/sksl/runtime/SampleWithUniformMatrix.rte new file mode 100644 index 0000000000..3de01e33bb --- /dev/null +++ b/tests/sksl/runtime/SampleWithUniformMatrix.rte @@ -0,0 +1,5 @@ +uniform shader child; +uniform float3x3 matrix; +half4 main() { + return sample(child, matrix); +} diff --git a/tests/sksl/runtime/SampleWithVariableMatrix.rte b/tests/sksl/runtime/SampleWithVariableMatrix.rte new file mode 100644 index 0000000000..043fb6da0a --- /dev/null +++ b/tests/sksl/runtime/SampleWithVariableMatrix.rte @@ -0,0 +1,7 @@ +uniform shader child; +half4 main() { + float x = sqrt(1.0); + return sample(child, float3x3(x, 0, 0, + 0, x, 0, + 0, 0, 1)); +} diff --git a/tests/sksl/runtime/golden/SampleWithConstantMatrix.skvm b/tests/sksl/runtime/golden/SampleWithConstantMatrix.skvm new file mode 100644 index 0000000000..1347f2d533 --- /dev/null +++ b/tests/sksl/runtime/golden/SampleWithConstantMatrix.skvm @@ -0,0 +1,37 @@ +12 registers, 35 instructions: +0 r0 = splat 3 (4.2038954e-45) +1 r1 = uniform32 arg(0) C +2 r2 = splat 3F800000 (1) +3 r3 = uniform32 arg(0) 0 +4 r4 = splat 0 (0) +5 r5 = mul_f32 r4 r3 +6 r6 = splat 40000000 (2) +7 r7 = splat 2 (2.8025969e-45) +8 r8 = splat 1 (1.4012985e-45) +loop: +9 r9 = index +10 r10 = mul_f32 r4 r9 +11 r11 = add_f32 r10 r5 +12 r11 = add_f32 r11 r2 +13 r11 = div_f32 r2 r11 +14 r10 = add_f32 r10 r3 +15 r10 = mul_f32 r10 r11 +16 r10 = trunc r10 +17 r10 = mul_i32 r10 r1 +18 r9 = mul_f32 r6 r9 +19 r9 = add_f32 r9 r5 +20 r11 = mul_f32 r9 r11 +21 r11 = trunc r11 +22 r10 = add_i32 r11 r10 +23 r10 = shl_i32 r10 2 +24 r11 = add_i32 r10 r0 +25 r11 = gather32 arg(0) 4 r11 +26 store32 arg(4) r11 +27 r11 = add_i32 r10 r7 +28 r11 = gather32 arg(0) 4 r11 +29 store32 arg(3) r11 +30 r11 = add_i32 r10 r8 +31 r11 = gather32 arg(0) 4 r11 +32 store32 arg(2) r11 +33 r10 = gather32 arg(0) 4 r10 +34 store32 arg(1) r10 diff --git a/tests/sksl/runtime/golden/SampleWithExplicitCoord.skvm b/tests/sksl/runtime/golden/SampleWithExplicitCoord.skvm new file mode 100644 index 0000000000..bbb795708d --- /dev/null +++ b/tests/sksl/runtime/golden/SampleWithExplicitCoord.skvm @@ -0,0 +1,24 @@ +7 registers, 22 instructions: +0 r0 = splat 3 (4.2038954e-45) +1 r1 = uniform32 arg(0) C +2 r2 = uniform32 arg(0) 0 +3 r2 = trunc r2 +4 r3 = splat 2 (2.8025969e-45) +5 r4 = splat 1 (1.4012985e-45) +loop: +6 r5 = index +7 r5 = trunc r5 +8 r5 = mul_i32 r5 r1 +9 r5 = add_i32 r2 r5 +10 r5 = shl_i32 r5 2 +11 r6 = add_i32 r5 r0 +12 r6 = gather32 arg(0) 4 r6 +13 store32 arg(4) r6 +14 r6 = add_i32 r5 r3 +15 r6 = gather32 arg(0) 4 r6 +16 store32 arg(3) r6 +17 r6 = add_i32 r5 r4 +18 r6 = gather32 arg(0) 4 r6 +19 store32 arg(2) r6 +20 r5 = gather32 arg(0) 4 r5 +21 store32 arg(1) r5 diff --git a/tests/sksl/runtime/golden/SampleWithUniformMatrix.skvm b/tests/sksl/runtime/golden/SampleWithUniformMatrix.skvm new file mode 100644 index 0000000000..33d01222e1 --- /dev/null +++ b/tests/sksl/runtime/golden/SampleWithUniformMatrix.skvm @@ -0,0 +1,49 @@ +17 registers, 47 instructions: +0 r0 = splat 3 (4.2038954e-45) +1 r1 = uniform32 arg(0) C +2 r2 = uniform32 arg(0) 30 +3 r3 = uniform32 arg(0) 0 +4 r4 = uniform32 arg(0) 24 +5 r4 = mul_f32 r4 r3 +6 r5 = uniform32 arg(0) 18 +7 r6 = splat 3F800000 (1) +8 r7 = uniform32 arg(0) 2C +9 r8 = uniform32 arg(0) 20 +10 r8 = mul_f32 r8 r3 +11 r9 = uniform32 arg(0) 14 +12 r10 = uniform32 arg(0) 28 +13 r11 = uniform32 arg(0) 1C +14 r3 = mul_f32 r11 r3 +15 r11 = uniform32 arg(0) 10 +16 r12 = splat 2 (2.8025969e-45) +17 r13 = splat 1 (1.4012985e-45) +loop: +18 r14 = index +19 r15 = mul_f32 r5 r14 +20 r15 = add_f32 r15 r4 +21 r15 = add_f32 r15 r2 +22 r15 = div_f32 r6 r15 +23 r16 = mul_f32 r9 r14 +24 r16 = add_f32 r16 r8 +25 r16 = add_f32 r16 r7 +26 r16 = mul_f32 r16 r15 +27 r16 = trunc r16 +28 r16 = mul_i32 r16 r1 +29 r14 = mul_f32 r11 r14 +30 r14 = add_f32 r14 r3 +31 r14 = add_f32 r14 r10 +32 r15 = mul_f32 r14 r15 +33 r15 = trunc r15 +34 r16 = add_i32 r15 r16 +35 r16 = shl_i32 r16 2 +36 r15 = add_i32 r16 r0 +37 r15 = gather32 arg(0) 4 r15 +38 store32 arg(4) r15 +39 r15 = add_i32 r16 r12 +40 r15 = gather32 arg(0) 4 r15 +41 store32 arg(3) r15 +42 r15 = add_i32 r16 r13 +43 r15 = gather32 arg(0) 4 r15 +44 store32 arg(2) r15 +45 r16 = gather32 arg(0) 4 r16 +46 store32 arg(1) r16 diff --git a/tests/sksl/runtime/golden/SampleWithVariableMatrix.skvm b/tests/sksl/runtime/golden/SampleWithVariableMatrix.skvm new file mode 100644 index 0000000000..e2debcab60 --- /dev/null +++ b/tests/sksl/runtime/golden/SampleWithVariableMatrix.skvm @@ -0,0 +1,35 @@ +11 registers, 33 instructions: +0 r0 = splat 3 (4.2038954e-45) +1 r1 = uniform32 arg(0) C +2 r2 = splat 3F800000 (1) +3 r3 = uniform32 arg(0) 0 +4 r4 = splat 0 (0) +5 r5 = mul_f32 r4 r3 +6 r6 = splat 2 (2.8025969e-45) +7 r7 = splat 1 (1.4012985e-45) +loop: +8 r8 = index +9 r9 = mul_f32 r4 r8 +10 r10 = add_f32 r9 r5 +11 r10 = add_f32 r10 r2 +12 r10 = div_f32 r2 r10 +13 r9 = add_f32 r9 r3 +14 r9 = mul_f32 r9 r10 +15 r9 = trunc r9 +16 r9 = mul_i32 r9 r1 +17 r8 = add_f32 r8 r5 +18 r10 = mul_f32 r8 r10 +19 r10 = trunc r10 +20 r9 = add_i32 r10 r9 +21 r9 = shl_i32 r9 2 +22 r10 = add_i32 r9 r0 +23 r10 = gather32 arg(0) 4 r10 +24 store32 arg(4) r10 +25 r10 = add_i32 r9 r6 +26 r10 = gather32 arg(0) 4 r10 +27 store32 arg(3) r10 +28 r10 = add_i32 r9 r7 +29 r10 = gather32 arg(0) 4 r10 +30 store32 arg(2) r10 +31 r9 = gather32 arg(0) 4 r9 +32 store32 arg(1) r9