Skip to content

Commit

Permalink
Add VBI Overclock
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-Belliveau authored and SuperSamus committed Sep 1, 2024
1 parent 7d08377 commit 21e517e
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ enum class BooleanSetting(
"OverclockEnable",
false
),
MAIN_VI_OVERCLOCK_ENABLE(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_CORE,
"VIOverclockEnable",
false
),
MAIN_RAM_OVERRIDE_ENABLE(
Settings.FILE_DOLPHIN,
Settings.SECTION_INI_CORE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class FloatSetting(
// These entries have the same names and order as in C++, just for consistency.
MAIN_EMULATION_SPEED(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "EmulationSpeed", 1.0f),
MAIN_OVERCLOCK(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "Overclock", 1.0f),
MAIN_VI_OVERCLOCK(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "VIOverclock", 1.0f),
GFX_CC_GAME_GAMMA(Settings.FILE_GFX, Settings.SECTION_GFX_COLOR_CORRECTION, "GameGamma", 2.35f);

override val isOverridden: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,27 @@ class SettingsFragmentPresenter(
false
)
)
sl.add(
SwitchSetting(
context,
BooleanSetting.MAIN_VI_OVERCLOCK_ENABLE,
R.string.vi_overclock_enable,
R.string.vi_overclock_enable_description
)
)
sl.add(
PercentSliderSetting(
context,
FloatSetting.MAIN_VI_OVERCLOCK,
R.string.vi_overclock_title,
R.string.vi_overclock_title_description,
0f,
400f,
"%",
1f,
false
)
)

val mem1Size = ScaledIntSetting(1024 * 1024, IntSetting.MAIN_MEM1_SIZE)
val mem2Size = ScaledIntSetting(1024 * 1024, IntSetting.MAIN_MEM2_SIZE)
Expand Down
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@
<string name="main_mem1_size">MEM1 Size</string>
<string name="main_mem2_size">MEM2 Size</string>
<string name="gpu_options">GPU Options</string>
<string name="vi_overclock_enable">Override VBI Clock Speed</string>
<string name="vi_overclock_enable_description">Higher values may make games run at a higher framerate without changing audio, which MAY impact game speed. Lower values MAY activate a game's internal frameskip, potentially improving performance.</string>
<string name="vi_overclock_title">Emulated VBI Clock Speed</string>
<string name="vi_overclock_title_description">Adjusts the emulated VBI clock rate if \"Override VBI Clock Speed\" is enabled.</string>
<string name="synchronize_gpu_thread">Synchronize GPU Thread</string>
<string name="synchronize_gpu_thread_description">Synchronizing the GPU thread reduces the risk of games crashing or becoming unstable with dual core enabled, but can also reduce the performance gain of dual core. If unsure, select \"On Idle Skipping\". Selecting \"Never\" is risky and not recommended!</string>
<string name="custom_rtc_options">Custom RTC Options</string>
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Config/MainSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ const Info<bool> MAIN_DISABLE_ICACHE{{System::Main, "Core", "DisableICache"}, fa
const Info<float> MAIN_EMULATION_SPEED{{System::Main, "Core", "EmulationSpeed"}, 1.0f};
const Info<float> MAIN_OVERCLOCK{{System::Main, "Core", "Overclock"}, 1.0f};
const Info<bool> MAIN_OVERCLOCK_ENABLE{{System::Main, "Core", "OverclockEnable"}, false};
const Info<float> MAIN_VI_OVERCLOCK{{System::Main, "Core", "VIOverclock"}, 1.0f};
const Info<bool> MAIN_VI_OVERCLOCK_ENABLE{{System::Main, "Core", "VIOverclockEnable"}, false};
const Info<bool> MAIN_RAM_OVERRIDE_ENABLE{{System::Main, "Core", "RAMOverrideEnable"}, false};
const Info<u32> MAIN_MEM1_SIZE{{System::Main, "Core", "MEM1Size"}, Memory::MEM1_SIZE_RETAIL};
const Info<u32> MAIN_MEM2_SIZE{{System::Main, "Core", "MEM2Size"}, Memory::MEM2_SIZE_RETAIL};
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/Config/MainSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ extern const Info<bool> MAIN_DISABLE_ICACHE;
extern const Info<float> MAIN_EMULATION_SPEED;
extern const Info<float> MAIN_OVERCLOCK;
extern const Info<bool> MAIN_OVERCLOCK_ENABLE;
extern const Info<float> MAIN_VI_OVERCLOCK;
extern const Info<bool> MAIN_VI_OVERCLOCK_ENABLE;
extern const Info<bool> MAIN_RAM_OVERRIDE_ENABLE;
extern const Info<u32> MAIN_MEM1_SIZE;
extern const Info<u32> MAIN_MEM2_SIZE;
Expand Down
18 changes: 16 additions & 2 deletions Source/Core/Core/HW/SystemTimers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,22 @@ void SystemTimersManager::VICallback(Core::System& system, u64 userdata, s64 cyc
auto& core_timing = system.GetCoreTiming();
auto& vi = system.GetVideoInterface();
vi.Update(core_timing.GetTicks() - cycles_late);
core_timing.ScheduleEvent(vi.GetTicksPerHalfLine() - cycles_late,
system.GetSystemTimers().m_event_type_vi);

const u32 ticks_per_halfline = vi.GetTicksPerHalfLine();

if (Config::Get(Config::MAIN_VI_OVERCLOCK_ENABLE))
{
const float overclock = Config::Get(Config::MAIN_VI_OVERCLOCK);
const u32 ticks_per_halfline_overclocked =
static_cast<u32>(0.5f + (ticks_per_halfline / overclock));
core_timing.ScheduleEvent(ticks_per_halfline_overclocked - cycles_late,
system.GetSystemTimers().m_event_type_vi);
}
else
{
core_timing.ScheduleEvent(ticks_per_halfline - cycles_late,
system.GetSystemTimers().m_event_type_vi);
}
}

void SystemTimersManager::DecrementerCallback(Core::System& system, u64 userdata, s64 cycles_late)
Expand Down
70 changes: 70 additions & 0 deletions Source/Core/DolphinQt/Settings/AdvancedPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/SystemTimers.h"
#include "Core/HW/VideoInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/System.h"

Expand Down Expand Up @@ -117,6 +118,36 @@ void AdvancedPane::CreateLayout()
cpu_clock_override_description->setWordWrap(true);
clock_override_layout->addWidget(cpu_clock_override_description);

auto* vi_clock_override = new QGroupBox(tr("VBI Clock Override"));
auto* vi_clock_override_layout = new QVBoxLayout();
vi_clock_override->setLayout(vi_clock_override_layout);
main_layout->addWidget(vi_clock_override);

m_vi_clock_override_checkbox = new QCheckBox(tr("Enable VBI Overclocking"));
vi_clock_override_layout->addWidget(m_vi_clock_override_checkbox);

auto* vi_clock_override_slider_layout = new QHBoxLayout();
vi_clock_override_slider_layout->setContentsMargins(0, 0, 0, 0);
vi_clock_override_layout->addLayout(vi_clock_override_slider_layout);

m_vi_clock_override_slider = new QSlider(Qt::Horizontal);
m_vi_clock_override_slider->setRange(1, 400);
vi_clock_override_slider_layout->addWidget(m_vi_clock_override_slider);

m_vi_clock_override_slider_label = new QLabel();
vi_clock_override_slider_layout->addWidget(m_vi_clock_override_slider_label);

auto* vi_clock_override_description = new QLabel(
tr("Adjusts the emulated VBI clock rate.\n\n"
"Higher values may make games run at a higher framerate without changing audio, "
"which MAY impact game speed. Lower values MAY activate a game's "
"internal frameskip, potentially improving performance.\n\n"
"WARNING: Changing this from the default (100%) can and will "
"break games and cause glitches. Do so at your own risk. "
"Please do not report bugs that occur with a non-default clock."));
vi_clock_override_description->setWordWrap(true);
vi_clock_override_layout->addWidget(vi_clock_override_description);

auto* ram_override = new QGroupBox(tr("Memory Override"));
auto* ram_override_layout = new QVBoxLayout();
ram_override->setLayout(ram_override_layout);
Expand Down Expand Up @@ -208,6 +239,19 @@ void AdvancedPane::ConnectLayout()
Update();
});

m_vi_clock_override_checkbox->setChecked(Config::Get(Config::MAIN_VI_OVERCLOCK_ENABLE));
connect(m_vi_clock_override_checkbox, &QCheckBox::toggled, [this](bool enable_clock_override) {
Config::SetBaseOrCurrent(Config::MAIN_VI_OVERCLOCK_ENABLE, enable_clock_override);
Update();
});

connect(m_vi_clock_override_slider, &QSlider::valueChanged, [this](int oc_factor) {
const float factor = m_vi_clock_override_slider->value() / 100.f;
Config::SetBaseOrCurrent(Config::MAIN_VI_OVERCLOCK, factor);
Update();
});

m_ram_override_checkbox->setChecked(Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE));
connect(m_ram_override_checkbox, &QCheckBox::toggled, [this](bool enable_ram_override) {
Config::SetBaseOrCurrent(Config::MAIN_RAM_OVERRIDE_ENABLE, enable_ram_override);
Update();
Expand Down Expand Up @@ -241,6 +285,7 @@ void AdvancedPane::Update()
{
const bool running = Core::GetState(Core::System::GetInstance()) != Core::State::Uninitialized;
const bool enable_cpu_clock_override_widgets = Config::Get(Config::MAIN_OVERCLOCK_ENABLE);
const bool enable_vi_clock_override_widgets = Config::Get(Config::MAIN_VI_OVERCLOCK_ENABLE);
const bool enable_ram_override_widgets = Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE);
const bool enable_custom_rtc_widgets = Config::Get(Config::MAIN_CUSTOM_RTC_ENABLE) && !running;

Expand Down Expand Up @@ -282,6 +327,31 @@ void AdvancedPane::Update()
return tr("%1% (%2 MHz)").arg(QString::number(percent), QString::number(clock));
}());

