From 34d733d376e8140048a9fbb96fd25155965434a6 Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 6 Oct 2016 21:35:46 +0200 Subject: [PATCH 1/7] OGL/Render: Drop write-only variable. --- Source/Core/VideoBackends/OGL/Render.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 21227a2614..bcef6562bf 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -51,7 +51,6 @@ void VideoConfig::UpdateProjectionHack() ::UpdateProjectionHack(g_Config.iPhackvalue, g_Config.sPhackvalue); } -static int OSDInternalW, OSDInternalH; static int s_max_texture_size = 0; namespace OGL @@ -333,9 +332,6 @@ static void InitDriverInfo() // Init functions Renderer::Renderer() { - OSDInternalW = 0; - OSDInternalH = 0; - s_blendMode = 0; bool bSuccess = true; @@ -1449,9 +1445,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, sourceRc.right -= Renderer::EFBToScaledX(fbStride - fbWidth); } - // Tell the OSD Menu about the current internal resolution - OSDInternalW = xfbSource->sourceRc.GetWidth(); - OSDInternalH = xfbSource->sourceRc.GetHeight(); BlitScreen(sourceRc, drawRc, xfbSource->texture, xfbSource->texWidth, xfbSource->texHeight); } From f45ddddf1cf5ec7904a83924614161e00bc10d21 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 20:31:51 +0200 Subject: [PATCH 2/7] VideoCommon: Add shared framedumping code. --- Source/Core/VideoCommon/RenderBase.cpp | 96 ++++++++++++++++++++++++-- Source/Core/VideoCommon/RenderBase.h | 14 +++- 2 files changed, 100 insertions(+), 10 deletions(-) diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 60375a43db..1ba81ecf2b 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -20,6 +20,7 @@ #include "Common/CommonTypes.h" #include "Common/Event.h" +#include "Common/FileUtil.h" #include "Common/Flag.h" #include "Common/Profiler.h" #include "Common/StringUtil.h" @@ -97,14 +98,10 @@ static float AspectToWidescreen(float aspect) return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f)); } -Renderer::Renderer() : frame_data(), bLastFrameDumped(false) +Renderer::Renderer() { UpdateActiveConfig(); TextureCacheBase::OnConfigChanged(g_ActiveConfig); - -#if defined _WIN32 || defined HAVE_LIBAV - bAVIDumping = false; -#endif } Renderer::~Renderer() @@ -113,9 +110,14 @@ Renderer::~Renderer() prev_efb_format = PEControl::INVALID_FMT; efb_scale_numeratorX = efb_scale_numeratorY = efb_scale_denominatorX = efb_scale_denominatorY = 1; -#if defined _WIN32 || defined HAVE_LIBAV - if (SConfig::GetInstance().m_DumpFrames && bLastFrameDumped && bAVIDumping) + +#if defined(HAVE_LIBAV) || defined(_WIN32) + // Stop frame dumping if it was left enabled at shutdown time. + if (bAVIDumping) + { AVIDump::Stop(); + bAVIDumping = false; + } #endif } @@ -534,6 +536,86 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const XFBWrited = false; } +bool Renderer::IsFrameDumping() +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (SConfig::GetInstance().m_DumpFrames) + return true; + + if (bLastFrameDumped && bAVIDumping) + { + AVIDump::Stop(); + std::vector().swap(frame_data); + m_last_framedump_width = m_last_framedump_height = 0; + bAVIDumping = false; + OSD::AddMessage("Stop dumping frames", 2000); + } + bLastFrameDumped = false; +#endif + return false; +} + +void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat format, + bool swap_upside_down) +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (w == 0 || h == 0) + return; + + size_t image_size; + switch (format) + { + case AVIDump::DumpFormat::FORMAT_BGR: + image_size = 3 * w * h; + break; + case AVIDump::DumpFormat::FORMAT_RGBA: + image_size = 4 * w * h; + break; + } + + m_last_framedump_width = w; + m_last_framedump_height = h; + m_last_framedump_format = format; + + // TODO: Refactor this. Right now it's needed for the implace flipping of the image. + // It's also used to repeat the last frame. + frame_data.assign(data, data + image_size); + + if (!bLastFrameDumped) + { + bAVIDumping = AVIDump::Start(w, h, format); + if (!bAVIDumping) + { + OSD::AddMessage("AVIDump Start failed", 2000); + } + else + { + OSD::AddMessage(StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", + File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), + 2000); + } + } + if (bAVIDumping) + { + if (swap_upside_down) + FlipImageData(&frame_data[0], w, h, 4); + AVIDump::AddFrame(&frame_data[0], w, h); + } + + bLastFrameDumped = true; +#endif +} + +void Renderer::RepeatFrameDumpFrame() +{ +#if defined(HAVE_LIBAV) || defined(_WIN32) + if (SConfig::GetInstance().m_DumpFrames && bAVIDumping && !frame_data.empty()) + { + AVIDump::AddFrame(&frame_data[0], m_last_framedump_width, m_last_framedump_height); + } +#endif +} + void Renderer::FlipImageData(u8* data, int w, int h, int pixel_width) { for (int y = 0; y < h / 2; ++y) diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 584c8dbec6..27a8dfa089 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -23,6 +23,7 @@ #include "Common/Event.h" #include "Common/Flag.h" #include "Common/MathUtil.h" +#include "VideoCommon/AVIDump.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/FPSCounter.h" #include "VideoCommon/VideoBackendBase.h" @@ -146,14 +147,21 @@ protected: static void CheckFifoRecording(); static void RecordVideoMemory(); + bool IsFrameDumping(); + void DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat format, + bool swap_upside_down = false); + void RepeatFrameDumpFrame(); + static volatile bool s_bScreenshot; static std::mutex s_criticalScreenshot; static std::string s_sScreenshotName; - bool bAVIDumping; - std::vector frame_data; - bool bLastFrameDumped; + bool bAVIDumping = false; + bool bLastFrameDumped = false; + int m_last_framedump_width = 0; + int m_last_framedump_height = 0; + AVIDump::DumpFormat m_last_framedump_format; // The framebuffer size static int s_target_width; From a530708bb10eeef55fb9e1c4a7c1c9dcc617bd51 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:14:27 +0200 Subject: [PATCH 3/7] OGL: Use VideoCommon framedump helpers. --- Source/Core/VideoBackends/OGL/Render.cpp | 75 +++--------------------- 1 file changed, 8 insertions(+), 67 deletions(-) diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index bcef6562bf..2f53d0e9a6 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -32,9 +32,7 @@ #include "VideoBackends/OGL/TextureCache.h" #include "VideoBackends/OGL/VertexManager.h" -#if defined(HAVE_LIBAV) || defined(_WIN32) #include "VideoCommon/AVIDump.h" -#endif #include "VideoCommon/BPFunctions.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/Fifo.h" @@ -1340,16 +1338,6 @@ void Renderer::SetBlendMode(bool forceUpdate) s_blendMode = newval; } -static void DumpFrame(const std::vector& data, int w, int h) -{ -#if defined(HAVE_LIBAV) || defined(_WIN32) - if (SConfig::GetInstance().m_DumpFrames && !data.empty()) - { - AVIDump::AddFrame(&data[0], w, h); - } -#endif -} - // This function has the final picture. We adjust the aspect ratio here. void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, float Gamma) @@ -1362,11 +1350,10 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, glDisable(GL_DEBUG_OUTPUT); } - static int w = 0, h = 0; if (Fifo::WillSkipCurrentFrame() || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { - DumpFrame(frame_data, w, h); + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -1376,7 +1363,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, FramebufferManager::GetXFBSource(xfbAddr, fbStride, fbHeight, &xfbCount); if (g_ActiveConfig.VirtualXFBEnabled() && (!xfbSourceList || xfbCount == 0)) { - DumpFrame(frame_data, w, h); + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -1474,64 +1461,18 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, s_screenshotCompleted.Set(); } -// Frame dumps are handled a little differently in Windows -#if defined(HAVE_LIBAV) || defined(_WIN32) - if (SConfig::GetInstance().m_DumpFrames) + if (IsFrameDumping()) { std::lock_guard lk(s_criticalScreenshot); - - if (frame_data.empty() || w != flipped_trc.GetWidth() || h != flipped_trc.GetHeight()) - { - w = flipped_trc.GetWidth(); - h = flipped_trc.GetHeight(); - frame_data.resize(4 * w * h); - } + std::vector image(flipped_trc.GetWidth() * flipped_trc.GetHeight() * 4); glPixelStorei(GL_PACK_ALIGNMENT, 1); - glReadPixels(flipped_trc.left, flipped_trc.bottom, w, h, GL_RGBA, GL_UNSIGNED_BYTE, - &frame_data[0]); - if (w > 0 && h > 0) - { - if (!bLastFrameDumped) - { - bAVIDumping = AVIDump::Start(w, h, AVIDump::DumpFormat::FORMAT_RGBA); - if (!bAVIDumping) - { - OSD::AddMessage("AVIDump Start failed", 2000); - } - else - { - OSD::AddMessage(StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", - File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), w, h), - 2000); - } - } - if (bAVIDumping) - { - FlipImageData(&frame_data[0], w, h, 4); - AVIDump::AddFrame(&frame_data[0], w, h); - } + glReadPixels(flipped_trc.left, flipped_trc.bottom, flipped_trc.GetWidth(), + flipped_trc.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.data()); - bLastFrameDumped = true; - } - else - { - NOTICE_LOG(VIDEO, "Error reading framebuffer"); - } + DumpFrameData(image.data(), flipped_trc.GetWidth(), flipped_trc.GetHeight(), + AVIDump::DumpFormat::FORMAT_RGBA, true); } - else - { - if (bLastFrameDumped && bAVIDumping) - { - AVIDump::Stop(); - std::vector().swap(frame_data); - w = h = 0; - bAVIDumping = false; - OSD::AddMessage("Stop dumping frames", 2000); - } - bLastFrameDumped = false; - } -#endif // Finish up the current frame, print some stats SetWindowSize(fbStride, fbHeight); From 64b648f6c8fa6e30f6a61607a5f4c57d7f6c48ad Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:23:16 +0200 Subject: [PATCH 4/7] D3D: Use VideoCommon framedumping helpers. --- Source/Core/VideoBackends/D3D/Render.cpp | 56 +++++------------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index 2997173014..fa0fe3581e 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -768,9 +768,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, if (Fifo::WillSkipCurrentFrame() || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) { - if (SConfig::GetInstance().m_DumpFrames && !frame_data.empty()) - AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight); - + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -780,9 +778,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, FramebufferManager::GetXFBSource(xfbAddr, fbStride, fbHeight, &xfbCount); if ((!xfbSourceList || xfbCount == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB) { - if (SConfig::GetInstance().m_DumpFrames && !frame_data.empty()) - AVIDump::AddFrame(&frame_data[0], fbWidth, fbHeight); - + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -877,7 +873,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, } // Dump frames - if (SConfig::GetInstance().m_DumpFrames) + if (IsFrameDumping()) { if (!s_screenshot_texture) CreateScreenshotTexture(); @@ -888,47 +884,17 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, D3D::context->CopySubresourceRegion(s_screenshot_texture, 0, 0, 0, 0, (ID3D11Resource*)D3D::GetBackBuffer()->GetTex(), 0, &source_box); - if (!bLastFrameDumped) - { - bAVIDumping = AVIDump::Start(source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR); - if (!bAVIDumping) - { - PanicAlert("Error dumping frames to AVI."); - } - else - { - std::string msg = StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", - File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), - source_width, source_height); - OSD::AddMessage(msg, 2000); - } - } - if (bAVIDumping) - { - D3D11_MAPPED_SUBRESOURCE map; - D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ, 0, &map); + D3D11_MAPPED_SUBRESOURCE map; + D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ, 0, &map); - if (frame_data.capacity() != 3 * source_width * source_height) - frame_data.resize(3 * source_width * source_height); + // TODO: This convertion is not needed. Get rid of it. + std::vector image(source_width * source_height * 3); + formatBufferDump((u8*)map.pData, image.data(), source_width, source_height, map.RowPitch); - formatBufferDump((u8*)map.pData, &frame_data[0], source_width, source_height, map.RowPitch); - FlipImageData(&frame_data[0], source_width, source_height); - AVIDump::AddFrame(&frame_data[0], source_width, source_height); - D3D::context->Unmap(s_screenshot_texture, 0); - } - bLastFrameDumped = true; - } - else - { - if (bLastFrameDumped && bAVIDumping) - { - AVIDump::Stop(); - std::vector().swap(frame_data); - bAVIDumping = false; - OSD::AddMessage("Stop dumping frames to AVI", 2000); - } - bLastFrameDumped = false; + DumpFrameData(image.data(), source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR, true); + + D3D::context->Unmap(s_screenshot_texture, 0); } // Reset viewport for drawing text From 6b08830a957d9dfe3259fd87186a614efadac56e Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:28:06 +0200 Subject: [PATCH 5/7] D3D12: Use VideoCommon framedump helpers. --- Source/Core/VideoBackends/D3D12/Render.cpp | 62 +++++----------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index 9bbe2699ba..fb1740d9ac 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -711,9 +711,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height if (Fifo::WillSkipCurrentFrame() || (!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fb_width || !fb_height) { - if (SConfig::GetInstance().m_DumpFrames && !frame_data.empty()) - AVIDump::AddFrame(&frame_data[0], fb_width, fb_height); - + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -723,9 +721,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height FramebufferManager::GetXFBSource(xfb_addr, fb_stride, fb_height, &xfb_count); if ((!xfb_source_list || xfb_count == 0) && g_ActiveConfig.bUseXFB && !g_ActiveConfig.bUseRealXFB) { - if (SConfig::GetInstance().m_DumpFrames && !frame_data.empty()) - AVIDump::AddFrame(&frame_data[0], fb_width, fb_height); - + RepeatFrameDumpFrame(); Core::Callback_VideoCopiedToXFB(false); return; } @@ -832,7 +828,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height } // Dump frames - if (SConfig::GetInstance().m_DumpFrames) + if (IsFrameDumping()) { if (!s_screenshot_texture) CreateScreenshotTexture(); @@ -865,51 +861,19 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height D3D::command_list_mgr->ExecuteQueuedWork(true); - if (!bLastFrameDumped) - { - bAVIDumping = AVIDump::Start(source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR); - if (!bAVIDumping) - { - PanicAlert("Error dumping frames to AVI."); - } - else - { - std::string msg = StringFromFormat("Dumping Frames to \"%sframedump0.avi\" (%dx%d RGB24)", - File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), - source_width, source_height); + void* screenshot_texture_map; + D3D12_RANGE read_range = {0, dst_location.PlacedFootprint.Footprint.RowPitch * source_height}; + CheckHR(s_screenshot_texture->Map(0, &read_range, &screenshot_texture_map)); - OSD::AddMessage(msg, 2000); - } - } - if (bAVIDumping) - { - if (frame_data.capacity() != 3 * source_width * source_height) - frame_data.resize(3 * source_width * source_height); + // TODO: This convertion is not needed. Get rid of it. + std::vector image(source_width * source_height * 3); + formatBufferDump(static_cast(screenshot_texture_map), image.data(), source_width, + source_height, dst_location.PlacedFootprint.Footprint.RowPitch); - void* screenshot_texture_map; - D3D12_RANGE read_range = {0, dst_location.PlacedFootprint.Footprint.RowPitch * source_height}; - CheckHR(s_screenshot_texture->Map(0, &read_range, &screenshot_texture_map)); - formatBufferDump(static_cast(screenshot_texture_map), &frame_data[0], source_width, - source_height, dst_location.PlacedFootprint.Footprint.RowPitch); + DumpFrameData(image.data(), source_width, source_height, AVIDump::DumpFormat::FORMAT_BGR, true); - D3D12_RANGE write_range = {}; - s_screenshot_texture->Unmap(0, &write_range); - - FlipImageData(&frame_data[0], source_width, source_height); - AVIDump::AddFrame(&frame_data[0], source_width, source_height); - } - bLastFrameDumped = true; - } - else - { - if (bLastFrameDumped && bAVIDumping) - { - AVIDump::Stop(); - std::vector().swap(frame_data); - bAVIDumping = false; - OSD::AddMessage("Stop dumping frames to AVI", 2000); - } - bLastFrameDumped = false; + D3D12_RANGE write_range = {}; + s_screenshot_texture->Unmap(0, &write_range); } // Reset viewport for drawing text From e82cf464361bde59c239edb036c0ee7ef52a666c Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:28:06 +0200 Subject: [PATCH 6/7] Vulkan: Use VideoCommon framedump helpers. --- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 82 +++---------------- Source/Core/VideoBackends/Vulkan/Renderer.h | 3 - 2 files changed, 11 insertions(+), 74 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index c8f9aaa4d3..42fd7373db 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -26,10 +26,7 @@ #include "VideoBackends/Vulkan/Util.h" #include "VideoBackends/Vulkan/VulkanContext.h" -#if defined(HAVE_LIBAV) || defined(_WIN32) #include "VideoCommon/AVIDump.h" -#endif - #include "VideoCommon/BPFunctions.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/ImageWrite.h" @@ -65,15 +62,6 @@ Renderer::Renderer(std::unique_ptr swap_chain) : m_swap_chain(std::mo Renderer::~Renderer() { -#if defined(HAVE_LIBAV) || defined(_WIN32) - // Stop frame dumping if it was left enabled at shutdown time. - if (bAVIDumping) - { - AVIDump::Stop(); - bAVIDumping = false; - } -#endif - g_Config.bRunning = false; UpdateActiveConfig(); DestroyScreenshotResources(); @@ -494,20 +482,22 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Draw to the screenshot buffer if needed. - bool needs_screenshot = (s_bScreenshot || SConfig::GetInstance().m_DumpFrames); + bool needs_framedump = IsFrameDumping(); + bool needs_screenshot = s_bScreenshot || needs_framedump; if (needs_screenshot && DrawScreenshot(source_rc, efb_color_texture)) { if (s_bScreenshot) + { WriteScreenshot(); + } - if (SConfig::GetInstance().m_DumpFrames) - WriteFrameDump(); - } - else - { - // Stop frame dump if requested. - if (bAVIDumping) - StopFrameDump(); + if (needs_framedump) + { + DumpFrameData(reinterpret_cast(m_screenshot_readback_texture->GetMapPointer()), + static_cast(m_screenshot_render_texture->GetWidth()), + static_cast(m_screenshot_render_texture->GetHeight()), + AVIDump::DumpFormat::FORMAT_RGBA); + } } // Restore the EFB color texture to color attachment ready for rendering the next frame. @@ -785,56 +775,6 @@ void Renderer::WriteScreenshot() s_screenshotCompleted.Set(); } -void Renderer::WriteFrameDump() -{ -#if defined(HAVE_LIBAV) || defined(_WIN32) - if (!bLastFrameDumped) - { - bLastFrameDumped = true; - bAVIDumping = AVIDump::Start(static_cast(m_screenshot_render_texture->GetWidth()), - static_cast(m_screenshot_render_texture->GetHeight()), - AVIDump::DumpFormat::FORMAT_RGBA); - - if (!bAVIDumping) - { - OSD::AddMessage("Failed to start frame dumping.", 2000); - return; - } - - OSD::AddMessage(StringFromFormat("Frame dumping started (%ux%u RGBA8).", - m_screenshot_render_texture->GetWidth(), - m_screenshot_render_texture->GetHeight()), - 2000); - } - - if (bAVIDumping) - { - AVIDump::AddFrame(reinterpret_cast(m_screenshot_readback_texture->GetMapPointer()), - static_cast(m_screenshot_render_texture->GetWidth()), - static_cast(m_screenshot_render_texture->GetHeight())); - } -#else - if (!bLastFrameDumped) - { - OSD::AddMessage("Dumping frames not supported", 2000); - bLastFrameDumped = true; - } -#endif -} - -void Renderer::StopFrameDump() -{ -#if defined(HAVE_LIBAV) || defined(_WIN32) - if (bAVIDumping) - { - OSD::AddMessage("Frame dumping stopped.", 2000); - bAVIDumping = false; - bLastFrameDumped = false; - AVIDump::Stop(); - } -#endif -} - void Renderer::CheckForTargetResize(u32 fb_width, u32 fb_stride, u32 fb_height) { if (FramebufferManagerBase::LastXfbWidth() == fb_stride && diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.h b/Source/Core/VideoBackends/Vulkan/Renderer.h index f292d722a0..b80b6c191b 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.h +++ b/Source/Core/VideoBackends/Vulkan/Renderer.h @@ -100,9 +100,6 @@ private: bool ResizeScreenshotBuffer(u32 new_width, u32 new_height); void DestroyScreenshotResources(); void WriteScreenshot(); - void WriteFrameDump(); - void StopFrameDump(); - FramebufferManager* m_framebuffer_mgr = nullptr; VkSemaphore m_image_available_semaphore = VK_NULL_HANDLE; From 8c999f9ee801116e723381432b96d8a9ae6ddc68 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 7 Oct 2016 21:39:23 +0200 Subject: [PATCH 7/7] VideoCommon: Mark framedump variables as private. And rename them to the new naming scheme. --- Source/Core/VideoCommon/RenderBase.cpp | 32 +++++++++++++------------- Source/Core/VideoCommon/RenderBase.h | 15 ++++++------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 1ba81ecf2b..1dd07c905b 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -113,10 +113,10 @@ Renderer::~Renderer() #if defined(HAVE_LIBAV) || defined(_WIN32) // Stop frame dumping if it was left enabled at shutdown time. - if (bAVIDumping) + if (m_AVI_dumping) { AVIDump::Stop(); - bAVIDumping = false; + m_AVI_dumping = false; } #endif } @@ -542,15 +542,15 @@ bool Renderer::IsFrameDumping() if (SConfig::GetInstance().m_DumpFrames) return true; - if (bLastFrameDumped && bAVIDumping) + if (m_last_frame_dumped && m_AVI_dumping) { AVIDump::Stop(); - std::vector().swap(frame_data); + std::vector().swap(m_frame_data); m_last_framedump_width = m_last_framedump_height = 0; - bAVIDumping = false; + m_AVI_dumping = false; OSD::AddMessage("Stop dumping frames", 2000); } - bLastFrameDumped = false; + m_last_frame_dumped = false; #endif return false; } @@ -579,12 +579,12 @@ void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat f // TODO: Refactor this. Right now it's needed for the implace flipping of the image. // It's also used to repeat the last frame. - frame_data.assign(data, data + image_size); + m_frame_data.assign(data, data + image_size); - if (!bLastFrameDumped) + if (!m_last_frame_dumped) { - bAVIDumping = AVIDump::Start(w, h, format); - if (!bAVIDumping) + m_AVI_dumping = AVIDump::Start(w, h, format); + if (!m_AVI_dumping) { OSD::AddMessage("AVIDump Start failed", 2000); } @@ -595,23 +595,23 @@ void Renderer::DumpFrameData(const u8* data, int w, int h, AVIDump::DumpFormat f 2000); } } - if (bAVIDumping) + if (m_AVI_dumping) { if (swap_upside_down) - FlipImageData(&frame_data[0], w, h, 4); - AVIDump::AddFrame(&frame_data[0], w, h); + FlipImageData(m_frame_data.data(), w, h, 4); + AVIDump::AddFrame(m_frame_data.data(), w, h); } - bLastFrameDumped = true; + m_last_frame_dumped = true; #endif } void Renderer::RepeatFrameDumpFrame() { #if defined(HAVE_LIBAV) || defined(_WIN32) - if (SConfig::GetInstance().m_DumpFrames && bAVIDumping && !frame_data.empty()) + if (SConfig::GetInstance().m_DumpFrames && m_AVI_dumping && !m_frame_data.empty()) { - AVIDump::AddFrame(&frame_data[0], m_last_framedump_width, m_last_framedump_height); + AVIDump::AddFrame(m_frame_data.data(), m_last_framedump_width, m_last_framedump_height); } #endif } diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 27a8dfa089..1f648bb17b 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -156,13 +156,6 @@ protected: static std::mutex s_criticalScreenshot; static std::string s_sScreenshotName; - std::vector frame_data; - bool bAVIDumping = false; - bool bLastFrameDumped = false; - int m_last_framedump_width = 0; - int m_last_framedump_height = 0; - AVIDump::DumpFormat m_last_framedump_format; - // The framebuffer size static int s_target_width; static int s_target_height; @@ -194,6 +187,14 @@ private: static unsigned int efb_scale_numeratorY; static unsigned int efb_scale_denominatorX; static unsigned int efb_scale_denominatorY; + + // framedumping + std::vector m_frame_data; + bool m_AVI_dumping = false; + bool m_last_frame_dumped = false; + int m_last_framedump_width = 0; + int m_last_framedump_height = 0; + AVIDump::DumpFormat m_last_framedump_format; }; extern std::unique_ptr g_renderer;