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

Create collision shapes from the meshing thread #124

Open
Zylann opened this issue Feb 15, 2020 · 2 comments
Open

Create collision shapes from the meshing thread #124

Zylann opened this issue Feb 15, 2020 · 2 comments
Labels
enhancement Waiting for Godot Godot needs an improvement

Comments

@Zylann
Copy link
Owner

Zylann commented Feb 15, 2020

As seen in #54 (comment), creating collision shapes is slow, about 10 times slower than creating Mesh objects.
image

However, they are currently created on the main thread, and queued if the time spent doing it exceeds 8 ms, which slows down updates a lot, and the game with it.
That means collision shapes are first responsible for collidable terrain update snappiness.

Originally, this happened on the main thread because Mesh objects could not be safely created from a thread without performance degradation, due to how Godot's renderer was implemented (OpenGL), and that Mesh used to be required before creating a collision shape.

However, since the current code for creating them no longer uses Mesh, it could be easily moved to the thread instead of being done on the main thread. Unfortunately, contrary to other servers, Godot doesn't implement any thread-safety on PhysicServer. Which prevents us from doing that. I just spent an hour modifying Voxel Tools code to do this, only to find it would be unsafe :(

This issue must be addressed as soon as Godot implements this.
For now, I pushed my WIP in the physics_multithread branch.

Made a proposal: godotengine/godot-proposals#483

@snouk-z
Copy link

snouk-z commented Mar 7, 2021

Hi,
I came across the same problem on my custom terrain generator.

I actually had the same idea of withdrawing my PhysicsServer calls from my meshing thread to enqueue them in the main thread. In order to avoid big framerate drops I tried to make an aynschronous (not threaded) worker to dequeue and generate the collisions, it doesn't work well, I still get crashes (asynchronism doesn't seem to be an option either).

I'm looking at the plugin sources right now to figure out which way you choose to handle the collision rendering in your main thead. But if you can share some hints on this, it would save me some time :p Thanks

@Zylann
Copy link
Owner Author

Zylann commented Mar 7, 2021

I did two things:

  • I build collision shapes on the main thread. If it takes more than 8 ms, I stop and continue dequeuing them next frame.
  • As an option, when the player is editing the terrain, I delay collision updates based on a configurable time so collision shapes won't have to update every frame.

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

No branches or pull requests

2 participants