I'm trying to pass a buffer of float2 items from CPU to GPU.
In the kernel, I can provide a parameter for the buffer:
device const float2* values
for example.
How do I specify float2 as the type for the MTL::Buffer?
I managed to get the code to work by "cheating" by defining a simple class that has the same data members as a float2, but there is probably a better way.
class Coord_f { public: float x{0.0f}; float y{0.0f}; };
then using code to allocate like this:
NS::TransferPtr(device->newBuffer(n_elements * sizeof(Coord_f), MTL::ResourceStorageModeManaged))
The headers for metal-cpp do not appear to define vector objects like float2, but I'm doubtless missing something.
Thanks.
Thanks for your help Ceylo; that definitely got me on the right track. In case this helps someone else, here are some additional notes.
It turns out that, for C++, the simd_prefix
is not required. Instead simply specify the namespace simd::
So in the .cpp file use simd::float2,
and use plain float2
in the .metal file.
As Ceylo indicated, #include <simd/simd.h>
in the .cpp file.