Engine API Reference - v2.16.1
    Preparing search index...

    Class Compute

    A representation of a compute shader with the associated resources, that can be executed on the GPU. Only supported on WebGPU platform.

    Index

    Constructors

    • Create a compute instance. Note that this is supported on WebGPU only and is a no-op on other platforms.

      Parameters

      • graphicsDevice: GraphicsDevice

        The graphics device.

      • shader: Shader

        The compute shader.

      • Optionalname: string = 'Unnamed'

        The name of the compute instance, used for debugging only.

      Returns Compute

    Properties

    name: string

    The non-unique name of an instance of the class. Defaults to 'Unnamed'.

    Methods

    • Deletes a shader parameter from the compute instance.

      Parameters

      • name: string

        The name of the parameter to delete.

      Returns void

    • Prepare the compute work dispatch.

      Parameters

      • x: number

        X dimension of the grid of work-groups to dispatch.

      • Optionaly: number

        Y dimension of the grid of work-groups to dispatch.

      • Optionalz: number

        Z dimension of the grid of work-groups to dispatch.

      Returns void

    • Prepare the compute work dispatch to use indirect parameters from a buffer. The dispatch parameters (x, y, z workgroup counts) are read from the buffer at the specified slot index.

      When using the device's built-in buffer (buffer parameter is null), this method must be called each frame as slots are only valid for the current frame.

      Parameters

      • slotIndex: number

        Slot index in the indirect dispatch buffer. When using the device's built-in buffer, obtain this by calling GraphicsDevice#getIndirectDispatchSlot.

      • Optionalbuffer: StorageBuffer | null = null

        Optional custom storage buffer containing dispatch parameters. If not provided, uses the device's built-in GraphicsDevice#indirectDispatchBuffer. When providing a custom buffer, the user is responsible for its lifetime and contents.

      Returns void

      // Reserve a slot in the indirect dispatch buffer
      const slot = device.getIndirectDispatchSlot();

      // First compute shader writes dispatch parameters to the buffer
      prepareCompute.setParameter('indirectBuffer', device.indirectDispatchBuffer);
      prepareCompute.setParameter('slot', slot);
      prepareCompute.setupDispatch(1, 1, 1);
      device.computeDispatch([prepareCompute]);

      // Second compute shader uses indirect dispatch
      processCompute.setupIndirectDispatch(slot);
      device.computeDispatch([processCompute]);