From 3429c6c0a400050284e9bedcaf8cc2ab1303ab1c Mon Sep 17 00:00:00 2001 From: shenlei Date: Wed, 14 Oct 2026 16:54:51 +0900 Subject: [PATCH] Android: render at the screen's native height (900-1080), 3D target kept 720 high UI and text now reach the screen 1:1 instead of through a 1.2x linear upscale. The 3D scale on Android is derived from a 720-high target and the two dynamic levels follow proportionally (720 -> 648 -> 630). DM_3D_SCALE still sets an absolute scale. OnePlus 13: 2376x1080 output, GPU 12.1 -> 11.9 ms/frame, 60 fps. Co-Authored-By: Claude Opus 5.5 --- dm/host/android/app/front_app.c | 10 +++++++--- dm/host/hle_oe.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/dm/host/android/app/front_app.c b/dm/host/android/app/front_app.c index 0e82347..9efa048 100644 --- a/dm/host/android/app/front_app.c +++ b/dm/host/android/app/front_app.c @@ -71,14 +71,18 @@ void front_run(void (*guest)(void)) { } // 只当「有窗口」标志用(hle_swkbd 据此决定弹不弹输入框)| Used only as a "has a window" flag (hle_swkbd decides from it whether to show the input box) void *front_metal_layer(void) { return (void *)(uintptr_t)1; } -// 主机档:原版高度 900 × 屏幕比例(宽取 8 的倍数,≤ 4096);掌机档 720 同比。比 16:9 窄的屏按 16:9。DM_GAME_RES=宽x高 覆盖 -// Docked profile: the original height 900 × the screen aspect ratio (width rounded to a multiple of 8, ≤ 4096); handheld uses 720 the same way. Screens narrower than 16:9 use 16:9. DM_GAME_RES=WxH overrides +// 主机档:屏幕原生高(夹在 900–1080)× 屏幕比例(宽取 8 的倍数,≤ 4096);掌机档 720 同比。比 16:9 窄的屏按 16:9。DM_GAME_RES=宽x高 覆盖 +// Docked profile: the screen's native height (clamped to 900–1080) × the screen aspect ratio (width rounded to a multiple of 8, ≤ 4096); handheld uses 720 the same way. Screens narrower than 16:9 use 16:9. DM_GAME_RES=WxH overrides uint64_t front_game_res(int docked) { unsigned w, h; const char *e = getenv("DM_GAME_RES"); if (e && sscanf(e, "%ux%u", &w, &h) == 2) return docked ? (uint64_t)h << 32 | w : (uint64_t)(h * 4 / 5) << 32 | (w * 4 / 5 + 3) / 4 * 4; double aspect = g_screen_w && g_screen_h ? (double)g_screen_w / g_screen_h : 16.0 / 9; if (aspect < 16.0 / 9) aspect = 16.0 / 9; - uint64_t hh = docked ? 900 : 720, ww = (uint64_t)llround(hh * aspect / 8) * 8; + // 主机档按屏幕原生高(900–1080 之间):界面与文字 1:1 上屏,不再经 1.2 倍线性放大发糊;3D 目标仍按 720 高(hle_oe.c),GPU 不变(OnePlus 13 实测 12.1 → 12.0 ms/帧)。 + // 上限 1080:2K 屏(1440 高)界面多画 78% 像素,换来的清晰度看不出 + // Docked uses the screen's native height (between 900 and 1080): UI and text go to the screen 1:1 instead of a blurry 1.2x linear upscale; the 3D target stays 720 high (hle_oe.c), GPU unchanged (OnePlus 13 measured 12.1 -> 12.0 ms/frame). + // Capped at 1080: on 2K screens (1440 high) the UI would draw 78% more pixels for sharpness nobody can see + uint64_t sh = g_screen_h < 900 ? 900 : g_screen_h > 1080 ? 1080 : g_screen_h, hh = docked ? sh : 720, ww = (uint64_t)llround(hh * aspect / 8) * 8; if (ww > 4096) ww = 4096; return hh << 32 | ww; } diff --git a/dm/host/hle_oe.c b/dm/host/hle_oe.c index ae3cbae..a4b153a 100644 --- a/dm/host/hle_oe.c +++ b/dm/host/hle_oe.c @@ -155,12 +155,14 @@ HLE_FORCE("_ZN2nn2oe20SetFocusHandlingModeENS0_17FocusHandlingModeE", "前后台 #include #define SCALE3D_MIN 0.70f #define SCALE3D_MID 0.72f -// 安卓缺省 0.8:输出高 900 时 3D 目标高 720(掌机档),界面仍按 900 画 | Android default 0.8: with output height 900 the 3D target is 720 high (handheld level), the UI is still drawn at 900 +// 安卓缺省按 3D 目标高 720 定比例(掌机档;输出高 1080 时 0.667、900 时 0.8),界面按输出高画;动态两级按同一比例跟着降(720 → 648 → 630 高,即旧的 0.72 / 0.70 × 900)。 +// DM_3D_SCALE 给了就照旧按绝对比例 +// Android default derives the scale from a 720-high 3D target (handheld level; 0.667 at output height 1080, 0.8 at 900), the UI is drawn at the output height; the two dynamic levels drop in the same proportion (720 -> 648 -> 630 high, i.e. the old 0.72 / 0.70 x 900). +// When DM_3D_SCALE is given, absolute scales as before #ifdef __ANDROID__ -#define DM_3D_SCALE_ANDROID 0.8f -#else -#define DM_3D_SCALE_ANDROID 1.0f +#define DM_3D_H_ANDROID 720.0f #endif +#define DM_3D_SCALE_ANDROID 1.0f // 纯函数控制器(单测 t_oe.c 直接喂序列):level 0 = 配置值,越大越低。安全阀:只在可感的掉帧时动。 // 窗:每累计 2 秒的上屏间隔一个窗,窗内帧率 = 上屏帧数 ÷ 间隔之和(被系统丢掉的帧不计数,那段时间落在下一张上屏帧的间隔里)。 // 降:连续两个窗的帧率都 < 目标 × 0.92(60 帧时 55.2)→ 降一级。 @@ -227,9 +229,29 @@ static void scale3d_tick(void) { if (want_cfg < 0) { const char *e = getenv("DM_3D_SCALE"); want_cfg = TARGET_OS_IPHONE ? 0.75f : DM_3D_SCALE_ANDROID; if (e) { char *end; float v = strtof(e, &end); if (end == e || *end || !(v >= 0.5f && v <= 1.0f)) die("DM_3D_SCALE 非法:%s(要求 0.5–1.0)", e); want_cfg = v; } +#ifdef DM_3D_H_ANDROID + else want_cfg = 0; // 0 = 按 3D 目标高算(要等读到输出高) | 0 = derive from the 3D target height (needs the output height first) +#endif for (int i = 0; i < g_nmod; i++) if (!strcmp(g_mod[i].name, "main")) main = &g_mod[i]; } int lv = atomic_load(&g_scale3d_level); // 动态级:0 = 配置值,1 = 0.72,2 = 0.70(都不高于配置值) | dynamic level: 0 = configured value, 1 = 0.72, 2 = 0.70 (none higher than the configured value) +#ifdef DM_3D_H_ANDROID + if (!want_cfg) { + if (!main || dm_nvn_frame_count() < 30) return; + uintptr_t renderer = *(uintptr_t *)(main->base + 0x31e0848); if (!renderer) return; + uint32_t oh = *(uint32_t *)(renderer + 0xee8c); if (!oh) return; + float cfg = DM_3D_H_ANDROID / oh; if (cfg > 1.0f) cfg = 1.0f; if (cfg < 0.5f) cfg = 0.5f; + float dyn = lv == 0 ? cfg : cfg * (lv == 1 ? SCALE3D_MID : SCALE3D_MIN) / 0.8f, want = dm_nvn_ruler_truth() ? 1.0f : dyn; + if (want == cur) return; + uint32_t ow = *(uint32_t *)(renderer + 0xee88); if (!ow) return; + { extern void mtl_rt_force_full(int) __attribute__((weak)); if (mtl_rt_force_full) mtl_rt_force_full(4); } + float *scale = (float *)(renderer + 0x66a4); dm_guest_write_prepare(scale, sizeof *scale); *scale = want; + ((void (*)(uint32_t, uint32_t))(main->base + 0x8582f0))(ow, oh); + cur = want; atomic_store(&g_scale3d_cur, want); + LOG("3D 渲染比例 %.3f:3D 目标 %ux%u,输出 %ux%u(帧 %llu)", want, *(uint32_t *)(renderer + 0xee78), *(uint32_t *)(renderer + 0xee7c), ow, oh, (unsigned long long)dm_nvn_frame_count()); + return; + } +#endif float dyn = lv == 0 ? want_cfg : lv == 1 ? SCALE3D_MID : SCALE3D_MIN; if (dyn > want_cfg) dyn = want_cfg; float want = dm_nvn_ruler_truth() ? 1.0f : dyn; if (want == cur || !main || dm_nvn_frame_count() < 30) return;