Class ExchangeBuffer
This class encapsulate the resident on GPU memory and provide functionality to manage it.
Namespace: Mechatronics.SystemGraph
Syntax
public abstract class ExchangeBuffer
Fields
_GPUData
Compute buffer reference used to contain the same data as the CPU buffer, but on the GPU memory.
Declaration
protected ComputeBuffer _GPUData
Field Value
Type | Description |
---|---|
ComputeBuffer |
_isDirty
Indicate if any changes made to the CPU buffer needs to be uploaded on the GPU.
Declaration
protected bool _isDirty
Field Value
Type | Description |
---|---|
Boolean |
isGPUOnly
Use to know if we need to keep a copy in the CPU memory when transferring data back to it.
Declaration
protected bool isGPUOnly
Field Value
Type | Description |
---|---|
Boolean |
Properties
Capacity
Return the number of elements that can be contained in the internal buffer.
Declaration
public int Capacity { get; }
Property Value
Type | Description |
---|---|
Int32 |
Count
The number of element in the buffers
Declaration
public int Count { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
GPUData
Get the data copy on the GPU. If dirty or not uploaded yet, the data is automatically uploaded. For performance reason, the user should consider uploading it, using UploadOnGPU(), in an Update() callback from unity before using it.
Declaration
public ComputeBuffer GPUData { get; }
Property Value
Type | Description |
---|---|
ComputeBuffer |
Stride
The size of an element in bytes.
Declaration
public int Stride { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
Allocate(Int32, Boolean)
Allocate a compute buffer with the provided size. It also deletes the buffer if not null. The buffer will be created on the GPU and also in CPU memory if gpuOnly = false.
Declaration
public void Allocate(int elementCountMax, bool gpuOnly)
Parameters
Type | Name | Description |
---|---|---|
Int32 | elementCountMax | Number of elements the buffer must contain. |
Boolean | gpuOnly | If the buffer will be used for gpu processing only, one can set this to true to save memory. |
InternalAllocate(Int32)
Used to allocate an element buffer on CPU side to contain the data.
Declaration
protected abstract void InternalAllocate(int elementCountMax)
Parameters
Type | Name | Description |
---|---|---|
Int32 | elementCountMax | Number of elements the buffer must contain. |
InternalGetElementStride()
Retrieves the size of an element in bytes.
Declaration
protected abstract int InternalGetElementStride()
Returns
Type | Description |
---|---|
Int32 | Number of bytes corresponding to the size of the element. |
InternalRelease()
Used to deallocate CPU-side buffer.
Declaration
protected abstract void InternalRelease()
InternalUpdateBuffer()
Used to upload child structured data on the GPU.
Declaration
protected abstract void InternalUpdateBuffer()
Release()
Release the GPU and CPU resources if created.
Declaration
public void Release()
UploadOnGPU()
Used to make sure the data is ready to be used by the GPU.
Declaration
public void UploadOnGPU()