From c57954a72e73e48fd9a093a79f63abf5c6160f41 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 5 Apr 2013 22:38:19 -0700 Subject: [PATCH] Implement sceGeDrawSync(). --- Core/HLE/sceGe.cpp | 2 +- Core/HLE/sceKernelThread.cpp | 2 +- Core/HLE/sceKernelThread.h | 1 + GPU/GPUCommon.cpp | 45 +++++++++++++++++++++++++++++------- GPU/GPUCommon.h | 1 + 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index d724ec120f..978c656ebd 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -227,7 +227,7 @@ int sceGeListSync(u32 displayListID, u32 mode) //0 : wait for completion 1:chec u32 sceGeDrawSync(u32 mode) { //wait/check entire drawing state - DEBUG_LOG(HLE, "FAKE sceGeDrawSync(mode=%d) (0=wait for completion)", mode); + DEBUG_LOG(HLE, "sceGeDrawSync(mode=%d) (0=wait for completion, 1=peek)", mode); return gpu->DrawSync(mode); } diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index c09fe8aa3a..ea917ea143 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -1153,7 +1153,7 @@ bool __KernelTriggerWait(WaitType type, int id, bool useRetVal, int retVal, cons hleReSchedule(reason); } } - return true; + return doneAnything; } bool __KernelTriggerWait(WaitType type, int id, const char *reason, bool dontSwitch) diff --git a/Core/HLE/sceKernelThread.h b/Core/HLE/sceKernelThread.h index e26536c7e9..30b722a34f 100644 --- a/Core/HLE/sceKernelThread.h +++ b/Core/HLE/sceKernelThread.h @@ -85,6 +85,7 @@ enum WaitType WAITTYPE_LWMUTEX = 14, WAITTYPE_CTRL = 15, WAITTYPE_IO = 16, + WAITTYPE_GEDRAWSYNC = 17, NUM_WAITTYPES }; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index ef03985088..44122959c0 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -16,6 +16,7 @@ GPUCommon::GPUCommon() : currentList(NULL), isbreak(false), + drawComplete(true), dumpNextFrame_(false), dumpThisFrame_(false), interruptsEnabled_(true) @@ -42,17 +43,29 @@ u32 GPUCommon::DrawSync(int mode) { if (mode < 0 || mode > 1) return SCE_KERNEL_ERROR_INVALID_MODE; - while (currentList != NULL && currentList->state == PSP_GE_DL_STATE_COMPLETED) - PopDLQueue(); - - CheckDrawSync(); - if (mode == 0) { - // TODO: Wait. + // TODO: What if dispatch / interrupts disabled? + if (!drawComplete) { + __KernelWaitCurThread(WAITTYPE_GEDRAWSYNC, 1, 0, 0, false, "GeDrawSync"); + } else { + for (int i = 0; i < DisplayListMaxCount; ++i) { + if (dls[i].state == PSP_GE_DL_STATE_COMPLETED) { + dls[i].state = PSP_GE_DL_STATE_NONE; + } + } + } return 0; } - if (!currentList) + // If there's no current list, it must be complete. + DisplayList *top = NULL; + for (auto it = dlQueue.begin(), end = dlQueue.end(); it != end; ++it) { + if (dls[*it].state != PSP_GE_DL_STATE_COMPLETED) { + top = &dls[*it]; + break; + } + } + if (!top || top->state == PSP_GE_DL_STATE_COMPLETED) return PSP_GE_LIST_COMPLETED; if (currentList->pc == currentList->stall) @@ -161,7 +174,6 @@ u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, bool head) dl.startpc = listpc & 0xFFFFFFF; dl.pc = listpc & 0xFFFFFFF; dl.stall = stall & 0xFFFFFFF; - dl.state = PSP_GE_DL_STATE_QUEUED; dl.subIntrBase = std::max(subIntrBase, -1); dl.stackptr = 0; dl.signal = PSP_GE_SIGNAL_NONE; @@ -186,6 +198,8 @@ u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, bool head) currentList = &dl; dlQueue.push_front(id); + drawComplete = false; + // TODO save context when starting the list if param is set ProcessDLQueue(); } @@ -244,6 +258,9 @@ u32 GPUCommon::Continue() // TODO Restore context of DL is necessary // TODO Restore BASE + + // We have a list now, so it's not complete. + drawComplete = false; } else currentList->state = PSP_GE_DL_STATE_QUEUED; @@ -426,6 +443,17 @@ bool GPUCommon::ProcessDLQueue() } } currentList = NULL; + + drawComplete = true; + if (__KernelTriggerWait(WAITTYPE_GEDRAWSYNC, 1, 0, "GeDrawSync")) + { + for (int i = 0; i < DisplayListMaxCount; ++i) { + if (dls[i].state == PSP_GE_DL_STATE_COMPLETED) { + dls[i].state = PSP_GE_DL_STATE_NONE; + } + } + } + return true; //no more lists! } @@ -586,6 +614,7 @@ void GPUCommon::DoState(PointerWrap &p) { p.Do(prev); p.Do(gpuState); p.Do(isbreak); + p.Do(drawComplete); p.DoMarker("GPUCommon"); } diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index b27d40503f..6cc325c68b 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -43,6 +43,7 @@ protected: u32 prev; GPUState gpuState; bool isbreak; + bool drawComplete; u64 startingTicks; u32 cycleLastPC;