mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
GPU/HW: Implement automatic resolution scale from window size
This commit is contained in:
parent
94777a15cd
commit
9b7512f7b8
|
@ -57,6 +57,8 @@ void GPU::UpdateSettings()
|
||||||
UpdateCRTCDisplayParameters();
|
UpdateCRTCDisplayParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPU::UpdateResolutionScale() {}
|
||||||
|
|
||||||
void GPU::Reset()
|
void GPU::Reset()
|
||||||
{
|
{
|
||||||
SoftReset();
|
SoftReset();
|
||||||
|
|
|
@ -154,12 +154,15 @@ public:
|
||||||
/// Returns true if a raster scanline or command execution is pending.
|
/// Returns true if a raster scanline or command execution is pending.
|
||||||
bool IsCommandCompletionPending() const;
|
bool IsCommandCompletionPending() const;
|
||||||
|
|
||||||
// Synchronizes the CRTC, updating the hblank timer.
|
/// Synchronizes the CRTC, updating the hblank timer.
|
||||||
void SynchronizeCRTC();
|
void SynchronizeCRTC();
|
||||||
|
|
||||||
// Recompile shaders/recreate framebuffers when needed.
|
/// Recompile shaders/recreate framebuffers when needed.
|
||||||
virtual void UpdateSettings();
|
virtual void UpdateSettings();
|
||||||
|
|
||||||
|
/// Updates the resolution scale when it's set to automatic.
|
||||||
|
virtual void UpdateResolutionScale();
|
||||||
|
|
||||||
// gpu_hw_d3d11.cpp
|
// gpu_hw_d3d11.cpp
|
||||||
static std::unique_ptr<GPU> CreateHardwareD3D11Renderer();
|
static std::unique_ptr<GPU> CreateHardwareD3D11Renderer();
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#include "pgxp.h"
|
#include "pgxp.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include <sstream>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <sstream>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
Log_SetChannel(GPU_HW);
|
Log_SetChannel(GPU_HW);
|
||||||
|
|
||||||
|
@ -38,18 +38,11 @@ bool GPU_HW::Initialize(HostDisplay* host_display)
|
||||||
if (!GPU::Initialize(host_display))
|
if (!GPU::Initialize(host_display))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_resolution_scale = g_settings.gpu_resolution_scale;
|
m_resolution_scale = CalculateResolutionScale();
|
||||||
m_render_api = host_display->GetRenderAPI();
|
m_render_api = host_display->GetRenderAPI();
|
||||||
m_true_color = g_settings.gpu_true_color;
|
m_true_color = g_settings.gpu_true_color;
|
||||||
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
||||||
m_texture_filtering = g_settings.gpu_texture_filtering;
|
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();
|
PrintSettingsToLog();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -90,13 +83,35 @@ void GPU_HW::UpdateSettings()
|
||||||
{
|
{
|
||||||
GPU::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_true_color = g_settings.gpu_true_color;
|
||||||
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
||||||
m_texture_filtering = g_settings.gpu_texture_filtering;
|
m_texture_filtering = g_settings.gpu_texture_filtering;
|
||||||
PrintSettingsToLog();
|
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()
|
void GPU_HW::PrintSettingsToLog()
|
||||||
{
|
{
|
||||||
Log_InfoPrintf("Resolution Scale: %u (%ux%u), maximum %u", m_resolution_scale, VRAM_WIDTH * m_resolution_scale,
|
Log_InfoPrintf("Resolution Scale: %u (%ux%u), maximum %u", m_resolution_scale, VRAM_WIDTH * m_resolution_scale,
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
virtual bool DoState(StateWrapper& sw) override;
|
virtual bool DoState(StateWrapper& sw) override;
|
||||||
virtual void UpdateSettings() override;
|
virtual void UpdateSettings() override;
|
||||||
|
virtual void UpdateResolutionScale() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum : u32
|
enum : u32
|
||||||
|
@ -167,6 +168,8 @@ protected:
|
||||||
virtual void UploadUniformBuffer(const void* uniforms, u32 uniforms_size) = 0;
|
virtual void UploadUniformBuffer(const void* uniforms, u32 uniforms_size) = 0;
|
||||||
virtual void DrawBatchVertices(BatchRenderMode render_mode, u32 base_vertex, u32 num_vertices) = 0;
|
virtual void DrawBatchVertices(BatchRenderMode render_mode, u32 base_vertex, u32 num_vertices) = 0;
|
||||||
|
|
||||||
|
u32 CalculateResolutionScale() const;
|
||||||
|
|
||||||
void SetFullVRAMDirtyRectangle()
|
void SetFullVRAMDirtyRectangle()
|
||||||
{
|
{
|
||||||
m_vram_dirty_rect.Set(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
m_vram_dirty_rect.Set(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
||||||
|
|
|
@ -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
|
// re-render the display, since otherwise it will be out of date and stretched if paused
|
||||||
if (!System::IsShutdown())
|
if (!System::IsShutdown())
|
||||||
|
{
|
||||||
|
g_gpu->UpdateResolutionScale();
|
||||||
renderDisplay();
|
renderDisplay();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtHostInterface::redrawDisplayWindow()
|
void QtHostInterface::redrawDisplayWindow()
|
||||||
|
@ -538,7 +541,12 @@ void QtHostInterface::updateDisplayState()
|
||||||
Panic("Failed to make device context current after updating");
|
Panic("Failed to make device context current after updating");
|
||||||
|
|
||||||
connectDisplaySignals(display_widget);
|
connectDisplaySignals(display_widget);
|
||||||
redrawDisplayWindow();
|
|
||||||
|
if (!System::IsShutdown())
|
||||||
|
{
|
||||||
|
g_gpu->UpdateResolutionScale();
|
||||||
|
redrawDisplayWindow();
|
||||||
|
}
|
||||||
UpdateSpeedLimiterState();
|
UpdateSpeedLimiterState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,10 @@ bool SDLHostInterface::SetFullscreen(bool enabled)
|
||||||
int window_width, window_height;
|
int window_width, window_height;
|
||||||
SDL_GetWindowSize(m_window, &window_width, &window_height);
|
SDL_GetWindowSize(m_window, &window_width, &window_height);
|
||||||
m_display->ResizeRenderWindow(window_width, window_height);
|
m_display->ResizeRenderWindow(window_width, window_height);
|
||||||
|
|
||||||
|
if (!System::IsShutdown())
|
||||||
|
g_gpu->UpdateResolutionScale();
|
||||||
|
|
||||||
m_fullscreen = enabled;
|
m_fullscreen = enabled;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -523,6 +527,9 @@ void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
|
||||||
{
|
{
|
||||||
m_display->ResizeRenderWindow(event->window.data1, event->window.data2);
|
m_display->ResizeRenderWindow(event->window.data1, event->window.data2);
|
||||||
UpdateFramebufferScale();
|
UpdateFramebufferScale();
|
||||||
|
|
||||||
|
if (!System::IsShutdown())
|
||||||
|
g_gpu->UpdateResolutionScale();
|
||||||
}
|
}
|
||||||
else if (event->window.event == SDL_WINDOWEVENT_MOVED)
|
else if (event->window.event == SDL_WINDOWEVENT_MOVED)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue