Move out Cg shader generators to VideoCommon (hope to use this in the DX plugin in the future). Also move out stats code. Comment a lot and cleanup. Kill DX9 Globals.cpp.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@938 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-10-22 20:54:40 +00:00
parent 32820d2036
commit 39df6c5624
41 changed files with 416 additions and 416 deletions

View File

@ -115,7 +115,7 @@ void CBreakPointView::DeleteCurrentSelection()
int Item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); int Item = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
if (Item >= 0) if (Item >= 0)
{ {
u32 Address = GetItemData(Item); u32 Address = (u32)GetItemData(Item);
CBreakPoints::DeleteElementByAddress(Address); CBreakPoints::DeleteElementByAddress(Address);
} }
} }

View File

@ -15,8 +15,6 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h"
#include <stdio.h> #include <stdio.h>
#include <cmath> #include <cmath>
#include <assert.h> #include <assert.h>
@ -429,14 +427,16 @@ char *GeneratePixelShader(u32 texture_mask, bool has_zbuffer_target, bool bRende
} }
else { else {
if (!bRenderZToCol0) { if (!bRenderZToCol0) {
/* NEEDS FIX - dstalpha does not change how fragments are blended with the EFB /* donkopunchstania: NEEDS FIX - dstalpha does not change how fragments are blended with the EFB
once the blending is done, the dstalpha is written to the EFB in place of the once the blending is done, the dstalpha is written to the EFB in place of the
fragment alpha if dstalpha is enabled. this only matters if the EFB supports alpha. fragment alpha if dstalpha is enabled. this only matters if the EFB supports alpha.
Commenting this out fixed Metroids but causes glitches in Super Mario Sunshine.
if (bpmem.dstalpha.enable) if (bpmem.dstalpha.enable)
WRITE(p, " ocol0 = float4(prev.rgb,"I_ALPHA"[0].w);\n"); WRITE(p, " ocol0 = float4(prev.rgb,"I_ALPHA"[0].w);\n");
else*/ else
*/
WRITE(p, " ocol0 = prev;\n"); WRITE(p, " ocol0 = prev;\n");
} }
} }

View File

@ -9,6 +9,9 @@ files = [
"TextureDecoder.cpp", "TextureDecoder.cpp",
"XFMemory.cpp", "XFMemory.cpp",
"XFBConvert.cpp", "XFBConvert.cpp",
"PixelShader.cpp",
"VertexShader.cpp",
"Statistics.cpp",
"Fifo.cpp", "Fifo.cpp",
"VideoState.cpp", "VideoState.cpp",
"Profiler.cpp", "Profiler.cpp",

View File

@ -0,0 +1,43 @@
// 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/
#include <string.h>
#include "Statistics.h"
Statistics stats;
template <class T>
void Xchg(T& a, T&b)
{
T c = a;
a = b;
b = c;
}
void Statistics::ResetFrame()
{
memset(&thisFrame, 0, sizeof(ThisFrame));
}
void Statistics::SwapDL()
{
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims);
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
}

View File

@ -15,56 +15,8 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#ifndef _GLOBALS_H #ifndef _STATISTICS_H
#define _GLOBALS_H #define _STATISTICS_H
#include <string>
struct Config
{
Config();
void Load();
void Save();
int iAdapter;
int iFSResolution;
int iMultisampleMode;
int iPostprocessEffect;
int iCompileDLsLevel;
bool renderToMainframe;
bool bFullscreen;
bool bVsync;
bool bWireFrame;
bool bOverlayStats;
bool bDumpTextures;
bool bOldCard;
bool bShowShaderErrors;
//enhancements
bool bForceFiltering;
bool bForceMaxAniso;
bool bPreUpscale;
int iPreUpscaleFilter;
bool bTruform;
int iTruformLevel;
int iWindowedRes;
char psProfile[16];
char vsProfile[16];
bool bTexFmtOverlayEnable;
bool bTexFmtOverlayCenter;
std::string texDumpPath;
};
extern Config g_Config;
struct Statistics struct Statistics
{ {
@ -101,12 +53,12 @@ struct Statistics
int numDLPrims; int numDLPrims;
int numPrims; int numPrims;
int numShaderChanges; int numShaderChanges;
int numBadCommands; //hope this always is zero ;)
int numDListsCalled; int numDListsCalled;
}; };
ThisFrame thisFrame; ThisFrame thisFrame;
void ResetFrame() {memset(&thisFrame,0,sizeof(ThisFrame));} void ResetFrame();
static void SwapDL();
}; };
extern Statistics stats; extern Statistics stats;
@ -116,11 +68,11 @@ extern Statistics stats;
#ifdef STATISTICS #ifdef STATISTICS
#define INCSTAT(a) (a)++; #define INCSTAT(a) (a)++;
#define ADDSTAT(a,b) (a)+=(b); #define ADDSTAT(a,b) (a)+=(b);
#define SETSTAT(a,x) (a)=(x); #define SETSTAT(a,x) (a)=(int)(x);
#else #else
#define INCSTAT(a) ; #define INCSTAT(a) ;
#define ADDSTAT(a,b) ; #define ADDSTAT(a,b) ;
#define SETSTAT(a,x) ; #define SETSTAT(a,x) ;
#endif #endif
#endif #endif // _STATISTICS_H

View File

@ -15,16 +15,12 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h"
#include "Profiler.h" #include "Profiler.h"
#include <math.h> #include <math.h>
#include "BPStructs.h" #include "BPMemory.h"
#include "VertexShader.h" #include "VertexShader.h"
// This is the tricky one to get rid off.
// #include "VertexLoader.h"
static char text[16384]; static char text[16384];
#define WRITE p+=sprintf #define WRITE p+=sprintf

View File

@ -36,7 +36,8 @@ enum {
VB_HAS_TEXMTXIDX6=(1<<8), VB_HAS_TEXMTXIDX6=(1<<8),
VB_HAS_TEXMTXIDX7=(1<<9), VB_HAS_TEXMTXIDX7=(1<<9),
VB_HAS_TEXMTXIDXALL=(0xff<<2), VB_HAS_TEXMTXIDXALL=(0xff<<2),
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
//VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
VB_HAS_NRM0=(1<<10), VB_HAS_NRM0=(1<<10),
VB_HAS_NRM1=(1<<11), VB_HAS_NRM1=(1<<11),
VB_HAS_NRM2=(1<<12), VB_HAS_NRM2=(1<<12),

View File

@ -22,9 +22,10 @@
void InitXFBConvTables(); void InitXFBConvTables();
// Converts 4:2:2 YUV (YUYV) data to 32-bit RGBA data.
void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height); void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height);
// converts 32-bit RGBA data to 16-bit 4:2:2 YUV data // Converts 32-bit RGBA data to 4:2:2 YUV (YUYV) data.
void ConvertToXFB(u32 *dst, const u8* _pEFB, int width, int height); void ConvertToXFB(u32 *dst, const u8* _pEFB, int width, int height);
#endif #endif

View File

