Merge branch 'VideoSoftware-savestates'

This commit is contained in:
Rachel Bryk
2013-02-28 13:36:29 -05:00
21 changed files with 203 additions and 12 deletions

View File

@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
static std::thread g_save_thread; static std::thread g_save_thread;
// Don't forget to increase this after doing changes on the savestate system // Don't forget to increase this after doing changes on the savestate system
static const u32 STATE_VERSION = 14; static const u32 STATE_VERSION = 15;
struct StateHeader struct StateHeader
{ {

View File

@ -186,6 +186,11 @@ void VideoBackendHardware::InitializeShared()
// Run from the CPU thread // Run from the CPU thread
void VideoBackendHardware::DoState(PointerWrap& p) void VideoBackendHardware::DoState(PointerWrap& p)
{ {
bool software = false;
p.Do(software);
if (p.GetMode() == PointerWrap::MODE_READ && software == true)
// change mode to abort load of incompatible save state.
p.SetMode(PointerWrap::MODE_VERIFY);
VideoCommon_DoState(p); VideoCommon_DoState(p);
p.DoMarker("VideoCommon"); p.DoMarker("VideoCommon");

View File

@ -65,6 +65,13 @@ namespace Clipper
OutputVertexData ClippedVertices[NUM_CLIPPED_VERTICES]; OutputVertexData ClippedVertices[NUM_CLIPPED_VERTICES];
OutputVertexData *Vertices[NUM_INDICES]; OutputVertexData *Vertices[NUM_INDICES];
void DoState(PointerWrap &p)
{
p.DoArray(m_ViewOffset,2);
for (int i = 0; i< NUM_CLIPPED_VERTICES; ++i)
ClippedVertices[i].DoState(p);
}
void Init() void Init()
{ {
for (int i = 0; i < NUM_CLIPPED_VERTICES; ++i) for (int i = 0; i < NUM_CLIPPED_VERTICES; ++i)

View File

@ -21,6 +21,7 @@
#include "Common.h" #include "Common.h"
#include "NativeVertexFormat.h" #include "NativeVertexFormat.h"
#include "ChunkFile.h"
namespace Clipper namespace Clipper
@ -36,6 +37,8 @@ namespace Clipper
bool CullTest(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2, bool &backface); bool CullTest(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2, bool &backface);
void PerspectiveDivide(OutputVertexData *vertex); void PerspectiveDivide(OutputVertexData *vertex);
void DoState(PointerWrap &p);
} }

View File

@ -28,6 +28,7 @@ u8 efb[EFB_WIDTH*EFB_HEIGHT*6];
namespace EfbInterface namespace EfbInterface
{ {
u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4];
inline u32 GetColorOffset(u16 x, u16 y) inline u32 GetColorOffset(u16 x, u16 y)
@ -40,6 +41,12 @@ namespace EfbInterface
return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START; return (x + y * EFB_WIDTH) * 3 + DEPTH_BUFFER_START;
} }
void DoState(PointerWrap &p)
{
p.DoArray(efb, EFB_WIDTH*EFB_HEIGHT*6);
p.DoArray(efbColorTexture, EFB_WIDTH*EFB_HEIGHT*4);
}
void SetPixelAlphaOnly(u32 offset, u8 a) void SetPixelAlphaOnly(u32 offset, u8 a)
{ {
switch (bpmem.zcontrol.pixel_format) switch (bpmem.zcontrol.pixel_format)

View File

@ -47,6 +47,7 @@ namespace EfbInterface
void UpdateColorTexture(); void UpdateColorTexture();
extern u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; // RGBA format extern u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; // RGBA format
void DoState(PointerWrap &p);
} }
#endif #endif

View File

@ -19,6 +19,7 @@
#define _NATIVEVERTEXFORMAT_H #define _NATIVEVERTEXFORMAT_H
#include "Vec3.h" #include "Vec3.h"
#include "ChunkFile.h"
#ifdef WIN32 #ifdef WIN32
#define LOADERDECL __cdecl #define LOADERDECL __cdecl
@ -92,6 +93,18 @@ struct OutputVertexData
#undef LINTERP #undef LINTERP
#undef LINTERP_INT #undef LINTERP_INT
} }
void DoState(PointerWrap &p)
{
mvPosition.DoState(p);
p.Do(projectedPosition);
screenPosition.DoState(p);
for (int i = 0; i < 3;++i)
normal[i].DoState(p);
p.DoArray(color, sizeof color);
for (int i = 0; i < 8;++i)
texCoords[i].DoState(p);
}
}; };
#endif #endif

