1*c8dee2aaSAndroid Build Coastguard Worker /* 2*c8dee2aaSAndroid Build Coastguard Worker * Copyright 2020 Google LLC 3*c8dee2aaSAndroid Build Coastguard Worker * 4*c8dee2aaSAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license that can be 5*c8dee2aaSAndroid Build Coastguard Worker * found in the LICENSE file. 6*c8dee2aaSAndroid Build Coastguard Worker */ 7*c8dee2aaSAndroid Build Coastguard Worker 8*c8dee2aaSAndroid Build Coastguard Worker #include "src/sksl/codegen/SkSLSPIRVtoHLSL.h" 9*c8dee2aaSAndroid Build Coastguard Worker 10*c8dee2aaSAndroid Build Coastguard Worker #include <spirv_hlsl.hpp> 11*c8dee2aaSAndroid Build Coastguard Worker 12*c8dee2aaSAndroid Build Coastguard Worker /* 13*c8dee2aaSAndroid Build Coastguard Worker * This translation unit serves as a bridge between Skia/SkSL and SPIRV-Cross. 14*c8dee2aaSAndroid Build Coastguard Worker * Each library is built with a separate copy of spirv.h (or spirv.hpp), so we 15*c8dee2aaSAndroid Build Coastguard Worker * avoid conflicts by never including both in the same cpp. 16*c8dee2aaSAndroid Build Coastguard Worker */ 17*c8dee2aaSAndroid Build Coastguard Worker 18*c8dee2aaSAndroid Build Coastguard Worker namespace SkSL { 19*c8dee2aaSAndroid Build Coastguard Worker SPIRVtoHLSL(const std::string & spirv,std::string * hlsl)20*c8dee2aaSAndroid Build Coastguard Workervoid SPIRVtoHLSL(const std::string& spirv, std::string* hlsl) { 21*c8dee2aaSAndroid Build Coastguard Worker spirv_cross::CompilerHLSL hlslCompiler((const uint32_t*)spirv.c_str(), 22*c8dee2aaSAndroid Build Coastguard Worker spirv.size() / sizeof(uint32_t)); 23*c8dee2aaSAndroid Build Coastguard Worker 24*c8dee2aaSAndroid Build Coastguard Worker spirv_cross::CompilerGLSL::Options optionsGLSL; 25*c8dee2aaSAndroid Build Coastguard Worker // Force all uninitialized variables to be 0, otherwise they will fail to compile 26*c8dee2aaSAndroid Build Coastguard Worker // by FXC. 27*c8dee2aaSAndroid Build Coastguard Worker optionsGLSL.force_zero_initialized_variables = true; 28*c8dee2aaSAndroid Build Coastguard Worker 29*c8dee2aaSAndroid Build Coastguard Worker spirv_cross::CompilerHLSL::Options optionsHLSL; 30*c8dee2aaSAndroid Build Coastguard Worker optionsHLSL.shader_model = 51; 31*c8dee2aaSAndroid Build Coastguard Worker // PointCoord and PointSize are not supported in HLSL 32*c8dee2aaSAndroid Build Coastguard Worker optionsHLSL.point_coord_compat = true; 33*c8dee2aaSAndroid Build Coastguard Worker optionsHLSL.point_size_compat = true; 34*c8dee2aaSAndroid Build Coastguard Worker 35*c8dee2aaSAndroid Build Coastguard Worker hlslCompiler.set_common_options(optionsGLSL); 36*c8dee2aaSAndroid Build Coastguard Worker hlslCompiler.set_hlsl_options(optionsHLSL); 37*c8dee2aaSAndroid Build Coastguard Worker hlsl->assign(hlslCompiler.compile()); 38*c8dee2aaSAndroid Build Coastguard Worker } 39*c8dee2aaSAndroid Build Coastguard Worker 40*c8dee2aaSAndroid Build Coastguard Worker } // namespace SkSL 41