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 SPIRVtoHLSL(const std::string & spirv,std::string * hlsl)20void SPIRVtoHLSL(const std::string& spirv, std::string* hlsl) { 21 spirv_cross::CompilerHLSL hlslCompiler((const uint32_t*)spirv.c_str(), 22 spirv.size() / sizeof(uint32_t)); 23 24 spirv_cross::CompilerGLSL::Options optionsGLSL; 25 // Force all uninitialized variables to be 0, otherwise they will fail to compile 26 // by FXC. 27 optionsGLSL.force_zero_initialized_variables = true; 28 29 spirv_cross::CompilerHLSL::Options optionsHLSL; 30 optionsHLSL.shader_model = 51; 31 // PointCoord and PointSize are not supported in HLSL 32 optionsHLSL.point_coord_compat = true; 33 optionsHLSL.point_size_compat = true; 34 35 hlslCompiler.set_common_options(optionsGLSL); 36 hlslCompiler.set_hlsl_options(optionsHLSL); 37 hlsl->assign(hlslCompiler.compile()); 38 } 39 40 } // namespace SkSL 41