State saving progress. Most core state seems to be saved/loaded correctly, not so for video yet unfortunately.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@386 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-08-30 16:05:32 +00:00
parent 95eb8f9ef3
commit 4608333a56
11 changed files with 159 additions and 42 deletions

View File

@ -18,6 +18,15 @@
#ifndef _POINTERWRAP_H #ifndef _POINTERWRAP_H
#define _POINTERWRAP_H #define _POINTERWRAP_H
// Extremely simple serialization framework.
// (mis)-features:
// + Super fast
// + Very simple
// + Same code is used for serialization and deserializaition (in most cases)
// - Zero backwards/forwards compatibility
// - Serialization code for anything complex has to be manually written.
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
@ -25,6 +34,13 @@
#include "Common.h" #include "Common.h"
template <class T>
struct LinkedListItem : public T
{
LinkedListItem<T> *next;
};
class PointerWrap class PointerWrap
{ {
public: public:
@ -61,10 +77,14 @@ public:
// Store maps to file. Very useful. // Store maps to file. Very useful.
template<class T> template<class T>
void Do(std::map<unsigned int, T> &x) { void Do(std::map<unsigned int, T> &x) {
// TODO
PanicAlert("Do(map<>) does not yet work.");
} }
// Store vectors. // Store vectors.
template<class T> template<class T>
void Do(std::vector<T> &x) { void Do(std::vector<T> &x) {
// TODO
PanicAlert("Do(vector<>) does not yet work.");
} }
template<class T> template<class T>
@ -76,6 +96,12 @@ public:
void Do(T &x) { void Do(T &x) {
DoVoid((void *)&x, sizeof(x)); DoVoid((void *)&x, sizeof(x));
} }
template<class T>
void DoLinkedList(LinkedListItem<T> **list_start) {
// TODO
PanicAlert("Do(vector<>) does not yet work.");
}
}; };
#endif // _POINTERWRAP_H #endif // _POINTERWRAP_H

View File

@ -20,6 +20,7 @@
#include "Thread.h" #include "Thread.h"
#include "PowerPC/PowerPC.h" #include "PowerPC/PowerPC.h"
#include "CoreTiming.h" #include "CoreTiming.h"
#include "StringUtil.h"
// TODO(ector): Replace new/delete in this file with a simple memory pool // TODO(ector): Replace new/delete in this file with a simple memory pool
// Don't expect a massive speedup though. // Don't expect a massive speedup though.
@ -35,14 +36,16 @@ struct EventType
std::vector<EventType> event_types; std::vector<EventType> event_types;
struct Event struct BaseEvent
{ {
s64 time; s64 time;
u64 userdata; u64 userdata;
Event *next;
int type; int type;
// Event *next;
}; };
typedef LinkedListItem<BaseEvent> Event;
// STATE_TO_SAVE (how?) // STATE_TO_SAVE (how?)
Event *first; Event *first;
Event *tsFirst; Event *tsFirst;
@ -55,6 +58,8 @@ s64 idledCycles;
Common::CriticalSection externalEventSection; Common::CriticalSection externalEventSection;
void (*advanceCallback)(int cyclesExecuted);
int RegisterEvent(const char *name, TimedCallback callback) int RegisterEvent(const char *name, TimedCallback callback)
{ {
EventType type; EventType type;
@ -71,14 +76,72 @@ void UnregisterAllEvents()
event_types.clear(); event_types.clear();
} }
void Init()
{
downcount = maxSliceLength;
slicelength = maxSliceLength;
globalTimer = 0;
idledCycles = 0;
}
void Shutdown()
{
ClearPendingEvents();
UnregisterAllEvents();
}
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
{ {
externalEventSection.Enter(); externalEventSection.Enter();
p.Do(downcount); p.Do(downcount);
p.Do(slicelength); p.Do(slicelength);
p.Do(maxSliceLength);
p.Do(globalTimer); p.Do(globalTimer);
p.Do(idledCycles); p.Do(idledCycles);
// OK, here we're gonna need to specialize depending on the mode.
// Should do something generic to serialize linked lists.
switch (p.GetMode()) {
case PointerWrap::MODE_READ:
{
ClearPendingEvents();
if (first)
PanicAlert("Clear failed.");
int more_events = 0;
Event *prev = 0;
while (true) {
p.Do(more_events);
if (!more_events)
break;
Event *ev = new Event;
if (!prev)
first = ev;
else
prev->next = ev;
p.Do(ev->time);
p.Do(ev->type);
p.Do(ev->userdata);
ev->next = 0;
prev = ev;
ev = ev->next;
}
}
break;
case PointerWrap::MODE_MEASURE:
case PointerWrap::MODE_WRITE:
{
Event *ev = first;
int more_events = 1;
while (ev) {
p.Do(more_events);
p.Do(ev->time);
p.Do(ev->type);
p.Do(ev->userdata);
ev = ev->next;
}
more_events = 0;
p.Do(more_events);
break;
}
}
externalEventSection.Leave(); externalEventSection.Leave();
} }
@ -106,14 +169,12 @@ void ScheduleEvent_Threadsafe(int cyclesIntoFuture, int event_type, u64 userdata
externalEventSection.Leave(); externalEventSection.Leave();
} }
void Clear() void ClearPendingEvents()
{ {
globalTimer = 0;
idledCycles = 0;
while (first) while (first)
{ {
Event *e = first->next; Event *e = first->next;
delete [] first; delete first;
first = e; first = e;
} }
} }
@ -172,9 +233,6 @@ void ScheduleEvent(int cyclesIntoFuture, int event_type, u64 userdata)
AddEventToQueue(ne); AddEventToQueue(ne);
} }
void (*advanceCallback)(int cyclesExecuted);
void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted)) void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted))
{ {
advanceCallback = callback; advanceCallback = callback;
@ -302,5 +360,23 @@ void Idle()
Advance(); Advance();
} }
std::string GetScheduledEventsSummary()
{
Event *ptr = first;
std::string text = "Scheduled events\n";
text.reserve(1000);
while (ptr)
{
int t = ptr->type;
if (t < 0 || t >= event_types.size())
PanicAlert("Invalid event type %i", t);
const char *name = event_types[ptr->type].name;
if (!name)
name = "[unknown]";
text += StringFromFormat("%s : %i %08x%08x\n", event_types[ptr->type].name, ptr->time, ptr->userdata >> 32, ptr->userdata);
ptr = ptr->next;
}
return text;
}
}; // end of namespace }; // end of namespace

