diff --git a/core/libs/prx/libSceAgcDriver/CMakeLists.txt b/core/libs/prx/libSceAgcDriver/CMakeLists.txt index ca0b6a3e8..38e55c2e2 100644 --- a/core/libs/prx/libSceAgcDriver/CMakeLists.txt +++ b/core/libs/prx/libSceAgcDriver/CMakeLists.txt @@ -607,6 +607,14 @@ if(BUILD_TESTING) set_tests_properties(vector_compare_i16_u16 PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() + add_test_executable(vector_min_max_med16_tests ${LIBS_INCLUDE_DIR}/tests/VectorMinMaxMed16.cpp) + target_link_libraries(vector_min_max_med16_tests PRIVATE shader_recompiler_agc_driver libc) + configure_windows_unwind(vector_min_max_med16_tests) + add_test(NAME vector_min_max_med16 COMMAND vector_min_max_med16_tests) + if(WIN32) + set_tests_properties(vector_min_max_med16 PROPERTIES ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:$") + endif() add_test_executable(guest_indexed_draw_tests ${LIBS_INCLUDE_DIR}/tests/GuestIndexedDraw.cpp) target_include_directories(guest_indexed_draw_tests PRIVATE ${LIBS_INCLUDE_DIR}) target_link_libraries(guest_indexed_draw_tests PRIVATE libSceAgc libSceAgcDriver libc) diff --git a/core/libs/tests/VectorMinMaxMed16.cpp b/core/libs/tests/VectorMinMaxMed16.cpp new file mode 100644 index 000000000..8ccd1d9cf --- /dev/null +++ b/core/libs/tests/VectorMinMaxMed16.cpp @@ -0,0 +1,29 @@ +#include "Translation/TranslationContext.hpp" +#include "RdnaDecoder/RdnaVectorOpDecoder.hpp" +#include +#include + +using namespace ShaderRecompiler; +static void Require(bool value) { if (!value) throw std::runtime_error("vector min/max/med regression"); } +static void Check(std::uint32_t encoding, RdnaOpcode opcode, IrOpcode expected) { + const std::array code{(encoding << 16u) | 1u, 1u | (2u << 9u) | (3u << 18u)}; + const RdnaInstruction instruction = DecodeRdnaVop3(0u, code, 0u); + Require(instruction.op == opcode); + Require(instruction.family == RdnaInstructionFamily::VOP3); + Require(IsVectorAluOpcode(instruction.op)); + IrProgram program; + auto& block = program.CreateBlock(); + program.SetEntryBlock(block); + TranslationContext context(program, block, 256); + context.TranslateInstruction(instruction); + bool found = false; + for (auto* value : block.Instructions()) found = found || value->Opcode() == expected; + Require(found); +} +int main() { + Check(0x352u, RdnaOpcode::VMin3I16, IrOpcode::SMinTri32); + Check(0x353u, RdnaOpcode::VMin3U16, IrOpcode::UMinTri32); + Check(0x355u, RdnaOpcode::VMax3I16, IrOpcode::SMaxTri32); + Check(0x356u, RdnaOpcode::VMax3U16, IrOpcode::UMaxTri32); + Check(0x359u, RdnaOpcode::VMed3U16, IrOpcode::UMedTri32); +} diff --git a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp index 5baa97363..52440fadb 100644 --- a/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp +++ b/core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaOpcode.hpp @@ -276,15 +276,20 @@ enum class RdnaOpcode : std::uint16_t { VMin3I32, VMin3U32, VMin3F16, + VMin3I16, + VMin3U16, VMax3F32, VMax3I32, VMax3U32, VMax3F16, + VMax3I16, + VMax3U16, VMed3F32, VMed3I32, VMed3U32, VMed3F16, VMed3I16, + VMed3U16, VAdd3U32, VLshlAddU32, VAddLshlU32, diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp index bcc1c9f2b..032c76070 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaOpcode.cpp @@ -251,15 +251,20 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) { case RdnaOpcode::VMin3I32: case RdnaOpcode::VMin3U32: case RdnaOpcode::VMin3F16: + case RdnaOpcode::VMin3I16: + case RdnaOpcode::VMin3U16: case RdnaOpcode::VMax3F32: case RdnaOpcode::VMax3I32: case RdnaOpcode::VMax3U32: case RdnaOpcode::VMax3F16: + case RdnaOpcode::VMax3I16: + case RdnaOpcode::VMax3U16: case RdnaOpcode::VMed3F32: case RdnaOpcode::VMed3I32: case RdnaOpcode::VMed3U32: case RdnaOpcode::VMed3F16: case RdnaOpcode::VMed3I16: + case RdnaOpcode::VMed3U16: case RdnaOpcode::VAdd3U32: case RdnaOpcode::VLshlAddU32: case RdnaOpcode::VAddLshlU32: diff --git a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp index 7cb36a945..a4d6ec2bc 100644 --- a/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp +++ b/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp @@ -334,15 +334,20 @@ constexpr VectorOpcodeInfo vop3Opcodes[] = { {0x152u, RdnaOpcode::VMin3I32}, {0x153u, RdnaOpcode::VMin3U32}, {0x351u, RdnaOpcode::VMin3F16}, + {0x352u, RdnaOpcode::VMin3I16}, + {0x353u, RdnaOpcode::VMin3U16}, {0x154u, RdnaOpcode::VMax3F32}, {0x155u, RdnaOpcode::VMax3I32}, {0x156u, RdnaOpcode::VMax3U32}, {0x354u, RdnaOpcode::VMax3F16}, + {0x355u, RdnaOpcode::VMax3I16}, + {0x356u, RdnaOpcode::VMax3U16}, {0x157u, RdnaOpcode::VMed3F32}, {0x158u, RdnaOpcode::VMed3I32}, {0x159u, RdnaOpcode::VMed3U32}, {0x357u, RdnaOpcode::VMed3F16}, {0x358u, RdnaOpcode::VMed3I16}, + {0x359u, RdnaOpcode::VMed3U16}, {0x15du, RdnaOpcode::VSadU32}, {0x15eu, RdnaOpcode::VCvtPkU8F32}, {0x178u, RdnaOpcode::VXor3B32}, diff --git a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp index a043535dd..f9b643bf7 100644 --- a/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp +++ b/core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp @@ -153,6 +153,7 @@ private: bool floatCube(const RdnaInstruction& inst, std::uint32_t resultKind); bool integer16Shift(const RdnaInstruction& inst, IrOpcode opcode, bool arithmetic); bool integer16Binary(const RdnaInstruction& inst, IrOpcode opcode, bool sign); + bool integer16Ternary(const RdnaInstruction& inst, IrOpcode opcode, bool sign); bool vMed3I16(const RdnaInstruction& inst); bool packedInteger16Shift(const RdnaInstruction& inst, IrOpcode opcode, bool arithmetic); bool packedInteger16Binary(const RdnaInstruction& inst, IrOpcode opcode); diff --git a/core/shader/recompiler/Translation/src/IntegerInstructions.cpp b/core/shader/recompiler/Translation/src/IntegerInstructions.cpp index 9dad85bc5..cccf494d0 100644 --- a/core/shader/recompiler/Translation/src/IntegerInstructions.cpp +++ b/core/shader/recompiler/Translation/src/IntegerInstructions.cpp @@ -34,6 +34,15 @@ bool TranslationContext::vMed3I16(const RdnaInstruction& inst) { return true; } +bool TranslationContext::integer16Ternary(const RdnaInstruction& inst, IrOpcode opcode, bool sign) { + const IrU32 first = readU16AsU32(sourceAt(inst, 0u), sign); + const IrU32 second = readU16AsU32(sourceAt(inst, 1u), sign); + const IrU32 third = readU16AsU32(sourceAt(inst, 2u), sign); + const IrU32 result(ir.Emit(opcode, IrType::U32, {&first.Value(), &second.Value(), &third.Value()})); + write16Bits(inst.destination, IrU32(ir.BitwiseAnd(result.Value(), ir.Constant(0xffffu)))); + return true; +} + bool TranslationContext::packedInteger16Shift(const RdnaInstruction& inst, IrOpcode opcode, bool arithmetic) { const auto translateLane = [&](bool highLane) { const IrU32 count(ir.BitwiseAnd(readU16LaneAsU32(sourceAt(inst, 0u), highLane, false).Value(), ir.Constant(15u))); diff --git a/core/shader/recompiler/Translation/src/VectorInstructions.cpp b/core/shader/recompiler/Translation/src/VectorInstructions.cpp index 4876e9c72..d1351b06b 100644 --- a/core/shader/recompiler/Translation/src/VectorInstructions.cpp +++ b/core/shader/recompiler/Translation/src/VectorInstructions.cpp @@ -432,6 +432,16 @@ bool TranslationContext::emitVector(const RdnaInstruction& inst) { return integer16Binary(inst, IrOpcode::ISub32, false); case RdnaOpcode::VMed3I16: return vMed3I16(inst); + case RdnaOpcode::VMin3I16: + return integer16Ternary(inst, IrOpcode::SMinTri32, true); + case RdnaOpcode::VMin3U16: + return integer16Ternary(inst, IrOpcode::UMinTri32, false); + case RdnaOpcode::VMax3I16: + return integer16Ternary(inst, IrOpcode::SMaxTri32, true); + case RdnaOpcode::VMax3U16: + return integer16Ternary(inst, IrOpcode::UMaxTri32, false); + case RdnaOpcode::VMed3U16: + return integer16Ternary(inst, IrOpcode::UMedTri32, false); case RdnaOpcode::VMinI16: return integer16Binary(inst, IrOpcode::SMin32, true); case RdnaOpcode::VMaxI16: