Merge pull request #4315 from stenzek/vulkan-aspect

Vulkan: Handle forced aspect ratio changes at runtime
This commit is contained in:
Markus Wick 2016-10-08 11:53:22 +02:00 committed by GitHub
commit 6e8901de17
1 changed files with 41 additions and 30 deletions

View File

@ -872,49 +872,63 @@ void Renderer::CheckForSurfaceChange()
void Renderer::CheckForConfigChanges() void Renderer::CheckForConfigChanges()
{ {
// Compare g_Config to g_ActiveConfig to determine what has changed before copying. // Save the video config so we can compare against to determine which settings have changed.
bool msaa_changed = (g_Config.iMultisamples != g_ActiveConfig.iMultisamples); int old_multisamples = g_ActiveConfig.iMultisamples;
bool ssaa_changed = (g_Config.bSSAA != g_ActiveConfig.bSSAA); int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
bool anisotropy_changed = (g_Config.iMaxAnisotropy != g_ActiveConfig.iMaxAnisotropy); int old_stereo_mode = g_ActiveConfig.iStereoMode;
bool force_texture_filtering_changed = int old_aspect_ratio = g_ActiveConfig.iAspectRatio;
(g_Config.bForceFiltering != g_ActiveConfig.bForceFiltering); bool old_force_filtering = g_ActiveConfig.bForceFiltering;
bool stereo_changed = (g_Config.iStereoMode != g_ActiveConfig.iStereoMode); bool old_ssaa = g_ActiveConfig.bSSAA;
// Copy g_Config to g_ActiveConfig. // Copy g_Config to g_ActiveConfig.
// NOTE: This can potentially race with the UI thread, however if it does, the changes will be
// delayed until the next time CheckForConfigChanges is called.
UpdateActiveConfig(); UpdateActiveConfig();
// Determine which (if any) settings have changed.
bool msaa_changed = old_multisamples != g_ActiveConfig.iMultisamples;
bool ssaa_changed = old_ssaa != g_ActiveConfig.bSSAA;
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 = s_last_efb_scale != g_ActiveConfig.iEFBScale;
bool aspect_changed = old_aspect_ratio != g_ActiveConfig.iAspectRatio;
// Update texture cache settings with any changed options. // Update texture cache settings with any changed options.
TextureCache::OnConfigChanged(g_ActiveConfig); TextureCache::OnConfigChanged(g_ActiveConfig);
// MSAA samples changed, we need to recreate the EFB render pass, and all shaders.
if (msaa_changed)
{
m_framebuffer_mgr->RecreateRenderPass();
m_framebuffer_mgr->ResizeEFBTextures();
}
// SSAA changed on/off, we can leave the buffers/render pass, but have to recompile shaders.
if (msaa_changed || ssaa_changed)
{
BindEFBToStateTracker();
m_framebuffer_mgr->RecompileShaders();
g_object_cache->ClearPipelineCache();
}
// Handle internal resolution changes. // Handle internal resolution changes.
if (s_last_efb_scale != g_ActiveConfig.iEFBScale) if (efb_scale_changed)
{
s_last_efb_scale = g_ActiveConfig.iEFBScale; s_last_efb_scale = g_ActiveConfig.iEFBScale;
// If the aspect ratio is changed, this changes the area that the game is drawn to.
if (aspect_changed)
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);
if (efb_scale_changed || aspect_changed)
{
if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height)) if (CalculateTargetSize(s_backbuffer_width, s_backbuffer_height))
ResizeEFBTextures(); ResizeEFBTextures();
} }
// Handle stereoscopy mode changes. // MSAA samples changed, we need to recreate the EFB render pass.
if (stereo_changed) // If the stereoscopy mode changed, we need to recreate the buffers as well.
if (msaa_changed || stereo_changed)
{ {
ResizeEFBTextures(); g_command_buffer_mgr->WaitForGPUIdle();
m_framebuffer_mgr->RecreateRenderPass();
m_framebuffer_mgr->ResizeEFBTextures();
BindEFBToStateTracker(); BindEFBToStateTracker();
}
// SSAA changed on/off, we can leave the buffers/render pass, but have to recompile shaders.
// Changing stereoscopy from off<->on also requires shaders to be recompiled.
if (msaa_changed || ssaa_changed || stereo_changed)
{
g_command_buffer_mgr->WaitForGPUIdle();
RecompileShaders(); RecompileShaders();
m_framebuffer_mgr->RecompileShaders();
g_object_cache->ClearPipelineCache();
} }
// For vsync, we need to change the present mode, which means recreating the swap chain. // For vsync, we need to change the present mode, which means recreating the swap chain.
@ -962,10 +976,7 @@ void Renderer::ResizeEFBTextures()
{ {
// Ensure the GPU is finished with the current EFB textures. // Ensure the GPU is finished with the current EFB textures.
g_command_buffer_mgr->WaitForGPUIdle(); g_command_buffer_mgr->WaitForGPUIdle();
m_framebuffer_mgr->ResizeEFBTextures(); m_framebuffer_mgr->ResizeEFBTextures();
s_last_efb_scale = g_ActiveConfig.iEFBScale;
BindEFBToStateTracker(); BindEFBToStateTracker();
// Viewport and scissor rect have to be reset since they will be scaled differently. // Viewport and scissor rect have to be reset since they will be scaled differently.