From 3582186951e13a7b7bb712ed9fd744fbe23052ef Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 19 Sep 2026 15:29:16 -0400 Subject: [PATCH] =?UTF-8?q?A=20performance=20line=20in=20the=20corner:=20f?= =?UTF-8?q?ps,=20and=20base=20=E2=86=92=20generated=20when=20frame=20gener?= =?UTF-8?q?ation=20runs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whether frame generation is doing anything was only knowable from a log. The top-right line counts the game's own frames from the compositor's per-frame callback, and while an engine generates it shows the engine's telemetry beside it — "LSFG 2× 60 → 118 fps" — or says the engine is starting, unsupported or failed. Touches pass through it. steamdeck-no-hud in Downloads hides it. --- README.md | 1 + .../com/steamdeck/launcher/SessionActivity.kt | 19 +++- .../com/steamdeck/launcher/session/PerfHud.kt | 106 ++++++++++++++++++ 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt diff --git a/README.md b/README.md index dd434e82fb..e3648d4ecb 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Files in `/sdcard/Download`, for a device that cannot be reached with a debugger | `steamdeck-no-pad` | Turns the controller feature off entirely (a true baseline) | | `steamdeck-pad-log` | Traces every interposer call into the session log | | `steamdeck-driver` | `a7xx`, `a8xx` or `system` — overrides the Turnip build the compositor loads | +| `steamdeck-no-hud` | Hides the top-right performance line (fps, and `base → generated` while frame generation runs) | | `steamdeck-osc` | `always` or `never` — pins the on-screen controls instead of following what is attached | Session logs land in `/sdcard/Download/SteamDeck/`. diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index 933da410f8..722ef187b6 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -23,6 +23,7 @@ import com.steamdeck.launcher.input.OnScreenControls import com.steamdeck.launcher.input.PadBridge import com.steamdeck.launcher.runtime.LinuxRuntime import com.steamdeck.launcher.session.LoadingPanel +import com.steamdeck.launcher.session.PerfHud import com.steamdeck.launcher.session.SessionService import com.steamdeck.launcher.session.SessionState import com.steamdeck.launcher.wayland.CompositorHost @@ -42,6 +43,7 @@ import java.io.File class SessionActivity : Activity(), SurfaceHolder.Callback { private lateinit var surfaceView: SurfaceView private lateinit var loading: LoadingPanel + private lateinit var hud: PerfHud private var padBridge: PadBridge? = null private var onScreenControls: OnScreenControls? = null private var watching = true @@ -77,8 +79,17 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { val panel = layoutInflater.inflate(R.layout.session_loading, root, false) root.addView(panel) loading = LoadingPanel(panel) + // The performance line, above everything but the loading panel; it starts with the + // client's first frame, since before that there is nothing to count. + hud = PerfHud(this) + root.addView(hud.view, root.indexOfChild(panel)) // A session that has already drawn is past its milestones; do not cover its picture. - if (SessionState.running && SessionState.firstFrameSeen) loading.hide() else loading.show() + if (SessionState.running && SessionState.firstFrameSeen) { + loading.hide() + hud.start() + } else { + loading.show() + } setContentView(root) val bridge = PadBridge(File(LinuxRuntime.sessionRoot(this), "dev/input")) @@ -87,7 +98,10 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { updateOnScreenControls() WaylandCompositor.setFirstFrameListener { SessionState.firstFrameSeen = true - runOnUiThread { loading.hide() } + runOnUiThread { + loading.hide() + hud.start() + } } SessionState.endListener = { status -> onSessionEnded(status) } watchSessionLog() @@ -328,6 +342,7 @@ class SessionActivity : Activity(), SurfaceHolder.Callback { // Deliberately does NOT end the session: this activity can be destroyed while the user is // in another app, and the whole point of the service is that Steam survives that. watching = false + hud.stop() padBridge?.stop() SessionState.endListener = null WaylandCompositor.setFirstFrameListener(null) diff --git a/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt b/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt new file mode 100644 index 0000000000..b2add2abfa --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/session/PerfHud.kt @@ -0,0 +1,106 @@ +package com.steamdeck.launcher.session + +import android.content.Context +import android.graphics.Color +import android.graphics.Typeface +import android.os.Environment +import android.os.Handler +import android.os.Looper +import android.os.SystemClock +import android.util.TypedValue +import android.view.Gravity +import android.view.View +import android.widget.FrameLayout +import android.widget.TextView +import com.steamdeck.launcher.gpu.FrameGen +import com.steamdeck.launcher.wayland.WaylandCompositor +import java.io.File +import java.util.Locale +import java.util.concurrent.atomic.AtomicInteger + +/** + * A line of numbers in the top-right corner: the game's own frame rate and, when frame generation + * is on, what the screen is actually being shown — "60 → 118 fps" is the proof that the engine is + * doing something, and "FG starting" or a reason is the proof that it is not. + * + * The base rate is counted here from the compositor's per-frame callback, so it is right with or + * without an engine. The presented rate comes from the engine's own telemetry while it generates. + * `steamdeck-no-hud` in Downloads hides it. + */ +class PerfHud(context: Context) { + val view: TextView = TextView(context).apply { + typeface = Typeface.MONOSPACE + setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f) + setTextColor(Color.WHITE) + setBackgroundColor(Color.argb(140, 0, 0, 0)) + setPadding(14, 6, 14, 6) + // Numbers only; every touch goes through to the game. + isClickable = false + isFocusable = false + visibility = View.GONE + layoutParams = FrameLayout.LayoutParams( + FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, + Gravity.TOP or Gravity.END, + ).apply { topMargin = 12; rightMargin = 12 } + } + + private val context = context.applicationContext + private val frames = AtomicInteger() + private var lastTick = 0L + private var running = false + private val handler = Handler(Looper.getMainLooper()) + private val enabled = !File(Environment.getExternalStorageDirectory(), "Download/steamdeck-no-hud").exists() + + private val listener = object : WaylandCompositor.GameListener { + override fun onGameSurface(window: String?, gpuName: String?) {} + override fun onGameFrame() { frames.incrementAndGet() } + } + + private val tick = object : Runnable { + override fun run() { + if (!running) return + val now = SystemClock.elapsedRealtime() + val dt = (now - lastTick).coerceAtLeast(1L) / 1000f + lastTick = now + val base = frames.getAndSet(0) / dt + view.text = line(base) + handler.postDelayed(this, 1000) + } + } + + fun start() { + if (!enabled || running) return + running = true + lastTick = SystemClock.elapsedRealtime() + frames.set(0) + WaylandCompositor.setGameListener(listener) + view.visibility = View.VISIBLE + handler.post(tick) + } + + fun stop() { + running = false + WaylandCompositor.setGameListener(null) + view.visibility = View.GONE + } + + private fun line(base: Float): String { + val engine = FrameGen.engine(context) + if (engine == FrameGen.ENGINE_OFF) return fps(base) + val name = if (engine == FrameGen.ENGINE_LSFG) "LSFG" else "Win-FG" + val multiplier = FrameGen.multiplier(context) + val stats = try { WaylandCompositor.nativeFrameGenStats() } catch (t: Throwable) { null } + val problem = try { WaylandCompositor.nativeFrameGenProblem() } catch (t: Throwable) { -1 } + return when { + problem == 1 -> "$name: unsupported" + problem == 2 -> "$name: engine failed" + stats != null && stats[3] > 1f -> { + val source = if (stats[2] > 1f) stats[2] else base + String.format(Locale.US, "%s %d× %.0f → %.0f fps", name, multiplier, source, stats[3]) + } + else -> String.format(Locale.US, "%s %d× %s · FG starting", name, multiplier, fps(base)) + } + } + + private fun fps(value: Float) = String.format(Locale.US, "%.0f fps", value) +}