mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(shader): implement VOP3 I16/U16 min/max/med3
This commit is contained in:
@@ -595,6 +595,14 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(vector_compare_i16_u16 PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
|
||||
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:$<TARGET_FILE_DIR:libc>")
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "Translation/TranslationContext.hpp"
|
||||
#include "RdnaDecoder/RdnaVectorOpDecoder.hpp"
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
|
||||
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<std::uint32_t, 2> 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);
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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},
|
||||
|
||||
@@ -152,6 +152,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);
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user