-
-
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
Improved Text2d glyph batching #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 |
Objective
Port the changes from #14848 to
Text2d
for improved glyph batching.Solution
Store the glyph geometry in a seperate contiguous array, queue one
Transparent2d
item per text span, add indices into the glyph array to theExtractedSprite
s forText2d
entities.This still needs a bit more work, maybe
ExtractedSprite
should be an enum and I think the namings of some of the fields could be better.many_text2d
doesn't show much improvement because it draws lots of four glyph text sections which means the number of extracted sprites is only reduced by three quarters. Whereasmany_glyphs
draws a single text span with 100,000 glyphs which results in a reduction from 100,000 sprites to just 1.Testing
Ran some naive benchmarks:
```cargo run --example text_pipeline --release``
main: ~100fps
this: ~250fps
```cargo run --example many_text2d --release``
main: ~600fps
this: ~620fps
(modified many_glyphs example to only use Text2d)
```cargo run --example many_glyphs --release``
main: ~45fps
this: ~445fps