1 /*
2 * Copyright 2020 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/sksl/codegen/SkSLHLSLCodeGenerator.h"
9
10 #include "include/private/base/SkDebug.h"
11 #include "src/core/SkTraceEvent.h"
12 #include "src/sksl/SkSLContext.h" // IWYU pragma: keep
13 #include "src/sksl/SkSLErrorReporter.h"
14 #include "src/sksl/SkSLOutputStream.h"
15 #include "src/sksl/SkSLPosition.h"
16 #include "src/sksl/codegen/SkSLSPIRVCodeGenerator.h"
17 #include "src/sksl/codegen/SkSLSPIRVtoHLSL.h"
18 #include "src/sksl/ir/SkSLProgram.h"
19
20 #include <cstdint>
21 #include <memory>
22 #include <type_traits>
23
24 namespace SkSL {
25
ToHLSL(Program & program,const ShaderCaps * caps,OutputStream & out)26 bool ToHLSL(Program& program, const ShaderCaps* caps, OutputStream& out) {
27 TRACE_EVENT0("skia.shaders", "SkSL::ToHLSL");
28 std::string hlsl;
29 if (!ToHLSL(program, caps, &hlsl)) {
30 return false;
31 }
32 out.writeString(hlsl);
33 return true;
34 }
35
ToHLSL(Program & program,const ShaderCaps * caps,std::string * out)36 bool ToHLSL(Program& program, const ShaderCaps* caps, std::string* out) {
37 std::string spirv;
38 if (!ToSPIRV(program, caps, &spirv)) {
39 return false;
40 }
41 if (!SPIRVtoHLSL(spirv, out)) {
42 program.fContext->fErrors->error(Position(), "HLSL cross-compilation not enabled");
43 return false;
44 }
45 return true;
46 }
47
48 } // namespace SkSL
49