The number of times a temporary image may be read by a CNN kernel before its contents become undefined.
- iOS 10.0+
- macOS 10.13+
- Mac Catalyst 13.0+
- tvOS 10.0+
- Metal Performance Shaders
Temporary images must release their underlying textures for reuse immediately after last use. In order to facilitate prompt and convenient memory recycling, each time a
MPSTemporary object is read by an
encode method of an MPSCNNKernel object, the value of its
read property is automatically decremented. When the value of
read reaches 0, the underlying texture is automatically made available and reusable to the framework for its own needs (and for other
MPSTemporary objects prior to return from the
encode method). The contents of the underlying texture become undefined at this time.
By default, the value of
read is initialized to 1, indicating a temporary image that may be overwritten any number of times, but read only once.
You may change the value of
read as desired to allow MPSCNNKernel objects to read the
MPSTemporary object additional times. However, it is an error to change the value of
read once it reaches 0 (it is also an error to read or write to a temporary image with a
read value of 0). You may set the value of
read to 0 yourself to cause the underlying texture to be returned to the framework. Writing to a temporary image does not adjust the value of
The Metal API Validation layer will assert if a temporary image is deallocated with a non-zero
read value to help identify cases when resources are not returned promptly.