From b4d7ce0197a691a4f07bf7e88d04b7b82c9dbfad Mon Sep 17 00:00:00 2001 From: hrydgard Date: Thu, 14 Aug 2008 21:34:39 +0000 Subject: [PATCH] Some cleanup, extracted XFB convert code into VideoCommon, added non-activated support to gl plugin. + a minor bugfix with no effects seen so far in gl plugin :P git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@209 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/Common.h | 120 +++++------------- Source/Core/VideoCommon/Src/SConscript | 1 + Source/Core/VideoCommon/Src/XFBConvert.cpp | 59 +++++++++ Source/Core/VideoCommon/Src/XFBConvert.h | 25 ++++ Source/Core/VideoCommon/VideoCommon.vcproj | 12 ++ .../Plugin_DSP_NULL/Src/DSPHandler.cpp | 6 +- .../Plugins/Plugin_DSP_NULL/Src/DSPHandler.h | 7 +- .../Plugin_VideoDX9/Plugin_VideoDX9.vcproj | 8 -- Source/Plugins/Plugin_VideoDX9/Src/XFB.cpp | 43 ------- Source/Plugins/Plugin_VideoDX9/Src/XFB.h | 7 - .../Plugin_VideoOGL/Plugin_VideoOGL.vcproj | 18 +-- Source/Plugins/Plugin_VideoOGL/Src/Globals.h | 10 +- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 17 ++- Source/Plugins/Plugin_VideoOGL/Src/XFB.cpp | 72 ++++++----- Source/Plugins/Plugin_VideoOGL/Src/XFB.h | 3 + 15 files changed, 196 insertions(+), 212 deletions(-) create mode 100644 Source/Core/VideoCommon/Src/XFBConvert.cpp create mode 100644 Source/Core/VideoCommon/Src/XFBConvert.h delete mode 100644 Source/Plugins/Plugin_VideoDX9/Src/XFB.cpp delete mode 100644 Source/Plugins/Plugin_VideoDX9/Src/XFB.h diff --git a/Source/Core/Common/Src/Common.h b/Source/Core/Common/Src/Common.h index 8421fd1225..fd5eb57727 100644 --- a/Source/Core/Common/Src/Common.h +++ b/Source/Core/Common/Src/Common.h @@ -117,62 +117,21 @@ typedef union _LARGE_INTEGER #endif -#if !defined (_MSC_VER) && !defined (HAVE_ALIGNED_MALLOC) - -// declare linux equivalents -extern __forceinline void* gc_aligned_malloc(size_t size, size_t align) -{ - char* p = (char*)malloc(size + align); - int off = 2 + align - ((s64)(p + 2) % align); - - p += off; - *(u16*)(p - 2) = off; - - return(p); -} - - -extern __forceinline void gc_aligned_free(void* pmem) -{ - if (pmem != NULL) - { - char* p = (char*)pmem; - free(p - (int)*(u16*)(p - 2)); - } -} - - -#define _aligned_malloc gc_aligned_malloc -#define _aligned_free gc_aligned_free - -#endif - #if defined (_M_IX86) && defined (_WIN32) #define HWCALL __cdecl #else #define HWCALL #endif - -// Hacks -#ifndef SAFE_DELETE -#define SAFE_DELETE(ptr) if (ptr){delete ptr; ptr = 0;} -#endif - -// Common defines -// TODO(ector,fires): turn into inline function? #undef min #undef max template -T min(const T& a, const T& b) {return(a > b ? b : a);} +inline T min(const T& a, const T& b) {return(a > b ? b : a);} template -T max(const T& a, const T& b) {return(a > b ? a : b);} - - - +inline T max(const T& a, const T& b) {return(a > b ? a : b);} // Byte ordering @@ -183,39 +142,25 @@ inline u8 swap8(u8 _data) {return(_data);} #ifdef _WIN32 inline u16 swap16(u16 _data) {return(_byteswap_ushort(_data));} - - inline u32 swap32(u32 _data) {return(_byteswap_ulong(_data));} - - inline u64 swap64(u64 _data) {return(_byteswap_uint64(_data));} - #elif __linux__ } #include namespace Common { inline u16 swap16(u16 _data) {return(bswap_16(_data));} - - inline u32 swap32(u32 _data) {return(bswap_32(_data));} - - inline u64 swap64(u64 _data) {return(bswap_64(_data));} #else inline u16 swap16(u16 data) {return((data >> 8) | (data << 8));} - - inline u32 swap32(u32 data) {return((swap16(data) << 16) | swap16(data >> 16));} - - inline u64 swap64(u64 data) {return(((u64)swap32(data) << 32) | swap32(data >> 32));} #endif - } // end of namespace Common // Utility functions @@ -231,36 +176,35 @@ extern void __Log(int logNumber, const char* text, ...); class LogTypes { public: - - enum LOG_TYPE - { - MASTER_LOG, - BOOT, - PIXELENGINE, - COMMANDPROCESSOR, - VIDEOINTERFACE, - SERIALINTERFACE, - PERIPHERALINTERFACE, - MEMMAP, - DSPINTERFACE, - STREAMINGINTERFACE, - DVDINTERFACE, - GPFIFO, - EXPANSIONINTERFACE, - AUDIO_INTERFACE, - GEKKO, - HLE, - DSPHLE, - VIDEO, - AUDIO, - DYNA_REC, - OSREPORT, - CONSOLE, - WII_IOB, - WII_IPC, - WII_IPC_HLE, - NUMBER_OF_LOGS - }; + enum LOG_TYPE + { + MASTER_LOG, + BOOT, + PIXELENGINE, + COMMANDPROCESSOR, + VIDEOINTERFACE, + SERIALINTERFACE, + PERIPHERALINTERFACE, + MEMMAP, + DSPINTERFACE, + STREAMINGINTERFACE, + DVDINTERFACE, + GPFIFO, + EXPANSIONINTERFACE, + AUDIO_INTERFACE, + GEKKO, + HLE, + DSPHLE, + VIDEO, + AUDIO, + DYNA_REC, + OSREPORT, + CONSOLE, + WII_IOB, + WII_IPC, + WII_IPC_HLE, + NUMBER_OF_LOGS + }; }; typedef bool (*PanicAlertHandler)(const char* text, bool yes_no); @@ -268,7 +212,6 @@ void RegisterPanicAlertHandler(PanicAlertHandler handler); void Host_UpdateLogDisplay(); - // Logging macros #ifdef LOGGING @@ -297,7 +240,6 @@ void Host_UpdateLogDisplay(); #endif - #ifdef _WIN32 #define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_) #define _assert_msg_(_t_, _a_, _fmt_, ...)\ diff --git a/Source/Core/VideoCommon/Src/SConscript b/Source/Core/VideoCommon/Src/SConscript index 415e17d5b5..a91f110e17 100644 --- a/Source/Core/VideoCommon/Src/SConscript +++ b/Source/Core/VideoCommon/Src/SConscript @@ -5,6 +5,7 @@ files = ["BPMemory.cpp", "LookUpTables.cpp", "TextureDecoder.cpp", "XFMemory.cpp", + "XFBConvert.cpp", ] env_common = env.Copy(CXXFLAGS = " -fPIC ") diff --git a/Source/Core/VideoCommon/Src/XFBConvert.cpp b/Source/Core/VideoCommon/Src/XFBConvert.cpp new file mode 100644 index 0000000000..3d9884f861 --- /dev/null +++ b/Source/Core/VideoCommon/Src/XFBConvert.cpp @@ -0,0 +1,59 @@ +// 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 "XFBConvert.h" +#include "Common.h" + +// TODO: Convert this thing into wicked fast SSE2. + +namespace { + +int bound(int i) +{ + return (i>255)?255:((i<0)?0:i); +} + +void yuv2rgb(int y, int u, int v, int &r, int &g, int &b) +{ + b = bound((76283*(y - 16) + 132252*(u - 128))>>16); + g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u? + r = bound((76283*(y - 16) + 104595*(v - 128))>>16); +} + +} // namespace + +void ConvertXFB(u32 *dst, const u8* _pXFB, int width, int height) +{ + const unsigned char *src = _pXFB; + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++, src += 4) + { + int Y1 = src[0]; + int U = src[1]; + int Y2 = src[2]; + int V = src[3]; + + int r, g, b; + yuv2rgb(Y1,U,V, r,g,b); + *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); + yuv2rgb(Y2,U,V, r,g,b); + *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); + } + } +} + diff --git a/Source/Core/VideoCommon/Src/XFBConvert.h b/Source/Core/VideoCommon/Src/XFBConvert.h new file mode 100644 index 0000000000..cd0557be02 --- /dev/null +++ b/Source/Core/VideoCommon/Src/XFBConvert.h @@ -0,0 +1,25 @@ +// 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 _XFB_CONVERT +#define _XFB_CONVERT + +#include "Common.h" + +void ConvertXFB(u32 *dst, const u8* _pXFB, int width, int height); + +#endif diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index 94ea3e07ee..4e80ec97f8 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -413,6 +413,10 @@ RelativePath=".\Src\LookUpTables.h" > + + @@ -421,6 +425,14 @@ RelativePath=".\Src\TextureDecoder.h" > + + + + diff --git a/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.cpp b/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.cpp index 5b01c7481a..8c2c144f57 100644 --- a/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.cpp +++ b/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.cpp @@ -36,7 +36,7 @@ CDSPHandler::CDSPHandler() CDSPHandler::~CDSPHandler() { - SAFE_DELETE(m_pUCode); + delete m_pUCode; } @@ -90,13 +90,13 @@ void CDSPHandler::SendMailToDSP(u32 _uMail) IUCode* CDSPHandler::GetUCode() { - return(m_pUCode); + return m_pUCode; } void CDSPHandler::SetUCode(u32 _crc) { - SAFE_DELETE(m_pUCode); + delete m_pUCode; m_MailHandler.Clear(); m_pUCode = UCodeFactory(_crc, m_MailHandler); diff --git a/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.h b/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.h index 6b76234da9..c6a91bde50 100644 --- a/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.h +++ b/Source/Plugins/Plugin_DSP_NULL/Src/DSPHandler.h @@ -33,22 +33,18 @@ class CDSPHandler IUCode* GetUCode(); void SetUCode(u32 _crc); - CMailHandler& AccessMailHandler() {return(m_MailHandler);} - static CDSPHandler& GetInstance() { return(*m_pInstance); } - static void Destroy() { - SAFE_DELETE(m_pInstance); + delete m_pInstance; } - static CDSPHandler& CreateInstance() { if (m_pInstance == NULL) @@ -59,7 +55,6 @@ class CDSPHandler return(*m_pInstance); } - private: CDSPHandler(); diff --git a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj index fb683a6a53..c7f43296df 100644 --- a/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj +++ b/Source/Plugins/Plugin_VideoDX9/Plugin_VideoDX9.vcproj @@ -1565,14 +1565,6 @@ RelativePath=".\Src\Vec3.h" > - - - - diff --git a/Source/Plugins/Plugin_VideoDX9/Src/XFB.cpp b/Source/Plugins/Plugin_VideoDX9/Src/XFB.cpp deleted file mode 100644 index 6d39642e46..0000000000 --- a/Source/Plugins/Plugin_VideoDX9/Src/XFB.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "XFB.h" -#include "Common.h" - -// __________________________________________________________________________________________________ -// Video_UpdateXFB -// - -// TODO(ector): Write protect XFB. As soon as something pokes there, -// switch to a mode where we actually display the XFB on top of the 3D. -// If no writes have happened within 5 frames, revert to normal mode. - -int bound(int i) -{ - return (i>255)?255:((i<0)?0:i); -} -void yuv2rgb(int y, int u, int v, int &r, int &g, int &b) -{ - b = bound((76283*(y - 16) + 132252*(u - 128))>>16); - g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u? - r = bound((76283*(y - 16) + 104595*(v - 128))>>16); -} - -void ConvertXFB(int *dst, const u8* _pXFB, int width, int height) -{ - const unsigned char *src = _pXFB; - for (int y=0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - int Y1 = *src++; - int U = *src++; - int Y2 = *src++; - int V = *src++; - - int r,g,b; - yuv2rgb(Y1,U,V,r,g,b); - *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); - yuv2rgb(Y2,U,V,r,g,b); - *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); - } - } -} - diff --git a/Source/Plugins/Plugin_VideoDX9/Src/XFB.h b/Source/Plugins/Plugin_VideoDX9/Src/XFB.h deleted file mode 100644 index a842bb9fd0..0000000000 --- a/Source/Plugins/Plugin_VideoDX9/Src/XFB.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _XFB_H -#define _XFB_H - -#include "Common.h" -void ConvertXFB(int *dst, const u8* _pXFB, int width, int height); - -#endif \ No newline at end of file diff --git a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj index 499c5532ac..a9a31c11e4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj +++ b/Source/Plugins/Plugin_VideoOGL/Plugin_VideoOGL.vcproj @@ -1,7 +1,7 @@ + + + + @@ -1040,14 +1048,6 @@ RelativePath=".\Src\Render.h" > - - - - diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Globals.h b/Source/Plugins/Plugin_VideoOGL/Src/Globals.h index dda0104203..c6789dae16 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Globals.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/Globals.h @@ -100,13 +100,7 @@ struct RECT // several macros // PLEASE DO NOT USE THE FOLLOWING SAFE* -// They only encourage sloppy coding, and hides bugs. -#ifndef SAFE_DELETE_ARRAY -#define SAFE_DELETE_ARRAY(x) if( (x) != NULL ) { delete[] (x); (x) = NULL; } -#endif -#ifndef SAFE_RELEASE -#define SAFE_RELEASE(x) if( (x) != NULL ) { (x)->Release(); (x) = NULL; } -#endif +// They only encourage sloppy coding, and hide bugs. #define SAFE_RELEASE_CGPROG(x) { if( (x) != NULL ) { cgDestroyProgram(x); x = NULL; } } #define SAFE_RELEASE_PROG(x) { if( (x) != 0 ) { glDeleteProgramsARB(1, &(x)); x = 0; } } #define SAFE_RELEASE_TEX(x) { if( (x) != 0 ) { glDeleteTextures(1, &(x)); x = 0; } } @@ -269,8 +263,6 @@ unsigned char memcmp_mmx(const void* src1, const void* src2, int cmpsize); #define memcmp_gc memcmp #endif -//#define RAM_MASK 0x1FFFFFF - #include "main.h" inline u8 *Memory_GetPtr(u32 _uAddress) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index a170128264..b2df8fe683 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -27,6 +27,7 @@ #include "VertexShader.h" #include "PixelShaderManager.h" #include "VertexLoader.h" +#include "XFB.h" #ifdef _WIN32 #include "OS\Win32.h" @@ -52,6 +53,7 @@ static bool s_bOutputCgErrors = true; static int nZBufferRender = 0; // if > 0, then using zbuffer render static u32 s_uFramebuffer = 0; static u32 s_RenderTargets[1] = {0}, s_DepthTarget = 0, s_ZBufferTarget = 0; + static bool s_bATIDrawBuffers = false, s_bHaveStencilBuffer = false; static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal; static int s_nCurTarget = 0; @@ -273,26 +275,29 @@ bool Renderer::Create2() if (!Initialize()) return false; + XFB_Init(); return glGetError() == GL_NO_ERROR && bSuccess; } void Renderer::Shutdown(void) { - SAFE_DELETE(s_pfont); + delete s_pfont; + s_pfont = 0; - if( g_cgcontext != 0 ) { + XFB_Shutdown(); + + if (g_cgcontext != 0) { cgDestroyContext(g_cgcontext); g_cgcontext = 0; } - if( s_RenderTargets[0] ) { + if (s_RenderTargets[0]) { glDeleteTextures(ARRAYSIZE(s_RenderTargets), (GLuint *)s_RenderTargets); memset(s_RenderTargets, 0, sizeof(s_RenderTargets)); } - if( s_DepthTarget ) { + if (s_DepthTarget) { glDeleteRenderbuffersEXT(1, (GLuint *)&s_DepthTarget); s_DepthTarget = 0; } - if (s_uFramebuffer != 0) { glDeleteFramebuffersEXT( 1, (GLuint *)&s_uFramebuffer); s_uFramebuffer = 0; @@ -550,7 +555,7 @@ void Renderer::FlushZBufferAlphaToTarget() glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(-1,-1); glTexCoord2f(0, (float)(GetTargetHeight()<255)?255:((i<0)?0:i); + xfb_buffer = new u8[XFB_WIDTH * XFB_HEIGHT * 4]; + memset(xfb_buffer, 0, XFB_WIDTH * XFB_HEIGHT * 4); + glGenTextures(1, &xfb_texture); + glBindTexture(GL_TEXTURE_RECTANGLE_NV, xfb_texture); + glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer); } -void yuv2rgb(int y, int u, int v, int &r, int &g, int &b) +void XFB_Draw(u8 *xfb_in_ram) { - b = bound((76283*(y - 16) + 132252*(u - 128))>>16); - g = bound((76283*(y - 16) - 53281 *(v - 128) - 25624*(u - 128))>>16); //last one u? - r = bound((76283*(y - 16) + 104595*(v - 128))>>16); + Renderer::ResetGLState(); + ConvertXFB((u32 *)xfb_buffer, xfb_in_ram, XFB_WIDTH, XFB_HEIGHT); + glBindTexture(GL_TEXTURE_RECTANGLE_NV, xfb_texture); + glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 4, XFB_WIDTH, XFB_HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, xfb_buffer); + TextureMngr::EnableTexRECT(0); + for (int i = 1; i < 8; ++i) + TextureMngr::DisableStage(i); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(-1,-1); + glTexCoord2f(0, XFB_WIDTH); glVertex2f(-1,1); + glTexCoord2f(XFB_WIDTH, XFB_HEIGHT); glVertex2f(1,1); + glTexCoord2f(XFB_WIDTH, 0); glVertex2f(1,-1); + glEnd(); + + Renderer::RestoreGLState(); } -void ConvertXFB(int *dst, const u8* _pXFB, int width, int height) +void XFB_Shutdown() { - const unsigned char *src = _pXFB; - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - int Y1 = *src++; - int U = *src++; - int Y2 = *src++; - int V = *src++; - - int r,g,b; - yuv2rgb(Y1, U, V, r, g, b); - *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); - yuv2rgb(Y2, U, V, r, g, b); - *dst++ = 0xFF000000 | (r<<16) | (g<<8) | (b); - } - } + glDeleteTextures(1, &xfb_texture); + xfb_texture = 0; + delete [] xfb_buffer; + xfb_buffer = 0; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/XFB.h b/Source/Plugins/Plugin_VideoOGL/Src/XFB.h index 62be9aff09..ae72b01044 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/XFB.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/XFB.h @@ -18,5 +18,8 @@ #ifndef _XFB_H #define _XFB_H +void XFB_Init(); +void XFB_Draw(u8 *xfb_in_ram); +void XFB_Shutdown(); #endif