• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/gpu/GrShaderCaps.h"
9 #include "src/sksl/SkSLCompiler.h"
10 
11 #include "fuzz/Fuzz.h"
12 
FuzzSKSL2SPIRV(sk_sp<SkData> bytes)13 bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes) {
14     SkSL::Compiler compiler;
15     SkSL::String output;
16     SkSL::Program::Settings settings;
17     sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
18     settings.fCaps = caps.get();
19     std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
20                                                     SkSL::Program::kFragment_Kind,
21                                                     SkSL::String((const char*) bytes->data(),
22                                                                  bytes->size()),
23                                                     settings);
24     if (!program || !compiler.toSPIRV(*program, &output)) {
25         return false;
26     }
27     return true;
28 }
29 
30 #if defined(IS_FUZZING_WITH_LIBFUZZER)
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32     auto bytes = SkData::MakeWithoutCopy(data, size);
33     FuzzSKSL2SPIRV(bytes);
34     return 0;
35 }
36 #endif
37