1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

egui-wgpu: only copy the part of the frame a backdrop effect reads

`capture_backdrop` copied the whole target into the backdrop texture for every
callback that asked for one, so a panel-sized blur on a large screen paid for
the entire frame, once per blur.

Ask the callback what it needs instead: `CallbackTrait::backdrop_rect` is given
the rect the callback will be drawn into, its own rect already cut down by the
clip rect, and returns the region it needs to read. Those are different
questions — a blur reads its radius beyond every edge it draws — and keeping
them apart is what lets the margin survive clipping, which inflating the
callback's own rect could not do: that rect is also the viewport it draws into.

`Backdrop::valid_in_pixels` reports what was captured. The texture stays
full-size so a pixel is still where the effect expects it; only the region that
was asked for holds this frame.

The default answer is the rect the callback is drawn into, which is right for an
effect that only reads the pixels it covers, so nothing has to change unless it
reads further out.

With nine blurred panels of 240x150 at radius 24 on a 1600x1200 canvas, this
plus scissoring the blur passes in regui takes the frame rate from 146 to 1690
fps on WebGPU and 135 to 616 on WebGL2, measured in Chrome; the marginal cost of
one blur drops about twentyfold. egui_kittest's snapshots of the same blurs come
out pixel for pixel identical.
This commit is contained in:
Lucas Meurer
2026-08-02 16:38:19 +02:00
parent b749228bcf
commit 7685362b87
4 changed files with 122 additions and 13 deletions

View File

@@ -431,6 +431,7 @@ impl WebPainter for WebPainterWgpu {
&render_state.queue,
&mut encoder,
clipped_primitives,
&screen_descriptor,
cursor,
target_texture,
backdrop_texture,