Debian Codegraph @

fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp

raw
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/ganesh/GrShaderCaps.h"
9 #include "src/sksl/SkSLCompiler.h"
10 #include "src/sksl/SkSLProgramKind.h"
11 #include "src/sksl/SkSLProgramSettings.h"
12 #include "src/sksl/codegen/SkSLNativeShader.h"
13 #include "src/sksl/codegen/SkSLSPIRVCodeGenerator.h"
14 #include "src/sksl/ir/SkSLProgram.h"
15
16 #include "fuzz/Fuzz.h"
17
18 bool FuzzSKSL2SPIRV(const uint8_t *data, size_t size) {
19 SkSL::Compiler compiler;
20 SkSL::ProgramSettings settings;
21
22 // This tells the compiler where the rt-flip uniform will live should it be required. For
23 // fuzzing purposes we don't care where that is, but the compiler will report an error if we
24 // leave them at their default invalid values, or if the offset overlaps another uniform.
25 settings.fRTFlipOffset = 16384;
26 settings.fRTFlipSet = 0;
27 settings.fRTFlipBinding = 0;
28
29 std::unique_ptr<SkSL::Program> program =
30 compiler.convertProgram(SkSL::ProgramKind::kFragment,
31 std::string(reinterpret_cast<const char*>(data), size),
32 settings);
33 SkSL::NativeShader output;
34 if (!program || !SkSL::ToSPIRV(*program, SkSL::ShaderCapsFactory::Default(), &output)) {
35 return false;
36 }
37 return true;
38 }
39
40 #if defined(SK_BUILD_FOR_LIBFUZZER)
41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42 if (size > 3000) {
43 return 0;
44 }
45 FuzzSKSL2SPIRV(data, size);
46 return 0;
47 }
48 #endif