ComputeShaderTask

Inherits: Resource

Description

Wraps a ComputeShaderFile into a dispatchable unit of compute work. Functions similarly to a ShaderMaterial, storing parameter values and sending them to the GPU during dispatch.

Properties

RenderingDevice

rendering_device

ComputeShaderFile

shader

Methods

void

clear_shader_parameters()

void

dispatch(kernel_name: StringName, thread_groups: Vector3i, context: Object = null)

void

dispatch_all(thread_groups: Vector3i, context: Object = null)

void

dispatch_at(kernel_index: int, thread_groups: Vector3i, context: Object = null)

void

dispatch_group(group_name: StringName, thread_groups: Vector3i, context: Object = null)

PackedByteArray

get_buffer_data(param: StringName) const

Error

get_buffer_data_async(param: StringName, callback: Callable) const

PackedByteArray

get_kernel_buffer_data(kernel: StringName, param: StringName) const

Error

get_kernel_buffer_data_async(kernel: StringName, param: StringName, callback: Callable) const

Variant

get_kernel_parameter(kernel: StringName, param: StringName) const

Array[RID]

get_kernel_rids(kernel: StringName, param: StringName) const

Array[RID]

get_rids(param: StringName) const

Variant

get_shader_parameter(param: StringName) const

void

set_kernel_parameter(kernel: StringName, param: StringName, value: Variant)

void

set_shader_parameter(param: StringName, value: Variant)


Property Descriptions

RenderingDevice rendering_device 🔗

  • void set_rendering_device(value: RenderingDevice)

  • RenderingDevice get_rendering_device()

The underlying RenderingDevice to use for dispatch. If not set, will use the rendering device associated with the RenderingServer.


ComputeShaderFile shader 🔗

The shader executed during dispatch of this task.


Method Descriptions

void clear_shader_parameters() 🔗

Clears all shader parameters for this task.


void dispatch(kernel_name: StringName, thread_groups: Vector3i, context: Object = null) 🔗

Dispatches a kernel by name with the specified number of thread groups.

Each dispatch method also accepts a context containing arbitrary data. This data may be used by user attributes declared in the shader when data is bound.


void dispatch_all(thread_groups: Vector3i, context: Object = null) 🔗

Dispatches all kernels associated with this task with the specified number of thread groups. Dispatch is ordered based on each kernel's index.


void dispatch_at(kernel_index: int, thread_groups: Vector3i, context: Object = null) 🔗

Dispatches a kernel by index with the specified number of thread groups.


void dispatch_group(group_name: StringName, thread_groups: Vector3i, context: Object = null) 🔗

Dispatches all kernels in the specified group_name. Kernels are associated with a group using the gd::KernelGroup attribute.


PackedByteArray get_buffer_data(param: StringName) const 🔗

Fetch the raw bytes for param. If this parameter is a buffer, this returns the full buffer. If this parameter is a region of a buffer, returns only the region associated with this param. See: RenderingDevice.buffer_get_data.


Error get_buffer_data_async(param: StringName, callback: Callable) const 🔗

Fetches the data for the buffer associated with param. See: get_buffer_data and RenderingDevice.buffer_get_data_async.


PackedByteArray get_kernel_buffer_data(kernel: StringName, param: StringName) const 🔗

Fetch the raw bytes for param in kernel. If this parameter is a buffer, this returns the full buffer. If this parameter is a region of a buffer, returns only the region associated with this param. See: RenderingDevice.buffer_get_data.


Error get_kernel_buffer_data_async(kernel: StringName, param: StringName, callback: Callable) const 🔗

Fetches the data for the buffer associated with param in kernel. See: get_buffer_data and RenderingDevice.buffer_get_data_async.


Variant get_kernel_parameter(kernel: StringName, param: StringName) const 🔗

Gets a kernel parameter by name.


Array[RID] get_kernel_rids(kernel: StringName, param: StringName) const 🔗

Gets the uniform RIDs associated with param in kernel for the most recent dispatch.


Array[RID] get_rids(param: StringName) const 🔗

Gets the uniform RIDs associated with param for the most recent dispatch.


Variant get_shader_parameter(param: StringName) const 🔗

Gets a shader parameter value by name.


void set_kernel_parameter(kernel: StringName, param: StringName, value: Variant) 🔗

Set's a parameter value of the entry-point kernel by name. See set_shader_parameter for more information.


void set_shader_parameter(param: StringName, value: Variant) 🔗

Sets a global shader parameter value by name.

If value is a PackedByteArray, the bytes will be copied directly without any additional interpretation.

If value is an RID or RDUniform, the resource (e.g., texture or sampler) will be bound directly to the descriptor slot associated with the param.

For other parameter types, this will make a best effort to convert value to the expected format of param.

For example, if you declare a float3 parameter in your shader, You can bind it via set_shader_parameter(Vector3.ONE) or set_shader_parameter(Color.RED). The value will be written to appropriate offset in the buffer associated with the parameter.

For array types and structured buffers, you may pass in an Array and it will be written with the correct element stride and alignment.

For Texture2D and Sampler2D parameters, you may pass a Texture2D resource for the value.

var buffer_rid := RenderingServer.get_rendering_device().storage_buffer_create(256)
compute_shader_task.set_shader_parameter("storage_buffer", buffer_rid)
# or
var sampler_rid := RenderingServer.get_rendering_device().sampler_create(RDSamplerState.new())
compute_shader_task.set_shader_parameter("sampler_state", sampler_rid)
# you can pass two RIDs in an array for Sampler2D params
compute_shader_task.set_shader_parameter("sampler2d", [sampler_rid, texture_rid])