-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExtractedSprites
slice buffer
#17041
base: main
Are you sure you want to change the base?
Conversation
I don't think I'm really qualified to review the rendering changes. But some notes:
I don't think this is true for the texture. Different glyphs of the same edit: Okay, I see that's probably not an issue in the code here. |
Yep in the rareish case the font is split across multiple textures, with if text_layout_info
.glyphs
.get(i + 1)
.map(|info| {
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
})
.unwrap_or(true)
{
extracted_sprites.sprites.insert(
(
commands.spawn(TemporaryRenderEntity).id(),
original_entity.into(),
),
ExtractedSprite {
transform,
color,
rect: None,
custom_size: None,
image_handle_id: atlas_info.texture.id(),
flip_x: false,
flip_y: false,
anchor: Anchor::Center.as_vec(),
original_entity: Some(original_entity),
group_indices: start..end,
},
);
start = end;
} |
This wouldn't be uncommon at all with something like CJK text, especially at larger (but still very reasonable) font sizes. But probably not worth doing something fancier here over. I'd rather add atlas-growing to mitigate that. |
I don't like how |
I think, unlike the spritesource fix, this should be backportable to 0.15 without any external api changes. |
This seems to have a measurable impact on sprite performance. edit: this seems consistent on my m1 mac, but not quite as dramatic my earlier numbers indicated.
|
@akimakinai @SludgePhD @kristoff3r, could y'all review this one too? <3 |
I didn't notice any significant difference on my computer but the new field holding the indices does add a couple of extra bytes to the size of an |
… and use a `MainEntityHashMap` for storage in `ExtractedSprites`
* `ExtractedGroupSprite` -> `ExtractedSlice`. * `ExtractedSprite::group_indices` -> `ExtractedSprite::slice_indices` * `ExtractedSprites::grouped_sprites` -> ExtractedSprites::slices` * `ComputedTextureSlices::extract_sprites` -> `ComputedTextureSlices::extract_slices`
ExtractedSprites
slice buffer
3693cbe
to
c670e19
Compare
Objective
Instead of extracting an individual sprite per glyph of a text spawn or slice of a nine-patched sprite, add a buffer to
ExtractedSprites
to store the extracted slice geometry.Solution
ExtractedSprites
in aMainEntityHashMap
, copying the optimisation from the reverted Fix sprite performance regression since retained render world #17078.ExtractedSlice
to hold sprite slice size, position and atlas info.slices: Vec<ExtractedSlice>
field toExtractedSprites
.slice_indices
field toExtractedSprite
.ExtractedSprite
for sets of glyphs or slices and push the geometry for each individual slice or glyph into theslices
buffer. The range of extracted sprite slices corresponding to theExtractedSprite
is stored in itsslice_indices
field.ComputedTextureSlices
to return anExtractedSlice
iterator instead ofExtractedSprites
.extract_text2d_sprite
to only queue a newExtractedSprite
s on font changes and otherwise push slices.*Testing
yellow = this pr, red = main
cargo run --example many_glyphs --release --features "trace_tracy" -- --no-ui
cargo run --example many_text2d --release --features "trace_tracy"
Migration Guide
ExtractedSprites
now uses aMainEntityHashMap
for storage.ExtractedSprites
has a new fieldslices
for storing extracted glyph and sprite geometry.ExtractedSprite
now has arender_entity
field containing its corresponding render world entity and a fieldslice_indices
that indexes intoExtractedSprites::slices
.ComputedTextureSlices::extract_sprites
has been renamed toextract_slices
and itstransform
andoriginal_entity
parameters have been removed.