fix(web): stop the transfer-FBO leak and the canvas-freeze resize churn
- renderer: release_transfer_images() deletes the transfer framebuffer instead of only zeroing the name; the leak exhausted VRAM and killed the GPU process under Vulkan after ~3-7 minutes - canvas: status notices are absolute overlays, so they no longer resize the native surface (each show/hide freed and recreated region draw buffers and eventually froze the main regions) - compute: bounded shader/layout/pipeline caches, staging pool, device-lost error propagation, dev-only ?glStats / ?computeFault / ?compute hooks - headed tools: soak/probe/smoke assets and docs - evidence: 20-minute Vulkan soak STABLE (GPU-SOAK-20261205-161007), SwiftShader control STABLE (GPU-SOAK-20261205-162105), Clip 28/28 NOT_CLAIMED (CLIP-HEADED-20261205-162214) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
96
docs/web/HEADED-TOOLS.md
Normal file
96
docs/web/HEADED-TOOLS.md
Normal file
@@ -0,0 +1,96 @@
|
||||
# 有头浏览器测试工具(`tools/web/headed/`)
|
||||
|
||||
这些工具从「原生桌面画布 GPU 进程崩溃」的排查中沉淀而来,按用途分为 `probe` / `smoke` / `soak`
|
||||
三类。它们不绑定某一次排查:换任意页面入口、任意 Chrome 参数都能用。
|
||||
|
||||
与五个 `run-*-headed.mjs` 套件运行器的分工:`run-` 前缀负责编排一条验收流程并出回执;
|
||||
这里的工具是单点动作,供排查和 soak 使用,也可以被其他脚本 import。
|
||||
|
||||
## 前置条件
|
||||
|
||||
- Playwright 从 `web/node_modules` 解析(`lib/browser.mjs` 用 `createRequire` 加载)。
|
||||
- 有头采集需要可用的 `DISPLAY`(本机为 `DISPLAY=:1`)。
|
||||
- Chrome 解析顺序:`WBV2_CHROME_PATH` → `google-chrome-stable` / `google-chrome` / `chromium` → `which`。
|
||||
- 被测来源必须可达;默认 `http://127.0.0.1:5173/`。
|
||||
- 对照页由 `lib/serve.mjs` 自带静态服务在 127.0.0.1 拉起(带 COOP/COEP,保证 `SharedArrayBuffer`),不引入新依赖。
|
||||
|
||||
## 工具一览
|
||||
|
||||
| 工具 | 作用 | 典型用法 |
|
||||
| --- | --- | --- |
|
||||
| `probe/probe-webgpu-flags.mjs` | 参数矩阵探测:每组 flags 各开一次应用,记录 `navigator.gpu`、适配器 vendor/architecture、能否建设备、WebGL2 renderer、引擎侧 WebGPU 报错 | `DISPLAY=:1 node tools/web/headed/probe/probe-webgpu-flags.mjs` |
|
||||
| `probe/probe-page-state.mjs` | 打开页面读状态:引擎/WASM 状态、原生画布属性、回退提示、canvas 列表、WebGL2 renderer | `DISPLAY=:1 node tools/web/headed/probe/probe-page-state.mjs --url http://127.0.0.1:5173/` |
|
||||
| `smoke/smoke-headed-boot.mjs` | 启动冒烟:等引擎 ready,断言原生画布/回退提示的期望状态 | `DISPLAY=:1 node tools/web/headed/smoke/smoke-headed-boot.mjs --flags="--enable-unsafe-webgpu" --expect-native true` |
|
||||
| `smoke/check-canvas-render.mjs` | 原生画布真的画出了东西:适配器存在、画布打开、截图非空 | `DISPLAY=:1 node tools/web/headed/smoke/check-canvas-render.mjs --flags="--enable-unsafe-webgpu"` |
|
||||
| `soak/soak-interaction.mjs` | 交互 soak:滚轮/拖拽/点击/快捷键循环,监听 Chrome stderr 崩溃行,截图差异做存活判定,可选调用 `__WBV2_GPU_STATS()` | `DISPLAY=:1 node tools/web/headed/soak/soak-interaction.mjs --minutes=10 --flags="--enable-unsafe-webgpu,--enable-features=Vulkan"` |
|
||||
| `fixtures/webgpu-control/index.html` | 最小 WebGPU 对照页(WGSL compute + render 循环),区分「浏览器/驱动问题」与「应用负载问题」 | 由 soak/探针经 `lib/serve.mjs` 打开 |
|
||||
| `fixtures/webgpu-control/main.js` | 最小对照页的 WGSL 与循环实现 | 由 `index.html` 引入 |
|
||||
| `fixtures/webgpu-control/control-combined.html` | WebGL2 渲染 + WebGPU 计算共存对照页(引擎托管模型的最小复刻) | 同上 |
|
||||
|
||||
共享库:
|
||||
|
||||
| 库 | 内容 |
|
||||
| --- | --- |
|
||||
| `lib/browser.mjs` | 仓库根/`WEB_DIR` 解析、Playwright 加载、硬件与 SwiftShader 参数表、`resolveChrome()`、`freePort()`、`launchChrome()`(spawn + `--remote-debugging-port` + `connectOverCDP` + stderr 逐行回调 + 确定性关闭)、`normalizeArgs()` |
|
||||
| `lib/crash-watch.mjs` | Chrome stderr 崩溃模式(`GPU process exited unexpectedly`、`exit_code=133`、`Check failed`、`FATAL`、`ContextResult::kTransientFailure`、`GPU state invalid`)与计数、时间戳 |
|
||||
| `lib/receipt.mjs` | `tests/golden/<topic>-<stamp>/report.json` 写入(不覆盖、带 `schemaVersion`、`acceptance:"NOT_CLAIMED"`);媒体默认写 `/tmp/<topic>-<stamp>/` |
|
||||
| `lib/preflight.mjs` | DISPLAY / Chrome / 来源可达性预检 |
|
||||
| `lib/liveness.mjs` | 截图缓冲哈希与 `snapshot()`,供 soak 判「画布还在变」 |
|
||||
| `lib/serve.mjs` | 对照页静态服务(127.0.0.1、COOP/COEP) |
|
||||
|
||||
## 共享命令行契约
|
||||
|
||||
与五个 `run-*-headed.mjs` 对齐:
|
||||
|
||||
| 参数 | 含义 |
|
||||
| --- | --- |
|
||||
| `--url <origin>` | 被测来源,默认 `http://127.0.0.1:5173/` |
|
||||
| `--flags <csv>` | 追加给 Chrome 的参数,逗号分隔;`--name=value` 与 `--name value` 两种写法都接受 |
|
||||
| `--minutes N` | soak 时长(`soak-interaction`,默认 3) |
|
||||
| `--expect-native true\|false\|any` | `smoke-headed-boot` 对原生画布的期望 |
|
||||
| `--expect-fallback true\|false\|any` | `smoke-headed-boot` 对回退提示的期望 |
|
||||
| `--shots <dir>` | 截图目录(默认 `/tmp/<topic>-<stamp>/`) |
|
||||
| `--out <dir>` | 回执目录(默认 `tests/golden/<topic>-<stamp>/`) |
|
||||
| `--json-only` | 完整报告打到 stdout |
|
||||
| `--help` | 用法 |
|
||||
|
||||
退出码:`0` 通过 / `1` 判定失败(或 soak 非 STABLE)/ `2` 前置条件不满足 / `64` 参数错误。
|
||||
|
||||
## 回执
|
||||
|
||||
- 位置:`tests/golden/GPU-PROBE-<stamp>/`、`tests/golden/HEADED-SMOKE-<stamp>/`、`tests/golden/GPU-SOAK-<stamp>/`。
|
||||
- 结构:`schemaVersion: 1`、`tool`、`url`、`flags`、`chrome`、`preflight`、`acceptance: "NOT_CLAIMED"` 加各工具自己的字段。
|
||||
- 重复运行不会覆盖:每次新时间戳一个目录。
|
||||
- 截图与完整 stderr 默认不入库;需要留证时用 `--shots`/`--out` 指到指定位置。
|
||||
|
||||
## 已验证结论(2026-12-05,Chrome `google-chrome-stable`,NVIDIA RTX 4060,`DISPLAY=:1`)
|
||||
|
||||
参数矩阵(`probe-webgpu-flags.mjs`,回执 `tests/golden/GPU-PROBE-20261205-035922/`):
|
||||
|
||||
| flags | `navigator.gpu` | 适配器 | 建设备 |
|
||||
| --- | --- | --- | --- |
|
||||
| 无参数 | 有 | **null** | — |
|
||||
| `--enable-unsafe-webgpu` | 有 | google / swiftshader | 成功 |
|
||||
| `--enable-unsafe-webgpu --ignore-gpu-blocklist` | 有 | google / swiftshader | 成功 |
|
||||
| `--enable-unsafe-webgpu --enable-features=Vulkan` | 有 | nvidia / lovelace | 成功 |
|
||||
| 同上 + `--use-angle=vulkan` | 有 | nvidia / lovelace | 成功 |
|
||||
|
||||
- 无参数(Chrome 默认)拿不到适配器:应用侧已回退到 Web 业务工具视图并显示提示
|
||||
(`data-testid="webgpu-fallback-notice"`)。`smoke-headed-boot.mjs` 两种模式均 PASS:有 flags → 原生画布打开;
|
||||
无 flags → 原生画布关闭 + 回退提示出现。
|
||||
- 10 分钟交互 soak:SwiftShader 稳定;`--enable-features=Vulkan`(真实 NVIDIA)在约 408 秒出现
|
||||
`GPU process exited unexpectedly`,退出码 133;同参数最小 WebGPU 对照页稳定 → 崩溃由引擎负载触发,
|
||||
不是浏览器/驱动本身。
|
||||
- 根因已定位并修复:`WebGLFrameBuffer::release_transfer_images()` 泄漏 transfer FBO(见
|
||||
`docs/web/KNOWN_LIMITATIONS.md`)。修复后 20 分钟 Vulkan soak 为 0 次 GPU 进程崩溃;暴露出的
|
||||
`CANVAS_STALL`(约 5 分钟后主区域停绘)已定位为流内状态提示条反复 resize 原生画布、触发 region
|
||||
draw buffer 重建,提示条改为绝对定位覆盖层后,20 分钟 Vulkan soak 判 `STABLE`
|
||||
(`tests/golden/GPU-SOAK-20261205-161007/`)。
|
||||
- 2 分钟 soak 冒烟:STABLE,33 轮,画布持续刷新,零崩溃行(回执 `tests/golden/GPU-SOAK-20261205-040136/`)。
|
||||
|
||||
## 新增工具的约定
|
||||
|
||||
1. 按用途放进 `probe/` / `smoke/` / `soak/`,动词前缀与上表一致。
|
||||
2. 复用 `lib/`:启动一律走 `launchChrome()`,参数一律先 `normalizeArgs()`,回执一律走 `writeReceipt()`。
|
||||
3. 回执 topic 用大写短横线名(`GPU-PROBE`、`HEADED-SMOKE`、`GPU-SOAK`)。
|
||||
4. 写完后在本文件的工具表登记,并运行 `node tools/web/check-headed-tools.mjs` 校验表与磁盘一致。
|
||||
@@ -17,10 +17,30 @@ boundary; the legacy `parity-ledger.json` is historical planning data.
|
||||
and is subject to adapter availability and limits. Chromium on Linux exposes no WebGPU adapter
|
||||
by default: launching with `--enable-unsafe-webgpu` selects the SwiftShader adapter, which a
|
||||
10-minute headed soak kept stable, while the NVIDIA Vulkan path
|
||||
(`--enable-unsafe-webgpu --enable-features=Vulkan`) rendered but crashed the GPU process
|
||||
(exit 133) after ~7 minutes of interaction, and a minimal WebGPU control page stayed stable on
|
||||
the same configuration — so the crash is tied to the engine's WebGPU workload, not to the
|
||||
machine. A browser without an adapter no longer shows a black canvas: the app probes
|
||||
(`--enable-unsafe-webgpu --enable-features=Vulkan`) crashed the GPU process (exit 133) after
|
||||
~3–7 minutes of interaction before the fix below. A minimal WebGPU control page stayed stable
|
||||
on the same configuration, so the crash was tied to the engine workload, not to the machine.
|
||||
- GPU-process crash root cause and fix: `WebGLFrameBuffer::release_transfer_images()` zeroed
|
||||
`transfer_id_` without calling `glDeleteFramebuffers`, leaking one framebuffer per
|
||||
clear/copy/blit/readback; `?glStats=1` counted ~11k more framebuffers created than deleted in
|
||||
53 s of idle interaction and idle VRAM rose from 488 MiB to ~7.7 GiB in ~65 s before the GPU
|
||||
process was killed (`vkCreateSwapchainKHR failed`). The method now deletes the transfer
|
||||
framebuffer before zeroing the name. After the fix idle VRAM stays at ~700 MiB, and with the
|
||||
canvas-freeze fix below the 20-minute Vulkan interaction soak is `STABLE`
|
||||
(`tests/golden/GPU-SOAK-20261205-161007/`: 351 rounds, canvas alive throughout, zero
|
||||
GPU-process crashes).
|
||||
- Canvas freeze root cause and fix (pre-existing, only visible once the crash was gone): after
|
||||
~5 minutes of interaction the native canvas's main regions (viewport, outliner, properties)
|
||||
stopped drawing and turned blank while the page, compositor and DOM HUD kept running; native
|
||||
operators still executed and repainted the status bar. The ECMAScript region-recovery path
|
||||
(`wm_draw.cc`: "Browser region requires redraw" / "Browser region draw buffer is unavailable")
|
||||
recreates region draw buffers when the surface size changes. The in-flow status notice
|
||||
(`operationNotice` / `grabNotice`) shrank the canvas from 1440x900 to 1440x882 on every
|
||||
show/hide, freeing and recreating those buffers on nearly every viewport click. Both notices are
|
||||
now absolutely positioned overlays that do not participate in layout. A/B: the same 12-minute
|
||||
interaction probe froze at ~5 minutes before the change and completed 222 rounds with zero
|
||||
frozen frames after it.
|
||||
- A browser without an adapter no longer shows a black canvas: the app probes
|
||||
`navigator.gpu.requestAdapter()` at startup, hides the native canvas, shows the Web
|
||||
business-tools view and a dismissible notice instead.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user