Merge pull request #4999 from stenzek/renderer-statics

VideoCommon: Eliminate static state in Renderer
This commit is contained in:
Markus Wick 2017-03-08 11:02:20 +01:00 committed by GitHub
commit 489d90b6f3
37 changed files with 303 additions and 381 deletions

View File

@ -484,8 +484,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulatio
jobject obj) jobject obj)
{ {
std::lock_guard<std::mutex> guard(s_host_identity_lock); std::lock_guard<std::mutex> guard(s_host_identity_lock);
Core::SaveScreenShot("thumb"); Core::SaveScreenShot("thumb", true);
Renderer::s_screenshotCompleted.WaitFor(std::chrono::seconds(2));
Core::Stop(); Core::Stop();
updateMainFrameEvent.Set(); // Kick the waiting event updateMainFrameEvent.Set(); // Kick the waiting event
} }

View File

@ -732,19 +732,19 @@ static std::string GenerateScreenshotName()
return name; return name;
} }
void SaveScreenShot() void SaveScreenShot(bool wait_for_completion)
{ {
const bool bPaused = GetState() == State::Paused; const bool bPaused = GetState() == State::Paused;
SetState(State::Paused); SetState(State::Paused);
Renderer::SetScreenshot(GenerateScreenshotName()); g_renderer->SaveScreenshot(GenerateScreenshotName(), wait_for_completion);
if (!bPaused) if (!bPaused)
SetState(State::Running); SetState(State::Running);
} }
void SaveScreenShot(const std::string& name) void SaveScreenShot(const std::string& name, bool wait_for_completion)
{ {
const bool bPaused = GetState() == State::Paused; const bool bPaused = GetState() == State::Paused;
@ -752,7 +752,7 @@ void SaveScreenShot(const std::string& name)
std::string filePath = GenerateScreenshotFolderPath() + name + ".png"; std::string filePath = GenerateScreenshotFolderPath() + name + ".png";
Renderer::SetScreenshot(filePath); g_renderer->SaveScreenshot(filePath, wait_for_completion);
if (!bPaused) if (!bPaused)
SetState(State::Running); SetState(State::Running);

View File

@ -55,8 +55,8 @@ bool IsGPUThread();
void SetState(State state); void SetState(State state);
State GetState(); State GetState();
void SaveScreenShot(); void SaveScreenShot(bool wait_for_completion = false);
void SaveScreenShot(const std::string& name); void SaveScreenShot(const std::string& name, bool wait_for_completion = false);
void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size); void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);

View File