QFont vi_bf = font();
vi_bf.setBold(Config::GetActiveLayerForConfig(Config::MAIN_VI_OVERCLOCK_ENABLE) !=
Config::LayerType::Base);
m_vi_clock_override_checkbox->setFont(vi_bf);
m_vi_clock_override_checkbox->setChecked(enable_vi_clock_override_widgets);

m_vi_clock_override_slider->setEnabled(enable_vi_clock_override_widgets);
m_vi_clock_override_slider_label->setEnabled(enable_vi_clock_override_widgets);

{
const QSignalBlocker blocker(m_vi_clock_override_slider);
m_vi_clock_override_slider->setValue(
static_cast<int>(std::round(Config::Get(Config::MAIN_VI_OVERCLOCK) * 100.f)));
}

m_vi_clock_override_slider_label->setText([] {
int percent = static_cast<int>(std::round(Config::Get(Config::MAIN_VI_OVERCLOCK) * 100.f));
float core_vps =
static_cast<float>(Core::System::GetInstance().GetVideoInterface().GetTargetRefreshRate());
if (core_vps == 0.0f)
core_vps = 59.94f;
float vps = static_cast<float>(core_vps * Config::Get(Config::MAIN_VI_OVERCLOCK));
return tr("%1% (%2 VPS)").arg(QString::number(percent), QString::number(vps, 'f', 2));
}());

m_ram_override_checkbox->setEnabled(!running);
SignalBlocking(m_ram_override_checkbox)->setChecked(enable_ram_override_widgets);

Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DolphinQt/Settings/AdvancedPane.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class AdvancedPane final : public QWidget
QLabel* m_cpu_clock_override_slider_label;
QLabel* m_cpu_clock_override_description;

QCheckBox* m_vi_clock_override_checkbox;
QSlider* m_vi_clock_override_slider;
QLabel* m_vi_clock_override_slider_label;
QLabel* m_vi_clock_override_description;

QCheckBox* m_custom_rtc_checkbox;
QDateTimeEdit* m_custom_rtc_datetime;

Expand Down

0 comments on commit 21e517e

Please sign in to comment.