Debian Codegraph @

src/sksl/codegen/SkSLSPIRVtoHLSL.cpp

raw
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/SkSLSPIRVtoHLSL.h"
9
10 #include <spirv_hlsl.hpp>
11
12 /*
13 * This translation unit serves as a bridge between Skia/SkSL and SPIRV-Cross.
14 * Each library is built with a separate copy of spirv.h (or spirv.hpp), so we
15 * avoid conflicts by never including both in the same cpp.
16 */
17
18 namespace SkSL {
19
20 void SPIRVtoHLSL(SkSpan<const uint32_t> spirv, std::string* hlsl) {
21 spirv_cross::CompilerHLSL hlslCompiler(spirv.data(), spirv.size());
22
23 spirv_cross::CompilerGLSL::Options optionsGLSL;
24 // Force all uninitialized variables to be 0, otherwise they will fail to compile
25 // by FXC.
26 optionsGLSL.force_zero_initialized_variables = true;
27
28 spirv_cross::CompilerHLSL::Options optionsHLSL;
29 optionsHLSL.shader_model = 51;
30 // PointCoord and PointSize are not supported in HLSL
31 optionsHLSL.point_coord_compat = true;
32 optionsHLSL.point_size_compat = true;
33
34 hlslCompiler.set_common_options(optionsGLSL);
35 hlslCompiler.set_hlsl_options(optionsHLSL);
36 hlsl->assign(hlslCompiler.compile());
37 }
38
39 } // namespace SkSL