Class MPSKernel

  • All Implemented Interfaces:
    NSCoding, NSCopying, NSSecureCoding, NSObject
    Direct Known Subclasses:
    MPSAccelerationStructure, MPSBinaryImageKernel, MPSCNNBinaryKernel, MPSCNNKernel, MPSCNNMultiaryKernel, MPSImageCopyToMatrix, MPSImageEDLines, MPSImageFindKeypoints, MPSImageGuidedFilter, MPSImageHistogram, MPSImageNormalizedHistogram, MPSMatrixBinaryKernel, MPSMatrixCopy, MPSMatrixCopyToImage, MPSMatrixMultiplication, MPSMatrixRandom, MPSMatrixSum, MPSMatrixUnaryKernel, MPSNDArrayMultiaryBase, MPSNNGraph, MPSNNOptimizer, MPSRayIntersector, MPSRNNMatrixInferenceLayer, MPSRNNMatrixTrainingLayer, MPSSVGF, MPSTemporalAA, MPSUnaryImageKernel

    public class MPSKernel
    extends NSObject
    implements NSCopying, NSSecureCoding
    MPSKernel [@dependency] This depends on Metal.framework The MPSKernel class is the base class for all MPS objects. It defines a standard interface for MPS kernels. You should not use the MPSKernel class directly. Instead, a number of MPSKernel subclasses are available in MetalPerformanceShaders.framework that define specific high-performance image processing operations. The basic sequence for applying a MPSKernel to an image is as follows: 1. Create a MPSKernel corresponding to the operation you wish to perform: [@code] MPSImageSobel *sobel = [[MPSImageSobel alloc] initWithDevice: mtlDevice]; [@endcode] 2. Encode the filter into a command buffer: [@code] sobel.offset = ...; sobel.clipRect = ...; sobel.options = ...; [sobel encodeToCommandBuffer: commandBuffer sourceTexture: inputImage destinationTexture: resultImage ]; [@endcode] Encoding the kernel merely encodes the operation into a MTLCommandBuffer. It does not modify any pixels, yet. All MPSKernel state has been copied to the command buffer. MPSKernels may be reused. If the texture was previously operated on by another command encoder (e.g. MTLRenderCommandEncoder), you should call -endEncoding on the other encoder before encoding the filter. Some MPS filters work in place (inputImage = resultImage) even in situations where Metal might not normally allow in place operation on textures. If in-place operation is desired, you may attempt to call [MPSKernel encodeKernelInPlace...]. If the operation can not be completed in place, then NO will be returned and you will have to create a new result texture and try again. To make an in-place image filter reliable, pass a fallback MPSCopyAllocator to the method to create a new texture to write to in the event that a filter can not operate in place. (Repeat steps 2 for more filters, as desired.) It should be self evident that step 2 may not be thread safe. That is, you can not have multiple threads manipulating the same properties on the same MPSKernel object at the same time and achieve coherent output. In common usage, the MPSKernel properties don't often need to be changed from their default values, but if you need to apply the same filter to multiple images on multiple threads with cropping / tiling, make additional MPSKernel objects per thread. They are cheap. You can use multiple MPSKernel objects on multiple threads, as long as only one thread is operating on any particular MPSKernel object at a time. 3. After encoding any additional work to the command buffer using other encoders, submit the MTLCommandBuffer to your MTLCommandQueue, using: [@code] [mtlCommandBuffer commit]; [@endcode] A MPSKernel can be saved to disk / network using NSCoders such as NSKeyedArchiver. When decoding, the system default MTLDevice will be chosen unless the NSCoder adopts the protocol. To accomplish this, subclass or extend your unarchiver to add this method.
    • Constructor Detail

      • MPSKernel

        protected MPSKernel​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • copyWithZone

        public java.lang.Object copyWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
        Specified by:
        copyWithZone in interface NSCopying
      • copyWithZoneDevice

        public java.lang.Object copyWithZoneDevice​(org.moe.natj.general.ptr.VoidPtr zone,
                                                   MTLDevice device)
        Make a copy of this MPSKernel for a new device -copyWithZone: will call this API to make a copy of the MPSKernel on the same device. This interface may also be called directly to make a copy of the MPSKernel on a new device. Typically, the same MPSKernels should not be used to encode kernels on multiple command buffers from multiple threads. Many MPSKernels have mutable properties that might be changed by the other thread while this one is trying to encode. If you need to use a MPSKernel from multiple threads make a copy of it for each additional thread using -copyWithZone: or -copyWithZone:device:
        Parameters:
        zone - The NSZone in which to allocate the object
        device - The device for the new MPSKernel. If nil, then use self.device.
        Returns:
        a pointer to a copy of this MPSKernel. This will fail, returning nil if the device is not supported. Devices must be MTLFeatureSet_iOS_GPUFamily2_v1 or later.
      • device

        public MTLDevice device()
        [@property] device The device on which the kernel will be used
      • initWithDevice

        public MPSKernel initWithDevice​(java.lang.Object device)
        Standard init with default properties per filter type
        Parameters:
        device - The device that the filter will be used on. May not be NULL.
        Returns:
        a pointer to the newly initialized object. This will fail, returning nil if the device is not supported. Devices must be MTLFeatureSet_iOS_GPUFamily2_v1 or later.
      • label

        public java.lang.String label()
        [@property] label A string to help identify this object.
      • options

        public long options()
        [@property] options The set of options used to run the kernel. [@ref] subsubsection_options
      • setLabel

        public void setLabel​(java.lang.String value)
        [@property] label A string to help identify this object.
      • setOptions

        public void setOptions​(long value)
        [@property] options The set of options used to run the kernel. [@ref] subsubsection_options
      • initWithCoderDevice

        public MPSKernel initWithCoderDevice​(NSCoder aDecoder,
                                             java.lang.Object device)
        NSSecureCoding compatability While the standard NSSecureCoding/NSCoding method -initWithCoder: should work, since the file can't know which device your data is allocated on, we have to guess and may guess incorrectly. To avoid that problem, use initWithCoder:device instead.
        Parameters:
        aDecoder - The NSCoder subclass with your serialized MPSKernel
        device - The MTLDevice on which to make the MPSKernel
        Returns:
        A new MPSKernel object, or nil if failure.
      • supportsSecureCoding

        public static boolean supportsSecureCoding()
      • _supportsSecureCoding

        public boolean _supportsSecureCoding()
        Description copied from interface: NSSecureCoding
        This property must return YES on all classes that allow secure coding. Subclasses of classes that adopt NSSecureCoding and override initWithCoder: must also override this method and return YES. The Secure Coding Guide should be consulted when writing methods that decode data.
        Specified by:
        _supportsSecureCoding in interface NSSecureCoding