summaryrefslogtreecommitdiffstats
path: root/gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp')
-rw-r--r--gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp b/gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp
new file mode 100644
index 0000000000..98bb969c5b
--- /dev/null
+++ b/gfx/skia/skia/src/sksl/codegen/SkSLSPIRVtoHLSL.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2020 Google LLC
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/sksl/codegen/SkSLSPIRVtoHLSL.h"
+
+#if defined(SK_ENABLE_SPIRV_CROSS)
+
+#include <spirv_hlsl.hpp>
+
+/*
+ * This translation unit serves as a bridge between Skia/SkSL and SPIRV-Cross.
+ * Each library is built with a separate copy of spirv.h (or spirv.hpp), so we
+ * avoid conflicts by never including both in the same cpp.
+ */
+
+namespace SkSL {
+
+bool SPIRVtoHLSL(const std::string& spirv, std::string* hlsl) {
+ spirv_cross::CompilerHLSL hlslCompiler((const uint32_t*)spirv.c_str(),
+ spirv.size() / sizeof(uint32_t));
+
+ spirv_cross::CompilerGLSL::Options optionsGLSL;
+ // Force all uninitialized variables to be 0, otherwise they will fail to compile
+ // by FXC.
+ optionsGLSL.force_zero_initialized_variables = true;
+
+ spirv_cross::CompilerHLSL::Options optionsHLSL;
+ optionsHLSL.shader_model = 51;
+ // PointCoord and PointSize are not supported in HLSL
+ optionsHLSL.point_coord_compat = true;
+ optionsHLSL.point_size_compat = true;
+
+ hlslCompiler.set_common_options(optionsGLSL);
+ hlslCompiler.set_hlsl_options(optionsHLSL);
+ hlsl->assign(hlslCompiler.compile());
+ return true;
+}
+
+}
+
+#else
+
+namespace SkSL { bool SPIRVtoHLSL(const std::string&, std::string*) { return false; } }
+
+#endif