<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4ComputeCommandEncoder/copy(sourceTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:destinationBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So25MTL4ComputeCommandEncoderP5MetalE4copy13sourceTexture0G5Slice0G5Level0G6Origin0G4Size17destinationBuffer0M6Offset0M11BytesPerRow0mpQ5Image7optionsySo10MTLTexture_p_S2iSo9MTLOriginaSo7MTLSizeaSo9MTLBuffer_pS3iSo13MTLBlitOptionVtF"
  },
  "title" : "copy(sourceTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:destinationBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:)"
}
-->

# copy(sourceTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:destinationBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:)

Encodes a command that copies image data from a slice of a texture instance to a buffer, with
options for special texture formats.

```
func copy(sourceTexture: any MTLTexture, sourceSlice: Int, sourceLevel: Int, sourceOrigin: MTLOrigin, sourceSize: MTLSize, destinationBuffer: any MTLBuffer, destinationOffset: Int, destinationBytesPerRow: Int, destinationBytesPerImage: Int, options: MTLBlitOption = [])
```

## Parameters

`sourceTexture`

An [`MTLTexture`](/documentation/Metal/MTLTexture) texture that the command copies data from. To read the source
texture contents, you need to set its [`isFramebufferOnly`](/documentation/Metal/MTLTexture/isFramebufferOnly) property
to <doc://com.apple.documentation/documentation/Swift/false> prior to drawing into it.

`sourceSlice`

A slice within `sourceTexture` the command uses as a starting point to copy
data from. Set this to `0` if `sourceTexture` isn’t a texture array or a
cube texture.

`sourceLevel`

A mipmap level within `sourceTexture`.

`sourceOrigin`

An [`MTLOrigin`](/documentation/Metal/MTLOrigin) instance that represents a location within `sourceTexture`
that the command begins copying data from. Assign `0` to each dimension
that’s not relevant to `sourceTexture`.

`sourceSize`

An [`MTLSize`](/documentation/Metal/MTLSize) instance that represents the size of the region, in pixels,
that the command copies from `sourceTexture`, starting at `sourceOrigin`.
Assign `1` to each dimension that’s not relevant to `sourceTexture`.
If `sourceTexture` uses a compressed pixel format, set `sourceSize` to a
multiple of the `sourceTexture's` [`pixelFormat`](/documentation/Metal/MTLTexture/pixelFormat) block size.
If the block extends outside the bounds of the texture, clamp `sourceSize`
to the edge of the texture.

`destinationBuffer`

An [`MTLBuffer`](/documentation/Metal/MTLBuffer) instance the command copies data to.

`destinationOffset`

A byte offset within `destinationBuffer` the command copies to. The value
you provide as this argument needs to be a multiple of `sourceTexture's` pixel size,
in bytes.

`destinationBytesPerRow`

The number of bytes between adjacent rows of pixels in `destinationBuffer`.
This value must be a multiple of `sourceTexture's` pixel size, in bytes,
and less than or equal to the product of `sourceTexture's` pixel size,
in bytes, and the largest pixel width `sourceTexture’s` type allows. If
`sourceTexture` uses a compressed pixel format, set `destinationBytesPerRow`
to the number of bytes between the starts of two row blocks.

`destinationBytesPerImage`

The number of bytes between each 2D image of a 3D texture. This value must
be a multiple of `sourceTexture's` pixel size, in bytes. Set this value to
`0` if `sourceSize's` [`depth`](/documentation/Metal/MTLSize/depth) value is `1`.

`options`

A [`MTLBlitOption`](/documentation/Metal/MTLBlitOption) value that applies to textures with applicable pixel
formats, such as combined depth/stencil or PVRTC formats. If `sourceTexture's`
[`pixelFormat`](/documentation/Metal/MTLTexture/pixelFormat) is a combined depth/stencil format, set `options`
to either [`depthFromDepthStencil`](/documentation/Metal/MTLBlitOption/depthFromDepthStencil) or
[`stencilFromDepthStencil`](/documentation/Metal/MTLBlitOption/stencilFromDepthStencil), but not both.
If `sourceTexture's` [`pixelFormat`](/documentation/Metal/MTLTexture/pixelFormat) is a PVRTC format, set
`options` to [`rowLinearPVRTC`](/documentation/Metal/MTLBlitOption/rowLinearPVRTC).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)