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;
|
|
|
|
|
2015-07-26 20:38:40 +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();
|
2015-07-26 20:38:40 +00:00
|
|
|
virtual ~GPUCommon();
|
2015-09-05 19:23:58 +00:00
|
|
|
|
2013-11-28 23:34:41 +00:00
|
|
|
virtual void Reinitialize();
|
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);
|
2014-03-29 23:51:38 +00:00
|
|
|
virtual void SyncEnd(GPUSyncType 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
|
|
|
|
2014-04-16 15:12:21 +00:00
|
|
|
void Execute_OffsetAddr(u32 op, u32 diff);
|
|
|
|
void Execute_Origin(u32 op, u32 diff);
|
|
|
|
void Execute_Jump(u32 op, u32 diff);
|
|
|
|
void Execute_BJump(u32 op, u32 diff);
|
|
|
|
void Execute_Call(u32 op, u32 diff);
|
|
|
|
void Execute_Ret(u32 op, u32 diff);
|
|
|
|
void Execute_End(u32 op, u32 diff);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-12-01 02:39:16 +00:00
|
|
|
virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-14 15:42:18 +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 void NotifySteppingEnter();
|
|
|
|
virtual void NotifySteppingExit();
|
|
|
|
|
|
|
|
virtual u32 GetRelativeAddress(u32 data);
|
|
|
|
virtual u32 GetVertexAddress();
|
|
|
|
virtual u32 GetIndexAddress();
|
|
|
|
virtual GPUgstate GetGState();
|
|
|
|
virtual void SetCmdValue(u32 op);
|
|
|
|
|
|
|
|
virtual DisplayList* getList(int listid) {
|
|
|
|
return &dls[listid];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::list<int>& GetDisplayLists() {
|
|
|
|
return dlQueue;
|
|
|
|
}
|
2015-01-17 19:57:07 +00:00
|
|
|
virtual bool DecodeTexture(u8* dest, const GPUgstate &state) {
|
2014-06-14 15:42:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::vector<FramebufferInfo> GetFramebufferList() {
|
|
|
|
return std::vector<FramebufferInfo>();
|
|
|
|
}
|
|
|
|
virtual void ClearShaderCache() {}
|
2014-06-23 04:42:29 +00:00
|
|
|
virtual void CleanupBeforeUI() {}
|
2014-06-14 15:42:18 +00:00
|
|
|
|
2015-10-14 15:45:21 +00:00
|
|
|
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override { return std::vector<std::string>(); };
|
|
|
|
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override {
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
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);
|
2014-04-05 19:04:10 +00:00
|
|
|
void UpdatePC(u32 currentPC, u32 newPC);
|
|
|
|
void UpdatePC(u32 currentPC) {
|
|
|
|
UpdatePC(currentPC, currentPC);
|
|
|
|
}
|
2015-07-26 20:38:40 +00:00
|
|
|
void UpdateState(GPURunState 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();
|
2015-09-06 10:23:14 +00:00
|
|
|
virtual void ReapplyGfxStateInternal();
|
2014-03-03 02:12:40 +00:00
|
|
|
virtual void FastLoadBoneMatrix(u32 target);
|
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;
|
|
|
|
}
|
2015-03-15 01:11:00 +00:00
|
|
|
virtual void FinishDeferred() {
|
|
|
|
}
|
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;
|
2015-07-26 20:38:40 +00:00
|
|
|
GPURunState 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
|
|
|
}
|
|
|
|
|
2014-06-14 15:42:18 +00:00
|
|
|
// Debug stats.
|
|
|
|
double timeSteppingStarted_;
|
|
|
|
double timeSpentStepping_;
|
2013-02-03 23:41:16 +00:00
|
|
|
};
|