Free textures after submitting queue instead of before with wgpu renderer on Web (#7291)

This commit is contained in:
Andreas Reich 2025-07-02 16:14:46 +02:00 committed by GitHub
parent dc79998044
commit 1878874f7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -279,13 +279,6 @@ impl WebPainter for WebPainterWgpu {
Some((output_frame, capture_buffer))
};
{
let mut renderer = render_state.renderer.write();
for id in &textures_delta.free {
renderer.free_texture(id);
}
}
// Submit the commands: both the main buffer and user-defined ones.
render_state
.queue
@ -307,6 +300,16 @@ impl WebPainter for WebPainterWgpu {
frame.present();
}
// Free textures marked for destruction **after** queue submit since they might still be used in the current frame.
// Calling `wgpu::Texture::destroy` on a texture that is still in use would invalidate the command buffer(s) it is used in.
// However, once we called `wgpu::Queue::submit`, it is up for wgpu to determine how long the underlying gpu resource has to live.
{
let mut renderer = render_state.renderer.write();
for id in &textures_delta.free {
renderer.free_texture(id);
}
}
Ok(())
}