2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-11-18 02:21:26 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
// GC graphics pipeline
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2015-01-11 05:17:29 +00:00
|
|
|
// 3d commands are issued through the fifo. The GPU draws to the 2MB EFB.
|
2010-11-18 02:21:26 +00:00
|
|
|
// The efb can be copied back into ram in two forms: as textures or as XFB.
|
|
|
|
// The XFB is the region in RAM that the VI chip scans out to the television.
|
|
|
|
// So, after all rendering to EFB is done, the image is copied into one of two XFBs in RAM.
|
|
|
|
// Next frame, that one is scanned out and the other one gets the copy. = double buffering.
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
|
|
|
|
2017-02-03 17:31:20 +00:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
|
|
|
|
2014-12-20 11:14:33 +00:00
|
|
|
#include <cinttypes>
|
2010-11-18 02:21:26 +00:00
|
|
|
#include <cmath>
|
2015-12-21 02:49:49 +00:00
|
|
|
#include <memory>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include <mutex>
|
2010-11-18 02:21:26 +00:00
|
|
|
#include <string>
|
2017-02-03 17:31:20 +00:00
|
|
|
#include <tuple>
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2016-11-10 12:36:11 +00:00
|
|
|
#include "Common/Assert.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-08-01 14:37:42 +00:00
|
|
|
#include "Common/Config/Config.h"
|
2015-06-19 01:28:40 +00:00
|
|
|
#include "Common/Event.h"
|
2016-10-07 18:31:51 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2016-01-17 21:54:31 +00:00
|
|
|
#include "Common/Flag.h"
|
2016-11-18 12:57:08 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2014-12-20 11:14:33 +00:00
|
|
|
#include "Common/Profiler.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2016-10-08 01:11:37 +00:00
|
|
|
#include "Common/Thread.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Timer.h"
|
|
|
|
|
2018-10-27 03:11:20 +00:00
|
|
|
#include "Core/Analytics.h"
|
2017-08-01 14:37:42 +00:00
|
|
|
#include "Core/Config/SYSCONFSettings.h"
|
2014-10-13 03:53:10 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/FifoPlayer/FifoRecorder.h"
|
2018-10-27 03:11:20 +00:00
|
|
|
#include "Core/HW/SystemTimers.h"
|
2015-07-21 00:12:29 +00:00
|
|
|
#include "Core/HW/VideoInterface.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Core/Host.h"
|
|
|
|
#include "Core/Movie.h"
|
2015-07-21 00:12:29 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/AVIDump.h"
|
2018-01-21 10:22:45 +00:00
|
|
|
#include "VideoCommon/AbstractFramebuffer.h"
|
2017-11-19 07:33:53 +00:00
|
|
|
#include "VideoCommon/AbstractStagingTexture.h"
|
2017-09-03 02:30:34 +00:00
|
|
|
#include "VideoCommon/AbstractTexture.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/BPMemory.h"
|
|
|
|
#include "VideoCommon/CPMemory.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/Debugger.h"
|
2014-07-09 21:18:11 +00:00
|
|
|
#include "VideoCommon/FPSCounter.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/FramebufferManagerBase.h"
|
2016-10-08 16:23:57 +00:00
|
|
|
#include "VideoCommon/ImageWrite.h"
|
2016-10-15 10:36:11 +00:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2017-03-04 06:40:08 +00:00
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
2015-12-22 23:47:20 +00:00
|
|
|
#include "VideoCommon/PostProcessing.h"
|
2018-02-24 15:15:35 +00:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2017-07-20 07:10:02 +00:00
|
|
|
#include "VideoCommon/ShaderGenCommon.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/Statistics.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
2017-01-03 07:31:16 +00:00
|
|
|
#include "VideoCommon/TextureDecoder.h"
|
2017-03-03 22:36:51 +00:00
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
#include "VideoCommon/XFMemory.h"
|
|
|
|
|
2010-11-18 02:21:26 +00:00
|
|
|
// TODO: Move these out of here.
|
|
|
|
int frameCount;
|
|
|
|
|
2015-12-21 02:49:49 +00:00
|
|
|
std::unique_ptr<Renderer> g_renderer;
|
2010-11-18 02:21:26 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
static float AspectToWidescreen(float aspect)
|
|
|
|
{
|
|
|
|
return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f));
|
|
|
|
}
|
2012-05-28 09:31:37 +00:00
|
|
|
|
2017-03-04 06:40:08 +00:00
|
|
|
Renderer::Renderer(int backbuffer_width, int backbuffer_height)
|
2017-07-03 14:32:02 +00:00
|
|
|
: m_backbuffer_width(backbuffer_width), m_backbuffer_height(backbuffer_height)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
UpdateActiveConfig();
|
2017-03-04 06:40:08 +00:00
|
|
|
UpdateDrawRectangle();
|
2017-03-09 13:39:48 +00:00
|
|
|
CalculateTargetSize();
|
2017-03-04 06:40:08 +00:00
|
|
|
|
2017-03-03 22:36:51 +00:00
|
|
|
if (SConfig::GetInstance().bWii)
|
2017-08-01 14:37:42 +00:00
|
|
|
m_aspect_wide = Config::Get(Config::SYSCONF_WIDESCREEN);
|
2017-07-20 07:10:02 +00:00
|
|
|
|
|
|
|
m_last_host_config_bits = ShaderHostConfig::GetCurrent().bits;
|
2018-02-24 15:15:35 +00:00
|
|
|
m_last_efb_multisamples = g_ActiveConfig.iMultisamples;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 04:46:30 +00:00
|
|
|
Renderer::~Renderer() = default;
|
|
|
|
|
2018-01-26 05:09:07 +00:00
|
|
|
void Renderer::Shutdown()
|
|
|
|
{
|
|
|
|
// First stop any framedumping, which might need to dump the last xfb frame. This process
|
|
|
|
// can require additional graphics sub-systems so it needs to be done first
|
|
|
|
ShutdownFrameDumping();
|
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbStride, u32 fbHeight,
|
|
|
|
float Gamma)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
CheckFifoRecording();
|
|
|
|
|
|
|
|
if (!fbStride || !fbHeight)
|
|
|
|
return;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 15:04:46 +00:00
|
|
|
unsigned int Renderer::GetEFBScale() const
|
|
|
|
{
|
|
|
|
return m_efb_scale;
|
|
|
|
}
|
|
|
|
|
2017-04-08 23:40:04 +00:00
|
|
|
int Renderer::EFBToScaledX(int x) const
|
2011-01-07 04:57:59 +00:00
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
return x * static_cast<int>(m_efb_scale);
|
2012-10-02 20:11:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 23:40:04 +00:00
|
|
|
int Renderer::EFBToScaledY(int y) const
|
2011-01-07 04:57:59 +00:00
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
return y * static_cast<int>(m_efb_scale);
|
2012-10-02 20:11:15 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 23:40:04 +00:00
|
|
|
float Renderer::EFBToScaledXf(float x) const
|
|
|
|
{
|
|
|
|
return x * ((float)GetTargetWidth() / (float)EFB_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Renderer::EFBToScaledYf(float y) const
|
|
|
|
{
|
|
|
|
return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT);
|
|
|
|
}
|
|
|
|
|
2017-04-09 18:38:43 +00:00
|
|
|
std::tuple<int, int> Renderer::CalculateTargetScale(int x, int y) const
|
2012-10-02 20:11:15 +00:00
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
return std::make_tuple(x * static_cast<int>(m_efb_scale), y * static_cast<int>(m_efb_scale));
|
2012-10-02 20:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return true if target size changed
|
2016-11-10 13:31:44 +00:00
|
|
|
bool Renderer::CalculateTargetSize()
|
2012-10-02 20:11:15 +00:00
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
if (g_ActiveConfig.iEFBScale == EFB_SCALE_AUTO_INTEGRAL)
|
|
|
|
{
|
|
|
|
// Set a scale based on the window size
|
2017-08-13 00:51:33 +00:00
|
|
|
int width = EFB_WIDTH * m_target_rectangle.GetWidth() / m_last_xfb_width;
|
2018-06-25 04:48:57 +00:00
|
|
|
int height = EFB_HEIGHT * m_target_rectangle.GetHeight() / m_last_xfb_height;
|
2017-07-03 14:32:02 +00:00
|
|
|
m_efb_scale = std::max((width - 1) / EFB_WIDTH + 1, (height - 1) / EFB_HEIGHT + 1);
|
|
|
|
}
|
|
|
|
else
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
m_efb_scale = g_ActiveConfig.iEFBScale;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-07-03 14:32:02 +00:00
|
|
|
const u32 max_size = g_ActiveConfig.backend_info.MaxTextureSize;
|
|
|
|
if (max_size < EFB_WIDTH * m_efb_scale)
|
|
|
|
m_efb_scale = max_size / EFB_WIDTH;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-07-03 14:32:02 +00:00
|
|
|
int new_efb_width = 0;
|
|
|
|
int new_efb_height = 0;
|
|
|
|
std::tie(new_efb_width, new_efb_height) = CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-09 18:38:43 +00:00
|
|
|
if (new_efb_width != m_target_width || new_efb_height != m_target_height)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-04-09 18:38:43 +00:00
|
|
|
m_target_width = new_efb_width;
|
|
|
|
m_target_height = new_efb_height;
|
2017-03-04 06:42:27 +00:00
|
|
|
PixelShaderManager::SetEfbScaleChanged(EFBToScaledXf(1), EFBToScaledYf(1));
|
2016-06-24 08:43:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:05:24 +00:00
|
|
|
std::tuple<TargetRectangle, TargetRectangle>
|
|
|
|
Renderer::ConvertStereoRectangle(const TargetRectangle& rc) const
|
2014-10-31 15:24:35 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Resize target to half its original size
|
2017-04-09 19:05:24 +00:00
|
|
|
TargetRectangle draw_rc = rc;
|
2017-11-11 03:55:00 +00:00
|
|
|
if (g_ActiveConfig.stereo_mode == StereoMode::TAB)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
// The height may be negative due to flipped rectangles
|
|
|
|
int height = rc.bottom - rc.top;
|
2017-04-09 19:05:24 +00:00
|
|
|
draw_rc.top += height / 4;
|
|
|
|
draw_rc.bottom -= height / 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int width = rc.right - rc.left;
|
2017-04-09 19:05:24 +00:00
|
|
|
draw_rc.left += width / 4;
|
|
|
|
draw_rc.right -= width / 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create two target rectangle offset to the sides of the backbuffer
|
2017-04-09 19:05:24 +00:00
|
|
|
TargetRectangle left_rc = draw_rc;
|
|
|
|
TargetRectangle right_rc = draw_rc;
|
2017-11-11 03:55:00 +00:00
|
|
|
if (g_ActiveConfig.stereo_mode == StereoMode::TAB)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-04-09 19:05:24 +00:00
|
|
|
left_rc.top -= m_backbuffer_height / 4;
|
|
|
|
left_rc.bottom -= m_backbuffer_height / 4;
|
|
|
|
right_rc.top += m_backbuffer_height / 4;
|
|
|
|
right_rc.bottom += m_backbuffer_height / 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-09 19:05:24 +00:00
|
|
|
left_rc.left -= m_backbuffer_width / 4;
|
|
|
|
left_rc.right -= m_backbuffer_width / 4;
|
|
|
|
right_rc.left += m_backbuffer_width / 4;
|
|
|
|
right_rc.right += m_backbuffer_width / 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-04-09 19:05:24 +00:00
|
|
|
|
|
|
|
return std::make_tuple(left_rc, right_rc);
|
2014-10-31 15:24:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 06:42:35 +00:00
|
|
|
void Renderer::SaveScreenshot(const std::string& filename, bool wait_for_completion)
|
2010-11-18 02:21:26 +00:00
|
|
|
{
|
2017-03-04 06:42:35 +00:00
|
|
|
// We must not hold the lock while waiting for the screenshot to complete.
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(m_screenshot_lock);
|
|
|
|
m_screenshot_name = filename;
|
|
|
|
m_screenshot_request.Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wait_for_completion)
|
|
|
|
{
|
|
|
|
// This is currently only used by Android, and it was using a wait time of 2 seconds.
|
|
|
|
m_screenshot_completed.WaitFor(std::chrono::seconds(2));
|
|
|
|
}
|
2010-11-18 02:21:26 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 07:10:02 +00:00
|
|
|
bool Renderer::CheckForHostConfigChanges()
|
|
|
|
{
|
|
|
|
ShaderHostConfig new_host_config = ShaderHostConfig::GetCurrent();
|
2018-02-24 15:15:35 +00:00
|
|
|
if (new_host_config.bits == m_last_host_config_bits &&
|
|
|
|
m_last_efb_multisamples == g_ActiveConfig.iMultisamples)
|
|
|
|
{
|
2017-07-20 07:10:02 +00:00
|
|
|
return false;
|
2018-02-24 15:15:35 +00:00
|
|
|
}
|
2017-07-20 07:10:02 +00:00
|
|
|
|
|
|
|
m_last_host_config_bits = new_host_config.bits;
|
2018-02-24 15:15:35 +00:00
|
|
|
m_last_efb_multisamples = g_ActiveConfig.iMultisamples;
|
|
|
|
|
|
|
|
// Reload shaders.
|
|
|
|
OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
|
|
|
|
SetPipeline(nullptr);
|
|
|
|
g_vertex_manager->InvalidatePipelineObject();
|
|
|
|
g_shader_cache->SetHostConfig(new_host_config, g_ActiveConfig.iMultisamples);
|
2017-07-20 07:10:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-15 10:36:11 +00:00
|
|
|
// Create On-Screen-Messages
|
2010-11-18 02:21:26 +00:00
|
|
|
void Renderer::DrawDebugText()
|
|
|
|
{
|
2016-10-15 10:36:11 +00:00
|
|
|
std::string final_yellow, final_cyan;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-10-15 10:36:11 +00:00
|
|
|
if (g_ActiveConfig.bShowFPS || SConfig::GetInstance().m_ShowFrameCount)
|
2016-10-04 02:37:18 +00:00
|
|
|
{
|
2016-10-15 10:36:11 +00:00
|
|
|
if (g_ActiveConfig.bShowFPS)
|
2017-06-30 07:25:32 +00:00
|
|
|
final_cyan += StringFromFormat("FPS: %.2f", m_fps_counter.GetFPS());
|
2016-10-04 02:37:18 +00:00
|
|
|
|
2016-10-15 10:36:11 +00:00
|
|
|
if (g_ActiveConfig.bShowFPS && SConfig::GetInstance().m_ShowFrameCount)
|
|
|
|
final_cyan += " - ";
|
|
|
|
if (SConfig::GetInstance().m_ShowFrameCount)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-02-01 01:25:45 +00:00
|
|
|
final_cyan += StringFromFormat("Frame: %" PRIu64, Movie::GetCurrentFrame());
|
2016-10-15 10:36:11 +00:00
|
|
|
if (Movie::IsPlayingInput())
|
2017-02-01 01:25:45 +00:00
|
|
|
final_cyan += StringFromFormat("\nInput: %" PRIu64 " / %" PRIu64,
|
|
|
|
Movie::GetCurrentInputCount(), Movie::GetTotalInputCount());
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2016-10-15 10:36:11 +00:00
|
|
|
|
|
|
|
final_cyan += "\n";
|
|
|
|
final_yellow += "\n";
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SConfig::GetInstance().m_ShowLag)
|
|
|
|
{
|
2016-10-15 10:36:11 +00:00
|
|
|
final_cyan += StringFromFormat("Lag: %" PRIu64 "\n", Movie::GetCurrentLagCount());
|
|
|
|
final_yellow += "\n";
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SConfig::GetInstance().m_ShowInputDisplay)
|
|
|
|
{
|
2016-10-15 10:36:11 +00:00
|
|
|
final_cyan += Movie::GetInputDisplay();
|
|
|
|
final_yellow += "\n";
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 00:23:25 +00:00
|
|
|
if (SConfig::GetInstance().m_ShowRTC)
|
|
|
|
{
|
2016-10-15 10:36:11 +00:00
|
|
|
final_cyan += Movie::GetRTCDisplay();
|
|
|
|
final_yellow += "\n";
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2016-10-15 10:36:11 +00:00
|
|
|
|
|
|
|
// OSD Menu messages
|
2018-05-11 15:09:39 +00:00
|
|
|
if (m_osd_message > 0)
|
2016-10-15 10:36:11 +00:00
|
|
|
{
|
2018-05-11 15:09:39 +00:00
|
|
|
m_osd_time = Common::Timer::GetTimeMs() + 3000;
|
|
|
|
m_osd_message = -m_osd_message;
|
2016-10-15 10:36:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-11 15:09:39 +00:00
|
|
|
if (static_cast<u32>(m_osd_time) > Common::Timer::GetTimeMs())
|
2016-10-15 10:36:11 +00:00
|
|
|
{
|
|
|
|
std::string res_text;
|
|
|
|
switch (g_ActiveConfig.iEFBScale)
|
|
|
|
{
|
2017-07-03 14:32:02 +00:00
|
|
|
case EFB_SCALE_AUTO_INTEGRAL:
|
2016-10-15 10:36:11 +00:00
|
|
|
res_text = "Auto (integral)";
|
|
|
|
break;
|
2017-07-03 14:32:02 +00:00
|
|
|
case 1:
|
2016-10-15 10:36:11 +00:00
|
|
|
res_text = "Native";
|
|
|
|
break;
|
|
|
|
default:
|
2017-07-03 14:32:02 +00:00
|
|
|
res_text = StringFromFormat("%dx", g_ActiveConfig.iEFBScale);
|
2016-10-15 10:36:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char* ar_text = "";
|
2017-11-11 03:45:32 +00:00
|
|
|
switch (g_ActiveConfig.aspect_mode)
|
2016-10-15 10:36:11 +00:00
|
|
|
{
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::Stretch:
|
2016-10-15 10:36:11 +00:00
|
|
|
ar_text = "Stretch";
|
|
|
|
break;
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::Analog:
|
2016-10-15 10:36:11 +00:00
|
|
|
ar_text = "Force 4:3";
|
|
|
|
break;
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::AnalogWide:
|
2016-10-15 10:36:11 +00:00
|
|
|
ar_text = "Force 16:9";
|
2017-11-11 03:45:32 +00:00
|
|
|
break;
|
2018-01-06 11:53:53 +00:00
|
|
|
case AspectMode::Auto:
|
|
|
|
default:
|
|
|
|
ar_text = "Auto";
|
|
|
|
break;
|
2016-10-15 10:36:11 +00:00
|
|
|
}
|
2018-06-05 21:34:28 +00:00
|
|
|
const std::string audio_text = SConfig::GetInstance().m_IsMuted ?
|
|
|
|
"Muted" :
|
|
|
|
std::to_string(SConfig::GetInstance().m_Volume) + "%";
|
2016-10-15 10:36:11 +00:00
|
|
|
|
|
|
|
const char* const efbcopy_text = g_ActiveConfig.bSkipEFBCopyToRam ? "to Texture" : "to RAM";
|
2017-06-26 03:23:47 +00:00
|
|
|
const char* const xfbcopy_text = g_ActiveConfig.bSkipXFBCopyToRam ? "to Texture" : "to RAM";
|
2016-10-15 10:36:11 +00:00
|
|
|
|
|
|
|
// The rows
|
|
|
|
const std::string lines[] = {
|
|
|
|
std::string("Internal Resolution: ") + res_text,
|
|
|
|
std::string("Aspect Ratio: ") + ar_text + (g_ActiveConfig.bCrop ? " (crop)" : ""),
|
|
|
|
std::string("Copy EFB: ") + efbcopy_text,
|
|
|
|
std::string("Fog: ") + (g_ActiveConfig.bDisableFog ? "Disabled" : "Enabled"),
|
|
|
|
SConfig::GetInstance().m_EmulationSpeed <= 0 ?
|
|
|
|
"Speed Limit: Unlimited" :
|
|
|
|
StringFromFormat("Speed Limit: %li%%",
|
|
|
|
std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)),
|
2017-09-03 02:30:34 +00:00
|
|
|
std::string("Copy XFB: ") + xfbcopy_text +
|
|
|
|
(g_ActiveConfig.bImmediateXFB ? " (Immediate)" : ""),
|
2018-06-05 21:34:28 +00:00
|
|
|
"Volume: " + audio_text,
|
2016-10-15 10:36:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
lines_count = sizeof(lines) / sizeof(*lines)
|
|
|
|
};
|
|
|
|
|
|
|
|
// The latest changed setting in yellow
|
|
|
|
for (int i = 0; i != lines_count; ++i)
|
|
|
|
{
|
2018-05-11 15:09:39 +00:00
|
|
|
if (m_osd_message == -i - 1)
|
2016-10-15 10:36:11 +00:00
|
|
|
final_yellow += lines[i];
|
|
|
|
final_yellow += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
// The other settings in cyan
|
|
|
|
for (int i = 0; i != lines_count; ++i)
|
|
|
|
{
|
2018-05-11 15:09:39 +00:00
|
|
|
if (m_osd_message != -i - 1)
|
2016-10-15 10:36:11 +00:00
|
|
|
final_cyan += lines[i];
|
|
|
|
final_cyan += '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final_cyan += Common::Profiler::ToString();
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayStats)
|
|
|
|
final_cyan += Statistics::ToString();
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bOverlayProjStats)
|
|
|
|
final_cyan += Statistics::ToStringProj();
|
|
|
|
|
|
|
|
// and then the text
|
2017-04-09 00:15:37 +00:00
|
|
|
RenderText(final_cyan, 20, 20, 0xFF00FFFF);
|
|
|
|
RenderText(final_yellow, 20, 20, 0xFFFFFF00);
|
2014-12-20 11:14:33 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
float Renderer::CalculateDrawAspectRatio() const
|
2016-11-10 12:36:11 +00:00
|
|
|
{
|
2017-11-11 03:45:32 +00:00
|
|
|
if (g_ActiveConfig.aspect_mode == AspectMode::Stretch)
|
2016-11-10 12:36:11 +00:00
|
|
|
{
|
|
|
|
// If stretch is enabled, we prefer the aspect ratio of the window.
|
2017-03-03 01:51:31 +00:00
|
|
|
return (static_cast<float>(m_backbuffer_width) / static_cast<float>(m_backbuffer_height));
|
2016-11-10 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
|
2017-11-11 03:45:32 +00:00
|
|
|
if (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
|
|
|
|
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide))
|
2016-11-10 12:36:11 +00:00
|
|
|
{
|
2017-03-03 01:51:31 +00:00
|
|
|
return AspectToWidescreen(VideoInterface::GetAspectRatio());
|
2016-11-10 12:36:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-03 01:51:31 +00:00
|
|
|
return VideoInterface::GetAspectRatio();
|
2016-11-10 12:36:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 06:53:44 +00:00
|
|
|
bool Renderer::IsHeadless() const
|
|
|
|
{
|
2018-10-03 13:03:13 +00:00
|
|
|
return true;
|
2017-11-23 06:53:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 06:23:24 +00:00
|
|
|
void Renderer::ChangeSurface(void* new_surface_handle)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(m_swap_mutex);
|
|
|
|
m_new_surface_handle = new_surface_handle;
|
|
|
|
m_surface_changed.Set();
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:03:16 +00:00
|
|
|
void Renderer::ResizeSurface()
|
2018-01-26 06:23:24 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(m_swap_mutex);
|
|
|
|
m_surface_resized.Set();
|
|
|
|
}
|
|
|
|
|
2017-04-08 23:40:04 +00:00
|
|
|
std::tuple<float, float> Renderer::ScaleToDisplayAspectRatio(const int width,
|
|
|
|
const int height) const
|
2017-01-23 18:33:26 +00:00
|
|
|
{
|
|
|
|
// Scale either the width or height depending the content aspect ratio.
|
|
|
|
// This way we preserve as much resolution as possible when scaling.
|
2017-03-03 01:51:31 +00:00
|
|
|
float scaled_width = static_cast<float>(width);
|
|
|
|
float scaled_height = static_cast<float>(height);
|
|
|
|
const float draw_aspect = CalculateDrawAspectRatio();
|
|
|
|
if (scaled_width / scaled_height >= draw_aspect)
|
|
|
|
scaled_height = scaled_width / draw_aspect;
|
|
|
|
else
|
|
|
|
scaled_width = scaled_height * draw_aspect;
|
|
|
|
return std::make_tuple(scaled_width, scaled_height);
|
2017-01-23 18:33:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-10 13:31:44 +00:00
|
|
|
void Renderer::UpdateDrawRectangle()
|
2010-11-18 03:50:50 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// The rendering window size
|
2017-03-03 01:51:31 +00:00
|
|
|
const float win_width = static_cast<float>(m_backbuffer_width);
|
|
|
|
const float win_height = static_cast<float>(m_backbuffer_height);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// Update aspect ratio hack values
|
|
|
|
// Won't take effect until next frame
|
|
|
|
// Don't know if there is a better place for this code so there isn't a 1 frame delay
|
|
|
|
if (g_ActiveConfig.bWidescreenHack)
|
|
|
|
{
|
|
|
|
float source_aspect = VideoInterface::GetAspectRatio();
|
2017-03-03 22:36:51 +00:00
|
|
|
if (m_aspect_wide)
|
2016-06-24 08:43:46 +00:00
|
|
|
source_aspect = AspectToWidescreen(source_aspect);
|
2017-11-11 03:45:32 +00:00
|
|
|
float target_aspect = 0.0f;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-11-11 03:45:32 +00:00
|
|
|
switch (g_ActiveConfig.aspect_mode)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::Stretch:
|
2017-03-03 01:51:31 +00:00
|
|
|
target_aspect = win_width / win_height;
|
2016-06-24 08:43:46 +00:00
|
|
|
break;
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::Analog:
|
2016-06-24 08:43:46 +00:00
|
|
|
target_aspect = VideoInterface::GetAspectRatio();
|
|
|
|
break;
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::AnalogWide:
|
2016-06-24 08:43:46 +00:00
|
|
|
target_aspect = AspectToWidescreen(VideoInterface::GetAspectRatio());
|
|
|
|
break;
|
2017-11-11 03:45:32 +00:00
|
|
|
case AspectMode::Auto:
|
2018-01-06 11:53:53 +00:00
|
|
|
default:
|
2016-06-24 08:43:46 +00:00
|
|
|
target_aspect = source_aspect;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float adjust = source_aspect / target_aspect;
|
|
|
|
if (adjust > 1)
|
|
|
|
{
|
|
|
|
// Vert+
|
|
|
|
g_Config.fAspectRatioHackW = 1;
|
|
|
|
g_Config.fAspectRatioHackH = 1 / adjust;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Hor+
|
|
|
|
g_Config.fAspectRatioHackW = adjust;
|
|
|
|
g_Config.fAspectRatioHackH = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Hack is disabled
|
|
|
|
g_Config.fAspectRatioHackW = 1;
|
|
|
|
g_Config.fAspectRatioHackH = 1;
|
|
|
|
}
|
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
float draw_width, draw_height, crop_width, crop_height;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
// get the picture aspect ratio
|
|
|
|
draw_width = crop_width = CalculateDrawAspectRatio();
|
|
|
|
draw_height = crop_height = 1;
|
|
|
|
|
|
|
|
// crop the picture to a standard aspect ratio
|
2017-11-11 03:45:32 +00:00
|
|
|
if (g_ActiveConfig.bCrop && g_ActiveConfig.aspect_mode != AspectMode::Stretch)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-11-11 03:45:32 +00:00
|
|
|
float expected_aspect = (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
|
|
|
|
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide)) ?
|
2017-03-03 01:51:31 +00:00
|
|
|
(16.0f / 9.0f) :
|
|
|
|
(4.0f / 3.0f);
|
|
|
|
if (crop_width / crop_height >= expected_aspect)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-03 01:51:31 +00:00
|
|
|
// the picture is flatter than it should be
|
|
|
|
crop_width = crop_height * expected_aspect;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-03 01:51:31 +00:00
|
|
|
// the picture is skinnier than it should be
|
|
|
|
crop_height = crop_width / expected_aspect;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
// scale the picture to fit the rendering window
|
|
|
|
if (win_width / win_height >= crop_width / crop_height)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-03 01:51:31 +00:00
|
|
|
// the window is flatter than the picture
|
|
|
|
draw_width *= win_height / crop_height;
|
|
|
|
crop_width *= win_height / crop_height;
|
|
|
|
draw_height *= win_height / crop_height;
|
|
|
|
crop_height = win_height;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-03-03 01:51:31 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// the window is skinnier than the picture
|
|
|
|
draw_width *= win_width / crop_width;
|
|
|
|
draw_height *= win_width / crop_width;
|
|
|
|
crop_height *= win_width / crop_width;
|
|
|
|
crop_width = win_width;
|
|
|
|
}
|
|
|
|
|
2018-05-08 13:19:38 +00:00
|
|
|
// Clamp the draw width/height to the screen size, to ensure we don't render off-screen.
|
|
|
|
draw_width = std::min(draw_width, win_width);
|
|
|
|
draw_height = std::min(draw_height, win_height);
|
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
// ensure divisibility by 4 to make it compatible with all the video encoders
|
|
|
|
draw_width = std::ceil(draw_width) - static_cast<int>(std::ceil(draw_width)) % 4;
|
|
|
|
draw_height = std::ceil(draw_height) - static_cast<int>(std::ceil(draw_height)) % 4;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-03 01:51:31 +00:00
|
|
|
m_target_rectangle.left = static_cast<int>(std::round(win_width / 2.0 - draw_width / 2.0));
|
|
|
|
m_target_rectangle.top = static_cast<int>(std::round(win_height / 2.0 - draw_height / 2.0));
|
|
|
|
m_target_rectangle.right = m_target_rectangle.left + static_cast<int>(draw_width);
|
|
|
|
m_target_rectangle.bottom = m_target_rectangle.top + static_cast<int>(draw_height);
|
2010-11-18 03:50:50 +00:00
|
|
|
}
|
|
|
|
|
2013-01-16 20:46:11 +00:00
|
|
|
void Renderer::SetWindowSize(int width, int height)
|
2011-03-15 23:09:12 +00:00
|
|
|
{
|
2017-08-29 05:24:25 +00:00
|
|
|
std::tie(width, height) = CalculateOutputDimensions(width, height);
|
|
|
|
|
|
|
|
// Track the last values of width/height to avoid sending a window resize event every frame.
|
|
|
|
if (width != m_last_window_request_width || height != m_last_window_request_height)
|
|
|
|
{
|
|
|
|
m_last_window_request_width = width;
|
|
|
|
m_last_window_request_height = height;
|
|
|
|
Host_RequestRenderWindowSize(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<int, int> Renderer::CalculateOutputDimensions(int width, int height)
|
|
|
|
{
|
|
|
|
width = std::max(width, 1);
|
|
|
|
height = std::max(height, 1);
|
|
|
|
|
2017-01-23 22:13:54 +00:00
|
|
|
float scaled_width, scaled_height;
|
|
|
|
std::tie(scaled_width, scaled_height) = ScaleToDisplayAspectRatio(width, height);
|
|
|
|
|
|
|
|
if (g_ActiveConfig.bCrop)
|
|
|
|
{
|
|
|
|
// Force 4:3 or 16:9 by cropping the image.
|
|
|
|
float current_aspect = scaled_width / scaled_height;
|
2017-11-11 03:45:32 +00:00
|
|
|
float expected_aspect = (g_ActiveConfig.aspect_mode == AspectMode::AnalogWide ||
|
|
|
|
(g_ActiveConfig.aspect_mode != AspectMode::Analog && m_aspect_wide)) ?
|
2017-03-03 22:36:51 +00:00
|
|
|
(16.0f / 9.0f) :
|
|
|
|
(4.0f / 3.0f);
|
2017-01-23 22:13:54 +00:00
|
|
|
if (current_aspect > expected_aspect)
|
|
|
|
{
|
|
|
|
// keep height, crop width
|
|
|
|
scaled_width = scaled_height * expected_aspect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// keep width, crop height
|
|
|
|
scaled_height = scaled_width / expected_aspect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width = static_cast<int>(std::ceil(scaled_width));
|
|
|
|
height = static_cast<int>(std::ceil(scaled_height));
|
|
|
|
|
|
|
|
// UpdateDrawRectangle() makes sure that the rendered image is divisible by four for video
|
|
|
|
// encoders, so do that here too to match it
|
|
|
|
width -= width % 4;
|
|
|
|
height -= height % 4;
|
|
|
|
|
2017-08-29 05:24:25 +00:00
|
|
|
return std::make_tuple(width, height);
|
2011-03-15 23:09:12 +00:00
|
|
|
}
|
|
|
|
|
2011-03-27 02:55:08 +00:00
|
|
|
void Renderer::CheckFifoRecording()
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
bool wasRecording = g_bRecordFifoData;
|
|
|
|
g_bRecordFifoData = FifoRecorder::GetInstance().IsRecording();
|
|
|
|
|
|
|
|
if (g_bRecordFifoData)
|
|
|
|
{
|
|
|
|
if (!wasRecording)
|
|
|
|
{
|
|
|
|
RecordVideoMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
FifoRecorder::GetInstance().EndFrame(CommandProcessor::fifo.CPBase,
|
|
|
|
CommandProcessor::fifo.CPEnd);
|
|
|
|
}
|
2011-03-27 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RecordVideoMemory()
|
|
|
|
{
|
2016-08-01 21:37:57 +00:00
|
|
|
const u32* bpmem_ptr = reinterpret_cast<const u32*>(&bpmem);
|
|
|
|
u32 cpmem[256] = {};
|
2016-06-24 08:43:46 +00:00
|
|
|
// The FIFO recording format splits XF memory into xfmem and xfregs; follow
|
|
|
|
// that split here.
|
2016-08-01 21:37:57 +00:00
|
|
|
const u32* xfmem_ptr = reinterpret_cast<const u32*>(&xfmem);
|
|
|
|
const u32* xfregs_ptr = reinterpret_cast<const u32*>(&xfmem) + FifoDataFile::XF_MEM_SIZE;
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 xfregs_size = sizeof(XFMemory) / 4 - FifoDataFile::XF_MEM_SIZE;
|
|
|
|
|
|
|
|
FillCPMemoryArray(cpmem);
|
|
|
|
|
2017-01-03 07:31:16 +00:00
|
|
|
FifoRecorder::GetInstance().SetVideoMemory(bpmem_ptr, cpmem, xfmem_ptr, xfregs_ptr, xfregs_size,
|
|
|
|
texMem);
|
2011-03-27 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc,
|
2017-08-15 04:07:39 +00:00
|
|
|
u64 ticks)
|
2014-02-05 10:48:45 +00:00
|
|
|
{
|
2017-03-03 22:36:51 +00:00
|
|
|
// Heuristic to detect if a GameCube game is in 16:9 anamorphic widescreen mode.
|
|
|
|
if (!SConfig::GetInstance().bWii)
|
|
|
|
{
|
|
|
|
size_t flush_count_4_3, flush_count_anamorphic;
|
|
|
|
std::tie(flush_count_4_3, flush_count_anamorphic) =
|
|
|
|
g_vertex_manager->ResetFlushAspectRatioCount();
|
|
|
|
size_t flush_total = flush_count_4_3 + flush_count_anamorphic;
|
|
|
|
|
|
|
|
// Modify the threshold based on which aspect ratio we're already using: if
|
|
|
|
// the game's in 4:3, it probably won't switch to anamorphic, and vice-versa.
|
|
|
|
if (m_aspect_wide)
|
|
|
|
m_aspect_wide = !(flush_count_4_3 > 0.75 * flush_total);
|
|
|
|
else
|
|
|
|
m_aspect_wide = flush_count_anamorphic > 0.75 * flush_total;
|
|
|
|
}
|
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
// Ensure the last frame was written to the dump.
|
|
|
|
// This is required even if frame dumping has stopped, since the frame dump is one frame
|
|
|
|
// behind the renderer.
|
|
|
|
FlushFrameDump();
|
2017-05-31 04:44:03 +00:00
|
|
|
|
2017-05-29 22:02:09 +00:00
|
|
|
if (xfbAddr && fbWidth && fbStride && fbHeight)
|
|
|
|
{
|
|
|
|
constexpr int force_safe_texture_cache_hash = 0;
|
|
|
|
// Get the current XFB from texture cache
|
2017-10-01 16:19:29 +00:00
|
|
|
auto* xfb_entry = g_texture_cache->GetXFBTexture(
|
|
|
|
xfbAddr, fbStride, fbHeight, TextureFormat::XFB, force_safe_texture_cache_hash);
|
2017-05-29 22:02:09 +00:00
|
|
|
|
2017-08-20 19:24:37 +00:00
|
|
|
if (xfb_entry && xfb_entry->id != m_last_xfb_id)
|
2017-07-03 02:24:20 +00:00
|
|
|
{
|
2018-01-13 03:37:04 +00:00
|
|
|
const TextureConfig& texture_config = xfb_entry->texture->GetConfig();
|
2017-05-31 04:44:03 +00:00
|
|
|
m_last_xfb_texture = xfb_entry->texture.get();
|
2017-08-20 19:24:37 +00:00
|
|
|
m_last_xfb_id = xfb_entry->id;
|
2017-09-14 04:46:30 +00:00
|
|
|
m_last_xfb_ticks = ticks;
|
2017-09-29 05:31:08 +00:00
|
|
|
|
2018-01-13 03:37:04 +00:00
|
|
|
auto xfb_rect = texture_config.GetRect();
|
2018-09-09 22:47:05 +00:00
|
|
|
|
|
|
|
// It's possible that the returned XFB texture is native resolution
|
|
|
|
// even when we're rendering at higher than native resolution
|
|
|
|
// if the XFB was was loaded entirely from console memory.
|
|
|
|
// If so, adjust the rectangle by native resolution instead of scaled resolution.
|
|
|
|
const u32 native_stride_width_difference = fbStride - fbWidth;
|
|
|
|
if (texture_config.width == xfb_entry->native_width)
|
|
|
|
xfb_rect.right -= native_stride_width_difference;
|
|
|
|
else
|
|
|
|
xfb_rect.right -= EFBToScaledX(native_stride_width_difference);
|
2017-09-29 05:31:08 +00:00
|
|
|
|
|
|
|
m_last_xfb_region = xfb_rect;
|
2017-05-29 22:02:09 +00:00
|
|
|
|
2017-07-03 02:24:20 +00:00
|
|
|
// TODO: merge more generic parts into VideoCommon
|
2018-01-26 06:23:24 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(m_swap_mutex);
|
2018-04-29 08:52:30 +00:00
|
|
|
g_renderer->SwapImpl(xfb_entry->texture.get(), xfb_rect, ticks);
|
2018-01-26 06:23:24 +00:00
|
|
|
}
|
2017-08-05 05:40:17 +00:00
|
|
|
|
2018-01-13 03:37:04 +00:00
|
|
|
// Update the window size based on the frame that was just rendered.
|
|
|
|
// Due to depending on guest state, we need to call this every frame.
|
|
|
|
SetWindowSize(texture_config.width, texture_config.height);
|
|
|
|
|
2017-08-05 05:40:17 +00:00
|
|
|
m_fps_counter.Update();
|
2017-11-19 07:33:53 +00:00
|
|
|
|
2018-10-27 03:11:20 +00:00
|
|
|
DolphinAnalytics::PerformanceSample perf_sample;
|
|
|
|
perf_sample.speed_ratio = SystemTimers::GetEstimatedEmulationPerformance();
|
|
|
|
perf_sample.num_prims = stats.thisFrame.numPrims + stats.thisFrame.numDLPrims;
|
|
|
|
perf_sample.num_draw_calls = stats.thisFrame.numDrawCalls;
|
|
|
|
DolphinAnalytics::Instance()->ReportPerformanceInfo(std::move(perf_sample));
|
|
|
|
|
2017-09-14 04:46:30 +00:00
|
|
|
if (IsFrameDumping())
|
2017-11-19 07:33:53 +00:00
|
|
|
DumpCurrentFrame();
|
2017-12-15 18:46:18 +00:00
|
|
|
|
|
|
|
frameCount++;
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true);
|
|
|
|
|
|
|
|
// Begin new frame
|
|
|
|
// Set default viewport and scissor, for the clear to work correctly
|
|
|
|
// New frame
|
|
|
|
stats.ResetFrame();
|
2018-02-24 15:15:35 +00:00
|
|
|
g_shader_cache->RetrieveAsyncShaders();
|
|
|
|
|
|
|
|
// We invalidate the pipeline object at the start of the frame.
|
|
|
|
// This is for the rare case where only a single pipeline configuration is used,
|
|
|
|
// and hybrid ubershaders have compiled the specialized shader, but without any
|
|
|
|
// state changes the specialized shader will not take over.
|
|
|
|
g_vertex_manager->InvalidatePipelineObject();
|
2017-12-15 18:46:18 +00:00
|
|
|
|
2018-11-02 14:17:00 +00:00
|
|
|
// Flush any outstanding EFB copies to RAM, in case the game is running at an uncapped frame
|
|
|
|
// rate and not waiting for vblank. Otherwise, we'd end up with a huge list of pending copies.
|
|
|
|
g_texture_cache->FlushEFBCopies();
|
|
|
|
|
2017-12-15 18:46:18 +00:00
|
|
|
Core::Callback_VideoCopiedToXFB(true);
|
2017-07-03 02:24:20 +00:00
|
|
|
}
|
2017-08-13 00:51:33 +00:00
|
|
|
|
|
|
|
// Update our last xfb values
|
|
|
|
m_last_xfb_width = (fbStride < 1 || fbStride > MAX_XFB_WIDTH) ? MAX_XFB_WIDTH : fbStride;
|
|
|
|
m_last_xfb_height = (fbHeight < 1 || fbHeight > MAX_XFB_HEIGHT) ? MAX_XFB_HEIGHT : fbHeight;
|
2017-05-29 22:02:09 +00:00
|
|
|
}
|
2014-02-05 10:48:45 +00:00
|
|
|
}
|
2015-05-01 16:58:11 +00:00
|
|
|
|
2016-10-07 18:31:51 +00:00
|
|
|
bool Renderer::IsFrameDumping()
|
|
|
|
{
|
2017-03-04 06:42:21 +00:00
|
|
|
if (m_screenshot_request.IsSet())
|
2016-10-08 16:23:57 +00:00
|
|
|
return true;
|
|
|
|
|
2016-10-07 18:31:51 +00:00
|
|
|
if (SConfig::GetInstance().m_DumpFrames)
|
|
|
|
return true;
|
2016-10-08 01:11:37 +00:00
|
|
|
|
2016-10-07 18:31:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
void Renderer::DumpCurrentFrame()
|
2017-09-14 04:46:30 +00:00
|
|
|
{
|
2017-11-19 07:33:53 +00:00
|
|
|
// Scale/render to frame dump texture.
|
|
|
|
RenderFrameDump();
|
2017-09-14 04:46:30 +00:00
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
// Queue a readback for the next frame.
|
|
|
|
QueueFrameDumpReadback();
|
2017-09-14 04:46:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
void Renderer::RenderFrameDump()
|
2017-08-29 05:24:25 +00:00
|
|
|
{
|
|
|
|
int target_width, target_height;
|
2017-11-23 06:53:44 +00:00
|
|
|
if (!g_ActiveConfig.bInternalResolutionFrameDumps && !IsHeadless())
|
2017-11-19 09:20:45 +00:00
|
|
|
{
|
|
|
|
auto target_rect = GetTargetRectangle();
|
|
|
|
target_width = target_rect.GetWidth();
|
|
|
|
target_height = target_rect.GetHeight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::tie(target_width, target_height) = CalculateOutputDimensions(
|
|
|
|
m_last_xfb_texture->GetConfig().width, m_last_xfb_texture->GetConfig().height);
|
|
|
|
}
|
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
// Ensure framebuffer exists (we lazily allocate it in case frame dumping isn't used).
|
|
|
|
// Or, resize texture if it isn't large enough to accommodate the current frame.
|
|
|
|
if (!m_frame_dump_render_texture ||
|
|
|
|
m_frame_dump_render_texture->GetConfig().width != static_cast<u32>(target_width) ||
|
2018-04-01 15:15:48 +00:00
|
|
|
m_frame_dump_render_texture->GetConfig().height != static_cast<u32>(target_height))
|
2017-11-19 07:33:53 +00:00
|
|
|
{
|
|
|
|
// Recreate texture objects. Release before creating so we don't temporarily use twice the RAM.
|
2018-01-21 05:03:06 +00:00
|
|
|
TextureConfig config(target_width, target_height, 1, 1, 1, AbstractTextureFormat::RGBA8, true);
|
2017-11-19 07:33:53 +00:00
|
|
|
m_frame_dump_render_texture.reset();
|
|
|
|
m_frame_dump_render_texture = CreateTexture(config);
|
2018-03-15 00:34:35 +00:00
|
|
|
ASSERT(m_frame_dump_render_texture);
|
2017-11-19 07:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Scaling is likely to occur here, but if possible, do a bit-for-bit copy.
|
|
|
|
if (m_last_xfb_region.GetWidth() != target_width ||
|
|
|
|
m_last_xfb_region.GetHeight() != target_height)
|
|
|
|
{
|
|
|
|
m_frame_dump_render_texture->ScaleRectangleFromTexture(
|
|
|
|
m_last_xfb_texture, m_last_xfb_region, EFBRectangle{0, 0, target_width, target_height});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame_dump_render_texture->CopyRectangleFromTexture(
|
|
|
|
m_last_xfb_texture, m_last_xfb_region, 0, 0,
|
|
|
|
EFBRectangle{0, 0, target_width, target_height}, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::QueueFrameDumpReadback()
|
|
|
|
{
|
|
|
|
// Index 0 was just sent to AVI dump. Swap with the second texture.
|
|
|
|
if (m_frame_dump_readback_textures[0])
|
|
|
|
std::swap(m_frame_dump_readback_textures[0], m_frame_dump_readback_textures[1]);
|
|
|
|
|
|
|
|
std::unique_ptr<AbstractStagingTexture>& rbtex = m_frame_dump_readback_textures[0];
|
|
|
|
if (!rbtex || rbtex->GetConfig() != m_frame_dump_render_texture->GetConfig())
|
|
|
|
{
|
|
|
|
rbtex = CreateStagingTexture(StagingTextureType::Readback,
|
|
|
|
m_frame_dump_render_texture->GetConfig());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_last_frame_state = AVIDump::FetchState(m_last_xfb_ticks);
|
|
|
|
m_last_frame_exported = true;
|
|
|
|
rbtex->CopyFromTexture(m_frame_dump_render_texture.get(), 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::FlushFrameDump()
|
|
|
|
{
|
|
|
|
if (!m_last_frame_exported)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure the previously-queued frame was encoded.
|
|
|
|
FinishFrameData();
|
|
|
|
|
|
|
|
// Queue encoding of the last frame dumped.
|
|
|
|
std::unique_ptr<AbstractStagingTexture>& rbtex = m_frame_dump_readback_textures[0];
|
|
|
|
rbtex->Flush();
|
|
|
|
if (rbtex->Map())
|
2017-08-29 05:24:25 +00:00
|
|
|
{
|
2017-11-19 07:33:53 +00:00
|
|
|
DumpFrameData(reinterpret_cast<u8*>(rbtex->GetMappedPointer()), rbtex->GetConfig().width,
|
|
|
|
rbtex->GetConfig().height, static_cast<int>(rbtex->GetMappedStride()),
|
|
|
|
m_last_frame_state);
|
|
|
|
rbtex->Unmap();
|
2017-08-29 05:24:25 +00:00
|
|
|
}
|
2017-11-19 07:33:53 +00:00
|
|
|
|
|
|
|
m_last_frame_exported = false;
|
|
|
|
|
|
|
|
// Shutdown frame dumping if it is no longer active.
|
|
|
|
if (!IsFrameDumping())
|
|
|
|
ShutdownFrameDumping();
|
2017-08-29 05:24:25 +00:00
|
|
|
}
|
|
|
|
|
2016-10-08 01:11:37 +00:00
|
|
|
void Renderer::ShutdownFrameDumping()
|
|
|
|
{
|
2017-11-19 07:33:53 +00:00
|
|
|
// Ensure the last queued readback has been sent to the encoder.
|
|
|
|
FlushFrameDump();
|
|
|
|
|
2016-10-08 01:11:37 +00:00
|
|
|
if (!m_frame_dump_thread_running.IsSet())
|
|
|
|
return;
|
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
// Ensure previous frame has been encoded.
|
2016-10-08 01:11:37 +00:00
|
|
|
FinishFrameData();
|
2017-11-19 07:33:53 +00:00
|
|
|
|
|
|
|
// Wake thread up, and wait for it to exit.
|
2016-10-08 01:11:37 +00:00
|
|
|
m_frame_dump_thread_running.Clear();
|
|
|
|
m_frame_dump_start.Set();
|
2017-11-19 07:33:53 +00:00
|
|
|
if (m_frame_dump_thread.joinable())
|
|
|
|
m_frame_dump_thread.join();
|
2018-01-26 02:12:00 +00:00
|
|
|
m_frame_dump_render_texture.reset();
|
|
|
|
for (auto& tex : m_frame_dump_readback_textures)
|
|
|
|
tex.reset();
|
2016-10-08 01:11:37 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 04:44:03 +00:00
|
|
|
void Renderer::DumpFrameData(const u8* data, int w, int h, int stride, const AVIDump::Frame& state)
|
2016-10-07 18:31:51 +00:00
|
|
|
{
|
2017-11-19 07:33:53 +00:00
|
|
|
m_frame_dump_config = FrameDumpConfig{data, w, h, stride, state};
|
2016-10-08 16:23:57 +00:00
|
|
|
|
2016-10-08 01:11:37 +00:00
|
|
|
if (!m_frame_dump_thread_running.IsSet())
|
2016-10-08 16:23:57 +00:00
|
|
|
{
|
2016-10-08 01:11:37 +00:00
|
|
|
if (m_frame_dump_thread.joinable())
|
|
|
|
m_frame_dump_thread.join();
|
|
|
|
m_frame_dump_thread_running.Set();
|
|
|
|
m_frame_dump_thread = std::thread(&Renderer::RunFrameDumps, this);
|
|
|
|
}
|
2016-10-08 16:23:57 +00:00
|
|
|
|
2017-11-19 07:33:53 +00:00
|
|
|
// Wake worker thread up.
|
2016-10-08 01:11:37 +00:00
|
|
|
m_frame_dump_start.Set();
|
|
|
|
m_frame_dump_frame_running = true;
|
|
|
|
}
|
2016-10-08 16:23:57 +00:00
|
|
|
|
2016-10-08 01:11:37 +00:00
|
|
|
void Renderer::FinishFrameData()
|
|
|
|
{
|
|
|
|
if (!m_frame_dump_frame_running)
|
|
|
|
return;
|
2016-10-07 18:31:51 +00:00
|
|
|
|
2016-10-08 01:11:37 +00:00
|
|
|
m_frame_dump_done.Wait();
|
|
|
|
m_frame_dump_frame_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::RunFrameDumps()
|
|
|
|
{
|
|
|
|
Common::SetCurrentThreadName("FrameDumping");
|
2016-11-18 12:57:08 +00:00
|
|
|
bool dump_to_avi = !g_ActiveConfig.bDumpFramesAsImages;
|
|
|
|
bool frame_dump_started = false;
|
|
|
|
|
|
|
|
// If Dolphin was compiled without libav, we only support dumping to images.
|
2017-05-22 19:27:10 +00:00
|
|
|
#if !defined(HAVE_FFMPEG)
|
2016-11-18 12:57:08 +00:00
|
|
|
if (dump_to_avi)
|
|
|
|
{
|
|
|
|
WARN_LOG(VIDEO, "AVI frame dump requested, but Dolphin was compiled without libav. "
|
|
|
|
"Frame dump will be saved as images instead.");
|
|
|
|
dump_to_avi = false;
|
|
|
|
}
|
|
|
|
#endif
|
2016-10-08 01:11:37 +00:00
|
|
|
|
|
|
|
while (true)
|
2016-10-07 18:31:51 +00:00
|
|
|
{
|
2016-10-08 01:11:37 +00:00
|
|
|
m_frame_dump_start.Wait();
|
|
|
|
if (!m_frame_dump_thread_running.IsSet())
|
|
|
|
break;
|
|
|
|
|
2016-11-07 21:46:48 +00:00
|
|
|
auto config = m_frame_dump_config;
|
2016-10-08 01:11:37 +00:00
|
|
|
|
|
|
|
// Save screenshot
|
2017-03-04 06:42:21 +00:00
|
|
|
if (m_screenshot_request.TestAndClear())
|
2016-10-07 18:31:51 +00:00
|
|
|
{
|
2017-03-04 06:42:21 +00:00
|
|
|
std::lock_guard<std::mutex> lk(m_screenshot_lock);
|
2016-10-08 01:11:37 +00:00
|
|
|
|
2017-03-04 06:42:21 +00:00
|
|
|
if (TextureToPng(config.data, config.stride, m_screenshot_name, config.width, config.height,
|
2016-10-08 01:11:37 +00:00
|
|
|
false))
|
2017-03-04 06:42:21 +00:00
|
|
|
OSD::AddMessage("Screenshot saved to " + m_screenshot_name);
|
2016-10-08 01:11:37 +00:00
|
|
|
|
|
|
|
// Reset settings
|
2017-03-04 06:42:21 +00:00
|
|
|
m_screenshot_name.clear();
|
2017-03-04 06:42:35 +00:00
|
|
|
m_screenshot_completed.Set();
|
2016-10-07 18:31:51 +00:00
|
|
|
}
|
2016-10-08 01:11:37 +00:00
|
|
|
|
|
|
|
if (SConfig::GetInstance().m_DumpFrames)
|
2016-10-07 18:31:51 +00:00
|
|
|
{
|
2016-11-18 12:57:08 +00:00
|
|
|
if (!frame_dump_started)
|
2016-10-08 01:11:37 +00:00
|
|
|
{
|
2016-11-18 12:57:08 +00:00
|
|
|
if (dump_to_avi)
|
|
|
|
frame_dump_started = StartFrameDumpToAVI(config);
|
2016-10-08 01:11:37 +00:00
|
|
|
else
|
2016-11-18 12:57:08 +00:00
|
|
|
frame_dump_started = StartFrameDumpToImage(config);
|
|
|
|
|
|
|
|
// Stop frame dumping if we fail to start.
|
|
|
|
if (!frame_dump_started)
|
2016-10-08 01:11:37 +00:00
|
|
|
SConfig::GetInstance().m_DumpFrames = false;
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:08 +00:00
|
|
|
// If we failed to start frame dumping, don't write a frame.
|
|
|
|
if (frame_dump_started)
|
|
|
|
{
|
|
|
|
if (dump_to_avi)
|
|
|
|
DumpFrameToAVI(config);
|
|
|
|
else
|
|
|
|
DumpFrameToImage(config);
|
|
|
|
}
|
2016-10-07 18:31:51 +00:00
|
|
|
}
|
2016-11-07 21:46:48 +00:00
|
|
|
|
|
|
|
m_frame_dump_done.Set();
|
2016-10-08 01:11:37 +00:00
|
|
|
}
|
2016-10-07 18:31:51 +00:00
|
|
|
|
2016-11-18 12:57:08 +00:00
|
|
|
if (frame_dump_started)
|
|
|
|
{
|
|
|
|
// No additional cleanup is needed when dumping to images.
|
|
|
|
if (dump_to_avi)
|
|
|
|
StopFrameDumpToAVI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 19:27:10 +00:00
|
|
|
#if defined(HAVE_FFMPEG)
|
2016-11-18 12:57:08 +00:00
|
|
|
|
|
|
|
bool Renderer::StartFrameDumpToAVI(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
return AVIDump::Start(config.width, config.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::DumpFrameToAVI(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
AVIDump::AddFrame(config.data, config.width, config.height, config.stride, config.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::StopFrameDumpToAVI()
|
|
|
|
{
|
|
|
|
AVIDump::Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
bool Renderer::StartFrameDumpToAVI(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::DumpFrameToAVI(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::StopFrameDumpToAVI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-22 19:27:10 +00:00
|
|
|
#endif // defined(HAVE_FFMPEG)
|
2016-11-18 12:57:08 +00:00
|
|
|
|
|
|
|
std::string Renderer::GetFrameDumpNextImageFileName() const
|
|
|
|
{
|
|
|
|
return StringFromFormat("%sframedump_%u.png", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
|
|
|
|
m_frame_dump_image_counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::StartFrameDumpToImage(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
m_frame_dump_image_counter = 1;
|
|
|
|
if (!SConfig::GetInstance().m_DumpFramesSilent)
|
2016-10-08 01:11:37 +00:00
|
|
|
{
|
2016-11-18 12:57:08 +00:00
|
|
|
// Only check for the presence of the first image to confirm overwriting.
|
|
|
|
// A previous run will always have at least one image, and it's safe to assume that if the user
|
|
|
|
// has allowed the first image to be overwritten, this will apply any remaining images as well.
|
|
|
|
std::string filename = GetFrameDumpNextImageFileName();
|
|
|
|
if (File::Exists(filename))
|
|
|
|
{
|
|
|
|
if (!AskYesNoT("Frame dump image(s) '%s' already exists. Overwrite?", filename.c_str()))
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-08 16:23:57 +00:00
|
|
|
}
|
2016-11-18 12:57:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::DumpFrameToImage(const FrameDumpConfig& config)
|
|
|
|
{
|
|
|
|
std::string filename = GetFrameDumpNextImageFileName();
|
|
|
|
TextureToPng(config.data, config.stride, filename, config.width, config.height, false);
|
|
|
|
m_frame_dump_image_counter++;
|
2016-10-07 18:31:51 +00:00
|
|
|
}
|
2017-02-24 14:16:28 +00:00
|
|
|
|
|
|
|
bool Renderer::UseVertexDepthRange() const
|
|
|
|
{
|
|
|
|
// We can't compute the depth range in the vertex shader if we don't support depth clamp.
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsDepthClamp)
|
|
|
|
return false;
|
|
|
|
|
2017-03-14 00:02:13 +00:00
|
|
|
// We need a full depth range if a ztexture is used.
|
|
|
|
if (bpmem.ztex2.type != ZTEXTURE_DISABLE && !bpmem.zcontrol.early_ztest)
|
|
|
|
return true;
|
2017-02-24 14:16:28 +00:00
|
|
|
|
2017-03-14 00:02:13 +00:00
|
|
|
// If an inverted depth range is unsupported, we also need to check if the range is inverted.
|
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsReversedDepthRange && xfmem.viewport.zRange < 0.0f)
|
|
|
|
return true;
|
2017-02-24 14:16:28 +00:00
|
|
|
|
2017-03-14 00:02:13 +00:00
|
|
|
// If an oversized depth range or a ztexture is used, we need to calculate the depth range
|
|
|
|
// in the vertex shader.
|
|
|
|
return fabs(xfmem.viewport.zRange) > 16777215.0f || fabs(xfmem.viewport.farZ) > 16777215.0f;
|
2017-02-24 14:16:28 +00:00
|
|
|
}
|
2018-02-25 07:56:09 +00:00
|
|
|
|
|
|
|
std::unique_ptr<VideoCommon::AsyncShaderCompiler> Renderer::CreateAsyncShaderCompiler()
|
|
|
|
{
|
|
|
|
return std::make_unique<VideoCommon::AsyncShaderCompiler>();
|
|
|
|
}
|
2018-05-11 15:09:39 +00:00
|
|
|
|
|
|
|
void Renderer::ShowOSDMessage(OSDMessage message)
|
|
|
|
{
|
|
|
|
m_osd_message = static_cast<s32>(message);
|
|
|
|
}
|