mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
feat: Mali Vulkan support through MaliBridge (#1950)
This commit is contained in:
83 files changed
+2331
-80
No files matched your search
@@ -14,6 +14,8 @@ import com.droiddeck.launcher.gpu.FrameGen
|
||||
import com.droiddeck.launcher.gpu.GpuInfo
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.ui.Motion
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
import java.io.File
|
||||
@@ -56,7 +58,10 @@ class DroidDeckHudHost(context: Context) {
|
||||
if (!gpuName.isNullOrBlank()) handler.post { this@DroidDeckHudHost.gpuName = cleanGpuName(gpuName) }
|
||||
if (window != null && window != lastWindow) {
|
||||
lastWindow = window
|
||||
handler.post { onPresentingWindowChanged?.invoke() }
|
||||
handler.post {
|
||||
onPresentingWindowChanged?.invoke()
|
||||
applyShown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,8 +179,9 @@ class DroidDeckHudHost(context: Context) {
|
||||
private fun applyShown() {
|
||||
if (!running) return
|
||||
val show = !hidden && !backgrounded
|
||||
view?.visibility = if (show) View.VISIBLE else View.GONE
|
||||
showing = show
|
||||
val visible = show && SessionState.mode != SessionService.MODE_DESKTOP
|
||||
view?.visibility = if (visible) View.VISIBLE else View.GONE
|
||||
showing = visible
|
||||
if (show != polling) {
|
||||
polling = show
|
||||
if (show) Choreographer.getInstance().postFrameCallback(frameCallback)
|
||||
@@ -208,14 +214,20 @@ class DroidDeckHudHost(context: Context) {
|
||||
file
|
||||
}.getOrNull()
|
||||
|
||||
private fun sessionResolution(): String {
|
||||
val (width, height) = SessionState.outputSize
|
||||
return "${width}x${height}"
|
||||
}
|
||||
|
||||
private fun refreshLabels(hud: DroidDeckHudView) {
|
||||
if (feed.engine.isNotBlank() && !feed.steamFocused) engine = feed.engine
|
||||
hud.setEngineLabel(engine)
|
||||
if (gpuName.isNotBlank()) hud.setGpuModel(gpuName)
|
||||
hud.setResolution(if (feed.outputWidth > 0 && feed.outputHeight > 0) buildString {
|
||||
val feedResolution = if (feed.outputWidth > 0 && feed.outputHeight > 0) buildString {
|
||||
append(feed.outputWidth).append('x').append(feed.outputHeight)
|
||||
if (feed.refreshMilliHz > 0) append(" @ ").append((feed.refreshMilliHz + 499) / 1000).append("Hz")
|
||||
} else "")
|
||||
} else ""
|
||||
hud.setResolution(feedResolution.ifBlank { sessionResolution() })
|
||||
val pid = feed.pid
|
||||
if (pid > 0 && pid != protonPid) {
|
||||
protonPid = pid
|
||||
|
||||
@@ -698,6 +698,9 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
contentW = max(contentW, pad + w + pad)
|
||||
}
|
||||
|
||||
private fun hasGpuStats(s: HudMetrics.Snapshot): Boolean =
|
||||
s.gpuPercent != null || s.gpuTempC != null || s.gpuClockMhz != null
|
||||
|
||||
private fun buildFull(s: HudMetrics.Snapshot) {
|
||||
val rowPx = sp(12f); val unitPx = rowPx * 0.62f
|
||||
val pad = sp(10f); val lineGap = sp(4f); val lvGap = sp(8f)
|
||||
@@ -709,7 +712,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
rows.add(HudRow(Span("DISP", colDisp, rowPx), listOf(Span(displayServer, colValue, rowPx))))
|
||||
if (hdrState != DroidDeckHudHdr.NONE)
|
||||
rows.add(HudRow(Span("HDR", colHdr, rowPx), hdrValue(rowPx)))
|
||||
if (showGPU) {
|
||||
if (showGPU && hasGpuStats(s)) {
|
||||
val v = ArrayList<Span>()
|
||||
v += numUnit(s.gpuPercent?.toString(), "%", rowPx, unitPx)
|
||||
if (showGpuTemp) tempSpans(s.gpuTempC, HudMetrics.TempSensor.GPU, rowPx, unitPx)
|
||||
@@ -720,9 +723,9 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
if (showCPU) {
|
||||
val v = ArrayList<Span>()
|
||||
v += numUnit(s.cpuPercent?.toString(), "%", rowPx, unitPx)
|
||||
v += gap(unitPx); v += numUnit(s.cpuClockMhz?.toString(), "MHz", rowPx, unitPx)
|
||||
if (showCpuTemp) tempSpans(s.cpuTempC, HudMetrics.TempSensor.CPU, rowPx, unitPx)
|
||||
.let { if (it.isNotEmpty()) { v += gap(unitPx); v += it } }
|
||||
v += gap(unitPx); v += numUnit(s.cpuClockMhz?.toString(), "MHz", rowPx, unitPx)
|
||||
rows.add(HudRow(Span("CPU", colCpu, rowPx), v))
|
||||
}
|
||||
if (showVram && s.vramText() != null)
|
||||
@@ -799,12 +802,13 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
"${fmt1(fpsAvg)} avg · ${lowText(lows.low1Fps) ?: "—"} 1%", false))
|
||||
if (showFPS) tiles.add(Tile("FRAME", colDim, numUnit(fmt1(1000f / max(fpsNow, 1f)), "ms", valPx, unitPx),
|
||||
"${fmt1(graphMinMs)} – ${fmt1(graphMaxMs)}", false))
|
||||
if (showGPU) tiles.add(Tile("GPU", colGpu, numUnit(s.gpuPercent?.toString(), "%", valPx, unitPx),
|
||||
if (showGPU && hasGpuStats(s)) tiles.add(Tile("GPU", colGpu, numUnit(s.gpuPercent?.toString(), "%", valPx, unitPx),
|
||||
if (showGpuTemp && s.gpuTempC != null) HudMetrics.formatTemp(s.gpuTempC.toFloat(), tempDisplay, false)
|
||||
else s.gpuClockMhz?.let { "${it}MHz" }, false))
|
||||
if (showCPU) tiles.add(Tile("CPU", colCpu, numUnit(s.cpuPercent?.toString(), "%", valPx, unitPx),
|
||||
listOfNotNull(if (showCpuTemp) s.cpuTempC?.let { HudMetrics.formatTemp(it.toFloat(), tempDisplay, false) } else null,
|
||||
s.cpuClockMhz?.toString()).joinToString(" · ").ifBlank { null }, false))
|
||||
listOfNotNull(s.cpuClockMhz?.let { "${it}MHz" },
|
||||
if (showCpuTemp) s.cpuTempC?.let { HudMetrics.formatTemp(it.toFloat(), tempDisplay, false) } else null)
|
||||
.joinToString(" · ").ifBlank { null }, false))
|
||||
if (showVram && s.vramText() != null) tiles.add(Tile("VRAM", colVram, valueUnit(s.vramText()!!, valPx, unitPx), null, false))
|
||||
if (showRAM) tiles.add(Tile("RAM", colRam, numUnit(s.ramPercent.roundToInt().toString(), "%", valPx, unitPx),
|
||||
"${s.ramUsedText()} / ${s.ramTotalText()}", false))
|
||||
@@ -881,7 +885,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
val gpuName = if (showGpuModel && gpuNameText().isNotBlank()) gpuModelSpans(stkPx, colDim, compact = true) else null
|
||||
run {
|
||||
val l = ArrayList<Span>()
|
||||
if (showGPU) { l += Span("GPU ${s.gpuPercent ?: "—"}%", colGpu, stkPx) }
|
||||
if (showGPU && s.gpuPercent != null) { l += Span("GPU ${s.gpuPercent}%", colGpu, stkPx) }
|
||||
if (showCPU) { if (l.isNotEmpty()) l += Span(" · ", colDim, stkPx); l += Span("CPU ${s.cpuPercent ?: "—"}%", colCpu, stkPx) }
|
||||
if (l.isNotEmpty()) stack.add(l)
|
||||
}
|
||||
@@ -1137,7 +1141,7 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
val left = ArrayList<HudRow>()
|
||||
if (showGpuModel && gpuNameText().isNotBlank())
|
||||
left.add(HudRow(Span("GPU", colGpu, rowPx), gpuModelSpans(rowPx, colValue)))
|
||||
if (showGPU) {
|
||||
if (showGPU && hasGpuStats(s)) {
|
||||
val v = ArrayList<Span>()
|
||||
v += numUnit(s.gpuPercent?.toString(), "%", rowPx, unitPx)
|
||||
if (showGpuTemp) tempSpans(s.gpuTempC, HudMetrics.TempSensor.GPU, rowPx, unitPx)
|
||||
@@ -1148,9 +1152,9 @@ class DroidDeckHudView(context: Context) : View(context) {
|
||||
if (showCPU) {
|
||||
val v = ArrayList<Span>()
|
||||
v += numUnit(s.cpuPercent?.toString(), "%", rowPx, unitPx)
|
||||
v += gap(unitPx); v += numUnit(s.cpuClockMhz?.toString(), "MHz", rowPx, unitPx)
|
||||
if (showCpuTemp) tempSpans(s.cpuTempC, HudMetrics.TempSensor.CPU, rowPx, unitPx)
|
||||
.let { if (it.isNotEmpty()) { v += gap(unitPx); v += it } }
|
||||
v += gap(unitPx); v += numUnit(s.cpuClockMhz?.toString(), "MHz", rowPx, unitPx)
|
||||
left.add(HudRow(Span("CPU", colCpu, rowPx), v))
|
||||
}
|
||||
if (showPerCore) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.droiddeck.launcher.hud
|
||||
|
||||
import android.os.Environment
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
internal class MangoReadings(private val sessionDir: File, private val rootDir: File) {
|
||||
class Cpu(val percent: Int, val perCore: IntArray)
|
||||
@@ -48,6 +50,7 @@ internal class MangoReadings(private val sessionDir: File, private val rootDir:
|
||||
}
|
||||
|
||||
fun cpuTempC(): Int? {
|
||||
externalCpuTemp()?.let { return it }
|
||||
var sum = 0f
|
||||
var count = 0
|
||||
for (zone in LinuxRuntime.cpuTempZones()) {
|
||||
@@ -58,6 +61,13 @@ internal class MangoReadings(private val sessionDir: File, private val rootDir:
|
||||
return if (count == 0) null else (sum / count).toInt()
|
||||
}
|
||||
|
||||
/** Optional ADB helper feed: /sdcard/DroidDeck/cpu-temp, written from the host while a session runs. */
|
||||
private fun externalCpuTemp(): Int? {
|
||||
val file = File(Environment.getExternalStorageDirectory(), "DroidDeck/cpu-temp")
|
||||
if (!file.isFile || System.currentTimeMillis() - file.lastModified() > CPU_TEMP_FRESH_MS) return null
|
||||
return readFloat(file)?.takeIf { it.isFinite() && it in -20f..150f }?.roundToInt()
|
||||
}
|
||||
|
||||
fun gpuPercent(): Int? {
|
||||
val feed = fresh(File(sessionDir, "sys/kgsl-3d0/perf_now"))
|
||||
val source = feed ?: LinuxRuntime.gpuLoadSource()?.let(::File) ?: return null
|
||||
@@ -92,7 +102,8 @@ internal class MangoReadings(private val sessionDir: File, private val rootDir:
|
||||
return Memory((total - available) * 1024, total * 1024, (swapTotal - swapFree) * 1024, swapTotal * 1024)
|
||||
}
|
||||
|
||||
fun vramBytes(): Long? = fresh(File(rootDir, VRAM_FILE), VRAM_FRESH_MS)?.let(::readLong)
|
||||
/** The KGSL total DroidDeck shares with the session (GpuMemComponent). */
|
||||
fun vramBytes(): Long? = fresh(File(rootDir, VRAM_FILE), VRAM_FRESH_MS)?.let(::readLong)?.takeIf { it > 0 }
|
||||
|
||||
fun battery(): Battery? {
|
||||
val dirs = File(sessionDir, "sys/power_supply").listFiles { f -> f.name.contains("BAT") }?.sortedBy { it.name }
|
||||
@@ -132,6 +143,7 @@ internal class MangoReadings(private val sessionDir: File, private val rootDir:
|
||||
const val VRAM_FILE = "run/droiddeck-hud/gpu-mem"
|
||||
private const val FEED_FRESH_MS = 10_000L
|
||||
private const val VRAM_FRESH_MS = 15_000L
|
||||
private const val CPU_TEMP_FRESH_MS = 10_000L
|
||||
private val WHITESPACE = Regex("\\s+")
|
||||
|
||||
private fun readLong(file: File): Long? = runCatching { file.readText().trim().toLong() }.getOrNull()
|
||||
|
||||
Reference in new issue
Block a user