Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: Add Overclock setting and Override CPU clock-speed setting #1467

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,9 @@ perf:
cache_shaders:
type: bool
default: true
override_clockspeed:
type: bool
default: false
cpu_clockspeed_scale:
type: number
default: 1
12 changes: 10 additions & 2 deletions hw/i386/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
#include CONFIG_DEVICES
#include "kvm/kvm_i386.h"

#ifdef XBOX
#include "ui/xemu-settings.h"
#endif

/* Physical Address of PVH entry point read from kernel ELF NOTE */
static size_t pvh_start_addr;

Expand Down Expand Up @@ -532,8 +536,12 @@ static long get_file_size(FILE *f)
uint64_t cpu_get_tsc(CPUX86State *env)
{
#ifdef XBOX
return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), 733333333,
NANOSECONDS_PER_SECOND);
int cpu_clock_hz = 733333333;

if (g_config.perf.override_clockspeed) {
cpu_clock_hz *= g_config.perf.cpu_clockspeed_scale;
}
return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), cpu_clock_hz, NANOSECONDS_PER_SECOND);
#else
return cpus_get_elapsed_ticks();
#endif
Expand Down
13 changes: 12 additions & 1 deletion ui/xui/compat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ void CompatibilityReporter::Draw()
ImGui::SameLine();
}

if (g_config.perf.override_clockspeed) {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);

ImGui::Text("Reports cannot be made while using altered CPU clock speeds");
ImGui::SameLine();
}

ImGui::SetCursorPosX(ImGui::GetWindowWidth()-(120+10)*g_viewport_mgr.m_scale);

ImGui::SetItemDefaultFocus();
Expand All @@ -213,7 +221,10 @@ void CompatibilityReporter::Draw()
is_open = false;
}
}

if (g_config.perf.override_clockspeed) {
ImGui::PopItemFlag();
ImGui::PopStyleVar();
}
ImGui::End();
}

Expand Down
11 changes: 11 additions & 0 deletions ui/xui/main-menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ void MainMenuGeneralView::Draw()
Toggle("Cache shaders to disk", &g_config.perf.cache_shaders,
"Reduce stutter in games by caching previously generated shaders");

Toggle("Emulated CPU clock override", &g_config.perf.override_clockspeed,
Spidy123222 marked this conversation as resolved.
Show resolved Hide resolved
"Enables to override default CPU clock speed");

char buf[32];
snprintf(buf, sizeof(buf), "Clock Speed %d%% (%.2f MHz)", (int)(g_config.perf.cpu_clockspeed_scale * 100), (733333333 * g_config.perf.cpu_clockspeed_scale) / 1000000);
Slider("Virtual CPU clock", &g_config.perf.cpu_clockspeed_scale, buf, 0.01f, 2.f, 0.01f);

if (fabs(g_config.perf.cpu_clockspeed_scale - 1.f) <= 0.0099f) {
g_config.perf.cpu_clockspeed_scale = 1;
}

SectionTitle("Miscellaneous");
Toggle("Skip startup animation", &g_config.general.skip_boot_anim,
"Skip the full Xbox boot animation sequence");
Expand Down
15 changes: 9 additions & 6 deletions ui/xui/widgets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "viewport-manager.hh"
#include "ui/xemu-os-utils.h"
#include "gl-helpers.hh"
#include <algorithm>

void Separator()
{
Expand Down Expand Up @@ -222,8 +223,9 @@ bool Toggle(const char *str_id, bool *v, const char *description)
return status;
}

void Slider(const char *str_id, float *v, const char *description)
void Slider(const char *str_id, float *v, const char *description, float min, float max, float increment)
{
float x = (*v - min) / (max - min);
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS);

ImGuiStyle &style = ImGui::GetStyle();
Expand Down Expand Up @@ -261,13 +263,13 @@ void Slider(const char *str_id, float *v, const char *description)
ImGui::IsKeyPressed(ImGuiKey_GamepadDpadLeft) ||
ImGui::IsKeyPressed(ImGuiKey_GamepadLStickLeft) ||
ImGui::IsKeyPressed(ImGuiKey_GamepadRStickLeft)) {
*v -= 0.05;
x -= increment / max;
}
if (ImGui::IsKeyPressed(ImGuiKey_RightArrow) ||
ImGui::IsKeyPressed(ImGuiKey_GamepadDpadRight) ||
ImGui::IsKeyPressed(ImGuiKey_GamepadLStickRight) ||
ImGui::IsKeyPressed(ImGuiKey_GamepadRStickRight)) {
*v += 0.05;
x += increment / max;
}

if (
Expand All @@ -286,10 +288,11 @@ void Slider(const char *str_id, float *v, const char *description)

if (ImGui::IsItemActive()) {
ImVec2 mouse = ImGui::GetMousePos();
*v = GetSliderValueForMousePos(mouse, slider_pos, slider_size);
x = GetSliderValueForMousePos(mouse, slider_pos, slider_size);
}
*v = fmax(0, fmin(*v, 1));
DrawSlider(*v, ImGui::IsItemHovered() || ImGui::IsItemActive(), slider_pos,
x = std::clamp(x, 0.f, 1.f);
*v = x * (max - min) + min;
DrawSlider(x, ImGui::IsItemHovered() || ImGui::IsItemActive(), slider_pos,
slider_size);

ImVec2 slider_max = ImVec2(slider_pos.x + slider_size.x, slider_pos.y + slider_size.y);
Expand Down
2 changes: 1 addition & 1 deletion ui/xui/widgets.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ float GetSliderValueForMousePos(ImVec2 mouse, ImVec2 pos, ImVec2 size);
void DrawSlider(float v, bool hovered, ImVec2 pos, ImVec2 size);
void DrawToggle(bool enabled, bool hovered, ImVec2 pos, ImVec2 size);
bool Toggle(const char *str_id, bool *v, const char *description = nullptr);
void Slider(const char *str_id, float *v, const char *description = nullptr);
void Slider(const char *str_id, float *v, const char *description = nullptr, float min = 0, float max = 1, float increment = 0.05);
bool FilePicker(const char *str_id, const char **buf, const char *filters,
bool dir = false);
void DrawComboChevron();
Expand Down