View File

@ -35,7 +35,6 @@ typedef void (*DecodingFunction)(u32);
namespace OpcodeDecoder namespace OpcodeDecoder
{ {
static DecodingFunction currentFunction = NULL; static DecodingFunction currentFunction = NULL;
static u32 minCommandSize; static u32 minCommandSize;
static u16 streamSize; static u16 streamSize;
@ -46,6 +45,20 @@ static bool inObjectStream;
static u8 lastPrimCmd; static u8 lastPrimCmd;
void DoState(PointerWrap &p)
{
p.Do(minCommandSize);
// Not sure what is wrong with this. Something(s) in here is causing dolphin to crash/hang when loading states saved from another run of dolphin. Doesn't seem too important anyway...
//vertexLoader.DoState(p);
p.Do(readOpcode);
p.Do(inObjectStream);
p.Do(lastPrimCmd);
p.Do(streamSize);
p.Do(streamAddress);
if (p.GetMode() == PointerWrap::MODE_READ)
ResetDecoding();
}
void DecodePrimitiveStream(u32 iBufferSize) void DecodePrimitiveStream(u32 iBufferSize)
{ {
u32 vertexSize = vertexLoader.GetVertexSize(); u32 vertexSize = vertexLoader.GetVertexSize();

View File

@ -20,6 +20,7 @@
#define _OPCODEDECODER_H_ #define _OPCODEDECODER_H_
#include "CommonTypes.h" #include "CommonTypes.h"
#include "ChunkFile.h"
namespace OpcodeDecoder namespace OpcodeDecoder
{ {
@ -57,6 +58,8 @@ namespace OpcodeDecoder
bool CommandRunnable(u32 iBufferSize); bool CommandRunnable(u32 iBufferSize);
void Run(u32 iBufferSize); void Run(u32 iBufferSize);
void DoState(PointerWrap &p);
} }
#endif #endif

View File

@ -62,6 +62,28 @@ s32 scissorBottom = 0;
Tev tev; Tev tev;
RasterBlock rasterBlock; RasterBlock rasterBlock;
void DoState(PointerWrap &p)
{
ZSlope.DoState(p);
WSlope.DoState(p);
for (int i=0;i<2;++i)
for (int n=0; n<4; ++n)
ColorSlopes[i][n].DoState(p);
for (int i=0;i<8;++i)
for (int n=0; n<3; ++n)
TexSlopes[i][n].DoState(p);
p.Do(vertex0X);
p.Do(vertex0Y);
p.Do(vertexOffsetX);
p.Do(vertexOffsetY);
p.Do(scissorLeft);
p.Do(scissorTop);
p.Do(scissorRight);
p.Do(scissorBottom);
tev.DoState(p);
p.Do(rasterBlock);
}
void Init() void Init()
{ {
tev.Init(); tev.Init();

View File

@ -19,6 +19,7 @@
#define _RASTERIZER_H_ #define _RASTERIZER_H_
#include "NativeVertexFormat.h" #include "NativeVertexFormat.h"
#include "ChunkFile.h"
namespace Rasterizer namespace Rasterizer
{ {
@ -37,6 +38,12 @@ namespace Rasterizer
float f0; float f0;
float GetValue(float dx, float dy) { return f0 + (dfdx * dx) + (dfdy * dy); } float GetValue(float dx, float dy) { return f0 + (dfdx * dx) + (dfdy * dy); }
void DoState(PointerWrap &p)
{
p.Do(dfdx);
p.Do(dfdy);
p.Do(f0);
}
}; };
struct RasterBlockPixel struct RasterBlockPixel
@ -53,6 +60,8 @@ namespace Rasterizer
s32 TextureLod[16]; s32 TextureLod[16];
bool TextureLinear[16]; bool TextureLinear[16];
}; };
void DoState(PointerWrap &p);
} }

View File

@ -57,6 +57,15 @@ CPReg cpreg; // shared between gfx and emulator thread
void DoState(PointerWrap &p) void DoState(PointerWrap &p)
{ {
p.Do(cpreg); p.Do(cpreg);
p.DoArray(commandBuffer, commandBufferSize);
p.Do(readPos);
p.Do(writePos);
p.Do(et_UpdateInterrupts);
p.Do(interruptSet);
p.Do(interruptWaiting);
// Is this right?
p.DoArray(g_pVideoData,writePos);
} }
// does it matter that there is no synchronization between threads during writes? // does it matter that there is no synchronization between threads during writes?

View File

@ -53,6 +53,8 @@ void DoState(PointerWrap &p)
p.Do(pereg); p.Do(pereg);
p.Do(g_bSignalTokenInterrupt); p.Do(g_bSignalTokenInterrupt);
p.Do(g_bSignalFinishInterrupt); p.Do(g_bSignalFinishInterrupt);
p.Do(et_SetTokenOnMainThread);
p.Do(et_SetFinishOnMainThread);
} }
void UpdateInterrupts(); void UpdateInterrupts();

