godot
godot copied to clipboard
RenderingDevice non blocking sync
What this adds
https://github.com/godotengine/godot-proposals/issues/10481#issue-2471732290
the function try_sync
was added to RenderingDevice
.
This function will not block. If the fence has been signaled (and thus the operation has finished) it will return true
. Returns false
otherwise.
Earlier you would've had to create a separate thread, call sync
and let it get blocked till operation completes. That might add complications when trying to use the GPU compute in a certain way.
Test project
https://github.com/darthLeviN/godot-compute/tree/1d26e56df3e6be6a53c992261850aed4a2cff79b
this project contains a simple loop that calls
while(not rd.try_sync()):
try_count += 1
await get_tree().process_frame
and allows for logging the try count.
Notes
When this succeeds side effects are the equivalent of calling sync. So you shouldn't keep calling it again.
Issues
Currently i think we don't have good error handling. In case of an error this fails and returns false
. and there won't be any way to know if it failed or we just need to wait for it.
This is also true for sync
because it's a void
function.
Also, Signals can be implemented here. If desired, We can internally do the once per frame check if the pipeline is still processing. This improvement can be added on top of this implementation while keeping backwards compatibility.
Docs
Full docs entry with notes was added.
Testing
I have tested this on ubuntu 22.04 with a RTX 3070 for vulkan. DirectX12 needs to be tested.
I think running the test project will suffice.