hajimehoshi / ebiten

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

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

Closed hajimehoshi closed 2 months ago

hajimehoshi commented 5 months 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 5 months 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 months ago

Tricky things are:

hajimehoshi commented 2 months ago

3100 would solve this issue.