Godot Version
4.3
Question
I have been trying to make a compute shader and after sorting out all the errors it gave me it now gets stuck when calling compute_pipeline_create()
but it doesn’t give me any errors. I have been trying to find a solution and reading through the code to find the problem for days but I just don’t seem to be able to find anything wrong. Here is the gdscript for the shader:
func shader_flood_fill() -> PackedInt32Array:
print("flood fill begin")
var rd: RenderingDevice = RenderingServer.create_local_rendering_device()
var shader_file := load("res://shaders/lighting/floodfill.glsl")
var shader_spirv: RDShaderSPIRV = shader_file.get_spirv()
var shader := rd.shader_create_from_spirv(shader_spirv)
var uniforms: Array[RDUniform] = []
var buffers: Array[RID]
var uniform := RDUniform.new()
var light_map_bytes = light_map.to_byte_array()
var lightmap_buffer := rd.storage_buffer_create(light_map_bytes.size(), light_map_bytes)
buffers.append(lightmap_buffer)
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
uniform.binding = 0
uniform.add_id(lightmap_buffer)
uniforms.append(uniform)
uniform = RDUniform.new()
var coords := PackedVector3Array([global_position])
var coords_bytes := coords.to_byte_array()
var buffer = rd.storage_buffer_create(coords_bytes.size(), coords_bytes)
buffers.append(buffer)
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
uniform.binding = 1
uniform.add_id(buffer)
uniforms.append(uniform)
uniform = RDUniform.new()
var solidity_array := PackedFloat32Array(LightPropagation.transparency_array)
var solidity_array_bytes := solidity_array.to_byte_array()
buffer = rd.storage_buffer_create(solidity_array_bytes.size(), solidity_array_bytes)
buffers.append(buffer)
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
uniform.binding = 2
uniform.add_id(buffer)
uniforms.append(uniform)
uniform = RDUniform.new()
var strength := PackedInt32Array([energy])
var strength_bytes := strength.to_byte_array()
buffer = rd.storage_buffer_create(strength_bytes.size(), strength_bytes)
buffers.append(buffer)
uniform.uniform_type = RenderingDevice.UNIFORM_TYPE_STORAGE_BUFFER
uniform.binding = 3
uniform.add_id(buffer)
uniforms.append(uniform)
var uniform_set := rd.uniform_set_create(uniforms, shader, 0)
var pipeline := rd.compute_pipeline_create(shader)
print( "compute list begin")
var compute_list := rd.compute_list_begin()
rd.compute_list_bind_compute_pipeline(compute_list, pipeline)
rd.compute_list_bind_uniform_set(compute_list, uniform_set, 0)
print(" compute list dispatch")
rd.compute_list_dispatch(compute_list, array_size, array_size, array_size)
rd.compute_list_end()
print(" submit")
rd.submit()
print(" sync")
rd.sync()
print(" output")
var output_bytes := rd.buffer_get_data(lightmap_buffer)
var output := output_bytes.to_int32_array()
rd.free_rid(pipeline)
rd.free_rid(uniform_set)
rd.free_rid(shader)
for i in buffers:
rd.free_rid(i)
rd.free()
return output
Also, I have already tried to run godot with in verbose mode and it still gave nothing out when getting stuck. Sorry if this is some stupid mistake I am just too blind too see but I am all out of ideas to test right now.
Update:
I took a closer look at the debugger and noticed that for some reason the solidity_array
gets null assigned to it. I tried printing the LightPropagation.transparency_array
that I assign to it and it prints a completely normal array. I think this might be the problem but I have no idea why it works like that. I have been trying to play around with different types of arrays and different methods of assigning them but nothing seems to fix this. (also moved the category from shaders to programming since this problem doesn’t seem to be related to shaders after all)