Draw Compute Shader As Texture

It may be disposing something between the _ready() call and the _draw() call. Not sure what, though.

There’s Texture2DRD which may be more useful but it only works with the main RenderingDevice that you get from RenderingServer.get_rendering_device(). Something like:

extends Node2D

var rd: RenderingDevice
var output_texture_rid: RID
var shader: RID
var pipeline: RID
var uniform_set: RID

var texture_width = 400
var texture_height = 400

var texture:Texture2DRD

func _ready():
    rd = RenderingServer.get_rendering_device()

    # Create the output texture.
    #...
    
    # Create the Texture2DRD here and assign the rid
    texture = Texture2DRD.new()
    texture.texture_rd_rid = output_texture_rid
    
    # Load and create the compute shader that fills the texture with neon pink.
    #...
    
    # Bind the output texture to the shader (set 0, binding 0).
    #...
    
    # Dispatch the compute shader.
    #...

    queue_redraw()

    
func _draw():
    draw_texture_rect(texture, Rect2(Vector2(50, 50), texture.get_size()), false)

I’m not sure if you can somehow share a texture between the main rendering device and a local one.

Edit:

This seems to work:

	var main_rd = RenderingServer.get_rendering_device()
	var main_rid = main_rd.texture_create(tformat, tview)

	texture = Texture2DRD.new()
	texture.texture_rd_rid = main_rid

	output_texture_rid = rd.texture_create_from_extension(RenderingDevice.TEXTURE_TYPE_2D,
		tformat.format,
		tformat.samples,
		tformat.usage_bits,
		main_rd.get_driver_resource(RenderingDevice.DRIVER_RESOURCE_TEXTURE, main_rid, 0),
		tformat.width,
		tformat.height,
		tformat.depth,
		tformat.array_layers)

Basically you create the texture in the main rendering device and you pass it to your local rendering device by “creating” a texture using the native texture handle from the texture in the main rendering device.