MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / WaitGS

Method WaitGS

pcsx2/MTGS.cpp:613–659  ·  view source on GitHub ↗

Waits for the GS to empty out the entire ring buffer contents. If syncRegs, then writes pcsx2's gs regs to MTGS's internal copy If weakWait, then this function is allowed to exit after MTGS finished a path1 packet If isMTVU, then this implies this function is being called from the MTVU thread...

Source from the content-addressed store, hash-verified

611// If weakWait, then this function is allowed to exit after MTGS finished a path1 packet
612// If isMTVU, then this implies this function is being called from the MTVU thread...
613void MTGS::WaitGS(bool syncRegs, bool weakWait, bool isMTVU)
614{
615 pxAssertMsg(IsOpen(), "MTGS Warning! WaitGS issued on a closed thread.");
616 if (!IsOpen()) [[unlikely]]
617 return;
618
619 Gif_Path& path = gifUnit.gifPath[GIF_PATH_1];
620
621 // Both m_ReadPos and m_WritePos can be relaxed as we only want to test if the queue is empty but
622 // we don't want to access the content of the queue
623
624 SetEvent();
625 if (weakWait && isMTVU)
626 {
627 // On weakWait we will stop waiting on the MTGS thread if the
628 // MTGS thread has processed a vu1 xgkick packet, or is pending on
629 // its final vu1 xgkick packet (!curP1Packs)...
630 // Note: m_WritePos doesn't seem to have proper atomic write
631 // code, so reading it from the MTVU thread might be dangerous;
632 // hence it has been avoided...
633 u32 startP1Packs = path.GetPendingGSPackets();
634 if (startP1Packs)
635 {
636 while (true)
637 {
638 // m_mtx_RingBufferBusy2.Wait();
639 s_mtx_RingBufferBusy2.lock();
640 s_mtx_RingBufferBusy2.unlock();
641 if (path.GetPendingGSPackets() != startP1Packs)
642 break;
643 }
644 }
645 }
646 else
647 {
648 if (!s_sem_event.WaitForEmpty())
649 pxFailRel("MTGS Thread Died");
650 }
651
652 pxAssert(!(weakWait && syncRegs) && "No synchronization for this!");
653
654 if (syncRegs)
655 {
656 // Completely synchronize GS and MTGS register states.
657 memcpy(RingBuffer.Regs, PS2MEM_GS, sizeof(RingBuffer.Regs));
658 }
659}
660
661// Sets the gsEvent flag and releases a timeslice.
662// For use in loops that wait on the GS thread to do certain things.

Callers

nothing calls this directly

Calls 5

SetEventFunction · 0.85
GetPendingGSPacketsMethod · 0.80
unlockMethod · 0.80
WaitForEmptyMethod · 0.80
lockMethod · 0.45

Tested by

no test coverage detected