Files

81 lines
2.0 KiB
C++
Raw Permalink Normal View History

// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
2024-07-30 13:42:36 +02:00
// SPDX-License-Identifier: GPL-3.0+
#include "Common.h"
#include "VUmicro.h"
#include "MTVU.h"
2021-09-03 00:04:55 +01:00
#include "GS.h"
#include "Gif_Unit.h"
2023-12-26 21:05:33 +10:00
BaseVUmicroCPU* CpuVU0 = nullptr;
BaseVUmicroCPU* CpuVU1 = nullptr;
2022-02-27 17:20:40 +00:00
__inline u32 CalculateMinRunCycles(u32 cycles, bool requiresAccurateCycles)
{
// If we're running an interlocked COP2 operation
// run for an exact amount of cycles
if(requiresAccurateCycles)
return cycles;
// Allow a minimum of 16 cycles to avoid running small blocks
// Running a block of like 3 cycles is highly inefficient
// so while sync isn't tight, it's okay to run ahead a little bit.
return std::max(16U, cycles);
}
// Executes a Block based on EE delta time
2021-08-31 20:51:14 +01:00
void BaseVUmicroCPU::ExecuteBlock(bool startUp)
{
const u32& stat = VU0.VI[REG_VPU_STAT].UL;
const int test = m_Idx ? 0x100 : 1;
if (m_Idx && THREAD_VU1)
{
2021-06-27 04:55:16 +01:00
vu1Thread.Get_MTVUChanges();
return;
}
if (!(stat & test))
2021-09-03 00:04:55 +01:00
{
// VU currently flushes XGKICK on VU1 end so no need for this, yet
/*if (m_Idx == 1 && VU1.xgkickenable)
2021-09-03 00:04:55 +01:00
{
_vuXGKICKTransfer((cpuRegs.cycle - VU1.xgkicklastcycle), false);
}*/
2021-08-31 20:51:14 +01:00
return;
}
if (startUp)
2021-09-05 18:14:53 +01:00
{
Execute(CalculateMinRunCycles(0, false));
}
2021-09-05 18:14:53 +01:00
else // Continue Executing
{
2026-03-15 11:04:19 +01:00
u64 cycle = m_Idx ? VU1.cycle : VU0.cycle;
s32 delta = (s32)(u32)(cpuRegs.cycle - cycle);
2021-08-28 06:45:15 +01:00
if (delta > 0)
Execute(CalculateMinRunCycles(delta, false));
}
}
// This function is called by VU0 Macro (COP2) after transferring some
// EE data to VU0's registers. We want to run VU0 Micro right after this
// to ensure that the register is used at the correct time.
// This fixes spinning/hanging in some games like Ratchet and Clank's Intro.
2022-02-27 17:20:40 +00:00
void BaseVUmicroCPU::ExecuteBlockJIT(BaseVUmicroCPU* cpu, bool interlocked)
2021-08-31 20:51:14 +01:00
{
const u32& stat = VU0.VI[REG_VPU_STAT].UL;
constexpr int test = 1;
2021-08-31 20:51:14 +01:00
if (stat & test)
{ // VU is running
2026-03-15 11:04:19 +01:00
s64 delta = (s64)(u64)(cpuRegs.cycle - VU0.cycle);
2021-08-28 06:45:15 +01:00
2021-08-31 20:51:14 +01:00
if (delta > 0)
2021-09-07 13:40:01 +01:00
{
2022-02-27 17:20:40 +00:00
cpu->Execute(CalculateMinRunCycles(delta, interlocked)); // Execute the time since the last call
}
}
}