GPU 渲染性能目标与基线(2026-11-11)¶
状态:stage 0 已可运行;本文定义“做到最好”的验收,不把 stage 0 当完成。
1. 现状¶
XTERVO_GPU=1 当前链路:
CPU Renderer 逐像素画终端 framebuffer
-> queue.write_texture(只传 dirty rows,首帧/resize 整帧)
-> slint::Image::try_from
-> Slint/Skia WGPU 合成
这解决了“显示走 GPU/同 device/无回读”,但终端内容仍是 CPU 合成。
小 pane 实测(80x24,Xvfb llvmpipe):
[render] pane=1 draw=0.05..0.26ms image=0.00ms
[gpu-profile] upload_frames=1 rows=528 bytes=1520640 upload_us=487.79
结论:
因此性能优化重点不是“把 CPU 画得更快”,而是:
2. 终极目标¶
Term -> Scene
TextBatch / ImageInstance / Cursor / Selection / Damage
-> WGPU Renderer
glyph atlas
instanced glyph quads
image textures + UV/source_rect + z-order
damage scissor
-> 终端 texture
-> Slint UI 合成
硬约束:
不产生 CPU 终端 framebuffer(默认路径)
CPU fallback 仍可用,且与 GPU 像素对齐
不每帧整屏 upload
不每帧新建 texture/buffer
不 GPU->CPU readback
终端与 Slint 同一 Device/Queue
3. 性能预算(待测量校准)¶
3.1 帧¶
3.2 CPU¶
Scene build: < 1ms(典型 200x50)
每帧 CPU 分配: 稳态 0
默认路径 CPU 终端 framebuffer: 0
glyph raster: 只在 cache miss
3.3 GPU 上传¶
3.4 内存¶
atlas: 上限固定,LRU 可回收
image texture: 随 source 生命周期释放
pane texture: 随 pane 释放
15m soak RSS 非线性增长;30m release 收敛
4. 分阶段验收¶
Stage 0:CPU framebuffer -> WGPU texture(已有)¶
Stage 1:Scene + CPU 对照¶
Stage 2:WGPU 文字¶
[ ] glyph atlas(R8/RGBA)
[ ] instanced quads + WGSL
[ ] 一个 render pass 到 offscreen texture
[ ] CPU/WGPU 文字像素对照
[ ] 无 CPU framebuffer 文字路径
[ ] 每帧 draw call/upload 统计
Stage 3:WGPU 图片/光标¶
[ ] image texture/source_rect/UV
[ ] z-order/above_text
[ ] RowId placement
[ ] cursor overlay
[ ] 图片生命周/回收
Stage 4:默认 GPU¶
5. 基准矩阵¶
终端尺寸: 120x32 / 200x50 / 3840x2160
内容: ASCII / CJK / emoji / 组合字符
操作: typing / scroll / alt-screen / images / resize
后端: CPU / WGPU llvmpipe / real GPU
测量: frame p50/p95, CPU%, upload bytes/frame, draw calls, atlas hit, RSS
6. 禁止的“伪优化”¶
每帧整屏 queue.write_texture
每帧新建 texture/SharedPixelBuffer
每帧 take_snapshot/copy_texture_to_buffer
为 GPU 再跑一个 clear/quad 全屏 pass
整窗 CPU 合成多 pane
在 UI 线程 device.poll(wait)
只 request_redraw 不重设 image 属性
7. 默认 GPU 是发布门禁¶
默认行为的目标:
如果 P2/P3 未完成:发布延期;不允许用 stage 0 冒充“默认 GPU 已完成”。
8. 当前判定¶
下一阶段从 Scene + WGPU 文字 glyph atlas 开始;图片/光标随后,默认 GPU 最后。