From 00a0a91513fbb52362fc7d3a7db6450d66c4c68a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 4 Mar 2017 16:42:27 +1000 Subject: [PATCH] VideoCommon: Move last EFB scale handling to CalculateTargetSize --- Source/Core/VideoBackends/D3D/Render.cpp | 4 ---- Source/Core/VideoBackends/D3D/main.cpp | 1 - Source/Core/VideoBackends/D3D12/Render.cpp | 4 ---- Source/Core/VideoBackends/D3D12/main.cpp | 1 - Source/Core/VideoBackends/Null/NullBackend.cpp | 1 - Source/Core/VideoBackends/OGL/Render.cpp | 8 +------- Source/Core/VideoBackends/Software/SWmain.cpp | 1 - Source/Core/VideoBackends/Vulkan/Renderer.cpp | 10 ++-------- Source/Core/VideoCommon/PixelShaderManager.cpp | 8 ++++---- Source/Core/VideoCommon/PixelShaderManager.h | 2 +- Source/Core/VideoCommon/RenderBase.cpp | 8 +++----- Source/Core/VideoCommon/RenderBase.h | 4 ---- 12 files changed, 11 insertions(+), 41 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index f3bc191d9e..884b9db544 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -865,7 +865,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, // Resize the back buffers NOW to avoid flickering if (CalculateTargetSize() || xfbchanged || windowResized || - m_last_efb_scale != g_ActiveConfig.iEFBScale || s_last_multisamples != g_ActiveConfig.iMultisamples || s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)) { @@ -885,11 +884,8 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, UpdateDrawRectangle(); - m_last_efb_scale = g_ActiveConfig.iEFBScale; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; - PixelShaderManager::SetEfbScaleChanged(); - D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), nullptr); g_framebuffer_manager.reset(); diff --git a/Source/Core/VideoBackends/D3D/main.cpp b/Source/Core/VideoBackends/D3D/main.cpp index 6b0e23ef1f..1fe55046ed 100644 --- a/Source/Core/VideoBackends/D3D/main.cpp +++ b/Source/Core/VideoBackends/D3D/main.cpp @@ -153,7 +153,6 @@ void VideoBackend::Video_Prepare() g_texture_cache = std::make_unique(); g_vertex_manager = std::make_unique(); g_perf_query = std::make_unique(); - g_renderer->InitializeCommon(); VertexShaderCache::Init(); PixelShaderCache::Init(); GeometryShaderCache::Init(); diff --git a/Source/Core/VideoBackends/D3D12/Render.cpp b/Source/Core/VideoBackends/D3D12/Render.cpp index 80ae8711d0..572660a06f 100644 --- a/Source/Core/VideoBackends/D3D12/Render.cpp +++ b/Source/Core/VideoBackends/D3D12/Render.cpp @@ -821,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 if (CalculateTargetSize() || xfb_changed || window_resized || - m_last_efb_scale != g_ActiveConfig.iEFBScale || s_last_multisamples != g_ActiveConfig.iMultisamples || s_last_stereo_mode != (g_ActiveConfig.iStereoMode > 0)) { @@ -854,11 +853,8 @@ void Renderer::SwapImpl(u32 xfb_addr, u32 fb_width, u32 fb_stride, u32 fb_height UpdateDrawRectangle(); - m_last_efb_scale = g_ActiveConfig.iEFBScale; s_last_stereo_mode = g_ActiveConfig.iStereoMode > 0; - PixelShaderManager::SetEfbScaleChanged(); - D3D::GetBackBuffer()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET); D3D::current_command_list->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV12(), FALSE, diff --git a/Source/Core/VideoBackends/D3D12/main.cpp b/Source/Core/VideoBackends/D3D12/main.cpp index f6a2347e40..7c31537d8a 100644 --- a/Source/Core/VideoBackends/D3D12/main.cpp +++ b/Source/Core/VideoBackends/D3D12/main.cpp @@ -168,7 +168,6 @@ void VideoBackend::Video_Prepare() g_vertex_manager = std::make_unique(); g_perf_query = std::make_unique(); g_xfb_encoder = std::make_unique(); - g_renderer->InitializeCommon(); ShaderCache::Init(); ShaderConstantsManager::Init(); StaticShaderCache::Init(); diff --git a/Source/Core/VideoBackends/Null/NullBackend.cpp b/Source/Core/VideoBackends/Null/NullBackend.cpp index f0d073db71..1e3117088e 100644 --- a/Source/Core/VideoBackends/Null/NullBackend.cpp +++ b/Source/Core/VideoBackends/Null/NullBackend.cpp @@ -67,7 +67,6 @@ void VideoBackend::Video_Prepare() g_perf_query = std::make_unique(); g_framebuffer_manager = std::make_unique(); g_texture_cache = std::make_unique(); - g_renderer->InitializeCommon(); VertexShaderCache::s_instance = std::make_unique(); GeometryShaderCache::s_instance = std::make_unique(); PixelShaderCache::s_instance = std::make_unique(); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 83141d4a96..1c03c30226 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -773,8 +773,6 @@ void Renderer::Shutdown() void Renderer::Init() { - InitializeCommon(); - // Initialize the FramebufferManager g_framebuffer_manager = std::make_unique(m_target_width, m_target_height, s_MSAASamples); @@ -1353,13 +1351,11 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, bool window_resized = false; int window_width = static_cast(std::max(GLInterface->GetBackBufferWidth(), 1u)); int window_height = static_cast(std::max(GLInterface->GetBackBufferHeight(), 1u)); - if (window_width != m_backbuffer_width || window_height != m_backbuffer_height || - m_last_efb_scale != g_ActiveConfig.iEFBScale) + if (window_width != m_backbuffer_width || window_height != m_backbuffer_height) { window_resized = true; m_backbuffer_width = window_width; m_backbuffer_height = window_height; - m_last_efb_scale = g_ActiveConfig.iEFBScale; } bool target_size_changed = CalculateTargetSize(); @@ -1390,8 +1386,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight, g_framebuffer_manager.reset(); g_framebuffer_manager = std::make_unique(m_target_width, m_target_height, s_MSAASamples); - - PixelShaderManager::SetEfbScaleChanged(); } } diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index 11ddad99b4..adbe5046b6 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -181,7 +181,6 @@ void VideoSoftware::Video_Prepare() g_vertex_manager = std::make_unique(); g_perf_query = std::make_unique(); g_texture_cache = std::make_unique(); - g_renderer->InitializeCommon(); SWRenderer::Init(); g_framebuffer_manager = std::make_unique(); } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index f76247a7b8..d44317b3de 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -1012,10 +1012,7 @@ void Renderer::CheckForTargetResize(u32 fb_width, u32 fb_stride, u32 fb_height) // Changing the XFB source area may alter the target size. if (CalculateTargetSize()) - { - PixelShaderManager::SetEfbScaleChanged(); ResizeEFBTextures(); - } } void Renderer::CheckForSurfaceChange() @@ -1095,6 +1092,7 @@ void Renderer::CheckForConfigChanges() int old_anisotropy = g_ActiveConfig.iMaxAnisotropy; int old_stereo_mode = g_ActiveConfig.iStereoMode; int old_aspect_ratio = g_ActiveConfig.iAspectRatio; + int old_efb_scale = g_ActiveConfig.iEFBScale; bool old_force_filtering = g_ActiveConfig.bForceFiltering; bool old_ssaa = g_ActiveConfig.bSSAA; bool old_use_xfb = g_ActiveConfig.bUseXFB; @@ -1111,7 +1109,7 @@ void Renderer::CheckForConfigChanges() bool anisotropy_changed = old_anisotropy != g_ActiveConfig.iMaxAnisotropy; bool force_texture_filtering_changed = old_force_filtering != g_ActiveConfig.bForceFiltering; bool stereo_changed = old_stereo_mode != g_ActiveConfig.iStereoMode; - bool efb_scale_changed = m_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 use_xfb_changed = old_use_xfb != g_ActiveConfig.bUseXFB; bool use_realxfb_changed = old_use_realxfb != g_ActiveConfig.bUseRealXFB; @@ -1122,7 +1120,6 @@ void Renderer::CheckForConfigChanges() // Handle settings that can cause the target rectangle to change. if (efb_scale_changed || aspect_changed || use_xfb_changed || use_realxfb_changed) { - m_last_efb_scale = g_ActiveConfig.iEFBScale; if (CalculateTargetSize()) ResizeEFBTextures(); } @@ -1166,10 +1163,7 @@ void Renderer::OnSwapChainResized() m_backbuffer_height = m_swap_chain->GetHeight(); UpdateDrawRectangle(); if (CalculateTargetSize()) - { - PixelShaderManager::SetEfbScaleChanged(); ResizeEFBTextures(); - } } void Renderer::BindEFBToStateTracker() diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index c9e102ab5b..c5a23a22c7 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -49,7 +49,7 @@ void PixelShaderManager::Dirty() // Any constants that can changed based on settings should be re-calculated s_bFogRangeAdjustChanged = true; - SetEfbScaleChanged(); + SetEfbScaleChanged(g_renderer->EFBToScaledXf(1), g_renderer->EFBToScaledYf(1)); SetFogParamChanged(); dirty = true; @@ -159,10 +159,10 @@ void PixelShaderManager::SetViewportChanged() 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 / g_renderer->EFBToScaledXf(1); - constants.efbscale[1] = 1.0f / g_renderer->EFBToScaledYf(1); + constants.efbscale[0] = 1.0f / scalex; + constants.efbscale[1] = 1.0f / scaley; dirty = true; } diff --git a/Source/Core/VideoCommon/PixelShaderManager.h b/Source/Core/VideoCommon/PixelShaderManager.h index fe57fd4655..c7d6e3b9ee 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.h +++ b/Source/Core/VideoCommon/PixelShaderManager.h @@ -29,7 +29,7 @@ public: static void SetTexDims(int texmapid, u32 width, u32 height); static void SetZTextureBias(); static void SetViewportChanged(); - static void SetEfbScaleChanged(); + static void SetEfbScaleChanged(float scalex, float scaley); static void SetZSlope(float dfdx, float dfdy, float f0); static void SetIndMatrixChanged(int matrixidx); static void SetZTextureTypeChanged(); diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index fc93f45896..784a294785 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -166,6 +166,8 @@ bool Renderer::CalculateTargetSize() int newEFBWidth, newEFBHeight; newEFBWidth = newEFBHeight = 0; + m_last_efb_scale = g_ActiveConfig.iEFBScale; + // TODO: Ugly. Clean up switch (m_last_efb_scale) { @@ -231,6 +233,7 @@ bool Renderer::CalculateTargetSize() { m_target_width = newEFBWidth; m_target_height = newEFBHeight; + PixelShaderManager::SetEfbScaleChanged(EFBToScaledXf(1), EFBToScaledYf(1)); return true; } return false; @@ -614,11 +617,6 @@ void Renderer::UpdateDrawRectangle() m_target_rectangle.bottom = YOffset + iHeight; } -void Renderer::InitializeCommon() -{ - PixelShaderManager::SetEfbScaleChanged(); -} - void Renderer::SetWindowSize(int width, int height) { if (width < 1) diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 92ebade7db..3afa8761d4 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -79,10 +79,6 @@ public: virtual void RestoreState() {} virtual void ResetAPIState() {} virtual void RestoreAPIState() {} - // Some of the methods called by here assume g_renderer is initialized, therefore - // we must call it after constructing the backend's Renderer instance. - void InitializeCommon(); - // Ideal internal resolution - determined by display resolution (automatic scaling) and/or a // multiple of the native EFB resolution int GetTargetWidth() { return m_target_width; }