# Xui.GPU.Hardware.Metal

Assembly: **Xui.Runtime.MacOS** · [C# declarations](index.cs) · [Assembly overview](../index.md)

## Types

- [`class MacOSGpuDevice`](#api-b015ab8cecaa0457)

<a id="api-b015ab8cecaa0457"></a>

## `class MacOSGpuDevice`

Apple Metal hardware GPU device implementation. Provides hardware-accelerated shader compilation and rendering on macOS and iOS.

This backend uses the Metal framework for rendering and the Metal shader compiler for MSL shader compilation. Rendering is done off-screen to a texture that can be read back to CPU memory for display via the 2D canvas pipeline.

```csharp
public sealed partial class MacOSGpuDevice : IGpuResourceDevice
{
    public string BackendName { get; }
    public bool IsDisposed { get; }

    public MacOSGpuDevice();
    public IGpuVertexShader CompileVertexShader(string source, string entryPoint);
    public IGpuFragmentShader CompileFragmentShader(string source, string entryPoint);
    public IGpuRenderTarget CreateRenderTarget(int width, int height);
    public IGpuCommandList CreateCommandList();
    public void Dispose();
}
public sealed partial class MacOSGpuDevice
{
    public unsafe IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
    public unsafe IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
}
```

<a id="api-08f8c674a59698ff"></a>

### [`MacOSGpuDevice.MacOSGpuDevice()`](#api-08f8c674a59698ff)


```csharp
public MacOSGpuDevice();
```

Creates a new Metal GPU device using the system default device.

**Throws** `Thrown if no Metal device is available.`: Thrown if no Metal device is available.

<a id="api-efd12fa9bb812008"></a>

### [`string MacOSGpuDevice.BackendName`](#api-efd12fa9bb812008)


```csharp
public string BackendName { get; }
```

Gets the name of this GPU backend (e.g., &quot;D3D11&quot;, &quot;Metal&quot;).

<a id="api-86c661be89ebcc5d"></a>

### [`IGpuFragmentShader MacOSGpuDevice.CompileFragmentShader(string source, string entryPoint)`](#api-86c661be89ebcc5d)


```csharp
public IGpuFragmentShader CompileFragmentShader(string source, string entryPoint);
```

Compiles a fragment (pixel) shader from native shader source code.

- **`source`** — The shader source (HLSL for D3D11, MSL for Metal).

- **`entryPoint`** — The name of the entry point function.

**Returns:** A compiled fragment shader.

<a id="api-ee7b2c09f98b6cc8"></a>

### [`IGpuVertexShader MacOSGpuDevice.CompileVertexShader(string source, string entryPoint)`](#api-ee7b2c09f98b6cc8)


```csharp
public IGpuVertexShader CompileVertexShader(string source, string entryPoint);
```

Compiles a vertex shader from native shader source code.

- **`source`** — The shader source (HLSL for D3D11, MSL for Metal).

- **`entryPoint`** — The name of the entry point function.

**Returns:** A compiled vertex shader.

<a id="api-0a58201ba2913bdb"></a>

### [`IGpuCommandList MacOSGpuDevice.CreateCommandList()`](#api-0a58201ba2913bdb)


```csharp
public IGpuCommandList CreateCommandList();
```

Creates a command list for recording rendering commands.

<a id="api-f1de65b339a773bc"></a>

### [`IGpuRenderTarget MacOSGpuDevice.CreateRenderTarget(int width, int height)`](#api-f1de65b339a773bc)


```csharp
public IGpuRenderTarget CreateRenderTarget(int width, int height);
```

Creates a render target texture.

- **`width`** — Width in pixels.

- **`height`** — Height in pixels.

**Returns:** A render target that can be used with a command list.

<a id="api-ed7c062236617069"></a>

### [`IGpuTexture MacOSGpuDevice.CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels)`](#api-ed7c062236617069)


```csharp
public unsafe IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
```

Uploads premultiplied RGBA8 mip levels, largest first, with tightly packed rows.

<a id="api-e413c15d69b284cc"></a>

### [`IGpuVertexBuffer MacOSGpuDevice.CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride)`](#api-e413c15d69b284cc)


```csharp
public unsafe IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
```

Uploads immutable vertices once. The caller owns the returned buffer.

<a id="api-a973f6941aa0ae37"></a>

### [`void MacOSGpuDevice.Dispose()`](#api-a973f6941aa0ae37)


```csharp
public void Dispose();
```

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

<a id="api-43746671e6609e11"></a>

### [`bool MacOSGpuDevice.IsDisposed`](#api-43746671e6609e11)


```csharp
public bool IsDisposed { get; }
```

Gets whether this device has been disposed.

