Repository navigation
fix(preview): WebGL2 double-flip on preferFallback bitmap upload - 8000 #45
Merged
Merged
Conversation
Root cause of the upside-down flicker that appeared at every pill and cam transition in the editor preview: the WebGL2 backend was applying two Y-flips that should have cancelled to zero but didn't. Chain at every pill transition: 1. Pool seeks the <video> to the new source-time range 2. el.seeking → true; buildSourcesMap sets preferFallback=true with the cached lastGoodFrame (an ImageBitmap) 3. WebGL2 uploadSource uploads the ImageBitmap via texImage2D 4. UNPACK_FLIP_Y_WEBGL=true is set globally — ImageBitmaps respect it and arrive already-flipped in the texture 5. drawFrame still set u_srcFlipY=1 because src.kind === "video" 6. Vertex shader flips UV.y a second time → double flip → upside-down output for that one tick 7. Seek completes, live <video> upload takes over (which DOES ignore UNPACK_FLIP_Y on Chrome's hardware path), srcFlipY=1 becomes correct again → upright Fix: u_srcFlipY now reflects the actual uploaded pixel source. When `kind === "video" && preferFallback && fallback`, the upload is an ImageBitmap that honoured UNPACK_FLIP_Y → srcFlipY=0. Otherwise (live <video> or VideoFrame) → srcFlipY=1. Also bundled here: - preview-runtime.maybeRefreshSnapshots now iterates hot-covering targets instead of just the active descriptor layer. A cam about to be cut to via a cut now has a fresh fallback ready for its first seek-in-progress window, instead of falling through to a black flash. - defaultCreateBitmapFromVideo passes imageOrientation: "from-image" for deterministic Y-orientation across browser/driver combos. - New regression test in webgl2-backend-video-flip.browser.test.ts that renders the same video frame via live-<video> and via preferFallback paths, then asserts orientation parity. Verified directly against the running dev server with gl.readPixels: a red-top / blue-bottom test bitmap rendered through the preferFallback path samples (255,0,0) at top and (0,0,255) at bottom — pre-fix it was inverted. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
u_srcFlipYshader uniform was set based onsrc.kind === "video", but during the seek-fallback window the actual upload is the cached ImageBitmap (which honoursUNPACK_FLIP_Y_WEBGL=true). Result: double flip → one inverted frame at every transition.u_srcFlipYnow reflects the actually uploaded pixel source. ImageBitmap fallback → 0; live<video>/VideoFrame→ 1.maybeRefreshSnapshotsiterates all hot-covering cams (not just the active layer) so a cam about to be cut to has a fresh fallback ready.defaultCreateBitmapFromVideousesimageOrientation: "from-image"for deterministic Y-orientation across browsers.Verification
<video>and via the preferFallback path; asserts orientation parity. Pre-fix this test reproduces the bug deterministically.gl.readPixels: red-top / blue-bottom test bitmap through preferFallback path samples (255,0,0) at top and (0,0,255) at bottom. Pre-fix it was inverted.Test plan
🤖 Generated with Claude Code