Godot Version
4.3
Question
Hi, I’m struggling with running a compute shader asyncronously. Unfortunately I need to use the results of the compute shader in CPU run code so can’t ‘fire and forget’, but I don’t want to block the main thread with a submit and following sync call
I set this up to run on an asynchronous thread so that this can take a couple of frames (or more) before returning and I can then get the results, relying on the previous set of results in the meantime.
I am encountering a couple issues with this:
- I get an error:
Found open compute list at the end of the frame, this should never happen (further compute will likely not work).
Further compute calls do work, the shader will run happily every other frame or so.
- As I load up this processing task I start to get vulkan errors: Condition “err != VK_SUCCESS” is true. Returning: FAILED
Which I think might the centred on the shader taking too long to return so it’s being killed? The amount of data I can give to it before this happens seems to be massively influenced by what else the gpu is being asked to do at the same time and overall quite inconsistent.
The current order of my calls are:
var compute_renderer := RenderingServer.create_local_rendering_device()
… intervening code setting up uniforms and configuring buffers etc …
compute_renderer.compute_list_dispatch(compute_list, number_of_groups, 1, 1)
compute_renderer.submit()
compute_renderer.sync()
compute_renderer.compute_list_end()
var output_bytes = compute_renderer.buffer_get_data(output_buffer)
I’ve tried moving the .compute_list_end() call around to try and make it happier but it still throws the error and this is also where the vulkan error originates (at least the debugger reckons so, I am skeptical)
I’ve seen some material about fences, but I’ve either missed them i the docs or they don’t seem to be part of godot 4? Are they called something else now?
My main question is first, am I even asking the right questions? If so how do I both let the core engine know that the thread is truly async so the pipeline being open between frames is not a problem, and prevent the shader being killed for taking too long to return, if that is what’s causing the problem.
As you can see, my understanding of compute shaders, and particularly the pipelines on which they are executed is quite limited, so I may have completely misunderstood what’s going on under the hood here.
Also if this is in the wrong topic let me know, shaders seemed most appropriate but might be a more code centric question.