CPU/NewRec: Fix lui/mfc0 not getting called in CPU PGXP mode

This commit is contained in:
Stenzek 2023-12-06 16:45:17 +10:00
parent 407049cd91
commit 185af2b039
No known key found for this signature in database
16 changed files with 468 additions and 458 deletions

View File

@ -26,6 +26,8 @@ add_library(core
cpu_core_private.h cpu_core_private.h
cpu_disasm.cpp cpu_disasm.cpp
cpu_disasm.h cpu_disasm.h
cpu_pgxp.cpp
cpu_pgxp.h
cpu_types.cpp cpu_types.cpp
cpu_types.h cpu_types.h
digital_controller.cpp digital_controller.cpp
@ -85,8 +87,6 @@ add_library(core
pad.h pad.h
pcdrv.cpp pcdrv.cpp
pcdrv.h pcdrv.h
pgxp.cpp
pgxp.h
playstation_mouse.cpp playstation_mouse.cpp
playstation_mouse.h playstation_mouse.h
psf_loader.cpp psf_loader.cpp

View File

@ -77,7 +77,7 @@
<ClCompile Include="pch.cpp"> <ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader> <PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile> </ClCompile>
<ClCompile Include="pgxp.cpp" /> <ClCompile Include="cpu_pgxp.cpp" />
<ClCompile Include="playstation_mouse.cpp" /> <ClCompile Include="playstation_mouse.cpp" />
<ClCompile Include="psf_loader.cpp" /> <ClCompile Include="psf_loader.cpp" />
<ClCompile Include="resources.cpp" /> <ClCompile Include="resources.cpp" />
@ -161,7 +161,7 @@
<ClInclude Include="controller.h" /> <ClInclude Include="controller.h" />
<ClInclude Include="pcdrv.h" /> <ClInclude Include="pcdrv.h" />
<ClInclude Include="pch.h" /> <ClInclude Include="pch.h" />
<ClInclude Include="pgxp.h" /> <ClInclude Include="cpu_pgxp.h" />
<ClInclude Include="playstation_mouse.h" /> <ClInclude Include="playstation_mouse.h" />
<ClInclude Include="psf_loader.h" /> <ClInclude Include="psf_loader.h" />
<ClInclude Include="resources.h" /> <ClInclude Include="resources.h" />

View File

@ -41,7 +41,7 @@
<ClCompile Include="negcon.cpp" /> <ClCompile Include="negcon.cpp" />
<ClCompile Include="resources.cpp" /> <ClCompile Include="resources.cpp" />
<ClCompile Include="host_interface_progress_callback.cpp" /> <ClCompile Include="host_interface_progress_callback.cpp" />
<ClCompile Include="pgxp.cpp" /> <ClCompile Include="cpu_pgxp.cpp" />
<ClCompile Include="cheats.cpp" /> <ClCompile Include="cheats.cpp" />
<ClCompile Include="memory_card_image.cpp" /> <ClCompile Include="memory_card_image.cpp" />
<ClCompile Include="analog_joystick.cpp" /> <ClCompile Include="analog_joystick.cpp" />
@ -107,7 +107,7 @@
<ClInclude Include="resources.h" /> <ClInclude Include="resources.h" />
<ClInclude Include="host_interface_progress_callback.h" /> <ClInclude Include="host_interface_progress_callback.h" />
<ClInclude Include="gte_types.h" /> <ClInclude Include="gte_types.h" />
<ClInclude Include="pgxp.h" /> <ClInclude Include="cpu_pgxp.h" />
<ClInclude Include="cpu_core_private.h" /> <ClInclude Include="cpu_core_private.h" />
<ClInclude Include="cheats.h" /> <ClInclude Include="cheats.h" />
<ClInclude Include="memory_card_image.h" /> <ClInclude Include="memory_card_image.h" />

View File

@ -14,7 +14,7 @@
#include "gte.h" #include "gte.h"
#include "host.h" #include "host.h"
#include "pcdrv.h" #include "pcdrv.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
#include "system.h" #include "system.h"
#include "timing_event.h" #include "timing_event.h"
@ -191,6 +191,9 @@ void CPU::Reset()
GTE::Reset(); GTE::Reset();
if (g_settings.gpu_pgxp_enable)
PGXP::Reset();
// TODO: This consumes cycles... // TODO: This consumes cycles...
SetPC(RESET_VECTOR); SetPC(RESET_VECTOR);
} }

View File

@ -47,6 +47,20 @@ union CacheControl
BitField<u32, bool, 11, 1> icache_enable; BitField<u32, bool, 11, 1> icache_enable;
}; };
struct PGXP_value
{
float x;
float y;
float z;
union
{
u32 flags;
u8 compFlags[4];
u16 halfFlags[2];
};
u32 value;
};
struct State struct State
{ {
// ticks the CPU has executed // ticks the CPU has executed
@ -93,6 +107,12 @@ struct State
std::array<u8, SCRATCHPAD_SIZE> scratchpad = {}; std::array<u8, SCRATCHPAD_SIZE> scratchpad = {};
PGXP_value pgxp_gpr[32];
PGXP_value pgxp_hi;
PGXP_value pgxp_lo;
PGXP_value pgxp_cop0[32];
PGXP_value pgxp_gte[64];
static constexpr u32 GPRRegisterOffset(u32 index) { return offsetof(State, regs.r) + (sizeof(u32) * index); } static constexpr u32 GPRRegisterOffset(u32 index) { return offsetof(State, regs.r) + (sizeof(u32) * index); }
static constexpr u32 GTERegisterOffset(u32 index) { return offsetof(State, gte_regs.r32) + (sizeof(u32) * index); } static constexpr u32 GTERegisterOffset(u32 index) { return offsetof(State, gte_regs.r32) + (sizeof(u32) * index); }
}; };

View File

