Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'VideoSoftware-savestates'
  • Loading branch information
RachelBryk committed Feb 28, 2013
2 parents 07539b9 + 46f5c19 commit 0c16489
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/State.cpp
Expand Up @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
static std::thread g_save_thread;

// 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
{
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/VideoCommon/Src/MainBase.cpp
Expand Up @@ -186,6 +186,11 @@ void VideoBackendHardware::InitializeShared()
// Run from the CPU thread
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);
p.DoMarker("VideoCommon");

Expand Down
7 changes: 7 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/Clipper.cpp
Expand Up @@ -65,6 +65,13 @@ namespace Clipper
OutputVertexData ClippedVertices[NUM_CLIPPED_VERTICES];
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()
{
for (int i = 0; i < NUM_CLIPPED_VERTICES; ++i)
Expand Down
3 changes: 3 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/Clipper.h
Expand Up @@ -21,6 +21,7 @@

#include "Common.h"
#include "NativeVertexFormat.h"
#include "ChunkFile.h"


namespace Clipper
Expand All @@ -36,6 +37,8 @@ namespace Clipper
bool CullTest(OutputVertexData *v0, OutputVertexData *v1, OutputVertexData *v2, bool &backface);

void PerspectiveDivide(OutputVertexData *vertex);

void DoState(PointerWrap &p);
}


Expand Down
7 changes: 7 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.cpp
Expand Up @@ -28,6 +28,7 @@ u8 efb[EFB_WIDTH*EFB_HEIGHT*6];

namespace EfbInterface
{

u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4];

inline u32 GetColorOffset(u16 x, u16 y)
Expand All @@ -40,6 +41,12 @@ namespace EfbInterface
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)
{
switch (bpmem.zcontrol.pixel_format)
Expand Down
1 change: 1 addition & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/EfbInterface.h
Expand Up @@ -47,6 +47,7 @@ namespace EfbInterface

void UpdateColorTexture();
extern u8 efbColorTexture[EFB_WIDTH*EFB_HEIGHT*4]; // RGBA format
void DoState(PointerWrap &p);
}

#endif
13 changes: 13 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/NativeVertexFormat.h
Expand Up @@ -19,6 +19,7 @@
#define _NATIVEVERTEXFORMAT_H

#include "Vec3.h"
#include "ChunkFile.h"

#ifdef WIN32
#define LOADERDECL __cdecl
Expand Down Expand Up @@ -92,6 +93,18 @@ struct OutputVertexData
#undef LINTERP
#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
15 changes: 14 additions & 1 deletion Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.cpp
Expand Up @@ -35,7 +35,6 @@ typedef void (*DecodingFunction)(u32);

namespace OpcodeDecoder
{

static DecodingFunction currentFunction = NULL;
static u32 minCommandSize;
static u16 streamSize;
Expand All @@ -46,6 +45,20 @@ static bool inObjectStream;
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)
{
u32 vertexSize = vertexLoader.GetVertexSize();
Expand Down
3 changes: 3 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/OpcodeDecoder.h
Expand Up @@ -20,6 +20,7 @@
#define _OPCODEDECODER_H_

#include "CommonTypes.h"
#include "ChunkFile.h"

namespace OpcodeDecoder
{
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace OpcodeDecoder
bool CommandRunnable(u32 iBufferSize);

void Run(u32 iBufferSize);

void DoState(PointerWrap &p);
}

#endif
22 changes: 22 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.cpp
Expand Up @@ -62,6 +62,28 @@ s32 scissorBottom = 0;
Tev tev;
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()
{
tev.Init();
Expand Down
9 changes: 9 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/Rasterizer.h
Expand Up @@ -19,6 +19,7 @@
#define _RASTERIZER_H_

#include "NativeVertexFormat.h"
#include "ChunkFile.h"

namespace Rasterizer
{
Expand All @@ -37,6 +38,12 @@ namespace Rasterizer
float f0;

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
Expand All @@ -53,6 +60,8 @@ namespace Rasterizer
s32 TextureLod[16];
bool TextureLinear[16];
};

void DoState(PointerWrap &p);

}

Expand Down
Expand Up @@ -57,6 +57,15 @@ CPReg cpreg; // shared between gfx and emulator thread
void DoState(PointerWrap &p)
{
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?
Expand Down
2 changes: 2 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/SWPixelEngine.cpp
Expand Up @@ -53,6 +53,8 @@ void DoState(PointerWrap &p)
p.Do(pereg);
p.Do(g_bSignalTokenInterrupt);
p.Do(g_bSignalFinishInterrupt);
p.Do(et_SetTokenOnMainThread);
p.Do(et_SetFinishOnMainThread);
}

void UpdateInterrupts();
Expand Down
13 changes: 12 additions & 1 deletion Source/Plugins/Plugin_VideoSoftware/Src/SWVertexLoader.cpp
Expand Up @@ -328,4 +328,15 @@ void SWVertexLoader::LoadTexCoord(SWVertexLoader *vertexLoader, InputVertexData
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);
}
3 changes: 2 additions & 1 deletion Source/Plugins/Plugin_VideoSoftware/Src/SWVertexLoader.h
Expand Up @@ -22,6 +22,7 @@

#include "NativeVertexFormat.h"
#include "CPMemLoader.h"
#include "ChunkFile.h"

class SetupUnit;

Expand Down Expand Up @@ -69,7 +70,7 @@ class SWVertexLoader
u32 GetVertexSize() { return m_VertexSize; }

void LoadVertex();

void DoState(PointerWrap &p);
};

#endif
31 changes: 29 additions & 2 deletions Source/Plugins/Plugin_VideoSoftware/Src/SWmain.cpp
Expand Up @@ -39,6 +39,9 @@
#include "FileUtil.h"
#include "VideoBackend.h"
#include "Core.h"
#include "OpcodeDecoder.h"
#include "SWVertexLoader.h"
#include "SWStatistics.h"

#define VSYNC_ENABLED 0

Expand Down Expand Up @@ -93,9 +96,33 @@ bool VideoSoftware::Initialize(void *&window_handle)
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()
Expand Down
30 changes: 24 additions & 6 deletions Source/Plugins/Plugin_VideoSoftware/Src/SetupUnit.cpp
Expand Up @@ -25,13 +25,13 @@

void SetupUnit::Init(u8 primitiveType)
{
m_PrimType = primitiveType;
m_PrimType = primitiveType;

m_VertexCounter = 0;
m_VertPointer[0] = &m_Vertices[0];
m_VertPointer[1] = &m_Vertices[1];
m_VertPointer[2] = &m_Vertices[2];
m_VertWritePointer = m_VertPointer[0];
m_VertexCounter = 0;
m_VertPointer[0] = &m_Vertices[0];
m_VertPointer[1] = &m_Vertices[1];
m_VertPointer[2] = &m_Vertices[2];
m_VertWritePointer = m_VertPointer[0];
}

void SetupUnit::SetupVertex()
Expand Down Expand Up @@ -169,3 +169,21 @@ void SetupUnit::SetupLineStrip()

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];
}*/
}
2 changes: 2 additions & 0 deletions Source/Plugins/Plugin_VideoSoftware/Src/SetupUnit.h
Expand Up @@ -21,6 +21,7 @@

#include "Common.h"
#include "NativeVertexFormat.h"
#include "ChunkFile.h"

class SetupUnit
{
Expand All @@ -45,6 +46,7 @@ class SetupUnit
OutputVertexData* GetVertex() { return m_VertWritePointer; }

void SetupVertex();
void DoState(PointerWrap &p);
};

#endif

0 comments on commit 0c16489

Please sign in to comment.