From ed5e61a250c4e41636d578f56ff6a0a5fc164003 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 28 Mar 2021 15:07:41 +0200 Subject: [PATCH] Android: Add "Synchronize GPU Thread" setting (SyncOnSkipIdle/SyncGPU) Many Android users want to disable SyncOnSkipIdle as a performance hack, to the point where it's often suggested as something to paste into Dolphin.ini (if not to use a fork). If adding it as a setting in the GUI gives us an opportunity to explain what the setting actually does and stops people from pasting stuff they don't understand into INI files, I think it can be worth adding despite how it can make games unstable. It not being in the GUI doesn't seem to be stopping people from disabling it anyway. The added setting in the GUI is a three-way setting called "Synchronize GPU Thread" with the following alternatives: "Never": SyncGPU = False, SyncOnIdleSkip = False "On Idle Skipping": SyncGPU = False, SyncOnIdleSkip = True "Always": SyncGPU = True, SyncOnIdleSkip = True --- .../settings/model/BooleanSetting.java | 2 + .../ui/SettingsFragmentPresenter.java | 68 +++++++++++++++++++ .../app/src/main/res/values/arrays.xml | 11 +++ .../app/src/main/res/values/strings.xml | 2 + 4 files changed, 83 insertions(+) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java index d4bb8accce..4d26c39aa8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/BooleanSetting.java @@ -11,6 +11,7 @@ public enum BooleanSetting implements AbstractBooleanSetting MAIN_DSP_HLE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "DSPHLE", true), MAIN_FASTMEM(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "Fastmem", true), MAIN_CPU_THREAD(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "CPUThread", true), + MAIN_SYNC_ON_SKIP_IDLE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "SyncOnSkipIdle", true), MAIN_OVERRIDE_REGION_SETTINGS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "OverrideRegionSettings", false), MAIN_AUDIO_STRETCH(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "AudioStretch", false), @@ -19,6 +20,7 @@ public enum BooleanSetting implements AbstractBooleanSetting "WiimoteContinuousScanning", false), MAIN_WIIMOTE_ENABLE_SPEAKER(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "WiimoteEnableSpeaker", false), + MAIN_SYNC_GPU(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "SyncGPU", false), MAIN_OVERCLOCK_ENABLE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "OverclockEnable", false), MAIN_AUTO_DISC_CHANGE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "AutoDiscChange", false), MAIN_ALLOW_SD_WRITES(Settings.FILE_DOLPHIN, Settings.SECTION_INI_CORE, "WiiSDCardAllowWrites", diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 917c975ac4..d64844d7b4 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -434,6 +434,71 @@ public final class SettingsFragmentPresenter private void addAdvancedSettings(ArrayList sl) { + final int SYNC_GPU_NEVER = 0; + final int SYNC_GPU_ON_IDLE_SKIP = 1; + final int SYNC_GPU_ALWAYS = 2; + + AbstractIntSetting synchronizeGpuThread = new AbstractIntSetting() + { + @Override + public int getInt(Settings settings) + { + if (BooleanSetting.MAIN_SYNC_GPU.getBoolean(settings)) + { + return SYNC_GPU_ALWAYS; + } + else + { + boolean syncOnSkipIdle = BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.getBoolean(settings); + return syncOnSkipIdle ? SYNC_GPU_ON_IDLE_SKIP : SYNC_GPU_NEVER; + } + } + + @Override + public void setInt(Settings settings, int newValue) + { + switch (newValue) + { + case SYNC_GPU_NEVER: + BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.setBoolean(settings, false); + BooleanSetting.MAIN_SYNC_GPU.setBoolean(settings, false); + break; + + case SYNC_GPU_ON_IDLE_SKIP: + BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.setBoolean(settings, true); + BooleanSetting.MAIN_SYNC_GPU.setBoolean(settings, false); + break; + + case SYNC_GPU_ALWAYS: + BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.setBoolean(settings, true); + BooleanSetting.MAIN_SYNC_GPU.setBoolean(settings, true); + break; + } + } + + @Override + public boolean isOverridden(Settings settings) + { + return BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.isOverridden(settings) || + BooleanSetting.MAIN_SYNC_GPU.isOverridden(settings); + } + + @Override + public boolean isRuntimeEditable() + { + return BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.isRuntimeEditable() && + BooleanSetting.MAIN_SYNC_GPU.isRuntimeEditable(); + } + + @Override + public boolean delete(Settings settings) + { + // Not short circuiting + return BooleanSetting.MAIN_SYNC_ON_SKIP_IDLE.delete(settings) & + BooleanSetting.MAIN_SYNC_GPU.delete(settings); + } + }; + // TODO: Having different emuCoresEntries/emuCoresValues for each architecture is annoying. // The proper solution would be to have one set of entries and one set of values // and exclude the values that aren't present in PowerPC::AvailableCPUCores(). @@ -461,6 +526,9 @@ public final class SettingsFragmentPresenter R.string.overclock_enable_description)); sl.add(new PercentSliderSetting(FloatSetting.MAIN_OVERCLOCK, R.string.overclock_title, R.string.overclock_title_description, 0, 400, "%")); + sl.add(new SingleChoiceSetting(synchronizeGpuThread, R.string.synchronize_gpu_thread, + R.string.synchronize_gpu_thread_description, R.array.synchronizeGpuThreadEntries, + R.array.synchronizeGpuThreadValues)); } private void addGcPadSettings(ArrayList sl) diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index c08a518e5f..b8371321ec 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -447,6 +447,17 @@ -1 + + Never + On Idle Skipping + Always + + + 0 + 1 + 2 + + Use Device Sensors (With Pointer Emulation) Use Device Sensors (Without Pointer Emulation) diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 004a29731a..d4fb123dff 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -286,6 +286,8 @@ Higher values can make variable-framerate games run at a higher framerate, requiring a powerful device. Lower values make games run at a lower framerate, increasing emulation speed, but reducing the emulated console\'s performance. Emulated CPU Clock Speed Adjusts the emulated CPU\'s clock rate if \"Override Emulated CPU Clock Speed\" is enabled. + Synchronize GPU Thread + 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! Log