Repository navigation
fix(skia): reset the GL state cache before composing a frame - #24796
Conversation
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24796/wasm-skia-net9/index.html |
|
The build 236072 found UI Test snapshots differences: Details
|
A host that retains through its own framebuffer (Win32 OpenGL) blits with raw GL calls at present, rebinding GL_FRAMEBUFFER behind Skia's back. Skia caches GL state, so from the next frame it believed the host's framebuffer was still bound and drew into the default one instead, while the blit kept copying the retained framebuffer. The window showed whatever that framebuffer last legitimately received: blank from startup, or frozen on the frame a resize happened to produce. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
e68d826 to
c4d5d91
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24796/wasm-skia-net9/index.html |
|
The build 236418 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
GitHub Issue: closes #24795
PR Type:
🐞 Bugfix
What changed? 🚀
On Win32 + OpenGL the window rendered blank and, after a resize, froze on a single frame — while the app stayed completely healthy (pump responsive, CPU spent,
SwapBuffersalways succeeding).The host retains the previous frame by composing into its own framebuffer and blitting it at present. That blit is raw GL, and it rebinds the framebuffer:
Skia's
GrDirectContextcaches GL state and nothing invalidated that cache, so from the next frame Skia believed the host's framebuffer was still bound and drew into the default one instead — while the blit kept copying the retained framebuffer over the top. The window showed whatever that framebuffer last legitimately received: blank from startup, or frozen on the frame a resize happened to produce.PresentForGLnow callsGRContext.ResetContext()before handing out the session.Vulkan and Metal never had this: they present their own image and issue no raw GL around Skia.
Measurement
glReadPixelson the default framebuffer immediately beforeSwapBuffers, sampling a full row across the middle of the frame (flat= max − min ≤ 2). An external capture is not usable here —PrintWindowreturns stale frames for this window, so it reports a frozen window as live.I also tried adding the
GRContext.Flush(submit: true)that Vulkan and Metal perform on present (GL is the only backend whose present session doesn't submit). That alone did not fix it, which is what ruled out command submission and pointed at the state cache.ResetContext()alone is sufficient, so this PR does not add a per-frame submit.PR Checklist ✅
Screenshots Compare Test Runresults.On tests: this is not observable from inside the process — the app renders, reports damage, and swaps successfully the entire time it is showing a blank window; only reading back the presented framebuffer distinguishes the two states. A runtime test would need a GL-backed host plus a framebuffer read-back after present, which no existing harness provides, and
RenderTargetBitmaprenders offscreen and so passes either way. I verified it with theglReadPixelsprobe above rather than claim coverage I don't have.Validation
SamplesAppdesktop head (net11.0-desktop).PresentForGLpath serves X11, Android GLES and WebAssembly/WebGL. Those hosts are equally exposed if they touch GL state around present, but I only tested Win32.🤖 Generated with Claude Code