From 1a48d7d4fcacd26642f6508690791b213d2365b9 Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Thu, 18 Aug 2016 12:54:22 +0200 Subject: [PATCH] Output code for OpFMod in HLSL when required --- spirv_hlsl.cpp | 22 +++++++++++++++++++--- spirv_hlsl.hpp | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 6ce45f5c..eec00290 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -138,7 +138,10 @@ void CompilerHLSL::emit_header() for (auto &header : header_lines) statement(header); - statement(""); + if (header_lines.size() > 0) + { + statement(""); + } } void CompilerHLSL::emit_interface_block_globally(const SPIRVariable &var) @@ -295,7 +298,6 @@ void CompilerHLSL::emit_resources() for (auto var : variables) { emit_interface_block_in_struct(*var, binding_number); - emitted = true; } end_scope_decl(); statement(""); @@ -329,7 +331,6 @@ void CompilerHLSL::emit_resources() for (auto var : variables) { emit_interface_block_in_struct(*var, binding_number); - emitted = true; } end_scope_decl(); statement(""); @@ -348,6 +349,15 @@ void CompilerHLSL::emit_resources() if (emitted) statement(""); + + if (requires_op_fmod) + { + statement("float mod(float x, float y)"); + begin_scope(); + statement("return x - y * floor(x / y);"); + end_scope(); + statement(""); + } } void CompilerHLSL::emit_function_prototype(SPIRFunction &func, uint64_t return_flags) @@ -845,6 +855,12 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction) emit_binary_func_op_transpose_all(ops[0], ops[1], ops[2], ops[3], "mul"); break; } + case OpFMod: + { + requires_op_fmod = true; + CompilerGLSL::emit_instruction(instruction); + break; + } default: CompilerGLSL::emit_instruction(instruction); break; diff --git a/spirv_hlsl.hpp b/spirv_hlsl.hpp index 4dad7c58..afda5f88 100644 --- a/spirv_hlsl.hpp +++ b/spirv_hlsl.hpp @@ -67,6 +67,7 @@ private: void emit_glsl_op(uint32_t result_type, uint32_t result_id, uint32_t op, const uint32_t *args, uint32_t count) override; Options options; + bool requires_op_fmod = false; }; }