From 5e3ffeafbebe9df2ddb801e0444db9b5f6d8246b Mon Sep 17 00:00:00 2001 From: UltraDaCat <113462733+UltraDaCat@users.noreply.github.com> Date: Sun, 7 Sep 2025 00:00:26 +0200 Subject: [PATCH] Replace Vblank Divider with Vblank Frequency (#3532) --- src/common/config.cpp | 18 +++++++++--------- src/common/config.h | 6 +++--- src/core/devtools/widget/frame_graph.cpp | 5 ++--- src/core/libraries/videoout/driver.cpp | 5 ++--- src/emulator.cpp | 4 ++-- src/qt_gui/settings_dialog.cpp | 8 ++++---- src/qt_gui/settings_dialog.ui | 15 ++++++++++++--- 7 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 23a79adf1..1462f2aa6 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -140,7 +140,7 @@ static ConfigEntry readbackLinearImagesEnabled(false); static ConfigEntry directMemoryAccessEnabled(false); static ConfigEntry shouldDumpShaders(false); static ConfigEntry shouldPatchShaders(false); -static ConfigEntry vblankDivider(1); +static ConfigEntry vblankFrequency(60); static ConfigEntry isFullscreen(false); static ConfigEntry fullscreenMode("Windowed"); static ConfigEntry presentMode("Mailbox"); @@ -398,8 +398,8 @@ bool isLoggingEnabled() { return logEnabled.get(); } -u32 vblankDiv() { - return vblankDivider.get(); +u32 vblankFreq() { + return vblankFrequency.get(); } bool vkValidationEnabled() { @@ -530,8 +530,8 @@ void setRdocEnabled(bool enable) { rdocEnable.base_value = enable; } -void setVblankDiv(u32 value) { - vblankDivider.base_value = value; +void setVblankFreq(u32 value) { + vblankFrequency.base_value = value; } void setIsFullscreen(bool enable) { @@ -821,7 +821,7 @@ void load(const std::filesystem::path& path, bool is_game_specific) { directMemoryAccessEnabled.setFromToml(gpu, "directMemoryAccess", is_game_specific); shouldDumpShaders.setFromToml(gpu, "dumpShaders", is_game_specific); shouldPatchShaders.setFromToml(gpu, "patchShaders", is_game_specific); - vblankDivider.setFromToml(gpu, "vblankDivider", is_game_specific); + vblankFrequency.setFromToml(gpu, "vblankFrequency", is_game_specific); isFullscreen.setFromToml(gpu, "Fullscreen", is_game_specific); fullscreenMode.setFromToml(gpu, "FullscreenMode", is_game_specific); presentMode.setFromToml(gpu, "presentMode", is_game_specific); @@ -992,7 +992,7 @@ void save(const std::filesystem::path& path) { data["GPU"]["directMemoryAccess"] = directMemoryAccessEnabled.base_value; data["GPU"]["dumpShaders"] = shouldDumpShaders.base_value; data["GPU"]["patchShaders"] = shouldPatchShaders.base_value; - data["GPU"]["vblankDivider"] = vblankDivider.base_value; + data["GPU"]["vblankFrequency"] = vblankFrequency.base_value; data["GPU"]["Fullscreen"] = isFullscreen.base_value; data["GPU"]["FullscreenMode"] = fullscreenMode.base_value; data["GPU"]["presentMode"] = presentMode.base_value; @@ -1103,7 +1103,7 @@ void setDefaultValues() { directMemoryAccessEnabled = false; shouldDumpShaders = false; shouldPatchShaders = false; - vblankDivider = 1; + vblankFrequency = 60; isFullscreen = false; fullscreenMode = "Windowed"; presentMode = "Mailbox"; diff --git a/src/common/config.h b/src/common/config.h index 2afa9ba0e..6631723af 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once @@ -61,8 +61,8 @@ bool directMemoryAccess(); void setDirectMemoryAccess(bool enable); bool dumpShaders(); void setDumpShaders(bool enable); -u32 vblankDiv(); -void setVblankDiv(u32 value); +u32 vblankFreq(); +void setVblankFreq(u32 value); bool getisTrophyPopupDisabled(); void setisTrophyPopupDisabled(bool disable); s16 getCursorState(); diff --git a/src/core/devtools/widget/frame_graph.cpp b/src/core/devtools/widget/frame_graph.cpp index 8f3e133f5..6b63d4978 100644 --- a/src/core/devtools/widget/frame_graph.cpp +++ b/src/core/devtools/widget/frame_graph.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "frame_graph.h" @@ -13,7 +13,6 @@ using namespace ImGui; namespace Core::Devtools::Widget { -constexpr float TARGET_FPS = 60.0f; constexpr float BAR_WIDTH_MULT = 1.4f; constexpr float BAR_HEIGHT_MULT = 1.25f; constexpr float FRAME_GRAPH_PADDING_Y = 3.0f; @@ -30,7 +29,7 @@ void FrameGraph::DrawFrameGraph() { return; } - float target_dt = 1.0f / (TARGET_FPS * (float)Config::vblankDiv()); + float target_dt = 1.0f / (float)Config::vblankFreq(); float cur_pos_x = pos.x + full_width; pos.y += FRAME_GRAPH_PADDING_Y; const float final_pos_y = pos.y + FRAME_GRAPH_HEIGHT; diff --git a/src/core/libraries/videoout/driver.cpp b/src/core/libraries/videoout/driver.cpp index 8f725e549..7c162de88 100644 --- a/src/core/libraries/videoout/driver.cpp +++ b/src/core/libraries/videoout/driver.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "common/assert.h" @@ -269,8 +269,7 @@ void VideoOutDriver::SubmitFlipInternal(VideoOutPort* port, s32 index, s64 flip_ } void VideoOutDriver::PresentThread(std::stop_token token) { - static constexpr std::chrono::nanoseconds VblankPeriod{16666667}; - const auto vblank_period = VblankPeriod / Config::vblankDiv(); + const std::chrono::nanoseconds vblank_period(1000000000 / Config::vblankFreq()); Common::SetCurrentThreadName("shadPS4:PresentThread"); Common::SetCurrentThreadRealtime(vblank_period); diff --git a/src/emulator.cpp b/src/emulator.cpp index d402fee4c..1388c9027 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -145,7 +145,7 @@ void Emulator::Run(std::filesystem::path file, const std::vector ar LOG_INFO(Config, "GPU readbackLinearImages: {}", Config::readbackLinearImages()); LOG_INFO(Config, "GPU directMemoryAccess: {}", Config::directMemoryAccess()); LOG_INFO(Config, "GPU shouldDumpShaders: {}", Config::dumpShaders()); - LOG_INFO(Config, "GPU vblankDivider: {}", Config::vblankDiv()); + LOG_INFO(Config, "GPU vblankFrequency: {}", Config::vblankFreq()); LOG_INFO(Config, "Vulkan gpuId: {}", Config::getGpuId()); LOG_INFO(Config, "Vulkan vkValidation: {}", Config::vkValidationEnabled()); LOG_INFO(Config, "Vulkan vkValidationSync: {}", Config::vkValidationSyncEnabled()); diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 6a19e51dd..50202695c 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include @@ -571,7 +571,7 @@ void SettingsDialog::LoadValuesFromConfig() { ui->graphicsAdapterBox->setCurrentIndex(toml::find_or(data, "Vulkan", "gpuId", -1) + 1); ui->widthSpinBox->setValue(toml::find_or(data, "GPU", "screenWidth", 1280)); ui->heightSpinBox->setValue(toml::find_or(data, "GPU", "screenHeight", 720)); - ui->vblankSpinBox->setValue(toml::find_or(data, "GPU", "vblankDivider", 1)); + ui->vblankSpinBox->setValue(toml::find_or(data, "GPU", "vblankFrequency", 60)); ui->dumpShadersCheckBox->setChecked(toml::find_or(data, "GPU", "dumpShaders", false)); ui->nullGpuCheckBox->setChecked(toml::find_or(data, "GPU", "nullGpu", false)); ui->enableHDRCheckBox->setChecked(toml::find_or(data, "GPU", "allowHDR", false)); @@ -817,7 +817,7 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) { } else if (elementName == "windowSizeGroupBox") { text = tr("Width/Height:\\nSets the size of the emulator window at launch, which can be resized during gameplay.\\nThis is different from the in-game resolution."); } else if (elementName == "heightDivider") { - text = tr("Vblank Divider:\\nThe frame rate at which the emulator refreshes at is multiplied by this number. Changing this may have adverse effects, such as increasing the game speed, or breaking critical game functionality that does not expect this to change!"); + text = tr("Vblank Frequency:\\nThe frame rate at which the emulator refreshes at is multiplied by this number. Changing this may have adverse effects, such as increasing the game speed, or breaking critical game functionality that does not expect this to change!"); } else if (elementName == "dumpShadersCheckBox") { text = tr("Enable Shaders Dumping:\\nFor the sake of technical debugging, saves the games shaders to a folder as they render."); } else if (elementName == "nullGpuCheckBox") { @@ -947,7 +947,7 @@ void SettingsDialog::UpdateSettings() { Config::setEnableDiscordRPC(ui->discordRPCCheckbox->isChecked()); Config::setWindowWidth(ui->widthSpinBox->value()); Config::setWindowHeight(ui->heightSpinBox->value()); - Config::setVblankDiv(ui->vblankSpinBox->value()); + Config::setVblankFreq(ui->vblankSpinBox->value()); Config::setDumpShaders(ui->dumpShadersCheckBox->isChecked()); Config::setNullGpu(ui->nullGpuCheckBox->isChecked()); Config::setFsrEnabled(ui->FSRCheckBox->isChecked()); diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index e6dee2c36..2ae74bd50 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -1,5 +1,5 @@ - SettingsDialog @@ -1211,7 +1211,7 @@ - Vblank Divider + Vblank Frequency @@ -1219,6 +1219,12 @@ true + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter + + + + true @@ -1228,6 +1234,9 @@ false + + Hz + 1 @@ -1235,7 +1244,7 @@ 9999 - 1 + 60