@ -8,7 +8,7 @@
#include "cpu_code_cache.h" #include "cpu_code_cache.h"
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "cpu_disasm.h" #include "cpu_disasm.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
@ -1274,7 +1274,7 @@ void CPU::NewRec::Compiler::CompileInstruction()
{ {
switch (inst->cop.CommonOp()) switch (inst->cop.CommonOp())
{ {
case CopCommonInstruction::mfcn: if (inst->r.rt != Reg::zero) { CompileTemplate(nullptr, &Compiler::Compile_mfc0, nullptr, TF_WRITES_T | TF_LOAD_DELAY); } SpecExec_mfc0(); break; case CopCommonInstruction::mfcn: if (inst->r.rt != Reg::zero) { CompileTemplate(nullptr, &Compiler::Compile_mfc0, PGXPFN(CPU_MFC0), TF_WRITES_T | TF_LOAD_DELAY); } SpecExec_mfc0(); break;
case CopCommonInstruction::mtcn: CompileTemplate(nullptr, &Compiler::Compile_mtc0, PGXPFN(CPU_MTC0), TF_READS_T); SpecExec_mtc0(); break; case CopCommonInstruction::mtcn: CompileTemplate(nullptr, &Compiler::Compile_mtc0, PGXPFN(CPU_MTC0), TF_READS_T); SpecExec_mtc0(); break;
default: Compile_Fallback(); break; default: Compile_Fallback(); break;
} }
@ -2122,6 +2122,9 @@ void CPU::NewRec::Compiler::Compile_lui()
return; return;
SetConstantReg(inst->i.rt, inst->i.imm_zext32() << 16); SetConstantReg(inst->i.rt, inst->i.imm_zext32() << 16);
if (g_settings.UsingPGXPCPUMode())
GeneratePGXPCallWithMIPSRegs(reinterpret_cast<const void*>(&PGXP::CPU_LUI), inst->bits);
} }
static constexpr const std::array<std::pair<u32*, u32>, 16> s_cop0_table = { static constexpr const std::array<std::pair<u32*, u32>, 16> s_cop0_table = {

View File

@ -7,10 +7,10 @@
#include "common/log.h" #include "common/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "cpu_pgxp.h"
#include "cpu_recompiler_thunks.h" #include "cpu_recompiler_thunks.h"
#include "cpu_recompiler_types.h" #include "cpu_recompiler_types.h"
#include "gte.h" #include "gte.h"
#include "pgxp.h"
#include "settings.h" #include "settings.h"
#include "timing_event.h" #include "timing_event.h"
#include <limits> #include <limits>

View File

@ -7,10 +7,10 @@
#include "common/log.h" #include "common/log.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "cpu_pgxp.h"
#include "cpu_recompiler_thunks.h" #include "cpu_recompiler_thunks.h"
#include "cpu_recompiler_types.h" #include "cpu_recompiler_types.h"
#include "gte.h" #include "gte.h"
#include "pgxp.h"
#include "settings.h" #include "settings.h"
#include "timing_event.h" #include "timing_event.h"
#include <limits> #include <limits>

View File

@ -8,10 +8,10 @@
#include "common/string_util.h" #include "common/string_util.h"
#include "cpu_code_cache_private.h" #include "cpu_code_cache_private.h"
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "cpu_pgxp.h"
#include "cpu_recompiler_thunks.h" #include "cpu_recompiler_thunks.h"
#include "cpu_recompiler_types.h" #include "cpu_recompiler_types.h"
#include "gte.h" #include "gte.h"
#include "pgxp.h"
#include "settings.h" #include "settings.h"
#include "timing_event.h" #include "timing_event.h"
#include <limits> #include <limits>

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
#pragma once #pragma once
#include "types.h" #include "types.h"
namespace PGXP { namespace CPU::PGXP {
void Initialize(); void Initialize();
void Reset(); void Reset();

View File

@ -7,7 +7,7 @@
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "cpu_disasm.h" #include "cpu_disasm.h"
#include "gte.h" #include "gte.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
Log_SetChannel(CPU::Recompiler); Log_SetChannel(CPU::Recompiler);

View File

@ -6,7 +6,7 @@
#include "gpu_hw_shadergen.h" #include "gpu_hw_shadergen.h"
#include "gpu_sw_backend.h" #include "gpu_sw_backend.h"
#include "host.h" #include "host.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
#include "system.h" #include "system.h"
@ -1671,9 +1671,9 @@ void GPU_HW::LoadVertices()
if (pgxp) if (pgxp)
{ {
valid_w &= valid_w &= CPU::PGXP::GetPreciseVertex(Truncate32(maddr_and_pos >> 32), vp.bits, native_x, native_y,
PGXP::GetPreciseVertex(Truncate32(maddr_and_pos >> 32), vp.bits, native_x, native_y, m_drawing_offset.x, m_drawing_offset.x, m_drawing_offset.y, &vertices[i].x, &vertices[i].y,
m_drawing_offset.y, &vertices[i].x, &vertices[i].y, &vertices[i].w); &vertices[i].w);
} }
} }
if (pgxp) if (pgxp)

View File

@ -5,7 +5,7 @@
#include "cpu_core.h" #include "cpu_core.h"
#include "cpu_core_private.h" #include "cpu_core_private.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
#include "timing_event.h" #include "timing_event.h"
@ -794,7 +794,7 @@ void GTE::RTPS(const s16 V[3], u8 shift, bool lm, bool last)
precise_x = std::clamp<float>(precise_x, -1024.0f, 1023.0f); precise_x = std::clamp<float>(precise_x, -1024.0f, 1023.0f);
precise_y = std::clamp<float>(precise_y, -1024.0f, 1023.0f); precise_y = std::clamp<float>(precise_y, -1024.0f, 1023.0f);
PGXP::GTE_PushSXYZ2f(precise_x, precise_y, precise_z, REGS.dr32[14]); CPU::PGXP::GTE_PushSXYZ2f(precise_x, precise_y, precise_z, REGS.dr32[14]);
} }
if (last) if (last)
@ -842,10 +842,10 @@ void GTE::Execute_NCLIP(Instruction inst)
void GTE::Execute_NCLIP_PGXP(Instruction inst) void GTE::Execute_NCLIP_PGXP(Instruction inst)
{ {
if (PGXP::GTE_NCLIP_valid(REGS.dr32[12], REGS.dr32[13], REGS.dr32[14])) if (CPU::PGXP::GTE_NCLIP_valid(REGS.dr32[12], REGS.dr32[13], REGS.dr32[14]))
{ {
REGS.FLAG.Clear(); REGS.FLAG.Clear();
REGS.MAC0 = static_cast<s32>(PGXP::GTE_NCLIP()); REGS.MAC0 = static_cast<s32>(CPU::PGXP::GTE_NCLIP());
} }
else else
{ {

View File

@ -8,7 +8,7 @@
#include "gpu.h" #include "gpu.h"
#include "host.h" #include "host.h"
#include "imgui_overlays.h" #include "imgui_overlays.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "settings.h" #include "settings.h"
#include "spu.h" #include "spu.h"
#include "system.h" #include "system.h"
@ -341,9 +341,9 @@ DEFINE_HOTKEY("TogglePGXP", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_NOO
5.0f); 5.0f);
if (g_settings.gpu_pgxp_enable) if (g_settings.gpu_pgxp_enable)
PGXP::Initialize(); CPU::PGXP::Initialize();
else else
PGXP::Shutdown(); CPU::PGXP::Shutdown();
// we need to recompile all blocks if pgxp is toggled on/off // we need to recompile all blocks if pgxp is toggled on/off
CPU::CodeCache::Reset(); CPU::CodeCache::Reset();
@ -433,8 +433,8 @@ DEFINE_HOTKEY("TogglePGXPCPU", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_
TRANSLATE_STR("OSDMessage", "PGXP CPU mode is now disabled."), TRANSLATE_STR("OSDMessage", "PGXP CPU mode is now disabled."),
5.0f); 5.0f);
PGXP::Shutdown(); CPU::PGXP::Shutdown();
PGXP::Initialize(); CPU::PGXP::Initialize();
// we need to recompile all blocks if pgxp is toggled on/off // we need to recompile all blocks if pgxp is toggled on/off
CPU::CodeCache::Reset(); CPU::CodeCache::Reset();

View File

@ -26,7 +26,7 @@
#include "multitap.h" #include "multitap.h"
#include "pad.h" #include "pad.h"
#include "pcdrv.h" #include "pcdrv.h"
#include "pgxp.h" #include "cpu_pgxp.h"
#include "psf_loader.h" #include "psf_loader.h"
#include "save_state_version.h" #include "save_state_version.h"
#include "sio.h" #include "sio.h"
@ -1561,7 +1561,7 @@ bool System::Initialize(bool force_software_renderer)
GTE::UpdateAspectRatio(); GTE::UpdateAspectRatio();
if (g_settings.gpu_pgxp_enable) if (g_settings.gpu_pgxp_enable)
PGXP::Initialize(); CPU::PGXP::Initialize();
// Was startup cancelled? (e.g. shading compilers took too long and the user closed the application) // Was startup cancelled? (e.g. shading compilers took too long and the user closed the application)
if (IsStartupCancelled()) if (IsStartupCancelled())
@ -1573,7 +1573,7 @@ bool System::Initialize(bool force_software_renderer)
Host::ReleaseRenderWindow(); Host::ReleaseRenderWindow();
} }
if (g_settings.gpu_pgxp_enable) if (g_settings.gpu_pgxp_enable)
PGXP::Shutdown(); CPU::PGXP::Shutdown();
CPU::Shutdown(); CPU::Shutdown();
Bus::Shutdown(); Bus::Shutdown();
return false; return false;
@ -1666,7 +1666,7 @@ void System::DestroySystem()
g_gpu.reset(); g_gpu.reset();
InterruptController::Shutdown(); InterruptController::Shutdown();
DMA::Shutdown(); DMA::Shutdown();
PGXP::Shutdown(); CPU::PGXP::Shutdown();
CPU::CodeCache::Shutdown(); CPU::CodeCache::Shutdown();
Bus::Shutdown(); Bus::Shutdown();
CPU::Shutdown(); CPU::Shutdown();
@ -2086,7 +2086,7 @@ bool System::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
// only reset pgxp if we're not runahead-rollbacking. the value checks will save us from broken rendering, and it // only reset pgxp if we're not runahead-rollbacking. the value checks will save us from broken rendering, and it
// saves using imprecise values for a frame in 30fps games. // saves using imprecise values for a frame in 30fps games.
if (sw.IsReading() && g_settings.gpu_pgxp_enable && !is_memory_state) if (sw.IsReading() && g_settings.gpu_pgxp_enable && !is_memory_state)
PGXP::Reset(); CPU::PGXP::Reset();
if (!sw.DoMarker("Bus") || !Bus::DoState(sw)) if (!sw.DoMarker("Bus") || !Bus::DoState(sw))
return false; return false;
@ -2201,7 +2201,7 @@ void System::InternalReset()
CPU::Reset(); CPU::Reset();
CPU::CodeCache::Reset(); CPU::CodeCache::Reset();
if (g_settings.gpu_pgxp_enable) if (g_settings.gpu_pgxp_enable)
PGXP::Initialize(); CPU::PGXP::Initialize();
Bus::Reset(); Bus::Reset();
DMA::Reset(); DMA::Reset();
@ -3670,10 +3670,10 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
g_settings.gpu_pgxp_cpu != old_settings.gpu_pgxp_cpu))) g_settings.gpu_pgxp_cpu != old_settings.gpu_pgxp_cpu)))
{ {
if (old_settings.gpu_pgxp_enable) if (old_settings.gpu_pgxp_enable)
PGXP::Shutdown(); CPU::PGXP::Shutdown();
if (g_settings.gpu_pgxp_enable) if (g_settings.gpu_pgxp_enable)
PGXP::Initialize(); CPU::PGXP::Initialize();
CPU::CodeCache::Reset(); CPU::CodeCache::Reset();
} }