DTolm / VkFFT

Vulkan/CUDA/HIP/OpenCL/Level Zero/Metal Fast Fourier Transform library
MIT License
1.48k stars 88 forks source link

[Question] How to pass a `id<MTLCommandQueue>` as a `MTL::CommandQueue` of Metal-Cpp? #131

Closed AtomicVar closed 10 months ago

AtomicVar commented 10 months ago

The situation: I'm developing an iOS Metal App in Objective-C. I'm using VkFFT which provides Metal FFTs based on Metal-Cpp.

What I need: pass a id<MTLCommandQueue> instance from Objective-C world to C++ world as a MTL::CommandQueue object so that I can push compute commands to it. I don't want to create a seperate commmand queue in Metal-Cpp because using a single command queue can let me keep pushing all commands to it without waitUntilCompleted.

After searching the web, I didn't find out how to do that. And Metal-Cpp doesn't have Issues opened so I can only ask here.

DTolm commented 10 months ago

Hello,

I have no experience in how Objective-C - C++ interoperability works, but shouldn't there be some casting available? Maybe @philipturner can help with that question?

Maybe this comment can be useful: https://github.com/DTolm/VkFFT/issues/91#issuecomment-1695524007

Best regards, Dmitrii

philipturner commented 10 months ago

There should be a way to call (__bridge void*) and then cast the result to MTL::Device*. It is used extensively in the Objective-C to metal-cpp interconversion in CCV.

https://github.com/liuliu/ccv/blob/f8332c6ba592e49ee9b83fcec821366ed2aac051/lib/nnc/mps/ccv_nnc_mps.m#L38

(mtl_device_t* is an alias of void*)

AtomicVar commented 10 months ago

@philipturner Awesome! That solved my problem, thank you a lot ❤️