cmt icon indicating copy to clipboard operation
cmt copied to clipboard

New Metal API Bindings

Open recp opened this issue 4 years ago • 6 comments

recp avatar Oct 26 '21 16:10 recp

ideally we should find a way to parse apple docs/headers from the frameworks and autogenerate cmt bindings...

PhilipVinc avatar Oct 26 '21 16:10 PhilipVinc

@PhilipVinc that could be nice, documentations also could be auto-imported maybe in this way

recp avatar Oct 26 '21 16:10 recp

Can you give an example how to properly use this library? I can't seem to get it working especially when I have to get the Drawable

Lu-TheCoder avatar Sep 30 '23 01:09 Lu-TheCoder

Hi @Lu-TheCoder

cmt does need some updates to fully support all functionalities of Metal. However, I haven’t had the time to work on it recently.

Apple has released Metal for C++ ( https://developer.apple.com/metal/cpp/) which might be a suitable alternative if using C isn't a strict requirement for your project.

Example project[s] would be nice, but unfortunately, I can’t promise to provide any in the near future due to my current time constraints. I hope to revisit this later when I have more availability.


Currently, my primary focus has shifted to libgpu ( https://github.com/recp/gpu ), which aims to provide a unified API on top of Metal, DirectX12, Vulkan, etc., and the Universal Shading Language ( https://github.com/UniversalShading/spec ) which aims to provide a single shading language that can be used with/without libgpu.

Thanks

recp avatar Oct 02 '23 20:10 recp

Thank you for the response...

I totally understand and yes I am aware of the Metal-CPP alternative and I was hoping for a C only solution as I'm strictly developing an engine in C... I have also began building on top of your C-Bindings and the issue I'm faced with is Memory management I can't seem to get rid of memory leaks once the Objective-c objects are passed onto C it becomes a challenge to manage that memory since ARC doesn't work in C nor do the autorelease pools truly natively work without including Objective-c headers...

Lu-TheCoder avatar Oct 02 '23 21:10 Lu-TheCoder

MT_EXPORT
void*
mtRetain(void *obj);

MT_EXPORT
void
mtRelease(void *obj);

These could help to manage memory manually, enabling ARC when building cmt could be an option to let ObjC objects do retain/release automatically. In this case pointers in C may become invalid if ARC objects are released in somewhere... you should be careful...

In cmt, new/create functions are marked as CF_RETURNS_RETAINED which is a hint for ARC also manual memory management, actually if function name contains Create, New, Alloc, Copy clang assumes the returned memory is retained (IIRC), in cmt these functions [should] return retained result.

If there are still memory leaks, Xcode Instruments could help to catch them more quickly. If there are any bugs in cmt which cause mem leaks, then it would be nice to fix them asap.

--

FWIW, https://github.com/recp/gpu is written in C and similar to Metal but there is no ETA for now.

recp avatar Oct 03 '23 08:10 recp