From e33db57f942d025a7d342208617722537b585d57 Mon Sep 17 00:00:00 2001 From: Crementif <26669564+Crementif@users.noreply.github.com> Date: Thu, 17 Sep 2026 20:03:23 +0200 Subject: [PATCH] Latte: Use the Wii U overflow value for MOVA The Wii U returns -256 when MOVA goes out of range. Cemu clamped large positive values to 255 instead. --- .../Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp | 4 ++-- .../Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp index f7af1e4f..c3ed719d 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitGLSL.cpp @@ -1084,7 +1084,7 @@ void _emitALUOP2InstructionCode(LatteDecompilerShaderContext* shaderContext, Lat _emitOperandInputCode(shaderContext, aluInstruction, 0, LATTE_DECOMPILER_DTYPE_FLOAT); src->add(";" _CRLF); src->add("tempResultf = floor(tempResultf);" _CRLF); - src->add("tempResultf = clamp(tempResultf, -256.0, 255.0);" _CRLF); + src->add("tempResultf = (tempResultf >= -256.0 && tempResultf <= 255.0) ? tempResultf : -256.0;" _CRLF); // set AR if( aluInstruction->destElem == 0 ) src->add("ARi.x = int(tempResultf);" _CRLF); @@ -1109,7 +1109,7 @@ void _emitALUOP2InstructionCode(LatteDecompilerShaderContext* shaderContext, Lat src->add("tempResulti = "); _emitOperandInputCode(shaderContext, aluInstruction, 0, LATTE_DECOMPILER_DTYPE_SIGNED_INT); src->add(";" _CRLF); - src->add("tempResulti = clamp(tempResulti, -256, 255);" _CRLF); + src->add("tempResulti = (tempResulti >= -256 && tempResulti <= 255) ? tempResulti : -256;" _CRLF); // set AR if( aluInstruction->destElem == 0 ) src->add("ARi.x = tempResulti;" _CRLF); diff --git a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp index e265ebd1..9cc15641 100644 --- a/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp +++ b/src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompilerEmitMSL.cpp @@ -1018,7 +1018,7 @@ static void _emitALUOP2InstructionCode(LatteDecompilerShaderContext* shaderConte _emitOperandInputCode(shaderContext, aluInstruction, 0, LATTE_DECOMPILER_DTYPE_FLOAT); src->add(";" _CRLF); src->add("tempResultf = floor(tempResultf);" _CRLF); - src->add("tempResultf = clamp(tempResultf, -256.0, 255.0);" _CRLF); + src->add("tempResultf = (tempResultf >= -256.0 && tempResultf <= 255.0) ? tempResultf : -256.0;" _CRLF); // set AR if( aluInstruction->destElem == 0 ) src->add("ARi.x = int(tempResultf);" _CRLF); @@ -1043,7 +1043,7 @@ static void _emitALUOP2InstructionCode(LatteDecompilerShaderContext* shaderConte src->add("tempResulti = "); _emitOperandInputCode(shaderContext, aluInstruction, 0, LATTE_DECOMPILER_DTYPE_SIGNED_INT); src->add(";" _CRLF); - src->add("tempResulti = clamp(tempResulti, -256, 255);" _CRLF); + src->add("tempResulti = (tempResulti >= -256 && tempResulti <= 255) ? tempResulti : -256;" _CRLF); // set AR if( aluInstruction->destElem == 0 ) src->add("ARi.x = tempResulti;" _CRLF);