diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 5b0ccc3535..26d3ddb1a6 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -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(); diff --git a/pcsx2/MTVU.cpp b/pcsx2/MTVU.cpp index f50e85b638..46750f2f3b 100644 --- a/pcsx2/MTVU.cpp +++ b/pcsx2/MTVU.cpp @@ -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) diff --git a/pcsx2/MTVU.h b/pcsx2/MTVU.h index dbfad2506e..d743224199 100644 --- a/pcsx2/MTVU.h +++ b/pcsx2/MTVU.h @@ -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 isBusy; // Is thread processing data? alignas(64) std::atomic m_ato_read_pos; // Only modified by VU thread alignas(64) std::atomic 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();