Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PipelineUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
9
15
16#include <memory>
17#include <string>
18
19namespace skgpu {
20
22 bool (*toBackend)(SkSL::Program&, const SkSL::ShaderCaps*, std::string*),
23 const char* backendLabel,
24 const std::string& sksl,
25 SkSL::ProgramKind programKind,
26 const SkSL::ProgramSettings& settings,
27 std::string* output,
28 SkSL::ProgramInterface* outInterface,
29 ShaderErrorHandler* errorHandler) {
30#ifdef SK_DEBUG
31 std::string src = SkShaderUtils::PrettyPrint(sksl);
32#else
33 const std::string& src = sksl;
34#endif
36 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(programKind, src, settings);
37 if (!program || !(*toBackend)(*program, caps, output)) {
38 errorHandler->compileError(src.c_str(),
39 compiler.errorText().c_str(),
40 /*shaderWasCached=*/false);
41 return false;
42 }
43
44#if defined(SK_PRINT_SKSL_SHADERS)
45 const bool kPrintSkSL = true;
46#else
47 const bool kPrintSkSL = false;
48#endif
49 const bool kSkSLPostCompilation = false;
50#if defined(SK_PRINT_NATIVE_SHADERS)
51 const bool printBackendSL = (backendLabel != nullptr);
52#else
53 const bool printBackendSL = false;
54#endif
55
56 if (kPrintSkSL || kSkSLPostCompilation || printBackendSL) {
58 if (kPrintSkSL) {
59 SkDebugf("SkSL:\n");
61 }
62 if (kSkSLPostCompilation) {
63 SkDebugf("SkSL (post-compilation):\n");
65 }
66 if (printBackendSL) {
67 SkDebugf("%s:\n", backendLabel);
69 }
70 }
71
72 if (outInterface) {
73 *outInterface = program->fInterface;
74 }
75 return true;
76}
77
78} // namespace skgpu
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
virtual void compileError(const char *shader, const char *errors)
std::string PrettyPrint(const std::string &string)
void PrintShaderBanner(SkSL::ProgramKind programKind)
void PrintLineByLine(const std::string &text)
bool SkSLToBackend(const SkSL::ShaderCaps *caps, bool(*toBackend)(SkSL::Program &, const SkSL::ShaderCaps *, std::string *), const char *backendLabel, const std::string &sksl, SkSL::ProgramKind programKind, const SkSL::ProgramSettings &settings, std::string *output, SkSL::ProgramInterface *outInterface, ShaderErrorHandler *errorHandler)