From 4236b42a571748df879f1b978235d435e49c9d20 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Fri, 2 Oct 2026 03:09:17 -0400 Subject: [PATCH] [Fix] (Server+Transpiler): configure the server once per process, and enable blend_func_extended for index-1 outputs --- MobileGL/MG_Remote/Server/ServerMain.cpp | 15 ++++++++++++--- MobileGL/MG_Test/Program/ProgramTest.cpp | 16 ++++++++++++++++ .../MG_Util/ShaderTranspiler/SpvcSession.cpp | 12 +++++++++++- MobileGL/MG_Util/ShaderTranspiler/SpvcSession.h | 3 ++- .../anland/handoff-legacy-mobilegl-unified.md | 11 +++++++++-- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/MobileGL/MG_Remote/Server/ServerMain.cpp b/MobileGL/MG_Remote/Server/ServerMain.cpp index d696f304..3469f838 100644 --- a/MobileGL/MG_Remote/Server/ServerMain.cpp +++ b/MobileGL/MG_Remote/Server/ServerMain.cpp @@ -461,9 +461,18 @@ int RunSession(std::unique_ptr control, std::vectorabiMajor(), hello->abiMinor(), hello->wireFingerprint(), hello->buildFingerprint() ? hello->buildFingerprint()->c_str() : nullptr, hello->dialMode()) != MOBILEGL_OK) return LeaveBeforeAccept(sourceFd, sourceKind, 0); - MobileGL::MG_ConfigLoader::Init(); - MobileGL::MG_Config::Transport = MobileGL::MG_Config::TransportMode::Spawn; - MobileGL::MG_Pipe::MGPipeSetServerProcessRole(true); + // ONCE PER PROCESS, NOT PER SESSION. The configuration is the process's environment, the same + // for every session it serves, and re-reading it is not a no-op: Init() rewrites the globals + // in place - Transport first falls back to Monolith before the line below puts Spawn back - so + // a second session accepted while the first is applying showed that session's apply thread a + // monolith process for a moment. It then skipped the server stamp on a draw and died on + // Fatal{UnmigratedPipeInput}, taking every session in the process with it. + static std::once_flag s_serverConfigured; + std::call_once(s_serverConfigured, [] { + MobileGL::MG_ConfigLoader::Init(); + MobileGL::MG_Config::Transport = MobileGL::MG_Config::TransportMode::Spawn; + MobileGL::MG_Pipe::MGPipeSetServerProcessRole(true); + }); // PH-1 (3), ID-P7-1: THIS PROCESS IS THE SESSION, so a named fault on the peer's bytes may end // it cleanly instead of aborting it (FatalFunnel.h's latch block). Armed here and nowhere // else: inproc keeps every Fatal (client and server share that process), and the supervisor diff --git a/MobileGL/MG_Test/Program/ProgramTest.cpp b/MobileGL/MG_Test/Program/ProgramTest.cpp index 9ea6e2da..0c776a8f 100644 --- a/MobileGL/MG_Test/Program/ProgramTest.cpp +++ b/MobileGL/MG_Test/Program/ProgramTest.cpp @@ -1706,6 +1706,22 @@ TEST_F(ProgramTest, CompileAndLinkWithExplicitFragmentOut) { ASSERT_TRUE(strstr(resultIndexed, indexNeedle) != nullptr) << "Expected dual-source color index in generated shader.\n(Searching for \"" << indexNeedle << "\")"; + // The ESSL the GLES backend hands the driver keeps index 1, and ESSL accepts it only with + // GL_EXT_blend_func_extended enabled in the shader itself. + MG_Util::ShaderTranspiler::SpvcSession spvcSessionEs(fragSpirvIndexed, + MG_Util::ShaderTranspiler::SessionUsageBit::Transpile); + spvc_compiler_options optionsEs; + spvcSessionEs.CreateOptions(&optionsEs); + spvc_compiler_options_set_uint(optionsEs, SPVC_COMPILER_OPTION_GLSL_VERSION, 320); + spvc_compiler_options_set_bool(optionsEs, SPVC_COMPILER_OPTION_GLSL_ES, SPVC_TRUE); + spvcSessionEs.SetOptions(optionsEs); + spvcSessionEs.DropDefaultFragmentOutputColorIndex(); + const char* resultEs = nullptr; + spvcSessionEs.Compile(&resultEs); + ASSERT_NE(resultEs, nullptr); + EXPECT_NE(strstr(resultEs, indexNeedle), nullptr) << resultEs; + EXPECT_NE(strstr(resultEs, "#extension GL_EXT_blend_func_extended : require"), nullptr) << resultEs; + // glBindFragDataLocation is equivalent to index 0 and resets it. BindFragDataLocation(program, 0, "fragColor"); LinkProgram(program); diff --git a/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp b/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp index 93fd2b0c..0a2d6ecd 100644 --- a/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp +++ b/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.cpp @@ -470,12 +470,22 @@ namespace MobileGL { size_t count = 0; SPVC_CHK_RESULT(spvc_resources_get_resource_list_for_type( resources, SPVC_RESOURCE_TYPE_STAGE_OUTPUT, &list, &count)); + Bool dualSourceIndex = false; for (size_t i = 0; i < count; ++i) { const spvc_reflected_resource& resource = list[i]; if (!spvc_compiler_has_decoration(compiler, resource.id, SpvDecorationIndex)) continue; - if (spvc_compiler_get_decoration(compiler, resource.id, SpvDecorationIndex) != 0u) continue; + if (spvc_compiler_get_decoration(compiler, resource.id, SpvDecorationIndex) != 0u) { + dualSourceIndex = true; + continue; + } spvc_compiler_unset_decoration(compiler, resource.id, SpvDecorationIndex); } + // The index that stays is printed as `layout(index = 1)`, which ESSL accepts only + // with the extension enabled in the shader itself: the driver having it is not + // enough, and without the directive the stage is refused exactly as above. + if (dualSourceIndex) { + SPVC_CHK_RESULT(spvc_compiler_require_extension(compiler, "GL_EXT_blend_func_extended")); + } SPVC_CHK_RETURN } diff --git a/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.h b/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.h index f899e5bb..3f460548 100644 --- a/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.h +++ b/MobileGL/MG_Util/ShaderTranspiler/SpvcSession.h @@ -150,7 +150,8 @@ namespace MobileGL { // A NON-zero index is left exactly as it is: that one really does select the // second dual-source input and cannot be expressed without the extension, so it // must keep reaching the driver (the frontend's own glBindFragDataLocationIndexed - // path already emits only non-zero indices for the same reason). + // path already emits only non-zero indices for the same reason) - and the stage + // then requires GL_EXT_blend_func_extended, which ESSL wants enabled by name. spvc_result DropDefaultFragmentOutputColorIndex(); // Drops `readonly` and `writeonly` from every shader storage block - and every // block member - that carries BOTH of them. diff --git a/docs/Disaggregated/notes/anland/handoff-legacy-mobilegl-unified.md b/docs/Disaggregated/notes/anland/handoff-legacy-mobilegl-unified.md index daf58d71..07b8e8bb 100644 --- a/docs/Disaggregated/notes/anland/handoff-legacy-mobilegl-unified.md +++ b/docs/Disaggregated/notes/anland/handoff-legacy-mobilegl-unified.md @@ -15,6 +15,9 @@ anland 5.x 用 MobileGL:容器(Droidspaces,arch-kde-mgl)里的 Linux cli | Commit | 内容 | |---|---| +| (本提交) | server:配置只在进程内第一个 session 接入时初始化一次——此前每个新 session 接入都重跑 `MG_ConfigLoader::Init()`,它先把 `Transport` 写回 Monolith 再被改回 Spawn,正在 apply 的别的 session 恰好读到就跳过 server stamp,`Fatal{UnmigratedPipeInput, "GetBoundVertexArray@DrawArrays"}` 带走整个 server 进程(整个桌面);转译:保留下来的非零 `layout(index = 1)`(双源混合)在 ESSL 里加 `#extension GL_EXT_blend_func_extended : require`(此前 Adreno 拒绝该 stage,程序整体不画) | +| `0b6842ac` | 让 ANGLE 的 GL 后端跑在 MobileGL 上:EGL 声明 `EGL_KHR_platform_gbm`/`EGL_MESA_platform_gbm`(GBM display 当离屏 display,拒绝 gbm 窗口 surface;Chrome 的 Wayland GL 层对每个 display 都标 GBM 平台);平台标 GBM 但 native display 实为 wl_display 时按 Wayland 处理,wl_display 识别兼容自带一份 libwayland 的程序(按接口名 "wl_display" 判断,经 `process_vm_readv` 读,野指针不会崩);实现 `glGetShaderPrecisionFormat`(此前是空 stub,ANGLE 读到 0 精度即拒绝 ES 2.0);`GL_VERSION` 里不再出现 "OpenGL ES" 子串(ANGLE 用子串搜索判断 ES 驱动,"Direct (OpenGL ES) Backend" 让它把 MobileGL 当 ES 驱动、按 ES 扩展名查 BGRA 等能力,Chrome 的 shared image 全部创建失败) | +| `47db68d5` | GLX:MobileGL 同时是 glvnd 的 GLX vendor(`__glx_Main`,装成 `/usr/lib/libGLX_mobilegl.so.0`,会话设 `__GLX_VENDOR_LIBRARY_NAME=mobilegl`;此前 X11 客户端经 Xwayland 拿到 Mesa vendor,报 `MESA-LOADER: failed to retrieve device information`);远端 X drawable(pbuffer)每次 `glXSwapBuffers` 回读并用 `xcb_put_image`(按服务器最大请求长度分带)上屏,resize 换新 pbuffer;GLX 出口持流锁;`eglReleaseThread` 在 MobileGL 已被 `eglTerminate` 拆掉后也返回 TRUE(glmark2 退出时的 "eglReleaseThread failed") | | `ccf8eb65` | 客户端:多线程 GL 流串行化——每个 GL/EGL 出口持同一把流锁,写入前按「最后真正发出的 `bind_context`」把 server 绑到调用线程的 context(Qt 每个窗口一个 QSGRenderThread,此前两线程记录在同一 ring 上交错、落进错的 applier、甚至撕裂记录);`MGPipeTracker` 按 context 的永不复用 id 判断换 context(指针 ABA);导出 `eglCreateImageKHR`/`eglDestroyImageKHR`(KWin 在 shm client 断开时调空指针 → 首个 KWin 约 2 秒必 SEGV);`eglGetPlatformDisplayEXT` 的 EGLint 属性表加宽;多窗口:surface 激活不再清空别的线程的 current 记录,swap 呈现本线程的 surface;Wayland 窗口 `wl_egl_window_resize` 在下一次 make-current/swap 生效 | | `0b314dda` | server:所有 session 的 apply 线程在一把 FIFO「backend turn」上串行(DirectGLES 是按单 GL 线程写的:单一 owner 线程、进程级绑定影子),换手时接管 owner 并清掉绑定影子;全部原生 context 进同一 share group(环、池、scratch 纹理是进程级 GL 对象);每个客户端 surface 一个原生 surface(激活时重绑而非新建),建 surface 后恢复当前 context 自己原来的 surface,释放 surface 只销毁它(此前 `DestroyEGLContext` 带走整个 session 的 context),`bind_context` 恢复 context 自己的 surface;pbuffer 背后的窗口 resize = 换新 pbuffer;session 结束时若别的 session 的 context 还活着,只清本 session 的东西(此前进程级 generation 被推进,所有活 session 的纹理/缓冲被当成死的空重建 → 关弹窗/退出 client 后全屏噪点);分块上传(stage chunk 切片)的 region 偏移按整层图像校验(此前 KWin 的 wl_shm 纹理在第 819 行后读到第 0 行);`SetSamplerViews.Count` 改为 per-session latch | | `30fef23d` | P14 收尾(统一 server 的两处进程级状态):server 的两个 staged store(纹理 level 声明、buffer shadow)按调用线程的 {session, share group} 分桶(与 S6 twin 表同一个探针),`DropAll` 只清本 session;`MGPipeServerSetContextLive` 的 live 标志从进程全局移进本 session 的 PipeInputs 块。各带单测(`StagedTextureStoreTest` 两例、`ServerContextLiveTest`) | @@ -45,10 +48,11 @@ anland 5.x 用 MobileGL:容器(Droidspaces,arch-kde-mgl)里的 Linux cli - **链路绿屏**:client clear → server(Adreno 750 厂商驱动)→ Android Surface → 屏幕,截图可见(win-smoke,60 帧 swap 无错误)。 - **egl-smoke**:pbuffer + clear + readback RGBA 精确(64,128,191,255)。 - **eglinfo**:GLVND vendor JSON 正常,EGL 1.5,两组配置。 -- **glxinfo**:GLX 1.4,Espryt (Adreno 750),GL 4.6 core,exit 0(注意:GLX 只到查询,无 X11 上屏)。 +- **glxinfo / glmark2(X11)**:经 glvnd 的 MobileGL GLX vendor,不需 `LD_LIBRARY_PATH`;glxinfo 报 Espryt (Adreno 750) GL 4.6;glmark2(X11 窗口经 Xwayland)画面正确上屏,shading 场景约 280 fps;glmark2-wayland / glmark2-es2-wayland 正常且退出无报错。 - **KWin 6.7.4**:合成器存活并呈现(黑桌面+光标可见)。 - **Konsole**:窗口完整正确渲染(标题栏、工具栏、shell 提示符,方向正确)。 - **多 session**:两个 win-smoke 连续运行同一窗口均 exit 0(stale surface 修复生效)。 +- **Chrome 跑在 MobileGL 上(2026-10-02)**:会话的 Chrome 启动项(`mobilegl-startup.sh chrome`,plasma 模式写入用户级 `google-chrome.desktop` 覆盖)用 `--use-gl=angle --use-angle=gles --in-process-gpu --render-node-override=<不存在的节点> --disable-features=WaylandFractionalScaleV1`:ANGLE 报 `ANGLE (MobileGL-Dev…, Espryt…, OpenGL 4.6.0 MobileGL…)`,GPU 合成开启,标签栏/工具栏/网页正确合成,缩放正确。为什么这样配:Chrome 的独立 GPU 进程在 Wayland 上只能经 GBM dma-buf 上屏(MobileGL 与本 KWin 都不收),放进浏览器进程后改走 wl_egl_window(MobileGL 的 wl_shm 呈现);该路径下 Chrome 不发 fractional-scale 的 viewport,整数缩放才会发 `set_buffer_scale`。此前镜像自带的 `/usr/local/bin/google-chrome` 是 `--use-angle=vulkan` + renderD128,走的是容器里的 Turnip。 - **Plasma 桌面可用(2026-10-02,`ccf8eb65`:server 与容器 client 同源)**:壁纸、面板、托盘、时钟、桌面图标、Kickoff 开始菜单、通知窗口都正确渲染;鼠标/触摸输入可用(点击打开 Kickoff);KWin 过渡动画正常;开/关托盘弹窗不再花屏;按返回键收起快捷键栏时输出 resize 跟随。三线程/三 context/三 surface 并发回读探针(`anland-egl-mt-readback-probe.c`)与大纹理分块上传探针(`anland-egl-upload-probe.c`)全过。 - **Plasma 会话(早期,`30fef23d` 的 server + `ff212061` 的容器 client)**:`desktop-session.service` 持续 active(>1 分钟,此前约 7 秒必拆);面板完整渲染(启动器、固定应用、托盘、时钟);光标尺寸正常;多个 session 并发、逐个 reap 而其余继续服务。截图里壁纸有横向条带错位(见下面第 1 条)。 @@ -60,9 +64,11 @@ anland 5.x 用 MobileGL:容器(Droidspaces,arch-kde-mgl)里的 Linux cli - **ksplash 启动动画闪黑**:开机时 ksplash 帧间偶有整帧黑;单独 `ksplashqml --test` 在会话内不复现。约 13–15 fps(每帧 2560x1412 全尺寸回读 + wl_shm + KWin 重新上传),见第 3 条。 - 合成成本:每个 Wayland 窗口每帧整幅 glReadPixels(2 MiB 一片)+ KWin 整幅 glTexSubImage,是当前帧率上限。 - DirectGLES 里少量进程级「容器」对象(resolve FBO、scratch FBO、XFB helper、timer query 探测)不在 share group 里共享,多 session 交替使用时理论上会拿到别的 context 的名字——尚未观察到症状。 + - **Chrome 剩余渲染问题**:WebGL 画布不显示(get.webgl.org 的立方体区域空白、aquarium 只有底色,fps 计数正常),工具栏两个扩展图标是黑块;两边日志都无报错,待查(怀疑 shared image 的某种格式/swizzle 或画布合成路径)。 + - **锁屏界面花屏**:`kscreenlocker_greet`(空闲约 5 分钟自动锁屏)背景是噪点、时钟重复三份,疑似 1x1→2560x1412 resize 后读回尺寸/步长不对;锁屏后只能输密码,复现时用 `loginctl lock-session` / `unlock-session`。 2. **光标巨大化**:2026-10-02 的 Plasma 会话截图里光标尺寸正常,未再复现;若再现,查 output scale 与 cursor layer 的 buffer scale。 3. **CPU blit 禁令**:用户明确要求最终形态上屏路径无 CPU blit——当前 Wayland wl_shm client 走 readback(`32c79f41`),只是过渡。目标:应用窗口内容也由 server 在 GPU 侧直接给 KWin 合成(server 侧 GPU buffer → 同进程共享给 compositor 的 share group → 合成上屏),不经过 CPU 回读。设计要进 11-state-ownership.md 的后续切片。 -4. **GLX 无上屏**:X drawable 仅远端 pbuffer 查询,无 X11 readback/present。 +4. **GLX 上屏是 CPU 回读**:每帧整幅 glReadPixels + `xcb_put_image`,同第 3 条的过渡方案;只处理 24/32 位深窗口;直接拿 X 窗口(未经 glXCreateWindow)当 drawable 的 surface 不会随窗口销毁回收。 5. **surface loss**:Wayland 窗口 resize 已跟随(`ccf8eb65`);surface loss 仍结束活动 session(无损挂起未实现);server 进程被杀后,新进程下 KWin 拿不到窗口 surface(KWin 不会重连,需重启会话)。 6. **AVC 审计未做**:全程在 Enforcing 下跑通(容器侧有 droidspacesd 的既有 permissive 规则),SCM_RIGHTS/memfd 的精确 AVC 采集没做。 7. **wire stamp 漂移**:容器构建的 `MGGitHash.h` 因 tar 无 .git 而陈旧(日志 WARN "compatible wire with different build");两端应同 commit + 显式 `-DMOBILEGL_BUILD_STAMP` 重建。 @@ -76,6 +82,7 @@ anland 5.x 用 MobileGL:容器(Droidspaces,arch-kde-mgl)里的 Linux cli - KWin 启动:`desktop-session.service` + drop-in ExecStart=mobilegl-startup.sh compositor|plasma;Qt 日志默认只出 warning(info 要 QT_LOGGING_RULES)。 - **当前设备上的 server 库是手工替换的**:`libMobileGL.so` 直接 root 覆盖到已装 APK 的 `/data/app/.../lib/arm64/`(保留 owner/SELinux context,原件备份在 `/data/local/tmp/anland-mobilegl/libMobileGL.so.orig`)。这样不用重签 APK(换签名要卸载重装,UID 会变,KernelSU grant 要重做)。本机构建:NDK 27.2 + `cmake -DCMAKE_TOOLCHAIN_FILE=.../android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-26 -DMOBILEGL_BUILD_DISAGGREGATED=ON -DMOBILEGL_BUILD_DISAGGREGATED_INPROC=ON -DMOBILEGL_BUILD_STAMP=`,`llvm-strip --strip-debug` 后推送。 - **复现用探针**(anland `producers/kde/Arch_v5/mobilegl-tools/`):`anland-egl-upload-probe.c`(2560x1412 纹理整幅 + 跨分片的局部 TexSubImage 回读校验)、`anland-egl-mt-readback-probe.c`(三线程各自 context/pbuffer 并发绘制+整幅回读);在容器里以 swung0x48 身份、带 MobileGL 的 `__EGL_VENDOR_LIBRARY_FILENAMES`/`MOBILEGL_*` 环境运行。注入点击要用 `input mouse tap`(anland 抓了触摸屏 EVIOCGRAB,`input tap` 无效);不要对容器进程用 `debuggerd -b`(发 signal 35,glibc 进程直接被杀)。 +- **Chrome/ANGLE 排查手段**:`--gpu-launcher=<脚本>` 包 GPU 进程(strace 每进程 `-o file.$$`,Chrome 会多次重启 GPU 进程);ANGLE 只 `dlsym` 一个 `eglGetProcAddress`,其余入口全经它取,LD_PRELOAD 拦 `dlsym` 再包 `eglGetProcAddress` 才能看到 display 调用;headless Chrome + `--remote-debugging-port` + CDP `SystemInfo.getInfo` 能拿到 GL_RENDERER/扩展列表/featureStatus(`--dump-dom chrome://gpu` 在 headless 下拿到的是新标签页)。user manager 里 PAM 带进来的 Mesa/KGSL 变量 `systemctl --user unset-environment` 删不掉(返回 0 但无效),对 MobileGL 会话无害。 - **诊断用的容器改动**:`/opt/mobilegl/kwin/bin/kwin_wayland` 现在是 shim(设 `MOBILEGL_LOG_FILE_PATH=/tmp/mgl-kwin-$$.log` 后 exec `/opt/mobilegl/kwin/real/kwin_wayland`;真二进制必须仍叫 `kwin_wayland`,否则 KWin 内置 QPA 插件拒绝加载);`~swung0x48/.config/systemd/user/plasma-plasmashell.service.d/mobilegl-log.conf` 给 plasmashell 单独日志 `/tmp/mgl-plasmashell.log`。MobileGL 打开日志是截断写,所以必须每进程一个文件。 - 构建(之前那台机器的环境,本机没有 `/root/anland-mgl-build` 也没有 gitignored 的 `build_bundled_apk.sh`;APK 按 `consumers/anland_v5/android_consumer/MOBILEGL.md` 用 gradle + `MOBILEGL_DIST` 构建):Android dist 用 WSL(NDK r27c,stamp 显式指定);APK 用 anland worktree 的 `build/build_bundled_apk.sh`;容器 client 用 `producers/kde/Arch_v5/mobilegl-tools/anland-sync-source.sh build`(`MOBILEGL_REPO` 指向已 init 子模块的 MobileGL worktree;注意 `tools/trace_replay` 789MB 必须排除)。 - 设备 30 秒无操作熄屏——熄屏可能 kill SurfaceView;长跑验证前 `svc power stayon true` 或调 screen_off_timeout。