blob: d7c7ac948ff95ae1dcfc1cf43b00fdd03aaa5543 [file] [log] [blame]
Ethan Nicholas5ac13c22017-05-10 15:06:17 -04001/*
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
8#include "SkSLCompiler.h"
9
10#include "Test.h"
11
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040012static 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 Osman93ba0a42017-08-14 14:48:10 -040018 SkSL::String(src), settings);
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040019 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
31DEF_TEST(SkSLBadOffset, r) {
32 test_failure(r,
Ethan Nicholas68dd2c12018-03-01 15:05:17 -050033 "struct Bad { layout (offset = 5) int x; } bad; void main() { bad.x = 5; "
34 "sk_FragColor.r = float(bad.x); }",
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040035 "error: 1: offset of field 'x' must be a multiple of 4\n1 error\n");
36 test_failure(r,
Ethan Nicholas68dd2c12018-03-01 15:05:17 -050037 "struct Bad { int x; layout (offset = 0) int y; } bad; void main() { bad.x = 5; "
38 "sk_FragColor.r = float(bad.x); }",
Ethan Nicholas5ac13c22017-05-10 15:06:17 -040039 "error: 1: offset of field 'y' must be at least 4\n1 error\n");
40}