---
title: "slice(unsafeBuffer:offset:size:bytesPerRow:)"
framework: realitykit
role: symbol
role_heading: Type Method
path: "realitykit/textureresource/contents/slice/slice(unsafebuffer:offset:size:bytesperrow:)"
---

# slice(unsafeBuffer:offset:size:bytesPerRow:)

Specifies a single mipmap level slice of a texture resource with pixel data that RealityKit copies from a Metal buffer.

## Declaration

```swift
static func slice(unsafeBuffer buffer: any MTLBuffer, offset: Int = 0, size: Int, bytesPerRow: Int) -> TextureResource.Contents.Slice
```

## Parameters

- `buffer`: The source buffer. Don’t modify this buffer while using it as the source of a copy operation.
- `offset`: The byte position in the source buffer where the copying starts. The offset needs to be a multiple of the destination texture’s pixel size, in bytes.
- `size`: The number of bytes in the source buffer (starting from offset) available for copying.
- `bytesPerRow`: The stride in bytes between rows of texture data that RealityKit stores in the source buffer. The value needs to be a multiple of the destination texture’s pixel size, in bytes.

## Discussion

Discussion important: A TextureResource.Contents.Slice that you create with this function and use to create a TextureResource copies from the source buffer. That copy occurs when initializing the texture resource. The caller is responsible for ensuring that the system doesn’t modify the source Metal buffer while copying it to a texture.

## See Also

### Creating a texture slice

- [slice(data:bytesPerRow:)](realitykit/textureresource/contents/slice/slice(data:bytesperrow:).md)
