2017-10-11 31 views
1

Objective-C このメソッドを使用して、コマンドバッファをインプレースでエンコードしようとしました。MPSCopyAllocatorが初期化できません

-(BOOL) encodeToCommandBuffer: (nonnull id <MTLCommandBuffer>)commandBuffer 
        inPlaceTexture: (__nonnull id <MTLTexture> __strong * __nonnull) texture 
      fallbackCopyAllocator: (nullable MPSCopyAllocator) copyAllocator 
       MPS_SWIFT_NAME(encode(commandBuffer:inPlaceTexture:fallbackCopyAllocator:)); 

私は新しいMPSCopyAllocatorを作成したいと思います。

私はドキュメントから次のコードを使用しました。

MPSCopyAllocator myAllocator = ^id <MTLTexture> _Nonnull (MPSKernel * __nonnull filter, __nonnull id <MTLCommandBuffer> cmdBuf, __nonnull id <MTLTexture> sourceTexture) 
{ 
    MTLPixelFormat format = sourceTexture.pixelFormat; 
    MTLTextureDescriptor *d = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: format width: sourceTexture.width height: sourceTexture.height mipmapped: NO]; 

    id <MTLTexture> result = [cmdBuf.device newTextureWithDescriptor: d]; 

    return result; 
    / 
}; 

しかし、私は

問題ナビゲータで

Incompatible block pointer types initializing '__strong MPSCopyAllocator' (aka 'id<MTLTexture> _Nonnull (^__strong)(MPSKernel * _Nonnull __strong, id<MTLCommandBuffer> _Nonnull __strong, id<MTLTexture> _Nonnull __strong)') with an expression of type 'id<MTLTexture> _Nonnull (^)(MPSKernel * _Nonnull __strong, id<MTLCommandBuffer> _Nonnull __strong, id<MTLTexture> _Nonnull __strong)' 
をセマンティック問題を得たMPSCopyAllocatorが

typedef id <MTLTexture> __nonnull NS_RETURNS_RETAINED (^MPSCopyAllocator)(MPSKernel * __nonnull filter, 
                      id <MTLCommandBuffer> __nonnull commandBuffer, 
                      id <MTLTexture> __nonnull sourceTexture); 

を定義MPSCopyAllocatorを作成するための正しい方法は何ですか?それを変数に割り当てるとき

答えて

2

残念ながら、あなたはブロック定義でNS_RETURNS_RETAINEDを含める必要があります:彼らはオプションだと簡潔さのために

MPSCopyAllocator allocator = ^id <MTLTexture> NS_RETURNS_RETAINED(MPSKernel *filter, 
                    id <MTLCommandBuffer> commandBuffer, 
                    id <MTLTexture> sourceTexture) 
{ 
    // ... 
}; 

を、私は、ここではNULL可能注釈を省略しました。

+0

ありがとう、それは動作します! –

関連する問題