Specify which mipmaps are affected by the data transfer.
When you copy data between resources, and the source or destination is a texture, you need to specify which mipmaps are affected.
Copy Data from System Memory to a Mipmap
When you copy data from system memory into a texture, state which mipmap is the destination of that copy, as shown in the code below:
Call this routine once for each mipmap you want to fill, changing the region to match the size of the mipmap level you are writing to.
Copy Mipmap Data Between Metal Resources
If you already have data in Metal resources, use a
MTLBlit to copy data to and from different mipmaps in a texture.
To copy all matching data between two textures, encode a command using the
copy(from:: method. The two textures must have the same pixel format and type. All matching mipmap sizes are copied to the destination texture.
To copy a selection of mipmaps from one texture to another, use the
copy(from: method. Specify the first source mipmap level and first destination mipmap level, both of which must have the same dimensions. Also specify the number of mipmap levels you want to copy.
For example, the following code is written with the assumption that the destination texture is twice as large in both dimensions as the source texture. Mipmap
1 in the destination matches the size of the source mipmap
0, so the code specifies a source level of
0 and a destination level of
1. The level count specifies that
5 mipmaps should be copied.
If you need to copy data between buffers and textures, encode a separate blit command for each mipmap level to copy. See
MTLBlit for other methods that copy data to and from textures.