mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
feat(upscale): run the NPU on the phone's own QNN runtime
Phones whose vendor offers the QNN HTP libraries to apps (public.libraries.txt) now run the NPU engines on them, any HTP generation, with nothing downloaded: the app finds the generation from the vendor's libQnnHtpV<NN>Stub.so and passes DROIDDECK_UPSCALE_HTP_ARCH; the layer takes the bundled QNN files only for an arch whose skel came with them, else loads the vendor libraries by name. Red Magic 12 Pro (SM8975, HTP V85, no root), layer QNN code in a probe: FSR 4.1.2 Lite INT8 graph compiled on the phone (2.0 s, cached 0.3 s), 1.2 ms per run at perf, 0 failures; arch found without HTP_ARCH.
This commit is contained in:
1 parent
94bcfca5c0
commit
c18aa23ac2
3 files changed
+122
-10
No files matched your search
@@ -150,8 +150,33 @@ object UpscaleComponent {
|
||||
fun bridgesDir(context: Context) = File(root(context), "bridges")
|
||||
fun runDir(context: Context) = File(LinuxRuntime.rootDir(context), GUEST_RUN.removePrefix("/"))
|
||||
|
||||
/** The Hexagon NPU generation the bundled QNN files serve, or null: v79 on the Snapdragon 8 Elite, v81 on the 8 Elite Gen 5. */
|
||||
fun npuArch(model: String = SocNames.model()): String? {
|
||||
/** The NPU this phone has: its Hexagon HTP generation and whether its own QNN libraries run it. */
|
||||
data class Npu(val arch: String, val systemLibs: Boolean)
|
||||
|
||||
private val SYSTEM_QNN = listOf("libQnnHtp.so", "libQnnHtpPrepare.so", "libQnnSystem.so")
|
||||
private val SYSTEM_STUB = Regex("libQnnHtpV(\\d{2,3})Stub\\.so")
|
||||
|
||||
/**
|
||||
* The HTP generation of the phone's own QNN runtime, when the vendor offers it to apps (listed in
|
||||
* public.libraries.txt): named by its one libQnnHtpV<NN>Stub.so. Null when absent or ambiguous.
|
||||
*/
|
||||
internal fun systemNpuArch(libDir: File = File("/vendor/lib64"), publicList: File = File("/vendor/etc/public.libraries.txt")): String? {
|
||||
val listed = runCatching {
|
||||
publicList.readLines().map { it.trim() }.filter { it.isNotEmpty() && !it.startsWith("#") }.map { it.substringBefore(' ') }.toSet()
|
||||
}.getOrNull() ?: return null
|
||||
if (!SYSTEM_QNN.all { it in listed && File(libDir, it).isFile }) return null
|
||||
val archs = libDir.list().orEmpty().filter { it in listed }.mapNotNull { SYSTEM_STUB.matchEntire(it)?.groupValues?.get(1) }.distinct()
|
||||
return archs.singleOrNull()?.let { "v$it" }
|
||||
}
|
||||
|
||||
private val systemNpu: String? by lazy { runCatching { systemNpuArch() }.getOrNull() }
|
||||
|
||||
/**
|
||||
* This phone's NPU, or null. The phone's own QNN runtime first (any HTP generation, nothing to download);
|
||||
* else the bundled QNN files: v79 on the Snapdragon 8 Elite, v81 on the 8 Elite Gen 5.
|
||||
*/
|
||||
fun npu(model: String = SocNames.model()): Npu? {
|
||||
systemNpu?.let { return Npu(it, systemLibs = true) }
|
||||
val soc = SocNames.normalizedModel(model)
|
||||
val arch = when {
|
||||
soc.startsWith("SM8750") -> "v79"
|
||||
@@ -159,13 +184,15 @@ object UpscaleComponent {
|
||||
else -> null
|
||||
} ?: return null
|
||||
val fastrpc = listOf("/dev/fastrpc-cdsp", "/dev/fastrpc-cdsp-secure", "/dev/adsprpc-smd").any { File(it).exists() }
|
||||
return arch.takeIf { fastrpc }
|
||||
return Npu(arch, systemLibs = false).takeIf { fastrpc }
|
||||
}
|
||||
|
||||
fun npuArch(model: String = SocNames.model()): String? = npu(model)?.arch
|
||||
|
||||
fun groups(engine: GameUpscaler.Engine, npu: Boolean = npuArch() != null): Set<Group> = buildSet {
|
||||
add(Group.CORE)
|
||||
if (engine == GameUpscaler.Engine.XESS) add(Group.XESS)
|
||||
if (engine.npu && npu) add(Group.NPU)
|
||||
if (engine.npu && npu && this.npu()?.systemLibs != true) add(Group.NPU)
|
||||
}
|
||||
|
||||
/** The bridge DLLs (tools/upscale/bridges/build.sh), each in both Wine PE folders. */
|
||||
@@ -356,11 +383,13 @@ object UpscaleComponent {
|
||||
return dir
|
||||
}
|
||||
|
||||
/** Session-wide guest variables: whether NPU engines can run here, and the bionic layer's manifest folder. */
|
||||
/** Session-wide guest variables: whether NPU engines can run here (and its HTP generation), and the bionic layer's manifest folder. */
|
||||
fun guestEnv(context: Context): List<String> {
|
||||
runCatching { runDir(context).mkdirs() }
|
||||
return listOf(
|
||||
"DROIDDECK_UPSCALE_NPU=" + (if (npuArch() != null) "1" else "0"),
|
||||
val here = npu()
|
||||
return listOfNotNull(
|
||||
"DROIDDECK_UPSCALE_NPU=" + (if (here != null) "1" else "0"),
|
||||
here?.let { "DROIDDECK_UPSCALE_HTP_ARCH=${it.arch}" },
|
||||
"DROIDDECK_UPSCALE_LAYER=" + bionicLayerDir(context).absolutePath,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user