Skip to main content

ComputeLua

Main module for ComputeLua, holds all the functions to manage ComputeBuffers, Dispatchers, threads, and more.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ComputeLua = require(ReplicatedStorage.ComputeLua)

Types

BufferDataType

type BufferDataType = Vector2 | Vector3 | CFrame | Color3 | UDim | UDim2 | number | boolean | string

The only data types allowed in buffers, Compute or Variable

ComputeBufferDataType

type ComputeBufferDataType = {[number]BufferDataType | ComputeBufferDataType}

Type for the data of a ComputeBuffer

VariableBufferDataType

type VariableBufferDataType = {[number]BufferDataType}

Type for the data of the VariableBuffer

Functions

CreateDispatcher

Parallel Unsafe
since v1.0.0
</>
ComputeLua.CreateDispatcher(
numWorkersnumber,--

How many workers to use, balanced this with performance and speed

workerScript | LocalScript--

The template script to clone as the worker

) → Dispatcher

Create a Dispatcher to run a bunch of workers in parallel

CreateComputeBuffer

Parallel Unsafe
since v1.0.0
</>
ComputeLua.CreateComputeBuffer(
bufferNamestring--

The name of the buffer.

) → ComputeBuffer

Create a ComputeBuffer to store vital information that is then sent to each worker.

GetComputeBufferData

Serial Unsafe
since v1.0.0
</>
ComputeLua.GetComputeBufferData(
bufferNamestring--

The name of the buffer.

) → ComputeBufferDataType--

The data of the ComputeBuffer

Get the ComputeBuffer data

CreateThread

Serial Unsafe
since v1.1.0
</>
ComputeLua.CreateThread(
actorActor,--

The Actor to bind the thread to, this should be the same actor as the parent of the worker.

threadNamestring,--

The unique name of the thread.

callback(
dispatchIdnumber,
variableBufferVariableBufferDataType
) → ()--

The function that will be executed when the thread is called

) → ()

Create a thread for the Dispatcher to execute

Show raw api
{
    "functions": [
        {
            "name": "CreateDispatcher",
            "desc": "Create a Dispatcher to run a bunch of workers in parallel",
            "params": [
                {
                    "name": "numWorkers",
                    "desc": "How many workers to use, balanced this with performance and speed",
                    "lua_type": "number"
                },
                {
                    "name": "worker",
                    "desc": "The template script to clone as the worker",
                    "lua_type": "Script | LocalScript"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Dispatcher"
                }
            ],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.0.0",
            "source": {
                "line": 468,
                "path": "src/init.lua"
            }
        },
        {
            "name": "CreateComputeBuffer",
            "desc": "Create a ComputeBuffer to store vital information that is then sent to each worker.",
            "params": [
                {
                    "name": "bufferName",
                    "desc": "The name of the buffer.",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ComputeBuffer"
                }
            ],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.0.0",
            "source": {
                "line": 480,
                "path": "src/init.lua"
            }
        },
        {
            "name": "GetComputeBufferData",
            "desc": "Get the ComputeBuffer data",
            "params": [
                {
                    "name": "bufferName",
                    "desc": "The name of the buffer.",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "The data of the ComputeBuffer",
                    "lua_type": "ComputeBufferDataType"
                }
            ],
            "function_type": "static",
            "tags": [
                "Serial Unsafe"
            ],
            "since": "v1.0.0",
            "source": {
                "line": 492,
                "path": "src/init.lua"
            }
        },
        {
            "name": "CreateThread",
            "desc": "Create a thread for the Dispatcher to execute",
            "params": [
                {
                    "name": "actor",
                    "desc": "The Actor to bind the thread to, this should be the same actor as the parent of the worker.",
                    "lua_type": "Actor"
                },
                {
                    "name": "threadName",
                    "desc": "The unique name of the thread.",
                    "lua_type": "string"
                },
                {
                    "name": "callback",
                    "desc": "The function that will be executed when the thread is called",
                    "lua_type": "(dispatchId: number, variableBuffer: VariableBufferDataType) -> ()"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Serial Unsafe"
            ],
            "since": "v1.1.0",
            "source": {
                "line": 506,
                "path": "src/init.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "BufferDataType",
            "desc": "The only data types allowed in buffers, Compute or Variable",
            "lua_type": "Vector2 | Vector3 | CFrame | Color3 | UDim | UDim2 | number | boolean | string",
            "source": {
                "line": 53,
                "path": "src/init.lua"
            }
        },
        {
            "name": "ComputeBufferDataType",
            "desc": "Type for the data of a ComputeBuffer",
            "lua_type": "{ [number]: BufferDataType | ComputeBufferDataType }",
            "source": {
                "line": 70,
                "path": "src/init.lua"
            }
        },
        {
            "name": "VariableBufferDataType",
            "desc": "Type for the data of the VariableBuffer",
            "lua_type": "{ [number]: BufferDataType }",
            "source": {
                "line": 75,
                "path": "src/init.lua"
            }
        }
    ],
    "name": "ComputeLua",
    "desc": "Main module for ComputeLua, holds all the functions to manage ComputeBuffers, Dispatchers, threads, and more.\n\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\nlocal ComputeLua = require(ReplicatedStorage.ComputeLua)\n```",
    "source": {
        "line": 457,
        "path": "src/init.lua"
    }
}