View File

@ -25,11 +25,18 @@
// callback. You then schedule events using the type id you get back. // callback. You then schedule events using the type id you get back.
#include "Common.h" #include "Common.h"
#include <string>
#include "ChunkFile.h" #include "ChunkFile.h"
namespace CoreTiming namespace CoreTiming
{ {
void Init();
void Shutdown();
typedef void (*TimedCallback)(u64 userdata, int cyclesLate); typedef void (*TimedCallback)(u64 userdata, int cyclesLate);
u64 GetTicks(); u64 GetTicks();
@ -58,13 +65,16 @@ void Advance();
// Pretend that the main CPU has executed enough cycles to reach the next event. // Pretend that the main CPU has executed enough cycles to reach the next event.
void Idle(); void Idle();
// Clear all pending events. This should ONLY be done on exit. // Clear all pending events. This should ONLY be done on exit or state load.
void Clear(); void ClearPendingEvents();
void LogPendingEvents(); void LogPendingEvents();
void SetMaximumSlice(int maximumSliceLength); void SetMaximumSlice(int maximumSliceLength);
void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted)); void RegisterAdvanceCallback(void (*callback)(int cyclesExecuted));
std::string GetScheduledEventsSummary();
extern int downcount; extern int downcount;
extern int slicelength; extern int slicelength;

View File

@ -45,6 +45,8 @@ namespace HW
{ {
void Init() void Init()
{ {
CoreTiming::Init();
Thunk_Init(); // not really hw, but this way we know it's inited first :P Thunk_Init(); // not really hw, but this way we know it's inited first :P
State_Init(); State_Init();
@ -83,8 +85,7 @@ namespace HW
State_Shutdown(); State_Shutdown();
Thunk_Shutdown(); Thunk_Shutdown();
CoreTiming::Shutdown();
CoreTiming::UnregisterAllEvents();
} }
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
@ -100,7 +101,6 @@ namespace HW
GPFifo::DoState(p); GPFifo::DoState(p);
ExpansionInterface::DoState(p); ExpansionInterface::DoState(p);
AudioInterface::DoState(p); AudioInterface::DoState(p);
CoreTiming::DoState(p);
WII_IPCInterface::DoState(p); WII_IPCInterface::DoState(p);
} }
} }

View File

@ -217,7 +217,6 @@ void Init()
void Shutdown() void Shutdown()
{ {
Common::Timer::RestoreResolution(); Common::Timer::RestoreResolution();
CoreTiming::Clear();
} }
} // namespace } // namespace

View File

@ -44,7 +44,6 @@ namespace PowerPC
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
{ {
p.Do(ppcState); p.Do(ppcState);
p.Do(state);
} }
void ResetRegisters() void ResetRegisters()

View File

