Substantial XFB speedup. There's more to get though, for example by using a shader for color conversion instead - but i like having a fast CPU implementation too. Also adds some sanity checks. PAL games still have problems.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@885 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-10-15 21:29:44 +00:00
parent fffc2b6a77
commit 34a4fee1c5
9 changed files with 145 additions and 34 deletions

View File

@ -508,25 +508,32 @@ void Update()
VerticalBeamPos = 1; VerticalBeamPos = 1;
} }
if(VerticalBeamPos == NextXFBRender) if (VerticalBeamPos == NextXFBRender)
{ {
u8* xfbPtr = 0; u8* xfbPtr = 0;
int yOffset = 0; int yOffset = 0;
if(NextXFBRender == 1) if (NextXFBRender == 1)
{ {
NextXFBRender = LinesPerField; NextXFBRender = LinesPerField;
xfbPtr = Memory::GetPointer(VideoInterface::m_FrameBufferTop.Hex); // The & mask is a hack for mario kart
u32 addr = (VideoInterface::m_FrameBufferTop.Hex & 0xFFFFFFF) | 0x80000000;
if (addr >= 0x80000000 &&
addr <= (0x81800000-640*480*2))
xfbPtr = Memory::GetPointer(addr);
} }
else else
{ {
NextXFBRender = 1; NextXFBRender = 1;
xfbPtr = Memory::GetPointer(VideoInterface::m_FrameBufferBottom.Hex); u32 addr = (VideoInterface::m_FrameBufferBottom.Hex & 0xFFFFFFF) | 0x80000000;
if (addr >= 0x80000000 &&
addr <= (0x81800000-640*480*2))
xfbPtr = Memory::GetPointer(addr);
yOffset = -1; yOffset = -1;
} }
if(xfbPtr && PluginVideo::IsLoaded()) if (xfbPtr && PluginVideo::IsLoaded())
{ {
int fbWidth = m_VIHorizontalStepping.FieldSteps * 16; int fbWidth = m_VIHorizontalStepping.FieldSteps * 16;
int fbHeight = (m_VIHorizontalStepping.FbSteps / m_VIHorizontalStepping.FieldSteps) * m_VIVerticalTimingRegister.ACV; int fbHeight = (m_VIHorizontalStepping.FbSteps / m_VIHorizontalStepping.FieldSteps) * m_VIVerticalTimingRegister.ACV;
@ -549,6 +556,6 @@ void Update()
} }
} }
} }
} }

View File

