Brian Osman | c024391 | 2020-02-19 15:35:26 -0500 | [diff] [blame] | 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 | |
John Stiles | 3738ef5 | 2021-04-13 10:41:57 -0400 | [diff] [blame] | 8 | #include "src/sksl/codegen/SkSLSPIRVtoHLSL.h" |
Brian Osman | c024391 | 2020-02-19 15:35:26 -0500 | [diff] [blame] | 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 | |
| 20 | namespace SkSL { |
| 21 | |
| 22 | bool SPIRVtoHLSL(const String& spirv, String* hlsl) { |
| 23 | spirv_cross::CompilerHLSL hlslCompiler((const uint32_t*)spirv.c_str(), |
| 24 | spirv.size() / sizeof(uint32_t)); |
Greg Daniel | 5fc5c81 | 2020-04-23 10:30:23 -0400 | [diff] [blame] | 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); |
Brian Osman | c024391 | 2020-02-19 15:35:26 -0500 | [diff] [blame] | 39 | hlsl->assign(hlslCompiler.compile()); |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | |
| 45 | #else |
| 46 | |
| 47 | namespace SkSL { bool SPIRVtoHLSL(const String&, String*) { return false; } } |
| 48 | |
| 49 | #endif |