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

examples/sprites: Performance improvement on Metal #762

Closed
hajimehoshi opened this issue Dec 22, 2018 · 7 comments
Closed

examples/sprites: Performance improvement on Metal #762

hajimehoshi opened this issue Dec 22, 2018 · 7 comments
Labels
Milestone

Comments

@hajimehoshi
Copy link
Owner

FPS should keep 60 FPS even when the number of sprites exceeds 10000.

@hajimehoshi hajimehoshi added this to the v1.9.0 milestone Dec 22, 2018
@hajimehoshi
Copy link
Owner Author

FPS reaches 60 with 10000 sprites, but does not with 20000 sprites.

BTW, it is hard to compare FPS with OpenGL era, since vsync didn't work at that time 🤔

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Feb 1, 2019

Screenshot from Gyazo

As I expected, Device's MakeBuffer is very slow when 9000> sprites are shown.

@hajimehoshi
Copy link
Owner Author

https://developer.apple.com/documentation/metal/advanced_command_setup/cpu_and_gpu_synchronization?language=objc

This sample renders hundreds of small quads, also known as sprites. To animate the sprites, the sample updates their positions at the start of each frame and writes them into a vertex buffer. When a frame is complete, the CPU and GPU no longer need the vertex buffer for that frame. Discarding a used vertex buffer and creating a new one for each frame is wasteful. Instead, a more sustainable model can be implemented with a FIFO queue of reusable vertex buffers.

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Feb 1, 2019

From my very simple experiment, the cost difference between copying bytes to a buffer and creating a new buffer was not so big.

@hajimehoshi
Copy link
Owner Author

Now we can keep 60 FPS with <20000 sprites. Can we keep it with more sprites by reusing buffers?

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Feb 14, 2019

Reduce 'if' from the shader programs 81101e0

Remove 'while' from the shader programs 7a76a5b

Thanks to them, now we can keep 60FPS with 40000 sprites on my MacBook Pro 2018 😄

@hajimehoshi
Copy link
Owner Author

Now I think Metal version is fast enough.

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

No branches or pull requests

1 participant