@ -411,22 +411,54 @@
<References> <References>
</References> </References>
<Files> <Files>
<File <Filter
RelativePath=".\Src\BPMemory.cpp" Name="ShaderGenerators"
> >
</File> <File
<File RelativePath=".\Src\PixelShader.cpp"
RelativePath=".\Src\BPMemory.h" >
</File>
<File
RelativePath=".\Src\PixelShader.h"
>
</File>
<File
RelativePath=".\Src\VertexShader.cpp"
>
</File>
<File
RelativePath=".\Src\VertexShader.h"
>
</File>
</Filter>
<Filter
Name="Sections"
> >
</File> <File
<File RelativePath=".\Src\BPMemory.cpp"
RelativePath=".\Src\CPMemory.cpp" >
> </File>
</File> <File
<File RelativePath=".\Src\BPMemory.h"
RelativePath=".\Src\CPMemory.h" >
> </File>
</File> <File
RelativePath=".\Src\CPMemory.cpp"
>
</File>
<File
RelativePath=".\Src\CPMemory.h"
>
</File>
<File
RelativePath=".\Src\XFMemory.cpp"
>
</File>
<File
RelativePath=".\Src\XFMemory.h"
>
</File>
</Filter>
<File <File
RelativePath=".\Src\DataReader.h" RelativePath=".\Src\DataReader.h"
> >
@ -463,6 +495,14 @@
RelativePath=".\Src\SConscript" RelativePath=".\Src\SConscript"
> >
</File> </File>
<File
RelativePath=".\Src\Statistics.cpp"
>
</File>
<File
RelativePath=".\Src\Statistics.h"
>
</File>
<File <File
RelativePath=".\Src\TextureDecoder.cpp" RelativePath=".\Src\TextureDecoder.cpp"
> >
@ -503,14 +543,6 @@
RelativePath=".\Src\XFBConvert.h" RelativePath=".\Src\XFBConvert.h"
> >
</File> </File>
<File
RelativePath=".\Src\XFMemory.cpp"
>
</File>
<File
RelativePath=".\Src\XFMemory.h"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -1375,11 +1375,11 @@
</File> </File>
</Filter> </Filter>
<File <File
RelativePath=".\Src\Globals.cpp" RelativePath=".\Src\Config.cpp"
> >
</File> </File>
<File <File
RelativePath=".\Src\Globals.h" RelativePath=".\Src\Config.h"
> >
</File> </File>
<File <File

View File

@ -17,7 +17,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "Globals.h" #include "Config.h"
#include "Common.h" #include "Common.h"
#include "Profiler.h" #include "Profiler.h"
#include "BPStructs.h" #include "BPStructs.h"

View File

@ -15,7 +15,7 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h" #include "Config.h"
#include "IniFile.h" #include "IniFile.h"
Config g_Config; Config g_Config;
@ -80,5 +80,3 @@ void Config::Save()
iniFile.Set("Enhancements", "ForceMaxAniso", bForceMaxAniso); iniFile.Set("Enhancements", "ForceMaxAniso", bForceMaxAniso);
iniFile.Save("gfx_dx9.ini"); iniFile.Save("gfx_dx9.ini");
} }
Statistics stats;

View File

@ -0,0 +1,67 @@
// 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 _GLOBALS_H
#define _GLOBALS_H
#include <string>
struct Config
{
Config();
void Load();
void Save();
int iAdapter;
int iFSResolution;
int iMultisampleMode;
int iPostprocessEffect;
int iCompileDLsLevel;
bool renderToMainframe;
bool bFullscreen;
bool bVsync;
bool bWireFrame;
bool bOverlayStats;
bool bDumpTextures;
bool bOldCard;
bool bShowShaderErrors;
//enhancements
bool bForceFiltering;
bool bForceMaxAniso;
bool bPreUpscale;
int iPreUpscaleFilter;
bool bTruform;
int iTruformLevel;
int iWindowedRes;
char psProfile[16];
char vsProfile[16];
bool bTexFmtOverlayEnable;
bool bTexFmtOverlayCenter;
std::string texDumpPath;
};
extern Config g_Config;
#endif

View File

@ -21,7 +21,7 @@
#include "D3DTexture.h" #include "D3DTexture.h"
#include "D3DUtil.h" #include "D3DUtil.h"
#include "Globals.h" #include "Config.h"
#include "Render.h" #include "Render.h"

View File

@ -18,7 +18,7 @@
#include <d3dx9.h> #include <d3dx9.h>
#include <string> #include <string>
#include "Globals.h" #include "Config.h"
#include "D3DShader.h" #include "D3DShader.h"

View File

@ -24,7 +24,7 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "D3DPostprocess.h" #include "D3DPostprocess.h"
#include "Globals.h" #include "Config.h"
#include "TextureCache.h" #include "TextureCache.h"

View File

@ -2,7 +2,7 @@
#include <windows.h> #include <windows.h>
#include "../../Core/Src/Core.h" #include "../../Core/Src/Core.h"
#include "Globals.h" #include "Config.h"
#include "main.h" #include "main.h"
#include "EmuWindow.h" #include "EmuWindow.h"

View File

