2017-10-11 5 views
1

En Objective-C j'essaie d'utiliser cette méthode pour encoder commandbuffer sur place.MPSCopyAllocator ne peut pas initialiser

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

et je voudrais créer un nouveau MPSCopyAllocator.

J'ai utilisé le code suivant du document.

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; 
    / 
}; 

mais je suis un problème sémantique dans le numéro de navigateur

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)' 

la MPSCopyAllocator définir

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

ce qui est la bonne façon de créer un MPSCopyAllocator?

Répondre

2

Malheureusement, vous devez inclure NS_RETURNS_RETAINED dans votre définition de bloc lors de l'affectation à une variable:

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

Pour laconisme, j'ai omis les annotations ici-nullité, car ils sont en option.

+0

merci beaucoup, ça marche! –