Add a way to synchronize with the GPU thread.

This commit is contained in:
Unknown W. Brackets 2013-08-08 00:10:30 -07:00
parent 02e301e5fe
commit 3819886e2e
4 changed files with 21 additions and 0 deletions

View File

@ -379,6 +379,8 @@ u32 sceGeSaveContext(u32 ctxAddr)
{
DEBUG_LOG(HLE, "sceGeSaveContext(%08x)", ctxAddr);
gpu->Flush();
gpu->SyncThread();
if (sizeof(gstate) > 512 * 4)
{
ERROR_LOG(HLE, "AARGH! sizeof(gstate) has grown too large!");
@ -400,6 +402,7 @@ u32 sceGeRestoreContext(u32 ctxAddr)
{
DEBUG_LOG(HLE, "sceGeRestoreContext(%08x)", ctxAddr);
gpu->Flush();
gpu->SyncThread();
if (sizeof(gstate) > 512 * 4)
{

View File

@ -539,6 +539,11 @@ GPUEvent GPUCommon::GetNextEvent() {
return ev;
}
bool GPUCommon::HasEvents() {
lock_guard guard(eventsLock);
return !events.empty();
}
void GPUCommon::ScheduleEvent(GPUEvent ev) {
lock_guard guard(eventsLock);
events.push_back(ev);
@ -576,6 +581,16 @@ void GPUCommon::RunEventsUntil(u64 globalticks) {
} while (CoreTiming::GetTicks() < globalticks);
}
void GPUCommon::SyncThread() {
if (!g_Config.bUseCPUThread) {
_dbg_assert_msg_(G3D, !HasEvents(), "Should never have pending events when CPU/GPU on same thread.");
}
while (HasEvents() && coreState == CORE_RUNNING) {
eventsCond.wait_for(eventsLock, 1);
};
}
int GPUCommon::GetNextListIndex() {
lock_guard guard(listLock);
auto iter = dlQueue.begin();

View File

@ -33,6 +33,7 @@ public:
virtual u32 Continue();
virtual u32 Break(int mode);
virtual void ReapplyGfxState();
virtual void SyncThread();
protected:
// To avoid virtual calls to PreExecuteOp().
@ -44,6 +45,7 @@ protected:
void CheckDrawSync();
int GetNextListIndex();
GPUEvent GetNextEvent();
bool HasEvents();
void ScheduleEvent(GPUEvent ev);
void ProcessDLQueueInternal();
void ReapplyGfxStateInternal();

View File

@ -218,6 +218,7 @@ public:
virtual void DeviceLost() = 0;
virtual void Flush() = 0;
virtual void ReapplyGfxState() = 0;
virtual void SyncThread() = 0;
virtual void DoState(PointerWrap &p) = 0;
// Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*.