GPU/HW: Implement automatic resolution scale from window size

This commit is contained in:
Connor McLaughlin 2020-08-03 03:06:03 +10:00
parent 94777a15cd
commit 9b7512f7b8
6 changed files with 51 additions and 13 deletions

View File

@ -57,6 +57,8 @@ void GPU::UpdateSettings()
UpdateCRTCDisplayParameters();
}
void GPU::UpdateResolutionScale() {}
void GPU::Reset()
{
SoftReset();

View File

@ -154,12 +154,15 @@ public:
/// Returns true if a raster scanline or command execution is pending.
bool IsCommandCompletionPending() const;
// Synchronizes the CRTC, updating the hblank timer.
/// Synchronizes the CRTC, updating the hblank timer.
void SynchronizeCRTC();
// Recompile shaders/recreate framebuffers when needed.
/// Recompile shaders/recreate framebuffers when needed.
virtual void UpdateSettings();
/// Updates the resolution scale when it's set to automatic.
virtual void UpdateResolutionScale();
// gpu_hw_d3d11.cpp
static std::unique_ptr<GPU> CreateHardwareD3D11Renderer();

View File

@ -7,8 +7,8 @@
#include "pgxp.h"
#include "settings.h"
#include "system.h"
#include <sstream>
#include <cmath>
#include <sstream>
#include <tuple>
Log_SetChannel(GPU_HW);
@ -38,18 +38,11 @@ bool GPU_HW::Initialize(HostDisplay* host_display)
if (!GPU::Initialize(host_display))
return false;
m_resolution_scale = g_settings.gpu_resolution_scale;
m_resolution_scale = CalculateResolutionScale();
m_render_api = host_display->GetRenderAPI();
m_true_color = g_settings.gpu_true_color;
m_scaled_dithering = g_settings.gpu_scaled_dithering;
m_texture_filtering = g_settings.gpu_texture_filtering;
if (m_resolution_scale < 1 || m_resolution_scale > m_max_resolution_scale)
{
g_host_interface->AddFormattedOSDMessage(5.0f, "Invalid resolution scale %ux specified. Maximum is %u.",
m_resolution_scale, m_max_resolution_scale);
m_resolution_scale = std::clamp<u32>(m_resolution_scale, 1u, m_max_resolution_scale);
}
PrintSettingsToLog();
return true;
}
@ -90,13 +83,35 @@ void GPU_HW::UpdateSettings()
{
GPU::UpdateSettings();
m_resolution_scale = std::clamp<u32>(g_settings.gpu_resolution_scale, 1, m_max_resolution_scale);
m_resolution_scale = CalculateResolutionScale();
m_true_color = g_settings.gpu_true_color;
m_scaled_dithering = g_settings.gpu_scaled_dithering;
m_texture_filtering = g_settings.gpu_texture_filtering;
PrintSettingsToLog();
}
u32 GPU_HW::CalculateResolutionScale() const
{
if (g_settings.gpu_resolution_scale != 0)
return std::clamp<u32>(g_settings.gpu_resolution_scale, 1, m_max_resolution_scale);
// auto scaling
const s32 height = (m_crtc_state.display_height != 0) ? static_cast<s32>(m_crtc_state.display_height) : 480;
const s32 preferred_scale =
static_cast<s32>(std::ceil(static_cast<float>(m_host_display->GetWindowHeight()) / height));
Log_InfoPrintf("Height = %d, preferred scale = %d", height, preferred_scale);
return static_cast<u32>(std::clamp<s32>(preferred_scale, 1, m_max_resolution_scale));
}
void GPU_HW::UpdateResolutionScale()
{
GPU::UpdateResolutionScale();
if (CalculateResolutionScale() != m_resolution_scale)
UpdateSettings();
}
void GPU_HW::PrintSettingsToLog()
{
Log_InfoPrintf("Resolution Scale: %u (%ux%u), maximum %u", m_resolution_scale, VRAM_WIDTH * m_resolution_scale,

View File

@ -35,6 +35,7 @@ public:
virtual void Reset() override;
virtual bool DoState(StateWrapper& sw) override;
virtual void UpdateSettings() override;
virtual void UpdateResolutionScale() override;
protected:
enum : u32
@ -167,6 +168,8 @@ protected:
virtual void UploadUniformBuffer(const void* uniforms, u32 uniforms_size) = 0;
virtual void DrawBatchVertices(BatchRenderMode render_mode, u32 base_vertex, u32 num_vertices) = 0;
u32 CalculateResolutionScale() const;
void SetFullVRAMDirtyRectangle()
{
m_vram_dirty_rect.Set(0, 0, VRAM_WIDTH, VRAM_HEIGHT);

View File

@ -425,7 +425,10 @@ void QtHostInterface::onHostDisplayWindowResized(int width, int height)
// re-render the display, since otherwise it will be out of date and stretched if paused
if (!System::IsShutdown())
{
g_gpu->UpdateResolutionScale();
renderDisplay();
}
}
void QtHostInterface::redrawDisplayWindow()
@ -538,7 +541,12 @@ void QtHostInterface::updateDisplayState()
Panic("Failed to make device context current after updating");
connectDisplaySignals(display_widget);
redrawDisplayWindow();
if (!System::IsShutdown())
{
g_gpu->UpdateResolutionScale();
redrawDisplayWindow();
}
UpdateSpeedLimiterState();
}

View File

@ -370,6 +370,10 @@ bool SDLHostInterface::SetFullscreen(bool enabled)
int window_width, window_height;
SDL_GetWindowSize(m_window, &window_width, &window_height);
m_display->ResizeRenderWindow(window_width, window_height);
if (!System::IsShutdown())
g_gpu->UpdateResolutionScale();
m_fullscreen = enabled;
return true;
}
@ -523,6 +527,9 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
{
m_display->ResizeRenderWindow(event->window.data1, event->window.data2);
UpdateFramebufferScale();
if (!System::IsShutdown())
g_gpu->UpdateResolutionScale();
}
else if (event->window.event == SDL_WINDOWEVENT_MOVED)
{