Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/sksl/SkSLCompiler.h" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 11 | |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 12 | static void test_failure(skiatest::Reporter* r, const char* src, const char* error) { |
| 13 | SkSL::Compiler compiler; |
| 14 | SkSL::Program::Settings settings; |
| 15 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); |
| 16 | settings.fCaps = caps.get(); |
| 17 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind, |
Brian Osman | 93ba0a4 | 2017-08-14 14:48:10 -0400 | [diff] [blame] | 18 | SkSL::String(src), settings); |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 19 | if (program) { |
| 20 | SkSL::String ignored; |
| 21 | compiler.toSPIRV(*program, &ignored); |
| 22 | } |
| 23 | SkSL::String skError(error); |
| 24 | if (compiler.errorText() != skError) { |
| 25 | SkDebugf("SKSL ERROR:\n source: %s\n expected: %s received: %s", src, error, |
| 26 | compiler.errorText().c_str()); |
| 27 | } |
| 28 | REPORTER_ASSERT(r, compiler.errorText() == skError); |
| 29 | } |
| 30 | |
| 31 | DEF_TEST(SkSLBadOffset, r) { |
| 32 | test_failure(r, |
Ethan Nicholas | 68dd2c1 | 2018-03-01 15:05:17 -0500 | [diff] [blame] | 33 | "struct Bad { layout (offset = 5) int x; } bad; void main() { bad.x = 5; " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 34 | "sk_FragColor.r = half(bad.x); }", |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 35 | "error: 1: offset of field 'x' must be a multiple of 4\n1 error\n"); |
| 36 | test_failure(r, |
Ethan Nicholas | 68dd2c1 | 2018-03-01 15:05:17 -0500 | [diff] [blame] | 37 | "struct Bad { int x; layout (offset = 0) int y; } bad; void main() { bad.x = 5; " |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame] | 38 | "sk_FragColor.r = half(bad.x); }", |
Ethan Nicholas | 5ac13c2 | 2017-05-10 15:06:17 -0400 | [diff] [blame] | 39 | "error: 1: offset of field 'y' must be at least 4\n1 error\n"); |
| 40 | } |