MetalCompute 1.0
An API to make GPU compute calls easier
Loading...
Searching...
No Matches
MTLCompute::Buffer< T > Class Template Reference

#include <MTLComputeBuffer.hpp>

Public Member Functions

 Buffer (MTL::Device *gpu, size_t length, ResourceStorage storageMode)
 Constructor for the Buffer class.
 
 Buffer (const Buffer &other)
 Copy constructor for the Buffer class.
 
 Buffer ()
 Default constructor for the Buffer class.
 
 ~Buffer ()
 Destructor for the Buffer class.
 
T * contents ()
 Get the contents of the buffer.
 
operator[] (size_t index) const
 Overload the [] operator to get the value at an index.
 
T & operator[] (size_t index)
 Overload the [] operator to set the value at an index.
 
void operator= (std::vector< T > data)
 Overload the = operator to set buffer contents from a vector.
 
Buffer< T > & operator= (const Buffer &other)
 Overload the = operator to set buffer contents from another buffer.
 
std::vector< T > getData ()
 Get the data from the buffer as a vector.
 
MTL::Buffer * getBuffer ()
 Get the MTL::Buffer object.
 
MTL::Device * getGPU ()
 Get the GPU device.
 
bool getFreed ()
 Get whether the buffer has been freed.
 
MTLCompute::ResourceStorage getStorageMode ()
 Get the storage mode of the buffer.
 

Public Attributes

size_t length
 The length of the buffer.
 
size_t itemsize
 The size of each item in the buffer.
 

Private Member Functions

void swap (Buffer &buffer) noexcept
 

Private Attributes

MTL::Device * gpu
 The Metal device object.
 
MTL::Buffer * buffer
 The Metal buffer object.
 
bool freed = false
 Whether the buffer has been freed.
 
MTLCompute::ResourceStorage storageMode
 The storage mode of the buffer.
 

Constructor & Destructor Documentation

◆ Buffer() [1/3]

template<typename T >
MTLCompute::Buffer< T >::Buffer ( MTL::Device * gpu,
size_t length,
ResourceStorage storageMode )
inline

Constructor for the Buffer class.

Takes in the length of the buffer, the GPU device, and the storage mode and creates a new buffer

Parameters
lengthThe length of the buffer
gpuThe GPU device
storageModeThe storage mode of the buffer

◆ Buffer() [2/3]

template<typename T >
MTLCompute::Buffer< T >::Buffer ( const Buffer< T > & other)
inline

Copy constructor for the Buffer class.

Constructs a new buffer from an existing buffer

Parameters
otherThe buffer to copy

◆ Buffer() [3/3]

template<typename T >
MTLCompute::Buffer< T >::Buffer ( )
inline

Default constructor for the Buffer class.

Creates a new empty buffer object

◆ ~Buffer()

template<typename T >
MTLCompute::Buffer< T >::~Buffer ( )
inline

Destructor for the Buffer class.

Calls autorelease on the buffer object and sets the freed flag to true

Member Function Documentation

◆ contents()

template<typename T >
T * MTLCompute::Buffer< T >::contents ( )
inline

Get the contents of the buffer.

Returns
T* The contents of the buffer

◆ getBuffer()

template<typename T >
MTL::Buffer * MTLCompute::Buffer< T >::getBuffer ( )
inline

Get the MTL::Buffer object.

Returns
MTL::Buffer* The MTL::Buffer object

◆ getData()

template<typename T >
std::vector< T > MTLCompute::Buffer< T >::getData ( )
inline

Get the data from the buffer as a vector.

Returns
std::vector<T> The data from the buffer

◆ getFreed()

template<typename T >
bool MTLCompute::Buffer< T >::getFreed ( )
inline

Get whether the buffer has been freed.

Returns
bool Whether the buffer has been freed

◆ getGPU()

template<typename T >
MTL::Device * MTLCompute::Buffer< T >::getGPU ( )
inline

Get the GPU device.

Returns
MTL::Device* The GPU device

◆ getStorageMode()

template<typename T >
MTLCompute::ResourceStorage MTLCompute::Buffer< T >::getStorageMode ( )
inline

Get the storage mode of the buffer.

Returns
MTLCompute::ResourceStorage The storage mode of the buffer

◆ operator=() [1/2]

template<typename T >
Buffer< T > & MTLCompute::Buffer< T >::operator= ( const Buffer< T > & other)
inline

Overload the = operator to set buffer contents from another buffer.

Parameters
otherThe buffer to set the contents from

◆ operator=() [2/2]

template<typename T >
void MTLCompute::Buffer< T >::operator= ( std::vector< T > data)
inline

Overload the = operator to set buffer contents from a vector.

Parameters
dataThe data to set the buffer contents to

◆ operator[]() [1/2]

template<typename T >
T & MTLCompute::Buffer< T >::operator[] ( size_t index)
inline

Overload the [] operator to set the value at an index.

Parameters
indexThe index to set the value at
Returns
T The value to set at the index

◆ operator[]() [2/2]

template<typename T >
T MTLCompute::Buffer< T >::operator[] ( size_t index) const
inline

Overload the [] operator to get the value at an index.

Parameters
indexThe index to get the value from
Returns
T The value at the index

◆ swap()

template<typename T >
void MTLCompute::Buffer< T >::swap ( Buffer< T > & buffer)
inlineprivatenoexcept

Member Data Documentation

◆ buffer

template<typename T >
MTL::Buffer* MTLCompute::Buffer< T >::buffer
private

The Metal buffer object.

◆ freed

template<typename T >
bool MTLCompute::Buffer< T >::freed = false
private

Whether the buffer has been freed.

◆ gpu

template<typename T >
MTL::Device* MTLCompute::Buffer< T >::gpu
private

The Metal device object.

◆ itemsize

template<typename T >
size_t MTLCompute::Buffer< T >::itemsize

The size of each item in the buffer.

◆ length

template<typename T >
size_t MTLCompute::Buffer< T >::length

The length of the buffer.

◆ storageMode

template<typename T >
MTLCompute::ResourceStorage MTLCompute::Buffer< T >::storageMode
private

The storage mode of the buffer.


The documentation for this class was generated from the following file: