Some gfx code reorg, make the two OpcodeDecoding.cpp identical - next change will move them to videocommon

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1659 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-12-25 20:07:13 +00:00
parent dcc48d6c41
commit 65e702030a
15 changed files with 197 additions and 194 deletions

View File

@ -837,4 +837,6 @@ struct BPMemory
extern BPMemory bpmem; extern BPMemory bpmem;
void LoadBPReg(u32 value0);
#endif #endif

View File

@ -258,4 +258,7 @@ struct VAT
extern TVtxDesc g_VtxDesc; extern TVtxDesc g_VtxDesc;
extern VAT g_VtxAttr[8]; extern VAT g_VtxAttr[8];
// Might move this into its own file later.
void LoadCPReg(u32 SubCmd, u32 Value);
#endif #endif

View File

@ -32,12 +32,6 @@ namespace VertexLoaderManager
// For debugging // For debugging
void AppendListToString(std::string *dest); void AppendListToString(std::string *dest);
// TODO - don't expose these like this.
// static u8* s_pCurBufferPointer;
}; };
// Might move this into its own file later.
void LoadCPReg(u32 SubCmd, u32 Value);
#endif // _VERTEXLOADERMANAGER_H #endif // _VERTEXLOADERMANAGER_H

View File

@ -0,0 +1,56 @@
// Copyright (C) 2003-2008 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _VIDEOCOMMON_H
#define _VIDEOCOMMON_H
#include "Common.h"
#include "main.h"
#include "pluginspecs_video.h"
extern SVideoInitialize g_VideoInitialize;
void DebugLog(const char* _fmt, ...);
inline u8 *Memory_GetPtr(u32 _uAddress)
{
return g_VideoInitialize.pGetMemoryPointer(_uAddress);//&g_pMemory[_uAddress & RAM_MASK];
}
inline u8 Memory_Read_U8(u32 _uAddress)
{
return *(u8*)g_VideoInitialize.pGetMemoryPointer(_uAddress);//g_pMemory[_uAddress & RAM_MASK];
}
inline u16 Memory_Read_U16(u32 _uAddress)
{
return Common::swap16(*(u16*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
}
inline u32 Memory_Read_U32(u32 _uAddress)
{
return Common::swap32(*(u32*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
}
inline float Memory_Read_Float(u32 _uAddress)
{
union {u32 i; float f;} temp;
temp.i = Memory_Read_U32(_uAddress);
return temp.f;
}
#endif // _VIDEOCOMMON_H

View File

@ -200,5 +200,7 @@ struct Viewport
extern XFRegisters xfregs; extern XFRegisters xfregs;
extern u32 xfmem[XFMEM_SIZE]; extern u32 xfmem[XFMEM_SIZE];
#endif void LoadXFReg(u32 transferSize, u32 address, u32 *pData);
void LoadIndexedXF(u32 val, int array);
#endif

View File

@ -515,6 +515,14 @@
RelativePath=".\Src\TextureDecoder.h" RelativePath=".\Src\TextureDecoder.h"
> >
</File> </File>
<File
RelativePath=".\Src\VertexLoaderManager.h"
>
</File>
<File
RelativePath=".\Src\VideoCommon.h"
>
</File>
<File <File
RelativePath=".\Src\VideoState.cpp" RelativePath=".\Src\VideoState.cpp"
> >

View File

@ -24,25 +24,24 @@
// and hope that the vertex format doesn't change, though, if you do it just when they are // and hope that the vertex format doesn't change, though, if you do it just when they are
// called. The reason is that the vertex format affects the sizes of the vertices. // called. The reason is that the vertex format affects the sizes of the vertices.
#include "D3DBase.h"
#include "Common.h" #include "Common.h"
#include "Statistics.h" #include "VideoCommon.h"
#include "Profiler.h" #include "Profiler.h"
#include "VertexManager.h"
#include "TransformEngine.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "TextureCache.h"
#include "VertexShaderManager.h"
#include "PixelShaderManager.h"
#include "BPStructs.h" #include "VertexLoader.h"
#include "XFStructs.h" #include "VertexLoaderManager.h"
#include "Utils.h" #include "VertexManager.h"
#include "Statistics.h"
#include "XFMemory.h"
#include "CPMemory.h"
#include "BPMemory.h"
#include "Fifo.h" #include "Fifo.h"
#include "DataReader.h" #include "DataReader.h"
DecodedVArray tempvarray;
u8* g_pVideoData = 0; u8* g_pVideoData = 0;
extern u8* FAKE_GetFifoStartPtr(); extern u8* FAKE_GetFifoStartPtr();
@ -73,11 +72,11 @@ static void ExecuteDisplayList(u32 address, u32 size)
// un-swap // un-swap
Statistics::SwapDL(); Statistics::SwapDL();
}
// reset to the old pointer // reset to the old pointer
g_pVideoData = old_pVideoData; g_pVideoData = old_pVideoData;
} }
}
bool FifoCommandRunnable() bool FifoCommandRunnable()
{ {
@ -148,10 +147,7 @@ bool FifoCommandRunnable()
{ {
iCommandSize = 1 + 2; iCommandSize = 1 + 2;
u16 numVertices = DataPeek16(1); u16 numVertices = DataPeek16(1);
VertexLoader& vtxLoader = g_VertexLoaders[Cmd & GX_VAT_MASK]; iCommandSize += numVertices * VertexLoaderManager::GetVertexSize(Cmd & GX_VAT_MASK);
vtxLoader.Setup();
int vsize = vtxLoader.GetVertexSize();
iCommandSize += numVertices * vsize;
} }
else else
{ {
@ -165,12 +161,11 @@ bool FifoCommandRunnable()
"This means one of the following:\n" "This means one of the following:\n"
"* The emulated GPU got desynced, disabling dual core can help\n" "* The emulated GPU got desynced, disabling dual core can help\n"
"* Command stream corrupted by some spurious memory bug\n" "* Command stream corrupted by some spurious memory bug\n"
"* This really is an unknown opcode (unlikely)\n\n" "* This really is an unknown opcode (unlikely)\n"
"* Some other sort of bug\n\n" "* Some other sort of bug\n\n"
"Dolphin will now likely crash or hang. Enjoy." , Cmd); "Dolphin will now likely crash or hang. Enjoy." , Cmd);
MessageBox(NULL, szTemp, "Video-Plugin", MB_OK); g_VideoInitialize.pSysMessage(szTemp);
g_VideoInitialize.pLog(szTemp, TRUE); g_VideoInitialize.pLog(szTemp, TRUE);
{ {
SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo; SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo;
@ -194,8 +189,8 @@ bool FifoCommandRunnable()
,fifo.bFF_BPEnable ? "true" : "false" ,fifo.bFF_GPLinkEnable ? "true" : "false" ,fifo.bFF_BPEnable ? "true" : "false" ,fifo.bFF_GPLinkEnable ? "true" : "false"
,fifo.bFF_Breakpoint ? "true" : "false"); ,fifo.bFF_Breakpoint ? "true" : "false");
g_VideoInitialize.pSysMessage(szTmp);
g_VideoInitialize.pLog(szTmp, TRUE); g_VideoInitialize.pLog(szTmp, TRUE);
MessageBox(0,szTmp,"GFX ERROR",0);
// _assert_msg_(0,szTmp,""); // _assert_msg_(0,szTmp,"");
} }
@ -206,16 +201,12 @@ bool FifoCommandRunnable()
if (iCommandSize > iBufferSize) if (iCommandSize > iBufferSize)
return false; return false;
#ifdef _DEBUG // INFO_LOG("OP detected: Cmd 0x%x size %i buffer %i",Cmd, iCommandSize, iBufferSize);
char temp[256];
sprintf(temp, "OP detected: Cmd 0x%x size %i buffer %i",Cmd, iCommandSize, iBufferSize);
g_VideoInitialize.pLog(temp, FALSE);
#endif
return true; return true;
} }
static void Decode(void) static void Decode()
{ {
int Cmd = DataReadU8(); int Cmd = DataReadU8();
switch(Cmd) switch(Cmd)
@ -223,24 +214,26 @@ static void Decode(void)
case GX_NOP: case GX_NOP:
break; break;
case GX_LOAD_CP_REG: case GX_LOAD_CP_REG: //0x08
{ {
u32 SubCmd = DataReadU8(); u32 SubCmd = DataReadU8();
u32 Value = DataReadU32(); u32 Value = DataReadU32();
LoadCPReg(SubCmd, Value); LoadCPReg(SubCmd, Value);
INCSTAT(stats.thisFrame.numCPLoads);
} }
break; break;
case GX_LOAD_XF_REG: case GX_LOAD_XF_REG:
{ {
u32 Cmd2 = DataReadU32(); u32 Cmd2 = DataReadU32();
int dwTransferSize = ((Cmd2 >> 16) & 15) + 1; int dwTransferSize = ((Cmd2 >> 16) & 15) + 1;
u32 dwAddress = Cmd2 & 0xFFFF; u32 dwAddress = Cmd2 & 0xFFFF;
// TODO - speed this up. pshufb?
static u32 pData[16]; static u32 pData[16];
for (int i = 0; i < dwTransferSize; i++) for (int i = 0; i < dwTransferSize; i++)
pData[i] = DataReadU32(); pData[i] = DataReadU32();
LoadXFReg(dwTransferSize, dwAddress, pData); LoadXFReg(dwTransferSize, dwAddress, pData);
INCSTAT(stats.thisFrame.numXFLoads);
} }
break; break;
@ -277,6 +270,7 @@ static void Decode(void)
{ {
u32 cmd = DataReadU32(); u32 cmd = DataReadU32();
LoadBPReg(cmd); LoadBPReg(cmd);
INCSTAT(stats.thisFrame.numBPLoads);
} }
break; break;
@ -284,46 +278,19 @@ static void Decode(void)
default: default:
if (Cmd & 0x80) if (Cmd & 0x80)
{ {
// load vertices // load vertices (use computed vertex size from FifoCommandRunnable above)
u16 numVertices = DataReadU16(); u16 numVertices = DataReadU16();
tempvarray.Reset(); VertexLoaderManager::RunVertices(
VertexLoader::SetVArray(&tempvarray); Cmd & GX_VAT_MASK, // Vertex loader index (0 - 7)
VertexLoader& vtxLoader = g_VertexLoaders[Cmd & GX_VAT_MASK]; (Cmd & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
vtxLoader.Setup(); numVertices);
vtxLoader.PrepareRun();
int vsize = vtxLoader.GetVertexSize();
vtxLoader.RunVertices(numVertices);
// add vertices
int primitive = (Cmd & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT;
VertexManager::AddVertices(primitive, numVertices, &tempvarray);
} }
else else
{ {
SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo; // char szTmp[256];
char szTmp[256];
//sprintf(szTmp, "Illegal command %02x (at %08x)",Cmd,g_pDataReader->GetPtr()); //sprintf(szTmp, "Illegal command %02x (at %08x)",Cmd,g_pDataReader->GetPtr());
sprintf(szTmp, "Illegal command %02x\n" //g_VideoInitialize.pLog(szTmp);
"CPBase: 0x%08x\n" //MessageBox(0,szTmp,"GFX ERROR",0);
"CPEnd: 0x%08x\n"
"CPHiWatermark: 0x%08x\n"
"CPLoWatermark: 0x%08x\n"
"CPReadWriteDistance: 0x%08x\n"
"CPWritePointer: 0x%08x\n"
"CPReadPointer: 0x%08x\n"
"CPBreakpoint: 0x%08x\n"
"bFF_GPReadEnable: %s\n"
"bFF_BPEnable: %s\n"
"bFF_GPLinkEnable: %s\n"
"bFF_Breakpoint: %s\n"
,Cmd, fifo.CPBase, fifo.CPEnd, fifo.CPHiWatermark, fifo.CPLoWatermark, fifo.CPReadWriteDistance
,fifo.CPWritePointer, fifo.CPReadPointer, fifo.CPBreakpoint, fifo.bFF_GPReadEnable ? "true" : "false"
,fifo.bFF_BPEnable ? "true" : "false" ,fifo.bFF_GPLinkEnable ? "true" : "false"
,fifo.bFF_Breakpoint ? "true" : "false");
g_VideoInitialize.pLog(szTmp, TRUE);
MessageBox(0,szTmp,"GFX ERROR",0);
// _assert_msg_(0,szTmp,""); // _assert_msg_(0,szTmp,"");
break; break;
} }
@ -334,22 +301,20 @@ static void Decode(void)
void OpcodeDecoder_Init() void OpcodeDecoder_Init()
{ {
g_pVideoData = FAKE_GetFifoStartPtr(); g_pVideoData = FAKE_GetFifoStartPtr();
tempvarray.Create(65536*3, 1, 8, 3, 2, 8);
} }
void OpcodeDecoder_Shutdown() void OpcodeDecoder_Shutdown()
{ {
//VirtualFree((LPVOID)buffer,0,MEM_RELEASE);
tempvarray.Destroy();
} }
void OpcodeDecoder_Run() void OpcodeDecoder_Run()
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
while (FifoCommandRunnable()) while (FifoCommandRunnable())
{ {
//TODO?: if really needed, do something like this: "InterlockedExchange((LONG*)&_fifo.CPCmdIdle, 0);"
Decode(); Decode();
} }
//TODO?: if really needed, do something like this: "InterlockedExchange((LONG*)&_fifo.CPCmdIdle, 1);"
} }

View File

@ -21,43 +21,11 @@
#include "Common.h" #include "Common.h"
#include "main.h" #include "main.h"
#include "LookUpTables.h" #include "LookUpTables.h"
#include "VideoCommon.h"
extern int frameCount; extern int frameCount;
LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
//#define RAM_MASK 0x1FFFFFF
inline u8 *Memory_GetPtr(u32 _uAddress)
{
return g_VideoInitialize.pGetMemoryPointer(_uAddress);
}
inline u8 Memory_Read_U8(u32 _uAddress)
{
return *g_VideoInitialize.pGetMemoryPointer(_uAddress);
}
inline u16 Memory_Read_U16(u32 _uAddress)
{
return _byteswap_ushort(*(u16*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
// return _byteswap_ushort(*(u16*)&g_pMemory[_uAddress & RAM_MASK]);
}
inline u32 Memory_Read_U32(u32 _uAddress)
{
if (_uAddress == 0x020143a8)
{
int i =0;
}
return _byteswap_ulong(*(u32*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
// return _byteswap_ulong(*(u32*)&g_pMemory[_uAddress & RAM_MASK]);
}
inline float Memory_Read_Float(u32 _uAddress)
{
u32 uTemp = Memory_Read_U32(_uAddress);
return *(float*)&uTemp;
}
#endif #endif

View File

@ -361,3 +361,39 @@ void VertexLoader::RunVertices(int count)
((void (*)())((void*)&m_compiledCode[0]))(); ((void (*)())((void*)&m_compiledCode[0]))();
}*/ }*/
} }
DecodedVArray tempvarray;
namespace VertexLoaderManager
{
void Init()
{
tempvarray.Create(65536*3, 1, 8, 3, 2, 8);
}
void Shutdown()
{
tempvarray.Destroy();
}
int GetVertexSize(int vat)
{
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
return vtxLoader.GetVertexSize();
}
void RunVertices(int vat, int primitive, int num_vertices)
{
tempvarray.Reset();
VertexLoader::SetVArray(&tempvarray);
VertexLoader& vtxLoader = g_VertexLoaders[vat];
vtxLoader.Setup();
vtxLoader.PrepareRun();
int vsize = vtxLoader.GetVertexSize();
vtxLoader.RunVertices(num_vertices);
VertexManager::AddVertices(primitive, num_vertices, &tempvarray);
}
}

View File

@ -191,5 +191,4 @@ public:
extern VertexLoader g_VertexLoaders[8]; extern VertexLoader g_VertexLoaders[8];
extern DecodedVArray* varray; extern DecodedVArray* varray;
#endif #endif

View File

@ -30,6 +30,7 @@
#include "TextureCache.h" #include "TextureCache.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "VertexManager.h" #include "VertexManager.h"
#include "VertexLoaderManager.h"
#include "TransformEngine.h" #include "TransformEngine.h"
#include "DlgSettings.h" #include "DlgSettings.h"
#include "D3DPostprocess.h" #include "D3DPostprocess.h"
@ -133,7 +134,6 @@ bool Init()
return true; return true;
} }
void DeInit() void DeInit()
{ {
initCount--; initCount--;
@ -144,19 +144,17 @@ void DeInit()
} }
} }
// ====================================================================================
void GetDllInfo (PLUGIN_INFO* _PluginInfo) void GetDllInfo (PLUGIN_INFO* _PluginInfo)
{ {
_PluginInfo->Version = 0x0100; _PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_VIDEO; _PluginInfo->Type = PLUGIN_TYPE_VIDEO;
#ifdef DEBUGFAST #ifdef DEBUGFAST
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin (DebugFast)"); sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (DebugFast)");
#else #else
#ifndef _DEBUG #ifndef _DEBUG
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin"); sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9");
#else #else
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin (Debug)"); sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (Debug)");
#endif #endif
#endif #endif
} }
@ -215,16 +213,18 @@ void Video_Prepare(void)
BPInit(); BPInit();
VertexManager::Init(); VertexManager::Init();
Fifo_Init(); Fifo_Init();
VertexLoaderManager::Init();
OpcodeDecoder_Init(); OpcodeDecoder_Init();
} }
void Video_Shutdown(void) void Video_Shutdown(void)
{ {
Fifo_Shutdown(); Fifo_Shutdown();
OpcodeDecoder_Shutdown();
VertexManager::Shutdown(); VertexManager::Shutdown();
TextureCache::Shutdown(); TextureCache::Shutdown();
Renderer::Shutdown(); Renderer::Shutdown();
OpcodeDecoder_Shutdown(); VertexLoaderManager::Shutdown();
DeInit(); DeInit();
} }

