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

With SDL backend on Windows, adding an element to a SpriteBatch can cause a large lag spike #671

Open
csclyde opened this issue Apr 1, 2024 · 1 comment

Comments

@csclyde
Copy link

csclyde commented Apr 1, 2024

I've been profiling my game recently, and found that when adding elements to a SpriteBatch (for a custom particle engine), it frequently creates a lag spike. I can confirm that it happens on the frame in which a particle is added, but I can't tell why certain adds trigger this behavior, and some do not. You can see a profile here, where frames are regularly dropped, corresponding to when a particle (BatchElement) is added to the SpriteBatch:

image

Zooming into the offending frame, you can see that the SpriteBatch flush is creating a massive delay:

image

Once it gets into allocBuffer, I have no clue what's happening. But I don't feel that I'm using the SpriteBatch improperly. I'm just creating a pool of BatchElement subclasses. Then periodically adding them to the SpriteBatch. Then, after a time, removing them from the sprite batch and returning them to the pool.

@ncannasse
Copy link
Member

You can try to setup a GPU buffer cache with hxd.impl.Allocator.set(new hxd.impl.CacheAllocator())
This will permit the reuse of GPU buffers for dynamic draws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants