feat: FusionHUD replaces the session HUD, with MangoHud's readings (#1743)

The session HUD is FusionHUD (Bannerlator's HUD) with every reading taken from
the same source, and worked out the same way, as the MangoHud build that runs
Steam's performance overlay in a DroidDeck session.

- gamescope patch 0125 (gamescope-3.16.29-p19) shares the frame times that
  mangoapp reads (one per signalled commit of connector 0) in a ring named by
  DROIDDECK_HUD_FRAMES; the app reads it once per display frame and counts the
  compositor's frames when gamescope sends none.
- MangoHud's rules: FPS over periods of at least 500 ms, frame time = 1000/FPS,
  200-frame graph on a fixed 0-50 ms scale; CPU, GPU, temperatures, RAM, swap,
  VRAM and battery from MangoHud's sources. Zones 22/26/28 are typed as GPU and
  DDR sensors, so Steam's overlay CPU temperature no longer includes them.
- Five sizes in a panel shaped like the DroidDeck mark, with a centred header,
  one left edge, neon outline and FPS; Minimal is the default size. Settings on
  a new "Performance HUD" drawer page, with Bannerlator's options.
- The HUD reads sensors and polls frames only while it is drawn (not while
  hidden, in picture-in-picture or behind another app), keeps its place after
  picture-in-picture, and the diagnostics export has its own reader.

Device-tested on the AYANEO Pocket FIT: same readings as Steam's overlay side
by side in Dead Cells; the HUD updates in a game, hides in picture-in-picture
and comes back in place, no crashes.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-29 01:53:45 +00:00
1 parent e871557bf2
commit 110cfc28f8
70 files changed
+7269 -320

No files matched your search

+10
View File
@@ -199,3 +199,13 @@ is marked done at once - no duplicate fence, no epoll add or delete, no waiter w
loop handles it in the same pass, after the import (FIFO commits still wait for a vblank). The
`commit_ready_check` convar (default on, `gamescopectl commit_ready_check 0`) turns it off; the
`xwm` log counts fences ready at import and waited for, every 10 s.
## 0125 steamcompmgr: share mangoapp's frame times with DroidDeck's HUD
DroidDeck's in-app HUD shows the same frame rate and frame times as Steam's performance overlay.
DroidDeck's mangoapp (Valve's 20260902.1 build) reads the field at byte 16 of gamescope's messages as
its frame time; gamescope 3.16.29 puts `app_frametime_ns` there, the time between signalled commits of
the connector's windows (`mangoapp_nudge_app_frame`). With `DROIDDECK_HUD_FRAMES` set (droiddeck-session
sets `/run/droiddeck-hud/frames`), gamescope maps that file and writes the same commits of connector 0,
whether or not a mangoapp runs, plus the focused pid, output size, refresh, Steam focus and engine name.
The layout is in the comment above `droiddeck_hud_frames_map`; the app reads it in `hudframes.c`.
@@ -0,0 +1,227 @@
diff --git a/src/commit.cpp b/src/commit.cpp
index f2e0f0c..fbfb550 100644
--- a/src/commit.cpp
+++ b/src/commit.cpp
@@ -86,6 +86,8 @@ void commit_t::Signal()
mangoapp_nudge_app_frame( k_uMangoappLegacyMsgType, now );
if ( m_uMangoMsgType != 0 )
mangoapp_nudge_app_frame( m_uMangoMsgType, now );
+ if ( m_bDroidDeckHudFrame )
+ droiddeck_hud_app_frame( now );
}
void commit_t::OnPollHangUp()
@@ -113,7 +115,7 @@ bool commit_t::CloseFenceInternal()
return true;
}
-void commit_t::SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits )
+void commit_t::SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits, bool bDroidDeckHudFrame )
{
std::unique_lock lock( m_WaitableCommitStateMutex );
CloseFenceInternal();
@@ -121,6 +123,7 @@ void commit_t::SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, c
m_nCommitFence = nFence;
m_bMangoNudge = bMangoNudge;
m_uMangoMsgType = uMangoMsgType;
+ m_bDroidDeckHudFrame = bDroidDeckHudFrame;
m_pDoneCommits = pDoneCommits;
}
diff --git a/src/commit.h b/src/commit.h
index 8603a9a..ae767b6 100644
--- a/src/commit.h
+++ b/src/commit.h
@@ -35,7 +35,7 @@ struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable,
// Returns true if we had a fence that was closed.
bool CloseFenceInternal();
- void SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits );
+ void SetFence( int nFence, bool bMangoNudge, uint32_t uMangoMsgType, const std::shared_ptr<CommitDoneList_t> &pDoneCommits, bool bDroidDeckHudFrame = false );
bool ShouldPreemptivelyUpscale( GamescopeUpscaleFilter eFilter, GamescopeUpscaleScaler eScaler );
@@ -82,5 +82,6 @@ struct commit_t final : public gamescope::RcObject, public gamescope::IWaitable,
bool m_bMangoNudge = false;
// Typed mangoapp stream to nudge, 0 for none, never the legacy type.
uint32_t m_uMangoMsgType = 0;
+ bool m_bDroidDeckHudFrame = false;
std::shared_ptr<CommitDoneList_t> m_pDoneCommits; // I hate this
};
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 0aef598..1473148 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -57,6 +57,7 @@
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
+#include <sys/mman.h>
#include <sys/poll.h>
#include <sys/inotify.h>
#include <sys/time.h>
@@ -8359,6 +8360,8 @@ static TempUpscaleImage_t *GetTempUpscaleImage( global_focus_t *pFocus, uint32_t
gamescope::ConVar<bool> cv_surface_update_force_only_current_surface( "surface_update_force_only_current_surface", false, "Force updates to apply only to the current surface, ignoring commits for other surfaces." );
+static bool droiddeck_hud_frames_wanted();
+
gamescope::ConVar<bool> cv_commit_ready_check( "commit_ready_check", true, "Check a new commit's fence at import; a finished frame is marked done in the same pass instead of through the image waiter." );
// Set when update_wayland_res marks a commit done itself, so the main loop handles it in the same pass.
@@ -8519,6 +8522,16 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
uMangoMsgType = pMangoFocus->externalOverlayWindow->uMangoappMsgType;
}
+ // The commits the typed stream of connector 0 counts, whether or not a mangoapp runs.
+ bool bDroidDeckHudFrame = false;
+ if ( pUpscaleFocus && !w->isSteamStreamingClient )
+ bDroidDeckHudFrame = pUpscaleFocus->ulVirtualFocusKey == 0;
+ else if ( w->isSteamStreamingClientVideo )
+ {
+ auto iter = g_VirtualConnectorFocuses.find( 0 );
+ bDroidDeckHudFrame = iter != g_VirtualConnectorFocuses.end() && iter->second.focusWindow && iter->second.focusWindow->isSteamStreamingClient;
+ }
+
bool bValidPreemptiveScale = reslistentry.pAcquirePoint && pUpscaleFocus && cv_upscale_preemptive;
bool bPreemptiveUpscale = bValidPreemptiveScale && newCommit->ShouldPreemptivelyUpscale( pUpscaleFocus->eUpscaleFilter, pUpscaleFocus->eUpscaleScaler );
@@ -8650,7 +8663,7 @@ void update_wayland_res(const std::shared_ptr<CommitDoneList_t> &doneCommits, st
gpuvis_trace_printf( "pushing wait for commit %lu win %lx", newCommit->commitID, w->type == steamcompmgr_win_type_t::XWAYLAND ? w->xwayland().id : 0 );
{
- newCommit->SetFence( fence, mango_nudge, uMangoMsgType, doneCommits );
+ newCommit->SetFence( fence, mango_nudge, uMangoMsgType, doneCommits, bDroidDeckHudFrame && droiddeck_hud_frames_wanted() );
if ( bKnownReady )
{
newCommit->Signal();
@@ -9865,6 +9878,109 @@ static void publish_mangoapp_connector_snapshots()
}
}
+// DroidDeck's own HUD reads the frame times DroidDeck's mangoapp shows from a shared file named by
+// DROIDDECK_HUD_FRAMES, also while no mangoapp runs. That mangoapp (Valve's 20260902.1 build) reads the
+// field at byte 16 of each message as its frame time, which is app_frametime_ns here: one time per
+// signalled commit of the connector's windows (mangoapp_nudge_app_frame). The file gets the same commits
+// of connector 0. Little-endian: 0 magic, 4 version, 8 capacity, 12 pid, 16 frames written (u64),
+// 24 info sequence (odd while the info is written), 28 output width, 32 height, 36 refresh mHz, 40 Steam
+// focused, 44 engine (40 bytes), then from 128 one { frametime ns, monotonic time ns } pair per frame,
+// a ring of capacity.
+static constexpr uint32_t k_uDroidDeckHudFramesMagic = 0x46484444;
+static constexpr uint32_t k_uDroidDeckHudFramesVersion = 1;
+static constexpr uint32_t k_uDroidDeckHudFramesCapacity = 1024;
+static constexpr size_t k_zDroidDeckHudFramesHeader = 128;
+static constexpr size_t k_zDroidDeckHudFramesSize = k_zDroidDeckHudFramesHeader + k_uDroidDeckHudFramesCapacity * 16;
+static std::mutex s_DroidDeckHudFramesMutex;
+
+static uint8_t *droiddeck_hud_frames_map()
+{
+ static uint8_t *s_pMap = nullptr;
+ static bool s_bTried = false;
+ if ( s_bTried )
+ return s_pMap;
+ s_bTried = true;
+
+ const char *pszPath = getenv( "DROIDDECK_HUD_FRAMES" );
+ if ( !pszPath || !*pszPath )
+ return nullptr;
+ int fd = open( pszPath, O_RDWR | O_CREAT | O_CLOEXEC, 0644 );
+ if ( fd < 0 )
+ {
+ xwm_log.errorf_errno( "DroidDeck HUD frames: open %s", pszPath );
+ return nullptr;
+ }
+ void *pMap = MAP_FAILED;
+ if ( ftruncate( fd, k_zDroidDeckHudFramesSize ) == 0 )
+ pMap = mmap( nullptr, k_zDroidDeckHudFramesSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
+ close( fd );
+ if ( pMap == MAP_FAILED )
+ {
+ xwm_log.errorf_errno( "DroidDeck HUD frames: map %s", pszPath );
+ return nullptr;
+ }
+ uint8_t *pBytes = static_cast<uint8_t *>( pMap );
+ __atomic_store_n( reinterpret_cast<uint32_t *>( pBytes ), 0u, __ATOMIC_RELEASE );
+ memset( pBytes + 4, 0, k_zDroidDeckHudFramesSize - 4 );
+ memcpy( pBytes + 4, &k_uDroidDeckHudFramesVersion, 4 );
+ memcpy( pBytes + 8, &k_uDroidDeckHudFramesCapacity, 4 );
+ __atomic_store_n( reinterpret_cast<uint32_t *>( pBytes ), k_uDroidDeckHudFramesMagic, __ATOMIC_RELEASE );
+ xwm_log.infof( "DroidDeck HUD frames: %s", pszPath );
+ s_pMap = pBytes;
+ return s_pMap;
+}
+
+static bool droiddeck_hud_frames_wanted()
+{
+ std::unique_lock lock( s_DroidDeckHudFramesMutex );
+ return droiddeck_hud_frames_map() != nullptr;
+}
+
+// Signal() runs on the image waiter thread or, for a frame finished at import, on steamcompmgr's.
+void droiddeck_hud_app_frame( uint64_t ulNow )
+{
+ std::unique_lock lock( s_DroidDeckHudFramesMutex );
+ uint8_t *pMap = droiddeck_hud_frames_map();
+ if ( !pMap )
+ return;
+ static uint64_t s_ulLastFrame = 0;
+ uint64_t ulLast = s_ulLastFrame;
+ s_ulLastFrame = ulNow;
+ if ( !ulLast || ulNow <= ulLast )
+ return;
+ uint64_t *pCount = reinterpret_cast<uint64_t *>( pMap + 16 );
+ uint64_t ulCount = __atomic_load_n( pCount, __ATOMIC_RELAXED );
+ uint64_t ulFrame[2] = { ulNow - ulLast, ulNow };
+ memcpy( pMap + k_zDroidDeckHudFramesHeader + ( ulCount % k_uDroidDeckHudFramesCapacity ) * 16, ulFrame, sizeof( ulFrame ) );
+ __atomic_store_n( pCount, ulCount + 1, __ATOMIC_RELEASE );
+}
+
+static void publish_droiddeck_hud_info()
+{
+ std::unique_lock lock( s_DroidDeckHudFramesMutex );
+ uint8_t *pMap = droiddeck_hud_frames_map();
+ if ( !pMap )
+ return;
+ auto focusIter = g_VirtualConnectorFocuses.find( 0 );
+ global_focus_t *pFocus = focusIter != g_VirtualConnectorFocuses.end() ? &focusIter->second : GetCurrentFocus();
+ if ( !pFocus )
+ return;
+
+ uint32_t *pSeq = reinterpret_cast<uint32_t *>( pMap + 24 );
+ uint32_t uSeq = __atomic_load_n( pSeq, __ATOMIC_RELAXED );
+ __atomic_store_n( pSeq, uSeq + 1, __ATOMIC_RELAXED );
+ __atomic_thread_fence( __ATOMIC_RELEASE );
+ uint32_t uPid = uint32_t( pFocus->nFocusWindowPid );
+ uint32_t uOutput[4] = { g_nOutputWidth, g_nOutputHeight, uint32_t( g_nOutputRefresh ), window_is_steam( pFocus->inputFocusWindow ) ? 1u : 0u };
+ char szEngine[40] = {};
+ if ( pFocus->pFocusWindowEngine )
+ pFocus->pFocusWindowEngine->copy( szEngine, sizeof( szEngine ) - 1 );
+ memcpy( pMap + 12, &uPid, 4 );
+ memcpy( pMap + 28, uOutput, sizeof( uOutput ) );
+ memcpy( pMap + 44, szEngine, sizeof( szEngine ) );
+ __atomic_store_n( pSeq, uSeq + 2, __ATOMIC_RELEASE );
+}
+
// mangohudctl posts one control message for every instance to act on.
static void relay_mangoapp_control()
{
@@ -10843,6 +10959,7 @@ steamcompmgr_main(int argc, char **argv)
publish_mangoapp_snapshot();
publish_mangoapp_connector_snapshots();
+ publish_droiddeck_hud_info();
relay_mangoapp_control();
if ( bIsVBlankFromTimer )
diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp
index bd62fd1..7a7119f 100644
--- a/src/steamcompmgr.hpp
+++ b/src/steamcompmgr.hpp
@@ -173,6 +173,7 @@ static constexpr uint32_t MangoappControlMsgType( uint32_t uMsgType )
static_assert( MangoappControlMsgType( k_uMangoappLegacyMsgType ) == k_uMangoappControlMsgType );
extern void mangoapp_update( uint64_t visible_frametime, uint64_t app_frametime_ns, uint64_t latency_ns, uint32_t uMsgType = k_uMangoappLegacyMsgType );
+extern void droiddeck_hud_app_frame( uint64_t ulNow );
extern void mangoapp_nudge_app_frame( uint32_t uMsgType, uint64_t ulNow );
extern void mangoapp_set_connector_snapshots( std::unordered_map<uint32_t, MangoappSnapshot_t> snapshots );
extern void mangoapp_drop_stream( uint32_t uMsgType );
+2 -2
View File
@@ -1,3 +1,3 @@
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
GAMESCOPE_TAG=gamescope-3.16.29-p18
GAMESCOPE_SHA256=a79d8acc5628973c807a43524638c20e7d5c101a4fc3bcb8b5068631e6f6fe55
GAMESCOPE_TAG=gamescope-3.16.29-p19
GAMESCOPE_SHA256=e7333c6a2b95708b199c2c5bd0973e3f0e711e2dc746950cc648c2515ea2926b
@@ -257,6 +257,8 @@ if [ -z "${BL_INSIDE:-}" ]; then
args+=(--mangoapp)
echo "== gamescope: mangoapp on ($(command -v mangoapp), config $MANGOHUD_CONFIGFILE)"
fi
# gamescope writes the frame times the app's HUD shows here (patch 0125).
mkdir -p /run/droiddeck-hud && export DROIDDECK_HUD_FRAMES=/run/droiddeck-hud/frames
export BL_INSIDE=1
# A fixed path: left to itself gamescope creates a new limiter state file on every start.
rm -f "${XDG_RUNTIME_DIR:-/tmp}"/gamescope-limiter-*
+136
View File
@@ -0,0 +1,136 @@
from pathlib import Path
import os
import shutil
import subprocess
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[2]
PATCH = ROOT / "tools/gamescope/patches/0125-droiddeck-hud-frame-times.patch"
READER = ROOT / "app/src/main/cpp/waylandcomp/src/hudframes.c"
def patch_writer():
added = [line[1:] for line in PATCH.read_text().splitlines() if line.startswith("+") and not line.startswith("+++")]
text = "\n".join(added)
start = text.index("// DroidDeck's own HUD reads")
end = text.index("\n}\n", text.index("static void publish_droiddeck_hud_info()", start)) + 3
return text[start:end]
PREAMBLE = r'''
#include <assert.h>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <memory>
#include <mutex>
#include <string>
#include <sys/mman.h>
#include <unistd.h>
#include <unordered_map>
extern "C" {
#include "hudframes.h"
}
struct steamcompmgr_win_t { int appID; };
struct global_focus_t {
uint64_t ulBasePlaneCommitID = 0;
pid_t nFocusWindowPid = 0;
std::shared_ptr<std::string> pFocusWindowEngine;
steamcompmgr_win_t *inputFocusWindow = nullptr;
};
static std::unordered_map<uint64_t, global_focus_t> g_VirtualConnectorFocuses;
static global_focus_t *GetCurrentFocus() { return nullptr; }
static bool window_is_steam(steamcompmgr_win_t *w) { return w && w->appID == 769; }
static uint64_t g_now = 1000000000ull;
static uint64_t get_time_in_nanos() { return g_now; }
static uint32_t g_nOutputWidth = 1280, g_nOutputHeight = 720;
static int g_nOutputRefresh = 144000;
struct Log {
void infof(const char *, ...) {}
void errorf_errno(const char *fmt, ...) { va_list a; va_start(a, fmt); vfprintf(stderr, fmt, a); va_end(a); }
} xwm_log;
'''
MAIN = r'''
static void frame(uint64_t step) { g_now += step; droiddeck_hud_app_frame(g_now); }
int main(int argc, char **argv) {
setenv("DROIDDECK_HUD_FRAMES", argv[1], 1);
assert(droiddeck_hud_frames_wanted());
global_focus_t &focus = g_VirtualConnectorFocuses[0];
focus.nFocusWindowPid = 4242;
focus.pFocusWindowEngine = std::make_shared<std::string>("DXVK");
steamcompmgr_win_t game{ 12345 };
focus.inputFocusWindow = &game;
publish_droiddeck_hud_info();
droiddeck_hud_app_frame(g_now);
struct hud_frames *h = hud_frames_open(argv[1]);
assert(h);
int64_t ft[2048], tm[2048];
assert(hud_frames_poll(h, ft, tm, 2048) == 0);
const uint64_t steps[] = { 2700000, 2800000, 41600000, 6944000 };
for (uint64_t step : steps) frame(step);
int n = hud_frames_poll(h, ft, tm, 2048);
assert(n == 4);
for (int i = 0; i < 4; i++) assert((uint64_t)ft[i] == steps[i]);
assert((uint64_t)tm[3] == g_now);
assert(hud_frames_poll(h, ft, tm, 2048) == 0);
int32_t info[5];
char engine[41];
assert(hud_frames_info(h, info, engine, sizeof(engine)));
assert(info[0] == 4242 && info[1] == 1280 && info[2] == 720 && info[3] == 144000 && info[4] == 0);
assert(strcmp(engine, "DXVK") == 0);
game.appID = 769;
publish_droiddeck_hud_info();
assert(hud_frames_info(h, info, engine, sizeof(engine)) && info[4] == 1);
for (int i = 0; i < 3000; i++) frame(1000000 + i);
n = hud_frames_poll(h, ft, tm, 2048);
assert(n == 1024);
assert(ft[1023] == 1000000 + 2999);
assert(ft[0] == 1000000 + 2999 - 1023);
for (int i = 0; i < 10; i++) frame(2000000);
assert(hud_frames_poll(h, ft, tm, 4) == 4 && ft[3] == 2000000);
hud_frames_close(h);
puts("ok");
return 0;
}
'''
@unittest.skipUnless(shutil.which("cc") and shutil.which("c++"), "needs a C and C++ compiler")
class HudFramesTest(unittest.TestCase):
def test_gamescope_writer_and_app_reader_agree(self):
with tempfile.TemporaryDirectory() as tmp:
tmp = Path(tmp)
source = tmp / "writer.cpp"
source.write_text(PREAMBLE + patch_writer() + MAIN)
include = READER.parent
subprocess.run(["cc", "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-c", str(READER), "-o", str(tmp / "reader.o")], check=True)
subprocess.run(["c++", "-std=c++20", "-Wall", "-Werror", "-Wno-unused-function", f"-I{include}", str(source), str(tmp / "reader.o"),
"-o", str(tmp / "hudframes")], check=True)
result = subprocess.run([str(tmp / "hudframes"), str(tmp / "frames")], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout.strip(), "ok")
self.assertEqual(os.path.getsize(tmp / "frames"), 128 + 1024 * 16)
def test_session_points_gamescope_at_the_file_the_app_reads(self):
session = (ROOT / "tools/linuxfs/overlay/usr/local/bin/droiddeck-session").read_text()
self.assertIn("export DROIDDECK_HUD_FRAMES=/run/droiddeck-hud/frames", session)
app = (ROOT / "app/src/main/java/com/droiddeck/launcher/hud/HudFrames.kt").read_text()
self.assertIn('"run/droiddeck-hud/frames"', app)
if __name__ == "__main__":
unittest.main()