Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Brian Osman | ee426f2 | 2020-01-02 11:55:24 -0500 | [diff] [blame] | 8 | #include "include/effects/SkRuntimeEffect.h" |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 9 | #include "tests/Test.h" |
| 10 | |
Brian Osman | 82d4970 | 2019-12-30 13:44:01 -0500 | [diff] [blame] | 11 | DEF_TEST(SkRuntimeEffectInvalidInputs, r) { |
| 12 | auto test = [r](const char* hdr, const char* expected) { |
| 13 | SkString src = SkStringPrintf("%s void main(float x, float y, inout half4 color) {}", hdr); |
| 14 | auto [effect, errorText] = SkRuntimeEffect::Make(src); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 15 | REPORTER_ASSERT(r, !effect); |
| 16 | REPORTER_ASSERT(r, errorText.contains(expected), |
| 17 | "Expected error message to contain \"%s\". Actual message: \"%s\"", |
| 18 | expected, errorText.c_str()); |
| 19 | }; |
| 20 | |
| 21 | // Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked). |
| 22 | // Ensure that these fail, and the error messages contain the relevant keyword. |
Brian Osman | 82d4970 | 2019-12-30 13:44:01 -0500 | [diff] [blame] | 23 | test("layout(key) in bool Input;", "key"); |
| 24 | test("in uniform float Input;", "in uniform"); |
| 25 | test("layout(ctype=SkRect) float4 Input;", "ctype"); |
| 26 | test("in bool Flag; layout(when=Flag) uniform float Input;", "when"); |
| 27 | test("layout(tracked) uniform float Input;", "tracked"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 28 | |
Brian Osman | 82d4970 | 2019-12-30 13:44:01 -0500 | [diff] [blame] | 29 | // Runtime SkSL supports a limited set of uniform types. No samplers, for example: |
| 30 | test("uniform sampler2D s;", "sampler2D"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 31 | |
Brian Osman | 82d4970 | 2019-12-30 13:44:01 -0500 | [diff] [blame] | 32 | // 'in' variables can't be arrays |
| 33 | test("in int Input[2];", "array"); |
Brian Osman | 8783b78 | 2020-01-06 11:13:45 -0500 | [diff] [blame] | 34 | |
| 35 | // Type specific restrictions: |
| 36 | |
| 37 | // 'bool', 'int' can't be 'uniform' |
| 38 | test("uniform bool Input;", "'uniform'"); |
| 39 | test("uniform int Input;", "'uniform'"); |
| 40 | |
| 41 | // vector and matrix types can't be 'in' |
| 42 | test("in float2 Input;", "'in'"); |
| 43 | test("in half3x3 Input;", "'in'"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 44 | } |