2012-12-28 20:58:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2013-08-12 15:40:36 +00:00
|
|
|
#include "Common/Common.h"
|
2013-10-27 01:11:17 +00:00
|
|
|
#include "Common/MemoryUtil.h"
|
2013-08-10 16:08:31 +00:00
|
|
|
#include "Core/ThreadEventQueue.h"
|
2013-08-08 06:27:29 +00:00
|
|
|
#include "GPU/GPUInterface.h"
|
2013-09-22 07:18:46 +00:00
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
2012-12-28 20:58:00 +00:00
|
|
|
|
2013-08-12 15:51:19 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
#include <atomic>
|
|
|
|
#elif defined(_M_SSE)
|
2013-08-12 15:40:36 +00:00
|
|
|
#include <xmmintrin.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-10 10:33:09 +00:00
|
|
|
typedef ThreadEventQueue<GPUInterface, GPUEvent, GPUEventType, GPU_EVENT_INVALID, GPU_EVENT_SYNC_THREAD, GPU_EVENT_FINISH_EVENT_LOOP> GPUThreadEventQueue;
|
|
|
|
|
2013-09-22 17:22:33 +00:00
|
|
|
class GPUCommon : public GPUThreadEventQueue, public GPUDebugInterface
|
2012-12-28 20:58:00 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-04-05 06:19:28 +00:00
|
|
|
GPUCommon();
|
|
|
|
virtual ~GPUCommon() {}
|
2012-12-29 01:10:29 +00:00
|
|
|
|
2013-04-06 15:19:54 +00:00
|
|
|
virtual void InterruptStart(int listid);
|
|
|
|
virtual void InterruptEnd(int listid);
|
2013-04-07 19:45:42 +00:00
|
|
|
virtual void SyncEnd(WaitType waitType, int listid, bool wokeThreads);
|
2013-04-01 06:02:46 +00:00
|
|
|
virtual void EnableInterrupts(bool enable) {
|
|
|
|
interruptsEnabled_ = enable;
|
|
|
|
}
|
2013-02-03 23:41:16 +00:00
|
|
|
|
2013-04-01 06:02:46 +00:00
|
|
|
virtual void ExecuteOp(u32 op, u32 diff);
|
2012-12-29 01:10:29 +00:00
|
|
|
virtual void PreExecuteOp(u32 op, u32 diff);
|
|
|
|
virtual bool InterpretList(DisplayList &list);
|
|
|
|
virtual bool ProcessDLQueue();
|
2013-04-01 06:23:03 +00:00
|
|
|
virtual u32 UpdateStall(int listid, u32 newstall);
|
2013-09-20 16:42:09 +00:00
|
|
|
virtual u32 EnqueueList(u32 listpc, u32 stall, int subIntrBase, PSPPointer<PspGeListArgs> args, bool head);
|
2013-04-01 06:23:03 +00:00
|
|
|
virtual u32 DequeueList(int listid);
|
|
|
|
virtual int ListSync(int listid, int mode);
|
|
|
|
virtual u32 DrawSync(int mode);
|
2013-09-21 17:03:49 +00:00
|
|
|
virtual int GetStack(int index, u32 stackPtr);
|
2012-12-29 19:41:33 +00:00
|
|
|
virtual void DoState(PointerWrap &p);
|
2013-08-11 01:45:07 +00:00
|
|
|
virtual bool FramebufferDirty() {
|
|
|
|
SyncThread();
|
|
|
|
return true;
|
|
|
|
}
|
2013-08-15 23:00:26 +00:00
|
|
|
virtual bool FramebufferReallyDirty() {
|
|
|
|
SyncThread();
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-22 02:31:54 +00:00
|
|
|
virtual bool BusyDrawing();
|
2013-04-01 06:23:03 +00:00
|
|
|
virtual u32 Continue();
|
|
|
|
virtual u32 Break(int mode);
|
2013-08-04 22:15:50 +00:00
|
|
|
virtual void ReapplyGfxState();
|
2012-12-28 20:58:00 +00:00
|
|
|
|
2013-08-11 20:41:42 +00:00
|
|
|
virtual u64 GetTickEstimate() {
|
2013-08-12 15:51:19 +00:00
|
|
|
#if defined(_M_X64) || defined(ANDROID)
|
2013-08-12 15:40:36 +00:00
|
|
|
return curTickEst_;
|
|
|
|
#elif defined(_M_SSE)
|
|
|
|
__m64 result = *(__m64 *)&curTickEst_;
|
2013-08-13 08:01:40 +00:00
|
|
|
u64 safeResult = *(u64 *)&result;
|
|
|
|
_mm_empty();
|
|
|
|
return safeResult;
|
2013-08-12 15:40:36 +00:00
|
|
|
#else
|
2013-08-11 20:41:42 +00:00
|
|
|
lock_guard guard(curTickEstLock_);
|
|
|
|
return curTickEst_;
|
2013-08-12 15:40:36 +00:00
|
|
|
#endif
|
2013-08-11 20:41:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-27 01:11:17 +00:00
|
|
|
void *operator new(size_t s) {
|
|
|
|
return AllocateAlignedMemory(s, 16);
|
|
|
|
}
|
|
|
|
void operator delete(void *p) {
|
|
|
|
FreeAlignedMemory(p);
|
|
|
|
}
|
|
|
|
|
2012-12-28 20:58:00 +00:00
|
|
|
protected:
|
2013-04-28 21:23:30 +00:00
|
|
|
// To avoid virtual calls to PreExecuteOp().
|
|
|
|
virtual void FastRunLoop(DisplayList &list) = 0;
|
|
|
|
void SlowRunLoop(DisplayList &list);
|
2013-04-28 20:34:29 +00:00
|
|
|
void UpdatePC(u32 currentPC, u32 newPC = 0);
|
|
|
|
void UpdateState(GPUState state);
|
2013-04-05 06:19:28 +00:00
|
|
|
void PopDLQueue();
|
|
|
|
void CheckDrawSync();
|
2013-08-04 23:31:11 +00:00
|
|
|
int GetNextListIndex();
|
2013-08-08 06:59:32 +00:00
|
|
|
void ProcessDLQueueInternal();
|
|
|
|
void ReapplyGfxStateInternal();
|
2013-08-10 10:33:09 +00:00
|
|
|
virtual void ProcessEvent(GPUEvent ev);
|
2013-08-11 18:40:41 +00:00
|
|
|
virtual bool ShouldExitEventLoop() {
|
|
|
|
return coreState != CORE_RUNNING;
|
|
|
|
}
|
2013-04-03 15:10:35 +00:00
|
|
|
|
2013-08-09 08:03:54 +00:00
|
|
|
// Allows early unlocking with a guard. Do not double unlock.
|
2013-08-09 07:32:40 +00:00
|
|
|
class easy_guard {
|
|
|
|
public:
|
|
|
|
easy_guard(recursive_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); }
|
|
|
|
~easy_guard() { if (locked_) mtx_.unlock(); }
|
2013-08-09 08:03:54 +00:00
|
|
|
void unlock() { if (locked_) mtx_.unlock(); else Crash(); locked_ = false; }
|
2013-08-09 07:32:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
recursive_mutex &mtx_;
|
2013-08-10 16:38:47 +00:00
|
|
|
bool locked_;
|
2013-08-09 07:32:40 +00:00
|
|
|
};
|
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
typedef std::list<int> DisplayListQueue;
|
2012-12-29 01:10:29 +00:00
|
|
|
|
2013-09-21 20:18:20 +00:00
|
|
|
int nextListID;
|
2013-04-05 06:19:28 +00:00
|
|
|
DisplayList dls[DisplayListMaxCount];
|
2012-12-28 20:58:00 +00:00
|
|
|
DisplayList *currentList;
|
|
|
|
DisplayListQueue dlQueue;
|
2013-08-08 06:27:29 +00:00
|
|
|
recursive_mutex listLock;
|
2012-12-29 01:10:29 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
bool interruptRunning;
|
2013-04-04 08:07:30 +00:00
|
|
|
GPUState gpuState;
|
2013-04-04 07:35:38 +00:00
|
|
|
bool isbreak;
|
2013-04-07 19:45:42 +00:00
|
|
|
u64 drawCompleteTicks;
|
2013-04-09 07:56:04 +00:00
|
|
|
u64 busyTicks;
|
2012-12-29 01:10:29 +00:00
|
|
|
|
2013-04-28 21:23:30 +00:00
|
|
|
int downcount;
|
2013-04-03 15:10:35 +00:00
|
|
|
u64 startingTicks;
|
|
|
|
u32 cycleLastPC;
|
|
|
|
int cyclesExecuted;
|
|
|
|
|
2012-12-29 01:10:29 +00:00
|
|
|
bool dumpNextFrame_;
|
|
|
|
bool dumpThisFrame_;
|
2013-04-01 06:02:46 +00:00
|
|
|
bool interruptsEnabled_;
|
2013-02-03 23:41:16 +00:00
|
|
|
|
2013-08-14 04:42:48 +00:00
|
|
|
private:
|
2013-08-11 20:41:42 +00:00
|
|
|
// For CPU/GPU sync.
|
2013-08-12 15:51:19 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
std::atomic<u64> curTickEst_;
|
|
|
|
#else
|
2013-08-12 15:40:36 +00:00
|
|
|
volatile MEMORY_ALIGNED16(u64) curTickEst_;
|
2013-08-11 20:41:42 +00:00
|
|
|
recursive_mutex curTickEstLock_;
|
2013-08-12 15:51:19 +00:00
|
|
|
#endif
|
2013-08-11 20:41:42 +00:00
|
|
|
|
2013-08-14 04:42:48 +00:00
|
|
|
inline void UpdateTickEstimate(u64 value) {
|
2013-08-12 15:51:19 +00:00
|
|
|
#if defined(_M_X64) || defined(ANDROID)
|
2013-08-12 15:40:36 +00:00
|
|
|
curTickEst_ = value;
|
|
|
|
#elif defined(_M_SSE)
|
|
|
|
__m64 result = *(__m64 *)&value;
|
|
|
|
*(__m64 *)&curTickEst_ = result;
|
2013-08-13 08:01:40 +00:00
|
|
|
_mm_empty();
|
2013-08-12 15:40:36 +00:00
|
|
|
#else
|
2013-08-11 20:41:42 +00:00
|
|
|
lock_guard guard(curTickEstLock_);
|
|
|
|
curTickEst_ = value;
|
2013-08-12 15:40:36 +00:00
|
|
|
#endif
|
2013-08-11 20:41:42 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
public:
|
2013-09-22 17:22:33 +00:00
|
|
|
// From GPUDebugInterface.
|
|
|
|
virtual bool GetCurrentDisplayList(DisplayList &list);
|
|
|
|
virtual std::vector<DisplayList> ActiveDisplayLists();
|
|
|
|
virtual void ResetListPC(int listID, u32 pc);
|
|
|
|
virtual void ResetListStall(int listID, u32 stall);
|
|
|
|
virtual void ResetListState(int listID, DisplayListState state);
|
|
|
|
|
|
|
|
virtual GPUDebugOp DissassembleOp(u32 pc, u32 op);
|
|
|
|
virtual std::vector<GPUDebugOp> DissassembleOpRange(u32 startpc, u32 endpc);
|
|
|
|
|
|
|
|
virtual u32 GetRelativeAddress(u32 data);
|
|
|
|
virtual u32 GetVertexAddress();
|
|
|
|
virtual u32 GetIndexAddress();
|
|
|
|
virtual GPUgstate GetGState();
|
2013-10-07 02:17:06 +00:00
|
|
|
virtual void SetCmdValue(u32 op);
|
2013-09-22 17:22:33 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
virtual DisplayList* getList(int listid)
|
|
|
|
{
|
2013-04-05 06:19:28 +00:00
|
|
|
return &dls[listid];
|
2013-02-03 23:41:16 +00:00
|
|
|
}
|
2013-02-10 15:36:06 +00:00
|
|
|
|
2013-04-05 06:19:28 +00:00
|
|
|
const std::list<int>& GetDisplayLists()
|
2013-02-10 15:36:06 +00:00
|
|
|
{
|
|
|
|
return dlQueue;
|
|
|
|
}
|
2013-02-17 00:06:06 +00:00
|
|
|
virtual bool DecodeTexture(u8* dest, GPUgstate state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::vector<FramebufferInfo> GetFramebufferList()
|
|
|
|
{
|
|
|
|
return std::vector<FramebufferInfo>();
|
|
|
|
}
|
2013-10-22 12:34:16 +00:00
|
|
|
virtual void ClearShaderCache() {}
|
2013-02-03 23:41:16 +00:00
|
|
|
};
|