Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ComputeBuffer

Create a Compute Buffer.
Read time 2 minutesLast updated 4 days ago

Definition

  • Type: Constructor
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

ComputeBuffer(int, int)

Create a Compute Buffer.
public ComputeBuffer(int count, int stride)

Parameters

count

Number of elements in the buffer.

stride

Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See Compute Shaders for cross-platform compatibility information.

Remarks

Use ComputeBuffer.Release to release the buffer when no longer needed.

ComputeBuffer(int, int, ComputeBufferType)

Create a Compute Buffer.
public ComputeBuffer(int count, int stride, ComputeBufferType type)

Parameters

count

Number of elements in the buffer.

stride

Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See Compute Shaders for cross-platform compatibility information.

Type of the buffer, default is ComputeBufferType.Default (structured buffer).

Remarks

Use ComputeBuffer.Release to release the buffer when no longer needed.

ComputeBuffer(int, int, ComputeBufferType, ComputeBufferMode)

Create a Compute Buffer.
public ComputeBuffer(int count, int stride, ComputeBufferType type, ComputeBufferMode usage)

Parameters

count

Number of elements in the buffer.

stride

Size of one element in the buffer, in bytes. Must be a multiple of 4 and less than 2048, and match the size of the buffer type in the shader. See Compute Shaders for cross-platform compatibility information.

Type of the buffer, default is ComputeBufferType.Default (structured buffer).

Usage mode of the buffer, default is ComputeBufferModeImmutable.

Remarks

Use ComputeBuffer.Release to release the buffer when no longer needed.