From e6be0532cba2dfc9519b5bc24e5bbf2205267a26 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 18 Dec 2023 20:36:07 +1000 Subject: [PATCH] System: Fix incorrect rewind VRAM estimation --- src/core/fullscreen_ui.cpp | 3 ++- src/core/system.cpp | 7 ++++--- src/core/system.h | 2 +- src/duckstation-qt/emulationsettingswidget.cpp | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 3324e4fbf..3d064422c 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -3155,6 +3155,7 @@ void FullscreenUI::DrawEmulationSettingsPage() } else if (rewind_enabled) { + const u32 resolution_scale = GetEffectiveUIntSetting(bsi, "GPU", "ResolutionScale", 1); const float rewind_frequency = GetEffectiveFloatSetting(bsi, "Main", "RewindFrequency", 10.0f); const s32 rewind_save_slots = GetEffectiveIntSetting(bsi, "Main", "RewindSaveSlots", 10); const float duration = @@ -3162,7 +3163,7 @@ void FullscreenUI::DrawEmulationSettingsPage() static_cast(rewind_save_slots); u64 ram_usage, vram_usage; - System::CalculateRewindMemoryUsage(rewind_save_slots, &ram_usage, &vram_usage); + System::CalculateRewindMemoryUsage(rewind_save_slots, resolution_scale, &ram_usage, &vram_usage); rewind_summary.format( FSUI_FSTR("Rewind for {0} frames, lasting {1:.2f} seconds will require up to {2} MB of RAM and {3} MB of VRAM."), rewind_save_slots, duration, ram_usage / 1048576, vram_usage / 1048576); diff --git a/src/core/system.cpp b/src/core/system.cpp index 82e9c12f8..3762ae6bc 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -3844,10 +3844,11 @@ void System::LogUnsafeSettingsToConsole(const std::string& messages) Log_WarningPrint(console_messages.c_str()); } -void System::CalculateRewindMemoryUsage(u32 num_saves, u64* ram_usage, u64* vram_usage) +void System::CalculateRewindMemoryUsage(u32 num_saves, u32 resolution_scale, u64* ram_usage, u64* vram_usage) { + const u64 real_resolution_scale = static_cast(std::max(g_settings.gpu_resolution_scale, 1u)); *ram_usage = MAX_SAVE_STATE_SIZE * static_cast(num_saves); - *vram_usage = (VRAM_WIDTH * VRAM_HEIGHT * 4) * static_cast(std::max(g_settings.gpu_resolution_scale, 1u)) * + *vram_usage = ((VRAM_WIDTH * real_resolution_scale) * (VRAM_HEIGHT * real_resolution_scale) * 4) * static_cast(g_settings.gpu_multisamples) * static_cast(num_saves); } @@ -3869,7 +3870,7 @@ void System::UpdateMemorySaveStateSettings() s_rewind_save_counter = 0; u64 ram_usage, vram_usage; - CalculateRewindMemoryUsage(g_settings.rewind_save_slots, &ram_usage, &vram_usage); + CalculateRewindMemoryUsage(g_settings.rewind_save_slots, g_settings.gpu_resolution_scale, &ram_usage, &vram_usage); Log_InfoPrintf( "Rewind is enabled, saving every %d frames, with %u slots and %" PRIu64 "MB RAM and %" PRIu64 "MB VRAM usage", std::max(s_rewind_save_frequency, 1), g_settings.rewind_save_slots, ram_usage / 1048576, vram_usage / 1048576); diff --git a/src/core/system.h b/src/core/system.h index c8fe75e2e..12b9de398 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -472,7 +472,7 @@ void InvalidateDisplay(); ////////////////////////////////////////////////////////////////////////// // Memory Save States (Rewind and Runahead) ////////////////////////////////////////////////////////////////////////// -void CalculateRewindMemoryUsage(u32 num_saves, u64* ram_usage, u64* vram_usage); +void CalculateRewindMemoryUsage(u32 num_saves, u32 resolution_scale, u64* ram_usage, u64* vram_usage); void ClearMemorySaveStates(); void UpdateMemorySaveStateSettings(); bool LoadRewindState(u32 skip_saves = 0, bool consume_state = true); diff --git a/src/duckstation-qt/emulationsettingswidget.cpp b/src/duckstation-qt/emulationsettingswidget.cpp index 55e00b950..447ed3480 100644 --- a/src/duckstation-qt/emulationsettingswidget.cpp +++ b/src/duckstation-qt/emulationsettingswidget.cpp @@ -183,13 +183,14 @@ void EmulationSettingsWidget::updateRewind() if (!runahead_enabled && rewind_enabled) { + const u32 resolution_scale = static_cast(m_dialog->getEffectiveIntValue("GPU", "ResolutionScale", 1)); const u32 frames = static_cast(m_ui.rewindSaveSlots->value()); const float frequency = static_cast(m_ui.rewindSaveFrequency->value()); const float duration = ((frequency <= std::numeric_limits::epsilon()) ? (1.0f / 60.0f) : frequency) * static_cast(frames); u64 ram_usage, vram_usage; - System::CalculateRewindMemoryUsage(frames, &ram_usage, &vram_usage); + System::CalculateRewindMemoryUsage(frames, resolution_scale, &ram_usage, &vram_usage); m_ui.rewindSummary->setText( tr("Rewind for %n frame(s), lasting %1 second(s) will require up to %2MB of RAM and %3MB of VRAM.", "", frames)