From 2c373f210c4b20ebbf8fa2bf964ec43964ed1bbf Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:36:49 +0300 Subject: [PATCH] Fix predicate implementations. --- ShaderRecomp/shader_recompiler.cpp | 50 ++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/ShaderRecomp/shader_recompiler.cpp b/ShaderRecomp/shader_recompiler.cpp index b176723..ed8d91b 100644 --- a/ShaderRecomp/shader_recompiler.cpp +++ b/ShaderRecomp/shader_recompiler.cpp @@ -124,6 +124,16 @@ void ShaderRecompiler::printDstSwizzle01(uint32_t dstRegister, uint32_t dstSwizz void ShaderRecompiler::recompile(const VertexFetchInstruction& instr, uint32_t address) { + if (instr.isPredicated) + { + indent(); + println("if ({}p0)", instr.predicateCondition ? "" : "!"); + + indent(); + out += "{\n"; + ++indentation; + } + indent(); print("r{}.", instr.dstRegister); printDstSwizzle(instr.dstSwizzle, false); @@ -167,6 +177,13 @@ void ShaderRecompiler::recompile(const VertexFetchInstruction& instr, uint32_t a out += ";\n"; printDstSwizzle01(instr.dstRegister, instr.dstSwizzle); + + if (instr.isPredicated) + { + --indentation; + indent(); + out += "}\n"; + } } void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) @@ -174,6 +191,16 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) if (instr.opcode != FetchOpcode::TextureFetch) return; + if (instr.isPredicated) + { + indent(); + println("if ({}p0)", instr.predCondition ? "" : "!"); + + indent(); + out += "{\n"; + ++indentation; + } + indent(); print("r{}.", instr.dstRegister); printDstSwizzle(instr.dstSwizzle, false); @@ -219,6 +246,13 @@ void ShaderRecompiler::recompile(const TextureFetchInstruction& instr) out += ";\n"; printDstSwizzle01(instr.dstRegister, instr.dstSwizzle); + + if (instr.isPredicated) + { + --indentation; + indent(); + out += "}\n"; + } } void ShaderRecompiler::recompile(const AluInstruction& instr) @@ -226,7 +260,7 @@ void ShaderRecompiler::recompile(const AluInstruction& instr) if (instr.isPredicated) { indent(); - println("if ({}p0)", instr.predicateCondition ? "!" : ""); + println("if ({}p0)", instr.predicateCondition ? "" : "!"); indent(); out += "{\n"; @@ -815,6 +849,18 @@ void ShaderRecompiler::recompile(const AluInstruction& instr) out += ')'; out += ";\n"; + + switch (instr.scalarOpcode) + { + case AluScalarOpcode::MaxAs: + indent(); + println("a0 = (int)clamp(floor({} + 0.5), -256.0, 255.0);", op(SCALAR_0)); + break; + case AluScalarOpcode::MaxAsf: + indent(); + println("a0 = (int)clamp(floor({}), -256.0, 255.0);", op(SCALAR_0)); + break; + } } uint32_t scalarWriteMask = instr.scalarWriteMask; @@ -1219,7 +1265,7 @@ void ShaderRecompiler::recompile(const uint8_t* shaderData) { if (cfInstr.condJmp.isPredicated) { - println("\t\t\tif ({}p0)", cfInstr.condJmp.condition ? "!" : ""); + println("\t\t\tif ({}p0)", cfInstr.condJmp.condition ? "" : "!"); } else {