From 3f52bf4b4b34922f9991e4696d27a8f432fe6ea2 Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Sat, 8 Aug 2026 04:39:47 +0200 Subject: [core, gpu, threads] Multithreading refactor (#4254) This insufferable work tries to cover some holes on previous threading implementation from yuzu's team, starting with Windows and Linux reordering of priorities (NICE), reworks previous Android's threading and cpu affinity with adpf, adjust emulated clocks/gpu for better "accuracy" with their work, bumps android minSDK for all flavors, legacy will now work with AP 29 to cover A10 - A12, standard will reach A13 as base and finally the optimized build will come with API 35, mostly targeted on devices with A15 support and newer, NDK and AGP wasn't upgraded yet. The performance cost efficiency have been improved based on device power configuration; preventing overheating if certain devices tended to fall into NICE0 (not allocated threads priority, all task ran with higher priority, 11 tasks running within the limited 2 - 7 threads available on the most common configuration 1x3x4 or 1x4x3). Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4254 --- src/android/app/build.gradle.kts | 3 +++ .../main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | 2 ++ .../features/settings/model/view/SettingsItem.kt | 2 +- .../settings/ui/SettingsFragmentPresenter.kt | 4 ++-- .../yuzu/yuzu_emu/fragments/EmulationFragment.kt | 1 + src/android/app/src/main/jni/native.cpp | 5 +++++ src/android/app/src/main/res/values-ar/strings.xml | 1 - src/android/app/src/main/res/values-de/strings.xml | 1 - src/android/app/src/main/res/values-es/strings.xml | 1 - src/android/app/src/main/res/values-fr/strings.xml | 1 - src/android/app/src/main/res/values-pl/strings.xml | 1 - src/android/app/src/main/res/values-ru/strings.xml | 1 - src/android/app/src/main/res/values-uk/strings.xml | 1 - .../app/src/main/res/values-zh-rCN/strings.xml | 1 - src/android/app/src/main/res/values/arrays.xml | 4 ++-- src/android/app/src/main/res/values/strings.xml | 24 ++++++++++++---------- .../app/src/main/res/xml/game_mode_config.xml | 2 +- 17 files changed, 30 insertions(+), 25 deletions(-) (limited to 'src/android') diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index a4076978a1..0cef7e7196 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts @@ -188,6 +188,7 @@ android { create("mainline") { dimension = "version" isDefault = true + minSdk = 33 manifestPlaceholders += mapOf("appNameBase" to "Eden") resValue("string", "app_name_suffixed", "Eden") @@ -199,6 +200,7 @@ android { create("genshinSpoof") { dimension = "version" + minSdk = 35 manifestPlaceholders += mapOf("appNameBase" to "Eden Optimized") resValue("string", "app_name_suffixed", "Eden Optimized") applicationId = "com.miHoYo.Yuanshen" @@ -216,6 +218,7 @@ android { create("legacy") { dimension = "version" + minSdk = 29 manifestPlaceholders += mapOf("appNameBase" to "Eden Legacy") resValue("string", "app_name_suffixed", "Eden Legacy") applicationId = "dev.legacy.eden_emulator" diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt index a8d6eaf6e1..797ac803eb 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt @@ -218,6 +218,8 @@ object NativeLibrary { external fun logSettings() + external fun refreshThreadPolicies() + external fun getDebugKnobAt(index: Int): Boolean /** diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt index 7c6063988f..63ac7b0630 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt @@ -594,7 +594,7 @@ abstract class SettingsItem( IntSetting.ANDROID_PIPELINE_WORKERS, titleId = R.string.pipeline_worker_cores, descriptionId = R.string.pipeline_worker_cores_description, - min = 4, + min = 2, max = 8, units = "cores" ) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt index 81702d7110..594099f159 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -250,8 +250,9 @@ class SettingsFragmentPresenter( add(BooleanSetting.USE_CUSTOM_RTC.key) add(LongSetting.CUSTOM_RTC.key) - add(HeaderSetting(R.string.cpu)) + add(HeaderSetting(R.string.clocks)) add(IntSetting.FAST_CPU_TIME.key) + add(IntSetting.FAST_GPU_TIME.key) add(BooleanSetting.CORE_SYNC_CORE_SPEED.key) add(IntSetting.MEMORY_LAYOUT.key) @@ -298,7 +299,6 @@ class SettingsFragmentPresenter( add(HeaderSetting(R.string.hacks)) - add(IntSetting.FAST_GPU_TIME.key) add(BooleanSetting.SKIP_CPU_INNER_INVALIDATION.key) add(BooleanSetting.FIX_BLOOM_EFFECTS.key) add(BooleanSetting.EMULATE_BGR565.key) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 0069e169b3..5b93c88161 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -1451,6 +1451,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { override fun onResume() { super.onResume() + NativeLibrary.refreshThreadPolicies() val b = _binding ?: return updateStatsPosition(IntSetting.PERF_OVERLAY_POSITION.getInt()) updateSocPosition(IntSetting.SOC_OVERLAY_POSITION.getInt()) diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 41ba1b2019..c367a06dfd 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -50,6 +50,7 @@ extern "C" { #include "common/scope_exit.h" #include "common/settings.h" #include "common/string_util.h" +#include "common/thread.h" #include "frontend_common/play_time_manager.h" #include "core/constants.h" #include "core/core.h" @@ -1182,6 +1183,10 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_logSettings(JNIEnv* env, jobject jobj Settings::LogSettings(); } +void Java_org_yuzu_yuzu_1emu_NativeLibrary_refreshThreadPolicies(JNIEnv* env, jobject jobj) { + Common::RefreshThreadPolicies(); +} + jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_getDebugKnobAt(JNIEnv* env, jobject jobj, jint index) { return static_cast(Settings::getDebugKnobAt(static_cast(index))); } diff --git a/src/android/app/src/main/res/values-ar/strings.xml b/src/android/app/src/main/res/values-ar/strings.xml index 616f160fd1..dd03ec453f 100644 --- a/src/android/app/src/main/res/values-ar/strings.xml +++ b/src/android/app/src/main/res/values-ar/strings.xml @@ -958,7 +958,6 @@ سريع (2000MHz) - تعطيل متوسط (256) مرتفع (512) diff --git a/src/android/app/src/main/res/values-de/strings.xml b/src/android/app/src/main/res/values-de/strings.xml index 182247580c..1c3b6c148f 100644 --- a/src/android/app/src/main/res/values-de/strings.xml +++ b/src/android/app/src/main/res/values-de/strings.xml @@ -884,7 +884,6 @@ Wirklich fortfahren? Schnell (2000MHz) - Aus Mittel (256) Hoch (512) diff --git a/src/android/app/src/main/res/values-es/strings.xml b/src/android/app/src/main/res/values-es/strings.xml index 37bd14b2d1..a5092c4b2f 100644 --- a/src/android/app/src/main/res/values-es/strings.xml +++ b/src/android/app/src/main/res/values-es/strings.xml @@ -950,7 +950,6 @@ Rápido (2000MHz) - Desactivado Medio (256) Alto (512) diff --git a/src/android/app/src/main/res/values-fr/strings.xml b/src/android/app/src/main/res/values-fr/strings.xml index 2cf6a1da91..602a542c5f 100644 --- a/src/android/app/src/main/res/values-fr/strings.xml +++ b/src/android/app/src/main/res/values-fr/strings.xml @@ -897,7 +897,6 @@ Rapide (2000MHz) - Désactivé Moyen (256) Élevé (512) diff --git a/src/android/app/src/main/res/values-pl/strings.xml b/src/android/app/src/main/res/values-pl/strings.xml index d96d420a98..4bcebd5a8c 100644 --- a/src/android/app/src/main/res/values-pl/strings.xml +++ b/src/android/app/src/main/res/values-pl/strings.xml @@ -871,7 +871,6 @@ Szybkie (2000MHz) - Wyłączone Średnie (256) Wysokie (512) diff --git a/src/android/app/src/main/res/values-ru/strings.xml b/src/android/app/src/main/res/values-ru/strings.xml index 6e85084b77..3dbeb6ffdb 100644 --- a/src/android/app/src/main/res/values-ru/strings.xml +++ b/src/android/app/src/main/res/values-ru/strings.xml @@ -954,7 +954,6 @@ Быстрая (2000MHz) - Выкл. Среднее (256) Высокое (512) diff --git a/src/android/app/src/main/res/values-uk/strings.xml b/src/android/app/src/main/res/values-uk/strings.xml index 86ea6ba787..83893210bd 100644 --- a/src/android/app/src/main/res/values-uk/strings.xml +++ b/src/android/app/src/main/res/values-uk/strings.xml @@ -943,7 +943,6 @@ Швидко (2000 МГц) - Вимкнено Середньо (256) Високо (512) diff --git a/src/android/app/src/main/res/values-zh-rCN/strings.xml b/src/android/app/src/main/res/values-zh-rCN/strings.xml index ff2db086e3..1e6ba26041 100644 --- a/src/android/app/src/main/res/values-zh-rCN/strings.xml +++ b/src/android/app/src/main/res/values-zh-rCN/strings.xml @@ -948,7 +948,6 @@ 快速 (2000MHz) - 关闭 中 (256) 高 (512) diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index 7a69d5b48b..1bad110d14 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -34,7 +34,7 @@ - @string/off + @string/clock_normal @string/clock_boost @string/clock_fast @@ -547,7 +547,7 @@ - @string/off + @string/fast_gpu_normal @string/fast_gpu_medium @string/fast_gpu_high diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 3023327f14..bb1d85db82 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -450,8 +450,8 @@ Set custom RTC - CPU Overclock - Forces the emulated CPU to run at a higher clock, reducing certain FPS limiters. Use Boost (1700MHz) to run at the Switch\'s highest native clock, or Fast (2000MHz) to run at 2x clock. + CPU Clocks + Raises the clock the emulated CPU reports, which removes some FPS limiters. Weaker CPUs may see reduced performance, and certain games may behave improperly. Custom CPU Ticks Set a custom value of CPU ticks. Higher values can increase performance, but may also cause the game to freeze. A range of 77–21000 is recommended. Ticks @@ -512,8 +512,8 @@ Hacks - Fast GPU Time - Forces most games to run at their highest native resolution. Use 256 for maximal performance and 512 for maximal graphics fidelity. + GPU Clocks + Makes the game believe GPU work finishes faster than it does, so it stops lowering resolution and render distance to fit the Switch\'s clocks. Skip CPU Inner Invalidation Skips certain CPU-side cache invalidations during memory updates, reducing CPU usage and improving it\'s performance. This may cause glitches or crashes on some games. Fix Bloom Effects @@ -560,6 +560,7 @@ CPU + Clocks Use Auto Stub Automatically stub missing services and functions. This may improve compatibility but can cause crashes and stability issues. @@ -968,14 +969,15 @@ 6GB (Unsafe) 8GB (Unsafe) - - Boost (1700MHz) - Fast (2000MHz) + + Normal + Boost + Overclock - - Off - Medium (256) - High (512) + + Normal + Boost + Overclock Very Small (16 MB) diff --git a/src/android/app/src/main/res/xml/game_mode_config.xml b/src/android/app/src/main/res/xml/game_mode_config.xml index 8f6e90d0d2..69e038cb5e 100644 --- a/src/android/app/src/main/res/xml/game_mode_config.xml +++ b/src/android/app/src/main/res/xml/game_mode_config.xml @@ -1,7 +1,7 @@ \ No newline at end of file -- cgit v1.2.3