diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/AppVulkan.kt b/app/src/main/java/com/droiddeck/launcher/gpu/AppVulkan.kt index 437f232f86..59818f263d 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/AppVulkan.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/AppVulkan.kt @@ -27,18 +27,23 @@ data class AppVulkan( if (!DeviceSupport.vkBridge(context)) return null val native = VulkanInfo.query() val file = File(VkBridgeComponent.cacheDir(context), BRIDGE_FILE) - val fromBridge = FileUtils.readString(file)?.let { fromBridgeFile(it, native["device"]) } + val fromBridge = FileUtils.readString(file)?.let { fromBridgeFile(it, native["device"], native["api"]) } val found = fromBridge ?: fromDriver(native) Log.i(TAG, found?.label ?: "unknown (driver query: ${native["error"] ?: "no api line"})") return found } - internal fun fromBridgeFile(text: String, driverDevice: String?): AppVulkan? { + internal fun fromBridgeFile(text: String, driverDevice: String?, driverApi: String? = null): AppVulkan? { val map = keyValues(text) val device = map["device"] if (device != null && driverDevice != null && device != driverDevice) return null - val (major, minor) = version(map["api"]) ?: return null - return AppVulkan(major, minor, bool(map["shader_int64"]), map["max_push_constants"]?.toIntOrNull(), "bridge") + val fileDriver = version(map["driver_api"]) + val native = version(driverApi) + if (fileDriver != null && native != null && fileDriver != native) return null + val promoted = map["promotion"]?.trim()?.lowercase() == "on" + val (major, minor) = (if (promoted) version(map["api"]) else fileDriver ?: version(map["api"])) ?: return null + return AppVulkan(major, minor, bool(map["shader_int64"]), map["max_push_constants"]?.toIntOrNull(), + if (promoted) "bridge, promoted" else "bridge") } internal fun fromDriver(map: Map): AppVulkan? { diff --git a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt index ca5afd557c..17f3d93da2 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/ComponentsManager.kt @@ -1041,8 +1041,13 @@ object ComponentsManager { val p = proton(context, protonId) val state = loadState(context) val entry = state.sub("active").optJSONObject(p.id)?.optJSONObject(comp) - if (entry?.optString("protonVersion") == p.version && originalFile(context, p, comp).isFile) + val sameProton = entry?.optString("protonVersion") == p.version + if (sameProton && originalFile(context, p, comp).isFile) return restore(context, protonId, comp, safeName(p.version)) + if (sameProton) { + Log.w(TAG, "${p.name}: its own ${LABEL[comp]} copy is gone; keeping ${entry?.optString("label")}") + return "${LABEL[comp]}: ${p.name} keeps ${entry?.optString("label")} (its own copy is gone)" + } state.sub("active").optJSONObject(p.id)?.remove(comp) saveState(context, state) "${LABEL[comp]}: ${p.name} keeps its own copy" @@ -1064,11 +1069,13 @@ object ComponentsManager { if (rules.isEmpty() && !bridgeSession) return null val installed = protons(context) val lines = mutableListOf() - if (bridgeSession) { + fun each(p: Proton, what: () -> String): String = + runCatching(what).getOrElse { e -> Log.w(TAG, "${p.name}: ${e.message}", e); "${p.name}: ${e.message ?: e.javaClass.simpleName}" } + if (bridgeSession && vulkan != null) { val state = loadState(context) for (p in installed) { val entry = state.optJSONObject("active")?.optJSONObject(p.id)?.optJSONObject("dxvk") - if (bridgeRule == null && autoChoiceStale(entry, null)) lines.add(undoAuto(p.id, "dxvk")) + if (bridgeRule == null && autoChoiceStale(entry, null)) lines.add(each(p) { undoAuto(p.id, "dxvk") }) } } for ((rule, auto) in rules) { @@ -1085,7 +1092,7 @@ object ComponentsManager { continue } if (auto) lines.add("${vulkan?.label}: DXVK ${rule.file}") - lines.add(targets.joinToString("; ") { if (auto) applyAuto(it.id, rule.file) else apply(it.id, rule.file) }) + lines.add(targets.joinToString("; ") { p -> if (auto) each(p) { applyAuto(p.id, rule.file) } else apply(p.id, rule.file) }) } return lines.filter { it.isNotEmpty() }.joinToString("; ").ifEmpty { null } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/BridgeDxvkTest.kt b/app/src/test/java/com/droiddeck/launcher/session/BridgeDxvkTest.kt index 9bcc7b6829..5f621a23a4 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/BridgeDxvkTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/BridgeDxvkTest.kt @@ -59,13 +59,24 @@ class BridgeDxvkTest { } @Test fun theBridgesFileWinsForItsOwnGpuOnly() { - val text = "device=Mali-G710 MC10\napi=1.2.177\ndriver_api=1.1.177\nshader_int64=0\nmax_push_constants=128\n" - assertEquals(promoted, AppVulkan.fromBridgeFile(text, "Mali-G710 MC10")) - assertEquals(promoted, AppVulkan.fromBridgeFile(text, null)) + val text = "device=Mali-G710 MC10\napi=1.2.177\ndriver_api=1.1.177\npromotion=on\nshader_int64=0\nmax_push_constants=128\n" + val on = promoted.copy(source = "bridge, promoted") + assertEquals(on, AppVulkan.fromBridgeFile(text, "Mali-G710 MC10")) + assertEquals(on, AppVulkan.fromBridgeFile(text, null)) + assertEquals(on, AppVulkan.fromBridgeFile(text, "Mali-G710 MC10", "1.1.177")) assertNull(AppVulkan.fromBridgeFile(text, "Mali-G720 Immortalis MC12")) assertNull(AppVulkan.fromBridgeFile("device=x\n", null)) } + @Test fun withoutPromotionOnTheDriversVersionCounts() { + val g710File = g710.copy(source = "bridge") + val off = "device=Mali-G710 MC10\napi=1.1.177\ndriver_api=1.1.177\npromotion=off\nshader_int64=0\nmax_push_constants=128\n" + assertEquals(g710File, AppVulkan.fromBridgeFile(off, "Mali-G710 MC10", "1.1.177")) + val old = "device=Mali-G710 MC10\napi=1.3.177\ndriver_api=1.1.177\nshader_int64=0\nmax_push_constants=128\n" + assertEquals(g710File, AppVulkan.fromBridgeFile(old, "Mali-G710 MC10")) + assertNull(AppVulkan.fromBridgeFile(off, "Mali-G710 MC10", "1.3.212")) + } + @Test fun anAdrenoSessionIsNotTouched() { proton("proton-exp") assertNull(run(g710, bridge = false)) @@ -120,6 +131,30 @@ class BridgeDxvkTest { assertNull(state().getJSONObject("active").optJSONObject("proton-exp")?.optJSONObject("dxvk")) } + @Test fun aFailedDetectionKeepsTheLastAutomaticChoice() { + proton("proton-exp") + writeState("proton-exp", JSONObject().put("file", old).put("protonVersion", "experimental-11").put("auto", true)) + assertNull(run(null)) + assertEquals(old, state().getJSONObject("active").getJSONObject("proton-exp").getJSONObject("dxvk").getString("file")) + } + + @Test fun oneProtonFailingDoesNotStopTheOthers() { + proton("ge") + proton("proton-exp") + val applied = mutableListOf() + val result = run(g710, applyAuto = { id, file -> if (id == "ge") error("disk full"); applied += "$id $file"; "swapped $id" }) + assertEquals(listOf("proton-exp $old"), applied) + assertTrue(result!!, result.contains("disk full") && result.contains("swapped proton-exp")) + } + + @Test fun aChoiceWhoseSavedCopyIsGoneIsKept() { + proton("proton-exp") + writeState("proton-exp", JSONObject().put("file", old).put("label", "DXVK 1.10.3").put("protonVersion", "experimental-11").put("auto", true)) + val result = run(full, undoAuto = { id, comp -> ComponentsManager.undoAutoChoice(context, id, comp) }) + assertTrue(result!!, result.contains("its own copy is gone")) + assertEquals(old, state().getJSONObject("active").getJSONObject("proton-exp").getJSONObject("dxvk").getString("file")) + } + @Test fun aProtonUpdateWithNoRuleLeftJustForgetsTheChoice() { proton("proton-exp", "experimental-12") writeState("proton-exp", JSONObject().put("file", old).put("protonVersion", "experimental-11").put("auto", true))