View File

@ -328,4 +328,15 @@ void SWVertexLoader::LoadTexCoord(SWVertexLoader *vertexLoader, InputVertexData
vertexLoader->m_texCoordLoader[index](); vertexLoader->m_texCoordLoader[index]();
} }
void SWVertexLoader::DoState(PointerWrap &p)
{
p.DoArray(m_AttributeLoaders, sizeof m_AttributeLoaders);
p.Do(m_VertexSize);
p.Do(*m_CurrentVat);
p.Do(m_positionLoader);
p.Do(m_normalLoader);
p.DoArray(m_colorLoader, sizeof m_colorLoader);
p.Do(m_NumAttributeLoaders);
m_SetupUnit->DoState(p);
p.Do(m_TexGenSpecialCase);
}

View File

@ -22,6 +22,7 @@
#include "NativeVertexFormat.h" #include "NativeVertexFormat.h"
#include "CPMemLoader.h" #include "CPMemLoader.h"
#include "ChunkFile.h"
class SetupUnit; class SetupUnit;
@ -69,7 +70,7 @@ public:
u32 GetVertexSize() { return m_VertexSize; } u32 GetVertexSize() { return m_VertexSize; }
void LoadVertex(); void LoadVertex();
void DoState(PointerWrap &p);
}; };
#endif #endif

View File

@ -39,6 +39,9 @@
#include "FileUtil.h" #include "FileUtil.h"
#include "VideoBackend.h" #include "VideoBackend.h"
#include "Core.h" #include "Core.h"
#include "OpcodeDecoder.h"
#include "SWVertexLoader.h"
#include "SWStatistics.h"
#define VSYNC_ENABLED 0 #define VSYNC_ENABLED 0
@ -93,9 +96,33 @@ bool VideoSoftware::Initialize(void *&window_handle)
return true; return true;
} }
void VideoSoftware::DoState(PointerWrap&) void VideoSoftware::DoState(PointerWrap& p)
{ {
// NYI bool software = true;
p.Do(software);
if (p.GetMode() == PointerWrap::MODE_READ && software == false)
// change mode to abort load of incompatible save state.
p.SetMode(PointerWrap::MODE_VERIFY);
// TODO: incomplete?
SWCommandProcessor::DoState(p);
SWPixelEngine::DoState(p);
EfbInterface::DoState(p);
OpcodeDecoder::DoState(p);
Clipper::DoState(p);
p.Do(swxfregs);
p.Do(bpmem);
p.Do(swstats);
// CP Memory
p.DoArray(arraybases, 16);
p.DoArray(arraystrides, 16);
p.Do(MatrixIndexA);
p.Do(MatrixIndexB);
p.Do(g_VtxDesc.Hex);
p.DoArray(g_VtxAttr, 8);
p.DoMarker("CP Memory");
} }
void VideoSoftware::CheckInvalidState() void VideoSoftware::CheckInvalidState()

View File

