| 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/SkSLStringStream.h" |
| 17 |
#include "src/sksl/codegen/SkSLSPIRVCodeGenerator.h" |
| 18 |
#include "src/sksl/codegen/SkSLSPIRVtoHLSL.h" |
| 19 |
#include "src/sksl/ir/SkSLProgram.h" |
| 20 |
|
| 21 |
#include <cstdint> |
| 22 |
#include <memory> |
| 23 |
#include <type_traits> |
| 24 |
|
| 25 |
namespace SkSL { |
| 26 |
|
| 27 |
bool ToHLSL(Program& program, |
| 28 |
const ShaderCaps* caps, |
| 29 |
OutputStream& out, |
| 30 |
ValidateSPIRVProc validateSPIRV) { |
| 31 |
TRACE_EVENT0("skia.shaders", "SkSL::ToHLSL"); |
| 32 |
std::string hlsl; |
| 33 |
if (!ToHLSL(program, caps, &hlsl, validateSPIRV)) { |
| 34 |
return false; |
| 35 |
} |
| 36 |
out.writeString(hlsl); |
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
bool ToHLSL(Program& program, |
| 41 |
const ShaderCaps* caps, |
| 42 |
std::string* out, |
| 43 |
ValidateSPIRVProc validateSPIRV) { |
| 44 |
std::vector<uint32_t> spirv; |
| 45 |
if (!ToSPIRV(program, caps, &spirv, validateSPIRV)) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
SPIRVtoHLSL(spirv, out); |
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
} // namespace SkSL |