Version: 2019.4
LanguageEnglish
  • C#

ComputeBuffer

class in UnityEngine

/

Implemented in:UnityEngine.CoreModule

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

Submission failed

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

Close

Cancel

Description

GPU data buffer, mostly for use with 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 buffers are always supported in compute shaders. Compute shader support can be queried runtime using SystemInfo.supportsComputeShaders. See the Compute Shaders Manual page for more information about platforms supporting compute shaders. In regular graphics shaders the compute buffer support requires minimum shader model 4.5.

For a ComputeBuffer that uses a counter, Metal and Vulkan platforms don't have native counters and use separate small buffers that act as counters internally. These small buffers are bound separately from the ComputeBuffer and count towards the limit of possible buffers bound (31 for Metal, based on the device for Vulkan).

On the shader side, ComputeBuffers with default ComputeBufferType map to StructuredBuffer<T> and RWStructuredBuffer<T> in HLSL.

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

Properties

countNumber of elements in the buffer (Read Only).
nameThe debug label for the ComputeBuffer. This name shows up in profiling and frame debugger tools, wherever supported.
strideSize of one element in the buffer (Read Only).

Constructors

ComputeBufferCreate a Compute Buffer.

Public Methods

GetDataRead data values from the buffer into an array. The array can only use blittable types.
GetNativeBufferPtrRetrieve a native (underlying graphics API) pointer to the buffer.
IsValidReturns true if this compute buffer is valid and false otherwise.
ReleaseRelease a Compute Buffer.
SetCounterValueSets counter value of append/consume buffer.
SetDataSet the buffer with values from an array.

Static Methods

CopyCountCopy counter value of append/consume buffer into another buffer.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961