+1 vote

So I've managed to get a compute pipeline working, but now I'm trying to render a triangle using a render pipeline. I've wrote the following code by referencing the source code and as far as I can see it should work. I very limited experience with GPU related things so I might very well be missing something completely.

extends Node3D
@onready var rd := RenderingServer.get_rendering_device()

func _ready():
    var shader_file: RDShaderFile = load("res://RenderTest.glsl")
    var shader_spirv: RDShaderSPIRV = shader_file.get_spirv()
    var shader := rd.shader_create_from_spirv(shader_spirv)

    # Create format
    var vertex_attrs = [RDVertexAttribute.new()]
    vertex_attrs[0].format = RenderingDevice.DATA_FORMAT_R8G8B8_SNORM
    vertex_attrs[0].location = 0
    var vertex_format = rd.vertex_format_create(vertex_attrs)

    # Create Vertex buffers
    var points := PackedFloat32Array([
        0, 0, 0,
        0, 1, 0,
        1, 1, 0,
    var points_bytes := points.to_byte_array()
    var vertex_buffers := [rd.vertex_buffer_create(points_bytes.size(), points_bytes)]
    # Create vertex array
    var vertex_array := rd.vertex_array_create(3, vertex_format, vertex_buffers)

    # Blend
    var blend = RDPipelineColorBlendState.new()

    # Create empty framebuffer size of viewport
    var rect_size = get_viewport().get_visible_rect().size
    var screen_size = Vector2i(rect_size.x, rect_size.y)
    var framebuffer = rd.framebuffer_create_empty(screen_size)

    # Define pipe
    var pipeline := rd.render_pipeline_create(

    # Create render pipeline
    if rd.render_pipeline_is_valid(pipeline):
        var draw_list := rd.draw_list_begin(framebuffer, RenderingDevice.INITIAL_ACTION_DROP, RenderingDevice.FINAL_ACTION_DISCARD, RenderingDevice.INITIAL_ACTION_DROP, RenderingDevice.FINAL_ACTION_DISCARD)
        # Bind pipe
        rd.draw_list_bind_render_pipeline(draw_list, pipeline)
        # Bind vertex array
        rd.draw_list_bind_vertex_array(draw_list, vertex_array)
        # Render
        rd.draw_list_draw(draw_list, false, 1)
        print("Invalid pipe")

And this is the shader file, I have limitex experience with shaders but as far as I understand this should be sufficient to render a mesh. Everything executes without errors, but no triangle is displayed...

#version 450 core

layout(location = 0) in vec3 vertex_attrib;

void main()
    gl_Position = vec4(vertex_attrib, 1.0);

#version 450 core

layout (location = 0) out vec4 frag_color;

void main()
    //Default color
    frag_color = vec4(1,1,1,1);

Note that the function "vertexarraycreate" is not currently (commit cf194847) bound, as pre this gitHub issue, so I added the following line of code to rendering_device.cpp, thus making it accessible, and recompiled. As far as I can see this works fine.

ClassDB::bind_method(D_METHOD("vertex_array_create", "vertex_count", "vertex_format", "buffers"), &RenderingDevice::_vertex_array_create)
Godot version 4.0
in Engine by (20 points)
retagged by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.