Instance Method


Creates a texture that shares its storage with the buffer.



- (id<MTLTexture>)newTextureWithDescriptor:(MTLTextureDescriptor *)descriptor offset:(NSUInteger)offset bytesPerRow:(NSUInteger)bytesPerRow;



The descriptor that contains the properties of the texture.


The offset, in bytes, from the base address for the first row of texture data.


The stride, in bytes, from one row of texture data to the next.

Return Value

A texture that shares its storage with this buffer.


This method creates a new MTLTexture object whose texture data is the same as the buffer data in the MTLBuffer object. The texture shares the same memory storage as the originating buffer, so modifying the buffer data also modifies the texture data.

Data Access and Coherence

The resource data is coherent between multiple render passes. However, data access within a single render pass may not be coherent due to possible data caching at execution time. For example, in a graphics or compute function, data written to the buffer may not be immediately available in a subsequent texture read.

On macOS, if the resource data has been modified by the graphics processing unit (GPU), you must call the synchronizeResource: method to update the data before a subsequent CPU access. CPU access is only coherent between command buffer boundaries. GPU barriers can guard GPU access to buffers and textures, so any earlier access is always executed before a later access.

Multiple nonoverlapping textures can be created from the same buffer. However, references to any of these textures are serialized. If you want to avoid this serialization, first create multiple buffers and then create an individual texture from each buffer.

Linear Texture Restrictions

The offset and bytesPerRow parameters must be byte aligned to the size returned by the minimumLinearTextureAlignmentForPixelFormat: method. The bytesPerRow parameter must also be greater than or equal to the size of one pixel, in bytes, multiplied by the pixel width of one row.

The descriptor parameter has the following restrictions on its properties:

See Also