Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLSPIRVtoHLSL.cpp
Go to the documentation of this file.
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
9
10#if defined(SK_ENABLE_SPIRV_CROSS)
11
12#include <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 std::string& spirv, std::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 std::string&, std::string*) { return false; } }
48
49#endif
bool SPIRVtoHLSL(const std::string &, std::string *)