Running compute shader in separate thread, sharing textures and TextureCubemapRD

Godot Version



Hi, I’m relatively new to Godot. I’m trying to port a compute shader that does ray marching on a separate thread, and then use the resulting texture in a material in the engine. The renderer draws progressively, so first at very low resolution, and then successive dispatches fill up higher and higher resolutions until the texture is ready. The rendering times are very unpredictable (fractal iterations, shadows, etc.), so running this in a separate thread is ideal.

Now, it looks like I need separate RenderingDevices for this, but I can’t seem to share the textures between them. It works if I dispatch the compute shader from the main thread from _process(), but this is a lot slower, because it is synced to the monitor FPS. Is there a way to share texture RIDs between threads that I’m unaware of?

Then about the texture. I can render to a Texture2DRD as per example, but ideally I would like to render to a TextureCubemapRD. Unfortunately, this is not available from the pulldown in the editor. Is there a way to work around this? Maybe hack the tscn with a text editor directly?

Many thanks,

Local RenderingDevices cannot draw to the screen or share resources with the main RenderingDevice You’ll need to use the main RenderingDevice with RenderingServer.get_rendering_device() to be able to share textures.

Cubemaps are mostly used in uniforms in custom shaders. Not a lot of methods in Godot use them directly. You can @export them in your custom resources and use them in your custom shaders.

Here’s a project creating volumetric clouds with compute shaders that share textures with the main rendering device GitHub - clayjohn/godot-volumetric-cloud-demo-v2: V2 of