-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Make Servers truly Thread Safe #45852
Make Servers truly Thread Safe #45852
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I haven't tested yet, but I've reviewed the physics code.
I haven't spotted any huge issue, just some details to fix or discuss. Most comments for 3D physics also apply for 2D.
When enabling multithread rendering and running project - https://github.com/qarmin/RegressionTestProject/archive/4.0.zip
|
With default single threaded mode, it crashes in different place(both crashes doesn't occur in master Godot branch):
|
52bdfee
to
5f1ec4b
Compare
@quarmin I think it should be fixed with latest commit, but let me know just in case |
There is still one more thing I have to do, which is to refactor the command queue for all this to actually work properly, but I will do it in the next PR. |
Crash with multithread rendering still exists(this one with physics was fixed). - RegressionTestProject.zip Now additionally prints this lines
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast<PhysicsServer3DSW *>(PhysicsServer3D::get_singleton())
must be replaced by
PhysicsServer3DSW::singleton
@qarmin, cold you try the same (with multi-threaded rendering) with this patch applied? I have the suspicion that some |
@RandomShaper ah man, I forgot to make those thread safe, great thing you spotted it |
5f1ec4b
to
66388b9
Compare
@RandomShaper @qarmin ok, should be fixed now. It will probably still error (needs the rewrite of CommandQueue to truly work as intended), but should not crash. |
I still have same crash It only adds nodes to scene and later remove them |
@qarmin this seems like a bug in the command queue that I don't understand, as it looks server code is being called from different threads (creating a race condition, or that's what it looks like from debugging) when it should not, so it's a bit unrelated to this PR. Currently @hpvb is rewriting the command queue, and I suggest testing this reproduction case against his new work (or opening an issue and we make sure his PR passes it). |
66388b9
to
1bb732e
Compare
@reduz, the last version pushed crashes for me unless I make more Specifically, I believe that every I've changed all the Not sure if that's something that will be addressed by the command queue rewrite. |
Sorry, I approved by mistake. I didn't want to approve yet. I've re-asked myself for review. |
@RandomShaper I already changed the rid owners to thread safe in my latest forced push, not sure which ones you believe are missing. |
-Rendering server now uses a split RID allocate/initialize internally, this allows generating RIDs immediately but initialization to happen later on the proper thread (as rendering APIs generally requiere to call on the right thread). -RenderingServerWrapMT is no more, multithreading is done in RenderingServerDefault. -Some functions like texture or mesh creation, when renderer supports it, can register and return immediately (so no waiting for server API to flush, and saving staging and command buffer memory). -3D physics server changed to be made multithread friendly. -Added PhysicsServer3DWrapMT to use 3D physics server from multiple threads. -Disablet Bullet (too much effort to make multithread friendly, this needs to be fixed eventually).
bbf9994
to
8b19ffd
Compare
Thanks! |
It has been disabled in `master` since one year (godotengine#45852) and our plan is for Bullet, and possibly other thirdparty physics engines, to be implemented via GDExtension so that they can be selected by the users who need them.
It has been disabled in `master` since one year (godotengine#45852) and our plan is for Bullet, and possibly other thirdparty physics engines, to be implemented via GDExtension so that they can be selected by the users who need them.
-Rendering server now uses a split RID allocate/initialize internally, this allows generating RIDs immediately but initialization to happen later on the proper thread (as rendering APIs generally requiere to call on the right thread).
-RenderingServerWrapMT is no more, multithreading is done in RenderingServerDefault.
-Some functions like texture or mesh creation, when renderer supports it, can register and return immediately (so no waiting for server API to flush, and saving staging and command buffer memory).
-3D physics server changed to be made multithread friendly.
-Added PhysicsServer3DWrapMT to use 3D physics server from multiple threads.
-Disablet Bullet (too much effort to make multithread friendly, this needs to be fixed eventually).
Once merged, servers will be perfectly multithread-safe, so I can enable multthreaded loading by default, for editor and engine.