View File

@ -788,10 +788,6 @@
RelativePath=".\Src\VertexLoaderManager.cpp" RelativePath=".\Src\VertexLoaderManager.cpp"
> >
</File> </File>
<File
RelativePath=".\Src\VertexLoaderManager.h"
>
</File>
<File <File
RelativePath=".\Src\VertexManager.cpp" RelativePath=".\Src\VertexManager.cpp"
> >

View File

@ -64,35 +64,6 @@ unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize);
#define memcmp_gc memcmp #define memcmp_gc memcmp
#endif #endif
#include "main.h" #include "VideoCommon.h"
inline u8 *Memory_GetPtr(u32 _uAddress)
{
return g_VideoInitialize.pGetMemoryPointer(_uAddress);//&g_pMemory[_uAddress & RAM_MASK];
}
inline u8 Memory_Read_U8(u32 _uAddress)
{
return *(u8*)g_VideoInitialize.pGetMemoryPointer(_uAddress);//g_pMemory[_uAddress & RAM_MASK];
}
inline u16 Memory_Read_U16(u32 _uAddress)
{
return Common::swap16(*(u16*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
//return _byteswap_ushort(*(u16*)&g_pMemory[_uAddress & RAM_MASK]);
}
inline u32 Memory_Read_U32(u32 _uAddress)
{
return Common::swap32(*(u32*)g_VideoInitialize.pGetMemoryPointer(_uAddress));
//return _byteswap_ulong(*(u32*)&g_pMemory[_uAddress & RAM_MASK]);
}
inline float Memory_Read_Float(u32 _uAddress)
{
union {u32 i; float f;} temp;
temp.i = Memory_Read_U32(_uAddress);
return temp.f;
}
#endif #endif

View File

@ -24,18 +24,21 @@
// and hope that the vertex format doesn't change, though, if you do it just when they are // and hope that the vertex format doesn't change, though, if you do it just when they are
// called. The reason is that the vertex format affects the sizes of the vertices. // called. The reason is that the vertex format affects the sizes of the vertices.
#include "Globals.h" #include "Common.h"
#include "VideoCommon.h"
#include "Profiler.h" #include "Profiler.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexLoaderManager.h" #include "VertexLoaderManager.h"
#include "VertexManager.h" #include "VertexManager.h"
#include "VertexShaderManager.h"
#include "Statistics.h" #include "Statistics.h"
#include "BPStructs.h" #include "XFMemory.h"
#include "CPMemory.h"
#include "BPMemory.h"
#include "Fifo.h" #include "Fifo.h"
#include "DataReader.h" #include "DataReader.h"

View File

@ -81,7 +81,7 @@ static int nZBufferRender = 0; // if > 0, then use zbuffer render, and count dow
// A framebuffer is a set of render targets: a color and a z buffer. They can be either RenderBuffers or Textures. // A framebuffer is a set of render targets: a color and a z buffer. They can be either RenderBuffers or Textures.
static GLuint s_uFramebuffer = 0; static GLuint s_uFramebuffer = 0;
// The size of these should be a (not necessarily even) multiple of the EFB size, 640x528, but isn't. // The size of these should be a (not necessarily even) multiple of the EFB size, 640x528, but isn'.t
static GLuint s_RenderTarget = 0; static GLuint s_RenderTarget = 0;
static GLuint s_DepthTarget = 0; static GLuint s_DepthTarget = 0;
static GLuint s_ZBufferTarget = 0; static GLuint s_ZBufferTarget = 0;