MTVU: Use WorkSema

This commit is contained in:
TellowKrinkle 2022-03-25 17:15:12 -05:00 committed by refractionpcsx2
parent d733730950
commit 481c92c1c8
3 changed files with 6 additions and 23 deletions

View File

@ -400,7 +400,6 @@ void SysMtgsThread::ExecuteTaskInThread()
case GS_RINGTYPE_MTVU_GSPACKET:
{
MTVU_LOG("MTGS - Waiting on semaXGkick!");
vu1Thread.KickStart(true);
if (!vu1Thread.semaXGkick.TryWait())
{
busy.PartialRelease();

View File

@ -105,10 +105,7 @@ VU_Thread::~VU_Thread()
void VU_Thread::Reset()
{
ScopedLock lock(mtxBusy);
vuCycleIdx = 0;
isBusy = false;
m_ato_write_pos = 0;
m_write_pos = 0;
m_ato_read_pos = 0;
@ -133,8 +130,7 @@ void VU_Thread::ExecuteRingBuffer()
{
for (;;)
{
semaEvent.WaitWithoutYield();
ScopedLockBool lock(mtxBusy, isBusy);
semaEvent.WaitForWork();
while (m_ato_read_pos.load(std::memory_order_relaxed) != GetWritePos())
{
u32 tag = Read();
@ -419,10 +415,9 @@ void VU_Thread::Get_MTVUChanges()
}
}
void VU_Thread::KickStart(bool forceKick)
void VU_Thread::KickStart()
{
if ((forceKick && !semaEvent.Count()) || (!isBusy.load(std::memory_order_acquire) && GetReadPos() != m_ato_write_pos.load(std::memory_order_relaxed)))
semaEvent.Post();
semaEvent.NotifyOfWork();
}
bool VU_Thread::IsDone()
@ -433,16 +428,7 @@ bool VU_Thread::IsDone()
void VU_Thread::WaitVU()
{
MTVU_LOG("MTVU - WaitVU!");
for (;;)
{
if (IsDone())
break;
//DevCon.WriteLn("WaitVU()");
//pxAssert(THREAD_VU1);
KickStart();
std::this_thread::yield(); // Give a chance to the MTVU thread to actually start
ScopedLock lock(mtxBusy);
}
semaEvent.WaitForEmpty();
}
void VU_Thread::ExecuteVU(u32 vu_addr, u32 vif_top, u32 vif_itop, u32 fbrst)

View File

@ -31,13 +31,11 @@ class VU_Thread : public pxThread {
u32 buffer[buffer_size];
// Note: keep atomic on separate cache line to avoid CPU conflict
alignas(64) std::atomic<bool> isBusy; // Is thread processing data?
alignas(64) std::atomic<int> m_ato_read_pos; // Only modified by VU thread
alignas(64) std::atomic<int> m_ato_write_pos; // Only modified by EE thread
alignas(64) int m_read_pos; // temporary read pos (local to the VU thread)
int m_write_pos; // temporary write pos (local to the EE thread)
Mutex mtxBusy;
Semaphore semaEvent;
WorkSema semaEvent;
BaseVUmicroCPU*& vuCPU;
VURegs& vuRegs;
@ -67,7 +65,7 @@ public:
void Reset();
// Get MTVU to start processing its packets if it isn't already
void KickStart(bool forceKick = false);
void KickStart();
// Used for assertions...
bool IsDone();