2013-04-02 06:54:19 +00:00
|
|
|
#include <algorithm>
|
2013-01-10 22:49:33 +00:00
|
|
|
#include "base/timeutil.h"
|
2012-12-29 01:10:29 +00:00
|
|
|
#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-04-03 15:10:35 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
2013-04-01 06:02:46 +00:00
|
|
|
#include "Core/MemMap.h"
|
2013-02-10 15:36:06 +00:00
|
|
|
#include "Core/Host.h"
|
2013-04-01 06:02:46 +00:00
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
#include "Core/HLE/sceGe.h"
|
2012-12-28 20:58:00 +00:00
|
|
|
|
|
|
|
static int dlIdGenerator = 1;
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
dlIdGenerator = 1;
|
|
|
|
}
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
u32 GPUCommon::DrawSync(int mode) {
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPUCommon::ListSync(int listid, int mode)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-04 06:05:54 +00:00
|
|
|
if (mode == 1) {
|
|
|
|
DisplayList *dl = NULL;
|
|
|
|
for (DisplayListQueue::iterator it(dlQueue.begin()); it != dlQueue.end(); ++it) {
|
|
|
|
if (it->id == listid) {
|
|
|
|
dl = &*it;
|
|
|
|
}
|
|
|
|
}
|
2013-04-01 06:23:03 +00:00
|
|
|
|
2013-04-04 06:05:54 +00:00
|
|
|
if (!dl)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
|
|
|
|
|
|
|
switch (dl->state) {
|
|
|
|
case PSP_GE_DL_STATE_QUEUED:
|
|
|
|
// TODO: interrupted -> return PSP_GE_LIST_PAUSED;
|
|
|
|
return PSP_GE_LIST_QUEUED;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_RUNNING:
|
|
|
|
if (dl->pc == dl->stall)
|
|
|
|
return PSP_GE_LIST_STALLING;
|
|
|
|
return PSP_GE_LIST_DRAWING;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_COMPLETED:
|
|
|
|
return PSP_GE_LIST_COMPLETED;
|
|
|
|
|
|
|
|
case PSP_GE_DL_STATE_PAUSED:
|
|
|
|
return PSP_GE_LIST_PAUSED;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_ID;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-04 06:05:54 +00:00
|
|
|
|
|
|
|
// TODO: Wait here for mode == 0.
|
|
|
|
return PSP_GE_LIST_COMPLETED;
|
2012-12-28 20:58:00 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2013-04-04 06:05:54 +00:00
|
|
|
dl.state = PSP_GE_DL_STATE_QUEUED;
|
2013-04-02 06:54:19 +00:00
|
|
|
dl.subIntrBase = std::max(subIntrBase, -1);
|
2013-04-01 06:28:35 +00:00
|
|
|
dl.stackptr = 0;
|
2013-04-02 06:54:19 +00:00
|
|
|
dl.signal = PSP_GE_SIGNAL_NONE;
|
2012-12-28 20:58:00 +00:00
|
|
|
if(head)
|
|
|
|
dlQueue.push_front(dl);
|
|
|
|
else
|
|
|
|
dlQueue.push_back(dl);
|
|
|
|
ProcessDLQueue();
|
|
|
|
return dl.id;
|
|
|
|
}
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
u32 GPUCommon::DequeueList(int listid)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::UpdateStall(int listid, u32 newstall)
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
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();
|
2013-04-01 06:23:03 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::Continue()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GPUCommon::Break(int mode)
|
|
|
|
{
|
2013-04-01 06:42:56 +00:00
|
|
|
if (mode < 0 || mode > 1)
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
|
2013-04-01 06:23:03 +00:00
|
|
|
// TODO
|
|
|
|
return 0;
|
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;
|
|
|
|
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
|
|
|
|
2013-04-03 15:10:35 +00:00
|
|
|
cycleLastPC = list.pc;
|
2013-04-04 06:05:54 +00:00
|
|
|
list.state = PSP_GE_DL_STATE_RUNNING;
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
while (!finished)
|
|
|
|
{
|
|
|
|
if (list.pc == list.stall)
|
|
|
|
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);
|
2013-03-04 21:15:39 +00:00
|
|
|
NOTICE_LOG(HLE, "%s", temp);
|
2012-12-29 01:10:29 +00:00
|
|
|
}
|
|
|
|
gstate.cmdmem[cmd] = op; // crashes if I try to put the whole op there??
|
|
|
|
|
|
|
|
ExecuteOp(op, diff);
|
|
|
|
|
|
|
|
list.pc += 4;
|
|
|
|
prev = op;
|
|
|
|
}
|
2013-04-03 15:10:35 +00:00
|
|
|
|
|
|
|
UpdateCycles(list.pc);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-03 15:10:35 +00:00
|
|
|
inline void GPUCommon::UpdateCycles(u32 pc, u32 newPC)
|
|
|
|
{
|
|
|
|
cyclesExecuted += (pc - cycleLastPC) / 4;
|
|
|
|
cycleLastPC = newPC == 0 ? pc : newPC;
|
|
|
|
}
|
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
bool GPUCommon::ProcessDLQueue()
|
|
|
|
{
|
2013-04-03 15:10:35 +00:00
|
|
|
startingTicks = CoreTiming::GetTicks();
|
|
|
|
cyclesExecuted = 0;
|
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-01 06:02:46 +00:00
|
|
|
void GPUCommon::ExecuteOp(u32 op, u32 diff) {
|
|
|
|
u32 cmd = op >> 24;
|
|
|
|
u32 data = op & 0xFFFFFF;
|
|
|
|
|
|
|
|
// Handle control and drawing commands here directly. The others we delegate.
|
|
|
|
switch (cmd) {
|
|
|
|
case GE_CMD_NOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_OFFSETADDR:
|
|
|
|
gstate_c.offsetAddr = data << 8;
|
|
|
|
// ???
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_ORIGIN:
|
|
|
|
gstate_c.offsetAddr = currentList->pc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_JUMP:
|
|
|
|
{
|
|
|
|
u32 target = gstate_c.getRelativeAddress(data);
|
|
|
|
if (Memory::IsValidAddress(target)) {
|
2013-04-03 15:10:35 +00:00
|
|
|
UpdateCycles(currentList->pc, target - 4);
|
2013-04-01 06:02:46 +00:00
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
|
|
|
} else {
|
|
|
|
ERROR_LOG(G3D, "JUMP to illegal address %08x - ignoring! data=%06x", target, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_CALL:
|
|
|
|
{
|
|
|
|
// Saint Seiya needs correct support for relative calls.
|
|
|
|
u32 retval = currentList->pc + 4;
|
|
|
|
u32 target = gstate_c.getRelativeAddress(data);
|
2013-04-01 06:28:35 +00:00
|
|
|
if (currentList->stackptr == ARRAY_SIZE(currentList->stack)) {
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "CALL: Stack full!");
|
|
|
|
} else if (!Memory::IsValidAddress(target)) {
|
|
|
|
ERROR_LOG(G3D, "CALL to illegal address %08x - ignoring! data=%06x", target, data);
|
|
|
|
} else {
|
2013-04-01 06:28:35 +00:00
|
|
|
currentList->stack[currentList->stackptr++] = retval;
|
2013-04-03 15:10:35 +00:00
|
|
|
UpdateCycles(currentList->pc, target - 4);
|
2013-04-01 06:02:46 +00:00
|
|
|
currentList->pc = target - 4; // pc will be increased after we return, counteract that
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_RET:
|
|
|
|
{
|
2013-04-01 06:28:35 +00:00
|
|
|
if (currentList->stackptr == 0) {
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "RET: Stack empty!");
|
|
|
|
} else {
|
2013-04-01 06:28:35 +00:00
|
|
|
u32 target = (currentList->pc & 0xF0000000) | (currentList->stack[--currentList->stackptr] & 0x0FFFFFFF);
|
2013-04-01 06:02:46 +00:00
|
|
|
//target = (target + gstate_c.originAddr) & 0xFFFFFFF;
|
2013-04-03 15:10:35 +00:00
|
|
|
UpdateCycles(currentList->pc, target - 4);
|
2013-04-01 06:02:46 +00:00
|
|
|
currentList->pc = target - 4;
|
|
|
|
if (!Memory::IsValidAddress(currentList->pc)) {
|
|
|
|
ERROR_LOG(G3D, "Invalid DL PC %08x on return", currentList->pc);
|
|
|
|
finished = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_SIGNAL:
|
|
|
|
case GE_CMD_FINISH:
|
2013-04-03 15:15:49 +00:00
|
|
|
// Processed in GE_END.
|
2013-04-01 06:02:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GE_CMD_END:
|
2013-04-03 15:10:35 +00:00
|
|
|
UpdateCycles(currentList->pc);
|
2013-04-01 06:02:46 +00:00
|
|
|
switch (prev >> 24) {
|
|
|
|
case GE_CMD_SIGNAL:
|
|
|
|
{
|
|
|
|
// TODO: see http://code.google.com/p/jpcsp/source/detail?r=2935#
|
|
|
|
int behaviour = (prev >> 16) & 0xFF;
|
|
|
|
int signal = prev & 0xFFFF;
|
|
|
|
int enddata = data & 0xFFFF;
|
2013-04-02 06:54:19 +00:00
|
|
|
currentList->subIntrToken = signal;
|
|
|
|
|
2013-04-01 06:02:46 +00:00
|
|
|
switch (behaviour) {
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_HANDLER_SUSPEND:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Wait UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_HANDLER_CONTINUE:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal without wait. signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_HANDLER_PAUSE:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Pause UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_SYNC:
|
|
|
|
ERROR_LOG(G3D, "Signal with Sync UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
case PSP_GE_SIGNAL_JUMP:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Jump UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_CALL:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Call UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
2013-04-02 06:54:19 +00:00
|
|
|
case PSP_GE_SIGNAL_RET:
|
2013-04-01 06:02:46 +00:00
|
|
|
ERROR_LOG(G3D, "Signal with Return UNIMPLEMENTED! signal/end: %04x %04x", signal, enddata);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR_LOG(G3D, "UNKNOWN Signal UNIMPLEMENTED %i ! signal/end: %04x %04x", behaviour, signal, enddata);
|
|
|
|
break;
|
|
|
|
}
|
2013-04-02 06:54:19 +00:00
|
|
|
if (currentList->subIntrBase >= 0 && interruptsEnabled_)
|
2013-04-01 06:02:46 +00:00
|
|
|
__GeTriggerInterrupt(currentList->id, currentList->pc, currentList->subIntrBase, currentList->subIntrToken);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GE_CMD_FINISH:
|
2013-04-04 06:05:54 +00:00
|
|
|
currentList->state = PSP_GE_DL_STATE_COMPLETED;
|
2013-04-01 06:02:46 +00:00
|
|
|
finished = true;
|
2013-04-03 15:15:49 +00:00
|
|
|
currentList->subIntrToken = prev & 0xFFFF;
|
|
|
|
if (interruptsEnabled_)
|
|
|
|
__GeTriggerInterrupt(currentList->id, currentList->pc, currentList->subIntrBase, currentList->subIntrToken);
|
2013-04-01 06:02:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DEBUG_LOG(G3D,"Ah, not finished: %06x", prev & 0xFFFFFF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_LOG(G3D,"DL Unknown: %08x @ %08x", op, currentList == NULL ? 0 : currentList->pc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(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();
|
|
|
|
}
|