Skip to content
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

Improve sheet packing. #21363

Merged
merged 1 commit into from Mar 11, 2024
Merged

Improve sheet packing. #21363

merged 1 commit into from Mar 11, 2024

Conversation

RoosterDragon
Copy link
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.
Copy link
Member

@PunkPun PunkPun left a comment

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
3 checks passed
@PunkPun
Copy link
Member

PunkPun commented Mar 11, 2024

changelog

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.

None yet

2 participants