From 35794f4f18dcb4e596829e53135a34daef9f1149 Mon Sep 17 00:00:00 2001 From: t895 Date: Wed, 24 Jan 2024 13:47:41 -0500 Subject: [PATCH 1/2] android: Add current driver vendor to FPS overlay --- .../app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | 5 +++++ .../java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | 7 +++++-- src/android/app/src/main/jni/native.cpp | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) 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 c408485c62..5b9f553f7c 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 @@ -303,6 +303,11 @@ object NativeLibrary { */ external fun getCpuBackend(): String + /** + * Returns the current GPU Driver. + */ + external fun getGpuDriver(): String + external fun applySettings() external fun logSettings() 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 2a97ae14da..82f8e3b505 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 @@ -485,12 +485,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { val FRAMETIME = 2 val SPEED = 3 perfStatsUpdater = { - if (emulationViewModel.emulationStarted.value) { + if (emulationViewModel.emulationStarted.value && + !emulationViewModel.isEmulationStopping.value + ) { val perfStats = NativeLibrary.getPerfStats() val cpuBackend = NativeLibrary.getCpuBackend() + val gpuDriver = NativeLibrary.getGpuDriver() if (_binding != null) { binding.showFpsText.text = - String.format("FPS: %.1f\n%s", perfStats[FPS], cpuBackend) + String.format("FPS: %.1f\n%s/%s", perfStats[FPS], cpuBackend, gpuDriver) } perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 800) } diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index 963f573802..c6c55b20c1 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -674,6 +674,11 @@ jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getCpuBackend(JNIEnv* env, jclass return ToJString(env, "JIT"); } +jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getGpuDriver(JNIEnv* env, jobject jobj) { + return ToJString(env, + EmulationSession::GetInstance().System().GPU().Renderer().GetDeviceVendor()); +} + void Java_org_yuzu_yuzu_1emu_NativeLibrary_applySettings(JNIEnv* env, jobject jobj) { EmulationSession::GetInstance().System().ApplySettings(); } From 0fdd6e893460472766b92ce01acbe7755acb7bc0 Mon Sep 17 00:00:00 2001 From: t895 Date: Thu, 25 Jan 2024 07:05:36 -0500 Subject: [PATCH 2/2] android: Fix waiting for driver install on startup --- .../yuzu_emu/fragments/EmulationFragment.kt | 35 ++++++++++++------- .../yuzu/yuzu_emu/model/DriverViewModel.kt | 1 + src/android/app/src/main/jni/native.cpp | 1 + 3 files changed, 24 insertions(+), 13 deletions(-) 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 82f8e3b505..d17e087fef 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 @@ -38,7 +38,6 @@ import androidx.window.layout.WindowLayoutInfo import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.slider.Slider import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.yuzu.yuzu_emu.HomeNavigationDirections @@ -141,7 +140,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { // So this fragment doesn't restart on configuration changes; i.e. rotation. retainInstance = true - emulationState = EmulationState(game.path) + emulationState = EmulationState(game.path) { + return@EmulationState driverViewModel.isInteractionAllowed.value + } } /** @@ -370,6 +371,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } } } + launch { + repeatOnLifecycle(Lifecycle.State.RESUMED) { + driverViewModel.isInteractionAllowed.collect { + if (it) { + startEmulation() + } + } + } + } launch { repeatOnLifecycle(Lifecycle.State.CREATED) { emulationViewModel.emulationStarted.collectLatest { @@ -398,19 +408,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } } } - launch { - repeatOnLifecycle(Lifecycle.State.RESUMED) { - driverViewModel.isInteractionAllowed.collect { - if (it) { - onEmulationStart() - } - } - } - } } } - private fun onEmulationStart() { + private fun startEmulation() { if (!NativeLibrary.isRunning() && !NativeLibrary.isPaused()) { if (!DirectoryInitialization.areDirectoriesReady) { DirectoryInitialization.start() @@ -810,7 +811,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } } - private class EmulationState(private val gamePath: String) { + private class EmulationState( + private val gamePath: String, + private val emulationCanStart: () -> Boolean + ) { private var state: State private var surface: Surface? = null @@ -904,6 +908,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { State.PAUSED -> Log.warning( "[EmulationFragment] Surface cleared while emulation paused." ) + else -> Log.warning( "[EmulationFragment] Surface cleared while emulation stopped." ) @@ -913,6 +918,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { private fun runWithValidSurface() { NativeLibrary.surfaceChanged(surface) + if (!emulationCanStart.invoke()) { + return + } + when (state) { State.STOPPED -> { val emulationThread = Thread({ diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt index 15ae3a42b4..5ed754c96c 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/DriverViewModel.kt @@ -144,6 +144,7 @@ class DriverViewModel : ViewModel() { val selectedDriverFile = File(StringSetting.DRIVER_PATH.getString()) val selectedDriverMetadata = GpuDriverHelper.customDriverSettingData if (GpuDriverHelper.installedCustomDriverData == selectedDriverMetadata) { + setDriverReady() return } diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index c6c55b20c1..c20c2d2b89 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp @@ -247,6 +247,7 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string m_system.GetCpuManager().OnGpuReady(); m_system.RegisterExitCallback([&] { HaltEmulation(); }); + OnEmulationStarted(); return Core::SystemResultStatus::Success; }