PixelEngine: Delay token updates by events.

To still get a speedup, mark if already an event is queued.
If so, don't raise a new event.
This commit is contained in:
degasus 2016-08-10 09:44:08 +02:00
parent a051db9792
commit 82bdc4ef86
2 changed files with 71 additions and 36 deletions

View File

@ -4,9 +4,8 @@
// http://www.nvidia.com/object/General_FAQ.html#t6 !!!!!
#include <atomic>
#include <mutex>
#include "Common/Atomic.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
@ -90,13 +89,18 @@ static UPEDstAlphaConfReg m_DstAlphaConf;
static UPEAlphaModeConfReg m_AlphaModeConf;
static UPEAlphaReadReg m_AlphaRead;
static UPECtrlReg m_Control;
static std::atomic<u16> s_Token; // token value most recently encountered
std::mutex s_token_finish_mutex;
static u16 s_token;
static u16 s_token_pending;
static bool s_token_interrupt_pending;
static bool s_finish_interrupt_pending;
static bool s_event_raised;
static bool s_signal_token_interrupt;
static bool s_signal_finish_interrupt;
static int et_SetTokenOnMainThread;
static int et_SetFinishOnMainThread;
static int et_SetTokenFinishOnMainThread;
enum
{
@ -112,15 +116,19 @@ void DoState(PointerWrap& p)
p.Do(m_AlphaModeConf);
p.Do(m_AlphaRead);
p.DoPOD(m_Control);
p.Do(s_Token);
p.Do(s_token);
p.Do(s_token_pending);
p.Do(s_token_interrupt_pending);
p.Do(s_finish_interrupt_pending);
p.Do(s_event_raised);
p.Do(s_signal_token_interrupt);
p.Do(s_signal_finish_interrupt);
}
static void UpdateInterrupts();
static void SetToken_OnMainThread(u64 userdata, s64 cyclesLate);
static void SetFinish_OnMainThread(u64 userdata, s64 cyclesLate);
static void SetTokenFinish_OnMainThread(u64 userdata, s64 cyclesLate);
void Init()
{
@ -130,13 +138,17 @@ void Init()
m_DstAlphaConf.Hex = 0;
m_AlphaModeConf.Hex = 0;
m_AlphaRead.Hex = 0;
s_Token = 0;
s_token = 0;
s_token_pending = 0;
s_token_interrupt_pending = false;
s_finish_interrupt_pending = false;
s_event_raised = false;
s_signal_token_interrupt = false;
s_signal_finish_interrupt = false;
et_SetTokenOnMainThread = CoreTiming::RegisterEvent("SetToken", SetToken_OnMainThread);
et_SetFinishOnMainThread = CoreTiming::RegisterEvent("SetFinish", SetFinish_OnMainThread);
et_SetTokenFinishOnMainThread = CoreTiming::RegisterEvent("SetTokenFinish", SetTokenFinish_OnMainThread);
}
void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
@ -207,8 +219,7 @@ void RegisterMMIO(MMIO::Mapping* mmio, u32 base)
// Token register, readonly.
mmio->Register(base | PE_TOKEN_REG,
MMIO::ComplexRead<u16>([](u32) { return s_Token.load(); }),
MMIO::ComplexRead<u16>([](u32) { return s_token; }),
MMIO::InvalidWrite<u16>());
// BBOX registers, readonly and need to update a flag.
@ -233,46 +244,70 @@ static void UpdateInterrupts()
s_signal_finish_interrupt && m_Control.PEFinishEnable);
}
static void SetToken_OnMainThread(u64 userdata, s64 cyclesLate)
static void SetTokenFinish_OnMainThread(u64 userdata, s64 cyclesLate)
{
s_signal_token_interrupt = true;
UpdateInterrupts();
std::unique_lock<std::mutex> lk(s_token_finish_mutex);
s_event_raised = false;
s_token = s_token_pending;
if (s_token_interrupt_pending)
{
s_token_interrupt_pending = false;
s_signal_token_interrupt = true;
UpdateInterrupts();
}
if (s_finish_interrupt_pending)
{
s_finish_interrupt_pending = false;
s_signal_finish_interrupt = true;
UpdateInterrupts();
lk.unlock();
Core::FrameUpdateOnCPUThread();
}
}
static void SetFinish_OnMainThread(u64 userdata, s64 cyclesLate)
// Raise the event handler above on the CPU thread.
// s_token_finish_mutex must be locked.
// THIS IS EXECUTED FROM VIDEO THREAD
static void RaiseEvent()
{
s_signal_finish_interrupt = true;
UpdateInterrupts();
if (s_event_raised)
return;
Core::FrameUpdateOnCPUThread();
s_event_raised = true;
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
CoreTiming::ScheduleEvent(0, et_SetTokenFinishOnMainThread, 0);
else
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenFinishOnMainThread, 0);
}
// SetToken
// THIS IS EXECUTED FROM VIDEO THREAD
void SetToken(const u16 _token, const int _bSetTokenAcknowledge)
void SetToken(const u16 token, const bool interrupt)
{
INFO_LOG(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: %04x)", _token);
s_Token.store(_token);
INFO_LOG(PIXELENGINE, "VIDEO Backend raises INT_CAUSE_PE_TOKEN (btw, token: %04x)", token);
if (_bSetTokenAcknowledge) // set token INT
{
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
CoreTiming::ScheduleEvent(0, et_SetTokenOnMainThread, 0);
else
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetTokenOnMainThread, 0);
}
std::lock_guard<std::mutex> lk(s_token_finish_mutex);
s_token_pending = token;
s_token_interrupt_pending |= interrupt;
RaiseEvent();
}
// SetFinish
// THIS IS EXECUTED FROM VIDEO THREAD (BPStructs.cpp) when a new frame has been drawn
void SetFinish()
{
if (!SConfig::GetInstance().bCPUThread || Fifo::UseDeterministicGPUThread())
CoreTiming::ScheduleEvent(0, et_SetFinishOnMainThread, 0);
else
CoreTiming::ScheduleEvent_Threadsafe(0, et_SetFinishOnMainThread, 0);
INFO_LOG(PIXELENGINE, "VIDEO Set Finish");
std::lock_guard<std::mutex> lk(s_token_finish_mutex);
s_finish_interrupt_pending |= true;
RaiseEvent();
}
UPEAlphaReadReg GetAlphaReadMode()

View File

@ -61,7 +61,7 @@ void DoState(PointerWrap& p);
void RegisterMMIO(MMIO::Mapping* mmio, u32 base);
// gfx backend support
void SetToken(const u16 _token, const int _bSetTokenAcknowledge);
void SetToken(const u16 token, const bool interrupt);
void SetFinish();
UPEAlphaReadReg GetAlphaReadMode();