@ -41,7 +41,7 @@ void DoState(PointerWrap &p)
PowerPC::DoState(p); PowerPC::DoState(p);
HW::DoState(p); HW::DoState(p);
CoreTiming::DoState(p); CoreTiming::DoState(p);
PluginVideo::Video_DoState(p.GetPPtr(), p.GetMode()); // PluginVideo::Video_DoState(p.GetPPtr(), p.GetMode());
} }
void SaveStateCallback(u64 userdata, int cyclesLate) void SaveStateCallback(u64 userdata, int cyclesLate)
@ -59,6 +59,7 @@ void SaveStateCallback(u64 userdata, int cyclesLate)
FILE *f = fopen(cur_filename.c_str(), "wb"); FILE *f = fopen(cur_filename.c_str(), "wb");
fwrite(buffer, sz, 1, f); fwrite(buffer, sz, 1, f);
fclose(f); fclose(f);
delete [] buffer; delete [] buffer;
Core::DisplayMessage("Saved State", 2000); Core::DisplayMessage("Saved State", 2000);
@ -68,17 +69,20 @@ void LoadStateCallback(u64 userdata, int cyclesLate)
{ {
Jit64::ClearCache(); Jit64::ClearCache();
FILE *f = fopen(cur_filename.c_str(), "r"); FILE *f = fopen(cur_filename.c_str(), "rb");
fseek(f, 0, SEEK_END); fseek(f, 0, SEEK_END);
int sz = ftell(f); int sz = ftell(f);
fseek(f, 0, SEEK_SET); fseek(f, 0, SEEK_SET);
u8 *buffer = new u8[sz]; u8 *buffer = new u8[sz];
fread(buffer, sz, 1, f); int x;
if (x=fread(buffer, 1, sz, f) != sz)
PanicAlert("wtf? %d %d", x, sz);
fclose(f); fclose(f);
u8 *ptr = buffer; u8 *ptr = buffer;
PointerWrap p(&ptr, PointerWrap::MODE_READ); PointerWrap p(&ptr, PointerWrap::MODE_READ);
DoState(p); DoState(p);
delete [] buffer;
Core::DisplayMessage("Loaded State", 2000); Core::DisplayMessage("Loaded State", 2000);
} }

View File

@ -33,16 +33,15 @@ static int size = 0;
static int readptr = 0; static int readptr = 0;
void Fifo_DoState(PointerWrap &p) { void Fifo_DoState(PointerWrap &p) {
p.Do(size);
p.DoArray(videoBuffer, size); p.DoArray(videoBuffer, size);
p.Do(size);
p.Do(readptr); p.Do(readptr);
} }
void Fifo_Init() void Fifo_Init()
{ {
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE); videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
fifo.Init(videoBuffer, videoBuffer); //zero length. there is no data yet. fifo.Init(videoBuffer, videoBuffer); //zero length. there is no data yet.
} }
void Fifo_Shutdown() void Fifo_Shutdown()

View File

@ -23,22 +23,25 @@
#include "TextureDecoder.h" #include "TextureDecoder.h"
#include "Fifo.h" #include "Fifo.h"
static void DoState(PointerWrap &p) {
// BP Memory
p.Do(bpmem);
// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
// XF Memory
p.Do(xfregs);
p.DoArray(xfmem, XFMEM_SIZE);
// Texture decoder
p.DoArray(texMem, TMEM_SIZE);
// FIFO
Fifo_DoState(p);
}
void VideoCommon_DoState(PointerWrap &p) { void VideoCommon_DoState(PointerWrap &p) {
// BP Memory DoState(p);
p.Do(bpmem);
// CP Memory
p.Do(arraybases);
p.Do(arraystrides);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
// XF Memory
p.Do(xfregs);
p.Do(xfmem);
// Texture decoder
p.Do(texMem);
// FIFO
Fifo_DoState(p);
//TODO: search for more data that should be saved and add it here //TODO: search for more data that should be saved and add it here
} }

View File

@ -179,7 +179,7 @@ void VShaderCache::Cleanup()
for (VSCache::iterator iter=vshaders.begin(); iter!=vshaders.end();iter++) for (VSCache::iterator iter=vshaders.begin(); iter!=vshaders.end();iter++)
{ {
VSCacheEntry &entry = iter->second; VSCacheEntry &entry = iter->second;
if (entry.frameCount<frameCount-30) if (entry.frameCount < frameCount - 30)
{ {
entry.Destroy(); entry.Destroy();
iter = vshaders.erase(iter); iter = vshaders.erase(iter);

View File

@ -29,15 +29,16 @@
#include "IniFile.h" #include "IniFile.h"
#include <assert.h> #include <assert.h>
float MValueX, MValueY; // Since it can Stretch to fit Window, we need two different multiplication values// float MValueX, MValueY; // Since it can Stretch to fit Window, we need two different multiplication values//
int frameCount; int frameCount;
Config g_Config; Config g_Config;
Statistics stats; Statistics stats;
void Statistics::ResetFrame() void Statistics::ResetFrame()
{ {
memset(&thisFrame,0,sizeof(ThisFrame)); memset(&thisFrame, 0, sizeof(ThisFrame));
} }
Config::Config() Config::Config()