<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShaders",
  "identifier" : "/documentation/MetalPerformanceShaders/MPSMatrix/init(buffer:descriptor:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Metal Performance Shaders"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSMatrix(im)initWithBuffer:descriptor:"
  },
  "title" : "init(buffer:descriptor:)"
}
-->

# init(buffer:descriptor:)

Initializes a matrix with a buffer.

```
init(buffer: any MTLBuffer, descriptor: MPSMatrixDescriptor)
```

## Parameters

`buffer`

The buffer that stores the matrix data.

`descriptor`

The matrix descriptor.

## Return Value

A valid [`MPSMatrix`](/documentation/MetalPerformanceShaders/MPSMatrix) object or `nil`, if failure.

## Discussion

The dimensions and stride of the matrix are specified by the [`MPSMatrixDescriptor`](/documentation/MetalPerformanceShaders/MPSMatrixDescriptor) object. The size of the provided <doc://com.apple.documentation/documentation/Metal/MTLBuffer> object must be large enough to store the following amount of bytes:

`(descriptor.rows-1) * descriptor.rowBytes + descriptor.columns * (element size)`

---

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)