Create a Material specifically built to run computations on the GPU. Internally used by ComputePass.

Compute pipeline

A ComputeMaterial automatically creates a ComputePipelineEntry. Once all the BindGroup have been created, they are sent with the compute shader code to the ComputePipelineEntry, which is in turns responsible for creating the GPUComputePipeline.

After the GPUComputePipeline has been successfully compiled, the ComputeMaterial is considered to be ready and it can start running the compute shader computations.

Hierarchy (view full)

Constructors

Properties

pipelineEntry: ComputePipelineEntry

Options used to create this ComputeMaterial

dispatchSize?: number | number[]

Default work group dispatch size to use with this ComputeMaterial

_useCustomRenderCallback: ((pass) => void)

function assigned to the useCustomRender callback

Type declaration

    • (pass): void
    • function assigned to the useCustomRender callback

      Parameters

      • pass: GPUComputePassEncoder

      Returns void

type: string

The type of the Material

uuid: string

The universal unique id of the Material

renderer: Renderer

The Renderer used

bindGroups: AllowedBindGroups[]

Array of bind groups used by this Material This array respects a specific order:

  1. The textures bind groups
  2. The bind group created using uniforms and storages parameters if any
  3. Additional bind groups parameters if any
texturesBindGroups: TextureBindGroup[]

Array of texture bind groups used by this Material

inputsBindGroups: BindGroup[]

Array of bind groups created using the uniforms and storages parameters when instancing this Material

clonedBindGroups: AllowedBindGroups[]

Array of cloned bind groups created by this Material

uniforms: Record<string, Record<string, BufferBindingInput>>

Object containing all uniforms inputs handled by this Material

storages: Record<string, Record<string, BufferBindingInput>>

Object containing all read only or read/write storages inputs handled by this Material

inputsBindings: Map<string, BindGroupBindingElement>

Map of bindings created using the uniforms and storages parameters when instancing this Material

domTextures: DOMTexture[]

Array of DOMTexture handled by this Material

textures: Texture[]

Array of Texture handled by this Material

samplers: Sampler[]

Array of Sampler handled by this Material

Accessors

  • get ready(): boolean
  • Get whether the renderer is ready, our pipeline entry and pipeline have been created and successfully compiled

    Returns boolean

Methods

  • If a custom render function has been defined instead of the default one, register the callback

    Parameters

    • callback: ((pass) => void)

      callback to run instead of the default render behaviour, which is to set the bind groups and dispatch the work groups based on the default dispatch size. This is where you will have to set all the bind groups and dispatch the workgroups by yourself.

        • (pass): void
        • Parameters

          • pass: GPUComputePassEncoder

          Returns void

    Returns void

  • Render the material if it is ready: Set the current pipeline, set the bind groups and dispatch the work groups

    Parameters

    • pass: GPUComputePassEncoder

      current compute pass encoder

    Returns void

  • Copy all writable binding buffers that need it

    Parameters

    • commandEncoder: GPUCommandEncoder

      current command encoder

    Returns void

  • Get the result GPU buffer content by binding and buffer element names

    Parameters

    • parameters: {
          bindingName?: string;
          bufferElementName?: string;
      }

      parameters used to get the result

      • Optional bindingName?: string

        binding name from which to get the result

      • Optional bufferElementName?: string

        optional buffer element (i.e. struct member) name if the result needs to be restrained to only one element

    Returns Promise<Float32Array>

    • the mapped content of the GPUBuffer as a Float32Array

    Async