From 70cb9e2eafe33b3bfc7ef31affd01b6b6b3f637b Mon Sep 17 00:00:00 2001 From: SamG-Coder <13449963+SamG-Coder@users.noreply.github.com> Date: Tue, 29 Sep 2026 22:34:21 +1000 Subject: [PATCH] feat(shader): translate signed and unsigned 24-bit high products --- .../RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp | 2 ++ core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp | 2 ++ .../recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp | 2 ++ .../Translation/include/Translation/TranslationContext.hpp | 2 +- .../recompiler/Translation/src/IntegerInstructions.cpp | 5 +++-- .../shader/recompiler/Translation/src/VectorInstructions.cpp | 4 ++++ 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index 5766be453..5baa97363 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -591,6 +591,8 @@ enum class RdnaOpcode : std::uint16_t { SClause, SCbranchCdbg, Exp, + VMulHiI32I24, + VMulHiU32U24, Count }; diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp index 6b42b406c..bcc1c9f2b 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp @@ -232,6 +232,8 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) { case RdnaOpcode::VFmaakF16: case RdnaOpcode::VMulI32I24: case RdnaOpcode::VMulU32U24: + case RdnaOpcode::VMulHiI32I24: + case RdnaOpcode::VMulHiU32U24: case RdnaOpcode::VMulLoI32: case RdnaOpcode::VMulHiI32: case RdnaOpcode::VCvtPkrtzF16F32: diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index 029d6a3cf..7cb36a945 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -53,7 +53,9 @@ constexpr Vop2OpcodeInfo vop2Opcodes[] = { {0x05u, RdnaOpcode::VSubrevF32}, {0x08u, RdnaOpcode::VMulF32, Vop2SdwaProfile::Float32}, {0x09u, RdnaOpcode::VMulI32I24, Vop2SdwaProfile::IntegerFullDestination}, + {0x0au, RdnaOpcode::VMulHiI32I24, Vop2SdwaProfile::IntegerFullDestination}, {0x0bu, RdnaOpcode::VMulU32U24, Vop2SdwaProfile::IntegerFullDestination}, + {0x0cu, RdnaOpcode::VMulHiU32U24, Vop2SdwaProfile::IntegerFullDestination}, {0x0fu, RdnaOpcode::VMinF32}, {0x10u, RdnaOpcode::VMaxF32}, {0x11u, RdnaOpcode::VMinI32}, diff --git a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp index 73e1d092e..b122c2c9b 100644 --- a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp +++ b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp @@ -167,7 +167,7 @@ private: bool sFf1I32B64(const RdnaInstruction& inst); bool vFfbh32(const RdnaInstruction& inst, bool sign); bool sFlbitI32B64(const RdnaInstruction& inst); - bool integer24(const RdnaInstruction& inst, bool sign, bool addend); + bool integer24(const RdnaInstruction& inst, bool sign, bool addend, bool high = false); bool vMadU64U32(const RdnaInstruction& inst); bool vSadU32(const RdnaInstruction& inst); bool vAdd3U32(const RdnaInstruction& inst); diff --git a/core/shader/recompiler/Translation/src/IntegerInstructions.cpp b/core/shader/recompiler/Translation/src/IntegerInstructions.cpp index 3bda0cbaf..9dad85bc5 100644 --- a/core/shader/recompiler/Translation/src/IntegerInstructions.cpp +++ b/core/shader/recompiler/Translation/src/IntegerInstructions.cpp @@ -252,13 +252,14 @@ bool TranslationContext::sFlbitI32B64(const RdnaInstruction& inst) { return true; } -bool TranslationContext::integer24(const RdnaInstruction& inst, bool sign, bool addend) { +bool TranslationContext::integer24(const RdnaInstruction& inst, bool sign, bool addend, bool high) { const IrOpcode extractOpcode = sign ? IrOpcode::BitFieldSExtract : IrOpcode::BitFieldUExtract; const IrU32 lhsSource = readU32(sourceAt(inst, 0u)); const IrU32 rhsSource = readU32(sourceAt(inst, 1u)); const IrU32 lhs(ir.Emit(extractOpcode, IrType::U32, {&lhsSource.Value(), &ir.Constant(0u), &ir.Constant(24u)})); const IrU32 rhs(ir.Emit(extractOpcode, IrType::U32, {&rhsSource.Value(), &ir.Constant(0u), &ir.Constant(24u)})); - IrU32 result(ir.IMul(lhs.Value(), rhs.Value())); + const IrOpcode multiplyOpcode = high ? (sign ? IrOpcode::SMulHi : IrOpcode::UMulHi) : IrOpcode::IMul32; + IrU32 result(ir.Emit(multiplyOpcode, IrType::U32, {&lhs.Value(), &rhs.Value()})); if (addend) { result = IrU32(ir.IAdd(result.Value(), readU32(sourceAt(inst, 2u)).Value())); } diff --git a/core/shader/recompiler/Translation/src/VectorInstructions.cpp b/core/shader/recompiler/Translation/src/VectorInstructions.cpp index 5fee4be62..4876e9c72 100644 --- a/core/shader/recompiler/Translation/src/VectorInstructions.cpp +++ b/core/shader/recompiler/Translation/src/VectorInstructions.cpp @@ -671,6 +671,10 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) { return integer24(inst, true, false); case RdnaOpcode::VMulU32U24: return integer24(inst, false, false); + case RdnaOpcode::VMulHiI32I24: + return integer24(inst, true, false, true); + case RdnaOpcode::VMulHiU32U24: + return integer24(inst, false, false, true); case RdnaOpcode::VMadI32I24: return integer24(inst, true, true); case RdnaOpcode::VMadU32U24: