gpui: Group sprites by atlas texture and colocate sort keys (#65814)

On Scene::finish we used to sort by tile_id, yet the grouping batch
iterator grouped by tile texture id, causing batches to split more than
necessary.

This also moves the atlas tile immediately after draw order and padding,
bringing the texture-index sort key to offset 8 without changing record
sizes.

Release Notes:

- [GPUI] Improved sprite batching by grouping sprites by atlas texture
and placing sprite sort keys closer together in memory.
This commit is contained in:
Lukas Wirth authored and GitHub committed 2026-10-19 09:28:50 +00:00
1 parent 56934ec056
commit b4ecc45422
5 files changed
+13 -13

No files matched your search

+6 -6
View File
@@ -154,11 +154,11 @@ impl Scene {
self.paths.sort_by_key(|path| path.order);
self.underlines.sort_by_key(|underline| underline.order);
self.monochrome_sprites
.sort_by_key(|sprite| (sprite.order, sprite.tile.tile_id));
.sort_by_key(|sprite| (sprite.order, sprite.tile.texture_id.index));
self.subpixel_sprites
.sort_by_key(|sprite| (sprite.order, sprite.tile.tile_id));
.sort_by_key(|sprite| (sprite.order, sprite.tile.texture_id.index));
self.polychrome_sprites
.sort_by_key(|sprite| (sprite.order, sprite.tile.tile_id));
.sort_by_key(|sprite| (sprite.order, sprite.tile.texture_id.index));
self.surfaces.sort_by_key(|surface| surface.order);
}
@@ -711,10 +711,10 @@ impl Default for TransformationMatrix {
pub struct MonochromeSprite {
pub order: DrawOrder,
pub pad: u32,
pub tile: AtlasTile,
pub bounds: Bounds<ScaledPixels>,
pub content_mask: ContentMask<ScaledPixels>,
pub color: Hsla,
pub tile: AtlasTile,
pub transformation: TransformationMatrix,
}
@@ -730,10 +730,10 @@ impl From<MonochromeSprite> for Primitive {
pub struct SubpixelSprite {
pub order: DrawOrder,
pub pad: u32, // align to 8 bytes
pub tile: AtlasTile,
pub bounds: Bounds<ScaledPixels>,
pub content_mask: ContentMask<ScaledPixels>,
pub color: Hsla,
pub tile: AtlasTile,
pub transformation: TransformationMatrix,
}
@@ -749,12 +749,12 @@ impl From<SubpixelSprite> for Primitive {
pub struct PolychromeSprite {
pub order: DrawOrder,
pub pad: u32,
pub tile: AtlasTile,
pub grayscale: PaddedBool32,
pub opacity: f32,
pub bounds: Bounds<ScaledPixels>,
pub content_mask: ContentMask<ScaledPixels>,
pub corner_radii: Corners<ScaledPixels>,
pub tile: AtlasTile,
}
impl From<PolychromeSprite> for Primitive {
+2 -2
View File
@@ -1215,10 +1215,10 @@ fn fs_underline(input: UnderlineVarying) -> @location(0) vec4<f32> {
struct MonochromeSprite {
order: u32,
pad: u32,
tile: AtlasTile,
bounds: Bounds,
content_mask: Bounds,
color: Hsla,
tile: AtlasTile,
transformation: TransformationMatrix,
}
@@ -1262,12 +1262,12 @@ fn fs_mono_sprite(input: MonoSpriteVarying) -> @location(0) vec4<f32> {
struct PolychromeSprite {
order: u32,
pad: u32,
tile: AtlasTile,
grayscale: u32,
opacity: f32,
bounds: Bounds,
content_mask: Bounds,
corner_radii: Corners,
tile: AtlasTile,
}
+1 -1
View File
@@ -3,10 +3,10 @@
struct SubpixelSprite {
order: u32,
pad: u32,
tile: AtlasTile,
bounds: Bounds,
content_mask: Bounds,
color: Hsla,
tile: AtlasTile,
transformation: TransformationMatrix,
}
@group(1) @binding(0) var<storage, read> b_subpixel_sprites: array<SubpixelSprite>;
+2 -2
View File
@@ -239,10 +239,10 @@ fn load_mono_sprite(instance_id: u32) -> MonochromeSprite {
return MonochromeSprite(
read_word(&cursor),
read_word(&cursor),
read_atlas_tile(&cursor),
read_bounds(&cursor),
read_bounds(&cursor),
read_hsla(&cursor),
read_atlas_tile(&cursor),
read_transformation(&cursor),
);
}
@@ -252,11 +252,11 @@ fn load_poly_sprite(instance_id: u32) -> PolychromeSprite {
return PolychromeSprite(
read_word(&cursor),
read_word(&cursor),
read_atlas_tile(&cursor),
read_word(&cursor),
read_f32(&cursor),
read_bounds(&cursor),
read_bounds(&cursor),
read_corners(&cursor),
read_atlas_tile(&cursor),
);
}
+2 -2
View File
@@ -1140,10 +1140,10 @@ float4 underline_fragment(UnderlineFragmentInput input): SV_Target {
struct MonochromeSprite {
uint order;
uint pad;
AtlasTile tile;
Bounds bounds;
Bounds content_mask;
Hsla color;
AtlasTile tile;
TransformationMatrix transformation;
};
@@ -1213,12 +1213,12 @@ SubpixelSpriteFragmentOutput subpixel_sprite_fragment(MonochromeSpriteFragmentIn
struct PolychromeSprite {
uint order;
uint pad;
AtlasTile tile;
uint grayscale;
float opacity;
Bounds bounds;
Bounds content_mask;
Corners corner_radii;
AtlasTile tile;
};
struct PolychromeSpriteVertexOutput {