From 8b84ddce9a3e9c889996e2022279f78ef7a4ab5c Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 3 Sep 2014 21:49:15 +0200 Subject: [PATCH] VideoCommon: rewrite frame skipping code --- Source/Core/VideoCommon/Fifo.cpp | 6 ++-- Source/Core/VideoCommon/Fifo.h | 2 +- Source/Core/VideoCommon/OpcodeDecoding.cpp | 34 +++++++------------ Source/Core/VideoCommon/OpcodeDecoding.h | 2 +- Source/Core/VideoCommon/RenderBase.cpp | 3 -- Source/Core/VideoCommon/RenderBase.h | 1 - .../Core/VideoCommon/VertexLoaderManager.cpp | 4 +-- Source/Core/VideoCommon/VertexLoaderManager.h | 2 +- 8 files changed, 20 insertions(+), 34 deletions(-) diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index fb47c73e49..8a872d5422 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -19,7 +19,7 @@ #include "VideoCommon/PixelEngine.h" #include "VideoCommon/VideoConfig.h" -volatile bool g_bSkipCurrentFrame = false; +bool g_bSkipCurrentFrame = false; namespace { @@ -173,7 +173,7 @@ void RunGpuLoop() ReadDataFromFifo(uData, 32); - cyclesExecuted = OpcodeDecoder_Run(g_bSkipCurrentFrame, GetVideoBufferEndPtr()); + cyclesExecuted = OpcodeDecoder_Run(GetVideoBufferEndPtr()); if (Core::g_CoreStartupParameter.bSyncGPU && Common::AtomicLoad(CommandProcessor::VITicks) > cyclesExecuted) Common::AtomicAdd(CommandProcessor::VITicks, -(s32)cyclesExecuted); @@ -235,7 +235,7 @@ void RunGpu() FPURoundMode::SaveSIMDState(); FPURoundMode::LoadDefaultSIMDState(); ReadDataFromFifo(uData, 32); - OpcodeDecoder_Run(g_bSkipCurrentFrame, GetVideoBufferEndPtr()); + OpcodeDecoder_Run(GetVideoBufferEndPtr()); FPURoundMode::LoadSIMDState(); //DEBUG_LOG(COMMANDPROCESSOR, "Fifo wraps to base"); diff --git a/Source/Core/VideoCommon/Fifo.h b/Source/Core/VideoCommon/Fifo.h index 1254a27a72..f6da09e377 100644 --- a/Source/Core/VideoCommon/Fifo.h +++ b/Source/Core/VideoCommon/Fifo.h @@ -11,7 +11,7 @@ class PointerWrap; #define FIFO_SIZE (2*1024*1024) -extern volatile bool g_bSkipCurrentFrame; +extern bool g_bSkipCurrentFrame; void Fifo_Init(); diff --git a/Source/Core/VideoCommon/OpcodeDecoding.cpp b/Source/Core/VideoCommon/OpcodeDecoding.cpp index fe644db21e..884a8c978a 100644 --- a/Source/Core/VideoCommon/OpcodeDecoding.cpp +++ b/Source/Core/VideoCommon/OpcodeDecoding.cpp @@ -91,7 +91,7 @@ static u32 InterpretDisplayList(u32 address, u32 size) Statistics::SwapDL(); u8 *end = g_pVideoData + size; - cycles = OpcodeDecoder_Run(false, end); + cycles = OpcodeDecoder_Run(end); INCSTAT(stats.thisFrame.numDListsCalled); // un-swap @@ -146,7 +146,7 @@ static void UnknownOpcode(u8 cmd_byte, void *buffer, bool preprocess) } } -static u32 Decode(u8* end, bool skipped_frame) +static u32 Decode(u8* end) { u8 *opcodeStart = g_pVideoData; if (g_pVideoData == end) @@ -221,10 +221,7 @@ static u32 Decode(u8* end, bool skipped_frame) return 0; u32 address = DataReadU32(); u32 count = DataReadU32(); - if (skipped_frame) - cycles = 45; // xxx - else - cycles = 6 + InterpretDisplayList(address, count); + cycles = 6 + InterpretDisplayList(address, count); } break; @@ -261,21 +258,14 @@ static u32 Decode(u8* end, bool skipped_frame) return 0; u16 numVertices = DataReadU16(); - if (skipped_frame) + if (!VertexLoaderManager::RunVertices( + cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7) + (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, + numVertices, + end - g_pVideoData, + g_bSkipCurrentFrame)) { - size_t size = numVertices * VertexLoaderManager::GetVertexSize(cmd_byte & GX_VAT_MASK); - if ((size_t) (end - g_pVideoData) < size) - return 0; - DataSkip((u32)size); - } - else - { - if (!VertexLoaderManager::RunVertices( - cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7) - (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, - numVertices, - end - g_pVideoData)) - return 0; + return 0; } } else @@ -311,13 +301,13 @@ void OpcodeDecoder_Shutdown() { } -u32 OpcodeDecoder_Run(bool skipped_frame, u8* end) +u32 OpcodeDecoder_Run(u8* end) { u32 totalCycles = 0; while (true) { u8* old = g_pVideoData; - u32 cycles = Decode(end, skipped_frame); + u32 cycles = Decode(end); if (cycles == 0) { g_pVideoData = old; diff --git a/Source/Core/VideoCommon/OpcodeDecoding.h b/Source/Core/VideoCommon/OpcodeDecoding.h index 2944863bbc..1702969825 100644 --- a/Source/Core/VideoCommon/OpcodeDecoding.h +++ b/Source/Core/VideoCommon/OpcodeDecoding.h @@ -38,4 +38,4 @@ extern bool g_bRecordFifoData; void OpcodeDecoder_Init(); void OpcodeDecoder_Shutdown(); -u32 OpcodeDecoder_Run(bool skipped_frame, u8* end); +u32 OpcodeDecoder_Run(u8* end); diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index e877023293..51f25d7880 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -65,7 +65,6 @@ TargetRectangle Renderer::target_rc; int Renderer::s_LastEFBScale; -bool Renderer::s_skipSwap; bool Renderer::XFBWrited; PEControl::PixelFormat Renderer::prev_efb_format = PEControl::INVALID_FMT; @@ -113,8 +112,6 @@ void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbWidt if (!fbWidth || !fbHeight) return; - s_skipSwap = g_bSkipCurrentFrame; - VideoFifo_CheckEFBAccess(); VideoFifo_CheckSwapRequestAt(xfbAddr, fbWidth, fbHeight); XFBWrited = true; diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index fc20752a50..fe4adf449e 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -152,7 +152,6 @@ protected: // can probably eliminate this static var static int s_LastEFBScale; - static bool s_skipSwap; static bool XFBWrited; FPSCounter m_fps_counter; diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 7ff21d103b..873590b1c2 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -151,7 +151,7 @@ static VertexLoaderCacheItem RefreshLoader(int vtx_attr_group) return s_VertexLoaders[vtx_attr_group]; } -bool RunVertices(int vtx_attr_group, int primitive, int count, size_t buf_size) +bool RunVertices(int vtx_attr_group, int primitive, int count, size_t buf_size, bool skip_drawing) { if (!count) return true; @@ -161,7 +161,7 @@ bool RunVertices(int vtx_attr_group, int primitive, int count, size_t buf_size) if (buf_size < size) return false; - if (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5) + if (skip_drawing || (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5)) { // if cull mode is CULL_ALL, ignore triangles and quads DataSkip((u32)size); diff --git a/Source/Core/VideoCommon/VertexLoaderManager.h b/Source/Core/VideoCommon/VertexLoaderManager.h index ff3485b9d5..97ae58b704 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.h +++ b/Source/Core/VideoCommon/VertexLoaderManager.h @@ -18,7 +18,7 @@ namespace VertexLoaderManager int GetVertexSize(int vtx_attr_group); // Returns false if buf_size is insufficient. - bool RunVertices(int vtx_attr_group, int primitive, int count, size_t buf_size); + bool RunVertices(int vtx_attr_group, int primitive, int count, size_t buf_size, bool skip_drawing = false); // For debugging void AppendListToString(std::string *dest);