Prepare benchmarks + ~1.7x prepare perf improvement (#121)

* Add prepare benchmarks

* Skip unnecessary peaks

* Cite sample sources
This commit is contained in:
Taj Pereira 2024-11-28 22:36:23 +09:00 committed by Héctor Ramón Jiménez
parent db2c1ca316
commit 28512c8630
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 964 additions and 43 deletions

View file

@ -107,16 +107,6 @@ impl InnerAtlas {
self.kind.num_channels()
}
pub(crate) fn promote(&mut self, glyph: CacheKey) {
self.glyph_cache.promote(&glyph);
self.glyphs_in_use.insert(glyph);
}
pub(crate) fn put(&mut self, glyph: CacheKey, details: GlyphDetails) {
self.glyph_cache.put(glyph, details);
self.glyphs_in_use.insert(glyph);
}
pub(crate) fn grow(
&mut self,
device: &wgpu::Device,
@ -327,13 +317,6 @@ impl TextAtlas {
did_grow
}
pub(crate) fn glyph(&self, glyph: &CacheKey) -> Option<&GlyphDetails> {
self.mask_atlas
.glyph_cache
.peek(glyph)
.or_else(|| self.color_atlas.glyph_cache.peek(glyph))
}
pub(crate) fn inner_for_content_mut(&mut self, content_type: ContentType) -> &mut InnerAtlas {
match content_type {
ContentType::Color => &mut self.color_atlas,

View file

@ -72,18 +72,16 @@ impl TextRenderer {
let physical_glyph =
glyph.physical((text_area.left, text_area.top), text_area.scale);
if atlas
.mask_atlas
.glyph_cache
.contains(&physical_glyph.cache_key)
let cache_key = physical_glyph.cache_key;
let details = if let Some(details) =
atlas.mask_atlas.glyph_cache.get(&cache_key)
{
atlas.mask_atlas.promote(physical_glyph.cache_key);
} else if atlas
.color_atlas
.glyph_cache
.contains(&physical_glyph.cache_key)
{
atlas.color_atlas.promote(physical_glyph.cache_key);
atlas.mask_atlas.glyphs_in_use.insert(cache_key);
details
} else if let Some(details) = atlas.color_atlas.glyph_cache.get(&cache_key) {
atlas.color_atlas.glyphs_in_use.insert(cache_key);
details
} else {
let Some(image) =
cache.get_image_uncached(font_system, physical_glyph.cache_key)
@ -167,20 +165,17 @@ impl TextRenderer {
(GpuCacheStatus::SkipRasterization, None, inner)
};
inner.put(
physical_glyph.cache_key,
GlyphDetails {
width: width as u16,
height: height as u16,
gpu_cache,
atlas_id,
top: image.placement.top as i16,
left: image.placement.left as i16,
},
);
}
let details = atlas.glyph(&physical_glyph.cache_key).unwrap();
inner.glyphs_in_use.insert(cache_key);
// Insert the glyph into the cache and return the details reference
inner.glyph_cache.get_or_insert(cache_key, || GlyphDetails {
width: image.placement.width as u16,
height: image.placement.height as u16,
gpu_cache,
atlas_id,
top: image.placement.top as i16,
left: image.placement.left as i16,
})
};
let mut x = physical_glyph.x + details.left as i32;
let mut y = (run.line_y * text_area.scale).round() as i32 + physical_glyph.y