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