diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index 0c1c3fd92..5f9a111fd 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -258,6 +258,10 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl // A Mali pair set by an earlier build put its PanVK Android half on the display, which fails // on Mali gralloc. Under Auto the display is the phone's own driver (Android's loader). if (gpu.family.mali) { + // Builds before 0.5.0-nad1 turned the bridge on under Auto without recording it, and + // left it on for good (it wins over the pair). Under Auto that switch is taken as Auto's. + if (!SessionPrefs.maliFallbackKnown(activity)) + SessionPrefs.setMaliFallbackByAuto(activity, if (SessionPrefs.vkBridge(activity)) "bridge" else "") val display = SessionPrefs.androidDriver(activity) if (display.isNotEmpty() && DriverPairs.isNonAdreno(DriverBundle.containing(activity, display, false)?.id)) { SessionPrefs.setAndroidDriver(activity, TurnipDriver.AUTO) @@ -296,8 +300,8 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl } Log.i(TAG, "auto: ${gpu.name} (${gpu.family}) -> " + (DriverPairs.recommendedKey(gpu, emptyList()) ?: "no pair")) if (gpu.family.mali && DriverPairs.recommendedKey(gpu, emptyList()) == null) { - useMaliBridge() - autoStatus = activity.getString(R.string.drivers_mali_bridge_auto) + // No PanVK build covers this Mali (e.g. the G1 series, arch v14): the phone's own driver. + autoStatus = useMaliFallback(null) refreshDrivers() return } @@ -327,10 +331,13 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl autoStatus = activity.getString(R.string.drivers_powervr_builtin) refreshDrivers() } + gpu.family.mali && (pair == null || !pair.complete) && + (problem != null || TurnipReleases.cached(activity)?.failed?.contains(TurnipReleases.NON_ADRENO_LABEL) == true) -> + // The list could not be read: nothing is known to be missing, so nothing is switched. + autoStatus = activity.getString(R.string.upd_couldnt_check, problem ?: TurnipReleases.NON_ADRENO_LABEL) gpu.family.mali && (pair == null || !pair.complete) -> { - // No open driver for this Mali published yet: draw through the bridge. - useMaliBridge() - autoStatus = activity.getString(R.string.drivers_mali_bridge_fallback, key?.let { DriverPairs.nonAdrenoName(it) } ?: gpu.name) + // No open driver for this Mali published yet: the phone's own driver until it is. + autoStatus = useMaliFallback(key?.let { DriverPairs.nonAdrenoName(it) } ?: gpu.name) refreshDrivers() } pair == null || !pair.complete -> @@ -345,12 +352,42 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl }, "gpu-driver-auto").start() } - private fun useMaliBridge() { - if (DeviceSupport.openDriverActive(activity)) { - SessionPrefs.setAndroidDriver(activity, TurnipDriver.AUTO) - SessionPrefs.setLinuxDriver(activity, "") + /** + * A Mali with no open driver pair to install ([missing] names the unpublished pair, or null when + * no PanVK build covers this GPU) runs through the phone's own driver: Mali (Venus) where this + * apk carries it (Steam runs on it from the G57 to the G1 series), the Mali bridge otherwise. + * Both need Vulkan 1.2 from the phone's driver for gamescope, so with an older one nothing is + * switched on. The Linux driver choice is left alone (it is the bridge's fallback), and Auto + * switches only its own choice off again once a pair is installed ([endMaliFallback]). + */ + private fun useMaliFallback(missing: String?): String { + com.droiddeck.launcher.session.VenusComponent.hostVulkanTooOld(activity)?.let { api -> + Log.i(TAG, "auto: Mali driver reports Vulkan $api; no Venus or bridge for gamescope") + return activity.getString(R.string.drivers_mali_vulkan_too_old, missing ?: gpu.name, api) } - SessionPrefs.setVkBridge(activity, true) + val venus = com.droiddeck.launcher.session.VenusComponent.available(activity) + if (venus && !SessionPrefs.venus(activity)) { + SessionPrefs.setVenus(activity, true) + SessionPrefs.setMaliFallbackByAuto(activity, "venus") + } else if (!venus && !SessionPrefs.vkBridge(activity)) { + SessionPrefs.setVkBridge(activity, true) + SessionPrefs.setMaliFallbackByAuto(activity, "bridge") + } + val route = activity.getString(if (venus) R.string.drivers_route_venus else R.string.drivers_route_bridge) + Log.i(TAG, "auto: Mali stand-in route $route (missing pair: ${missing ?: "none covers ${gpu.name}"})") + return if (missing == null) activity.getString(R.string.drivers_mali_no_pair_auto, route) + else activity.getString(R.string.drivers_mali_unpublished_auto, missing, route) + } + + /** A pair is installed for this Mali: the route Auto switched on in its place goes off again. */ + private fun endMaliFallback() { + when (SessionPrefs.maliFallbackByAuto(activity)) { + "venus" -> SessionPrefs.setVenus(activity, false) + "bridge" -> SessionPrefs.setVkBridge(activity, false) + else -> return + } + Log.i(TAG, "auto: pair installed; ${SessionPrefs.maliFallbackByAuto(activity)} (Auto's stand-in) off") + SessionPrefs.setMaliFallbackByAuto(activity, "") } fun selectPair(key: String) { @@ -409,8 +446,10 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl val displayChanged = previousDisplay != displayId SessionPrefs.setAndroidDriver(activity, displayId) SessionPrefs.setLinuxDriver(activity, linuxId) - // The Mali bridge switch is the user's and is left as it is: when it is on, the - // bridge wins for the session (DeviceSupport.vkBridge) and the pair waits. + // A route Auto switched on in place of a missing pair goes off now that one is + // here. A Mali bridge or Venus switch the user set stays: it wins for the session + // (DeviceSupport.vkBridge, VenusComponent.wanted) and the pair waits. + if (gpu.family.mali && DriverPairs.isNonAdreno(pair.key)) endMaliFallback() val restart = displayChanged && CompositorHost.isStarted if (auto) { val trial = AutoDriverTrial.current(activity) diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 349fde979..41a8234f3 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -904,9 +904,10 @@ class MainActivity : ComponentActivity() { onInstallPackage = { id -> installPackage(id) }, onRemovePackage = { id -> removePackage(id) }, onRuntime = { onRuntimeButton() }, - onVkBridge = { on -> SessionPrefs.setVkBridge(this, on); vkBridge = on }, + onVkBridge = { on -> SessionPrefs.setVkBridge(this, on); SessionPrefs.setMaliFallbackByAuto(this, ""); vkBridge = on }, onVenus = { on -> SessionPrefs.setVenus(this, on) + SessionPrefs.setMaliFallbackByAuto(this, "") venus = on if (on && !com.droiddeck.launcher.core.DeviceSupport.adreno()) Thread({ com.droiddeck.launcher.gpu.VulkanInfo.query()["api"]?.let { SessionPrefs.setHostVulkanApi(this, it) } @@ -1192,6 +1193,9 @@ class MainActivity : ComponentActivity() { com.droiddeck.launcher.frontend.GamesFolderMigration.run(this) SessionLogShare.clear(this) SessionArtifacts.finishAbandoned(this) + if (SessionPrefs.takeMemoryKillNotice(this)) runOnUiThread { + android.widget.Toast.makeText(this, R.string.session_killed_for_memory, android.widget.Toast.LENGTH_LONG).show() + } SessionArtifacts.scrubOlder(this) SessionArtifacts.prune(this) }, "finish-abandoned").start() diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt b/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt index 80d9e75c1..e58191e89 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/GpuInfo.kt @@ -57,7 +57,7 @@ data class GpuInfo( Support.UNTESTED -> when (family) { Family.POWERVR -> if (name.contains("Xclipse", ignoreCase = true)) "Experimental: RADV or the system Xclipse driver" else "System PowerVR driver: compatibility varies by device" - Family.MALI_OTHER -> "Experimental: Mali through the Vulkan bridge" + Family.MALI_OTHER -> "Experimental: Mali through the phone's own driver (Venus)" Family.MALI_JM, Family.MALI_G610_G710, Family.MALI_G615, Family.MALI_G720, Family.MALI_LATEST -> "Experimental: open Mali driver (test builds)" Family.A7XX_LOW -> "Experimental: its drivers are test builds" else -> "Outside tested hardware (Adreno 650, 725 and newer): it may not run" @@ -152,7 +152,7 @@ data class GpuInfo( /** Chips whose Mali is known for certain (MediaTek Dimensity / Helio / Kompanio, Google Tensor). */ private val MALI_SOCS = mapOf( - "mt6991" to "Mali-G925", "mt6989" to "Mali-G720", "mt6899" to "Mali-G720", "mt6985" to "Mali-G715", + "mt6993" to "Mali-G1-Ultra", "mt6991" to "Mali-G925", "mt6989" to "Mali-G720", "mt6899" to "Mali-G720", "mt6985" to "Mali-G715", "mt6983" to "Mali-G710", "mt6897" to "Mali-G615", "mt6878" to "Mali-G615", "mt6895" to "Mali-G610", "mt6896" to "Mali-G610", "mt6886" to "Mali-G610", "mt6893" to "Mali-G77", "mt6891" to "Mali-G77", "mt6889" to "Mali-G77", "mt6885" to "Mali-G77", "mt6877" to "Mali-G68", "mt6853" to "Mali-G57", diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt index 05de23d81..6356229bd 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipReleases.kt @@ -63,7 +63,7 @@ object TurnipReleases { // -Pair.zip: open drivers for GPUs that are not Adreno (PanVK for Mali, RADV for // Xclipse), both halves in one zip. One release per driver, replaced in place on each // rebuild; every one is a test build, published as a pre-release. - Source("Non-Adreno", NON_ADRENO_REPO, prerelease = true) { name, _ -> + Source(NON_ADRENO_LABEL, NON_ADRENO_REPO, prerelease = true) { name, _ -> val m = Regex("""^(RADV-Xclipse(?:-[A-Za-z0-9]+)*?|PanVK-[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*?)-Pair\.zip$""").find(name) ?: return@Source null val key = DriverPairs.nonAdreno(m.groupValues[1]) Kind(false, "Android + Linux ยท " + DriverPairs.nonAdrenoName(key), key, bundle = true) @@ -71,6 +71,7 @@ object TurnipReleases { ) private const val NON_ADRENO_REPO = "The412Banner/droiddeck-nonadreno-drivers" + const val NON_ADRENO_LABEL = "Non-Adreno" private fun sources(): List = if (com.droiddeck.launcher.core.DeviceSupport.adreno()) SOURCES.filter { it.repo != NON_ADRENO_REPO } else SOURCES @@ -88,7 +89,10 @@ object TurnipReleases { val sources = sources() for (src in sources) { try { - val releases = JSONArray(get(context, "https://api.github.com/repos/${src.repo}/releases?per_page=15")) + // The non-Adreno repo keeps one release per driver plus many component builds (gamescope, + // Venus): its driver pairs fall past the first 15, so it is read in one full page. + val perPage = if (src.repo == NON_ADRENO_REPO) 100 else 15 + val releases = JSONArray(get(context, "https://api.github.com/repos/${src.repo}/releases?per_page=$perPage")) val seen = HashSet() var newest: String? = null for (i in 0 until releases.length()) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index a01b37e8a..f9d7e46ac 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -216,13 +216,19 @@ object SessionArtifacts { Log.i(TAG, "collected ${out.listFiles()?.size ?: 0} Steam log(s), scrubbed, into $out") } + /** + * Finishes the folders of sessions whose process died without its teardown. Returns true when + * the newest of them ended because Android killed the app for memory, so the app can say so + * (a game "crashing" on a phone with little free RAM is usually this, not a driver fault). + */ @Synchronized - fun finishAbandoned(context: Context) { + fun finishAbandoned(context: Context): Boolean { val parent = LinuxRuntime.logDir(context) val abandoned = parent.listFiles { f -> SessionPaths.isSessionFolder(f) && !File(f, COMPLETE_MARKER).exists() && !inFlight(f) - }?.sortedWith(SessionPaths.chronological) ?: return - if (abandoned.isEmpty()) return + }?.sortedWith(SessionPaths.chronological) ?: return false + if (abandoned.isEmpty()) return false + var killedForMemory = false val current = SessionPaths.current() LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) abandoned.forEachIndexed { i, dir -> @@ -240,6 +246,7 @@ object SessionArtifacts { "session died of a crash, the entry is in there unless the device rebooted.\n" + (if (newest) exitReasons(context) else "") ) + if (newest && lastExitForMemory(context)) killedForMemory = true val record = Record(dir) if (newest) { copySteamLogs(context, dir, record, recordedClient(dir)) @@ -254,6 +261,21 @@ object SessionArtifacts { Log.w(TAG, "could not finish $dir", e) } } + // Whoever finishes the folder first (the agent provider starts before the activity) leaves + // the notice for the launcher to show. + if (killedForMemory) SessionPrefs.setMemoryKillNotice(context, true) + return killedForMemory + } + + /** Android's newest record for this app's main process says it was killed for memory. */ + private fun lastExitForMemory(context: Context): Boolean { + if (android.os.Build.VERSION.SDK_INT < 30) return false + return runCatching { + val am = context.getSystemService(android.app.ActivityManager::class.java) ?: return false + am.getHistoricalProcessExitReasons(context.packageName, 0, 3) + .firstOrNull { it.processName == context.packageName } + ?.reason == android.app.ApplicationExitInfo.REASON_LOW_MEMORY + }.getOrDefault(false) } private fun exitReasons(context: Context): String { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 813393645..20688e1fa 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -483,6 +483,31 @@ object SessionPrefs { prefs(context).edit().putBoolean("steamGpuCompositing", on && steamGpuCompositingAllowed()).apply() } + /** + * The route Auto switched on for a Mali that has no open driver pair yet ("venus" or "bridge"), + * or "" when the user's own Setup switches are in charge. Auto turns only its own choice off + * again once a pair is installed; a Setup switch the user flips clears this. + */ + /** The last session's process was killed by Android for memory; the launcher says so once. */ + fun takeMemoryKillNotice(context: Context): Boolean { + val on = prefs(context).getBoolean("memoryKillNotice", false) + if (on) prefs(context).edit().putBoolean("memoryKillNotice", false).apply() + return on + } + + fun setMemoryKillNotice(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("memoryKillNotice", on).apply() + } + + fun maliFallbackByAuto(context: Context): String = prefs(context).getString("maliFallbackByAuto", "").orEmpty() + + /** Whether [maliFallbackByAuto] was ever recorded (builds before it left the bridge on without saying who). */ + fun maliFallbackKnown(context: Context): Boolean = prefs(context).contains("maliFallbackByAuto") + + fun setMaliFallbackByAuto(context: Context, route: String) { + prefs(context).edit().putString("maliFallbackByAuto", route).apply() + } + fun setVenus(context: Context, on: Boolean) { prefs(context).edit().putBoolean("venus", on).apply() } diff --git a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt index 222d30859..8265e21c6 100644 --- a/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt +++ b/app/src/main/java/com/droiddeck/launcher/update/AppUpdates.kt @@ -74,6 +74,12 @@ object AppUpdates { val updatable: Boolean, val committedAt: Long = 0L, val ciBuild: Boolean = BuildConfig.CI_BUILD, + /** + * A build of the non-Adreno test branch (Mali / Xclipse / PowerVR routes). The official + * channels carry the Adreno-only app: installing one over it drops those routes, so none is + * offered. Its updates are published on The412Banner/droiddeck-nonadreno-drivers. + */ + val nonAdrenoTest: Boolean = false, ) enum class PreviewHistoryKind { CURRENT, BEHIND, RECENT } @@ -125,6 +131,7 @@ object AppUpdates { BuildConfig.VERSION_CODE, releaseSigned, BuildConfig.COMMIT_TIME, + nonAdrenoTest = BuildConfig.BUILD_LABEL.contains("non-adreno"), ) fun release(catalog: Catalog, follow: Follow): Release? = when (follow.channel) { @@ -191,6 +198,7 @@ object AppUpdates { } fun installBlock(r: Release, me: Installed = installed()): InstallBlock? = when { + me.nonAdrenoTest -> InstallBlock(R.string.upd_block_non_adreno_test) r.apk == null -> InstallBlock(R.string.upd_block_no_apk) r.apk.versionCode < me.versionCode -> InstallBlock(R.string.upd_block_version_code, r.apk.versionCode, me.versionCode) else -> null diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8aad0781c..b7ac5c171 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1854,6 +1854,13 @@ Uses the built-in drivers for this GPU The system PowerVR driver is selected for the runtime and display. No open driver covers this Mali yet: the Mali bridge is on. + This is the non-Snapdragon test build: the official builds here only run on Adreno, so they are not installed over it. New test builds are on github.com/The412Banner/droiddeck-nonadreno-drivers. + The last session ended because Android closed DroidDeck to free memory, not a crash. Close other apps or lower the game\'s texture settings, then try again. + Mali (Venus) + the Mali bridge + No open driver covers this Mali yet: %1$s is used, on the phone\'s own driver. + %1$s isn\'t published yet: %2$s is used until it is. + %1$s isn\'t available, and this phone\'s driver reports Vulkan %2$s (Venus and the Mali bridge need 1.2). Pick a PanVK pair under Driver pairs. %1$s isn\'t published yet: the Mali bridge is on until it is. Queued: %1$s (waiting for a different runtime driver) DXVK is provided by the system PowerVR runtime. Other DXVK packages can be stored but are not applied with this driver. diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt index b5686401d..065c30896 100644 --- a/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/gpu/DriverPairsTest.kt @@ -248,6 +248,13 @@ class DriverPairsTest { assertTrue(GpuInfo.maliKbaseCovered("Mali-G720 (by chip mt6989)")) } + @Test + fun theMaliG1SeriesHasNoPanVkPairAndIsKnownByItsChip() { + // Arch v14 (Dimensity 9500): no PanVK build is proven there, so Auto uses the phone's own driver. + assertEquals("Mali-G1-Ultra (by chip mt6993)", GpuInfo.maliOfSoc(listOf("MT6993"))) + assertEquals(Family.MALI_OTHER, GpuInfo.familyOf(false, 0, mali = "Mali-G1-Ultra MC12")) + } + @Test fun autoTakesRadvOnAnXclipseAndLeavesPowerVrOnTheSystemDriver() { assertEquals(DriverPairs.NAD_RADV_XCLIPSE, DriverPairs.recommendedKey(GpuInfo("Samsung Xclipse 940", 0, Family.POWERVR, "", false), emptyList())) diff --git a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt index ada2ff3be..a81d9ad78 100644 --- a/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/update/AppUpdatesTest.kt @@ -129,6 +129,12 @@ class AppUpdatesTest { assertNull(AppUpdates.installBlock(stable, me("eeeeeee", versionCode = 9))) } + @Test + fun theNonAdrenoTestBuildIsNeverReplacedByAnOfficialBuild() { + val testBuild = AppUpdates.Installed("eeeeeee", 0, "0.2.0", 9, updatable = true, nonAdrenoTest = true) + assertNotNull(AppUpdates.installBlock(stable, testBuild)) + } + @Test fun aMissingVariantIsBlockedBeforeDownload() { val missing = release("ddddddd", withApk = false) diff --git a/tools/vkbridge/client/cmdbuf.c b/tools/vkbridge/client/cmdbuf.c index 5d7e7f624..0e3c23237 100644 --- a/tools/vkbridge/client/cmdbuf.c +++ b/tools/vkbridge/client/cmdbuf.c @@ -170,8 +170,17 @@ VKAPI_ATTR VkResult VKAPI_CALL vkb_ep_vkBeginCommandBuffer(VkCommandBuffer comma vkb_enc *e = vkb_cmd_record_begin(commandBuffer, VKB_CMD_vkBeginCommandBuffer); vkb_enc_u64(e, cb->obj.remote); tls_encoding = cb; - vkb_enc_u8(e, pBeginInfo != NULL); - if (pBeginInfo) vkb_enc_VkCommandBufferBeginInfo(e, pBeginInfo); + /* The server decodes a present pointer as a count and that many structs (vkb_sv_vkBeginCommandBuffer, + * as vkb_wire_vkBeginCommandBuffer sends it). Without the count it read 0 and handed Mali a zeroed + * 16-byte begin info, so flags and pInheritanceInfo came from stale memory: the driver crashed in + * vkBeginCommandBuffer at 0x10 whenever those flags had RENDER_PASS_CONTINUE set. */ + if (pBeginInfo) { + vkb_enc_u8(e, 1); + vkb_enc_u32(e, 1); + vkb_enc_VkCommandBufferBeginInfo(e, pBeginInfo); + } else { + vkb_enc_u8(e, 0); + } tls_encoding = NULL; vkb_cmd_record_end(commandBuffer); return cb->broken ? VK_ERROR_OUT_OF_HOST_MEMORY : VK_SUCCESS;