Skip to content

fix(ShaderView): resize drawing buffer on layout change (rotation) - #21

Merged
blazejkustra merged 1 commit into
mainfrom
fix/shaderview-resize
Jun 28, 2026
Merged

fix(ShaderView): resize drawing buffer on layout change (rotation)#21
blazejkustra merged 1 commit into
mainfrom
fix/shaderview-resize

Conversation

@blazejkustra

Copy link
Copy Markdown
Owner

What

Medium-severity fix from the worklets/WebGPU audit: no resize / rotation handling.

The drawing buffer was sized and context.configure called exactly once at setup. After a rotation or any layout change, the buffer kept its original dimensions → the shader rendered stretched / wrong-aspect.

Change

  • useWGPUSetup now exposes onCanvasLayout, wired to <Canvas onLayout> in ShaderView (composed with any consumer-provided onLayout).
  • On layout change it recomputes the physical-pixel size (layoutSize * PixelRatio.get()), updates canvas.width/height, and reconfigures the surface — but only when the size actually changed (redundant same-size passes are skipped).
  • The render loop already reads canvas.width/height every frame, so the resolution uniform picks up the new size on the next frame.
  • Sizes are rounded to integers for consistent pixel dimensions (initial setup rounded too, so the mount layout pass is a no-op).

Stack

This is PR 1 of 3 for the medium audit items, based on fix/rn-webgpu-worklets-high-bugs (PR #20):

  1. this — resize/rotation
  2. render-loop error/context-loss handling
  3. GPU resource cleanup

Verification

  • yarn typecheck
  • yarn lint (changed files) ✅
  • Runtime: rotation verification on device recommended (reviewer note).

Note on cross-thread reconfigure

configure() runs on the JS thread while the render loop runs on the worklet runtime. Reconfigure is infrequent (rotation only) and mirrors the existing initial-configure-on-main pattern; a brief race window is possible but low-risk and is made safe once the error-handling PR (next in the stack) lands.

The drawing buffer was sized and the context configured exactly once at
setup, so after a rotation/layout change the buffer kept its original
dimensions and the shader rendered stretched / wrong-aspect.

useWGPUSetup now exposes onCanvasLayout, wired to <Canvas onLayout>, which
recomputes the physical-pixel size (clientSize * PixelRatio) and reconfigures
the surface when it actually changes. The render loop reads canvas.width/height
each frame, so the resolution uniform picks up the new size on the next frame.
Sizes are rounded to integers for consistent pixel dimensions; redundant
reconfigures (same size) are skipped.
@blazejkustra
blazejkustra changed the base branch from fix/rn-webgpu-worklets-high-bugs to main June 28, 2026 12:38
@blazejkustra
blazejkustra merged commit a70e062 into main Jun 28, 2026
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