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

Method MainLoop

pcsx2/MTGS.cpp:314–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312};
313
314void MTGS::MainLoop()
315{
316 // Threading info: run in MTGS thread
317 // m_ReadPos is only update by the MTGS thread so it is safe to load it with a relaxed atomic
318
319#ifdef RINGBUF_DEBUG_STACK
320 PacketTagType prevCmd;
321#endif
322
323 std::unique_lock mtvu_lock(s_mtx_RingBufferBusy2);
324
325 while (true)
326 {
327 if (s_run_idle_flag.load(std::memory_order_acquire) && VMManager::GetState() != VMState::Running && GSHasDisplayWindow())
328 {
329 if (!s_sem_event.CheckForWork())
330 {
331 GSPresentCurrentFrame();
332 GSThrottlePresentation();
333 }
334 }
335 else
336 {
337 mtvu_lock.unlock();
338 s_sem_event.WaitForWork();
339 mtvu_lock.lock();
340 }
341
342 if (!s_open_flag.load(std::memory_order_acquire))
343 break;
344
345 // note: m_ReadPos is intentionally not volatile, because it should only
346 // ever be modified by this thread.
347 while (s_ReadPos.load(std::memory_order_relaxed) != s_WritePos.load(std::memory_order_acquire))
348 {
349 const unsigned int local_ReadPos = s_ReadPos.load(std::memory_order_relaxed);
350
351 pxAssert(local_ReadPos < RingBufferSize);
352
353 const PacketTagType& tag = (PacketTagType&)RingBuffer[local_ReadPos];
354 u32 ringposinc = 1;
355
356#ifdef RINGBUF_DEBUG_STACK
357 // pop a ringpos off the stack. It should match this one!
358
359 s_lock_Stack.Lock();
360 uptr stackpos = ringposStack.back();
361 if (stackpos != local_ReadPos)
362 {
363 Console.Error("MTGS Ringbuffer Critical Failure ---> %x to %x (prevCmd: %x)\n", stackpos, local_ReadPos, prevCmd.command);
364 }
365 pxAssert(stackpos == local_ReadPos);
366 prevCmd = tag;
367 ringposStack.pop_back();
368 s_lock_Stack.Release();
369#endif
370
371 switch (static_cast<Command>(tag.command))

Callers

nothing calls this directly

Calls 15

GSHasDisplayWindowFunction · 0.85
GSPresentCurrentFrameFunction · 0.85
GSThrottlePresentationFunction · 0.85
GSgifTransferFunction · 0.85
GSgifTransfer2Function · 0.85
GSgifTransfer3Function · 0.85
MemCopy_WrappedSrcFunction · 0.85
GSvsyncFunction · 0.85
GSfreezeFunction · 0.85
GSresetFunction · 0.85
GSgifSoftResetFunction · 0.85
GSInitAndReadFIFOFunction · 0.85

Tested by

no test coverage detected