| 1 | // Copyright 2017 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "DolphinQt/Config/Graphics/HacksWidget.h" |
| 5 | |
| 6 | #include <QGridLayout> |
| 7 | #include <QGroupBox> |
| 8 | #include <QLabel> |
| 9 | #include <QSignalBlocker> |
| 10 | #include <QVBoxLayout> |
| 11 | |
| 12 | #include "Core/Config/GraphicsSettings.h" |
| 13 | #include "Core/Config/MainSettings.h" |
| 14 | |
| 15 | #include "DolphinQt/Config/ConfigControls/ConfigBool.h" |
| 16 | #include "DolphinQt/Config/ConfigControls/ConfigSlider.h" |
| 17 | #include "DolphinQt/Config/GameConfigWidget.h" |
| 18 | #include "DolphinQt/Config/Graphics/GraphicsPane.h" |
| 19 | |
| 20 | #include "VideoCommon/VideoConfig.h" |
| 21 | |
| 22 | HacksWidget::HacksWidget(GraphicsPane* gfx_pane) : m_game_layer{gfx_pane->GetConfigLayer()} |
| 23 | { |
| 24 | CreateWidgets(); |
| 25 | ConnectWidgets(); |
| 26 | AddDescriptions(); |
| 27 | |
| 28 | connect(gfx_pane, &GraphicsPane::BackendChanged, this, &HacksWidget::OnBackendChanged); |
| 29 | OnBackendChanged(QString::fromStdString(Config::Get(Config::MAIN_GFX_BACKEND))); |
| 30 | connect(gfx_pane, &GraphicsPane::UpdateGPUTextureDecoding, this, |
| 31 | &HacksWidget::UpdateGPUTextureDecodingEnabled); |
| 32 | } |
| 33 | |
| 34 | void HacksWidget::CreateWidgets() |
| 35 | { |
| 36 | auto* main_layout = new QVBoxLayout; |
| 37 | |
| 38 | // EFB |
| 39 | auto* efb_box = new QGroupBox(tr("Embedded Frame Buffer (EFB)")); |
| 40 | auto* efb_layout = new QGridLayout(); |
| 41 | efb_box->setLayout(efb_layout); |
| 42 | m_skip_efb_cpu = new ConfigBool(tr("Skip EFB Access from CPU"), |
| 43 | Config::GFX_HACK_EFB_ACCESS_ENABLE, m_game_layer, true); |
| 44 | m_ignore_format_changes = new ConfigBool( |
| 45 | tr("Ignore Format Changes"), Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES, m_game_layer, true); |
| 46 | m_store_efb_copies = new ConfigBool(tr("Store EFB Copies to Texture Only"), |
| 47 | Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, m_game_layer); |
| 48 | m_defer_efb_copies = new ConfigBool(tr("Defer EFB Copies to RAM"), |
| 49 | Config::GFX_HACK_DEFER_EFB_COPIES, m_game_layer); |
| 50 | |
| 51 | efb_layout->addWidget(m_skip_efb_cpu, 0, 0); |
| 52 | efb_layout->addWidget(m_ignore_format_changes, 0, 1); |
| 53 | efb_layout->addWidget(m_store_efb_copies, 1, 0); |
| 54 | efb_layout->addWidget(m_defer_efb_copies, 1, 1); |
| 55 | |
| 56 | // Texture Cache |
| 57 | auto* texture_cache_box = new QGroupBox(tr("Texture Cache")); |
| 58 | auto* texture_cache_layout = new QGridLayout(); |
| 59 | texture_cache_box->setLayout(texture_cache_layout); |
| 60 | |
| 61 | m_accuracy = |
| 62 | new ConfigSlider({0, 512, 128}, Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES, m_game_layer); |
| 63 | m_gpu_texture_decoding = new ConfigBool(tr("GPU Texture Decoding"), |
| 64 | Config::GFX_ENABLE_GPU_TEXTURE_DECODING, m_game_layer); |
| 65 | |
| 66 | auto* safe_label = new QLabel(tr("Safe")); |
| 67 | safe_label->setAlignment(Qt::AlignRight); |
| 68 | |
| 69 | m_accuracy_label = new ConfigSliderLabel(tr("Accuracy:"), m_accuracy); |
| 70 | |
| 71 | texture_cache_layout->addWidget(m_accuracy_label, 0, 0); |
| 72 | texture_cache_layout->addWidget(safe_label, 0, 1); |
| 73 | texture_cache_layout->addWidget(m_accuracy, 0, 2); |
| 74 | texture_cache_layout->addWidget(new QLabel(tr("Fast")), 0, 3); |
| 75 | texture_cache_layout->addWidget(m_gpu_texture_decoding, 1, 0); |
| 76 | |
| 77 | // XFB |
| 78 | auto* xfb_box = new QGroupBox(tr("External Frame Buffer (XFB)")); |
| 79 | auto* xfb_layout = new QVBoxLayout(); |
| 80 | xfb_box->setLayout(xfb_layout); |
| 81 | |
| 82 | m_store_xfb_copies = new ConfigBool(tr("Store XFB Copies to Texture Only"), |
| 83 | Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM, m_game_layer); |
| 84 | m_immediate_xfb = |
| 85 | new ConfigBool(tr("Immediately Present XFB"), Config::GFX_HACK_IMMEDIATE_XFB, m_game_layer); |
| 86 | m_skip_duplicate_xfbs = new ConfigBool(tr("Skip Presenting Duplicate Frames"), |
| 87 | Config::GFX_HACK_SKIP_DUPLICATE_XFBS, m_game_layer); |
| 88 | |
| 89 | xfb_layout->addWidget(m_store_xfb_copies); |
| 90 | xfb_layout->addWidget(m_immediate_xfb); |
| 91 | xfb_layout->addWidget(m_skip_duplicate_xfbs); |
| 92 | |
| 93 | // Other |
| 94 | auto* other_box = new QGroupBox(tr("Other")); |
| 95 | auto* other_layout = new QGridLayout(); |
| 96 | other_box->setLayout(other_layout); |
| 97 | |
| 98 | m_fast_depth_calculation = |
| 99 | new ConfigBool(tr("Fast Depth Calculation"), Config::GFX_FAST_DEPTH_CALC, m_game_layer); |
| 100 | m_disable_bounding_box = |
| 101 | new ConfigBool(tr("Disable Bounding Box"), Config::GFX_HACK_BBOX_ENABLE, m_game_layer, true); |
| 102 | m_vertex_rounding = |
| 103 | new ConfigBool(tr("Vertex Rounding"), Config::GFX_HACK_VERTEX_ROUNDING, m_game_layer); |
| 104 | m_save_texture_cache_state = new ConfigBool( |
| 105 | tr("Save Texture Cache to State"), Config::GFX_SAVE_TEXTURE_CACHE_TO_STATE, m_game_layer); |
| 106 | m_vi_skip = new ConfigBool(tr("VBI Skip"), Config::GFX_HACK_VI_SKIP, m_game_layer); |
| 107 | |
| 108 | other_layout->addWidget(m_fast_depth_calculation, 0, 0); |
| 109 | other_layout->addWidget(m_disable_bounding_box, 0, 1); |
| 110 | other_layout->addWidget(m_vertex_rounding, 1, 0); |
| 111 | other_layout->addWidget(m_save_texture_cache_state, 1, 1); |
| 112 | other_layout->addWidget(m_vi_skip, 2, 0); |
| 113 | |
| 114 | main_layout->addWidget(efb_box); |
| 115 | main_layout->addWidget(texture_cache_box); |
| 116 | main_layout->addWidget(xfb_box); |
| 117 | main_layout->addWidget(other_box); |
| 118 | main_layout->addStretch(); |
| 119 | |
| 120 | setLayout(main_layout); |
| 121 | |
| 122 | UpdateDeferEFBCopiesEnabled(); |
| 123 | UpdateSkipPresentingDuplicateFramesEnabled(); |
| 124 | } |
| 125 | |
| 126 | void HacksWidget::OnBackendChanged(const QString& backend_name) |
| 127 | { |
| 128 | const bool bbox = g_backend_info.bSupportsBBox; |
| 129 | const bool gpu_texture_decoding = g_backend_info.bSupportsGPUTextureDecoding; |
| 130 | |
| 131 | UpdateGPUTextureDecodingEnabled(); |
| 132 | m_disable_bounding_box->setEnabled(bbox); |
| 133 | |
| 134 | const QString tooltip = tr("%1 doesn't support this feature on your system.") |
| 135 | .arg(tr(backend_name.toStdString().c_str())); |
| 136 | |
| 137 | m_gpu_texture_decoding->setToolTip(!gpu_texture_decoding ? tooltip : QString{}); |
| 138 | m_disable_bounding_box->setToolTip(!bbox ? tooltip : QString{}); |
| 139 | } |
| 140 | |
| 141 | void HacksWidget::ConnectWidgets() |
| 142 | { |
| 143 | #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0) |
| 144 | connect(m_store_efb_copies, &QCheckBox::checkStateChanged, |
| 145 | [this](Qt::CheckState) { UpdateDeferEFBCopiesEnabled(); }); |
| 146 | connect(m_store_xfb_copies, &QCheckBox::checkStateChanged, |
| 147 | [this](Qt::CheckState) { UpdateDeferEFBCopiesEnabled(); }); |
| 148 | connect(m_immediate_xfb, &QCheckBox::checkStateChanged, |
| 149 | [this](Qt::CheckState) { UpdateSkipPresentingDuplicateFramesEnabled(); }); |
| 150 | connect(m_vi_skip, &QCheckBox::checkStateChanged, |
| 151 | [this](Qt::CheckState) { UpdateSkipPresentingDuplicateFramesEnabled(); }); |
| 152 | #else |
| 153 | connect(m_store_efb_copies, &QCheckBox::stateChanged, |
| 154 | [this](int) { UpdateDeferEFBCopiesEnabled(); }); |
| 155 | connect(m_store_xfb_copies, &QCheckBox::stateChanged, |
| 156 | [this](int) { UpdateDeferEFBCopiesEnabled(); }); |
| 157 | connect(m_immediate_xfb, &QCheckBox::stateChanged, |
| 158 | [this](int) { UpdateSkipPresentingDuplicateFramesEnabled(); }); |
| 159 | connect(m_vi_skip, &QCheckBox::stateChanged, |
| 160 | [this](int) { UpdateSkipPresentingDuplicateFramesEnabled(); }); |
| 161 | #endif |
| 162 | } |
| 163 | |
| 164 | void HacksWidget::AddDescriptions() |
| 165 | { |
| 166 | static const char TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION[] = QT_TR_NOOP( |
| 167 | "Ignores any requests from the CPU to read from or write to the EFB. " |
| 168 | "<br><br>Improves performance in some games, but will disable all EFB-based " |
| 169 | "graphical effects or gameplay-related features.<br><br><dolphin_emphasis>If unsure, " |
| 170 | "leave this checked.</dolphin_emphasis>"); |
| 171 | static const char TR_IGNORE_FORMAT_CHANGE_DESCRIPTION[] = QT_TR_NOOP( |
| 172 | "Ignores any changes to the EFB format.<br><br>Improves performance in many games " |
| 173 | "without " |
| 174 | "any negative effect. Causes graphical defects in a small number of other " |
| 175 | "games.<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>"); |
| 176 | static const char TR_STORE_EFB_TO_TEXTURE_DESCRIPTION[] = QT_TR_NOOP( |
| 177 | "Stores EFB copies exclusively on the GPU, bypassing system memory. Causes graphical defects " |
| 178 | "in a small number of games.<br><br>Enabled = EFB Copies to Texture<br>Disabled = EFB " |
| 179 | "Copies to " |
| 180 | "RAM (and Texture)<br><br><dolphin_emphasis>If unsure, leave this " |
| 181 | "checked.</dolphin_emphasis>"); |
| 182 | static const char TR_DEFER_EFB_COPIES_DESCRIPTION[] = QT_TR_NOOP( |
| 183 | "Waits until the game synchronizes with the emulated GPU before writing the contents of EFB " |
| 184 | "copies to RAM.<br><br>Reduces the overhead of EFB RAM copies, providing a performance " |
| 185 | "boost in " |
| 186 | "many games, at the risk of breaking those which do not safely synchronize with the " |
| 187 | "emulated GPU.<br><br><dolphin_emphasis>If unsure, leave this " |
| 188 | "checked.</dolphin_emphasis>"); |
| 189 | static const char TR_ACCUARCY_DESCRIPTION[] = QT_TR_NOOP( |
| 190 | "Adjusts the accuracy at which the GPU receives texture updates from RAM.<br><br>" |
| 191 | "The \"Safe\" setting eliminates the likelihood of the GPU missing texture updates " |
| 192 | "from RAM. Lower accuracies cause in-game text to appear garbled in certain " |
| 193 | "games.<br><br><dolphin_emphasis>If unsure, select the rightmost " |
| 194 | "value.</dolphin_emphasis>"); |
| 195 | static const char TR_STORE_XFB_TO_TEXTURE_DESCRIPTION[] = QT_TR_NOOP( |
| 196 | "Stores XFB copies exclusively on the GPU, bypassing system memory. Causes graphical defects " |
| 197 | "in a small number of games.<br><br>Enabled = XFB Copies to " |
| 198 | "Texture<br>Disabled = XFB Copies to RAM (and Texture)<br><br><dolphin_emphasis>If " |
| 199 | "unsure, leave this checked.</dolphin_emphasis>"); |
| 200 | static const char TR_IMMEDIATE_XFB_DESCRIPTION[] = QT_TR_NOOP( |
| 201 | "Displays XFB copies as soon as they are created, instead of waiting for " |
| 202 | "scanout.<br><br>Can cause graphical defects in some games if the game doesn't " |
| 203 | "expect all XFB copies to be displayed. However, turning this setting on reduces latency." |
| 204 | "<br><br>Enabling this also forces an effect equivalent to the " |
| 205 | "Skip Presenting Duplicate Frames setting." |
| 206 | "<br><br><dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 207 | static const char TR_SKIP_DUPLICATE_XFBS_DESCRIPTION[] = QT_TR_NOOP( |
| 208 | "Skips presentation of duplicate frames (XFB copies) in 25fps/30fps games. " |
| 209 | "This may improve performance on low-end devices, while making frame pacing less consistent." |
| 210 | "<br><br>Disable this option for optimal frame pacing." |
| 211 | "<br><br>This setting is unavailable when Immediately Present XFB or VBI Skip is " |
| 212 | "enabled. In those cases, duplicate frames are never presented." |
| 213 | "<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>"); |
| 214 | static const char TR_GPU_DECODING_DESCRIPTION[] = QT_TR_NOOP( |
| 215 | "Enables texture decoding using the GPU instead of the CPU.<br><br>This may result in " |
| 216 | "performance gains in some scenarios, or on systems where the CPU is the " |
| 217 | "bottleneck.<br><br>This setting is disabled when Arbitrary Mipmap Detection is " |
| 218 | "enabled.<br><br>" |
| 219 | "<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 220 | static const char TR_FAST_DEPTH_CALC_DESCRIPTION[] = QT_TR_NOOP( |
| 221 | "Uses a less accurate algorithm to calculate depth values.<br><br>Causes issues in a few " |
| 222 | "games, but can result in a decent speed increase depending on the game and/or " |
| 223 | "GPU.<br><br><dolphin_emphasis>If unsure, leave this checked.</dolphin_emphasis>"); |
| 224 | static const char TR_DISABLE_BOUNDINGBOX_DESCRIPTION[] = |
| 225 | QT_TR_NOOP("Disables bounding box emulation.<br><br>This may improve GPU performance " |
| 226 | "significantly, but some games will break.<br><br><dolphin_emphasis>If " |
| 227 | "unsure, leave this checked.</dolphin_emphasis>"); |
| 228 | static const char TR_SAVE_TEXTURE_CACHE_TO_STATE_DESCRIPTION[] = |
| 229 | QT_TR_NOOP("Includes the contents of the embedded frame buffer (EFB) and upscaled EFB copies " |
| 230 | "in save states. Fixes missing and/or non-upscaled textures/objects when loading " |
| 231 | "states at the cost of additional save/load time.<br><br><dolphin_emphasis>If " |
| 232 | "unsure, leave this checked.</dolphin_emphasis>"); |
| 233 | static const char TR_VERTEX_ROUNDING_DESCRIPTION[] = QT_TR_NOOP( |
| 234 | "Rounds 2D vertices to whole pixels and rounds the viewport size to a whole number.<br><br>" |
| 235 | "Fixes graphical problems in some games at higher internal resolutions. This setting has no " |
| 236 | "effect when native internal resolution is used.<br><br>" |
| 237 | "<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 238 | static const char TR_VI_SKIP_DESCRIPTION[] = |
| 239 | QT_TR_NOOP("Skips Vertical Blank Interrupts when lag is detected, allowing for " |
| 240 | "smooth audio playback when emulation speed is not 100%. <br><br>" |
| 241 | "Enabling this also forces the effect of the" |
| 242 | " Skip Presenting Duplicate Frames setting.<br><br>" |
| 243 | "<dolphin_emphasis>WARNING: Can cause freezes and compatibility " |
| 244 | "issues.</dolphin_emphasis> <br><br>" |
| 245 | "<dolphin_emphasis>If unsure, leave this unchecked.</dolphin_emphasis>"); |
| 246 | |
| 247 | m_skip_efb_cpu->SetDescription(tr(TR_SKIP_EFB_CPU_ACCESS_DESCRIPTION)); |
| 248 | m_ignore_format_changes->SetDescription(tr(TR_IGNORE_FORMAT_CHANGE_DESCRIPTION)); |
| 249 | m_store_efb_copies->SetDescription(tr(TR_STORE_EFB_TO_TEXTURE_DESCRIPTION)); |
| 250 | m_defer_efb_copies->SetDescription(tr(TR_DEFER_EFB_COPIES_DESCRIPTION)); |
| 251 | m_accuracy->SetTitle(tr("Texture Cache Accuracy")); |
| 252 | m_accuracy->SetDescription(tr(TR_ACCUARCY_DESCRIPTION)); |
| 253 | m_store_xfb_copies->SetDescription(tr(TR_STORE_XFB_TO_TEXTURE_DESCRIPTION)); |
| 254 | m_immediate_xfb->SetDescription(tr(TR_IMMEDIATE_XFB_DESCRIPTION)); |
| 255 | m_skip_duplicate_xfbs->SetDescription(tr(TR_SKIP_DUPLICATE_XFBS_DESCRIPTION)); |
| 256 | m_gpu_texture_decoding->SetDescription(tr(TR_GPU_DECODING_DESCRIPTION)); |
| 257 | m_fast_depth_calculation->SetDescription(tr(TR_FAST_DEPTH_CALC_DESCRIPTION)); |
| 258 | m_disable_bounding_box->SetDescription(tr(TR_DISABLE_BOUNDINGBOX_DESCRIPTION)); |
| 259 | m_save_texture_cache_state->SetDescription(tr(TR_SAVE_TEXTURE_CACHE_TO_STATE_DESCRIPTION)); |
| 260 | m_vertex_rounding->SetDescription(tr(TR_VERTEX_ROUNDING_DESCRIPTION)); |
| 261 | m_vi_skip->SetDescription(tr(TR_VI_SKIP_DESCRIPTION)); |
| 262 | } |
| 263 | |
| 264 | void HacksWidget::UpdateGPUTextureDecodingEnabled() |
| 265 | { |
| 266 | const bool gpu_texture_decoding = g_backend_info.bSupportsGPUTextureDecoding; |
| 267 | m_gpu_texture_decoding->setEnabled( |
| 268 | gpu_texture_decoding && !Get(m_game_layer, Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION)); |
| 269 | } |
| 270 | |
| 271 | void HacksWidget::UpdateDeferEFBCopiesEnabled() |
| 272 | { |
| 273 | // We disable the checkbox for defer EFB copies when both EFB and XFB copies to texture are |
| 274 | // enabled. |
| 275 | const bool can_defer = m_store_efb_copies->isChecked() && m_store_xfb_copies->isChecked(); |
| 276 | m_defer_efb_copies->setEnabled(!can_defer); |
| 277 | } |
| 278 | |
| 279 | void HacksWidget::UpdateSkipPresentingDuplicateFramesEnabled() |
| 280 | { |
| 281 | // If Immediate XFB is on, there's no point to skipping duplicate XFB copies as immediate presents |
| 282 | // when the XFB is created, therefore all XFB copies will be unique. |
| 283 | m_skip_duplicate_xfbs->setDisabled(m_immediate_xfb->isChecked() || m_vi_skip->isChecked()); |
| 284 | } |