@ -28,8 +28,8 @@
#include "D3DBase.h" #include "D3DBase.h"
#include "Common.h" #include "Common.h"
#include "Statistics.h"
#include "Profiler.h" #include "Profiler.h"
#include "Globals.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "TransformEngine.h" #include "TransformEngine.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
@ -72,10 +72,7 @@ void ExecuteDisplayList(u32 address, u32 size)
g_pVideoData = startAddress; 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)
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims); Statistics::SwapDL();
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
while((u32)(g_pVideoData - startAddress) < size) while((u32)(g_pVideoData - startAddress) < size)
{ {
@ -85,10 +82,7 @@ void ExecuteDisplayList(u32 address, u32 size)
INCSTAT(stats.thisFrame.numDListsCalled); INCSTAT(stats.thisFrame.numDListsCalled);
// un-swap // un-swap
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims); Statistics::SwapDL();
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
// reset to the old pointer // reset to the old pointer
g_pVideoData = old_pVideoData; g_pVideoData = old_pVideoData;

View File

@ -15,7 +15,6 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h"
#include "PixelShader.h" #include "PixelShader.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "XFStructs.h" #include "XFStructs.h"

View File

@ -18,8 +18,9 @@
#include <d3dx9.h> #include <d3dx9.h>
#include "Common.h" #include "Common.h"
#include "Statistics.h"
#include "Globals.h" #include "Config.h"
#include "main.h" #include "main.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "Render.h" #include "Render.h"
@ -209,7 +210,6 @@ void Renderer::SwapBuffers(void)
p+=sprintf(p,"Num strip joins: %i\n",stats.numJoins); p+=sprintf(p,"Num strip joins: %i\n",stats.numJoins);
p+=sprintf(p,"Num primitives: %i\n",stats.thisFrame.numPrims); p+=sprintf(p,"Num primitives: %i\n",stats.thisFrame.numPrims);
p+=sprintf(p,"Num primitives (DL): %i\n",stats.thisFrame.numDLPrims); p+=sprintf(p,"Num primitives (DL): %i\n",stats.thisFrame.numDLPrims);
p+=sprintf(p,"Num bad commands: %i%s\n",stats.thisFrame.numBadCommands,stats.thisFrame.numBadCommands?"!!!":"");
p+=sprintf(p,"Num XF loads: %i\n",stats.thisFrame.numXFLoads); p+=sprintf(p,"Num XF loads: %i\n",stats.thisFrame.numXFLoads);
p+=sprintf(p,"Num XF loads (DL): %i\n",stats.thisFrame.numXFLoadsInDL); p+=sprintf(p,"Num XF loads (DL): %i\n",stats.thisFrame.numXFLoadsInDL);
p+=sprintf(p,"Num CP loads: %i\n",stats.thisFrame.numCPLoads); p+=sprintf(p,"Num CP loads: %i\n",stats.thisFrame.numCPLoads);

View File

@ -16,9 +16,9 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "D3DBase.h" #include "D3DBase.h"
#include "Statistics.h"
#include "Utils.h" #include "Utils.h"
#include "Profiler.h" #include "Profiler.h"
#include "Globals.h"
#include "ShaderManager.h" #include "ShaderManager.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPMemory.h" #include "BPMemory.h"

View File

@ -18,6 +18,7 @@
#include <d3dx9.h> #include <d3dx9.h>
#include "Common.h" #include "Common.h"
#include "Statistics.h"
#include "D3DBase.h" #include "D3DBase.h"
#include "D3DTexture.h" #include "D3DTexture.h"
@ -27,7 +28,7 @@
#include "TextureDecoder.h" #include "TextureDecoder.h"
#include "TextureCache.h" #include "TextureCache.h"
#include "Globals.h" #include "Config.h"
#include "main.h" #include "main.h"
u8 *TextureCache::temp = NULL; u8 *TextureCache::temp = NULL;

View File

@ -19,7 +19,7 @@
#include "Common.h" #include "Common.h"
#include "Profiler.h" #include "Profiler.h"
#include "Globals.h" // #include "Globals.h"
#include "Vec3.h" #include "Vec3.h"
#include "TransformEngine.h" #include "TransformEngine.h"
#include "VertexHandler.h" #include "VertexHandler.h"

View File

@ -15,11 +15,12 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "D3DBase.h" #include "D3DBase.h"
#include "Common.h" #include "Statistics.h"
#include "Profiler.h" #include "Profiler.h"
#include "Globals.h"
#include "VertexHandler.h" #include "VertexHandler.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "TransformEngine.h" #include "TransformEngine.h"

View File

@ -24,7 +24,7 @@
#include "svnrev.h" #include "svnrev.h"
#include "resource.h" #include "resource.h"
#include "main.h" #include "main.h"
#include "Globals.h" #include "Config.h"
#include "Fifo.h" #include "Fifo.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"
#include "TextureCache.h" #include "TextureCache.h"

View File

@ -772,14 +772,6 @@
<Filter <Filter
Name="Render" Name="Render"
> >
<File
RelativePath=".\Src\PixelShader.cpp"
>
</File>
<File
RelativePath=".\Src\PixelShader.h"
>
</File>
<File <File
RelativePath=".\Src\PixelShaderManager.cpp" RelativePath=".\Src\PixelShaderManager.cpp"
> >
@ -828,14 +820,6 @@
RelativePath=".\Src\TextureMngr.h" RelativePath=".\Src\TextureMngr.h"
> >
</File> </File>
<File
RelativePath=".\Src\VertexShader.cpp"
>
</File>
<File
RelativePath=".\Src\VertexShader.h"
>
</File>
<File <File
RelativePath=".\Src\VertexShaderManager.cpp" RelativePath=".\Src\VertexShaderManager.cpp"
> >

View File

@ -60,6 +60,4 @@ void OpenGL_SetWindowText(const char *text);
void OpenGL_Shutdown(); void OpenGL_Shutdown();
void OpenGL_Update(); void OpenGL_Update();
#endif #endif

View File

@ -31,13 +31,6 @@
Config g_Config; Config g_Config;
Statistics stats;
void Statistics::ResetFrame()
{
memset(&thisFrame, 0, sizeof(ThisFrame));
}
Config::Config() Config::Config()
{ {
memset(this, 0, sizeof(Config)); memset(this, 0, sizeof(Config));

View File

@ -140,62 +140,6 @@ struct Config
extern Config g_Config; extern Config g_Config;
struct Statistics
{
int numPrimitives;
int numPixelShadersCreated;
int numPixelShadersAlive;
int numVertexShadersCreated;
int numVertexShadersAlive;
int numTexturesCreated;
int numTexturesAlive;
int numRenderTargetsCreated;
int numRenderTargetsAlive;
int numDListsCalled;
int numDListsCreated;
int numDListsAlive;
int numJoins;
struct ThisFrame
{
int numBPLoads;
int numCPLoads;
int numXFLoads;
int numBPLoadsInDL;
int numCPLoadsInDL;
int numXFLoadsInDL;
int numDLs;
int numDLPrims;
int numPrims;
int numShaderChanges;
int numDListsCalled;
};
ThisFrame thisFrame;
void ResetFrame();
};
extern Statistics stats;
#define STATISTICS
#ifdef STATISTICS
#define INCSTAT(a) (a)++;
#define ADDSTAT(a,b) (a)+=(b);
#define SETSTAT(a,x) (a)=(int)(x);
#else
#define INCSTAT(a) ;
#define ADDSTAT(a,b) ;
#define SETSTAT(a,x) ;
#endif
void DebugLog(const char* _fmt, ...); void DebugLog(const char* _fmt, ...);
void __Log(const char *format, ...); void __Log(const char *format, ...);
void __Log(int type, const char *format, ...); void __Log(int type, const char *format, ...);

View File

@ -30,6 +30,7 @@
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h" #include "VertexManager.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "Statistics.h"
#include "BPStructs.h" #include "BPStructs.h"
#include "Fifo.h" #include "Fifo.h"
@ -44,14 +45,6 @@ extern u8* FAKE_GetFifoEndPtr();
void Decode(); void Decode();
template <class T>
void Xchg(T& a, T&b)
{
T c = a;
a = b;
b = c;
}
void ExecuteDisplayList(u32 address, u32 size) void ExecuteDisplayList(u32 address, u32 size)
{ {
u8* old_pVideoData = g_pVideoData; u8* old_pVideoData = g_pVideoData;
@ -59,13 +52,10 @@ void ExecuteDisplayList(u32 address, u32 size)
u8* startAddress = Memory_GetPtr(address); u8* startAddress = Memory_GetPtr(address);
g_pVideoData = startAddress; 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)
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims); Statistics::SwapDL();
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
while((u32)(g_pVideoData - startAddress) < size) while((u32)(g_pVideoData - startAddress) < size)
{ {
Decode(); Decode();
} }
@ -73,10 +63,7 @@ void ExecuteDisplayList(u32 address, u32 size)
INCSTAT(stats.thisFrame.numDListsCalled); INCSTAT(stats.thisFrame.numDListsCalled);
// un-swap // un-swap
Xchg(stats.thisFrame.numDLPrims, stats.thisFrame.numPrims); Statistics::SwapDL();
Xchg(stats.thisFrame.numXFLoadsInDL, stats.thisFrame.numXFLoads);
Xchg(stats.thisFrame.numCPLoadsInDL, stats.thisFrame.numCPLoads);
Xchg(stats.thisFrame.numBPLoadsInDL, stats.thisFrame.numBPLoads);
// reset to the old pointer // reset to the old pointer
g_pVideoData = old_pVideoData; g_pVideoData = old_pVideoData;

View File

@ -23,6 +23,7 @@
#include <cmath> #include <cmath>
#include "Statistics.h"
#include "ImageWrite.h" #include "ImageWrite.h"
#include "Common.h" #include "Common.h"
#include "Render.h" #include "Render.h"
@ -32,7 +33,7 @@
PixelShaderMngr::PSCache PixelShaderMngr::pshaders; PixelShaderMngr::PSCache PixelShaderMngr::pshaders;
FRAGMENTSHADER* PixelShaderMngr::pShaderLast = NULL; FRAGMENTSHADER* PixelShaderMngr::pShaderLast = NULL;
PixelShaderMngr::PIXELSHADERUID PixelShaderMngr::s_curuid; PIXELSHADERUID PixelShaderMngr::s_curuid;
static int s_nMaxPixelInstructions; static int s_nMaxPixelInstructions;
static int s_nColorsChanged[2]; // 0 - regular colors, 1 - k colors static int s_nColorsChanged[2]; // 0 - regular colors, 1 - k colors
@ -517,7 +518,7 @@ GLuint PixelShaderMngr::GetColorMatrixProgram()
// Mash together all the inputs that contribute to the code of a generated pixel shader into // Mash together all the inputs that contribute to the code of a generated pixel shader into
// a unique identifier, basically containing all the bits. Yup, it's a lot .... // a unique identifier, basically containing all the bits. Yup, it's a lot ....
void PixelShaderMngr::GetPixelShaderId(PixelShaderMngr::PIXELSHADERUID& uid) void PixelShaderMngr::GetPixelShaderId(PIXELSHADERUID &uid)
{ {
u32 projtexcoords = 0; u32 projtexcoords = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; i++) { for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; i++) {

View File

@ -18,12 +18,10 @@
#ifndef _PIXELSHADERMANAGER_H #ifndef _PIXELSHADERMANAGER_H
#define _PIXELSHADERMANAGER_H #define _PIXELSHADERMANAGER_H
#include "PixelShader.h" #include <map>
#include "BPMemory.h" #include "BPMemory.h"
#include <map>
struct FRAGMENTSHADER struct FRAGMENTSHADER
{ {
FRAGMENTSHADER() : glprogid(0) { } FRAGMENTSHADER() : glprogid(0) { }
@ -33,65 +31,59 @@ struct FRAGMENTSHADER
#endif #endif
}; };
class PIXELSHADERUID
{
public:
u32 values[4+32+6+11];
u16 tevstages, indstages;
PIXELSHADERUID() {
memset(values, 0, (4+32+6+11) * 4);
tevstages = indstages = 0;
}
PIXELSHADERUID(const PIXELSHADERUID& r)
{
tevstages = r.tevstages;
indstages = r.indstages;
int N = tevstages + indstages + 3;
_assert_(N <= 4+32+6+11);
for (int i = 0; i < N; ++i)
values[i] = r.values[i];
}
int GetNumValues() const {
return tevstages + indstages + 3; // numTevStages*3/2+1
}
bool operator <(const PIXELSHADERUID& _Right) const
{
if (values[0] < _Right.values[0])
return true;
else if (values[0] > _Right.values[0])
return false;
int N = GetNumValues();
for (int i = 1; i < N; ++i) {
if (values[i] < _Right.values[i])
return true;
else if (values[i] > _Right.values[i])
return false;
}
return false;
}
bool operator ==(const PIXELSHADERUID& _Right) const
{
if (values[0] != _Right.values[0])
return false;
int N = GetNumValues();
for (int i = 1; i < N; ++i) {
if (values[i] != _Right.values[i])
return false;
}
return true;
}
};
class PixelShaderMngr class PixelShaderMngr
{ {
class PIXELSHADERUID
{
public:
PIXELSHADERUID() {
values = new u32[4+32+6+11];
memset(values, 0, (4+32+6+11) * 4);
tevstages = indstages = 0;
}
~PIXELSHADERUID() { delete[] values; values = NULL;}
PIXELSHADERUID(const PIXELSHADERUID& r)
{
values = new u32[4+32+6+11];
tevstages = r.tevstages; indstages = r.indstages;
int N = tevstages + indstages + 3;
_assert_(N <= 4+32+6+11);
for(int i = 0; i < N; ++i)
values[i] = r.values[i];
}
bool operator <(const PIXELSHADERUID& _Right) const
{
if( values[0] < _Right.values[0] )
return true;
else if( values[0] > _Right.values[0] )
return false;
int N = tevstages + indstages + 3; // numTevStages*3/2+1
int i = 1;
for(; i < N; ++i) {
if( values[i] < _Right.values[i] )
return true;
else if( values[i] > _Right.values[i] )
return false;
}
return false;
}
bool operator ==(const PIXELSHADERUID& _Right) const
{
if( values[0] != _Right.values[0] )
return false;
int N = tevstages + indstages + 3; // numTevStages*3/2+1
int i = 1;
for(; i < N; ++i) {
if( values[i] != _Right.values[i] )
return false;
}
return true;
}
u32* values;
u16 tevstages, indstages;
};
struct PSCacheEntry struct PSCacheEntry
{ {
FRAGMENTSHADER shader; FRAGMENTSHADER shader;
@ -105,7 +97,7 @@ class PixelShaderMngr
} }
}; };
typedef std::map<PIXELSHADERUID,PSCacheEntry> PSCache; typedef std::map<PIXELSHADERUID, PSCacheEntry> PSCache;
static FRAGMENTSHADER* pShaderLast; // last used shader static FRAGMENTSHADER* pShaderLast; // last used shader
static PSCache pshaders; static PSCache pshaders;

View File

@ -29,6 +29,7 @@
#include "GLInit.h" #include "GLInit.h"
#include "Profiler.h" #include "Profiler.h"
#include "Statistics.h"
#include "ImageWrite.h" #include "ImageWrite.h"
#include "Render.h" #include "Render.h"
#include "OpcodeDecoding.h" #include "OpcodeDecoding.h"

View File

@ -13,7 +13,6 @@ files = [
'main.cpp', 'main.cpp',
'memcpy_amd.cpp', 'memcpy_amd.cpp',
'OpcodeDecoding.cpp', 'OpcodeDecoding.cpp',
'PixelShader.cpp',
'PixelShaderManager.cpp', 'PixelShaderManager.cpp',
'rasterfont.cpp', 'rasterfont.cpp',
'Render.cpp', 'Render.cpp',
@ -22,7 +21,6 @@ files = [
'VertexManager.cpp', 'VertexManager.cpp',
'VertexLoader.cpp', 'VertexLoader.cpp',
'VertexLoader_Normal.cpp', 'VertexLoader_Normal.cpp',
'VertexShader.cpp',
'VertexShaderManager.cpp', 'VertexShaderManager.cpp',
'XFB.cpp', 'XFB.cpp',
'GUI/ConfigDlg.cpp', 'GUI/ConfigDlg.cpp',

View File

@ -29,6 +29,7 @@
#undef _interlockedbittestandreset64 #undef _interlockedbittestandreset64
#endif #endif
#include "Statistics.h"
#include "Profiler.h" #include "Profiler.h"
#include "ImageWrite.h" #include "ImageWrite.h"
@ -51,8 +52,15 @@ static u32 s_TempFramebuffer = 0;
#define TEMP_SIZE (1024*1024*4) #define TEMP_SIZE (1024*1024*4)
const GLint c_MinLinearFilter[8] = { const GLint c_MinLinearFilter[8] = {
GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST, GL_NEAREST,
GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}; GL_NEAREST_MIPMAP_NEAREST,
GL_NEAREST_MIPMAP_LINEAR,
GL_NEAREST,
GL_LINEAR,
GL_LINEAR_MIPMAP_NEAREST,
GL_LINEAR_MIPMAP_LINEAR,
GL_LINEAR
};
const GLint c_WrapSettings[4] = { GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT, GL_REPEAT }; const GLint c_WrapSettings[4] = { GL_CLAMP_TO_EDGE, GL_REPEAT, GL_MIRRORED_REPEAT, GL_REPEAT };

View File

@ -28,6 +28,7 @@
#include "StringUtil.h" #include "StringUtil.h"
#include "Render.h" #include "Render.h"
#include "VertexShader.h"
#include "VertexManager.h" #include "VertexManager.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "BPStructs.h" #include "BPStructs.h"
@ -55,7 +56,6 @@ static int colIndex;
#define inline #define inline
#endif #endif
TVtxDesc VertexManager::s_GlobalVtxDesc;
// ============================================================================== // ==============================================================================
// Direct // Direct
@ -120,7 +120,7 @@ VertexLoader::VertexLoader()
{ {
m_numPipelineStages = 0; m_numPipelineStages = 0;
m_VertexSize = 0; m_VertexSize = 0;
m_AttrDirty = 1; m_AttrDirty = AD_DIRTY;
VertexLoader_Normal::Init(); VertexLoader_Normal::Init();
m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false); m_compiledCode = (u8 *)AllocateExecutableMemory(COMPILED_CODE_SIZE, false);
@ -136,7 +136,7 @@ VertexLoader::~VertexLoader()
int VertexLoader::ComputeVertexSize() int VertexLoader::ComputeVertexSize()
{ {
if (!m_AttrDirty) { if (m_AttrDirty == AD_CLEAN) {
// Compare the 33 desc bits. // Compare the 33 desc bits.
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 &&
(m_VtxDesc.Hex1 & 1) == (VertexManager::GetVtxDesc().Hex1 & 1)) (m_VtxDesc.Hex1 & 1) == (VertexManager::GetVtxDesc().Hex1 & 1))
@ -152,7 +152,7 @@ int VertexLoader::ComputeVertexSize()
if (fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_compiledCode) if (fnSetupVertexPointers != NULL && fnSetupVertexPointers == (void (*)())(void*)m_compiledCode)
VertexManager::Flush(); VertexManager::Flush();
m_AttrDirty = 1; m_AttrDirty = AD_DIRTY;
m_VertexSize = 0; m_VertexSize = 0;
// Position Matrix Index // Position Matrix Index
if (m_VtxDesc.PosMatIdx) if (m_VtxDesc.PosMatIdx)
@ -257,6 +257,7 @@ int VertexLoader::ComputeVertexSize()
return m_VertexSize; return m_VertexSize;
} }
// Note the use of CallCdeclFunction3I etc. // Note the use of CallCdeclFunction3I etc.
// This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit // This is a horrible hack that is necessary because in 64-bit mode, Opengl32.dll is based way, way above the 32-bit
// address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we // address space that is within reach of a CALL, and just doing &fn gives us these high uncallable addresses. So we
@ -269,20 +270,24 @@ DECLARE_IMPORT(glVertexPointer);
DECLARE_IMPORT(glColorPointer); DECLARE_IMPORT(glColorPointer);
DECLARE_IMPORT(glTexCoordPointer); DECLARE_IMPORT(glTexCoordPointer);
void VertexLoader::ProcessFormat() void VertexLoader::PrepareForVertexFormat()
{ {
using namespace Gen; using namespace Gen;
//_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer ); //_assert_( VertexManager::s_pCurBufferPointer == s_pBaseBufferPointer );
if (!m_AttrDirty) if (m_AttrDirty == AD_CLEAN)
{ {
// Check if local cached desc (in this VL) matches global desc // Check if local cached desc (in this VL) matches global desc
if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1 & 1)==(VertexManager::GetVtxDesc().Hex1 & 1)) if (m_VtxDesc.Hex0 == VertexManager::GetVtxDesc().Hex0 && (m_VtxDesc.Hex1 & 1)==(VertexManager::GetVtxDesc().Hex1 & 1))
return; // same {
return; // same
}
} }
else else
m_AttrDirty = 0; {
m_AttrDirty = AD_CLEAN;
}
m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex; m_VtxDesc.Hex = VertexManager::GetVtxDesc().Hex;
DVSTARTPROFILE(); DVSTARTPROFILE();
@ -315,7 +320,7 @@ void VertexLoader::ProcessFormat()
m_VBVertexStride += 12; m_VBVertexStride += 12;
switch (m_VtxDesc.Position) { switch (m_VtxDesc.Position) {
case NOT_PRESENT: {_assert_msg_(0,"Vertex descriptor without position!","WTF?");} break; case NOT_PRESENT: {_assert_msg_(0, "Vertex descriptor without position!", "WTF?");} break;
case DIRECT: case DIRECT:
{ {
switch (m_VtxAttr.PosFormat) { switch (m_VtxAttr.PosFormat) {
@ -409,7 +414,6 @@ void VertexLoader::ProcessFormat()
m_VBVertexStride += 6; // still include the texture coordinate, but this time as 6 bytes m_VBVertexStride += 6; // still include the texture coordinate, but this time as 6 bytes
m_components |= VB_HAS_UV0 << i; // have to include since using now m_components |= VB_HAS_UV0 << i; // have to include since using now
} }
} }
else { else {
if (tc[i] != NOT_PRESENT) if (tc[i] != NOT_PRESENT)
@ -425,8 +429,7 @@ void VertexLoader::ProcessFormat()
break; break;
} }
} }
if (j == 8 && !((m_components&VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL<<(i+1)))) // no more tex coords and tex matrices, so exit loop
if (j == 8 && !((m_components&VB_HAS_TEXMTXIDXALL)&(VB_HAS_TEXMTXIDXALL<<(i+1)))) // no more tex coords and tex matrices, so exit loop
break; break;
} }
} }
@ -438,18 +441,18 @@ void VertexLoader::ProcessFormat()
if (m_VBVertexStride & 3) { if (m_VBVertexStride & 3) {
// make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost) // make sure all strides are at least divisible by 4 (some gfx cards experience a 3x speed boost)
m_VBStridePad = 4 - (m_VBVertexStride&3); m_VBStridePad = 4 - (m_VBVertexStride & 3);
m_VBVertexStride += m_VBStridePad; m_VBVertexStride += m_VBStridePad;
} }
// compile the pointer set function // compile the pointer set function - why?
u8 *old_code_ptr = GetWritableCodePtr(); u8 *old_code_ptr = GetWritableCodePtr();
SetCodePtr(m_compiledCode); SetCodePtr(m_compiledCode);
Util::EmitPrologue(6); Util::EmitPrologue(6);
int offset = 0; int offset = 0;
// Position // Position
if (m_VtxDesc.Position != NOT_PRESENT) { if (m_VtxDesc.Position != NOT_PRESENT) { // TODO: Why the check? Always present, AFAIK!
CallCdeclFunction4_I(glVertexPointer, 3, GL_FLOAT, m_VBVertexStride, offset); CallCdeclFunction4_I(glVertexPointer, 3, GL_FLOAT, m_VBVertexStride, offset);
offset += 12; offset += 12;
} }
@ -484,6 +487,8 @@ void VertexLoader::ProcessFormat()
} }
} }
// TODO : With byte or short normals above, offset will be misaligned (not 4byte aligned)! Ugh!
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
if (col[i] != NOT_PRESENT) { if (col[i] != NOT_PRESENT) {
if (i) if (i)
@ -496,9 +501,8 @@ void VertexLoader::ProcessFormat()
// TextureCoord // TextureCoord
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (tc[i] != NOT_PRESENT || (m_components&(VB_HAS_TEXMTXIDX0<<i))) { if (tc[i] != NOT_PRESENT || (m_components & (VB_HAS_TEXMTXIDX0 << i))) {
int id = GL_TEXTURE0 + i;
int id = GL_TEXTURE0+i;
#ifdef _M_X64 #ifdef _M_X64
#ifdef _MSC_VER #ifdef _MSC_VER
MOV(32, R(RCX), Imm32(id)); MOV(32, R(RCX), Imm32(id));
@ -517,6 +521,7 @@ void VertexLoader::ProcessFormat()
ABI_RestoreStack(1 * 4); ABI_RestoreStack(1 * 4);
#endif #endif
#endif #endif
// TODO : More potential disalignment!
if (m_components & (VB_HAS_TEXMTXIDX0 << i)) { if (m_components & (VB_HAS_TEXMTXIDX0 << i)) {
if (tc[i] != NOT_PRESENT) { if (tc[i] != NOT_PRESENT) {
CallCdeclFunction4_I(glTexCoordPointer, 3, GL_FLOAT, m_VBVertexStride, offset); CallCdeclFunction4_I(glTexCoordPointer, 3, GL_FLOAT, m_VBVertexStride, offset);
@ -528,14 +533,14 @@ void VertexLoader::ProcessFormat()
} }
} }
else { else {
CallCdeclFunction4_I(glTexCoordPointer, m_VtxAttr.texCoord[i].Elements?2:1, GL_FLOAT, m_VBVertexStride, offset); CallCdeclFunction4_I(glTexCoordPointer, m_VtxAttr.texCoord[i].Elements ? 2 : 1, GL_FLOAT, m_VBVertexStride, offset);
offset += 4 * (m_VtxAttr.texCoord[i].Elements?2:1); offset += 4 * (m_VtxAttr.texCoord[i].Elements?2:1);
} }
} }
} }
if (m_VtxDesc.PosMatIdx) { if (m_VtxDesc.PosMatIdx) {
CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_POSMTX_ATTRIB,1,GL_UNSIGNED_BYTE, GL_FALSE, m_VBVertexStride, offset); CallCdeclFunction6((void *)glVertexAttribPointer, SHADER_POSMTX_ATTRIB, 1, GL_UNSIGNED_BYTE, GL_FALSE, m_VBVertexStride, offset);
offset += 1; offset += 1;
} }
@ -551,19 +556,6 @@ void VertexLoader::ProcessFormat()
SetCodePtr(old_code_ptr); SetCodePtr(old_code_ptr);
} }
void VertexLoader::PrepareRun()
{
posScale = shiftLookup[m_VtxAttr.PosFrac];
if (m_components & VB_HAS_UVALL) {
for (int i = 0; i < 8; i++) {
tcScaleU[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
tcScaleV[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
}
}
for (int i = 0; i < 2; i++)
colElements[i] = m_VtxAttr.color[i].Elements;
}
void VertexLoader::SetupColor(int num, int mode, int format, int elements) void VertexLoader::SetupColor(int num, int mode, int format, int elements)
{ {
// if COL0 not present, then embed COL1 into COL0 // if COL0 not present, then embed COL1 into COL0
@ -669,38 +661,49 @@ void VertexLoader::RunVertices(int primitive, int count)
{ {
DVSTARTPROFILE(); DVSTARTPROFILE();
ComputeVertexSize(); // HACK for underruns in Super Monkey Ball etc. !!!! dirty handling must be wrong. // This has dirty handling - won't actually recompute unless necessary.
if (count <= 0) ComputeVertexSize();
return;
// Figure out a better check. Also, jitting fnSetupVertexPointers seems pretty silly - not likely to be a bottleneck.
if (fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode) if (fnSetupVertexPointers != NULL && fnSetupVertexPointers != (void (*)())(void*)m_compiledCode)
VertexManager::Flush(); VertexManager::Flush();
if (bpmem.genMode.cullmode == 3 && primitive < 5) if (bpmem.genMode.cullmode == 3 && primitive < 5)
{ {
// if cull mode is none, ignore triangles and quads // if cull mode is none, ignore triangles and quads
DataSkip(count*m_VertexSize); DataSkip(count * m_VertexSize);
return; return;
} }
ProcessFormat(); // This has dirty handling - won't actually recompute unless necessary.
fnSetupVertexPointers = (void (*)())(void*)m_compiledCode; PrepareForVertexFormat();
fnSetupVertexPointers = (void (*)())(void*)m_compiledCode;
VertexManager::EnableComponents(m_components); VertexManager::EnableComponents(m_components);
PrepareRun(); // Load position and texcoord scale factors.
// Hm, this could be done when the VtxAttr is set, instead.
posScale = shiftLookup[m_VtxAttr.PosFrac];
if (m_components & VB_HAS_UVALL) {
for (int i = 0; i < 8; i++) {
tcScaleU[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
tcScaleV[i] = shiftLookup[m_VtxAttr.texCoord[i].Frac];
}
}
for (int i = 0; i < 2; i++)
colElements[i] = m_VtxAttr.color[i].Elements;
// if strips or fans, make sure all vertices can fit in buffer, otherwise flush // if strips or fans, make sure all vertices can fit in buffer, otherwise flush
int granularity = 1; int granularity = 1;
switch (primitive) {
switch(primitive) {
case 3: // strip case 3: // strip
case 4: // fan case 4: // fan
if (VertexManager::GetRemainingSize() < 3*m_VBVertexStride ) if (VertexManager::GetRemainingSize() < 3 * m_VBVertexStride )
VertexManager::Flush(); VertexManager::Flush();
break; break;
case 6: // line strip case 6: // line strip
if (VertexManager::GetRemainingSize() < 2*m_VBVertexStride ) if (VertexManager::GetRemainingSize() < 2 * m_VBVertexStride )
VertexManager::Flush(); VertexManager::Flush();
break; break;
case 0: // quads case 0: // quads

View File

@ -64,7 +64,11 @@ private:
void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac); void SetupTexCoord(int num, int _iMode, int _iFormat, int _iElements, int _iFrac);
// The 3 possible values (0, 1, 2) should be documented here. // The 3 possible values (0, 1, 2) should be documented here.
int m_AttrDirty; enum {
AD_CLEAN = 0,
AD_DIRTY = 1,
AD_VAT_DIRTY = 2,
} m_AttrDirty;
public: public:
// constructor // constructor
@ -72,23 +76,19 @@ public:
~VertexLoader(); ~VertexLoader();
// run the pipeline // run the pipeline
void ProcessFormat(); void PrepareForVertexFormat();
void PrepareRun();
void RunVertices(int primitive, int count); void RunVertices(int primitive, int count);
void WriteCall(void (LOADERDECL *func)(void *)); void WriteCall(void (LOADERDECL *func)(void *));
int GetGCVertexSize() const { _assert_( !m_AttrDirty ); return m_VertexSize; } int GetGCVertexSize() const { _assert_( !m_AttrDirty ); return m_VertexSize; }
int GetVBVertexStride() const { _assert_( !m_AttrDirty); return m_VBVertexStride; } int GetVBVertexStride() const { _assert_( !m_AttrDirty); return m_VBVertexStride; }
int ComputeVertexSize(); int ComputeVertexSize();
// SetVAT_group
// ignore PosFrac, texCoord[i].Frac
void SetVAT_group0(u32 _group0) void SetVAT_group0(u32 _group0)
{ {
if ((m_group0.Hex & ~0x3e0001f0) != (_group0 & ~0x3e0001f0)) { if ((m_group0.Hex & ~0x3e0001f0) != (_group0 & ~0x3e0001f0)) {
m_AttrDirty = 2; m_AttrDirty = AD_VAT_DIRTY;
} }
m_group0.Hex = _group0; m_group0.Hex = _group0;
@ -111,11 +111,10 @@ public:
void SetVAT_group1(u32 _group1) void SetVAT_group1(u32 _group1)
{ {
if ((m_group1.Hex & ~0x7c3e1f0) != (_group1 & ~0x7c3e1f0)) { if ((m_group1.Hex & ~0x7c3e1f0) != (_group1 & ~0x7c3e1f0)) {
m_AttrDirty = 2; m_AttrDirty = AD_VAT_DIRTY;
} }
m_group1.Hex = _group1; m_group1.Hex = _group1;
m_VtxAttr.texCoord[1].Elements = m_group1.Tex1CoordElements; m_VtxAttr.texCoord[1].Elements = m_group1.Tex1CoordElements;
m_VtxAttr.texCoord[1].Format = m_group1.Tex1CoordFormat; m_VtxAttr.texCoord[1].Format = m_group1.Tex1CoordFormat;
m_VtxAttr.texCoord[1].Frac = m_group1.Tex1Frac; m_VtxAttr.texCoord[1].Frac = m_group1.Tex1Frac;
@ -132,7 +131,7 @@ public:
void SetVAT_group2(u32 _group2) void SetVAT_group2(u32 _group2)
{ {
if ((m_group2.Hex & ~0xf87c3e1f) != (_group2 & ~0xf87c3e1f)) { if ((m_group2.Hex & ~0xf87c3e1f) != (_group2 & ~0xf87c3e1f)) {
m_AttrDirty = 2; m_AttrDirty = AD_VAT_DIRTY;
} }
m_group2.Hex = _group2; m_group2.Hex = _group2;

View File

@ -3,6 +3,7 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include "Statistics.h"
#include "MemoryUtil.h" #include "MemoryUtil.h"
#include "Profiler.h" #include "Profiler.h"
#include "Render.h" #include "Render.h"
@ -11,6 +12,7 @@
#include "TextureMngr.h" #include "TextureMngr.h"
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "VertexShader.h"
#include "VertexLoader.h" #include "VertexLoader.h"
#include "VertexManager.h" #include "VertexManager.h"
@ -23,6 +25,7 @@ static vector< pair<int, int> > s_vStoredPrimitives; // every element, mode and
static u32 s_prevcomponents; // previous state set static u32 s_prevcomponents; // previous state set
u8* VertexManager::s_pCurBufferPointer = NULL; u8* VertexManager::s_pCurBufferPointer = NULL;
TVtxDesc VertexManager::s_GlobalVtxDesc;
static const GLenum c_primitiveType[8] = static const GLenum c_primitiveType[8] =
{ {
@ -294,32 +297,32 @@ void VertexManager::Flush()
ResetBuffer(); ResetBuffer();
} }
void VertexManager::LoadCPReg(u32 SubCmd, u32 Value) void VertexManager::LoadCPReg(u32 sub_cmd, u32 value)
{ {
switch (SubCmd & 0xF0) switch (sub_cmd & 0xF0)
{ {
case 0x30: case 0x30:
VertexShaderMngr::SetTexMatrixChangedA(Value); VertexShaderMngr::SetTexMatrixChangedA(value);
break; break;
case 0x40: case 0x40:
VertexShaderMngr::SetTexMatrixChangedB(Value); VertexShaderMngr::SetTexMatrixChangedB(value);
break; break;
case 0x50: case 0x50:
s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits s_GlobalVtxDesc.Hex &= ~0x1FFFF; // keep the Upper bits
s_GlobalVtxDesc.Hex |= Value; s_GlobalVtxDesc.Hex |= value;
break; break;
case 0x60: case 0x60:
s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits s_GlobalVtxDesc.Hex &= 0x1FFFF; // keep the lower 17Bits
s_GlobalVtxDesc.Hex |= (u64)Value << 17; s_GlobalVtxDesc.Hex |= (u64)value << 17;
break; break;
case 0x70: g_VertexLoaders[SubCmd & 7].SetVAT_group0(Value); _assert_((SubCmd & 0x0F) < 8); break; case 0x70: g_VertexLoaders[sub_cmd & 7].SetVAT_group0(value); _assert_((sub_cmd & 0x0F) < 8); break;
case 0x80: g_VertexLoaders[SubCmd & 7].SetVAT_group1(Value); _assert_((SubCmd & 0x0F) < 8); break; case 0x80: g_VertexLoaders[sub_cmd & 7].SetVAT_group1(value); _assert_((sub_cmd & 0x0F) < 8); break;
case 0x90: g_VertexLoaders[SubCmd & 7].SetVAT_group2(Value); _assert_((SubCmd & 0x0F) < 8); break; case 0x90: g_VertexLoaders[sub_cmd & 7].SetVAT_group2(value); _assert_((sub_cmd & 0x0F) < 8); break;
case 0xA0: arraybases[SubCmd & 0xF] = Value & 0xFFFFFFFF; break; case 0xA0: arraybases[sub_cmd & 0xF] = value & 0xFFFFFFFF; break;
case 0xB0: arraystrides[SubCmd & 0xF] = Value & 0xFF; break; case 0xB0: arraystrides[sub_cmd & 0xF] = value & 0xFF; break;
} }
} }

View File

@ -15,16 +15,15 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Globals.h" #include "Globals.h"
#include "Profiler.h" #include "Profiler.h"
#include <Cg/cg.h> #include <Cg/cg.h>
#include <Cg/cgGL.h> #include <Cg/cgGL.h>
#include <math.h> #include <math.h>
#include "Statistics.h"
#include "ImageWrite.h" #include "ImageWrite.h"
#include "Render.h" #include "Render.h"
#include "VertexShader.h" #include "VertexShader.h"
@ -366,7 +365,8 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
int overfl; int overfl;
int xoffs = 0, yoffs = 0; int xoffs = 0, yoffs = 0;
int wid, hei, actualWid, actualHei; int wid, hei, actualWid, actualHei;
int winw = nBackbufferWidth; int winh = nBackbufferHeight; int winw = nBackbufferWidth;
int winh = nBackbufferHeight;
if (g_Config.bKeepAR) if (g_Config.bKeepAR)
{ {
// Check if height or width is the limiting factor // Check if height or width is the limiting factor
@ -405,7 +405,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
hei = ceil(fabs(2 * rawViewport[1])); hei = ceil(fabs(2 * rawViewport[1]));
} }
if(g_Config.bStretchToFit && g_Config.renderToMainframe) if (g_Config.bStretchToFit && g_Config.renderToMainframe)
{ {
glViewport( glViewport(
(int)(rawViewport[3]-rawViewport[0]-342-scissorXOff) + xoffs, (int)(rawViewport[3]-rawViewport[0]-342-scissorXOff) + xoffs,
@ -471,7 +471,7 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
} }
PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]); PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
SetVSConstant4fv(C_PROJECTION, &g_fProjectionMatrix[0]); SetVSConstant4fv(C_PROJECTION, &g_fProjectionMatrix[0]);
SetVSConstant4fv(C_PROJECTION+1, &g_fProjectionMatrix[4]); SetVSConstant4fv(C_PROJECTION+1, &g_fProjectionMatrix[4]);
SetVSConstant4fv(C_PROJECTION+2, &g_fProjectionMatrix[8]); SetVSConstant4fv(C_PROJECTION+2, &g_fProjectionMatrix[8]);
SetVSConstant4fv(C_PROJECTION+3, &g_fProjectionMatrix[12]); SetVSConstant4fv(C_PROJECTION+3, &g_fProjectionMatrix[12]);
@ -480,8 +480,10 @@ void VertexShaderMngr::SetConstants(VERTEXSHADER& vs)
void VertexShaderMngr::InvalidateXFRange(int start, int end) void VertexShaderMngr::InvalidateXFRange(int start, int end)
{ {
if( ((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx*4 && (u32)start < (u32)MatrixIndexA.PosNormalMtxIdx*4+12) || if (((u32)start >= (u32)MatrixIndexA.PosNormalMtxIdx*4 &&
((u32)start >= XFMEM_NORMALMATRICES+((u32)MatrixIndexA.PosNormalMtxIdx&31)*3 && (u32)start < XFMEM_NORMALMATRICES+((u32)MatrixIndexA.PosNormalMtxIdx&31)*3+9) ) { (u32)start < (u32)MatrixIndexA.PosNormalMtxIdx*4 + 12) ||
((u32)start >= XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31)*3 &&
(u32)start < XFMEM_NORMALMATRICES + ((u32)MatrixIndexA.PosNormalMtxIdx & 31)*3 + 9)) {
bPosNormalMatrixChanged = true; bPosNormalMatrixChanged = true;
} }
@ -499,7 +501,7 @@ void VertexShaderMngr::InvalidateXFRange(int start, int end)
bTexMatricesChanged[1] = true; bTexMatricesChanged[1] = true;
} }
if (start < XFMEM_POSMATRICES_END ) { if (start < XFMEM_POSMATRICES_END) {
if (nTransformMatricesChanged[0] == -1) { if (nTransformMatricesChanged[0] == -1) {
nTransformMatricesChanged[0] = start; nTransformMatricesChanged[0] = start;
nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end; nTransformMatricesChanged[1] = end>XFMEM_POSMATRICES_END?XFMEM_POSMATRICES_END:end;
@ -510,7 +512,7 @@ void VertexShaderMngr::InvalidateXFRange(int start, int end)
} }
} }
if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES ) { if (start < XFMEM_NORMALMATRICES_END && end > XFMEM_NORMALMATRICES) {
int _start = start < XFMEM_NORMALMATRICES ? 0 : start-XFMEM_NORMALMATRICES; int _start = start < XFMEM_NORMALMATRICES ? 0 : start-XFMEM_NORMALMATRICES;
int _end = end < XFMEM_NORMALMATRICES_END ? end-XFMEM_NORMALMATRICES : XFMEM_NORMALMATRICES_END-XFMEM_NORMALMATRICES; int _end = end < XFMEM_NORMALMATRICES_END ? end-XFMEM_NORMALMATRICES : XFMEM_NORMALMATRICES_END-XFMEM_NORMALMATRICES;
@ -524,7 +526,7 @@ void VertexShaderMngr::InvalidateXFRange(int start, int end)
} }
} }
if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES ) { if (start < XFMEM_POSTMATRICES_END && end > XFMEM_POSTMATRICES) {
int _start = start < XFMEM_POSTMATRICES ? XFMEM_POSTMATRICES : start-XFMEM_POSTMATRICES; int _start = start < XFMEM_POSTMATRICES ? XFMEM_POSTMATRICES : start-XFMEM_POSTMATRICES;
int _end = end < XFMEM_POSTMATRICES_END ? end-XFMEM_POSTMATRICES : XFMEM_POSTMATRICES_END-XFMEM_POSTMATRICES; int _end = end < XFMEM_POSTMATRICES_END ? end-XFMEM_POSTMATRICES : XFMEM_POSTMATRICES_END-XFMEM_POSTMATRICES;
@ -548,7 +550,7 @@ void VertexShaderMngr::InvalidateXFRange(int start, int end)
} }
else { else {
if (nLightsChanged[0] > _start) nLightsChanged[0] = _start; if (nLightsChanged[0] > _start) nLightsChanged[0] = _start;
if (nLightsChanged[1] < _end) nLightsChanged[1] = _end; if (nLightsChanged[1] < _end) nLightsChanged[1] = _end;
} }
} }
} }
@ -598,7 +600,6 @@ void VertexShaderMngr::SetProjection(float* _pProjection, int constantIndex)
// LoadXFReg 0x10 // LoadXFReg 0x10
void VertexShaderMngr::LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData) void VertexShaderMngr::LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
{ {
u32 address = baseAddress; u32 address = baseAddress;
for (int i = 0; i < (int)transferSize; i++) for (int i = 0; i < (int)transferSize; i++)
{ {
@ -644,7 +645,7 @@ void VertexShaderMngr::LoadXFReg(u32 transferSize, u32 baseAddress, u32 *pData)
xfregs.hostinfo = *(INVTXSPEC*)&data; xfregs.hostinfo = *(INVTXSPEC*)&data;
break; break;
case 0x1009: //GXSetNumChans (no) case 0x1009: //GXSetNumChans (no)
if ((u32)xfregs.nNumChans != (data&3) ) { if ((u32)xfregs.nNumChans != (data&3)) {
VertexManager::Flush(); VertexManager::Flush();
xfregs.nNumChans = data&3; xfregs.nNumChans = data&3;
} }

View File

@ -20,9 +20,6 @@
#include <map> #include <map>
#include "VertexShader.h"
struct VERTEXSHADER struct VERTEXSHADER
{ {
VERTEXSHADER() : glprogid(0) {} VERTEXSHADER() : glprogid(0) {}
@ -33,6 +30,55 @@ struct VERTEXSHADER
#endif #endif
}; };
class VERTEXSHADERUID
{
public:
u32 values[9];
VERTEXSHADERUID() {
memset(values, 0, sizeof(values));
}
VERTEXSHADERUID(const VERTEXSHADERUID& r) {
for (size_t i = 0; i < sizeof(values) / sizeof(u32); ++i)
values[i] = r.values[i];
}
int GetNumValues() const {
return (((values[0] >> 23) & 0xf)*3 + 3)/4 + 3; // numTexGens*3/4+1
}
bool operator <(const VERTEXSHADERUID& _Right) const
{
if (values[0] < _Right.values[0])
return true;
else if (values[0] > _Right.values[0])
return false;
int N = GetNumValues();
for (int i = 1; i < N; ++i) {
if (values[i] < _Right.values[i])
return true;
else if (values[i] > _Right.values[i])
return false;
}
return false;
}
bool operator ==(const VERTEXSHADERUID& _Right) const
{
if (values[0] != _Right.values[0])
return false;
int N = GetNumValues();
for (int i = 1; i < N; ++i) {
if (values[i] != _Right.values[i])
return false;
}
return true;
}
};
class VertexShaderMngr class VertexShaderMngr
{ {
struct VSCacheEntry struct VSCacheEntry
@ -47,53 +93,7 @@ class VertexShaderMngr
} }
}; };
class VERTEXSHADERUID typedef std::map<VERTEXSHADERUID, VSCacheEntry> VSCache;
{
public:
VERTEXSHADERUID() {
memset(values, 0, sizeof(values));
}
VERTEXSHADERUID(const VERTEXSHADERUID& r) {
for(size_t i = 0; i < sizeof(values) / sizeof(u32); ++i)
values[i] = r.values[i];
}
bool operator<(const VERTEXSHADERUID& _Right) const
{
if( values[0] < _Right.values[0] )
return true;
else if( values[0] > _Right.values[0] )
return false;
int N = (((values[0]>>23)&0xf)*3+3)/4 + 3; // numTexGens*3/4+1
for(int i = 1; i < N; ++i) {
if( values[i] < _Right.values[i] )
return true;
else if( values[i] > _Right.values[i] )
return false;
}
return false;
}
bool operator==(const VERTEXSHADERUID& _Right) const
{
if( values[0] != _Right.values[0] )
return false;
int N = (((values[0]>>23)&0xf)*3+3)/4 + 3; // numTexGens*3/4+1
for(int i = 1; i < N; ++i) {
if( values[i] != _Right.values[i] )
return false;
}
return true;
}
u32 values[9];
};
typedef std::map<VERTEXSHADERUID,VSCacheEntry> VSCache;
static VSCache vshaders; static VSCache vshaders;
static VERTEXSHADER* pShaderLast; static VERTEXSHADER* pShaderLast;