From 49d568488ca9052d3275009e4ab6db716184bd59 Mon Sep 17 00:00:00 2001 From: Rodolfo Osvaldo Bogado Date: Sun, 28 Mar 2010 23:51:32 +0000 Subject: [PATCH] fixed fps limiting when using using virtual xfb, now fps = vps, in fact now real xfb is as fast as no using xfb, i'm thinking now that the correct thing is leave it enabled as default, and even remove the option. the problem is one strange behavior i found, in opengl when xfb is enable, frame limit causes the frame rate to be limited exact half the correct speed, so if you choose auto and the game uses 30 fps you get 15 fps so in opengl, you have to limit to the exact double of the game speed, 100 to pal games and 120 to ntsc. in d3d this not happened every time, it just happen when you change some time consuming setting like changing the ssaa or resizing the window, in that case you have to disable and re enable frame limit to get the correct fps to all the devs please if you can help me debug this, will give you a lot of thanks as i'm short in time to debug this error and is driving me crazy not to find the source of the problem. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5249 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugin_VideoDX9/Src/FramebufferManager.cpp | 3 ++- Source/Plugins/Plugin_VideoDX9/Src/Render.cpp | 17 +++++++---------- Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 14 +++++++------- Source/Plugins/Plugin_VideoDX9/Src/main.h | 1 + Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 9 +++++---- Source/Plugins/Plugin_VideoOGL/Src/Render.cpp | 7 +++---- Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 16 +++++++--------- 7 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp index 9e1ae5ebc9..6d926cba9d 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp @@ -208,7 +208,8 @@ void FramebufferManager::Destroy() for (VirtualXFBListType::iterator it = m_virtualXFBList.begin(); it != m_virtualXFBList.end(); ++it) { - it->xfbSource.texture->Release(); + if(it->xfbSource.texture) + it->xfbSource.texture->Release(); } m_virtualXFBList.clear(); if(m_realXFBSource.texture) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp index f6cd4e947f..9f7ed73d95 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/Render.cpp @@ -86,7 +86,6 @@ static bool s_bScreenshot = false; static Common::CriticalSection s_criticalScreenshot; static char s_sScreenshotName[1024]; static LPDIRECT3DSURFACE9 ScreenShootMEMSurface = NULL; -extern volatile u32 s_swapRequested; // State translation lookup tables @@ -1013,13 +1012,14 @@ void Renderer::SetBlendMode(bool forceUpdate) void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { - if(!fbWidth || !fbHeight) + if (g_bSkipCurrentFrame || !XFBWrited || !fbWidth || !fbHeight) + { + g_VideoInitialize.pCopiedToXFB(false); return; + } // this function is called after the XFB field is changed, not after // EFB is copied to XFB. In this way, flickering is reduced in games - // and seems to also give more FPS in ZTP - if(!XFBWrited) - return; + // and seems to also give more FPS in ZTP if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2; @@ -1027,14 +1027,11 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) const XFBSource** xfbSourceList = FBManager.GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount); if (!xfbSourceList || xfbCount == 0) { + g_VideoInitialize.pCopiedToXFB(false); return; } - if (g_bSkipCurrentFrame) - { - g_VideoInitialize.pCopiedToXFB(false); - return; - } + Renderer::ResetAPIState(); // Set the backbuffer as the rendering target diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 171bb6676a..9db267fe85 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -359,6 +359,12 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) if (s_PluginInitialized && g_ActiveConfig.bUseXFB) { // Make sure previous swap request has made it to the screen + s_beginFieldArgs.xfbAddr = xfbAddr; + s_beginFieldArgs.field = field; + s_beginFieldArgs.fbWidth = fbWidth; + s_beginFieldArgs.fbHeight = fbHeight; + + Common::AtomicStoreRelease(s_swapRequested, TRUE); if (g_VideoInitialize.bOnThread) { while (Common::AtomicLoadAcquire(s_swapRequested) && !s_FifoShuttingDown) @@ -367,13 +373,7 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) } else VideoFifo_CheckSwapRequest(); - - s_beginFieldArgs.xfbAddr = xfbAddr; - s_beginFieldArgs.field = field; - s_beginFieldArgs.fbWidth = fbWidth; - s_beginFieldArgs.fbHeight = fbHeight; - - Common::AtomicStoreRelease(s_swapRequested, TRUE); + } } diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.h b/Source/Plugins/Plugin_VideoDX9/Src/main.h index f76403b2f4..fb3775ab7e 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.h @@ -22,5 +22,6 @@ #include "Render.h" extern SVideoInitialize g_VideoInitialize; +extern volatile u32 s_swapRequested; #endif diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 53e35c690a..1cf70b4dc9 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -761,11 +761,12 @@ void OpenGL_Update() int height = rcWindow.bottom - rcWindow.top; // If we are rendering to a child window - if (EmuWindow::GetParentWnd() != 0) + if (EmuWindow::GetParentWnd() != 0 && (s_backbuffer_width != width || s_backbuffer_height != height) && width >= 4 && height >= 4) + { ::MoveWindow(EmuWindow::GetWnd(), 0, 0, width, height, FALSE); - - s_backbuffer_width = width; - s_backbuffer_height = height; + s_backbuffer_width = width; + s_backbuffer_height = height; + } #elif defined(HAVE_X11) && HAVE_X11 #endif diff --git a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index f3e23037fc..8aae9d64e4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -801,13 +801,11 @@ void Renderer::RenderToXFB(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRect // This function has the final picture. We adjust the aspect ratio here. void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { - if (s_skipSwap) + if (g_bSkipCurrentFrame || !XFBWrited || !fbWidth || !fbHeight) { g_VideoInitialize.pCopiedToXFB(false); return; - } - if(!XFBWrited) - return; + } if (field == FIELD_LOWER) xfbAddr -= fbWidth * 2; @@ -815,6 +813,7 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) const XFBSource** xfbSourceList = g_framebufferManager.GetXFBSource(xfbAddr, fbWidth, fbHeight, xfbCount); if (!xfbSourceList) { + g_VideoInitialize.pCopiedToXFB(false); WARN_LOG(VIDEO, "Failed to get video for this frame"); return; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 947e98194e..245d146841 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -518,7 +518,12 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { if (s_PluginInitialized && g_ActiveConfig.bUseXFB) { - // Make sure previous swap request has made it to the screen + s_beginFieldArgs.xfbAddr = xfbAddr; + s_beginFieldArgs.field = field; + s_beginFieldArgs.fbWidth = fbWidth; + s_beginFieldArgs.fbHeight = fbHeight; + + Common::AtomicStoreRelease(s_swapRequested, TRUE); if (g_VideoInitialize.bOnThread) { while (Common::AtomicLoadAcquire(s_swapRequested) && !s_FifoShuttingDown) @@ -526,14 +531,7 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) Common::YieldCPU(); } else - VideoFifo_CheckSwapRequest(); - - s_beginFieldArgs.xfbAddr = xfbAddr; - s_beginFieldArgs.field = field; - s_beginFieldArgs.fbWidth = fbWidth; - s_beginFieldArgs.fbHeight = fbHeight; - - Common::AtomicStoreRelease(s_swapRequested, TRUE); + VideoFifo_CheckSwapRequest(); } }