class
CrShader::ComputeHelper
- CrShader::ComputeHelper
- Reference
- Object
Overview
============================================================================= ComputeHelper - High-Level Godot 4 RenderingDevice Compute Orchestration
Eliminates low-level RenderingDevice boilerplate for compiling GLSL 450 compute kernels to SPIR-V, managing pipeline states, sampler states, multi-set uniform descriptors, push constants, and workgroup dispatches.
Defined in:
crshader/compute/compute_helper.crConstant Summary
-
RD_BRIDGE_GDSCRIPT =
"extends RefCounted\nvar _uniforms: Array[RDUniform] = []\n\nfunc clear_uniforms() -> void:\n\t_uniforms.clear()\n\nfunc push_uniform(u: RDUniform) -> void:\n\t_uniforms.push_back(u)\n\nfunc create_uniform_set(rd: RenderingDevice, shader_id: int, set_idx: int) -> int:\n\tvar rid := rd.uniform_set_create(_uniforms, rid_from_int64(shader_id), set_idx)\n\t_uniforms.clear()\n\treturn rid.get_id()\n\nfunc create_ubo(rd: RenderingDevice, size_bytes: int, data: PackedByteArray) -> int:\n\treturn rd.uniform_buffer_create(size_bytes, data).get_id()\n\nfunc update_buf(rd: RenderingDevice, buf_id: int, offset: int, size_bytes: int, data: PackedByteArray) -> int:\n\treturn rd.buffer_update(rid_from_int64(buf_id), offset, size_bytes, data)\n\nfunc create_ssbo_data(rd: RenderingDevice, size_bytes: int, data: PackedByteArray) -> int:\n\treturn rd.storage_buffer_create(size_bytes, data).get_id()\n\nfunc create_ssbo_empty(rd: RenderingDevice, size_bytes: int) -> int:\n\treturn rd.storage_buffer_create(size_bytes).get_id()\n\nfunc set_push_const(rd: RenderingDevice, compute_list: int, data: PackedByteArray, size_bytes: int) -> void:\n\trd.compute_list_set_push_constant(compute_list, data, size_bytes)" -
SHADER_STAGE_COMPUTE =
4_i64 -
UNIFORM_TYPE_IMAGE =
3 -
UNIFORM_TYPE_SAMPLER =
0 -
Exact Godot 4.x RenderingDevice::UniformType values
-
UNIFORM_TYPE_SAMPLER_WITH_TEXTURE =
1 -
UNIFORM_TYPE_STORAGE_BUFFER =
8 -
UNIFORM_TYPE_TEXTURE =
2 -
UNIFORM_TYPE_UNIFORM_BUFFER =
7
Constructors
-
.create(shader_rid : Int64, rd : Godot::RenderingDevice | Nil = nil) : ComputeHelper
Factory method creating helper from a compiled shader RID
- .new(rd : Godot::RenderingDevice | Nil = nil)
Instance Method Summary
-
#bind_image(binding : Int32, texture_rid : Int64, set_index : Int32 = 0) : Void
Binds an image2D storage image (UniformTypeImage = 3)
-
#bind_sampler_with_texture(binding : Int32, texture_rid : Int64, linear : Bool = false, set_index : Int32 = 0) : Void
Binds a combined sampler2D (UniformTypeSamplerWithTexture = 1), required for depth & normal_roughness buffers
-
#bind_storage_buffer(binding : Int32, buffer_rid : Int64, set_index : Int32 = 0) : Void
Binds a storage buffer (UniformTypeStorageBuffer = 8)
-
#bind_texture(binding : Int32, texture_rid : Int64, set_index : Int32 = 0) : Void
Binds a raw texture without sampler (UniformTypeTexture = 2)
-
#bind_uniform_buffer(binding : Int32, ubo_rid : Int64, set_index : Int32 = 0) : Void
Binds a Uniform Buffer Object (UniformTypeUniformBuffer = 7)
-
#bindings : Hash(Int32, BoundUniform)
Backwards-compatible accessor for set 0 bindings
- #cleanup_all : Void
-
#cleanup_pipeline(free_shader : Bool = false) : Void
Cleans up GPU pipeline, uniform sets, samplers, and owned shader/buffer RIDs
-
#compile_glsl(glsl_source : String, name : String = "CrShaderCompute") : Int64
Compiles GLSL 450 compute source directly to SPIR-V on RenderingDevice and creates pipeline
-
#create_storage_buffer(byte_size : Int32, data : Bytes | Nil = nil, binding : Int32 | Nil = nil, set_index : Int32 = 0) : Int64
Allocates a GPU storage buffer of
byte_sizebytes on the RenderingDevice - #dirty_sets : Set(Int32)
- #dirty_sets=(dirty_sets : Set(Int32))
-
#dispatch(width : Int32, height : Int32, depth : Int32 = 1, local_x : Int32 = 8, local_y : Int32 = 8, local_z : Int32 = 1) : Bool
Dispatches the compute shader over screen / volume dimensions
-
#dispatch_1d(element_count : Int32, local_x : Int32 = 64) : Bool
Dispatches a 1D compute kernel over
element_countitems - #ensure_linear_sampler : Int64
- #ensure_nearest_sampler : Int64
-
#ensure_uniform_buffer(existing_rid : Int64, bytes : Bytes, binding : Int32, set_index : Int32 = 0) : Int64
Allocates or updates a GPU Uniform Buffer Object (UBO)
- #finalize
- #last_compile_error : String
- #pipeline_rid : Int64
- #pipeline_rid=(pipeline_rid : Int64)
-
#push_constant_bytes : Bytes | Nil
Cached push constant payload bytes for the next dispatch
-
#push_constant_bytes=(push_constant_bytes : Bytes | Nil)
Cached push constant payload bytes for the next dispatch
- #rd : Godot::RenderingDevice | Nil
- #rd=(rd : Godot::RenderingDevice | Nil)
- #set_bindings : Hash(Int32, Hash(Int32, BoundUniform))
- #set_bindings=(set_bindings : Hash(Int32, Hash(Int32, BoundUniform)))
-
#set_push_constant(bytes : Bytes) : Void
Sets push constant bytes (aligned to 16 bytes as required by Vulkan / RenderingDevice)
- #set_rids : Hash(Int32, Int64)
- #set_rids=(set_rids : Hash(Int32, Int64))
- #set_shader(shader_rid : Int64, owned : Bool = false) : Void
- #shader_rid : Int64
- #shader_rid=(shader_rid : Int64)
-
#sync : Void
Syncs execution on local RenderingDevices
- #uniform_set_dirty : Bool
- #uniform_set_dirty=(uniform_set_dirty : Bool)
- #uniform_set_rid : Int64
- #uniform_set_rid=(uniform_set_rid : Int64)
-
#update_uniform_set(set_index : Int32 = 0) : Bool
Rebuilds the RDUniform set for
set_indexif bindings changed
Constructor Detail
Factory method creating helper from a compiled shader RID
Instance Method Detail
Binds an image2D storage image (UniformTypeImage = 3)
Binds a combined sampler2D (UniformTypeSamplerWithTexture = 1), required for depth & normal_roughness buffers
Binds a storage buffer (UniformTypeStorageBuffer = 8)
Binds a raw texture without sampler (UniformTypeTexture = 2)
Binds a Uniform Buffer Object (UniformTypeUniformBuffer = 7)
Cleans up GPU pipeline, uniform sets, samplers, and owned shader/buffer RIDs
Compiles GLSL 450 compute source directly to SPIR-V on RenderingDevice and creates pipeline
Allocates a GPU storage buffer of byte_size bytes on the RenderingDevice
Dispatches the compute shader over screen / volume dimensions
Dispatches a 1D compute kernel over element_count items
Allocates or updates a GPU Uniform Buffer Object (UBO)
Cached push constant payload bytes for the next dispatch
Sets push constant bytes (aligned to 16 bytes as required by Vulkan / RenderingDevice)
Rebuilds the RDUniform set for set_index if bindings changed