@ -347,7 +347,7 @@ void CFrame::OnOpen(wxCommandEvent& WXUNUSED (event))
wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString,
wxString::Format wxString::Format
( (
_T("All GC/Wii files (elf, dol, gcm, iso)|*.elf;*.dol;*.gcm;*.iso|All files (%s)|%s"), _T("All GC/Wii files (elf, dol, gcm, iso)|*.elf;*.dol;*.gcm;*.iso;*.gcz|All files (%s)|%s"),
wxFileSelectorDefaultWildcardStr, wxFileSelectorDefaultWildcardStr,
wxFileSelectorDefaultWildcardStr wxFileSelectorDefaultWildcardStr
), ),
@ -607,6 +607,9 @@ void CFrame::OnToggleStatusbar(wxCommandEvent& event)
void CFrame::OnKeyDown(wxKeyEvent& event) void CFrame::OnKeyDown(wxKeyEvent& event)
{ {
event.Skip();
return;
if (((event.GetKeyCode() == WXK_RETURN) && (event.GetModifiers() == wxMOD_ALT)) || if (((event.GetKeyCode() == WXK_RETURN) && (event.GetModifiers() == wxMOD_ALT)) ||
(event.GetKeyCode() == WXK_ESCAPE)) (event.GetKeyCode() == WXK_ESCAPE))
{ {

View File

@ -15,26 +15,39 @@
// 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/
#if _WIN32
#include <intrin.h>
#endif
#include <xmmintrin.h>
#include "XFBConvert.h" #include "XFBConvert.h"
#include "Common.h" #include "Common.h"
// TODO: Convert this thing into wicked fast SSE2.
namespace { namespace {
int bound(int i) u8 bound_table[3*256];
int y[256];
int v1[256];
int v2[256];
int u1[256];
int u2[256];
u8 *bound_lut = bound_table + 256;
inline int bound(int i)
{ {
return (i>255)?255:((i<0)?0:i); return bound_lut[i];
} }
void yuv2rgb(int y, int u, int v, int &r, int &g, int &b) inline void yuv2rgb(int y, int u, int v, int &r, int &g, int &b)
{ {
b = bound((76283*(y - 16) + 132252*(u - 128))>>16); int gray = 76283*(y - 16);
g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u? b = bound((gray + 132252*(u - 128))>>16);
r = bound((76283*(y - 16) + 104595*(v - 128))>>16); g = bound((gray - 53281 *(v - 128) - 25624*(u - 128))>>16);
r = bound((gray + 104595*(v - 128))>>16);
} }
void rgb2yuv(int r, int g, int b, int &y, int &u, int &v) inline void rgb2yuv(int r, int g, int b, int &y, int &u, int &v)
{ {
y = (((16843 * r) + (33030 * g) + (6423 * b)) >> 16) + 16; y = (((16843 * r) + (33030 * g) + (6423 * b)) >> 16) + 16;
v = (((28770 * r) - (24117 * g) - (4653 * b)) >> 16) + 128; v = (((28770 * r) - (24117 * g) - (4653 * b)) >> 16) + 128;
@ -43,24 +56,61 @@ void rgb2yuv(int r, int g, int b, int &y, int &u, int &v)
} // namespace } // namespace
//const __m128i _bias1 = _mm_set_epi32(16 << 16, 128/2 << 16, 0, 128/2 << 16);
//const __m128i _bias2 = _mm_set_epi32(0, 128/2 << 16, 16 << 16, 128/2 << 16);
const __m128i _bias1 = _mm_set_epi32(128/2 << 16, 0, 128/2 << 16, 16 << 16);
const __m128i _bias2 = _mm_set_epi32(128/2 << 16, 16 << 16, 128/2 << 16, 0);
__m128i _r1[256];
__m128i _r2[256];
__m128i _g1[256];
__m128i _g2[256];
__m128i _b1[256];
__m128i _b2[256];
void InitXFBConvTables()
{
for (int i = 0; i < 256; i++)
{
bound_table[i] = 0;
bound_table[256 + i] = i;
bound_table[512 + i] = 255;
y[i] = 76283*(i - 16);
u1[i] = 132252 * (i - 128);
u2[i] = -25624 * (i - 128);
v1[i] = -53281 * (i - 128);
v2[i] = 104595 * (i - 128);
_r1[i] = _mm_set_epi32( 28770 * i / 2, 0, -9699 * i / 2, 16843 * i);
_g1[i] = _mm_set_epi32(-24117 * i / 2, 0, -19071 * i / 2, 33030 * i);
_b1[i] = _mm_set_epi32( -4653 * i / 2, 0, 28770 * i / 2, 6423 * i);
_r2[i] = _mm_set_epi32( 28770 * i / 2, 16843 * i, -9699 * i / 2, 0);
_g2[i] = _mm_set_epi32(-24117 * i / 2, 33030 * i, -19071 * i / 2, 0);
_b2[i] = _mm_set_epi32( -4653 * i / 2, 6423 * i, 28770 * i / 2, 0);
}
}
void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height) void ConvertFromXFB(u32 *dst, const u8* _pXFB, int width, int height)
{ {
const unsigned char *src = _pXFB; const unsigned char *src = _pXFB;
u32 numBlocks = (width * height) / 2; u32 numBlocks = (width * height) / 2;
for (u32 i = 0; i < numBlocks; i++, src += 4) for (u32 i = 0; i < numBlocks; i++, src += 4)
{ {
int Y1 = src[0]; int Y1 = y[src[0]];
int Y2 = y[src[2]];
int U = src[1]; int U = src[1];
int Y2 = src[2];
int V = src[3]; int V = src[3];
int b1 = bound((Y1 + u1[U]) >> 16);
int r, g, b; int g1 = bound((Y1 + v1[V] + u2[U])>>16);
yuv2rgb(Y1,U,V, r,g,b); int r1 = bound((Y1 + v2[V]) >> 16);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); int b2 = bound((Y2 + u1[U]) >> 16);
yuv2rgb(Y2,U,V, r,g,b); int g2 = bound((Y2 + v1[V] + u2[U]) >> 16);
*dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); int r2 = bound((Y2 + v2[V]) >> 16);
*dst++ = 0xFF000000 | (r1<<16) | (g1<<8) | (b1);
*dst++ = 0xFF000000 | (r2<<16) | (g2<<8) | (b2);
} }
} }
@ -69,18 +119,43 @@ void ConvertToXFB(u32 *dst, const u8* _pEFB, int width, int height)
const unsigned char *src = _pEFB; const unsigned char *src = _pEFB;
u32 numBlocks = (width * height) / 2; u32 numBlocks = (width * height) / 2;
#if 1
for (u32 i = 0; i < numBlocks; i++) __m128i zero = _mm_setzero_si128();
for (int i = 0; i < numBlocks / 4; i++)
{
__m128i yuyv[4];
for (int j = 0; j < 4; j++) {
yuyv[j] = _mm_srai_epi32(
_mm_add_epi32(
_mm_add_epi32(
_mm_add_epi32(_r1[src[0]], _mm_add_epi32(_g1[src[1]], _b1[src[2]])), _bias1),
_mm_add_epi32(
_mm_add_epi32(_r2[src[4]], _mm_add_epi32(_g2[src[5]], _b2[src[6]])), _bias2)
), 16);
src += 8;
}
__m128i four_dest = _mm_packus_epi16(_mm_packs_epi32(yuyv[0], yuyv[1]), _mm_packs_epi32(yuyv[2], yuyv[3]));
_mm_storeu_si128((__m128i *)dst, four_dest);
dst += 4;
}
#else
for (int i = 0; i < numBlocks; i++)
{ {
int y1 = (((16843 * src[0]) + (33030 * src[1]) + (6423 * src[2])) >> 16) + 16; int y1 = (((16843 * src[0]) + (33030 * src[1]) + (6423 * src[2])) >> 16) + 16;
int u1 = ((-(9699 * src[0]) - (19071 * src[1]) + (28770 * src[2])) >> 16) + 128; int u1 = ((-(9699 * src[0]) - (19071 * src[1]) + (28770 * src[2])) >> 16) + 128;
int v1 = (((28770 * src[0]) - (24117 * src[1]) - (4653 * src[2])) >> 16) + 128;
src += 4; src += 4;
int u2 = ((-(9699 * src[0]) - (19071 * src[1]) + (28770 * src[2])) >> 16) + 128;
int y2 = (((16843 * src[0]) + (33030 * src[1]) + (6423 * src[2])) >> 16) + 16; int y2 = (((16843 * src[0]) + (33030 * src[1]) + (6423 * src[2])) >> 16) + 16;
int v2 = (((28770 * src[0]) - (24117 * src[1]) - (4653 * src[2])) >> 16) + 128; int v2 = (((28770 * src[0]) - (24117 * src[1]) - (4653 * src[2])) >> 16) + 128;
src += 4; src += 4;
*dst++ = (v2 << 24) | (y2 << 16) | (u1 << 8) | (y1); int u = bound_lut[(u1 + u2) / 2];
} int v = bound_lut[(v1 + v2) / 2];
*dst++ = (v << 24) | (y2 << 16) | (u << 8) | (y1);
}
#endif
} }

View File

@ -20,6 +20,8 @@
#include "Common.h" #include "Common.h"
void InitXFBConvTables();
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 16-bit 4:2:2 YUV data

View File

@ -173,10 +173,15 @@
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs" AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
StringPooling="true"
RuntimeLibrary="0" RuntimeLibrary="0"
BufferSecurityCheck="false" BufferSecurityCheck="false"
EnableEnhancedInstructionSet="2"
FloatingPointModel="0"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
WarnAsError="false" WarnAsError="false"
@ -236,6 +241,10 @@
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="false"
AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs" AdditionalIncludeDirectories="../../Core/Common/Src;../../PluginSpecs"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="0" RuntimeLibrary="0"
@ -473,6 +482,14 @@
<File <File
RelativePath=".\Src\XFBConvert.cpp" RelativePath=".\Src\XFBConvert.cpp"
> >
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AssemblerOutput="4"
/>
</FileConfiguration>
</File> </File>
<File <File
RelativePath=".\Src\XFBConvert.h" RelativePath=".\Src\XFBConvert.h"

View File

@ -38,6 +38,7 @@
#include "W32Util/Misc.h" #include "W32Util/Misc.h"
#include "EmuWindow.h" #include "EmuWindow.h"
#include "VideoState.h" #include "VideoState.h"
#include "XFBConvert.h"
#include "Utils.h" #include "Utils.h"
@ -125,7 +126,7 @@ bool Init()
return false; return false;
} }
InitLUTs(); InitLUTs();
InitXFBConvTables();
} }
initCount++; initCount++;

