Fix Vulkan multithreaded compute list and GPU particle processing #79849
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.
Possibly helps with some other existing issues too, anything that uses compute shaders and threads can be affected.
Best test project to test this is probably this one: #70607 (comment) The project has a nice, big button that seems to trigger this bug every time.
The issue is that under heavy load, the multithreaded scene culling sometimes ends up calling
RenderingDeviceVulkan::compute_list_begin()
quickly in multiple threads when dealing with particles etc. This should be fine, but the actual bug is that the lock (_THREAD_SAFE_LOCK_
) was taken too late, only after the error checks. This causes some threads processing particles to simply fail instead of simply waiting their turn before doing those error checks. This PR adds_THREAD_SAFE_METHOD_
to make sure the other threads wait their turn properly before proceeding.Usually, the code fails here: https://github.com/godotengine/godot/blob/6588a4a29af1621086feac0117d5d4d37af957fd/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp#L1210C3-L1210C3 as the processing code is run in a multiple WorkerThreadPool threads at the same time.
This continues the somewhat piecemeal fashion of adding thread thread safety into the Vulkan rendering device similar to #79526, not sure if these should also ported to the Direct3D 12 PR eventually.