mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #366 from DotDebian/feat/shader-vop1-pipeflush-clrexcp
feat(shader): decode v_pipeflush and v_clrexcp as no-ops
This commit is contained in:
@@ -221,6 +221,11 @@ target_link_libraries(agc_dpp_write_tests PRIVATE shader_recompiler_agc_driver l
|
||||
set_target_properties(agc_dpp_write_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(agc_dpp_write_tests)
|
||||
|
||||
add_test_executable(agc_vop1_control_decode_tests EXCLUDE_FROM_ALL tests/Vop1ControlDecode.cpp)
|
||||
target_link_libraries(agc_vop1_control_decode_tests PRIVATE shader_recompiler_agc_driver libc)
|
||||
set_target_properties(agc_vop1_control_decode_tests PROPERTIES CXX_EXTENSIONS OFF)
|
||||
configure_windows_unwind(agc_vop1_control_decode_tests)
|
||||
|
||||
add_test_executable(agc_shader_disk_cache_tests EXCLUDE_FROM_ALL tests/ShaderDiskCache.cpp)
|
||||
target_include_directories(agc_shader_disk_cache_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(agc_shader_disk_cache_tests PRIVATE shader_recompiler_agc_driver libc)
|
||||
@@ -413,7 +418,7 @@ foreach(agcExecutionTestSource IN LISTS agcExecutionTestSources)
|
||||
endforeach()
|
||||
|
||||
if(BUILD_TESTING)
|
||||
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests})
|
||||
foreach(agcTest IN ITEMS agc_driver_tests agc_shader_memory_tests agc_structurizer_tests agc_dpp_write_tests agc_vop1_control_decode_tests agc_shader_disk_cache_tests agc_shader_control_flow_tests agc_driver_flip_tests agc_driver_pm4_tests agc_driver_graphics_tests ${agcExecutionTests})
|
||||
string(REGEX REPLACE "_tests$" "" agcTestName "${agcTest}")
|
||||
set_target_properties(${agcTest} PROPERTIES EXCLUDE_FROM_ALL OFF)
|
||||
add_test(NAME ${agcTestName} COMMAND ${agcTest})
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "RdnaDecoder/RdnaInstructionDecoder.hpp"
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
|
||||
using namespace ShaderRecompiler;
|
||||
|
||||
int main() {
|
||||
const std::vector<std::uint32_t> code{
|
||||
0x7e000000u, 0x7e003600u, 0x7e008200u,
|
||||
0xd5800000u, 0x00000000u, 0xd59b0000u, 0x00000000u, 0xd5c10000u, 0x00000000u,
|
||||
0xbf810000u,
|
||||
};
|
||||
constexpr std::array expected{
|
||||
RdnaOpcode::VNop, RdnaOpcode::VPipeflush, RdnaOpcode::VClrexcp,
|
||||
RdnaOpcode::VNop, RdnaOpcode::VPipeflush, RdnaOpcode::VClrexcp,
|
||||
};
|
||||
try {
|
||||
const auto decoded = RdnaInstructionDecoder{}.Decode(code);
|
||||
if (decoded.instructions.size() != expected.size() + 1u) {
|
||||
std::fprintf(stderr, "decoded %zu instructions, expected %zu\n", decoded.instructions.size(), expected.size() + 1u);
|
||||
return 1;
|
||||
}
|
||||
for (std::size_t index = 0; index < expected.size(); ++index) {
|
||||
const auto& instruction = decoded.instructions[index];
|
||||
const auto wordCount = index < 3u ? 1u : 2u;
|
||||
if (instruction.op != expected[index] || instruction.wordCount != wordCount) {
|
||||
std::fprintf(stderr, "instruction %zu decodes to the wrong opcode or length\n", index);
|
||||
return 1;
|
||||
}
|
||||
if (instruction.destination.kind != RdnaOperandKind::Null || instruction.sourceCount != 0u) {
|
||||
std::fprintf(stderr, "instruction %zu decodes with operands\n", index);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
|
||||
#include "prx/libSceAgcDriver/Graphics/include/Draw.hpp"
|
||||
#include "Recompiler.hpp"
|
||||
#include "VulkanTestDevice.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
using AgcDriver::Graphics::Require;
|
||||
using ShaderRecompiler::ShaderStage;
|
||||
|
||||
constexpr std::uint32_t Threads = 64;
|
||||
constexpr std::uint32_t Stride = 4;
|
||||
alignas(256) std::array<std::uint32_t, Threads * Stride> Input{};
|
||||
alignas(256) std::array<std::uint32_t, Threads * Stride> Output{};
|
||||
|
||||
alignas(256) constexpr std::array<std::uint32_t, 17> Vop1ControlCode{
|
||||
0x34020082, 0xe0302000, 0x80000401, 0xbf8c3f70, 0x7e000000, 0x7e003600, 0x7e008200, 0x4a080881,
|
||||
0xd5800000, 0x00000000, 0xd59b0000, 0x00000000, 0xd5c10000, 0x00000000, 0xe0702000, 0x80010401, 0xbf810000,
|
||||
};
|
||||
|
||||
std::array<std::uint32_t, 4> BufferDescriptor(const void* data, std::uint32_t count) {
|
||||
const auto address = reinterpret_cast<std::uintptr_t>(data);
|
||||
return {static_cast<std::uint32_t>(address), static_cast<std::uint32_t>((address >> 32u) & 0xffffu) | (4u << 16u), count, 0x01016facu};
|
||||
}
|
||||
|
||||
void Run(AgcDriver::VulkanDevice& device) {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) Input[tid * Stride] = tid * 0x01010101u + 7u;
|
||||
Output.fill(0xdeadbeefu);
|
||||
std::vector<std::uint32_t> userData(8, 0u);
|
||||
const auto input = BufferDescriptor(Input.data(), static_cast<std::uint32_t>(Input.size()));
|
||||
const auto output = BufferDescriptor(Output.data(), static_cast<std::uint32_t>(Output.size()));
|
||||
std::copy(input.begin(), input.end(), userData.begin());
|
||||
std::copy(output.begin(), output.end(), userData.begin() + 4);
|
||||
const std::span<const std::uint32_t> code(Vop1ControlCode);
|
||||
const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
|
||||
const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0, {false, false, false}, false, 1};
|
||||
ShaderRecompiler::RecompileRequest request{
|
||||
{ShaderStage::Compute, reinterpret_cast<std::uintptr_t>(code.data()), code, 0, {}},
|
||||
{32, 0, userData, compute, std::nullopt, std::nullopt, memory},
|
||||
device.Target(),
|
||||
{0, 0, 0, 128}
|
||||
};
|
||||
request.useCache = false;
|
||||
const auto result = ShaderRecompiler::Recompile(request);
|
||||
device.Dispatch(result, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
|
||||
device.WaitIdle();
|
||||
}
|
||||
|
||||
void Check() {
|
||||
for (std::uint32_t tid = 0; tid < Threads; ++tid) {
|
||||
const auto expected = Input[tid * Stride] + 1u;
|
||||
const auto actual = Output[tid * Stride];
|
||||
Require(actual == expected, "vop1 control: thread " + std::to_string(tid) + " is " + std::to_string(actual) + ", expected " + std::to_string(expected));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
try {
|
||||
const auto device = OpenVulkanTestDevice();
|
||||
if (!device) return VulkanTestSkipped;
|
||||
Run(*device);
|
||||
Check();
|
||||
std::puts("vop1 control tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -261,6 +261,8 @@ enum class RdnaOpcode : std::uint16_t {
|
||||
SCmpEqU64,
|
||||
SCmpLgU64,
|
||||
VNop,
|
||||
VPipeflush,
|
||||
VClrexcp,
|
||||
VMovrelsB32,
|
||||
VPermlane16B32,
|
||||
VPermlanex16B32,
|
||||
|
||||
@@ -209,6 +209,8 @@ bool IsVectorAluOpcode(RdnaOpcode opcode) {
|
||||
case RdnaOpcode::VWritelaneB32:
|
||||
case RdnaOpcode::VMovreldB32:
|
||||
case RdnaOpcode::VNop:
|
||||
case RdnaOpcode::VPipeflush:
|
||||
case RdnaOpcode::VClrexcp:
|
||||
case RdnaOpcode::VMovrelsB32:
|
||||
case RdnaOpcode::VPermlane16B32:
|
||||
case RdnaOpcode::VPermlanex16B32:
|
||||
|
||||
@@ -120,6 +120,7 @@ constexpr VectorOpcodeInfo vop1Opcodes[] = {
|
||||
{0x12u, RdnaOpcode::VCvtF32Ubyte1},
|
||||
{0x13u, RdnaOpcode::VCvtF32Ubyte2},
|
||||
{0x14u, RdnaOpcode::VCvtF32Ubyte3},
|
||||
{0x1bu, RdnaOpcode::VPipeflush},
|
||||
{0x2au, RdnaOpcode::VRcpF32},
|
||||
{0x20u, RdnaOpcode::VFractF32},
|
||||
{0x21u, RdnaOpcode::VTruncF32},
|
||||
@@ -140,6 +141,7 @@ constexpr VectorOpcodeInfo vop1Opcodes[] = {
|
||||
{0x3bu, RdnaOpcode::VFfbhI32},
|
||||
{0x3fu, RdnaOpcode::VFrexpExpI32F32},
|
||||
{0x40u, RdnaOpcode::VFrexpMantF32},
|
||||
{0x41u, RdnaOpcode::VClrexcp},
|
||||
{0x42u, RdnaOpcode::VMovreldB32},
|
||||
{0x43u, RdnaOpcode::VMovrelsB32},
|
||||
{0x50u, RdnaOpcode::VCvtF16U16},
|
||||
@@ -182,6 +184,7 @@ constexpr VectorOpcodeInfo vop3EncodedVop1Opcodes[] = {
|
||||
{0x12u, RdnaOpcode::VCvtF32Ubyte1},
|
||||
{0x13u, RdnaOpcode::VCvtF32Ubyte2},
|
||||
{0x14u, RdnaOpcode::VCvtF32Ubyte3},
|
||||
{0x1bu, RdnaOpcode::VPipeflush},
|
||||
{0x2au, RdnaOpcode::VRcpF32},
|
||||
{0x20u, RdnaOpcode::VFractF32},
|
||||
{0x21u, RdnaOpcode::VTruncF32},
|
||||
@@ -202,6 +205,7 @@ constexpr VectorOpcodeInfo vop3EncodedVop1Opcodes[] = {
|
||||
{0x3bu, RdnaOpcode::VFfbhI32},
|
||||
{0x3fu, RdnaOpcode::VFrexpExpI32F32},
|
||||
{0x40u, RdnaOpcode::VFrexpMantF32},
|
||||
{0x41u, RdnaOpcode::VClrexcp},
|
||||
{0x42u, RdnaOpcode::VMovreldB32},
|
||||
{0x43u, RdnaOpcode::VMovrelsB32},
|
||||
{0x50u, RdnaOpcode::VCvtF16U16},
|
||||
@@ -613,6 +617,10 @@ RdnaOpcode lookupVintrpOpcode(std::uint32_t opcode) {
|
||||
}
|
||||
}
|
||||
|
||||
bool isVop1WithoutOperands(RdnaOpcode opcode) {
|
||||
return opcode == RdnaOpcode::VNop || opcode == RdnaOpcode::VPipeflush || opcode == RdnaOpcode::VClrexcp;
|
||||
}
|
||||
|
||||
bool usesScalarDestination(RdnaOpcode opcode) {
|
||||
return opcode == RdnaOpcode::VReadfirstlaneB32 || opcode == RdnaOpcode::VReadlaneB32;
|
||||
}
|
||||
@@ -1801,7 +1809,7 @@ RdnaInstruction DecodeRdnaVop1(std::uint32_t programCounter, std::span<const std
|
||||
instruction.op = lookupVectorOpcode(vop1Opcodes, opcode, "VOP1 opcode is not implemented");
|
||||
SetRdnaRawWords(instruction, code, wordIndex, 1);
|
||||
|
||||
if (instruction.op == RdnaOpcode::VNop) {
|
||||
if (isVop1WithoutOperands(instruction.op)) {
|
||||
instruction.destination.kind = RdnaOperandKind::Null;
|
||||
instruction.sourceCount = 0;
|
||||
return instruction;
|
||||
@@ -1929,6 +1937,11 @@ RdnaInstruction DecodeRdnaVop3(std::uint32_t programCounter, std::span<const std
|
||||
|
||||
checkNativeVop3Modifiers(instruction.op, permlane, vop3bUsesSdst, scalarDst, abs, opSel, clamp, omod, neg);
|
||||
|
||||
if (isVop1WithoutOperands(instruction.op)) {
|
||||
instruction.destination.kind = RdnaOperandKind::Null;
|
||||
instruction.sourceCount = 0;
|
||||
return instruction;
|
||||
}
|
||||
if (compareExec) {
|
||||
instruction.destination.kind = RdnaOperandKind::ExecLo;
|
||||
} else if (scalarDst) {
|
||||
|
||||
@@ -23,6 +23,8 @@ bool roundsProductSeparately(const RdnaInstruction& inst) {
|
||||
bool TranslationContext::emitVector(const RdnaInstruction& inst) {
|
||||
switch (inst.op) {
|
||||
case RdnaOpcode::VNop:
|
||||
case RdnaOpcode::VPipeflush:
|
||||
case RdnaOpcode::VClrexcp:
|
||||
return true;
|
||||
case RdnaOpcode::VMovB32:
|
||||
movB32(inst, true);
|
||||
|
||||
Reference in New Issue
Block a user