View File

@ -126,6 +126,8 @@ namespace EmuWindow
break; break;
case WM_CLOSE: case WM_CLOSE:
ExitProcess(0);
//Core::SetState(Core::CORE_UNINITIALIZED); //Core::SetState(Core::CORE_UNINITIALIZED);
return 0; return 0;

View File

@ -27,7 +27,9 @@
enum { enum {
XFB_WIDTH = 640, XFB_WIDTH = 640,
XFB_HEIGHT = 480, XFB_HEIGHT = 480, //480,
XFB_BUF_HEIGHT = 538, //480,
// TODO: figure out what to do with PAL
}; };
static GLuint xfb_texture; static GLuint xfb_texture;
@ -39,8 +41,8 @@ static GLuint s_xfbRenderBuffer = 0;
void XFB_Init() void XFB_Init()
{ {
// used to render XFB // used to render XFB
xfb_buffer = new u8[XFB_WIDTH * XFB_HEIGHT * 4]; xfb_buffer = new u8[XFB_WIDTH * XFB_BUF_HEIGHT * 4];
memset(xfb_buffer, 0, XFB_WIDTH * XFB_HEIGHT * 4); memset(xfb_buffer, 0, XFB_WIDTH * XFB_BUF_HEIGHT * 4);
glGenTextures(1, &xfb_texture); glGenTextures(1, &xfb_texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, xfb_texture); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, xfb_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer);

View File

@ -37,6 +37,7 @@
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "VertexShaderManager.h" #include "VertexShaderManager.h"
#include "XFB.h" #include "XFB.h"
#include "XFBConvert.h"
#include "VideoState.h" #include "VideoState.h"
#include "Debugger/Debugger.h" // for the CDebugger class #include "Debugger/Debugger.h" // for the CDebugger class
@ -182,6 +183,7 @@ void Video_Initialize(SVideoInitialize* _pVideoInitialize)
frameCount = 0; frameCount = 0;
g_VideoInitialize = *_pVideoInitialize; g_VideoInitialize = *_pVideoInitialize;
InitLUTs(); InitLUTs();
InitXFBConvTables();
g_Config.Load(); g_Config.Load();
if (!OpenGL_Create(g_VideoInitialize, 640, 480)) { //640x480 will be the default if all else fails// if (!OpenGL_Create(g_VideoInitialize, 640, 480)) { //640x480 will be the default if all else fails//