From 4d217907665180537ea217f9f2213c9d53a22b99 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:57:44 -0800 Subject: Fix incorrect behavior of operator% (#3470) * Fix incorrect behavior of operator% Fixes #1059. This change fixes the incorrect translation of "operator%" from HLSL to SPIRV. The issue stems from the fact that the behavior of "operator%" in GLSL differs from that in HLSL. In HLSL it behaves as "remainder" where as it behaves as "modulus" in GLSL. We have been using SpvOpFMod for operator% when Slang compiles from HLSL to SPRIV, which is incorrect. This change switches it to SpvOpFRem. The tests are slightly modified to reveal any potential issues. * Change output type of test/compute/frem For testing the operator%, we are using "int" as the output type of the test, "test/compute/frem.slang". Since the operands are in float type, it is more preferable to have a float type as the resulting type. This can be done with an option, "-output-using-type". --------- Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index a600d4b10..46ce1d0b5 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -4398,7 +4398,7 @@ struct SPIRVEmitContext opCode = isSigned ? SpvOpSRem : SpvOpUMod; break; case kIROp_FRem: - opCode = SpvOpFMod; + opCode = SpvOpFRem; break; case kIROp_Less: opCode = isFloatingPoint ? SpvOpFOrdLessThan -- cgit v1.2.3