8000 fix(preview): WebGL2 double-flip on preferFallback bitmap upload by johannboehme · Pull Request #45 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

fix(preview): WebGL2 double-flip on preferFallback bitmap upload - 8000 #45

Merged
johannboehme merged 1 commit into
mainfrom
claude/wonderful-ritchie-fe57d9
May 9, 2026
Merged

johannboehme merged 1 commit into
mainfrom
claude/wonderful-ritchie-fe57d9

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Summary

  • Root cause of the upside-down flicker at every pill / cam transition: WebGL2's u_srcFlipY shader uniform was set based on src.kind === "video", but during the seek-fallback window the actual upload is the cached ImageBitmap (which honours UNPACK_FLIP_Y_WEBGL=true). Result: double flip → one inverted frame at every transition.
  • Fix: u_srcFlipY now reflects the actually uploaded pixel source. ImageBitmap fallback → 0; live <video> / VideoFrame → 1.
  • Bundled hardening: maybeRefreshSnapshots iterates all hot-covering cams (not just the active layer) so a cam about to be cut to has a fresh fallback ready. defaultCreateBitmapFromVideo uses imageOrientation: "from-image" for deterministic Y-orientation across browsers.

Verification

  • New regression test webgl2-backend-video-flip.browser.test.ts renders the same video frame via live-<video> and via the preferFallback path; asserts orientation parity. Pre-fix this test reproduces the bug deterministically.
  • Live in dev server via 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.
  • 238/238 render tests green (excluding flaky stress/bench benches that hit machine-dependent p95 budgets).
  • Manually verified in chromium that pill transitions in the editor preview no longer flicker upside down.

Test plan

  • Pull, hard reload editor preview (Cmd+Shift+R)
  • Cross-cam cuts (different cams via cuts) — no upside-down flicker
  • Same-cam pill-trim transitions (same camId, different source-time range) — no upside-down flicker
  • Loop wrap with cam-switch right after wrap point — no flicker
  • Manual scrubbing across cuts — smooth, no black flash, no upside-down

🤖 Generated with Claude Code

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>
@johannboehme
johannboehme merged commit d2d6a8d into main May 9, 2026
1 check passed
@johannboehme
johannboehme deleted the claude/wonderful-ritchie-fe57d9 branch May 9, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0