blob: 70eac064e40237c3cf4f280c6de30b340f669fc5 [file] [log] [blame]
/*
* Copyright 2023 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/graphite/PipelineUtils.h"
namespace skgpu::graphite {
bool SkSLToSPIRV(SkSL::Compiler* compiler,
const std::string& sksl,
SkSL::ProgramKind programKind,
const SkSL::ProgramSettings& settings,
std::string* spirv,
SkSL::Program::Interface* outInterface,
ShaderErrorHandler* errorHandler) {
#ifdef SK_DEBUG
std::string src = SkShaderUtils::PrettyPrint(sksl);
#else
const std::string& src = sksl;
#endif
std::unique_ptr<SkSL::Program> program = compiler->convertProgram(programKind,
src,
settings);
if (!program || !compiler->toSPIRV(*program, spirv)) {
errorHandler->compileError(src.c_str(), compiler->errorText().c_str());
return false;
}
if (gPrintSKSL) {
SkShaderUtils::PrintShaderBanner(programKind);
SkDebugf("SKSL:\n");
SkShaderUtils::PrintLineByLine(SkShaderUtils::PrettyPrint(sksl));
}
*outInterface = program->fInterface;
return true;
}
} // namespace skgpu::graphite