Skip to content

Improve sheet packing. - #21363

Merged
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:sheet-packing
Mar 11, 2024
Merged

Improve sheet packing.#21363
PunkPun merged 1 commit into
OpenRA:bleedfrom
RoosterDragon:sheet-packing

Conversation

@RoosterDragon

Copy link
Copy Markdown
Member

When sheet builders are adding sprites to a sheet, they work left to right along each row. They reserve height for the highest sprite seen along that row, resetting the height reservation when the row runs out of space and it moves down to the next row.

As the SpriteCache adds the sprites in a giant batch, it can optimise this operation by ordering the sprites by their height. This reduces wastage where shorter sprites don't use the the full height reserved within the row. The reduced wastage can help the sheet builder allocate fewer sheets, improving load times and improving GPU memory usage as less texture memory is required.


By inserting this code after the SpriteCache.LoadReservations call in SequenceSet.LoadSprites method, you can view the results of this change.

var count = 0;
foreach (var s in SpriteCache.SheetBuilders[SheetType.BGRA].AllSheets)
	s.AsPng().Save($"{count++}.png");

For the Tiberian Dawn HD mod, which uses 8192x8192 sprite sheets, the change reduces the sheet count for the sequence set from 5 to 4.

When sheet builders are adding sprites to a sheet, they work left to right along each row. They reserve height for the highest sprite seen along that row, resetting the height reservation when the row runs out of space and it moves down to the next row.

As the SpriteCache adds the sprites in a giant batch, it can optimise this operation by ordering the sprites by their height. This reduces wastage where shorter sprites don't use the the full height reserved within the row. The reduced wastage can help the sheet builder allocate fewer sheets, improving load times and improving GPU memory usage as less texture memory is required.
Comment thread OpenRA.Game/Graphics/SpriteCache.cs

@PunkPun PunkPun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also reduces TS sheets from 8 -> 6

to test I used

./utility.sh ts --extract isotem.pal
./utility.sh ts --dump-sequence-sheets isotem.pal TEMPERATE

@PunkPun
PunkPun merged commit a3d0a50 into OpenRA:bleed Mar 11, 2024
@PunkPun

PunkPun commented Mar 11, 2024

Copy link
Copy Markdown
Member

changelog

@RoosterDragon
RoosterDragon deleted the sheet-packing branch March 11, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants