Skip to content

vello_hybrid: Deallocate filter regions at the end of each frame instead of the start of next#1734

Open
LaurenzV wants to merge 1 commit into
mainfrom
laurenz/fix-probe-2
Open

vello_hybrid: Deallocate filter regions at the end of each frame instead of the start of next#1734
LaurenzV wants to merge 1 commit into
mainfrom
laurenz/fix-probe-2

Conversation

@LaurenzV

@LaurenzV LaurenzV commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Currently, the probe method piggybacks an existing WebGlRenderer and does some mem::swaps in an effort to not dirty the existing renderer state. Unfortunately, it turns out that this is not enough. Currently, filter handling is written in such a way that at the beginning of the render operation (i.e. when calling render_scene), we check the filter context and clear/deallocate image regions from the last frame. Obviously, this doesn't work well with probing: If we rendered a filter in the previous frame and are about to render the probe image next, it thinks it still needs to deallocate an image from the last frame, and if the image IDs happen to be the same it will instead deallocate the image that is needed by the probe itself. The fact that filter regions are currently deallocated this way is more than dubious, but I won't bother fixing this now since it will go away with the Vello Hybrid rewrite.

However, I also don't want to fix this issue with a bandaid fix by just trying to mem::swap the filter context and any other associated state that we missed, since this is still fragile. Therefore, we instead simply make probe create its own WebGlRenderContext and therefore leave any other existing contexts untouched. I initially didn't do this because I wanted to avoid having to allocate those additional buffers, but I now think that this is the best and cleanest way.

As a nice side effect, this also seems to fix the CI flakiness, so we can run the probe in CI again.

I verified on a number of low-tier devices that this does not seem to regress the probe time itself.

This PR was done with assistance of GPT5.6-Sol.

@LaurenzV
LaurenzV marked this pull request as draft July 9, 2026 14:55
Comment on lines +88 to +92
let canvas = web_sys::window()
.and_then(|window| window.document())
.and_then(|document| document.create_element("canvas").ok())
.and_then(|element| element.dyn_into::<HtmlCanvasElement>().ok())
.ok_or(WebGlProbeError::CanvasCreationError)?;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taj-p Is this fine to do? Can we assume that this will always yield a canvas from our side?

@laurenz-canva
laurenz-canva force-pushed the laurenz/fix-probe-2 branch from 2506488 to 600b43f Compare July 9, 2026 15:08
@LaurenzV
LaurenzV marked this pull request as ready for review July 9, 2026 15:14
@LaurenzV
LaurenzV requested a review from grebmeg July 9, 2026 15:14
Comment on lines 96 to 102
let renderer = Self::new_with(
&canvas,
RenderSettings {
atlas_config: PROBE_ATLAS_CONFIG,
..RenderSettings::default()
},
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the biggest concern in this PR, since webgl contexts are a limited resource. You mentioned this will go away with the rewrite, but still would it be worth just adding a temporary bandaid fix?

I can think of a few possible approaches:

  • the one you mentioned: add another swap for filter_textures (it might be the other resources wouldn’t need swapping);
  • move filter image cache deallocation to the end of render_scene;
  • make deallocation unable to free Ids from the wrong cache by associating each cache with a generation or identity.

My concern is that if a user opens a page with multiple vello_hybrid instances running, we could see more webgl context losses, especially since other parts of the page may also consume additional contexts. What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, we can do 1) or 2). Not so sure about 3) for now. If we can convince ourselves that 1) is enough, this is probably the easiest. But I would need to take some time to look into whether this is actually enough again.

@LaurenzV LaurenzV changed the title vello_hybrid: Make probe construct its custom renderer vello_hybrid: Deallocate filter regions at the end of each frame instead of the start of next Jul 17, 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.

2 participants