From 2b0a8fcd6d5d8012dbc83afa8c9816563bd48c24 Mon Sep 17 00:00:00 2001 From: swurl Date: Thu, 17 Apr 2025 01:40:19 -0400 Subject: [PATCH] CPU clock rate slider very wip Signed-off-by: swurl --- src/common/settings.h | 7 +++ src/common/wall_clock.h | 44 +++++++++++++++---- src/core/hardware_properties.h | 11 ++++- src/core/hle/service/apm/apm_controller.cpp | 7 +-- src/yuzu/applets/qt_controller.cpp | 2 +- src/yuzu/configuration/configure_cpu.cpp | 5 ++- src/yuzu/configuration/configure_cpu.ui | 24 +++++++--- .../configuration/configure_filesystem.cpp | 4 +- .../configure_input_advanced.cpp | 8 ++-- src/yuzu/configuration/configure_system.cpp | 3 +- src/yuzu/configuration/configure_ui.cpp | 10 ++--- src/yuzu/configuration/shared_translation.cpp | 2 + src/yuzu/configuration/shared_widget.cpp | 2 +- 13 files changed, 94 insertions(+), 35 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index cf3579892c..ad7bcd16d7 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -198,6 +198,7 @@ struct Values { MemoryLayout::Memory_8Gb, "memory_layout_mode", Category::Core}; + SwitchableSetting use_speed_limit{ linkage, true, "use_speed_limit", Category::Core, Specialization::Paired, false, true}; SwitchableSetting speed_limit{linkage, @@ -229,6 +230,12 @@ struct Values { SwitchableSetting cpu_accuracy{linkage, CpuAccuracy::Auto, CpuAccuracy::Auto, CpuAccuracy::Paranoid, "cpu_accuracy", Category::Cpu}; + + SwitchableSetting cpu_clock_rate{linkage, 1020, + 500, 1785, + "cpu_clock_rate", Category::Cpu, + Specialization::Scalar}; + SwitchableSetting cpu_debug_mode{linkage, false, "cpu_debug_mode", Category::CpuDebug}; Setting cpuopt_page_tables{linkage, true, "cpuopt_page_tables", Category::CpuDebug}; diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index 3a0c43909a..0d0cd22411 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h @@ -8,6 +8,7 @@ #include #include "common/common_types.h" +#include "core/hardware_properties.h" namespace Common { @@ -15,7 +16,9 @@ class WallClock { public: static constexpr u64 CNTFRQ = 19'200'000; // CNTPCT_EL0 Frequency = 19.2 MHz static constexpr u64 GPUTickFreq = 614'400'000; // GM20B GPU Tick Frequency = 614.4 MHz - static constexpr u64 CPUTickFreq = 1'020'000'000; // T210/4 A57 CPU Tick Frequency = 1020.0 MHz + static inline u64 CPUTickFreq() { + return Core::Hardware::BASE_CLOCK_RATE(); + } virtual ~WallClock() = default; @@ -51,19 +54,19 @@ public: // Cycle Timing static inline u64 CPUTickToNS(u64 cpu_tick) { - return cpu_tick * CPUTickToNsRatio::num / CPUTickToNsRatio::den; + return cpu_tick * CPUTickToNsRatio::num / CPUTickToNsRatio::den(); } static inline u64 CPUTickToUS(u64 cpu_tick) { - return cpu_tick * CPUTickToUsRatio::num / CPUTickToUsRatio::den; + return cpu_tick * CPUTickToUsRatio::num / CPUTickToUsRatio::den(); } static inline u64 CPUTickToCNTPCT(u64 cpu_tick) { - return cpu_tick * CPUTickToCNTPCTRatio::num / CPUTickToCNTPCTRatio::den; + return cpu_tick * CPUTickToCNTPCTRatio::num / CPUTickToCNTPCTRatio::den(); } static inline u64 CPUTickToGPUTick(u64 cpu_tick) { - return cpu_tick * CPUTickToGPUTickRatio::num / CPUTickToGPUTickRatio::den; + return cpu_tick * CPUTickToGPUTickRatio::num / CPUTickToGPUTickRatio::den(); } protected: @@ -78,10 +81,33 @@ protected: // Cycle Timing - using CPUTickToNsRatio = std::ratio; - using CPUTickToUsRatio = std::ratio; - using CPUTickToCNTPCTRatio = std::ratio; - using CPUTickToGPUTickRatio = std::ratio; + struct CPUTickToNsRatio { + static inline std::intmax_t num = std::nano::den; + static inline std::intmax_t den() { + return CPUTickFreq(); + } + }; + + struct CPUTickToUsRatio { + static inline std::intmax_t num = std::micro::den; + static inline std::intmax_t den() { + return CPUTickFreq(); + } + }; + + struct CPUTickToCNTPCTRatio { + static inline std::intmax_t num = CNTFRQ; + static inline std::intmax_t den() { + return CPUTickFreq(); + } + }; + + struct CPUTickToGPUTickRatio { + static inline std::intmax_t num = GPUTickFreq; + static inline std::intmax_t den() { + return CPUTickFreq(); + } + }; }; std::unique_ptr CreateOptimalClock(); diff --git a/src/core/hardware_properties.h b/src/core/hardware_properties.h index 191c28bb46..6a2354c3bf 100644 --- a/src/core/hardware_properties.h +++ b/src/core/hardware_properties.h @@ -1,19 +1,26 @@ // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 eden Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include -#include +#include #include "common/bit_util.h" #include "common/common_types.h" +#include "common/settings.h" +#include "common/logging/log.h" namespace Core { namespace Hardware { -constexpr u64 BASE_CLOCK_RATE = 1'020'000'000; // Default CPU Frequency = 1020 MHz +inline u64 BASE_CLOCK_RATE() { + LOG_DEBUG(Core, "Settings reported clock rate={:08X}", Settings::values.cpu_clock_rate.GetValue()); + // std::cout << Settings::values.cpu_clock_rate.GetValue() << std::endl; + return Settings::values.cpu_clock_rate.GetValue() * 1'000'000; +} constexpr u64 CNTFREQ = 19'200'000; // CNTPCT_EL0 Frequency = 19.2 MHz constexpr u32 NUM_CPU_CORES = 4; // Number of CPU Cores diff --git a/src/core/hle/service/apm/apm_controller.cpp b/src/core/hle/service/apm/apm_controller.cpp index 4f1aa5cc27..60540df27c 100644 --- a/src/core/hle/service/apm/apm_controller.cpp +++ b/src/core/hle/service/apm/apm_controller.cpp @@ -7,7 +7,6 @@ #include "common/logging/log.h" #include "common/settings.h" -#include "common/settings_enums.h" #include "core/core_timing.h" #include "core/hle/service/apm/apm_controller.h" @@ -81,8 +80,10 @@ PerformanceConfiguration Controller::GetCurrentPerformanceConfiguration(Performa void Controller::SetClockSpeed(u32 mhz) { LOG_DEBUG(Service_APM, "called, mhz={:08X}", mhz); - // TODO(DarkLordZach): Actually signal core_timing to change clock speed. - // TODO(Rodrigo): Remove [[maybe_unused]] when core_timing is used. + + // TODO: needs to be verified + // Settings::values.cpu_clock_rate.SetGlobal(false); + // Settings::values.cpu_clock_rate.SetValue(mhz); } } // namespace Service::APM diff --git a/src/yuzu/applets/qt_controller.cpp b/src/yuzu/applets/qt_controller.cpp index 48ce860ad7..7a7190f5b5 100644 --- a/src/yuzu/applets/qt_controller.cpp +++ b/src/yuzu/applets/qt_controller.cpp @@ -184,7 +184,7 @@ QtControllerSelectorDialog::QtControllerSelectorDialog( CheckIfParametersMet(); }); - connect(connected_controller_checkboxes[i], &QCheckBox::stateChanged, [this, i](int state) { + connect(connected_controller_checkboxes[i], &QCheckBox::checkStateChanged, [this, i](int state) { player_groupboxes[i]->setChecked(state == Qt::Checked); UpdateControllerIcon(i); UpdateControllerState(i); diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 7e16cf17d4..c82734b0e6 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include #include #include #include "common/common_types.h" @@ -39,10 +38,12 @@ ConfigureCpu::ConfigureCpu(const Core::System& system_, ConfigureCpu::~ConfigureCpu() = default; void ConfigureCpu::SetConfiguration() {} + void ConfigureCpu::Setup(const ConfigurationShared::Builder& builder) { auto* accuracy_layout = ui->widget_accuracy->layout(); auto* backend_layout = ui->widget_backend->layout(); auto* unsafe_layout = ui->unsafe_widget->layout(); + auto* clock_layout = ui->widget_clock->layout(); std::map unsafe_hold{}; std::vector settings; @@ -73,6 +74,8 @@ void ConfigureCpu::Setup(const ConfigurationShared::Builder& builder) { } else if (setting->Id() == Settings::values.cpu_backend.Id()) { backend_layout->addWidget(widget); backend_combobox = widget->combobox; + } else if (setting->Id() == Settings::values.cpu_clock_rate.Id()) { + clock_layout->addWidget(widget); } else { // Presently, all other settings here are unsafe checkboxes unsafe_hold.insert({setting->Id(), widget}); diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index 13fd43605a..965effd9f1 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -59,8 +59,25 @@ + + + + Clock + + + + + + + + + + + + false + CPU Backend @@ -84,9 +101,6 @@ - - false - @@ -129,10 +143,10 @@ - Qt::Vertical + Qt::Orientation::Vertical - QSizePolicy::Expanding + QSizePolicy::Policy::Expanding diff --git a/src/yuzu/configuration/configure_filesystem.cpp b/src/yuzu/configuration/configure_filesystem.cpp index ad19517546..d0328575cb 100644 --- a/src/yuzu/configuration/configure_filesystem.cpp +++ b/src/yuzu/configuration/configure_filesystem.cpp @@ -29,9 +29,9 @@ ConfigureFilesystem::ConfigureFilesystem(QWidget* parent) connect(ui->reset_game_list_cache, &QPushButton::pressed, this, &ConfigureFilesystem::ResetMetadata); - connect(ui->gamecard_inserted, &QCheckBox::stateChanged, this, + connect(ui->gamecard_inserted, &QCheckBox::checkStateChanged, this, &ConfigureFilesystem::UpdateEnabledControls); - connect(ui->gamecard_current_game, &QCheckBox::stateChanged, this, + connect(ui->gamecard_current_game, &QCheckBox::checkStateChanged, this, &ConfigureFilesystem::UpdateEnabledControls); } diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp index d6c4e09ec0..b9ff58bf7b 100644 --- a/src/yuzu/configuration/configure_input_advanced.cpp +++ b/src/yuzu/configuration/configure_input_advanced.cpp @@ -74,13 +74,13 @@ ConfigureInputAdvanced::ConfigureInputAdvanced(Core::HID::HIDCore& hid_core_, QW } } - connect(ui->mouse_enabled, &QCheckBox::stateChanged, this, + connect(ui->mouse_enabled, &QCheckBox::checkStateChanged, this, &ConfigureInputAdvanced::UpdateUIEnabled); - connect(ui->debug_enabled, &QCheckBox::stateChanged, this, + connect(ui->debug_enabled, &QCheckBox::checkStateChanged, this, &ConfigureInputAdvanced::UpdateUIEnabled); - connect(ui->touchscreen_enabled, &QCheckBox::stateChanged, this, + connect(ui->touchscreen_enabled, &QCheckBox::checkStateChanged, this, &ConfigureInputAdvanced::UpdateUIEnabled); - connect(ui->enable_ring_controller, &QCheckBox::stateChanged, this, + connect(ui->enable_ring_controller, &QCheckBox::checkStateChanged, this, &ConfigureInputAdvanced::UpdateUIEnabled); connect(ui->debug_configure, &QPushButton::clicked, this, diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index e193b5f95b..6195aa63cb 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include #include #include @@ -83,7 +82,7 @@ ConfigureSystem::ConfigureSystem(Core::System& system_, connect(combo_language, qOverload(&QComboBox::currentIndexChanged), this, locale_check); connect(combo_region, qOverload(&QComboBox::currentIndexChanged), this, locale_check); - connect(checkbox_rtc, qOverload(&QCheckBox::stateChanged), this, update_rtc_date); + connect(checkbox_rtc, &QCheckBox::checkStateChanged, this, update_rtc_date); connect(date_rtc_offset, qOverload(&QSpinBox::valueChanged), this, update_rtc_date); connect(date_rtc, &QDateTimeEdit::dateTimeChanged, this, update_date_offset); diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index a75a1b264e..c05cecc56e 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -119,11 +119,11 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) SetConfiguration(); // Force game list reload if any of the relevant settings are changed. - connect(ui->show_add_ons, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); - connect(ui->show_compat, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); - connect(ui->show_size, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); - connect(ui->show_types, &QCheckBox::stateChanged, this, &ConfigureUi::RequestGameListUpdate); - connect(ui->show_play_time, &QCheckBox::stateChanged, this, + connect(ui->show_add_ons, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate); + connect(ui->show_compat, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate); + connect(ui->show_size, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate); + connect(ui->show_types, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate); + connect(ui->show_play_time, &QCheckBox::checkStateChanged, this, &ConfigureUi::RequestGameListUpdate); connect(ui->game_icon_size_combobox, QOverload::of(&QComboBox::currentIndexChanged), this, &ConfigureUi::RequestGameListUpdate); diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 0549e8ae44..f4b8db22bc 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -77,6 +77,8 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { tr("This setting controls the accuracy of the emulated CPU.\nDon't change this unless " "you know what you are doing.")); INSERT(Settings, cpu_backend, tr("Backend:"), QStringLiteral()); + INSERT(Settings, cpu_clock_rate, tr("CPU Clock Rate (MHz):"), tr("Increasing CPU clock rate may " + "improve performance, but may also reduce stability.")); // Cpu Debug diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 85f4f76550..d38ad519e7 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -699,7 +699,7 @@ void Widget::SetupComponent(const QString& label, std::function& load_fu restore_func(); } }; - connect(checkbox, &QCheckBox::stateChanged, reset); + connect(checkbox, &QCheckBox::checkStateChanged, reset); reset(checkbox->checkState()); } }