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;
void LoadBPReg(u32 value0);
#endif

View file

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

View file

@ -32,12 +32,6 @@ namespace VertexLoaderManager
// For debugging
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

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 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"
>
</File>
<File
RelativePath=".\Src\VertexLoaderManager.h"
>
</File>
<File
RelativePath=".\Src\VideoCommon.h"
>
</File>
<File
RelativePath=".\Src\VideoState.cpp"
>

View file

@ -24,26 +24,25 @@
// 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.
#include "D3DBase.h"
#include "Common.h"
#include "Statistics.h"
#include "VideoCommon.h"
#include "Profiler.h"
#include "VertexManager.h"
#include "TransformEngine.h"
#include "OpcodeDecoding.h"
#include "TextureCache.h"
#include "VertexShaderManager.h"
#include "PixelShaderManager.h"
#include "BPStructs.h"
#include "XFStructs.h"
#include "Utils.h"
#include "VertexLoader.h"
#include "VertexLoaderManager.h"
#include "VertexManager.h"
#include "Statistics.h"
#include "XFMemory.h"
#include "CPMemory.h"
#include "BPMemory.h"
#include "Fifo.h"
#include "DataReader.h"
DecodedVArray tempvarray;
u8 *g_pVideoData = 0;
u8* g_pVideoData = 0;
extern u8* FAKE_GetFifoStartPtr();
extern u8* FAKE_GetFifoEndPtr();
@ -53,7 +52,7 @@ static void Decode();
static void ExecuteDisplayList(u32 address, u32 size)
{
u8* old_pVideoData = g_pVideoData;
u8* startAddress = Memory_GetPtr(address);
//Avoid the crash if Memory_GetPtr failed ..
@ -61,10 +60,10 @@ static void ExecuteDisplayList(u32 address, u32 size)
{
g_pVideoData = startAddress;
// temporarily swap dl and non-dl(small "hack" for the stats)
// temporarily swap dl and non-dl (small "hack" for the stats)
Statistics::SwapDL();
while((u32)(g_pVideoData - startAddress) < size)
while ((u32)(g_pVideoData - startAddress) < size)
{
Decode();
}
@ -73,22 +72,22 @@ static void ExecuteDisplayList(u32 address, u32 size)
// un-swap
Statistics::SwapDL();
// reset to the old pointer
g_pVideoData = old_pVideoData;
}
// reset to the old pointer
g_pVideoData = old_pVideoData;
}
bool FifoCommandRunnable()
{
u32 iBufferSize = (u32)(FAKE_GetFifoEndPtr()-g_pVideoData);
u32 iBufferSize = (u32)(FAKE_GetFifoEndPtr() - g_pVideoData);
if (iBufferSize == 0)
return false; // can't peek
u8 Cmd = DataPeek8(0);
u8 Cmd = DataPeek8(0);
u32 iCommandSize = 0;
switch(Cmd)
switch (Cmd)
{
case GX_NOP:
// Hm, this means that we scan over nop streams pretty slowly...
@ -131,7 +130,7 @@ bool FifoCommandRunnable()
iCommandSize = 1 + 4;
u32 Cmd2 = DataPeek32(1);
int dwTransferSize = ((Cmd2 >> 16) & 15) + 1;
iCommandSize += dwTransferSize * 4;
iCommandSize += dwTransferSize * 4;
}
else
{
@ -141,17 +140,14 @@ bool FifoCommandRunnable()
break;
default:
if (Cmd&0x80)
if (Cmd & 0x80)
{
// check if we can read the header
if (iBufferSize >= 3)
{
iCommandSize = 1 + 2;
u16 numVertices = DataPeek16(1);
VertexLoader& vtxLoader = g_VertexLoaders[Cmd & GX_VAT_MASK];
vtxLoader.Setup();
int vsize = vtxLoader.GetVertexSize();
iCommandSize += numVertices * vsize;
iCommandSize += numVertices * VertexLoaderManager::GetVertexSize(Cmd & GX_VAT_MASK);
}
else
{
@ -160,17 +156,16 @@ bool FifoCommandRunnable()
}
else
{
char szTemp[1024];
sprintf(szTemp, "GFX: Unknown Opcode (0x%x).\n"
char szTemp[1024];
sprintf(szTemp, "GFX: Unknown Opcode (0x%x).\n"
"This means one of the following:\n"
"* The emulated GPU got desynced, disabling dual core can help\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"
"Dolphin will now likely crash or hang. Enjoy.", Cmd);
MessageBox(NULL, szTemp, "Video-Plugin", MB_OK);
"Dolphin will now likely crash or hang. Enjoy." , Cmd);
g_VideoInitialize.pSysMessage(szTemp);
g_VideoInitialize.pLog(szTemp, TRUE);
{
SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo;
@ -194,67 +189,65 @@ bool FifoCommandRunnable()
,fifo.bFF_BPEnable ? "true" : "false" ,fifo.bFF_GPLinkEnable ? "true" : "false"
,fifo.bFF_Breakpoint ? "true" : "false");
g_VideoInitialize.pSysMessage(szTmp);
g_VideoInitialize.pLog(szTmp, TRUE);
MessageBox(0,szTmp,"GFX ERROR",0);
// _assert_msg_(0,szTmp,"");
}
}
break;
}
if (iCommandSize > iBufferSize)
return false;
#ifdef _DEBUG
char temp[256];
sprintf(temp, "OP detected: Cmd 0x%x size %i buffer %i",Cmd, iCommandSize, iBufferSize);
g_VideoInitialize.pLog(temp, FALSE);
#endif
// INFO_LOG("OP detected: Cmd 0x%x size %i buffer %i",Cmd, iCommandSize, iBufferSize);
return true;
}
static void Decode(void)
static void Decode()
{
int Cmd = DataReadU8();
switch (Cmd)
int Cmd = DataReadU8();
switch(Cmd)
{
case GX_NOP:
break;
case GX_LOAD_CP_REG:
case GX_LOAD_CP_REG: //0x08
{
u32 SubCmd = DataReadU8();
u32 Value = DataReadU32();
LoadCPReg(SubCmd,Value);
LoadCPReg(SubCmd, Value);
INCSTAT(stats.thisFrame.numCPLoads);
}
break;
case GX_LOAD_XF_REG:
{
u32 Cmd2 = DataReadU32();
int dwTransferSize = ((Cmd2>>16)&15) + 1;
int dwTransferSize = ((Cmd2 >> 16) & 15) + 1;
u32 dwAddress = Cmd2 & 0xFFFF;
// TODO - speed this up. pshufb?
static u32 pData[16];
for (int i=0; i<dwTransferSize; i++)
for (int i = 0; i < dwTransferSize; i++)
pData[i] = DataReadU32();
LoadXFReg(dwTransferSize,dwAddress,pData);
LoadXFReg(dwTransferSize, dwAddress, pData);
INCSTAT(stats.thisFrame.numXFLoads);
}
break;
case GX_LOAD_INDX_A: //used for position matrices
LoadIndexedXF(DataReadU32(),0xC);
LoadIndexedXF(DataReadU32(), 0xC);
break;
case GX_LOAD_INDX_B: //used for normal matrices
LoadIndexedXF(DataReadU32(),0xD);
LoadIndexedXF(DataReadU32(), 0xD);
break;
case GX_LOAD_INDX_C: //used for postmatrices
LoadIndexedXF(DataReadU32(),0xE);
LoadIndexedXF(DataReadU32(), 0xE);
break;
case GX_LOAD_INDX_D: //used for lights
LoadIndexedXF(DataReadU32(),0xF);
LoadIndexedXF(DataReadU32(), 0xF);
break;
case GX_CMD_CALL_DL:
@ -277,53 +270,27 @@ static void Decode(void)
{
u32 cmd = DataReadU32();
LoadBPReg(cmd);
INCSTAT(stats.thisFrame.numBPLoads);
}
break;
// draw primitives
// draw primitives
default:
if (Cmd&0x80)
{
// load vertices
u16 numVertices = DataReadU16();
tempvarray.Reset();
VertexLoader::SetVArray(&tempvarray);
VertexLoader& vtxLoader = g_VertexLoaders[Cmd & GX_VAT_MASK];
vtxLoader.Setup();
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);
if (Cmd & 0x80)
{
// load vertices (use computed vertex size from FifoCommandRunnable above)
u16 numVertices = DataReadU16();
VertexLoaderManager::RunVertices(
Cmd & GX_VAT_MASK, // Vertex loader index (0 - 7)
(Cmd & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
numVertices);
}
else
{
SCPFifoStruct &fifo = *g_VideoInitialize.pCPFifo;
char szTmp[256];
// sprintf(szTmp, "Illegal command %02x (at %08x)",Cmd,g_pDataReader->GetPtr());
sprintf(szTmp, "Illegal command %02x\n"
"CPBase: 0x%08x\n"
"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);
// char szTmp[256];
//sprintf(szTmp, "Illegal command %02x (at %08x)",Cmd,g_pDataReader->GetPtr());
//g_VideoInitialize.pLog(szTmp);
//MessageBox(0,szTmp,"GFX ERROR",0);
// _assert_msg_(0,szTmp,"");
break;
}
@ -334,22 +301,20 @@ static void Decode(void)
void OpcodeDecoder_Init()
{
g_pVideoData = FAKE_GetFifoStartPtr();
tempvarray.Create(65536*3, 1, 8, 3, 2, 8);
}
void OpcodeDecoder_Shutdown()
{
//VirtualFree((LPVOID)buffer,0,MEM_RELEASE);
tempvarray.Destroy();
}
void OpcodeDecoder_Run()
{
DVSTARTPROFILE();
DVSTARTPROFILE();
while (FifoCommandRunnable())
{
//TODO?: if really needed, do something like this: "InterlockedExchange((LONG*)&_fifo.CPCmdIdle, 0);"
Decode();
}
}
//TODO?: if really needed, do something like this: "InterlockedExchange((LONG*)&_fifo.CPCmdIdle, 1);"
}

View file

@ -21,43 +21,11 @@
#include "Common.h"
#include "main.h"
#include "LookUpTables.h"
#include "VideoCommon.h"
extern int frameCount;
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

View file

@ -360,4 +360,40 @@ void VertexLoader::RunVertices(int count)
this->m_counter = count;
((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 DecodedVArray* varray;
#endif

View file

@ -30,6 +30,7 @@
#include "TextureCache.h"
#include "BPStructs.h"
#include "VertexManager.h"
#include "VertexLoaderManager.h"
#include "TransformEngine.h"
#include "DlgSettings.h"
#include "D3DPostprocess.h"
@ -90,7 +91,7 @@ void UpdateFPSDisplay(const char *text)
{
char temp[512];
sprintf_s(temp, 512, "SVN R%i: DX9: %s", SVN_REV, text);
SetWindowText( EmuWindow::GetWnd(), temp);
SetWindowText(EmuWindow::GetWnd(), temp);
}
@ -101,7 +102,7 @@ bool Init()
if (initCount == 0)
{
// create the window
if ( !g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL ) // ignore parent for this plugin
if (!g_Config.renderToMainframe || g_VideoInitialize.pWindowHandle == NULL) // ignore parent for this plugin
{
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create(NULL, g_hInstance, "Loading - Please wait.");
}
@ -110,7 +111,7 @@ bool Init()
g_VideoInitialize.pWindowHandle = (void*)EmuWindow::Create((HWND)g_VideoInitialize.pWindowHandle, g_hInstance, "Loading - Please wait.");
}
if ( g_VideoInitialize.pWindowHandle == NULL )
if (g_VideoInitialize.pWindowHandle == NULL)
{
MessageBox(GetActiveWindow(), "An error has occurred while trying to create the window.", "Fatal Error", MB_OK);
return false;
@ -133,30 +134,27 @@ bool Init()
return true;
}
void DeInit()
{
initCount--;
if (initCount==0)
if (initCount == 0)
{
D3D::Shutdown();
EmuWindow::Close();
}
}
// ====================================================================================
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
{
_PluginInfo->Version = 0x0100;
_PluginInfo->Type = PLUGIN_TYPE_VIDEO;
#ifdef DEBUGFAST
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin (DebugFast)");
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (DebugFast)");
#else
#ifndef _DEBUG
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin");
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9");
#else
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 Plugin (Debug)");
sprintf_s(_PluginInfo->Name, 100, "Dolphin Direct3D9 (Debug)");
#endif
#endif
}
@ -215,16 +213,18 @@ void Video_Prepare(void)
BPInit();
VertexManager::Init();
Fifo_Init();
VertexLoaderManager::Init();
OpcodeDecoder_Init();
}
void Video_Shutdown(void)
{
Fifo_Shutdown();
OpcodeDecoder_Shutdown();
VertexManager::Shutdown();
TextureCache::Shutdown();
Renderer::Shutdown();
OpcodeDecoder_Shutdown();
VertexLoaderManager::Shutdown();
DeInit();
}
@ -256,9 +256,9 @@ void DebugLog(const char* _fmt, ...)
char Msg[512];
va_list ap;
va_start( ap, _fmt );
vsprintf( Msg, _fmt, ap );
va_end( ap );
va_start(ap, _fmt);
vsprintf(Msg, _fmt, ap);
va_end(ap);
g_VideoInitialize.pLog(Msg, FALSE);
#endif

View file

@ -788,10 +788,6 @@
RelativePath=".\Src\VertexLoaderManager.cpp"
>
</File>
<File
RelativePath=".\Src\VertexLoaderManager.h"
>
</File>
<File
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
#endif
#include "main.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;
}
#include "VideoCommon.h"
#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
// 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 "OpcodeDecoding.h"
#include "VertexLoader.h"
#include "VertexLoaderManager.h"
#include "VertexManager.h"
#include "VertexShaderManager.h"
#include "Statistics.h"
#include "BPStructs.h"
#include "XFMemory.h"
#include "CPMemory.h"
#include "BPMemory.h"
#include "Fifo.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.
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_DepthTarget = 0;
static GLuint s_ZBufferTarget = 0;