gpt4 book ai didi

c++ - 如何将 Metal-Cpp 的 `id` 转换为 `MTL::CommandQueue`?

转载 作者:行者123 更新时间:2023-12-03 07:51:30 29 4
gpt4 key购买 nike

情况:我正在使用Objective-C开发iOS Metal应用程序。我需要使用第三方库VkFFT提供基于 Metal-Cpp 的 Metal FFT .

我需要什么:传递 id<MTLCommandQueue>从 Objective-C 世界到 C++ 世界的实例为 MTL::CommandQueue对象,以便我可以将计算命令推送给它。 我不想在 Metal-Cpp 中创建单独的命令队列,因为使用单个命令队列可以让我继续将所有命令推送到它,而无需 waitUntilCompleted .

最佳答案

Bridged casts

A bridged cast is a C-style cast annotated with one of three keywords:

  • (__bridge T) op casts the operand to the destination type T. If T is aretainable object pointer type, then op must have a non-retainablepointer type. If T is a non-retainable pointer type, then op must havea retainable object pointer type. Otherwise the cast is ill-formed.There is no transfer of ownership, and ARC inserts no retainoperations.
  • (__bridge_retained T) op casts the operand, which musthave retainable object pointer type, to the destination type, whichmust be a non-retainable pointer type. ARC retains the value, subjectto the usual optimizations on local values, and the recipient isresponsible for balancing that +1.
  • (__bridge_transfer T) op casts theoperand, which must have non-retainable pointer type, to thedestination type, which must be a retainable object pointer type. ARCwill release the value at the end of the enclosing full-expression,subject to the usual optimizations on local values. These casts arerequired in order to transfer objects in and out of ARC control; seethe rationale in the section on conversion of retainable objectpointers.

Using a __bridge_retained or __bridge_transfer cast purely to convince ARC > to emit an unbalanced retain or release, respectively, is poor form.

id<MTLCommandQueue> objcQueue = /* Your Objective-c queue */;
MTL::CommandQueue* queue = (__bridge MTL::CommandQueue*)objcQueue;

关于c++ - 如何将 Metal-Cpp 的 `id<MTLCommandQueue>` 转换为 `MTL::CommandQueue`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76989609/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com