2013-01-10 22:49:33 +00:00
|
|
|
#include "base/timeutil.h"
|
2012-12-29 01:10:29 +00:00
|
|
|
#include "../Core/MemMap.h"
|
|
|
|
#include "GeDisasm.h"
|
2012-12-28 20:58:00 +00:00
|
|
|
#include "GPUCommon.h"
|
2012-12-29 01:10:29 +00:00
|
|
|
#include "GPUState.h"
|
2013-02-04 04:31:46 +00:00
|
|
|
#include "ChunkFile.h"
|
2013-02-10 15:36:06 +00:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
#include "Core/Host.h"
|
|
|
|
#endif
|
2012-12-28 20:58:00 +00:00
|
|
|
|
|
|
|
static int dlIdGenerator = 1;
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
dlIdGenerator = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPUCommon::listStatus(int listid)
|
|
|
|
{
|
2013-01-10 08:02:55 +00:00
|
|
|
for(DisplayListQueue::iterator it(dlQueue.begin()); it != dlQueue.end(); ++it)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
|
|
|
if(it->id == listid)
|
|
|
|
{
|
|
|
|
return it->status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0x80000100; // INVALID_ID
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:50:35 +00:00
|
|
|
u32 GPUCommon::EnqueueList(u32 listpc, u32 stall, int subIntrBase, bool head)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
|
|
|
DisplayList dl;
|
|
|
|
dl.id = dlIdGenerator++;
|
2013-02-10 15:36:06 +00:00
|
|
|
dl.startpc = listpc & 0xFFFFFFF;
|
2012-12-28 20:58:00 +00:00
|
|
|
dl.pc = listpc & 0xFFFFFFF;
|
|
|
|
dl.stall = stall & 0xFFFFFFF;
|
|
|
|
dl.status = PSP_GE_LIST_QUEUED;
|
2012-12-22 06:50:35 +00:00
|
|
|
dl.subIntrBase = subIntrBase;
|
2012-12-28 20:58:00 +00:00
|
|
|
if(head)
|
|
|
|
dlQueue.push_front(dl);
|
|
|
|
else
|
|
|
|
dlQueue.push_back(dl);
|
|
|
|
ProcessDLQueue();
|
|
|
|
return dl.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::UpdateStall(int listid, u32 newstall)
|
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
for (auto iter = dlQueue.begin(); iter != dlQueue.end(); ++iter)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
DisplayList &cur = *iter;
|
|
|
|
if (cur.id == listid)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2013-01-09 21:13:09 +00:00
|
|
|
cur.stall = newstall & 0xFFFFFFF;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessDLQueue();
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::InterpretList(DisplayList &list)
|
|
|
|
{
|
2013-01-10 22:49:33 +00:00
|
|
|
time_update();
|
|
|
|
double start = time_now_d();
|
2012-12-29 01:10:29 +00:00
|
|
|
currentList = &list;
|
|
|
|
// Reset stackptr for safety
|
|
|
|
stackptr = 0;
|
|
|
|
u32 op = 0;
|
|
|
|
prev = 0;
|
|
|
|
finished = false;
|
2013-01-29 16:07:36 +00:00
|
|
|
|
2013-02-02 22:47:35 +00:00
|
|
|
// I don't know if this is the correct place to zero this, but something
|
|
|
|
// need to do it. See Sol Trigger title screen.
|
|
|
|
gstate_c.offsetAddr = 0;
|
|
|
|
|
2013-01-29 16:07:36 +00:00
|
|
|
if (!Memory::IsValidAddress(list.pc)) {
|
|
|
|
ERROR_LOG(G3D, "DL PC = %08x WTF!!!!", list.pc);
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-17 00:06:06 +00:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
if(host->GpuStep())
|
|
|
|
{
|
|
|
|
host->SendGPUStart();
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-29 16:07:36 +00:00
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
while (!finished)
|
|
|
|
{
|
|
|
|
list.status = PSP_GE_LIST_DRAWING;
|
|
|
|
if (list.pc == list.stall)
|
|
|
|
{
|
|
|
|
list.status = PSP_GE_LIST_STALL_REACHED;
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-17 00:06:06 +00:00
|
|
|
|
|
|
|
op = Memory::ReadUnchecked_U32(list.pc); //read from memory
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
|
2013-02-10 15:36:06 +00:00
|
|
|
#if defined(USING_QT_UI)
|
|
|
|
if(host->GpuStep())
|
|
|
|
{
|
2013-02-17 17:25:43 +00:00
|
|
|
host->SendGPUWait(cmd, list.pc, &gstate);
|
2013-02-10 15:36:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-12-29 01:10:29 +00:00
|
|
|
u32 diff = op ^ gstate.cmdmem[cmd];
|
|
|
|
PreExecuteOp(op, diff);
|
|
|
|
// TODO: Add a compiler flag to remove stuff like this at very-final build time.
|
|
|
|
if (dumpThisFrame_) {
|
|
|
|
char temp[256];
|
|
|
|
GeDisassembleOp(list.pc, op, prev, temp);
|
|
|
|
NOTICE_LOG(G3D, "%s", temp);
|
|
|
|
}
|
|
|
|
gstate.cmdmem[cmd] = op; // crashes if I try to put the whole op there??
|
|
|
|
|
|
|
|
ExecuteOp(op, diff);
|
|
|
|
|
|
|
|
list.pc += 4;
|
|
|
|
prev = op;
|
|
|
|
}
|
2013-01-10 22:49:33 +00:00
|
|
|
time_update();
|
|
|
|
gpuStats.msProcessingDisplayLists += time_now_d() - start;
|
2012-12-29 01:10:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUCommon::ProcessDLQueue()
|
|
|
|
{
|
|
|
|
DisplayListQueue::iterator iter = dlQueue.begin();
|
2013-01-10 22:49:33 +00:00
|
|
|
while (iter != dlQueue.end())
|
2012-12-29 01:10:29 +00:00
|
|
|
{
|
|
|
|
DisplayList &l = *iter;
|
|
|
|
DEBUG_LOG(G3D,"Okay, starting DL execution at %08x - stall = %08x", l.pc, l.stall);
|
|
|
|
if (!InterpretList(l))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//At the end, we can remove it from the queue and continue
|
|
|
|
dlQueue.erase(iter);
|
|
|
|
//this invalidated the iterator, let's fix it
|
|
|
|
iter = dlQueue.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true; //no more lists!
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::PreExecuteOp(u32 op, u32 diff) {
|
|
|
|
// Nothing to do
|
2012-12-29 19:41:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPUCommon::DoState(PointerWrap &p) {
|
|
|
|
p.Do(dlIdGenerator);
|
|
|
|
p.Do<DisplayList>(dlQueue);
|
2013-02-12 09:06:11 +00:00
|
|
|
int currentID = currentList == NULL ? 0 : currentList->id;
|
|
|
|
p.Do(currentID);
|
|
|
|
if (currentID == 0) {
|
|
|
|
currentList = 0;
|
|
|
|
} else {
|
|
|
|
for (auto it = dlQueue.begin(), end = dlQueue.end(); it != end; ++it) {
|
|
|
|
if (it->id == currentID) {
|
|
|
|
currentList = &*it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.Do(interruptRunning);
|
|
|
|
p.Do(prev);
|
|
|
|
p.Do(stack);
|
|
|
|
p.Do(stackptr);
|
|
|
|
p.Do(finished);
|
2012-12-29 19:41:33 +00:00
|
|
|
p.DoMarker("GPUCommon");
|
|
|
|
}
|
2013-02-03 23:41:16 +00:00
|
|
|
|
|
|
|
void GPUCommon::InterruptStart()
|
|
|
|
{
|
|
|
|
interruptRunning = true;
|
|
|
|
}
|
|
|
|
void GPUCommon::InterruptEnd()
|
|
|
|
{
|
|
|
|
interruptRunning = false;
|
|
|
|
ProcessDLQueue();
|
|
|
|
}
|