diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index e5f3fb1d32..9c80488ad1 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'}; // Update this to the current SVN revision every time you change shader generation code. // We don't automatically get this from SVN_REV because that would mean regenerating the // shader cache for every revision, graphics-related or not, which is simply annoying. -const int version = 5691; +const int version = 5812; LinearDiskCache::LinearDiskCache() : file_(NULL), num_entries_(0) { diff --git a/Source/Core/Core/Src/HW/VideoInterface.cpp b/Source/Core/Core/Src/HW/VideoInterface.cpp index 69a2c284d8..b627fed499 100644 --- a/Source/Core/Core/Src/HW/VideoInterface.cpp +++ b/Source/Core/Core/Src/HW/VideoInterface.cpp @@ -729,7 +729,7 @@ void UpdateParameters() TargetRefreshRate = PAL_FIELD_RATE; // AyuanX: Some games are pretty sensitive to this value // So we have to make it run a little faster to prevent potential time out - TicksPerFrame = SystemTimers::GetTicksPerSecond() / (PAL_FIELD_RATE + 1); + TicksPerFrame = SystemTimers::GetTicksPerSecond() / (PAL_FIELD_RATE + 1); s_lineCount = m_DisplayControlRegister.NIN ? PAL_LINE_COUNT : (PAL_LINE_COUNT+1)/2; //s_upperFieldBegin = PAL_UPPER_BEGIN; //s_lowerFieldBegin = PAL_LOWER_BEGIN; @@ -800,19 +800,16 @@ void Update() { // Progressive NewVBeamPos = s_lineCount + 1; - BeginField(FIELD_PROGRESSIVE); } else if (m_VBeamPos == s_lineCount) { // Interlace Upper NewVBeamPos = s_lineCount * 2; - BeginField(FIELD_UPPER); } else { // Interlace Lower NewVBeamPos = s_lineCount; - BeginField(FIELD_LOWER); } for (int i = 0; i < 4; i++) @@ -821,8 +818,25 @@ void Update() m_InterruptRegister[i].IR_INT = 1; } UpdateInterrupts(); + + if (m_DisplayControlRegister.NIN) + { + // Progressive + BeginField(FIELD_PROGRESSIVE); + } + else if (m_VBeamPos == s_lineCount) + { + // Interlace Upper + BeginField(FIELD_UPPER); + } + else + { + // Interlace Lower + BeginField(FIELD_LOWER); + } m_VBeamPos = (NewVBeamPos > s_lineCount) ? 1 : NewVBeamPos; + Core::VideoThrottle(); } diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index afc1400c3a..388e16ffab 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -345,6 +345,15 @@ static char swapModeTable[4][5]; static char text[16384]; +struct RegisterState +{ + bool ColorNeedOverflowControl; + bool AlphaNeedOverflowControl; + bool AuxStored; +}; + +static RegisterState RegisterStates[4]; + static void BuildSwapModeTable() { for (int i = 0; i < 4; i++) @@ -383,21 +392,10 @@ const char *GeneratePixelShaderCode(u32 texture_mask, bool dstAlphaEnable, API_ } // Declare samplers - if (texture_mask) + if (texture_mask && ApiType == API_OPENGL) { - if (ApiType == API_D3D11) - { - WRITE(p, "sampler "); - } - else if (ApiType == API_D3D9) - { - WRITE(p, "uniform sampler "); - } - else - { - WRITE(p, "uniform samplerRECT "); - } - bool bfirst = true; + WRITE(p, "uniform samplerRECT "); + bool bfirst = true; for (int i = 0; i < 8; ++i) { if (texture_mask & (1<= bUpper) || (bLower >= aUpper)); } -// Run from the graphics thread +// Run from the graphics thread (from Fifo.cpp) void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight) { - if (Common::AtomicLoadAcquire(s_swapRequested) && g_ActiveConfig.bUseXFB) + if (g_ActiveConfig.bUseXFB) { - u32 aLower = xfbAddr; - u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; - u32 bLower = s_beginFieldArgs.xfbAddr; - u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; + if(Common::AtomicLoadAcquire(s_swapRequested)) + { + u32 aLower = xfbAddr; + u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; + u32 bLower = s_beginFieldArgs.xfbAddr; + u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; - if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) - VideoFifo_CheckSwapRequest(); - } - ForceSwap = false; + if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) + VideoFifo_CheckSwapRequest(); + } + } } // Run from the CPU thread (from VideoInterface.cpp) void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { if (s_PluginInitialized && g_ActiveConfig.bUseXFB) - { - 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) @@ -359,7 +353,13 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) Common::YieldCPU(); } else - VideoFifo_CheckSwapRequest(); + 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/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index 827ce5800d..e648004864 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -19,7 +19,7 @@ #include "FileUtil.h" #include "D3DBase.h" - +#include "Fifo.h" #include "Statistics.h" #include "Profiler.h" #include "VertexManager.h" @@ -226,7 +226,7 @@ void Flush() if (LocalVBuffer == s_pCurBufferPointer) return; if(Flushed) return; Flushed=true; - + VideoFifo_CheckEFBAccess(); DVSTARTPROFILE(); u32 usedtextures = 0; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 160afdd22f..d460b27154 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -65,7 +65,6 @@ static bool s_PluginInitialized = false; volatile u32 s_swapRequested = FALSE; static u32 s_efbAccessRequested = FALSE; static volatile u32 s_FifoShuttingDown = FALSE; -static bool ForceSwap = true; static volatile struct { @@ -275,7 +274,6 @@ void Video_Prepare() s_efbAccessRequested = FALSE; s_FifoShuttingDown = FALSE; s_swapRequested = FALSE; - ForceSwap = true; Renderer::Init(); TextureCache::Init(); BPInit(); @@ -342,16 +340,16 @@ void Video_SetRendering(bool bEnabled) { Fifo_SetRendering(bEnabled); } -// Run from the graphics thread +// Run from the graphics thread (from Fifo.cpp) void VideoFifo_CheckSwapRequest() { - if (Common::AtomicLoadAcquire(s_swapRequested)) + if(g_ActiveConfig.bUseXFB) { - if (ForceSwap || g_ActiveConfig.bUseXFB) + if (Common::AtomicLoadAcquire(s_swapRequested)) { Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.field, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight); + Common::AtomicStoreRelease(s_swapRequested, FALSE); } - Common::AtomicStoreRelease(s_swapRequested, FALSE); } } @@ -360,34 +358,29 @@ inline bool addrRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper) return !((aLower >= bUpper) || (bLower >= aUpper)); } -// Run from the graphics thread +// Run from the graphics thread (from Fifo.cpp) void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight) { - if (Common::AtomicLoadAcquire(s_swapRequested) && g_ActiveConfig.bUseXFB) + if (g_ActiveConfig.bUseXFB) { - u32 aLower = xfbAddr; - u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; - u32 bLower = s_beginFieldArgs.xfbAddr; - u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; + if(Common::AtomicLoadAcquire(s_swapRequested)) + { + u32 aLower = xfbAddr; + u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; + u32 bLower = s_beginFieldArgs.xfbAddr; + u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; - if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) - VideoFifo_CheckSwapRequest(); - } - - ForceSwap = false; + if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) + VideoFifo_CheckSwapRequest(); + } + } } // Run from the CPU thread (from VideoInterface.cpp) void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { if (s_PluginInitialized && g_ActiveConfig.bUseXFB) - { - 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) @@ -395,7 +388,13 @@ void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) Common::YieldCPU(); } else - VideoFifo_CheckSwapRequest(); + 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_VideoOGL/Src/Render.cpp b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp index fda80312df..ce0c3132e3 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/Render.cpp @@ -557,8 +557,6 @@ void Renderer::ResetAPIState() { // Gets us to a reasonably sane state where it's possible to do things like // image copies with textured quads, etc. - glDisable(GL_VERTEX_PROGRAM_ARB);// needed by nvidia cards to avoid texture problems - glDisable(GL_FRAGMENT_PROGRAM_ARB);// needed by nvidia cards to avoid texture problems VertexShaderCache::DisableShader(); PixelShaderCache::DisableShader(); glDisable(GL_SCISSOR_TEST); @@ -586,10 +584,8 @@ void Renderer::RestoreAPIState() SetColorMask(); SetBlendMode(true); - glEnable(GL_VERTEX_PROGRAM_ARB);// needed by nvidia cards o avoid texture problems - glEnable(GL_FRAGMENT_PROGRAM_ARB);// needed by nvidia cards o avoid texture problems - VertexShaderCache::SetCurrentShader(0); - PixelShaderCache::SetCurrentShader(0); + VertexShaderCache::SetCurrentShader(1); + PixelShaderCache::SetCurrentShader(1); } void Renderer::SetColorMask() diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index ad1226142d..1ef2451d29 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -202,6 +202,7 @@ void Flush() if (LocalVBuffer == s_pCurBufferPointer) return; if(Flushed) return; Flushed=true; + VideoFifo_CheckEFBAccess(); #if defined(_DEBUG) || defined(DEBUGFAST) PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGens, xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op, diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index db51766be4..e291a8803e 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -106,7 +106,6 @@ static bool s_PluginInitialized = false; volatile u32 s_swapRequested = FALSE; static u32 s_efbAccessRequested = FALSE; static volatile u32 s_FifoShuttingDown = FALSE; -static bool ForceSwap = true; bool IsD3D() { @@ -301,8 +300,7 @@ void Video_Prepare(void) void Shutdown(void) { - s_PluginInitialized = false; - ForceSwap = true; + s_PluginInitialized = false; s_efbAccessRequested = FALSE; s_swapRequested = FALSE; @@ -368,14 +366,13 @@ static volatile struct // Run from the graphics thread (from Fifo.cpp) void VideoFifo_CheckSwapRequest() { - if (Common::AtomicLoadAcquire(s_swapRequested)) + if(g_ActiveConfig.bUseXFB) { - if (ForceSwap || g_ActiveConfig.bUseXFB) + if (Common::AtomicLoadAcquire(s_swapRequested)) { Renderer::Swap(s_beginFieldArgs.xfbAddr, s_beginFieldArgs.field, s_beginFieldArgs.fbWidth, s_beginFieldArgs.fbHeight); + Common::AtomicStoreRelease(s_swapRequested, FALSE); } - - Common::AtomicStoreRelease(s_swapRequested, FALSE); } } @@ -387,31 +384,26 @@ inline bool addrRangesOverlap(u32 aLower, u32 aUpper, u32 bLower, u32 bUpper) // Run from the graphics thread (from Fifo.cpp) void VideoFifo_CheckSwapRequestAt(u32 xfbAddr, u32 fbWidth, u32 fbHeight) { - if (Common::AtomicLoadAcquire(s_swapRequested) && g_ActiveConfig.bUseXFB) + if (g_ActiveConfig.bUseXFB) { - u32 aLower = xfbAddr; - u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; - u32 bLower = s_beginFieldArgs.xfbAddr; - u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; + if(Common::AtomicLoadAcquire(s_swapRequested)) + { + u32 aLower = xfbAddr; + u32 aUpper = xfbAddr + 2 * fbWidth * fbHeight; + u32 bLower = s_beginFieldArgs.xfbAddr; + u32 bUpper = s_beginFieldArgs.xfbAddr + 2 * s_beginFieldArgs.fbWidth * s_beginFieldArgs.fbHeight; - if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) - VideoFifo_CheckSwapRequest(); - } - - ForceSwap = false; + if (addrRangesOverlap(aLower, aUpper, bLower, bUpper)) + VideoFifo_CheckSwapRequest(); + } + } } // Run from the CPU thread (from VideoInterface.cpp) void Video_BeginField(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight) { if (s_PluginInitialized && g_ActiveConfig.bUseXFB) - { - 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) @@ -420,6 +412,12 @@ 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); } }