Godot Physics collisions and solver processed on threads #48221
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
ThreadWorkPool
to process physics step tasks in multiple threads.Collisions are all processed in parallel and solving impulses is processed in parallel for rigid body islands.
Additional changes:
Test configuration
CPU: AMD Ryzen 9 4900HS with Radeon Graphics, 3000 Mhz, 8 Core(s), 16 Logical Processor(s)
RAM: 16.0 GB
Display: GeForce RTX 2060 with Max-Q Design/PCIe/SSE2
Test scenes
2D - Simple contacts (1 island - 500 rigid bodies)
https://github.com/godotengine/godot-demo-projects/tree/master/2d/physics_tests/tests/performance/test_perf_contacts.tscn
~15% improvement (physics ticks)
2D - Advanced contacts (multiple islands - 9 x 300 rigid bodies)
https://github.com/godotengine/godot-demo-projects/tree/master/2d/physics_tests/tests/performance/test_perf_contact_islands.tscn
~25% improvement (physics ticks)
3D - Simple contacts (1 island - 500 rigid bodies)
https://github.com/godotengine/godot-demo-projects/tree/master/3d/physics_tests/tests/performance/test_perf_contacts.tscn
~30% improvement (physics ticks)
3D - Advanced contacts (multiple islands - 16 x 200 rigid bodies)
https://github.com/godotengine/godot-demo-projects/tree/master/3d/physics_tests/tests/performance/test_perf_contact_islands.tscn
~65% improvement (physics ticks)
These results are measured with a 3.x port of this PR.
The lower results in 2D can be explained by a bottleneck in the broadphase, which takes more than half of the physics tick time. It would be worth checking if replacing the Hash Grid with a 2D dynamic BVH would help with that.
Edit: This is done on the 3.x branch with #48314.