@ -98,18 +98,10 @@ D3DTexture2D*& FramebufferManager::GetResolvedEFBDepthTexture()
} }
} }
FramebufferManager::FramebufferManager() FramebufferManager::FramebufferManager(int target_width, int target_height)
{ {
m_target_width = Renderer::GetTargetWidth(); m_target_width = static_cast<unsigned int>(std::max(target_width, 1));
m_target_height = Renderer::GetTargetHeight(); m_target_height = static_cast<unsigned int>(std::max(target_height, 1));
if (m_target_height < 1)
{
m_target_height = 1;
}
if (m_target_width < 1)
{
m_target_width = 1;
}
DXGI_SAMPLE_DESC sample_desc; DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples; sample_desc.Count = g_ActiveConfig.iMultisamples;
sample_desc.Quality = 0; sample_desc.Quality = 0;
@ -318,8 +310,8 @@ void XFBSource::CopyEFB(float Gamma)
D3D::SetPointCopySampler(); D3D::SetPointCopySampler();
D3D::drawShadedTexQuad( D3D::drawShadedTexQuad(
FramebufferManager::GetEFBColorTexture()->GetSRV(), &rect, Renderer::GetTargetWidth(), FramebufferManager::GetEFBColorTexture()->GetSRV(), &rect, g_renderer->GetTargetWidth(),
Renderer::GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(true), g_renderer->GetTargetHeight(), PixelShaderCache::GetColorCopyProgram(true),
VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(),
GeometryShaderCache::GetCopyGeometryShader(), Gamma); GeometryShaderCache::GetCopyGeometryShader(), Gamma);

View File

@ -60,7 +60,7 @@ struct XFBSource : public XFBSourceBase
class FramebufferManager : public FramebufferManagerBase class FramebufferManager : public FramebufferManagerBase
{ {
public: public:
FramebufferManager(); FramebufferManager(int target_width, int target_height);
~FramebufferManager(); ~FramebufferManager();
static D3DTexture2D*& GetEFBColorTexture(); static D3DTexture2D*& GetEFBColorTexture();

View File

@ -137,7 +137,7 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
D3D::SetPointCopySampler(); D3D::SetPointCopySampler();
D3D::drawShadedTexQuad( D3D::drawShadedTexQuad(
pEFB, targetRect.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), pEFB, targetRect.AsRECT(), g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
SetStaticShader(format, is_depth_copy, isIntensity, scaleByHalf), SetStaticShader(format, is_depth_copy, isIntensity, scaleByHalf),
VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout()); VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout());

View File

@ -84,8 +84,6 @@ static void SetupDeviceObjects()
{ {
s_television.Init(); s_television.Init();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
HRESULT hr; HRESULT hr;
D3D11_DEPTH_STENCIL_DESC ddesc; D3D11_DEPTH_STENCIL_DESC ddesc;
@ -235,25 +233,13 @@ static void Create3DVisionTexture(int width, int height)
delete[] sysData.pSysMem; delete[] sysData.pSysMem;
} }
Renderer::Renderer(void*& window_handle) Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
{ {
D3D::Create((HWND)window_handle);
s_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight();
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_multisamples = g_ActiveConfig.iMultisamples; s_last_multisamples = g_ActiveConfig.iMultisamples;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB; s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
SetupDeviceObjects(); SetupDeviceObjects();
// Setup GX pipeline state // Setup GX pipeline state
@ -282,7 +268,7 @@ Renderer::Renderer(void*& window_handle)
D3D::context->ClearDepthStencilView(FramebufferManager::GetEFBDepthTexture()->GetDSV(), D3D::context->ClearDepthStencilView(FramebufferManager::GetEFBDepthTexture()->GetDSV(),
D3D11_CLEAR_DEPTH, 0.f, 0); D3D11_CLEAR_DEPTH, 0.f, 0);
D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)s_target_width, (float)s_target_height); D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.f, 0.f, (float)m_target_width, (float)m_target_height);
D3D::context->RSSetViewports(1, &vp); D3D::context->RSSetViewports(1, &vp);
D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(), D3D::context->OMSetRenderTargets(1, &FramebufferManager::GetEFBColorTexture()->GetRTV(),
FramebufferManager::GetEFBDepthTexture()->GetDSV()); FramebufferManager::GetEFBDepthTexture()->GetDSV());
@ -324,8 +310,7 @@ bool Renderer::CheckForResize()
int client_height = rcWindow.bottom - rcWindow.top; int client_height = rcWindow.bottom - rcWindow.top;
// Sanity check // Sanity check
if ((client_width != Renderer::GetBackbufferWidth() || if ((client_width != GetBackbufferWidth() || client_height != GetBackbufferHeight()) &&
client_height != Renderer::GetBackbufferHeight()) &&
client_width >= 4 && client_height >= 4) client_width >= 4 && client_height >= 4)
{ {
return true; return true;
@ -726,7 +711,7 @@ void Renderer::SetBlendMode(bool forceUpdate)
void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
const EFBRectangle& rc, u64 ticks, float Gamma) const EFBRectangle& rc, u64 ticks, float Gamma)
{ {
if ((!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) if ((!m_xfb_written && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{ {
Core::Callback_VideoCopiedToXFB(false); Core::Callback_VideoCopiedToXFB(false);
return; return;
@ -880,7 +865,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
// Resize the back buffers NOW to avoid flickering // Resize the back buffers NOW to avoid flickering
if (CalculateTargetSize() || xfbchanged || windowResized || if (CalculateTargetSize() || xfbchanged || windowResized ||
s_last_efb_scale != g_ActiveConfig.iEFBScale ||
s_last_multisamples != g_ActiveConfig.iMultisamples || s_last_multisamples != g_ActiveConfig.iMultisamples ||
s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)) s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
{ {
@ -894,21 +878,18 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
D3D::Reset(); D3D::Reset();
SAFE_RELEASE(s_screenshot_texture); SAFE_RELEASE(s_screenshot_texture);
SAFE_RELEASE(s_3d_vision_texture); SAFE_RELEASE(s_3d_vision_texture);
s_backbuffer_width = D3D::GetBackBufferWidth(); m_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight(); m_backbuffer_height = D3D::GetBackBufferHeight();
} }
UpdateDrawRectangle(); UpdateDrawRectangle();
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
PixelShaderManager::SetEfbScaleChanged();
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr); D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr);
g_framebuffer_manager.reset(); g_framebuffer_manager.reset();
g_framebuffer_manager = std::make_unique<FramebufferManager>(); g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
float clear_col[4] = {0.f, 0.f, 0.f, 1.f}; float clear_col[4] = {0.f, 0.f, 0.f, 1.f};
D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(), D3D::context->ClearRenderTargetView(FramebufferManager::GetEFBColorTexture()->GetRTV(),
clear_col); clear_col);
@ -1162,12 +1143,12 @@ u16 Renderer::BBoxRead(int index)
if (index < 2) if (index < 2)
{ {
// left/right // left/right
value = value * EFB_WIDTH / s_target_width; value = value * EFB_WIDTH / m_target_width;
} }
else else
{ {
// up/down // up/down
value = value * EFB_HEIGHT / s_target_height; value = value * EFB_HEIGHT / m_target_height;
} }
if (index & 1) if (index & 1)
value++; // fix max values to describe the outer border value++; // fix max values to describe the outer border
@ -1182,11 +1163,11 @@ void Renderer::BBoxWrite(int index, u16 _value)
value--; value--;
if (index < 2) if (index < 2)
{ {
value = value * s_target_width / EFB_WIDTH; value = value * m_target_width / EFB_WIDTH;
} }
else else
{ {
value = value * s_target_height / EFB_HEIGHT; value = value * m_target_height / EFB_HEIGHT;
} }
BBox::Set(index, value); BBox::Set(index, value);
@ -1220,11 +1201,11 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
else if (g_ActiveConfig.iStereoMode == STEREO_3DVISION) else if (g_ActiveConfig.iStereoMode == STEREO_3DVISION)
{ {
if (!s_3d_vision_texture) if (!s_3d_vision_texture)
Create3DVisionTexture(s_backbuffer_width, s_backbuffer_height); Create3DVisionTexture(m_backbuffer_width, m_backbuffer_height);
D3D11_VIEWPORT leftVp = CD3D11_VIEWPORT((float)dst.left, (float)dst.top, (float)dst.GetWidth(), D3D11_VIEWPORT leftVp = CD3D11_VIEWPORT((float)dst.left, (float)dst.top, (float)dst.GetWidth(),
(float)dst.GetHeight()); (float)dst.GetHeight());
D3D11_VIEWPORT rightVp = CD3D11_VIEWPORT((float)(dst.left + s_backbuffer_width), (float)dst.top, D3D11_VIEWPORT rightVp = CD3D11_VIEWPORT((float)(dst.left + m_backbuffer_width), (float)dst.top,
(float)dst.GetWidth(), (float)dst.GetHeight()); (float)dst.GetWidth(), (float)dst.GetHeight());
// Render to staging texture which is double the width of the backbuffer // Render to staging texture which is double the width of the backbuffer
@ -1244,7 +1225,7 @@ void Renderer::BlitScreen(TargetRectangle src, TargetRectangle dst, D3DTexture2D
// Copy the left eye to the backbuffer, if Nvidia 3D Vision is enabled it should // Copy the left eye to the backbuffer, if Nvidia 3D Vision is enabled it should
// recognize the signature and automatically include the right eye frame. // recognize the signature and automatically include the right eye frame.
D3D11_BOX box = CD3D11_BOX(0, 0, 0, s_backbuffer_width, s_backbuffer_height, 1); D3D11_BOX box = CD3D11_BOX(0, 0, 0, m_backbuffer_width, m_backbuffer_height, 1);
D3D::context->CopySubresourceRegion(D3D::GetBackBuffer()->GetTex(), 0, 0, 0, 0, D3D::context->CopySubresourceRegion(D3D::GetBackBuffer()->GetTex(), 0, 0, 0, 0,
s_3d_vision_texture->GetTex(), 0, &box); s_3d_vision_texture->GetTex(), 0, &box);

View File

@ -16,8 +16,8 @@ class D3DTexture2D;
class Renderer : public ::Renderer class Renderer : public ::Renderer
{ {
public: public:
Renderer(void*& window_handle); Renderer();
~Renderer(); ~Renderer() override;
void SetColorMask() override; void SetColorMask() override;
void SetBlendMode(bool forceUpdate) override; void SetBlendMode(bool forceUpdate) override;
@ -60,7 +60,7 @@ public:
void ReinterpretPixelData(unsigned int convtype) override; void ReinterpretPixelData(unsigned int convtype) override;
static bool CheckForResize(); bool CheckForResize();
u32 GetMaxTextureSize() override; u32 GetMaxTextureSize() override;

View File

@ -230,7 +230,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool is_depth_copy, const EFBRe
// Create texture copy // Create texture copy
D3D::drawShadedTexQuad( D3D::drawShadedTexQuad(
efbTexSRV, &sourcerect, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), efbTexSRV, &sourcerect, g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
is_depth_copy ? PixelShaderCache::GetDepthMatrixProgram(multisampled) : is_depth_copy ? PixelShaderCache::GetDepthMatrixProgram(multisampled) :
PixelShaderCache::GetColorMatrixProgram(multisampled), PixelShaderCache::GetColorMatrixProgram(multisampled),
VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(),

View File

@ -6,6 +6,7 @@
#include <string> #include <string>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "VideoBackends/D3D/BoundingBox.h" #include "VideoBackends/D3D/BoundingBox.h"
@ -144,8 +145,11 @@ bool VideoBackend::Initialize(void* window_handle)
void VideoBackend::Video_Prepare() void VideoBackend::Video_Prepare()
{ {
if (FAILED(D3D::Create(reinterpret_cast<HWND>(m_window_handle))))
PanicAlert("Failed to create D3D device.");
// internal interfaces // internal interfaces
g_renderer = std::make_unique<Renderer>(m_window_handle); g_renderer = std::make_unique<Renderer>();
g_texture_cache = std::make_unique<TextureCache>(); g_texture_cache = std::make_unique<TextureCache>();
g_vertex_manager = std::make_unique<VertexManager>(); g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>(); g_perf_query = std::make_unique<PerfQuery>();

View File

@ -84,10 +84,10 @@ D3DTexture2D*& FramebufferManager::GetResolvedEFBDepthTexture()
} }
} }
FramebufferManager::FramebufferManager() FramebufferManager::FramebufferManager(int target_width, int target_height)
{ {
m_target_width = std::max(Renderer::GetTargetWidth(), 1); m_target_width = static_cast<unsigned int>(std::max(target_width, 1));
m_target_height = std::max(Renderer::GetTargetHeight(), 1); m_target_height = static_cast<unsigned int>(std::max(target_height, 1));
DXGI_SAMPLE_DESC sample_desc; DXGI_SAMPLE_DESC sample_desc;
sample_desc.Count = g_ActiveConfig.iMultisamples; sample_desc.Count = g_ActiveConfig.iMultisamples;
@ -525,7 +525,7 @@ void XFBSource::CopyEFB(float gamma)
D3D::SetPointCopySampler(); D3D::SetPointCopySampler();
D3D::DrawShadedTexQuad(FramebufferManager::GetEFBColorTexture(), &rect, D3D::DrawShadedTexQuad(FramebufferManager::GetEFBColorTexture(), &rect,
Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
StaticShaderCache::GetColorCopyPixelShader(true), StaticShaderCache::GetColorCopyPixelShader(true),
StaticShaderCache::GetSimpleVertexShader(), StaticShaderCache::GetSimpleVertexShader(),
StaticShaderCache::GetSimpleVertexShaderInputLayout(), StaticShaderCache::GetSimpleVertexShaderInputLayout(),

View File

@ -58,7 +58,7 @@ struct XFBSource final : public XFBSourceBase
class FramebufferManager final : public FramebufferManagerBase class FramebufferManager final : public FramebufferManagerBase
{ {
public: public:
FramebufferManager(); FramebufferManager(int target_width, int target_height);
~FramebufferManager(); ~FramebufferManager();
static D3DTexture2D*& GetEFBColorTexture(); static D3DTexture2D*& GetEFBColorTexture();

View File

@ -166,7 +166,7 @@ void PSTextureEncoder::Encode(u8* dst, u32 format, u32 native_width, u32 bytes_p
D3D::SetPointCopySampler(); D3D::SetPointCopySampler();
D3D::DrawShadedTexQuad( D3D::DrawShadedTexQuad(
efb_source, target_rect.AsRECT(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), efb_source, target_rect.AsRECT(), g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
SetStaticShader(format, is_depth_copy, is_intensity, scale_by_half), SetStaticShader(format, is_depth_copy, is_intensity, scale_by_half),
StaticShaderCache::GetSimpleVertexShader(), StaticShaderCache::GetSimpleVertexShader(),
StaticShaderCache::GetSimpleVertexShaderInputLayout(), D3D12_SHADER_BYTECODE(), 1.0f, 0, StaticShaderCache::GetSimpleVertexShaderInputLayout(), D3D12_SHADER_BYTECODE(), 1.0f, 0,

View File

@ -101,8 +101,6 @@ StateCache gx_state_cache;
static void SetupDeviceObjects() static void SetupDeviceObjects()
{ {
g_framebuffer_manager = std::make_unique<FramebufferManager>();
D3D12_DEPTH_STENCIL_DESC depth_desc; D3D12_DEPTH_STENCIL_DESC depth_desc;
depth_desc.DepthEnable = FALSE; depth_desc.DepthEnable = FALSE;
depth_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; depth_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO;
@ -211,7 +209,7 @@ static void Create3DVisionTexture(int width, int height)
// D3D12TODO: 3D Vision not implemented on D3D12 backend. // D3D12TODO: 3D Vision not implemented on D3D12 backend.
} }
Renderer::Renderer(void*& window_handle) Renderer::Renderer() : ::Renderer(D3D::GetBackBufferWidth(), D3D::GetBackBufferHeight())
{ {
if (g_ActiveConfig.iStereoMode == STEREO_3DVISION) if (g_ActiveConfig.iStereoMode == STEREO_3DVISION)
{ {
@ -219,21 +217,11 @@ Renderer::Renderer(void*& window_handle)
return; return;
} }
s_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight();
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_multisamples = g_ActiveConfig.iMultisamples; s_last_multisamples = g_ActiveConfig.iMultisamples;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB; s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
SetupDeviceObjects(); SetupDeviceObjects();
// Setup GX pipeline state // Setup GX pipeline state
@ -269,8 +257,8 @@ Renderer::Renderer(void*& window_handle)
D3D12_VIEWPORT vp = {0.f, D3D12_VIEWPORT vp = {0.f,
0.f, 0.f,
static_cast<float>(s_target_width), static_cast<float>(m_target_width),
static_cast<float>(s_target_height), static_cast<float>(m_target_height),
D3D12_MIN_DEPTH, D3D12_MIN_DEPTH,
D3D12_MAX_DEPTH}; D3D12_MAX_DEPTH};
D3D::current_command_list->RSSetViewports(1, &vp); D3D::current_command_list->RSSetViewports(1, &vp);
@ -308,7 +296,7 @@ TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
// With D3D, we have to resize the backbuffer if the window changed // With D3D, we have to resize the backbuffer if the window changed
// size. // size.
__declspec(noinline) bool Renderer::CheckForResize() bool Renderer::CheckForResize()
{ {
RECT rc_window; RECT rc_window;
GetClientRect(D3D::hWnd, &rc_window); GetClientRect(D3D::hWnd, &rc_window);
@ -646,7 +634,7 @@ void Renderer::SetBlendMode(bool force_update)
void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height, void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height,
const EFBRectangle& rc, u64 ticks, float gamma) const EFBRectangle& rc, u64 ticks, float gamma)
{ {
if ((!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fb_width || !fb_height) if ((!m_xfb_written && !g_ActiveConfig.RealXFBEnabled()) || !fb_width || !fb_height)
{ {
Core::Callback_VideoCopiedToXFB(false); Core::Callback_VideoCopiedToXFB(false);
return; return;
@ -833,7 +821,6 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
// Resize the back buffers NOW to avoid flickering // Resize the back buffers NOW to avoid flickering
if (CalculateTargetSize() || xfb_changed || window_resized || if (CalculateTargetSize() || xfb_changed || window_resized ||
s_last_efb_scale != g_ActiveConfig.iEFBScale ||
s_last_multisamples != g_ActiveConfig.iMultisamples || s_last_multisamples != g_ActiveConfig.iMultisamples ||
s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)) s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0))
{ {
@ -860,24 +847,21 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
s_screenshot_texture = nullptr; s_screenshot_texture = nullptr;
} }
s_backbuffer_width = D3D::GetBackBufferWidth(); m_backbuffer_width = D3D::GetBackBufferWidth();
s_backbuffer_height = D3D::GetBackBufferHeight(); m_backbuffer_height = D3D::GetBackBufferHeight();
} }
UpdateDrawRectangle(); UpdateDrawRectangle();
s_last_efb_scale = g_ActiveConfig.iEFBScale;
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
PixelShaderManager::SetEfbScaleChanged();
D3D::GetBackBuffer()->TransitionToResourceState(D3D::current_command_list, D3D::GetBackBuffer()->TransitionToResourceState(D3D::current_command_list,
D3D12_RESOURCE_STATE_RENDER_TARGET); D3D12_RESOURCE_STATE_RENDER_TARGET);
D3D::current_command_list->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV12(), FALSE, D3D::current_command_list->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV12(), FALSE,
nullptr); nullptr);
g_framebuffer_manager.reset(); g_framebuffer_manager.reset();
g_framebuffer_manager = std::make_unique<FramebufferManager>(); g_framebuffer_manager = std::make_unique<FramebufferManager>(m_target_width, m_target_height);
const float clear_color[4] = {0.f, 0.f, 0.f, 1.f}; const float clear_color[4] = {0.f, 0.f, 0.f, 1.f};
FramebufferManager::GetEFBColorTexture()->TransitionToResourceState( FramebufferManager::GetEFBColorTexture()->TransitionToResourceState(
@ -1189,12 +1173,12 @@ u16 Renderer::BBoxRead(int index)
if (index < 2) if (index < 2)
{ {
// left/right // left/right
value = value * EFB_WIDTH / s_target_width; value = value * EFB_WIDTH / m_target_width;
} }
else else
{ {
// up/down // up/down
value = value * EFB_HEIGHT / s_target_height; value = value * EFB_HEIGHT / m_target_height;
} }
if (index & 1) if (index & 1)
value++; // fix max values to describe the outer border value++; // fix max values to describe the outer border
@ -1209,11 +1193,11 @@ void Renderer::BBoxWrite(int index, u16 value)
local_value--; local_value--;
if (index < 2) if (index < 2)
{ {
local_value = local_value * s_target_width / EFB_WIDTH; local_value = local_value * m_target_width / EFB_WIDTH;
} }
else else
{ {
local_value = local_value * s_target_height / EFB_HEIGHT; local_value = local_value * m_target_height / EFB_HEIGHT;
} }
BBox::Set(index, local_value); BBox::Set(index, local_value);

View File

@ -17,8 +17,8 @@ class D3DTexture2D;
class Renderer final : public ::Renderer class Renderer final : public ::Renderer
{ {
public: public:
Renderer(void*& window_handle); Renderer();
~Renderer(); ~Renderer() override;
void SetColorMask() override; void SetColorMask() override;
void SetBlendMode(bool force_update) override; void SetBlendMode(bool force_update) override;
@ -59,7 +59,7 @@ public:
void ReinterpretPixelData(unsigned int conv_type) override; void ReinterpretPixelData(unsigned int conv_type) override;
static bool CheckForResize(); bool CheckForResize();
u32 GetMaxTextureSize() override; u32 GetMaxTextureSize() override;

View File

@ -288,7 +288,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(bool is_depth_copy, const EFBRe
// Create texture copy // Create texture copy
D3D::DrawShadedTexQuad( D3D::DrawShadedTexQuad(
efb_tex, &sourcerect, Renderer::GetTargetWidth(), Renderer::GetTargetHeight(), efb_tex, &sourcerect, g_renderer->GetTargetWidth(), g_renderer->GetTargetHeight(),
is_depth_copy ? StaticShaderCache::GetDepthMatrixPixelShader(multisampled) : is_depth_copy ? StaticShaderCache::GetDepthMatrixPixelShader(multisampled) :
StaticShaderCache::GetColorMatrixPixelShader(multisampled), StaticShaderCache::GetColorMatrixPixelShader(multisampled),
StaticShaderCache::GetSimpleVertexShader(), StaticShaderCache::GetSimpleVertexShader(),

View File

@ -163,7 +163,7 @@ bool VideoBackend::Initialize(void* window_handle)
void VideoBackend::Video_Prepare() void VideoBackend::Video_Prepare()
{ {
// internal interfaces // internal interfaces
g_renderer = std::make_unique<Renderer>(m_window_handle); g_renderer = std::make_unique<Renderer>();
g_texture_cache = std::make_unique<TextureCache>(); g_texture_cache = std::make_unique<TextureCache>();
g_vertex_manager = std::make_unique<VertexManager>(); g_vertex_manager = std::make_unique<VertexManager>();
g_perf_query = std::make_unique<PerfQuery>(); g_perf_query = std::make_unique<PerfQuery>();

View File

@ -11,7 +11,7 @@
namespace Null namespace Null
{ {
// Init functions // Init functions
Renderer::Renderer() Renderer::Renderer() : ::Renderer(1, 1)
{ {
g_Config.bRunning = true; g_Config.bRunning = true;
UpdateActiveConfig(); UpdateActiveConfig();

View File

@ -12,7 +12,7 @@ class Renderer : public ::Renderer
{ {
public: public:
Renderer(); Renderer();
~Renderer(); ~Renderer() override;
void RenderText(const std::string& pstr, int left, int top, u32 color) override; void RenderText(const std::string& pstr, int left, int top, u32 color) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; } u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }

View File

@ -329,6 +329,8 @@ static void InitDriverInfo()
// Init functions // Init functions
Renderer::Renderer() Renderer::Renderer()
: ::Renderer(static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u)),
static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u)))
{ {
bool bSuccess = true; bool bSuccess = true;
@ -687,26 +689,11 @@ Renderer::Renderer()
s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0;
s_last_xfb_mode = g_ActiveConfig.bUseRealXFB; s_last_xfb_mode = g_ActiveConfig.bUseRealXFB;
// Decide framebuffer size
s_backbuffer_width = static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u));
s_backbuffer_height = static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u));
// Handle VSync on/off // Handle VSync on/off
s_vsync = g_ActiveConfig.IsVSync(); s_vsync = g_ActiveConfig.IsVSync();
if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC)) if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_VSYNC))
GLInterface->SwapInterval(s_vsync); GLInterface->SwapInterval(s_vsync);
// TODO: Move these somewhere else?
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateDrawRectangle();
s_last_efb_scale = g_ActiveConfig.iEFBScale;
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
// Because of the fixed framebuffer size we need to disable the resolution // Because of the fixed framebuffer size we need to disable the resolution
// options while running // options while running
g_Config.bRunning = true; g_Config.bRunning = true;
@ -788,7 +775,7 @@ void Renderer::Init()
{ {
// Initialize the FramebufferManager // Initialize the FramebufferManager
g_framebuffer_manager = g_framebuffer_manager =
std::make_unique<FramebufferManager>(s_target_width, s_target_height, s_MSAASamples); std::make_unique<FramebufferManager>(m_target_width, m_target_height, s_MSAASamples);
m_post_processor = std::make_unique<OpenGLPostProcessing>(); m_post_processor = std::make_unique<OpenGLPostProcessing>();
s_raster_font = std::make_unique<RasterFont>(); s_raster_font = std::make_unique<RasterFont>();
@ -1056,12 +1043,12 @@ u16 Renderer::BBoxRead(int index)
if (index < 2) if (index < 2)
{ {
// left/right // left/right
value = value * EFB_WIDTH / s_target_width; value = value * EFB_WIDTH / m_target_width;
} }
else else
{ {
// up/down -- we have to swap up and down // up/down -- we have to swap up and down
value = value * EFB_HEIGHT / s_target_height; value = value * EFB_HEIGHT / m_target_height;
value = EFB_HEIGHT - value - 1; value = EFB_HEIGHT - value - 1;
} }
if (index & 1) if (index & 1)
@ -1077,13 +1064,13 @@ void Renderer::BBoxWrite(int index, u16 _value)
value--; value--;
if (index < 2) if (index < 2)
{ {
value = value * s_target_width / EFB_WIDTH; value = value * m_target_width / EFB_WIDTH;
} }
else else
{ {
index ^= 1; // swap 2 and 3 for top/bottom index ^= 1; // swap 2 and 3 for top/bottom
value = EFB_HEIGHT - value - 1; value = EFB_HEIGHT - value - 1;
value = value * s_target_height / EFB_HEIGHT; value = value * m_target_height / EFB_HEIGHT;
} }
BoundingBox::Set(index, value); BoundingBox::Set(index, value);
@ -1294,7 +1281,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
glDisable(GL_DEBUG_OUTPUT); glDisable(GL_DEBUG_OUTPUT);
} }
if ((!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight) if ((!m_xfb_written && !g_ActiveConfig.RealXFBEnabled()) || !fbWidth || !fbHeight)
{ {
Core::Callback_VideoCopiedToXFB(false); Core::Callback_VideoCopiedToXFB(false);
return; return;
@ -1364,13 +1351,11 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
bool window_resized = false; bool window_resized = false;
int window_width = static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u)); int window_width = static_cast<int>(std::max(GLInterface->GetBackBufferWidth(), 1u));
int window_height = static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u)); int window_height = static_cast<int>(std::max(GLInterface->GetBackBufferHeight(), 1u));
if (window_width != s_backbuffer_width || window_height != s_backbuffer_height || if (window_width != m_backbuffer_width || window_height != m_backbuffer_height)
s_last_efb_scale != g_ActiveConfig.iEFBScale)
{ {
window_resized = true; window_resized = true;
s_backbuffer_width = window_width; m_backbuffer_width = window_width;
s_backbuffer_height = window_height; m_backbuffer_height = window_height;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
} }
bool target_size_changed = CalculateTargetSize(); bool target_size_changed = CalculateTargetSize();
@ -1400,9 +1385,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
g_framebuffer_manager.reset(); g_framebuffer_manager.reset();
g_framebuffer_manager = g_framebuffer_manager =
std::make_unique<FramebufferManager>(s_target_width, s_target_height, s_MSAASamples); std::make_unique<FramebufferManager>(m_target_width, m_target_height, s_MSAASamples);
PixelShaderManager::SetEfbScaleChanged();
} }
} }
@ -1420,13 +1403,13 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
OSD::DrawMessages(); OSD::DrawMessages();
#ifdef ANDROID #ifdef ANDROID
if (s_surface_needs_change.IsSet()) if (m_surface_needs_change.IsSet())
{ {
GLInterface->UpdateHandle(s_new_surface_handle); GLInterface->UpdateHandle(m_new_surface_handle);
GLInterface->UpdateSurface(); GLInterface->UpdateSurface();
s_new_surface_handle = nullptr; m_new_surface_handle = nullptr;
s_surface_needs_change.Clear(); m_surface_needs_change.Clear();
s_surface_changed.Set(); m_surface_changed.Set();
} }
#endif #endif
@ -1493,7 +1476,7 @@ void Renderer::DrawEFB(GLuint framebuffer, const TargetRectangle& target_rc,
// for msaa mode, we must resolve the efb content to non-msaa // for msaa mode, we must resolve the efb content to non-msaa
GLuint tex = FramebufferManager::ResolveAndGetRenderTarget(source_rc); GLuint tex = FramebufferManager::ResolveAndGetRenderTarget(source_rc);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
BlitScreen(scaled_source_rc, target_rc, tex, s_target_width, s_target_height); BlitScreen(scaled_source_rc, target_rc, tex, m_target_width, m_target_height);
} }
void Renderer::DrawVirtualXFB(GLuint framebuffer, const TargetRectangle& target_rc, u32 xfb_addr, void Renderer::DrawVirtualXFB(GLuint framebuffer, const TargetRectangle& target_rc, u32 xfb_addr,
@ -1815,9 +1798,9 @@ void Renderer::ChangeSurface(void* new_surface_handle)
// This is only necessary for Android at this point, although handling resizes here // This is only necessary for Android at this point, although handling resizes here
// would be more efficient than polling. // would be more efficient than polling.
#ifdef ANDROID #ifdef ANDROID
s_new_surface_handle = new_surface_handle; m_new_surface_handle = new_surface_handle;
s_surface_needs_change.Set(); m_surface_needs_change.Set();
s_surface_changed.Wait(); m_surface_changed.Wait();
#endif #endif
} }
} }

View File

@ -69,10 +69,10 @@ class Renderer : public ::Renderer
{ {
public: public:
Renderer(); Renderer();
~Renderer(); ~Renderer() override;
static void Init(); void Init();
static void Shutdown(); void Shutdown();
void SetBlendMode(bool forceUpdate) override; void SetBlendMode(bool forceUpdate) override;
void SetScissorRect(const EFBRectangle& rc) override; void SetScissorRect(const EFBRectangle& rc) override;

View File

@ -149,7 +149,7 @@ void VideoBackend::Video_Prepare()
ProgramShaderCache::Init(); ProgramShaderCache::Init();
g_texture_cache = std::make_unique<TextureCache>(); g_texture_cache = std::make_unique<TextureCache>();
g_sampler_cache = std::make_unique<SamplerCache>(); g_sampler_cache = std::make_unique<SamplerCache>();
Renderer::Init(); static_cast<Renderer*>(g_renderer.get())->Init();
TextureConverter::Init(); TextureConverter::Init();
BoundingBox::Init(); BoundingBox::Init();
} }
@ -166,7 +166,7 @@ void VideoBackend::Video_Cleanup()
// The following calls are NOT Thread Safe // The following calls are NOT Thread Safe
// And need to be called from the video thread // And need to be called from the video thread
CleanupShared(); CleanupShared();
Renderer::Shutdown(); static_cast<Renderer*>(g_renderer.get())->Shutdown();
BoundingBox::Shutdown(); BoundingBox::Shutdown();
TextureConverter::Shutdown(); TextureConverter::Shutdown();
g_sampler_cache.reset(); g_sampler_cache.reset();

View File

@ -25,6 +25,11 @@
static u8* s_xfbColorTexture[2]; static u8* s_xfbColorTexture[2];
static int s_currentColorTexture = 0; static int s_currentColorTexture = 0;
SWRenderer::SWRenderer()
: ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT))
{
}
SWRenderer::~SWRenderer() SWRenderer::~SWRenderer()
{ {
delete[] s_xfbColorTexture[0]; delete[] s_xfbColorTexture[0];

View File

@ -13,6 +13,7 @@
class SWRenderer : public Renderer class SWRenderer : public Renderer
{ {
public: public:
SWRenderer();
~SWRenderer() override; ~SWRenderer() override;
static void Init(); static void Init();

View File

@ -226,8 +226,8 @@ void FramebufferManager::DestroyEFBRenderPass()
bool FramebufferManager::CreateEFBFramebuffer() bool FramebufferManager::CreateEFBFramebuffer()
{ {
m_efb_width = static_cast<u32>(std::max(Renderer::GetTargetWidth(), 1)); m_efb_width = static_cast<u32>(std::max(g_renderer->GetTargetWidth(), 1));
m_efb_height = static_cast<u32>(std::max(Renderer::GetTargetHeight(), 1)); m_efb_height = static_cast<u32>(std::max(g_renderer->GetTargetHeight(), 1));
m_efb_layers = (g_ActiveConfig.iStereoMode != STEREO_OFF) ? 2 : 1; m_efb_layers = (g_ActiveConfig.iStereoMode != STEREO_OFF) ? 2 : 1;
INFO_LOG(VIDEO, "EFB size: %ux%ux%u", m_efb_width, m_efb_height, m_efb_layers); INFO_LOG(VIDEO, "EFB size: %ux%ux%u", m_efb_width, m_efb_height, m_efb_layers);

View File

@ -42,7 +42,10 @@
namespace Vulkan namespace Vulkan
{ {
Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain) : m_swap_chain(std::move(swap_chain)) Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain)
: ::Renderer(swap_chain ? static_cast<int>(swap_chain->GetWidth()) : 1,
swap_chain ? static_cast<int>(swap_chain->GetHeight()) : 0),
m_swap_chain(std::move(swap_chain))
{ {
g_Config.bRunning = true; g_Config.bRunning = true;
UpdateActiveConfig(); UpdateActiveConfig();
@ -50,17 +53,6 @@ Renderer::Renderer(std::unique_ptr<SwapChain> swap_chain) : m_swap_chain(std::mo
// Set to something invalid, forcing all states to be re-initialized. // Set to something invalid, forcing all states to be re-initialized.
for (size_t i = 0; i < m_sampler_states.size(); i++) for (size_t i = 0; i < m_sampler_states.size(); i++)
m_sampler_states[i].bits = std::numeric_limits<decltype(m_sampler_states[i].bits)>::max(); m_sampler_states[i].bits = std::numeric_limits<decltype(m_sampler_states[i].bits)>::max();
// These have to be initialized before FramebufferManager is created.
// If running surfaceless, assume a window size of MAX_XFB_{WIDTH,HEIGHT}.
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
s_backbuffer_width = m_swap_chain ? m_swap_chain->GetWidth() : MAX_XFB_WIDTH;
s_backbuffer_height = m_swap_chain ? m_swap_chain->GetHeight() : MAX_XFB_HEIGHT;
s_last_efb_scale = g_ActiveConfig.iEFBScale;
UpdateDrawRectangle();
CalculateTargetSize();
PixelShaderManager::SetEfbScaleChanged();
} }
Renderer::~Renderer() Renderer::~Renderer()
@ -274,12 +266,12 @@ u16 Renderer::BBoxRead(int index)
if (index < 2) if (index < 2)
{ {
// left/right // left/right
value = value * EFB_WIDTH / s_target_width; value = value * EFB_WIDTH / m_target_width;
} }
else else
{ {
// up/down // up/down
value = value * EFB_HEIGHT / s_target_height; value = value * EFB_HEIGHT / m_target_height;
} }
// fix max values to describe the outer border // fix max values to describe the outer border
@ -301,12 +293,12 @@ void Renderer::BBoxWrite(int index, u16 value)
if (index < 2) if (index < 2)
{ {
// left/right // left/right
scaled_value = scaled_value * s_target_width / EFB_WIDTH; scaled_value = scaled_value * m_target_width / EFB_WIDTH;
} }
else else
{ {
// up/down // up/down
scaled_value = scaled_value * s_target_height / EFB_HEIGHT; scaled_value = scaled_value * m_target_height / EFB_HEIGHT;
} }
m_bounding_box->Set(static_cast<size_t>(index), scaled_value); m_bounding_box->Set(static_cast<size_t>(index), scaled_value);
@ -485,7 +477,7 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height
FramebufferManager::GetInstance()->FlushEFBPokes(); FramebufferManager::GetInstance()->FlushEFBPokes();
// Check that we actually have an image to render in XFB-on modes. // Check that we actually have an image to render in XFB-on modes.
if ((!XFBWrited && !g_ActiveConfig.RealXFBEnabled()) || !fb_width || !fb_height) if ((!m_xfb_written && !g_ActiveConfig.RealXFBEnabled()) || !fb_width || !fb_height)
{ {
Core::Callback_VideoCopiedToXFB(false); Core::Callback_VideoCopiedToXFB(false);
return; return;
@ -1020,30 +1012,27 @@ void Renderer::CheckForTargetResize(u32 fb_width, u32 fb_stride, u32 fb_height)
// Changing the XFB source area may alter the target size. // Changing the XFB source area may alter the target size.
if (CalculateTargetSize()) if (CalculateTargetSize())
{
PixelShaderManager::SetEfbScaleChanged();
ResizeEFBTextures(); ResizeEFBTextures();
}
} }
void Renderer::CheckForSurfaceChange() void Renderer::CheckForSurfaceChange()
{ {
if (!s_surface_needs_change.IsSet()) if (!m_surface_needs_change.IsSet())
return; return;
u32 old_width = m_swap_chain ? m_swap_chain->GetWidth() : 0; u32 old_width = m_swap_chain ? m_swap_chain->GetWidth() : 0;
u32 old_height = m_swap_chain ? m_swap_chain->GetHeight() : 0; u32 old_height = m_swap_chain ? m_swap_chain->GetHeight() : 0;
// Fast path, if the surface handle is the same, the window has just been resized. // Fast path, if the surface handle is the same, the window has just been resized.
if (m_swap_chain && s_new_surface_handle == m_swap_chain->GetNativeHandle()) if (m_swap_chain && m_new_surface_handle == m_swap_chain->GetNativeHandle())
{ {
INFO_LOG(VIDEO, "Detected window resize."); INFO_LOG(VIDEO, "Detected window resize.");
ResizeSwapChain(); ResizeSwapChain();
// Notify the main thread we are done. // Notify the main thread we are done.
s_surface_needs_change.Clear(); m_surface_needs_change.Clear();
s_new_surface_handle = nullptr; m_new_surface_handle = nullptr;
s_surface_changed.Set(); m_surface_changed.Set();
} }
else else
{ {
@ -1053,7 +1042,7 @@ void Renderer::CheckForSurfaceChange()
// Did we previously have a swap chain? // Did we previously have a swap chain?
if (m_swap_chain) if (m_swap_chain)
{ {
if (!s_new_surface_handle) if (!m_new_surface_handle)
{ {
// If there is no surface now, destroy the swap chain. // If there is no surface now, destroy the swap chain.
m_swap_chain.reset(); m_swap_chain.reset();
@ -1061,7 +1050,7 @@ void Renderer::CheckForSurfaceChange()
else else
{ {
// Recreate the surface. If this fails we're in trouble. // Recreate the surface. If this fails we're in trouble.
if (!m_swap_chain->RecreateSurface(s_new_surface_handle)) if (!m_swap_chain->RecreateSurface(m_new_surface_handle))
PanicAlert("Failed to recreate Vulkan surface. Cannot continue."); PanicAlert("Failed to recreate Vulkan surface. Cannot continue.");
} }
} }
@ -1069,10 +1058,10 @@ void Renderer::CheckForSurfaceChange()
{ {
// Previously had no swap chain. So create one. // Previously had no swap chain. So create one.
VkSurfaceKHR surface = SwapChain::CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(), VkSurfaceKHR surface = SwapChain::CreateVulkanSurface(g_vulkan_context->GetVulkanInstance(),
s_new_surface_handle); m_new_surface_handle);
if (surface != VK_NULL_HANDLE) if (surface != VK_NULL_HANDLE)
{ {
m_swap_chain = SwapChain::Create(s_new_surface_handle, surface, g_ActiveConfig.IsVSync()); m_swap_chain = SwapChain::Create(m_new_surface_handle, surface, g_ActiveConfig.IsVSync());
if (!m_swap_chain) if (!m_swap_chain)
PanicAlert("Failed to create swap chain."); PanicAlert("Failed to create swap chain.");
} }
@ -1083,9 +1072,9 @@ void Renderer::CheckForSurfaceChange()
} }
// Notify calling thread. // Notify calling thread.
s_surface_needs_change.Clear(); m_surface_needs_change.Clear();
s_new_surface_handle = nullptr; m_new_surface_handle = nullptr;
s_surface_changed.Set(); m_surface_changed.Set();
} }
if (m_swap_chain) if (m_swap_chain)
@ -1103,6 +1092,7 @@ void Renderer::CheckForConfigChanges()
int old_anisotropy = g_ActiveConfig.iMaxAnisotropy; int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
int old_stereo_mode = g_ActiveConfig.iStereoMode; int old_stereo_mode = g_ActiveConfig.iStereoMode;
int old_aspect_ratio = g_ActiveConfig.iAspectRatio; int old_aspect_ratio = g_ActiveConfig.iAspectRatio;
int old_efb_scale = g_ActiveConfig.iEFBScale;
bool old_force_filtering = g_ActiveConfig.bForceFiltering; bool old_force_filtering = g_ActiveConfig.bForceFiltering;
bool old_ssaa = g_ActiveConfig.bSSAA; bool old_ssaa = g_ActiveConfig.bSSAA;
bool old_use_xfb = g_ActiveConfig.bUseXFB; bool old_use_xfb = g_ActiveConfig.bUseXFB;
@ -1119,7 +1109,7 @@ void Renderer::CheckForConfigChanges()
bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy; bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy;
bool force_texture_filtering_changed = old_force_filtering != g_ActiveConfig.bForceFiltering; bool force_texture_filtering_changed = old_force_filtering != g_ActiveConfig.bForceFiltering;
bool stereo_changed = old_stereo_mode != g_ActiveConfig.iStereoMode; bool stereo_changed = old_stereo_mode != g_ActiveConfig.iStereoMode;
bool efb_scale_changed = s_last_efb_scale != g_ActiveConfig.iEFBScale; bool efb_scale_changed = old_efb_scale != g_ActiveConfig.iEFBScale;
bool aspect_changed = old_aspect_ratio != g_ActiveConfig.iAspectRatio; bool aspect_changed = old_aspect_ratio != g_ActiveConfig.iAspectRatio;
bool use_xfb_changed = old_use_xfb != g_ActiveConfig.bUseXFB; bool use_xfb_changed = old_use_xfb != g_ActiveConfig.bUseXFB;
bool use_realxfb_changed = old_use_realxfb != g_ActiveConfig.bUseRealXFB; bool use_realxfb_changed = old_use_realxfb != g_ActiveConfig.bUseRealXFB;
@ -1130,7 +1120,6 @@ void Renderer::CheckForConfigChanges()
// Handle settings that can cause the target rectangle to change. // Handle settings that can cause the target rectangle to change.
if (efb_scale_changed || aspect_changed || use_xfb_changed || use_realxfb_changed) if (efb_scale_changed || aspect_changed || use_xfb_changed || use_realxfb_changed)
{ {
s_last_efb_scale = g_ActiveConfig.iEFBScale;
if (CalculateTargetSize()) if (CalculateTargetSize())
ResizeEFBTextures(); ResizeEFBTextures();
} }
@ -1170,14 +1159,11 @@ void Renderer::CheckForConfigChanges()
void Renderer::OnSwapChainResized() void Renderer::OnSwapChainResized()
{ {
s_backbuffer_width = m_swap_chain->GetWidth(); m_backbuffer_width = m_swap_chain->GetWidth();
s_backbuffer_height = m_swap_chain->GetHeight(); m_backbuffer_height = m_swap_chain->GetHeight();
UpdateDrawRectangle(); UpdateDrawRectangle();
if (CalculateTargetSize()) if (CalculateTargetSize())
{
PixelShaderManager::SetEfbScaleChanged();
ResizeEFBTextures(); ResizeEFBTextures();
}
} }
void Renderer::BindEFBToStateTracker() void Renderer::BindEFBToStateTracker()
@ -1676,9 +1662,9 @@ void Renderer::SetViewport()
void Renderer::ChangeSurface(void* new_surface_handle) void Renderer::ChangeSurface(void* new_surface_handle)
{ {
// Called by the main thread when the window is resized. // Called by the main thread when the window is resized.
s_new_surface_handle = new_surface_handle; m_new_surface_handle = new_surface_handle;
s_surface_needs_change.Set(); m_surface_needs_change.Set();
s_surface_changed.Set(); m_surface_changed.Set();
} }
void Renderer::RecompileShaders() void Renderer::RecompileShaders()

View File

@ -28,7 +28,7 @@ class Renderer : public ::Renderer
{ {
public: public:
Renderer(std::unique_ptr<SwapChain> swap_chain); Renderer(std::unique_ptr<SwapChain> swap_chain);
~Renderer(); ~Renderer() override;
static Renderer* GetInstance(); static Renderer* GetInstance();

View File

@ -136,8 +136,8 @@ void AsyncRequests::HandleEvent(const AsyncRequests::Event& e)
break; break;
case Event::SWAP_EVENT: case Event::SWAP_EVENT:
Renderer::Swap(e.swap_event.xfbAddr, e.swap_event.fbWidth, e.swap_event.fbStride, g_renderer->Swap(e.swap_event.xfbAddr, e.swap_event.fbWidth, e.swap_event.fbStride,
e.swap_event.fbHeight, rc, e.time); e.swap_event.fbHeight, rc, e.time);
break; break;
case Event::BBOX_READ: case Event::BBOX_READ:

View File

@ -156,7 +156,7 @@ void OnPixelFormatChange()
if (!g_ActiveConfig.bEFBEmulateFormatChanges) if (!g_ActiveConfig.bEFBEmulateFormatChanges)
return; return;
auto old_format = Renderer::GetPrevPixelFormat(); auto old_format = g_renderer->GetPrevPixelFormat();
auto new_format = bpmem.zcontrol.pixel_format; auto new_format = bpmem.zcontrol.pixel_format;
// no need to reinterpret pixel data in these cases // no need to reinterpret pixel data in these cases
@ -209,7 +209,7 @@ skip:
DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", static_cast<int>(new_format), DEBUG_LOG(VIDEO, "pixelfmt: pixel=%d, zc=%d", static_cast<int>(new_format),
static_cast<int>(bpmem.zcontrol.zformat)); static_cast<int>(bpmem.zcontrol.zformat));
Renderer::StorePixelFormat(new_format); g_renderer->StorePixelFormat(new_format);
} }
void SetInterlacingMode(const BPCmd& bp) void SetInterlacingMode(const BPCmd& bp)

View File

@ -261,7 +261,7 @@ static void BPWritten(const BPCmd& bp)
"fbStride: %u | fbHeight: %u", "fbStride: %u | fbHeight: %u",
destAddr, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom, destAddr, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom,
bpmem.copyTexSrcWH.x + 1, destStride, height); bpmem.copyTexSrcWH.x + 1, destStride, height);
Renderer::RenderToXFB(destAddr, srcRect, destStride, height, s_gammaLUT[PE_copy.gamma]); g_renderer->RenderToXFB(destAddr, srcRect, destStride, height, s_gammaLUT[PE_copy.gamma]);
} }
// Clear the rectangular region after copying it. // Clear the rectangular region after copying it.

View File

@ -253,8 +253,8 @@ int FramebufferManagerBase::ScaleToVirtualXfbWidth(int x)
if (g_ActiveConfig.RealXFBEnabled()) if (g_ActiveConfig.RealXFBEnabled())
return x; return x;
return x * (int)Renderer::GetTargetRectangle().GetWidth() / return x * static_cast<int>(g_renderer->GetTargetRectangle().GetWidth()) /
(int)FramebufferManagerBase::LastXfbWidth(); static_cast<int>(FramebufferManagerBase::LastXfbWidth());
} }
int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y) int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y)
@ -262,6 +262,6 @@ int FramebufferManagerBase::ScaleToVirtualXfbHeight(int y)
if (g_ActiveConfig.RealXFBEnabled()) if (g_ActiveConfig.RealXFBEnabled())
return y; return y;
return y * (int)Renderer::GetTargetRectangle().GetHeight() / return y * static_cast<int>(g_renderer->GetTargetRectangle().GetHeight()) /
(int)FramebufferManagerBase::LastXfbHeight(); static_cast<int>(FramebufferManagerBase::LastXfbHeight());
} }

View File

@ -27,7 +27,6 @@ void PixelShaderManager::Init()
s_bFogRangeAdjustChanged = true; s_bFogRangeAdjustChanged = true;
s_bViewPortChanged = false; s_bViewPortChanged = false;
SetEfbScaleChanged();
SetIndMatrixChanged(0); SetIndMatrixChanged(0);
SetIndMatrixChanged(1); SetIndMatrixChanged(1);
SetIndMatrixChanged(2); SetIndMatrixChanged(2);
@ -50,7 +49,7 @@ void PixelShaderManager::Dirty()
// Any constants that can changed based on settings should be re-calculated // Any constants that can changed based on settings should be re-calculated
s_bFogRangeAdjustChanged = true; s_bFogRangeAdjustChanged = true;
SetEfbScaleChanged(); SetEfbScaleChanged(g_renderer->EFBToScaledXf(1), g_renderer->EFBToScaledYf(1));
SetFogParamChanged(); SetFogParamChanged();
dirty = true; dirty = true;
@ -78,7 +77,8 @@ void PixelShaderManager::SetConstants()
// so to simplify I use the hi coefficient as K in the shader taking 256 as the scale // so to simplify I use the hi coefficient as K in the shader taking 256 as the scale
// TODO: Shouldn't this be EFBToScaledXf? // TODO: Shouldn't this be EFBToScaledXf?
constants.fogf[0][0] = ScreenSpaceCenter; constants.fogf[0][0] = ScreenSpaceCenter;
constants.fogf[0][1] = (float)Renderer::EFBToScaledX((int)(2.0f * xfmem.viewport.wd)); constants.fogf[0][1] =
static_cast<float>(g_renderer->EFBToScaledX(static_cast<int>(2.0f * xfmem.viewport.wd)));
constants.fogf[0][2] = bpmem.fogRange.K[4].HI / 256.0f; constants.fogf[0][2] = bpmem.fogRange.K[4].HI / 256.0f;
} }
else else
@ -159,10 +159,10 @@ void PixelShaderManager::SetViewportChanged()
true; // TODO: Shouldn't be necessary with an accurate fog range adjust implementation true; // TODO: Shouldn't be necessary with an accurate fog range adjust implementation
} }
void PixelShaderManager::SetEfbScaleChanged() void PixelShaderManager::SetEfbScaleChanged(float scalex, float scaley)
{ {
constants.efbscale[0] = 1.0f / Renderer::EFBToScaledXf(1); constants.efbscale[0] = 1.0f / scalex;
constants.efbscale[1] = 1.0f / Renderer::EFBToScaledYf(1); constants.efbscale[1] = 1.0f / scaley;
dirty = true; dirty = true;
} }

View File

@ -29,7 +29,7 @@ public:
static void SetTexDims(int texmapid, u32 width, u32 height); static void SetTexDims(int texmapid, u32 width, u32 height);
static void SetZTextureBias(); static void SetZTextureBias();
static void SetViewportChanged(); static void SetViewportChanged();
static void SetEfbScaleChanged(); static void SetEfbScaleChanged(float scalex, float scaley);
static void SetZSlope(float dfdx, float dfdy, float f0); static void SetZSlope(float dfdx, float dfdy, float f0);
static void SetIndMatrixChanged(int matrixidx); static void SetIndMatrixChanged(int matrixidx);
static void SetZTextureTypeChanged(); static void SetZTextureTypeChanged();

View File

@ -50,6 +50,7 @@
#include "VideoCommon/FramebufferManagerBase.h" #include "VideoCommon/FramebufferManagerBase.h"
#include "VideoCommon/ImageWrite.h" #include "VideoCommon/ImageWrite.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/PostProcessing.h" #include "VideoCommon/PostProcessing.h"
#include "VideoCommon/Statistics.h" #include "VideoCommon/Statistics.h"
#include "VideoCommon/TextureCacheBase.h" #include "VideoCommon/TextureCacheBase.h"
@ -64,39 +65,6 @@ static int OSDTime;
std::unique_ptr<Renderer> g_renderer; std::unique_ptr<Renderer> g_renderer;
std::mutex Renderer::s_criticalScreenshot;
std::string Renderer::s_sScreenshotName;
Common::Event Renderer::s_screenshotCompleted;
Common::Flag Renderer::s_screenshot;
// The framebuffer size
int Renderer::s_target_width;
int Renderer::s_target_height;
// TODO: Add functionality to reinit all the render targets when the window is resized.
int Renderer::s_backbuffer_width;
int Renderer::s_backbuffer_height;
std::unique_ptr<PostProcessingShaderImplementation> Renderer::m_post_processor;
// Final surface changing
Common::Flag Renderer::s_surface_needs_change;
Common::Event Renderer::s_surface_changed;
void* Renderer::s_new_surface_handle;
TargetRectangle Renderer::target_rc;
int Renderer::s_last_efb_scale;
bool Renderer::XFBWrited;
PEControl::PixelFormat Renderer::prev_efb_format = PEControl::INVALID_FMT;
unsigned int Renderer::efb_scale_numeratorX = 1;
unsigned int Renderer::efb_scale_numeratorY = 1;
unsigned int Renderer::efb_scale_denominatorX = 1;
unsigned int Renderer::efb_scale_denominatorY = 1;
// The maximum depth that is written to the depth buffer should never exceed this value. // The maximum depth that is written to the depth buffer should never exceed this value.
// This is necessary because we use a 2^24 divisor for all our depth values to prevent // This is necessary because we use a 2^24 divisor for all our depth values to prevent
// floating-point round-trip errors. However the console GPU doesn't ever write a value // floating-point round-trip errors. However the console GPU doesn't ever write a value
@ -108,9 +76,16 @@ static float AspectToWidescreen(float aspect)
return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f)); return aspect * ((16.0f / 9.0f) / (4.0f / 3.0f));
} }
Renderer::Renderer() Renderer::Renderer(int backbuffer_width, int backbuffer_height)
: m_backbuffer_width(backbuffer_width), m_backbuffer_height(backbuffer_height),
m_last_efb_scale(g_ActiveConfig.iEFBScale)
{ {
FramebufferManagerBase::SetLastXfbWidth(MAX_XFB_WIDTH);
FramebufferManagerBase::SetLastXfbHeight(MAX_XFB_HEIGHT);
UpdateActiveConfig(); UpdateActiveConfig();
CalculateTargetSize();
UpdateDrawRectangle();
OSDChoice = 0; OSDChoice = 0;
OSDTime = 0; OSDTime = 0;
@ -118,11 +93,6 @@ Renderer::Renderer()
Renderer::~Renderer() Renderer::~Renderer()
{ {
// invalidate previous efb format
prev_efb_format = PEControl::INVALID_FMT;
efb_scale_numeratorX = efb_scale_numeratorY = efb_scale_denominatorX = efb_scale_denominatorY = 1;
ShutdownFrameDumping(); ShutdownFrameDumping();
if (m_frame_dump_thread.joinable()) if (m_frame_dump_thread.joinable())
m_frame_dump_thread.join(); m_frame_dump_thread.join();
@ -136,7 +106,7 @@ void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbStri
if (!fbStride || !fbHeight) if (!fbStride || !fbHeight)
return; return;
XFBWrited = true; m_xfb_written = true;
if (g_ActiveConfig.bUseXFB) if (g_ActiveConfig.bUseXFB)
{ {
@ -160,7 +130,7 @@ int Renderer::EFBToScaledX(int x)
return FramebufferManagerBase::ScaleToVirtualXfbWidth(x); return FramebufferManagerBase::ScaleToVirtualXfbWidth(x);
default: default:
return x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX; return x * (int)m_efb_scale_numeratorX / (int)m_efb_scale_denominatorX;
}; };
} }
@ -172,7 +142,7 @@ int Renderer::EFBToScaledY(int y)
return FramebufferManagerBase::ScaleToVirtualXfbHeight(y); return FramebufferManagerBase::ScaleToVirtualXfbHeight(y);
default: default:
return y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY; return y * (int)m_efb_scale_numeratorY / (int)m_efb_scale_denominatorY;
}; };
} }
@ -185,8 +155,8 @@ void Renderer::CalculateTargetScale(int x, int y, int* scaledX, int* scaledY)
} }
else else
{ {
*scaledX = x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX; *scaledX = x * (int)m_efb_scale_numeratorX / (int)m_efb_scale_denominatorX;
*scaledY = y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY; *scaledY = y * (int)m_efb_scale_numeratorY / (int)m_efb_scale_denominatorY;
} }
} }
@ -196,71 +166,74 @@ bool Renderer::CalculateTargetSize()
int newEFBWidth, newEFBHeight; int newEFBWidth, newEFBHeight;
newEFBWidth = newEFBHeight = 0; newEFBWidth = newEFBHeight = 0;
m_last_efb_scale = g_ActiveConfig.iEFBScale;
// TODO: Ugly. Clean up // TODO: Ugly. Clean up
switch (s_last_efb_scale) switch (m_last_efb_scale)
{ {
case SCALE_AUTO: case SCALE_AUTO:
case SCALE_AUTO_INTEGRAL: case SCALE_AUTO_INTEGRAL:
newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH); newEFBWidth = FramebufferManagerBase::ScaleToVirtualXfbWidth(EFB_WIDTH);
newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT); newEFBHeight = FramebufferManagerBase::ScaleToVirtualXfbHeight(EFB_HEIGHT);
if (s_last_efb_scale == SCALE_AUTO_INTEGRAL) if (m_last_efb_scale == SCALE_AUTO_INTEGRAL)
{ {
efb_scale_numeratorX = efb_scale_numeratorY = m_efb_scale_numeratorX = m_efb_scale_numeratorY =
std::max((newEFBWidth - 1) / EFB_WIDTH + 1, (newEFBHeight - 1) / EFB_HEIGHT + 1); std::max((newEFBWidth - 1) / EFB_WIDTH + 1, (newEFBHeight - 1) / EFB_HEIGHT + 1);
efb_scale_denominatorX = efb_scale_denominatorY = 1; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 1;
newEFBWidth = EFBToScaledX(EFB_WIDTH); newEFBWidth = EFBToScaledX(EFB_WIDTH);
newEFBHeight = EFBToScaledY(EFB_HEIGHT); newEFBHeight = EFBToScaledY(EFB_HEIGHT);
} }
else else
{ {
efb_scale_numeratorX = newEFBWidth; m_efb_scale_numeratorX = newEFBWidth;
efb_scale_denominatorX = EFB_WIDTH; m_efb_scale_denominatorX = EFB_WIDTH;
efb_scale_numeratorY = newEFBHeight; m_efb_scale_numeratorY = newEFBHeight;
efb_scale_denominatorY = EFB_HEIGHT; m_efb_scale_denominatorY = EFB_HEIGHT;
} }
break; break;
case SCALE_1X: case SCALE_1X:
efb_scale_numeratorX = efb_scale_numeratorY = 1; m_efb_scale_numeratorX = m_efb_scale_numeratorY = 1;
efb_scale_denominatorX = efb_scale_denominatorY = 1; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 1;
break; break;
case SCALE_1_5X: case SCALE_1_5X:
efb_scale_numeratorX = efb_scale_numeratorY = 3; m_efb_scale_numeratorX = m_efb_scale_numeratorY = 3;
efb_scale_denominatorX = efb_scale_denominatorY = 2; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 2;
break; break;
case SCALE_2X: case SCALE_2X:
efb_scale_numeratorX = efb_scale_numeratorY = 2; m_efb_scale_numeratorX = m_efb_scale_numeratorY = 2;
efb_scale_denominatorX = efb_scale_denominatorY = 1; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 1;
break; break;
case SCALE_2_5X: case SCALE_2_5X:
efb_scale_numeratorX = efb_scale_numeratorY = 5; m_efb_scale_numeratorX = m_efb_scale_numeratorY = 5;
efb_scale_denominatorX = efb_scale_denominatorY = 2; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 2;
break; break;
default: default:
efb_scale_numeratorX = efb_scale_numeratorY = s_last_efb_scale - 3; m_efb_scale_numeratorX = m_efb_scale_numeratorY = m_last_efb_scale - 3;
efb_scale_denominatorX = efb_scale_denominatorY = 1; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 1;
const u32 max_size = GetMaxTextureSize(); const u32 max_size = GetMaxTextureSize();
if (max_size < EFB_WIDTH * efb_scale_numeratorX / efb_scale_denominatorX) if (max_size < EFB_WIDTH * m_efb_scale_numeratorX / m_efb_scale_denominatorX)
{ {
efb_scale_numeratorX = efb_scale_numeratorY = (max_size / EFB_WIDTH); m_efb_scale_numeratorX = m_efb_scale_numeratorY = (max_size / EFB_WIDTH);
efb_scale_denominatorX = efb_scale_denominatorY = 1; m_efb_scale_denominatorX = m_efb_scale_denominatorY = 1;
} }
break; break;
} }
if (s_last_efb_scale > SCALE_AUTO_INTEGRAL) if (m_last_efb_scale > SCALE_AUTO_INTEGRAL)
CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT, &newEFBWidth, &newEFBHeight); CalculateTargetScale(EFB_WIDTH, EFB_HEIGHT, &newEFBWidth, &newEFBHeight);
if (newEFBWidth != s_target_width || newEFBHeight != s_target_height) if (newEFBWidth != m_target_width || newEFBHeight != m_target_height)
{ {
s_target_width = newEFBWidth; m_target_width = newEFBWidth;
s_target_height = newEFBHeight; m_target_height = newEFBHeight;
PixelShaderManager::SetEfbScaleChanged(EFBToScaledXf(1), EFBToScaledYf(1));
return true; return true;
} }
return false; return false;
@ -289,25 +262,34 @@ void Renderer::ConvertStereoRectangle(const TargetRectangle& rc, TargetRectangle
leftRc = drawRc, rightRc = drawRc; leftRc = drawRc, rightRc = drawRc;
if (g_ActiveConfig.iStereoMode == STEREO_TAB) if (g_ActiveConfig.iStereoMode == STEREO_TAB)
{ {
leftRc.top -= s_backbuffer_height / 4; leftRc.top -= m_backbuffer_height / 4;
leftRc.bottom -= s_backbuffer_height / 4; leftRc.bottom -= m_backbuffer_height / 4;
rightRc.top += s_backbuffer_height / 4; rightRc.top += m_backbuffer_height / 4;
rightRc.bottom += s_backbuffer_height / 4; rightRc.bottom += m_backbuffer_height / 4;
} }
else else
{ {
leftRc.left -= s_backbuffer_width / 4; leftRc.left -= m_backbuffer_width / 4;
leftRc.right -= s_backbuffer_width / 4; leftRc.right -= m_backbuffer_width / 4;
rightRc.left += s_backbuffer_width / 4; rightRc.left += m_backbuffer_width / 4;
rightRc.right += s_backbuffer_width / 4; rightRc.right += m_backbuffer_width / 4;
} }
} }
void Renderer::SetScreenshot(const std::string& filename) void Renderer::SaveScreenshot(const std::string& filename, bool wait_for_completion)
{ {
std::lock_guard<std::mutex> lk(s_criticalScreenshot); // We must not hold the lock while waiting for the screenshot to complete.
s_sScreenshotName = filename; {
s_screenshot.Set(); 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));
}
} }
// Create On-Screen-Messages // Create On-Screen-Messages
@ -460,7 +442,7 @@ float Renderer::CalculateDrawAspectRatio(int target_width, int target_height)
{ {
// If stretch is enabled, we prefer the aspect ratio of the window. // If stretch is enabled, we prefer the aspect ratio of the window.
return (static_cast<float>(target_width) / static_cast<float>(target_height)) / return (static_cast<float>(target_width) / static_cast<float>(target_height)) /
(static_cast<float>(s_backbuffer_width) / static_cast<float>(s_backbuffer_height)); (static_cast<float>(m_backbuffer_width) / static_cast<float>(m_backbuffer_height));
} }
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
@ -505,8 +487,8 @@ TargetRectangle Renderer::CalculateFrameDumpDrawRectangle()
if (!g_ActiveConfig.bInternalResolutionFrameDumps || g_ActiveConfig.RealXFBEnabled()) if (!g_ActiveConfig.bInternalResolutionFrameDumps || g_ActiveConfig.RealXFBEnabled())
{ {
// But still remove the borders, since the caller expects this. // But still remove the borders, since the caller expects this.
rc.right = target_rc.GetWidth(); rc.right = m_target_rectangle.GetWidth();
rc.bottom = target_rc.GetHeight(); rc.bottom = m_target_rectangle.GetHeight();
return rc; return rc;
} }
@ -524,8 +506,8 @@ TargetRectangle Renderer::CalculateFrameDumpDrawRectangle()
void Renderer::UpdateDrawRectangle() void Renderer::UpdateDrawRectangle()
{ {
float FloatGLWidth = static_cast<float>(s_backbuffer_width); float FloatGLWidth = static_cast<float>(m_backbuffer_width);
float FloatGLHeight = static_cast<float>(s_backbuffer_height); float FloatGLHeight = static_cast<float>(m_backbuffer_height);
float FloatXOffset = 0; float FloatXOffset = 0;
float FloatYOffset = 0; float FloatYOffset = 0;
@ -584,7 +566,7 @@ void Renderer::UpdateDrawRectangle()
// Check for force-settings and override. // Check for force-settings and override.
// The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio // The rendering window aspect ratio as a proportion of the 4:3 or 16:9 ratio
float Ratio = CalculateDrawAspectRatio(s_backbuffer_width, s_backbuffer_height); float Ratio = CalculateDrawAspectRatio(m_backbuffer_width, m_backbuffer_height);
if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH) if (g_ActiveConfig.iAspectRatio != ASPECT_STRETCH)
{ {
if (Ratio >= 0.995f && Ratio <= 1.005f) if (Ratio >= 0.995f && Ratio <= 1.005f)
@ -638,18 +620,16 @@ void Renderer::UpdateDrawRectangle()
iWhidth % 4; // ensure divisibility by 4 to make it compatible with all the video encoders iWhidth % 4; // ensure divisibility by 4 to make it compatible with all the video encoders
iHeight -= iHeight % 4; iHeight -= iHeight % 4;
target_rc.left = XOffset; m_target_rectangle.left = XOffset;
target_rc.top = YOffset; m_target_rectangle.top = YOffset;
target_rc.right = XOffset + iWhidth; m_target_rectangle.right = XOffset + iWhidth;
target_rc.bottom = YOffset + iHeight; m_target_rectangle.bottom = YOffset + iHeight;
} }
void Renderer::SetWindowSize(int width, int height) void Renderer::SetWindowSize(int width, int height)
{ {
if (width < 1) width = std::max(width, 1);
width = 1; height = std::max(height, 1);
if (height < 1)
height = 1;
// Scale the window size by the EFB scale. // Scale the window size by the EFB scale.
CalculateTargetScale(width, height, &width, &height); CalculateTargetScale(width, height, &width, &height);
@ -686,7 +666,13 @@ void Renderer::SetWindowSize(int width, int height)
width -= width % 4; width -= width % 4;
height -= height % 4; height -= height % 4;
Host_RequestRenderWindowSize(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);
}
} }
void Renderer::CheckFifoRecording() void Renderer::CheckFifoRecording()
@ -728,7 +714,7 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const
// TODO: merge more generic parts into VideoCommon // TODO: merge more generic parts into VideoCommon
g_renderer->SwapImpl(xfbAddr, fbWidth, fbStride, fbHeight, rc, ticks, Gamma); g_renderer->SwapImpl(xfbAddr, fbWidth, fbStride, fbHeight, rc, ticks, Gamma);
if (XFBWrited) if (m_xfb_written)
g_renderer->m_fps_counter.Update(); g_renderer->m_fps_counter.Update();
frameCount++; frameCount++;
@ -739,14 +725,14 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const
// New frame // New frame
stats.ResetFrame(); stats.ResetFrame();
Core::Callback_VideoCopiedToXFB(XFBWrited || Core::Callback_VideoCopiedToXFB(m_xfb_written ||
(g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB)); (g_ActiveConfig.bUseXFB && g_ActiveConfig.bUseRealXFB));
XFBWrited = false; m_xfb_written = false;
} }
bool Renderer::IsFrameDumping() bool Renderer::IsFrameDumping()
{ {
if (s_screenshot.IsSet()) if (m_screenshot_request.IsSet())
return true; return true;
#if defined(HAVE_LIBAV) || defined(_WIN32) #if defined(HAVE_LIBAV) || defined(_WIN32)
@ -827,17 +813,17 @@ void Renderer::RunFrameDumps()
} }
// Save screenshot // Save screenshot
if (s_screenshot.TestAndClear()) if (m_screenshot_request.TestAndClear())
{ {
std::lock_guard<std::mutex> lk(s_criticalScreenshot); std::lock_guard<std::mutex> lk(m_screenshot_lock);
if (TextureToPng(config.data, config.stride, s_sScreenshotName, config.width, config.height, if (TextureToPng(config.data, config.stride, m_screenshot_name, config.width, config.height,
false)) false))
OSD::AddMessage("Screenshot saved to " + s_sScreenshotName); OSD::AddMessage("Screenshot saved to " + m_screenshot_name);
// Reset settings // Reset settings
s_sScreenshotName.clear(); m_screenshot_name.clear();
s_screenshotCompleted.Set(); m_screenshot_completed.Set();
} }
if (SConfig::GetInstance().m_DumpFrames) if (SConfig::GetInstance().m_DumpFrames)

