Skip to content

RenderingDevice.uniform_set_create() reports invalid texture RID for valid textures in RenderingServer #108095

Closed
@dmlary

Description

@dmlary

Tested versions

Reproducable in v4.4.1.stable.official [49a5bc7], v4.3.stable.official [77dcf97]

System information

Godot v4.4.1.stable - macOS Sonoma (14.7.6) - Multi-window, 2 monitors - Metal (Forward+) - integrated Apple M3 Max (Apple9) - Apple M3 Max (16 threads)

Issue description

The global RenderingDevice (returned by RenderingServer.get_rendering_device()) is unable to use textures from the RenderingServer, such as RenderingServer.get_test_texture(), or any SubViewport texture. RenderingDevice.uniform_set_create() returns an error stating "Texture (binding: N, index M) is not a valid texture", despite RenderingServer.texture_get_format() confirming they are valid textures.

What is confusing here is that these are valid textures according to the RenderingServer, but RenderingDevice.texture_is_valid() says they're not.
NOTE: this is not a local rendering device created with RenderingServer.create_local_rendering_device(), so I would expect it to have access to textures returned by the RenderingServer.

RenderingDevice *RenderingServer::get_rendering_device() const {
// Return the rendering device we're using globally.
return RenderingDevice::get_singleton();
}

Steps to reproduce

Use the mini-project I attached. There are two buttons, one tries to create the shader using the SubViewport texture that is clearly valid and visible on screen. The other uses the texture RID returned by RenderingServer.get_test_texture()

Each button prints out the RID used, and the results of RenderDevice.texture_is_valid(), before calling RenderingDevice.uniform_set_create().

Image

Key code involved:

# from button.gd in mini project

    var texture_rid : RID
    if viewport:
        # This is my intended usage, which does not work
        texture_rid = viewport.get_texture().get_rid()
        print("Using viewport.get_texture().get_rid():",
            " RenderingDevice.texture_is_valid(", texture_rid, ") = ",
            rd.texture_is_valid(texture_rid))
    else:
        # HERE IS THE PART THAT MAKES NO SENSE
        # Using the **guaranteed** valid texture for testing
        texture_rid = RenderingServer.get_test_texture()
        print("Using RenderingServer.get_test_texture():",
            " RenderingDevice.texture_is_valid(", texture_rid, ") = ",
            rd.texture_is_valid(texture_rid))

    # create a uniform
    var tex_uniform = RDUniform.new()
    tex_uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_SAMPLER_WITH_TEXTURE
    tex_uniform.binding = 1
    tex_uniform.add_id(samp)
    tex_uniform.add_id(RenderingServer.get_test_texture())
    var uniform_set = rd.uniform_set_create([buffer_uniform, tex_uniform], shader, 0)
    if !uniform_set.is_valid():
        print("ERROR: failed to set uniforms;",
            " detailed error in Debugger->Errors tab")
        return

Minimal reproduction project (MRP)

subviewport-compute-shader-issue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions