From 672e782990365dd49c9217a3c8c11bcace9196ec Mon Sep 17 00:00:00 2001 From: wheremyfoodat Date: Sun, 12 Mar 2023 04:47:34 +0200 Subject: [PATCH] [PICA] Implement FLR --- include/PICA/shader.hpp | 2 ++ src/core/PICA/shader_interpreter.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/PICA/shader.hpp b/include/PICA/shader.hpp index 9875bb39..2f9c4688 100644 --- a/include/PICA/shader.hpp +++ b/include/PICA/shader.hpp @@ -16,6 +16,7 @@ namespace ShaderOpcodes { DP3 = 0x01, DP4 = 0x02, MUL = 0x08, + FLR = 0x0B, MAX = 0x0C, MIN = 0x0D, RCP = 0x0E, @@ -95,6 +96,7 @@ class PICAShader { void cmp(u32 instruction); void dp3(u32 instruction); void dp4(u32 instruction); + void flr(u32 instruction); void ifc(u32 instruction); void ifu(u32 instruction); void jmpc(u32 instruction); diff --git a/src/core/PICA/shader_interpreter.cpp b/src/core/PICA/shader_interpreter.cpp index 5d72c7b8..bb5fd1d6 100644 --- a/src/core/PICA/shader_interpreter.cpp +++ b/src/core/PICA/shader_interpreter.cpp @@ -22,6 +22,7 @@ void PICAShader::run() { case ShaderOpcodes::DP3: dp3(instruction); break; case ShaderOpcodes::DP4: dp4(instruction); break; case ShaderOpcodes::END: return; // Stop running shader + case ShaderOpcodes::FLR: flr(instruction); break; case ShaderOpcodes::IFC: ifc(instruction); break; case ShaderOpcodes::IFU: ifu(instruction); break; case ShaderOpcodes::JMPC: jmpc(instruction); break; @@ -176,6 +177,24 @@ void PICAShader::mul(u32 instruction) { } } +void PICAShader::flr(u32 instruction) { + const u32 operandDescriptor = operandDescriptors[instruction & 0x7f]; + u32 src = (instruction >> 12) & 0x7f; + const u32 idx = (instruction >> 19) & 3; + const u32 dest = (instruction >> 21) & 0x1f; + + src = getIndexedSource(src, idx); + vec4f srcVector = getSourceSwizzled<1>(src, operandDescriptor); + vec4f& destVector = getDest(dest); + + u32 componentMask = operandDescriptor & 0xf; + for (int i = 0; i < 4; i++) { + if (componentMask & (1 << i)) { + destVector[3 - i] = f24::fromFloat32(std::floor(srcVector[3 - 1].toFloat32())); + } + } +} + void PICAShader::max(u32 instruction) { const u32 operandDescriptor = operandDescriptors[instruction & 0x7f]; const u32 src1 = (instruction >> 12) & 0x7f;