View File

@ -50,7 +50,7 @@ extern int OSDChoice;
class Renderer class Renderer
{ {
public: public:
Renderer(); Renderer(int backbuffer_width, int backbuffer_height);
virtual ~Renderer(); virtual ~Renderer();
enum PixelPerfQuery enum PixelPerfQuery
@ -81,46 +81,46 @@ public:
virtual void RestoreAPIState() {} virtual void RestoreAPIState() {}
// Ideal internal resolution - determined by display resolution (automatic scaling) and/or a // Ideal internal resolution - determined by display resolution (automatic scaling) and/or a
// multiple of the native EFB resolution // multiple of the native EFB resolution
static int GetTargetWidth() { return s_target_width; } int GetTargetWidth() { return m_target_width; }
static int GetTargetHeight() { return s_target_height; } int GetTargetHeight() { return m_target_height; }
// Display resolution // Display resolution
static int GetBackbufferWidth() { return s_backbuffer_width; } int GetBackbufferWidth() { return m_backbuffer_width; }
static int GetBackbufferHeight() { return s_backbuffer_height; } int GetBackbufferHeight() { return m_backbuffer_height; }
static void SetWindowSize(int width, int height); void SetWindowSize(int width, int height);
// EFB coordinate conversion functions // EFB coordinate conversion functions
// Use this to convert a whole native EFB rect to backbuffer coordinates // Use this to convert a whole native EFB rect to backbuffer coordinates
virtual TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) = 0; virtual TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) = 0;
static const TargetRectangle& GetTargetRectangle() { return target_rc; } const TargetRectangle& GetTargetRectangle() { return m_target_rectangle; }
static float CalculateDrawAspectRatio(int target_width, int target_height); float CalculateDrawAspectRatio(int target_width, int target_height);
static std::tuple<float, float> ScaleToDisplayAspectRatio(int width, int height); std::tuple<float, float> ScaleToDisplayAspectRatio(int width, int height);
static TargetRectangle CalculateFrameDumpDrawRectangle(); TargetRectangle CalculateFrameDumpDrawRectangle();
static void UpdateDrawRectangle(); void UpdateDrawRectangle();
// Use this to convert a single target rectangle to two stereo rectangles // Use this to convert a single target rectangle to two stereo rectangles
static void ConvertStereoRectangle(const TargetRectangle& rc, TargetRectangle& leftRc, void ConvertStereoRectangle(const TargetRectangle& rc, TargetRectangle& leftRc,
TargetRectangle& rightRc); TargetRectangle& rightRc);
// Use this to upscale native EFB coordinates to IDEAL internal resolution // Use this to upscale native EFB coordinates to IDEAL internal resolution
static int EFBToScaledX(int x); int EFBToScaledX(int x);
static int EFBToScaledY(int y); int EFBToScaledY(int y);
// Floating point versions of the above - only use them if really necessary // Floating point versions of the above - only use them if really necessary
static float EFBToScaledXf(float x) { return x * ((float)GetTargetWidth() / (float)EFB_WIDTH); } float EFBToScaledXf(float x) { return x * ((float)GetTargetWidth() / (float)EFB_WIDTH); }
static float EFBToScaledYf(float y) { return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT); } float EFBToScaledYf(float y) { return y * ((float)GetTargetHeight() / (float)EFB_HEIGHT); }
// Random utilities // Random utilities
static void SetScreenshot(const std::string& filename); void SaveScreenshot(const std::string& filename, bool wait_for_completion);
static void DrawDebugText(); void DrawDebugText();
virtual void RenderText(const std::string& text, int left, int top, u32 color) = 0; virtual void RenderText(const std::string& text, int left, int top, u32 color) = 0;
virtual void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable, virtual void ClearScreen(const EFBRectangle& rc, bool colorEnable, bool alphaEnable, bool zEnable,
u32 color, u32 z) = 0; u32 color, u32 z) = 0;
virtual void ReinterpretPixelData(unsigned int convtype) = 0; virtual void ReinterpretPixelData(unsigned int convtype) = 0;
static void RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbStride, u32 fbHeight, void RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbStride, u32 fbHeight,
float Gamma = 1.0f); float Gamma = 1.0f);
virtual u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) = 0; virtual u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) = 0;
virtual void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) = 0; virtual void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) = 0;
@ -129,72 +129,71 @@ public:
virtual void BBoxWrite(int index, u16 value) = 0; virtual void BBoxWrite(int index, u16 value) = 0;
// Finish up the current frame, print some stats // Finish up the current frame, print some stats
static void Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, void Swap(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, const EFBRectangle& rc, u64 ticks,
u64 ticks, float Gamma = 1.0f); float Gamma = 1.0f);
virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, virtual void SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight,
const EFBRectangle& rc, u64 ticks, float Gamma = 1.0f) = 0; const EFBRectangle& rc, u64 ticks, float Gamma = 1.0f) = 0;
static PEControl::PixelFormat GetPrevPixelFormat() { return prev_efb_format; } PEControl::PixelFormat GetPrevPixelFormat() { return m_prev_efb_format; }
static void StorePixelFormat(PEControl::PixelFormat new_format) { prev_efb_format = new_format; } void StorePixelFormat(PEControl::PixelFormat new_format) { m_prev_efb_format = new_format; }
PostProcessingShaderImplementation* GetPostProcessor() { return m_post_processor.get(); } PostProcessingShaderImplementation* GetPostProcessor() { return m_post_processor.get(); }
// Max height/width // Max height/width
virtual u32 GetMaxTextureSize() = 0; virtual u32 GetMaxTextureSize() = 0;
static Common::Event s_screenshotCompleted;
// Final surface changing // Final surface changing
// This is called when the surface is resized (WX) or the window changes (Android). // This is called when the surface is resized (WX) or the window changes (Android).
virtual void ChangeSurface(void* new_surface_handle) {} virtual void ChangeSurface(void* new_surface_handle) {}
protected: protected:
static void CalculateTargetScale(int x, int y, int* scaledX, int* scaledY); void CalculateTargetScale(int x, int y, int* scaledX, int* scaledY);
bool CalculateTargetSize(); bool CalculateTargetSize();
static void CheckFifoRecording(); void CheckFifoRecording();
static void RecordVideoMemory(); void RecordVideoMemory();
bool IsFrameDumping(); bool IsFrameDumping();
void DumpFrameData(const u8* data, int w, int h, int stride, const AVIDump::Frame& state, void DumpFrameData(const u8* data, int w, int h, int stride, const AVIDump::Frame& state,
bool swap_upside_down = false); bool swap_upside_down = false);
void FinishFrameData(); void FinishFrameData();
static Common::Flag s_screenshot; Common::Flag m_screenshot_request;
static std::mutex s_criticalScreenshot; Common::Event m_screenshot_completed;
static std::string s_sScreenshotName; std::mutex m_screenshot_lock;
std::string m_screenshot_name;
// The framebuffer size // The framebuffer size
static int s_target_width; int m_target_width = 0;
static int s_target_height; int m_target_height = 0;
// TODO: Add functionality to reinit all the render targets when the window is resized. // TODO: Add functionality to reinit all the render targets when the window is resized.
static int s_backbuffer_width; int m_backbuffer_width = 0;
static int s_backbuffer_height; int m_backbuffer_height = 0;
int m_last_efb_scale = 0;
static TargetRectangle target_rc; TargetRectangle m_target_rectangle;
bool m_xfb_written = false;
// TODO: Can probably eliminate this static var.
static int s_last_efb_scale;
static bool XFBWrited;
FPSCounter m_fps_counter; FPSCounter m_fps_counter;
static std::unique_ptr<PostProcessingShaderImplementation> m_post_processor; std::unique_ptr<PostProcessingShaderImplementation> m_post_processor;
static const float GX_MAX_DEPTH; static const float GX_MAX_DEPTH;
static Common::Flag s_surface_needs_change; Common::Flag m_surface_needs_change;
static Common::Event s_surface_changed; Common::Event m_surface_changed;
static void* s_new_surface_handle; void* m_new_surface_handle = nullptr;
private: private:
void RunFrameDumps(); void RunFrameDumps();
void ShutdownFrameDumping(); void ShutdownFrameDumping();
static PEControl::PixelFormat prev_efb_format; PEControl::PixelFormat m_prev_efb_format = PEControl::INVALID_FMT;
static unsigned int efb_scale_numeratorX; unsigned int m_efb_scale_numeratorX = 1;
static unsigned int efb_scale_numeratorY; unsigned int m_efb_scale_numeratorY = 1;
static unsigned int efb_scale_denominatorX; unsigned int m_efb_scale_denominatorX = 1;
static unsigned int efb_scale_denominatorY; unsigned int m_efb_scale_denominatorY = 1;
// These will be set on the first call to SetWindowSize.
int m_last_window_request_width = 0;
int m_last_window_request_height = 0;
// frame dumping // frame dumping
std::thread m_frame_dump_thread; std::thread m_frame_dump_thread;

