Repository navigation
perf(wasm): Repaint only damaged regions on WebGL - #26041
MartinZikmund wants to merge 3 commits into
Conversation
An antialiased, fractional damage clip blends cleared and redrawn edge pixels with the retained ones, and a multi-rect AA path clip is costly on the GPU. Snap outwards and use a hard rect/region clip instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA
WebGL was the only host that repainted the whole canvas every frame: it reported no retained contents, and the canvas carried 4x MSAA and a depth buffer Skia never uses. Create it single-sampled with a preserved drawing buffer so the compositor repaints only the damaged regions. SwiftShader (weak-GPU proxy, 2560x1600 ProgressRing): 23-25 fps -> 101-107 fps; hardware GPU under 6x CPU throttle: neutral. An FBO + blitFramebuffer variant was slower (18.6 fps), the full copy dominates. The canvas size is floored, since re-assigning it clears the preserved buffer, and a resize or lost context repaints whole. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA
|
Claude finished @MartinZikmund's task in 30s —— View job PR review summaryVerdict: ship, with minor follow-ups. I reviewed this by reading the diff only. I did not build it or run any tests. Findings: 0 high, 0 medium, 2 low. Both are inline comments:
Cross-cutting notes
|
| } | ||
|
|
||
| /** False when the drawing buffer lost the previous frame: resizing the canvas or losing the context clears it. */ | ||
| public static isContentPreserved(instance: WebGlBrowserRenderer): boolean { |
There was a problem hiding this comment.
isContentPreserved reads like a query but mutates lastWidth/lastHeight, so a second call in the same frame returns true even after a resize. It works today because AcquireRenderTarget calls it once per frame, but the contract is fragile. Consider renaming it (e.g. consumeContentPreserved) or documenting the side effect in the doc comment.
Also, after a context loss and restore, the result is true again on the next frame. Skia's GrDirectContext may then still hold stale GL state. Please confirm this path is handled elsewhere, e.g. by a context-restored handler that recreates the backend.
| // The preserved drawing buffer keeps the previous frame, so only the damaged regions are repainted. No MSAA: | ||
| // Skia's coverage AA does not use it, and resolving it costs a full-canvas pass every frame. No depth either: | ||
| // Skia only needs the stencil. | ||
| this.glCtx = EmscriptenWebGL.createContext(this.canvas, { antialias: 0, depth: 0, stencil: 8, preserveDrawingBuffer: 1 }); |
There was a problem hiding this comment.
preserveDrawingBuffer: 1 forces a copy or blocks the swap-chain flip on some tiled mobile GPUs and compositors, and it can cost more than the damage savings there. The PR notes this is not yet measured on a physical low-end device. Please validate on one (e.g. a mid-range Android) before merge, or consider a fallback to full repaint if it regresses.
There was a problem hiding this comment.
🟡 Changes recommended
Critical buffer-preservation checks miss resize round-trips and same-size WebGL context restoration, allowing partial or skipped repaints over a cleared drawing buffer.
2 open issues
What changed in this PR
This PR addresses #26040 by enabling damage-region repainting for the WebAssembly WebGL host and correcting damage clipping on Skia hosts that retain frames.
Changes:
- Preserves the WebGL drawing buffer and disables unused MSAA and depth buffers.
- Adds preservation checks and avoids redundant canvas resets from fractional dimensions.
- Uses pixel-aligned, non-antialiased damage clips and adds regression tests.
| File | Description |
|---|---|
src/Uno.UI.RuntimeTests/Microsoft/UI/Composition/Given_SkiaPresentSession.cs |
Tests fractional damage edges and disjoint damage regions. |
src/Uno.UI.Runtime.WebAssembly.Browser/ts/Runtime/WebGlBrowserRenderer.ts |
Configures buffer preservation and checks canvas/context state. |
src/Uno.UI.Runtime.WebAssembly.Browser/ts/Runtime/BrowserRenderer.ts |
Floors canvas dimensions to avoid redundant buffer clears. |
src/Uno.UI.Runtime.WebAssembly.Browser/Rendering/WebGlBrowserRenderer.cs |
Exposes preservation checks and simplifies framebuffer metadata. |
src/Uno.UI.Runtime.WebAssembly.Browser/Rendering/WasmGraphicsContext.cs |
Reports frame preservation to the compositor. |
src/Uno.UI.Composition.Skia/Composition/Uno/Drawing/SkiaPresentSession.cs |
Snaps damage outward and applies hard rectangular or region clips. |
Review effort: Balanced
| const unchanged = canvas.width === instance.lastWidth && canvas.height === instance.lastHeight; | ||
| instance.lastWidth = canvas.width; | ||
| instance.lastHeight = canvas.height; |
| const gl = instance.anyGL.getContext(instance.glCtx)?.GLctx; | ||
| return unchanged && !!gl && !gl.isContextLost(); |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243642 found UI Test snapshots differences: Details
|
|
Tick the box to add this pull request to the merge queue (same as
|

GitHub Issue: closes #26040
PR Type:
✨ Feature (performance)
What changed? 🚀
WebGL was the only Skia host that repainted the whole canvas every frame.
WasmGLGraphicsContext.PreservesContentswas alwaysfalse, so the compositor's damage-region path never ran, and the canvas carried 4x MSAA and a depth buffer that Skia never uses.preserveDrawingBuffer, so the compositor repaints only the damaged regions. A resized canvas or a lost context repaints whole.setCanvasSizenow floors the size, because re-assigning an unchanged fractional size still clears the preserved buffer. This also removes a C#/TS property-name mismatch (fboId/samplesvsfbo/sample).SkiaPresentSession.ClipToDamagesnaps the damage outwards to whole pixels and clips without AA. A rect becomes a scissor, and several rects become a region. The fractional AA clip blended cleared and redrawn edge pixels with the retained ones on every host that keeps frames.Given_SkiaPresentSession. It fails on the previous AA clip and passes with the fix.Measured on SamplesApp
Progress/ProgressRing, 2560x1600, Chrome:Retaining frames through an offscreen FBO and
blitFramebufferwas measured too, and it was slower (18.6 fps on SwiftShader): the full-canvas copy outweighs the damage savings.Validation: runtime tests on Skia Desktop (
Given_SkiaPresentSession, plus the fail-before check), the WASM SamplesApp checked manually for resizes at 1.25 DPR with odd sizes, hover/press damage and an animating ProgressRing, and no stale or ghosted pixels.On physical hardware (Pixel Tablet, Tensor G2 / Mali-G710, 2560x1224 canvas, Chrome 157, profiled-AOT build,
RealWorld_SpotlightMenu), two runs with the order reversed:A bare full-screen WebGL2 canvas runs at 60 fps on the tablet with MSAA, without it, with
preserveDrawingBuffer, and with FBO + blit alike (3 interleaved rounds), so the preserved buffer costs nothing there. On a Galaxy Z Fold7 every full-screen WebGL canvas, whatever its configuration, was capped at ~20 fps while driven over remote debugging, so that device could not separate the variants. It showed no regression either.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01TXMNu2pLwNk6UenehZFfNA