@ -25,13 +25,13 @@
void SetupUnit::Init(u8 primitiveType) void SetupUnit::Init(u8 primitiveType)
{ {
m_PrimType = primitiveType; m_PrimType = primitiveType;
m_VertexCounter = 0; m_VertexCounter = 0;
m_VertPointer[0] = &m_Vertices[0]; m_VertPointer[0] = &m_Vertices[0];
m_VertPointer[1] = &m_Vertices[1]; m_VertPointer[1] = &m_Vertices[1];
m_VertPointer[2] = &m_Vertices[2]; m_VertPointer[2] = &m_Vertices[2];
m_VertWritePointer = m_VertPointer[0]; m_VertWritePointer = m_VertPointer[0];
} }
void SetupUnit::SetupVertex() void SetupUnit::SetupVertex()
@ -169,3 +169,21 @@ void SetupUnit::SetupLineStrip()
void SetupUnit::SetupPoint() void SetupUnit::SetupPoint()
{} {}
void SetupUnit::DoState(PointerWrap &p)
{
// TODO: some or all of this is making the save states stop working once dolphin is closed...sometimes (usually)
// I have no idea what specifically is wrong, or if this is even important. Disabling it doesn't seem to make any noticible difference...
/* p.Do(m_PrimType);
p.Do(m_VertexCounter);
for (int i = 0; i < 3; ++i)
m_Vertices[i].DoState(p);
if (p.GetMode() == PointerWrap::MODE_READ)
{
m_VertPointer[0] = &m_Vertices[0];
m_VertPointer[1] = &m_Vertices[1];
m_VertPointer[2] = &m_Vertices[2];
m_VertWritePointer = m_VertPointer[0];
}*/
}

View File

@ -21,6 +21,7 @@
#include "Common.h" #include "Common.h"
#include "NativeVertexFormat.h" #include "NativeVertexFormat.h"
#include "ChunkFile.h"
class SetupUnit class SetupUnit
{ {
@ -45,6 +46,7 @@ public:
OutputVertexData* GetVertex() { return m_VertWritePointer; } OutputVertexData* GetVertex() { return m_VertWritePointer; }
void SetupVertex(); void SetupVertex();
void DoState(PointerWrap &p);
}; };
#endif #endif

View File

@ -827,3 +827,31 @@ void Tev::SetRegColor(int reg, int comp, bool konst, s16 color)
Reg[reg][comp] = color; Reg[reg][comp] = color;
} }
} }
void Tev::DoState(PointerWrap &p)
{
p.DoArray(Reg, sizeof(Reg));
p.DoArray(KonstantColors, sizeof(KonstantColors));
p.DoArray(TexColor,4);
p.DoArray(RasColor,4);
p.DoArray(StageKonst,4);
p.DoArray(Zero16,4);
p.DoArray(FixedConstants,9);
p.Do(AlphaBump);
p.DoArray(IndirectTex, sizeof(IndirectTex));
p.Do(TexCoord);
p.DoArray(m_BiasLUT,4);
p.DoArray(m_ScaleLShiftLUT,4);
p.DoArray(m_ScaleRShiftLUT,4);
p.DoArray(Position,3);
p.DoArray(Color, sizeof(Color));
p.DoArray(Uv, 8);
p.DoArray(IndirectLod,4);
p.DoArray(IndirectLinear,4);
p.DoArray(TextureLod,16);
p.DoArray(TextureLinear,16);
}

View File

@ -19,6 +19,7 @@
#define _TEV_H_ #define _TEV_H_
#include "BPMemLoader.h" #include "BPMemLoader.h"
#include "ChunkFile.h"
class Tev class Tev
{ {
@ -96,6 +97,8 @@ public:
void SetRegColor(int reg, int comp, bool konst, s16 color); void SetRegColor(int reg, int comp, bool konst, s16 color);
enum { ALP_C, BLU_C, GRN_C, RED_C }; enum { ALP_C, BLU_C, GRN_C, RED_C };
void DoState(PointerWrap &p);
}; };
#endif #endif

View File

@ -20,6 +20,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "ChunkFile.h"
class Vec3 class Vec3
{ {
@ -111,6 +112,12 @@ public:
{ {
memset((void *)this,0,sizeof(float)*3); memset((void *)this,0,sizeof(float)*3);
} }
void DoState(PointerWrap &p)
{
p.Do(x);
p.Do(y);
p.Do(z);
}
}; };
#endif #endif