Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ComputeBuffer

Namespace: UnityEngine

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Data buffer to hold data for compute shaders.

ComputeShader programs often need arbitrary data to be read & written into memory buffers. ComputeBuffer class is exactly for that - you can create & fill them from script code, and use them in compute shaders or regular shaders.

Compute shaders need a fairly modern GPU and are only available when using DirectX 11 right now. On shader side, ComputeBuffers map to StructuredBuffer<T> and RWStructuredBuffer<T> in HLSL.

See Also: SystemInfo.supportsComputeShaders, ComputeShader class, Shader.SetGlobalBuffer, Material.SetBuffer, Compute Shaders.

Variables

count Number of elements in the buffer (Read Only).
stride Size of one element in the buffer (Read Only).

Constructors

ComputeBuffer Create a Compute Buffer.

Functions

GetData Read data values from the buffer into an array.
Release Release a Compute Buffer.
SetData Set the buffer with values from an array.

Static Functions

CopyCount Set buffer data.