View File

@ -385,17 +385,17 @@ TextureCacheBase::DoPartialTextureUpdates(TCacheEntryBase* entry_to_update, u8*
entry->native_height != entry->config.height) entry->native_height != entry->config.height)
{ {
ScaleTextureCacheEntryTo(&entry_to_update, ScaleTextureCacheEntryTo(&entry_to_update,
Renderer::EFBToScaledX(entry_to_update->native_width), g_renderer->EFBToScaledX(entry_to_update->native_width),
Renderer::EFBToScaledY(entry_to_update->native_height)); g_renderer->EFBToScaledY(entry_to_update->native_height));
ScaleTextureCacheEntryTo(&entry, Renderer::EFBToScaledX(entry->native_width), ScaleTextureCacheEntryTo(&entry, g_renderer->EFBToScaledX(entry->native_width),
Renderer::EFBToScaledY(entry->native_height)); g_renderer->EFBToScaledY(entry->native_height));
src_x = Renderer::EFBToScaledX(src_x); src_x = g_renderer->EFBToScaledX(src_x);
src_y = Renderer::EFBToScaledY(src_y); src_y = g_renderer->EFBToScaledY(src_y);
dst_x = Renderer::EFBToScaledX(dst_x); dst_x = g_renderer->EFBToScaledX(dst_x);
dst_y = Renderer::EFBToScaledY(dst_y); dst_y = g_renderer->EFBToScaledY(dst_y);
copy_width = Renderer::EFBToScaledX(copy_width); copy_width = g_renderer->EFBToScaledX(copy_width);
copy_height = Renderer::EFBToScaledY(copy_height); copy_height = g_renderer->EFBToScaledY(copy_height);
} }
MathUtil::Rectangle<int> srcrect, dstrect; MathUtil::Rectangle<int> srcrect, dstrect;
@ -1197,8 +1197,10 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFo
const unsigned int tex_w = scaleByHalf ? srcRect.GetWidth() / 2 : srcRect.GetWidth(); const unsigned int tex_w = scaleByHalf ? srcRect.GetWidth() / 2 : srcRect.GetWidth();
const unsigned int tex_h = scaleByHalf ? srcRect.GetHeight() / 2 : srcRect.GetHeight(); const unsigned int tex_h = scaleByHalf ? srcRect.GetHeight() / 2 : srcRect.GetHeight();
unsigned int scaled_tex_w = g_ActiveConfig.bCopyEFBScaled ? Renderer::EFBToScaledX(tex_w) : tex_w; unsigned int scaled_tex_w =
unsigned int scaled_tex_h = g_ActiveConfig.bCopyEFBScaled ? Renderer::EFBToScaledY(tex_h) : tex_h; g_ActiveConfig.bCopyEFBScaled ? g_renderer->EFBToScaledX(tex_w) : tex_w;
unsigned int scaled_tex_h =
g_ActiveConfig.bCopyEFBScaled ? g_renderer->EFBToScaledY(tex_h) : tex_h;
// Remove all texture cache entries at dstAddr // Remove all texture cache entries at dstAddr
// It's not possible to have two EFB copies at the same address, this makes sure any old efb // It's not possible to have two EFB copies at the same address, this makes sure any old efb

View File

@ -382,8 +382,8 @@ void VertexShaderManager::SetConstants()
// NOTE: If we ever emulate antialiasing, the sample locations set by // NOTE: If we ever emulate antialiasing, the sample locations set by
// BP registers 0x01-0x04 need to be considered here. // BP registers 0x01-0x04 need to be considered here.
const float pixel_center_correction = 7.0f / 12.0f - 0.5f; const float pixel_center_correction = 7.0f / 12.0f - 0.5f;
const float pixel_size_x = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.wd); const float pixel_size_x = 2.f / g_renderer->EFBToScaledXf(2.f * xfmem.viewport.wd);
const float pixel_size_y = 2.f / Renderer::EFBToScaledXf(2.f * xfmem.viewport.ht); const float pixel_size_y = 2.f / g_renderer->EFBToScaledXf(2.f * xfmem.viewport.ht);
constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x; constants.pixelcentercorrection[0] = pixel_center_correction * pixel_size_x;
constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y; constants.pixelcentercorrection[1] = pixel_center_correction * pixel_size_y;