SlangShaderTask

Inherits: Resource

Description

Wraps a SlangShaderFile 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

SlangShaderFile

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_program_buffer_data(program: StringName, param: StringName) const

Error

get_program_buffer_data_async(program: StringName, param: StringName, callback: Callable) const

Variant

get_program_parameter(program: StringName, param: StringName) const

Array[RID]

get_program_rids(program: StringName, param: StringName) const

Array[RID]

get_rids(param: StringName) const

Variant

get_shader_parameter(param: StringName) const

void

set_program_parameter(program: 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.


SlangShaderFile shader 🔗

The shader executed during dispatch of this task.


Method Descriptions

void clear_shader_parameters() 🔗

Clears all shader parameters for this task.

Every parameter is written again on the next dispatch, including parameters that are unsynced.


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 every compute program associated with this task with the specified number of thread groups, in SlangShaderFile.programs order. Programs that are not compute kernels are skipped.


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

Dispatches the compute program at kernel_index in SlangShaderFile.programs with the specified number of thread groups. Errors if that program is not a compute kernel.


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_program_buffer_data(program: StringName, param: StringName) const 🔗

Fetch the raw bytes for param in program. 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_program_buffer_data_async(program: StringName, param: StringName, callback: Callable) const 🔗

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


Variant get_program_parameter(program: StringName, param: StringName) const 🔗

Gets a program parameter by name.


Array[RID] get_program_rids(program: StringName, param: StringName) const 🔗

Gets the uniform RIDs associated with param in program 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_program_parameter(program: StringName, param: StringName, value: Variant) 🔗

Set's a parameter value of the entry-point program 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.

For SamplerState parameters, you may pass an RDSamplerState instance 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])

Assigning a parameter is also what schedules an unsynced parameter to be written. Parameters that the shader writes to are not rewritten on every dispatch, so their contents survive until the parameter is assigned again. See the gd::Sync attribute.

Assigning a value writes every member that value supplies, so a member left out of it keeps whatever the shader wrote there.

Mutating an Array or Dictionary in place is not an assignment. Call this method again with the mutated value to write the change.