RenderingServer.texture_2d_get() quite not working

Godot Version

4.3

Question

I’m trying to create a custom Texture2D by drawing stuff on a canvas item, converting it to an image and creating the texture from the image
This is my current setup:

extends Sprite2D

var rs := RenderingServer

func _ready() -> void:
	var ca: RID = rs.canvas_item_create()
	rs.canvas_item_set_transform(ca, Transform2D.IDENTITY)
	rs.canvas_item_add_rect(ca, Rect2(-100, -100, 200, 200), Color.RED)
	rs.canvas_item_add_circle(ca, Vector2.ZERO, 100, Color.MAGENTA)
	var img: Image = rs.texture_2d_get(ca)
	print("Image: ", img)
	texture = ImageTexture.create_from_image(img)

But when I run the script the sprite does not get a texture and the console prints:

Image: <Object#null>

So it looks like rs.texture_2d_get() is not working at all and I have no idea why…
Please help me!
Thanks in advance!

why not to use SubViewport for it?
or directly Image.set_pixel()

extends SubViewport
func _ready()->void:
	await RenderingServer.frame_post_draw
	Textures.output=ImageTexture.create_from_image(get_texture().get_image())

Thanks for the reply!
I’m not using SubViewport or Image.set_pixel() because I’d like to draw directly on it and to use the more advanced functions provided by the RenderingServer, for example to add a material with a shader