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

Speed up converter texture packing with Cython #1371

Open
3 tasks
heinezen opened this issue Jan 22, 2021 · 4 comments · May be fixed by #1671
Open
3 tasks

Speed up converter texture packing with Cython #1371

heinezen opened this issue Jan 22, 2021 · 4 comments · May be fixed by #1671
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers improvement Enhancement of an existing component lang: cython Implemented using Cython code

Comments

@heinezen
Copy link
Member

heinezen commented Jan 22, 2021

Required skills: Cython

Difficulty: Medium

Animation frames from AoE2 graphics files are packed into a texture atlas by the openage converter. We use bin packing to find the optimal arrangement (= smallest atlas dimensions) of the frames in the atlas. Bin packing becomes computationally intensive if a lot of frames are packed (looking at you Definitive Edition), so we want to optimize the algorithm as much as possible.

The goal of this issue is to speed up the bin packing implemented here using Cython. The most important methods to cythonize are pack() and factor(), since they are responsible for the packing logic. Ideally, these functions should contain as little Python overhead as possible.

Additional optimization might be possible such as:

  • Currently pack() gets passed a list of frame objects, but technically only width, height and index of a frame are needed.
  • Most of the games have a fixed number of frames per animation (e.g. 50 frames for a unit animation in AoC). These could be hardcoded as lookups into factor()
  • texture_merge.pyx, the function initiating the binpacking, could also use optimization for merging the individual frames into the atlas using the packer settings.

You can test your changes with the singlefile media converter.

Further Reading

@heinezen heinezen added improvement Enhancement of an existing component lang: python Done in Python code area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers labels Jan 22, 2021
@heinezen heinezen added the hacktoberfest For newcomers from Hacktoberfest event label Sep 30, 2021
@heinezen heinezen removed the hacktoberfest For newcomers from Hacktoberfest event label Nov 9, 2021
@heinezen heinezen added lang: cython Implemented using Cython code and removed lang: python Done in Python code labels Sep 8, 2023
@fabiobarkoski
Copy link
Contributor

Looking in the binpack.pyx history, seems that the converter already received some speed up improvement

@heinezen
Copy link
Member Author

@fabiobarkoski It has been converted to Cython but none of the points in the ssue have been solved completely afaik.

@fabiobarkoski
Copy link
Contributor

Can I try to work on it? But I'll need some guidance :)

@heinezen
Copy link
Member Author

heinezen commented Jul 12, 2024

You absolutely can :) Although it might be a bit harder than medium difficulty if you don't work with Cython much. Just saying :D

@heinezen heinezen linked a pull request Sep 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: assets Involved with assets (images, sounds, ...) good first issue Suitable for newcomers improvement Enhancement of an existing component lang: cython Implemented using Cython code
Projects
Status: converter
Status: 🔖 TODO
Development

Successfully merging a pull request may close this issue.

2 participants