From fa17d909ce7b4b53516b3f2a5f4e5e0df35a547f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sun, 29 Nov 2026 00:21:56 -0500 Subject: [PATCH] feat(gpu): detect the Hexagon NPU and whether the app can reach it, and document neural upscaling findings --- .../com/droiddeck/launcher/gpu/DeviceInfo.kt | 6 +- .../com/droiddeck/launcher/gpu/NpuInfo.kt | 63 +++++++++++++++++++ .../com/droiddeck/launcher/gpu/NpuInfoTest.kt | 44 +++++++++++++ docs/development/npu-upscaler.md | 54 ++++++++++++++++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/gpu/NpuInfo.kt create mode 100644 app/src/test/java/com/droiddeck/launcher/gpu/NpuInfoTest.kt create mode 100644 docs/development/npu-upscaler.md diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt index 45a396b652..e6cc51ec99 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DeviceInfo.kt @@ -16,7 +16,7 @@ object DeviceInfo { val vk = VulkanInfo.query() val gpu = GpuInfo.detect() return listOf( - chip(), gpu(context, gpu), cpu(), memory(context), system(), vulkan(context, vk), drivers(context, gpu), + chip(), gpu(context, gpu), npu(context), cpu(), memory(context), system(), vulkan(context, vk), drivers(context, gpu), ).filter { it.rows.isNotEmpty() } } @@ -51,6 +51,10 @@ object DeviceInfo { add("Family", read("/sys/devices/soc0/family")) }) + private fun npu(context: Context) = Section("NPU", NpuInfo.rows( + NpuInfo.detect(context.applicationInfo.nativeLibraryDir?.let(::File)), + )) + private fun gpu(context: Context, gpu: GpuInfo) = Section("GPU", buildList> { add("GPU", gpu.name) add("Family", gpu.family.label(gpu.name)) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/NpuInfo.kt b/app/src/main/java/com/droiddeck/launcher/gpu/NpuInfo.kt new file mode 100644 index 0000000000..4a88d5a562 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/gpu/NpuInfo.kt @@ -0,0 +1,63 @@ +package com.droiddeck.launcher.gpu + +import java.io.File + +/** What this device's Qualcomm Hexagon NPU would offer a neural upscaler, and whether the app can reach it. */ +object NpuInfo { + enum class Hexagon(val arch: String, val vtcmMb: Int) { + V68("v68", 4), V69("v69", 4), V73("v73", 4), V75("v75", 8), V79("v79", 8), V81("v81", 8), + } + + enum class Access { OPEN, NO_NODE, DENIED } + + data class Status( + val hexagon: Hexagon?, + val node: String?, + val access: Access, + val qnnRuntime: Boolean, + ) { + val usable: Boolean get() = hexagon != null && access == Access.OPEN && qnnRuntime + } + + private val BY_MODEL = mapOf( + "SM8350" to Hexagon.V68, "SM8450" to Hexagon.V69, "SM8475" to Hexagon.V69, + "SM8550" to Hexagon.V73, "QCS8550" to Hexagon.V73, "SM8650" to Hexagon.V75, + "SM8750" to Hexagon.V79, "SM8850" to Hexagon.V81, + ) + private val BY_PLATFORM = mapOf( + "lahaina" to Hexagon.V68, "taro" to Hexagon.V69, "cape" to Hexagon.V69, "kalama" to Hexagon.V73, + "pineapple" to Hexagon.V75, "sun" to Hexagon.V79, "canoe" to Hexagon.V81, + ) + + // The compute DSP is the one that runs HTP graphs; /dev/adsprpc-smd is the pre-5.x name of the same service. + internal val NODES = listOf("/dev/fastrpc-cdsp", "/dev/adsprpc-smd", "/dev/cdsprpc-smd") + internal val QNN_LIBS = listOf("libQnnHtp.so", "libQnnSystem.so") + + fun hexagon( + model: String = SocNames.model(), + platform: String = GpuInfo.systemProperty("ro.board.platform"), + ): Hexagon? = BY_MODEL[SocNames.normalizedModel(model)] ?: BY_PLATFORM[platform.trim().lowercase()] + + /** `canWrite` is access(2) for the app's own uid, so it answers for DAC but not SELinux. */ + internal fun access(nodes: List): Pair { + val present = nodes.firstOrNull { it.exists() } ?: return null to Access.NO_NODE + return present to if (present.canRead() && present.canWrite()) Access.OPEN else Access.DENIED + } + + fun detect(nativeLibDir: File?, hexagon: Hexagon? = hexagon()): Status { + val (node, access) = access(NODES.map(::File)) + val qnn = nativeLibDir != null && QNN_LIBS.all { File(nativeLibDir, it).exists() } + return Status(hexagon, node?.path, access, qnn) + } + + fun rows(status: Status): List> = buildList { + add("Hexagon" to (status.hexagon?.let { "${it.arch} (${it.vtcmMb} MB VTCM)" } ?: "not recognised")) + add("FastRPC node" to when (status.access) { + Access.NO_NODE -> "none found" + Access.OPEN -> "${status.node} (app can open it)" + Access.DENIED -> "${status.node} (app cannot open it)" + }) + add("QNN runtime" to if (status.qnnRuntime) "bundled" else "not bundled") + add("Neural upscaling" to if (status.usable) "possible" else "not available") + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/gpu/NpuInfoTest.kt b/app/src/test/java/com/droiddeck/launcher/gpu/NpuInfoTest.kt new file mode 100644 index 0000000000..693408ad55 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/gpu/NpuInfoTest.kt @@ -0,0 +1,44 @@ +package com.droiddeck.launcher.gpu + +import java.io.File +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class NpuInfoTest { + @get:Rule val tmp = TemporaryFolder() + + @Test fun modelPicksTheHexagonGenerationAndFallsBackToThePlatform() { + assertEquals(NpuInfo.Hexagon.V79, NpuInfo.hexagon("SM8750", "sun")) + assertEquals(NpuInfo.Hexagon.V81, NpuInfo.hexagon("QTI SM8850", "")) + assertEquals(NpuInfo.Hexagon.V73, NpuInfo.hexagon("", "Kalama")) + assertNull(NpuInfo.hexagon("MT6989", "mt6989")) + } + + @Test fun nodeAccessSeparatesMissingFromDenied() { + assertEquals(NpuInfo.Access.NO_NODE, NpuInfo.access(listOf(File(tmp.root, "nope"))).second) + val node = tmp.newFile("fastrpc-cdsp") + assertEquals(NpuInfo.Access.OPEN, NpuInfo.access(listOf(File(tmp.root, "nope"), node)).second) + node.setWritable(false) + if (!node.canWrite()) assertEquals(NpuInfo.Access.DENIED, NpuInfo.access(listOf(node)).second) + } + + @Test fun usableNeedsChipNodeAndRuntime() { + val ok = NpuInfo.Status(NpuInfo.Hexagon.V79, "/dev/fastrpc-cdsp", NpuInfo.Access.OPEN, true) + assertTrue(ok.usable) + assertFalse(ok.copy(access = NpuInfo.Access.DENIED).usable) + assertFalse(ok.copy(qnnRuntime = false).usable) + assertFalse(ok.copy(hexagon = null).usable) + } + + @Test fun runtimeIsBundledOnlyWhenEveryLibraryIsPresent() { + NpuInfo.QNN_LIBS.dropLast(1).forEach { File(tmp.root, it).createNewFile() } + assertFalse(NpuInfo.detect(tmp.root, NpuInfo.Hexagon.V79).qnnRuntime) + File(tmp.root, NpuInfo.QNN_LIBS.last()).createNewFile() + assertTrue(NpuInfo.detect(tmp.root, NpuInfo.Hexagon.V79).qnnRuntime) + } +} diff --git a/docs/development/npu-upscaler.md b/docs/development/npu-upscaler.md new file mode 100644 index 0000000000..430edc9c25 --- /dev/null +++ b/docs/development/npu-upscaler.md @@ -0,0 +1,54 @@ +# Neural upscaling on the Hexagon NPU + +Reference: [Winlator-NeuralScale](https://github.com/michaelisomer-cyber/Winlator-NeuralScale), a Winlator fork that +runs AMD FSR 4 on the Qualcomm Hexagon HTP through QNN, with GPU (DP4a) FSR 4 / XeSS / FSR 3.1 fallbacks. This note +records what carries over to DroidDeck, what does not, and what has been built so far. + +## How the reference works + +A Vulkan layer in the game's process intercepts the game's own upscaler calls (FSR 2/3/4, DLSS through an NGX +bridge, XeSS) via replacement DLLs. Those calls hand over colour, depth, motion vectors, exposure and jitter. The +layer runs the FSR 4 network (INT8, compiled on the device by `libQnnHtpPrepare.so`) on the NPU, with Vulkan passes +before and after it and `AHardwareBuffer` for the hand-off. + +## What carries over, what does not + +| Piece | In DroidDeck | +|---|---| +| Game-side hook (DLL replacement, NGX/FFX bridges) | The guest runs Steam under FEX and Proton, so the same Windows-side bridge DLLs could apply, but nothing in the repo loads them yet. | +| Temporal inputs (depth, motion vectors, jitter) | Only exist inside the guest. The Wayland compositor (`waylandcomp`, where FSR 1 / SGSR / frame generation run) sees a finished colour frame, so FSR 4 cannot run there. A compositor-side network would have to be a spatial-only super-resolution model, a different thing from FSR 4. | +| QNN runtime and skel libraries | Qualcomm's, not redistributable here. They would come from the user's own QAIRT SDK or a runtime download. | +| FSR 4 weights | AMD's. The reference ships them in its APK; DroidDeck should not copy them without a licence check. | +| DP4a GPU path | Independent of the NPU and the most portable part. Needs the same guest-side hook. | + +## Findings on the Retroid Pocket Duo (SM8750, Hexagon v79) + +- `/dev/fastrpc-cdsp` is `crw-rw-r-- system system`. The DroidDeck app uid (10120 here) fails `access(W_OK)`, so an + unprivileged app cannot open a FastRPC session on the compute DSP on this firmware, whatever it bundles. The + reference fork targets devices where the node is world-writable. `NpuInfo` reports this as "app cannot open it". +- The AYANEO Pocket FIT Elite (SM8750P, stock, no root) has the same node, same `0664 system:system`, and the same + DAC result for a non-`system` uid, so this is the stock 8 Elite layout and not a Retroid quirk. The check was done as + the adb shell uid, which has the same "other" bits as an app uid; DroidDeck's own uid has not run it on the FIT Elite + because the fast deploy loop needs `tools/build_local.sh` first. +- The vendor partition has `libcdsprpc.so` but no QNN libraries, so the runtime has to be bundled or downloaded. +- SELinux is permissive on this unit (Magisk), so it says nothing about a stock device. The DAC check is the + conclusion that holds. + +## Built so far + +- `gpu/NpuInfo.kt`: maps the SoC model or board platform to a Hexagon generation (v68 to v81, with the VTCM size the + reference caps `vtcmSizeInMB` to), checks whether the app's uid can open the FastRPC node, and whether the QNN + libraries are bundled. Shown as an "NPU" section in Device info. +- `NpuInfoTest`. + +## Next steps, in order + +1. Decide the hook point. Guest-side (Winlator's approach) is the only one that can run FSR 4; compositor-side + limits it to spatial super-resolution. +2. Resolve the FastRPC access problem: it needs either a device where the node is open, or a privileged helper, + before any QNN work on this hardware is worth starting. Both 8 Elite devices tried so far are closed; an 8 Elite Gen 5 + handheld is still untested. +3. GPU-only FSR 4.1 Lite (DP4a) behind the hook, since it needs no NPU access and exercises the same plumbing. +4. QNN graph compile and run, per-architecture cache directories (`v73/`, `v75/`, `v79/`, `v81/`), and a fallback to + the GPU path whenever `NpuInfo.usable` is false. +5. Licence review of AMD weights and Qualcomm binaries before anything is bundled or downloaded.