hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.39k stars 633 forks source link

internal/atlas: GPU memory optimization by deallocating automatically #3023

Open hajimehoshi opened 2 weeks ago

hajimehoshi commented 2 weeks ago

Operating System

What feature would you like to be added?

In order to reduce GPU memory, deallocate GPU memory for an image that is unused as a source for a while. We can put the memory back to GPU memory whenever necessary. This optimization works only for a source image that has all the pixel information. (e.g. an image just after NewImageFromImage), and not for an image for offscreen.

From our experience (Odencat), if an image is not used as a source for one second, the image's GPU memory can be freed.

Why is this needed?

In order to reduce crashes due to short of GPU memory. We have confirmed this happens on mobiles, and also could happen on Windows.

hajimehoshi commented 2 weeks ago

By this optimization, write-pixels will be increased. In the worst case, each new write-pixels will be interleaved into draw-triangles. This would degrade performance. In order to avoid this, we would have to reorder draw calls by accumulating write-pixels first.

EDIT: This optimization has been already implemented!

hajimehoshi commented 5 days ago

Tricky things are: