fix(upscale): fixes from the first Elite test round

- Bridge DLLs: staged from an exact list (24 files) and only reported done when all of them are in
  place; the local copy is also read from the app's own external files folder, which needs no storage
  permission (Download/ alone could not be listed without it, so nothing was copied while the log said
  true). An installed add-on pack is staged again when the rootfs copy is gone.
- "Upscaler files" counts the bridge DLLs, not only the data files.
- FSR 4 / FSR 4 Lite: a render-sized D32 stand-in depth (cleared to the far plane) when the game sends
  none, as XeSS allows; both used to fall back to FSR 3.1 for such games.
- droiddeck-game-env writes the live switch file from the game's own settings at every launch, so the
  previous game's or the in-game menu's choice no longer wins at start.
- Intel's XeSS runtime goes into every upscaler game's prefix once downloaded (hard link where the file
  system allows), so XeSS 3 also works when picked in the in-game menu.
This commit is contained in:
The412Banner committed 2026-11-30 02:22:54 -05:00
1 parent 217817fa83
commit b6457b0cf7
6 files changed
+200 -53

No files matched your search

@@ -168,15 +168,26 @@ object UpscaleComponent {
if (engine.npu && npu) add(Group.NPU)
}
fun ready(context: Context, groups: Set<Group>): Boolean =
/** The bridge DLLs (tools/upscale/bridges/build.sh), each in both Wine PE folders. */
private val BRIDGE_NAMES = listOf(
"_nvngx.dll", "amd_fidelityfx_dx12.dll", "amd_fidelityfx_loader_dx12.dll", "amd_fidelityfx_upscaler_dx12.dll",
"amd_fidelityfx_upscaler_vk.dll", "amd_fidelityfx_vk.dll", "ffx_fsr2_api_x64.dll", "ffx_fsr3upscaler_x64.dll",
"libxess.dll", "nvapi64.dll", "nvngx.dll", "nvngx_dlss.dll",
)
internal val BRIDGE_FILES = listOf("x86_64-windows", "aarch64-windows").flatMap { arch -> BRIDGE_NAMES.map { "$arch/$it" } }
fun filesReady(context: Context, groups: Set<Group>): Boolean =
FILES.filter { it.group in groups }.all { f -> File(dataDir(context), f.relative).let { it.isFile && it.length() == f.size } }
fun bridgesReady(context: Context): Boolean = File(bridgesDir(context), "x86_64-windows/libxess.dll").isFile
fun bridgesReady(context: Context): Boolean =
BRIDGE_FILES.all { File(bridgesDir(context), it).let { f -> f.isFile && f.length() > 0 } }
/** Fetches what [groups] still lack (and the bridge pack) in the background. */
/** Everything a game with [groups] needs: the data files and the bridge DLLs. */
fun ready(context: Context, groups: Set<Group>): Boolean = filesReady(context, groups) && bridgesReady(context)
/** Fetches what [groups] still lack (data files, then the bridge DLLs) in the background. */
fun ensure(context: Context, groups: Set<Group>, onDone: (Boolean) -> Unit = {}) {
val app = context.applicationContext
ensureBridges(app)
if (ready(app, groups)) {
mutableState.value = State.Ready
onDone(true)
@@ -188,7 +199,13 @@ object UpscaleComponent {
}
Thread({
val ok = try {
download(app, groups)
val files = filesReady(app, groups) || download(app, groups)
val bridges = files && (bridgesReady(app) || fetchBridges(app))
when {
bridges -> mutableState.value = State.Ready
files -> mutableState.value = State.Failed("upscaler DLLs not installed")
}
bridges
} catch (e: Exception) {
Log.w(TAG, "upscaler files not fetched", e)
mutableState.value = State.Failed(e.message ?: e.javaClass.simpleName)
@@ -210,7 +227,7 @@ object UpscaleComponent {
val target = File(dataDir(context), f.relative)
target.parentFile?.mkdirs()
val part = File(target.path + ".part")
val ok = copyLocal(f, part) || Downloader.downloadFile(f.url, part, true, f.sha256) { p ->
val ok = copyLocal(context, f, part) || Downloader.downloadFile(f.url, part, true, f.sha256) { p ->
mutableState.value = State.Downloading(((done + p * f.size) / total).coerceIn(0f, 1f))
}
if (!ok || !part.renameTo(target)) {
@@ -227,19 +244,28 @@ object UpscaleComponent {
done += f.size
mutableState.value = State.Downloading((done.toFloat() / total).coerceIn(0f, 1f))
}
mutableState.value = State.Ready
Log.i(TAG, "upscaler files ready (${wanted.size} files, groups $groups)")
return true
}
/** A copy of the same file under Download/droiddeck-upscale (same relative path), used when its SHA-256 matches. */
private fun copyLocal(f: DataFile, part: File): Boolean = runCatching {
@Suppress("DEPRECATION")
val local = File(Environment.getExternalStorageDirectory(), "Download/$LOCAL_COPY/${f.relative}")
if (!local.isFile || local.length() != f.size || sha256(local) != f.sha256) return false
local.inputStream().use { input -> part.outputStream().use { output -> input.copyTo(output, 1 shl 20) } }
sha256(part) == f.sha256
}.getOrDefault(false)
/**
* Folders that may hold a local copy (same layout as the upstream tree): the app's own external
* files folders, readable without any storage permission, then Download/droiddeck-upscale.
*/
@Suppress("DEPRECATION")
private fun localRoots(context: Context): List<File> =
context.getExternalFilesDirs(null).orEmpty().filterNotNull().map { File(it, LOCAL_COPY) } +
File(Environment.getExternalStorageDirectory(), "Download/$LOCAL_COPY")
/** A local copy of [f] (see [localRoots]), used when its SHA-256 matches. */
private fun copyLocal(context: Context, f: DataFile, part: File): Boolean = localRoots(context).any { root ->
runCatching {
val local = File(root, f.relative)
if (!local.isFile || !local.canRead() || local.length() != f.size || sha256(local) != f.sha256) return@runCatching false
local.inputStream().use { input -> part.outputStream().use { output -> input.copyTo(output, 1 shl 20) } }
sha256(part) == f.sha256
}.getOrDefault(false)
}
private fun sha256(file: File): String {
val digest = MessageDigest.getInstance("SHA-256")
@@ -254,46 +280,53 @@ object UpscaleComponent {
return digest.digest().joinToString("") { "%02x".format(it) }
}
fun ensureBridges(context: Context) {
val app = context.applicationContext
if (localBridges() != null && !AddonPack.UPSCALE.installed(app)) {
Thread({ stageBridges(app) }, "upscale-bridges").start()
return
}
if (!AddonPack.UPSCALE.available) return
AddonPack.UPSCALE.ensure(app) { stageBridges(it) }
/** The add-on pack's bridges/ (fetched now when there is no local copy), staged into the rootfs. */
private fun fetchBridges(context: Context): Boolean {
val pack = AddonPack.UPSCALE
if (!pack.installed(context) && localBridges(context) == null && pack.available) pack.await(context)
return stageBridges(context)
}
/** A bridges/ tree beside the data files under Download/droiddeck-upscale: builds without a published pack. */
@Suppress("DEPRECATION")
private fun localBridges(): File? = runCatching {
File(Environment.getExternalStorageDirectory(), "Download/$LOCAL_COPY/bridges")
.takeIf { File(it, "x86_64-windows/libxess.dll").isFile }
}.getOrNull()
/** A complete, readable bridges/ tree in one of [localRoots]: builds without a published pack. */
private fun localBridges(context: Context): File? = localRoots(context).map { File(it, "bridges") }.firstOrNull { dir ->
runCatching { BRIDGE_FILES.all { File(dir, it).let { f -> f.isFile && f.canRead() && f.length() > 0 } } }.getOrDefault(false)
}
/** Copies the add-on pack's bridges/ tree (or the local one) into the rootfs, once per version. */
/**
* Copies the bridge DLLs from the add-on pack (or the local tree) into the rootfs, once per version. True only
* when every one of [BRIDGE_FILES] is in place afterwards.
*/
@Synchronized
fun stageBridges(context: Context): Boolean {
val pack = AddonPack.UPSCALE.takeIf { it.installed(context) }?.dir(context)
val source = pack?.let { File(it, "bridges") } ?: localBridges() ?: return bridgesReady(context)
if (!source.isDirectory) return false
val version = pack?.name ?: ("local-" + File(source, "x86_64-windows/libxess.dll").let { it.length().toString() + "-" + it.lastModified() })
val packDir = AddonPack.UPSCALE.takeIf { it.installed(context) }?.dir(context)
val pack = packDir?.let { File(it, "bridges") }
val source = pack?.takeIf { dir -> BRIDGE_FILES.all { File(dir, it).isFile } } ?: localBridges(context)
if (source == null) {
val ready = bridgesReady(context)
if (!ready) Log.w(TAG, "upscaler bridges: no add-on pack and no readable local copy")
return ready
}
val version = if (packDir != null && source == pack) packDir.name
else "local-" + File(source, "x86_64-windows/libxess.dll").let { it.length().toString() + "-" + it.lastModified() }
val target = bridgesDir(context)
val stamp = File(target, BRIDGES_STAMP)
if (bridgesReady(context) && runCatching { stamp.readText() }.getOrNull() == version) return true
var ok = true
source.walkTopDown().filter { it.isFile }.forEach { file ->
val out = File(target, file.relativeTo(source).path)
var copied = 0
for (name in BRIDGE_FILES) {
val from = File(source, name)
val out = File(target, name)
out.parentFile?.mkdirs()
val staged = File(out.path + ".staged")
ok = runCatching {
file.inputStream().use { input -> staged.outputStream().use { output -> input.copyTo(output) } }
staged.renameTo(out)
}.getOrDefault(false) && ok
val ok = runCatching {
from.inputStream().use { input -> staged.outputStream().use { output -> input.copyTo(output) } }
staged.length() == from.length() && staged.renameTo(out)
}.getOrDefault(false)
staged.delete()
if (ok) copied++ else Log.w(TAG, "upscaler bridge $name not staged from $source")
}
val ok = copied == BRIDGE_FILES.size && bridgesReady(context)
if (ok) runCatching { stamp.writeText(version) }
Log.i(TAG, "upscaler bridges staged from $version: $ok")
Log.i(TAG, "upscaler bridges staged from $version: $copied/${BRIDGE_FILES.size} files")
return ok
}