Bug fix: make sure `end_pass` is called for all loaders (#7072)

None of the built-in loaders does any cache eviction (yet), but 3rd
party ones might have
This commit is contained in:
Emil Ernerfeldt 2025-05-21 19:52:59 +02:00 committed by GitHub
parent f57cb27386
commit b05a40745f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View File

@ -2316,6 +2316,8 @@ impl ContextImpl {
let viewport = self.viewports.entry(ended_viewport_id).or_default();
let pixels_per_point = viewport.input.pixels_per_point;
self.loaders.end_pass(viewport.repaint.cumulative_pass_nr);
viewport.repaint.cumulative_pass_nr += 1;
self.memory.end_pass(&viewport.this_pass.used_ids);

View File

@ -322,8 +322,8 @@ pub trait BytesLoader {
/// Implementations may use this to perform work at the end of a frame,
/// such as evicting unused entries from a cache.
fn end_pass(&self, frame_index: usize) {
let _ = frame_index;
fn end_pass(&self, pass_index: u64) {
let _ = pass_index;
}
/// If the loader caches any data, this should return the size of that cache.
@ -394,8 +394,8 @@ pub trait ImageLoader {
/// Implementations may use this to perform work at the end of a pass,
/// such as evicting unused entries from a cache.
fn end_pass(&self, frame_index: usize) {
let _ = frame_index;
fn end_pass(&self, pass_index: u64) {
let _ = pass_index;
}
/// If the loader caches any data, this should return the size of that cache.
@ -539,8 +539,8 @@ pub trait TextureLoader {
/// Implementations may use this to perform work at the end of a pass,
/// such as evicting unused entries from a cache.
fn end_pass(&self, frame_index: usize) {
let _ = frame_index;
fn end_pass(&self, pass_index: u64) {
let _ = pass_index;
}
/// If the loader caches any data, this should return the size of that cache.
@ -572,3 +572,26 @@ impl Default for Loaders {
}
}
}
impl Loaders {
/// The given pass has just ended.
pub fn end_pass(&self, pass_index: u64) {
let Self {
include,
bytes,
image,
texture,
} = self;
include.end_pass(pass_index);
for loader in bytes.lock().iter() {
loader.end_pass(pass_index);
}
for loader in image.lock().iter() {
loader.end_pass(pass_index);
}
for loader in texture.lock().iter() {
loader.end_pass(pass_index);
}
}
}

View File

@ -64,8 +64,6 @@ impl TextureLoader for DefaultTextureLoader {
self.cache.lock().clear();
}
fn end_pass(&self, _: usize) {}
fn byte_size(&self) -> usize {
self.cache
.lock()