godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Non blocking sync for RenderingDevice #10481

Open darthLeviN opened 2 months ago

darthLeviN commented 2 months ago

Describe the project you are working on

A project that uses gpu compute to speed some things up.

Describe the problem or limitation you are having in your project

Let's say we offload a task to a gpu compute pipeline. Now the only way that we can wait for it is by calling sync (correct me if i'm wrong). calling sync just blocks the thread till the pipeline finishes processing. This is inconvenient as it requires the creation of a redundant thread. Graphics APIs provide a way to check if the processing has finished or not. So we can expose this functionality.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

try_sync that just returns false if the pipeline is still processing. If not does what sync does.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

https://github.com/godotengine/godot/pull/95718 https://github.com/darthLeviN/godot-compute/tree/1d26e56df3e6be6a53c992261850aed4a2cff79b

rd.submit()

print("Starting try")
while(not rd.try_sync()):
   try_count += 1
   await get_tree().process_frame

If this enhancement will not be used often, can it be worked around with a few lines of script?

With an extra redundant thread.

Is there a reason why this should be core and not an add-on in the asset library?

Sometimes we just want to offload some simple task to the gpu and not have to deal with thread creation/management. It can't be an addon.

Extra note

Currently the fence status checks are not really used anywhere in the code base. Eventually godot should expose fences for high end users. This is a good starting point by at least using the fence status internally.

clayjohn commented 2 months ago

Related to https://github.com/godotengine/godot-proposals/issues/7886 and https://github.com/godotengine/godot/pull/87850/files