Initializes an image from a texture. The user-allocated texture has been created for a specific number of feature channels and number of images.
SDKs
- iOS 10.0+
- macOS 10.13+
- Mac Catalyst 13.0+
- tvOS 10.0+
Framework
- Metal Performance Shaders
Declaration
- (instancetype)initWithTexture:(id<MTLTexture>)texture featureChannels:(NSUInteger)featureChannels;
Parameters
texture
The texture allocated by the user to be used as a backing storage for the image.
featureChannels
The number of feature channels the texture contains.
Return Value
A valid MPSImage
object or nil
, if failure.
Discussion
In a memory-intensive app, you can save memory (and allocation/deallocation time) by using an MPSTemporary
object, where the framework aggressively reuses underlying texture memory within the same command buffer. However, in certain cases, you may want more control on the allocation, placement, reuse, and recycling of memory-backing textures used in your app by using the Metal Resource Heaps API. In this case, an app can create an MPSImage
object from a pre-allocated texture by calling this method.
The texture
property of the given texture can be of type MTLTexture
only if feature
(meaning that number
). Otherwise, the texture type should be MTLTexture
with the array
property of the given texture being equal to number
.
For textures containing typical image data, the feature
parameter should be set to the number of valid color channels (e.g. for RGB data, even though the pixel format is a form of MTLPixel
, feature
should be set to 3.).