# Xui.GPU.Hardware

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

## Types

- [`enum GpuCullMode`](#api-992a6fb58e36a40f)
- [`class GpuPipelineDesc`](#api-e24c835fbd70b781)
- [`class GpuTextureValidation`](#api-ddbc69dc9ab9b6b4)
- [`class GpuVertexBufferDesc`](#api-80142e2a7a067881)
- [`interface IGpuCommandList`](#api-f69bdb61b977d198)
- [`interface IGpuDevice`](#api-0cb886cdcee628e4)
- [`interface IGpuFragmentShader`](#api-4397c7c9f80356c0)
- [`interface IGpuRenderTarget`](#api-78cf4033bab286be)
- [`interface IGpuResourceCommandList`](#api-81f25577e1b767bb)
- [`interface IGpuResourceDevice`](#api-cbdcf1b4123afe03)
- [`interface IGpuShader`](#api-cf2c9bb4eab5e8ab)
- [`interface IGpuTexture`](#api-38608fc05bb88a69)
- [`interface IGpuVertexBuffer`](#api-79191fc55f93ca2d)
- [`interface IGpuVertexShader`](#api-8583f7306283e7b4)

<a id="api-992a6fb58e36a40f"></a>

## `enum GpuCullMode`

Specifies which triangle faces to cull during rasterization.

```csharp
public enum GpuCullMode
{
    None = 0,
    Back = 1,
    Front = 2,
}
```

<a id="api-6bb3d1ceddb3dafe"></a>

### [`GpuCullMode.Back`](#api-6bb3d1ceddb3dafe)


```csharp
Back = 1
```

Back-facing triangles are culled (default).

<a id="api-fbd2f04d9cd52eb5"></a>

### [`GpuCullMode.Front`](#api-fbd2f04d9cd52eb5)


```csharp
Front = 2
```

Front-facing triangles are culled.

<a id="api-0d2511d8487a9ce8"></a>

### [`GpuCullMode.None`](#api-0d2511d8487a9ce8)


```csharp
None = 0
```

No culling — all triangles are rendered.


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

## `class GpuPipelineDesc`

Describes a hardware GPU render pipeline, binding shaders and state together.

```csharp
public sealed class GpuPipelineDesc
{
    public bool PremultipliedAlpha { get; set; }
    public int[]? VertexComponents { get; set; }
    public IGpuVertexShader? VertexShader { get; set; }
    public IGpuFragmentShader? FragmentShader { get; set; }
    public bool DepthTestEnabled { get; set; }
    public bool DepthWriteEnabled { get; set; }
    public GpuCullMode CullMode { get; set; }
}
```

<a id="api-2f64f977fbae1553"></a>

### [`GpuCullMode GpuPipelineDesc.CullMode`](#api-2f64f977fbae1553)


```csharp
public GpuCullMode CullMode { get; set; }
```

Gets or sets the triangle cull mode.

<a id="api-8672431f39c385ce"></a>

### [`bool GpuPipelineDesc.DepthTestEnabled`](#api-8672431f39c385ce)


```csharp
public bool DepthTestEnabled { get; set; }
```

Gets or sets whether depth testing is enabled.

<a id="api-191ae20785024f77"></a>

### [`bool GpuPipelineDesc.DepthWriteEnabled`](#api-191ae20785024f77)


```csharp
public bool DepthWriteEnabled { get; set; }
```

Gets or sets whether depth writing is enabled.

<a id="api-c03ad71778adafb8"></a>

### [`IGpuFragmentShader? GpuPipelineDesc.FragmentShader`](#api-c03ad71778adafb8)


```csharp
public IGpuFragmentShader? FragmentShader { get; set; }
```

Gets or sets the compiled fragment (pixel) shader.

<a id="api-13b3c2a09dd01d86"></a>

### [`bool GpuPipelineDesc.PremultipliedAlpha`](#api-13b3c2a09dd01d86)


```csharp
public bool PremultipliedAlpha { get; set; }
```

Enables premultiplied source-over blending. Requires the resource-device capability.

<a id="api-34e03ebe03256c68"></a>

### [`int[]? GpuPipelineDesc.VertexComponents`](#api-34e03ebe03256c68)


```csharp
public int[]? VertexComponents { get; set; }
```

Vertex attribute component counts in location order; null selects Float3 + Float4.

<a id="api-3ab64e381d4684f5"></a>

### [`IGpuVertexShader? GpuPipelineDesc.VertexShader`](#api-3ab64e381d4684f5)


```csharp
public IGpuVertexShader? VertexShader { get; set; }
```

Gets or sets the compiled vertex shader.


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

## `class GpuTextureValidation`

Shared validation for tightly packed RGBA8 mip chains.

```csharp
public static class GpuTextureValidation
{
    public static void Validate(int width, int height, IReadOnlyList<byte[]> levels);
}
```

<a id="api-d72f5b2ec01475d7"></a>

### [`void GpuTextureValidation.Validate(int width, int height, IReadOnlyList<byte[]> levels)`](#api-d72f5b2ec01475d7)


```csharp
public static void Validate(int width, int height, IReadOnlyList<byte[]> levels);
```

Checks dimensions and each mip&#39;s byte length before any native allocation.


<a id="api-80142e2a7a067881"></a>

## `class GpuVertexBufferDesc`

Describes the vertex buffer layout for a GPU draw call.

```csharp
public sealed class GpuVertexBufferDesc
{
    public int Stride { get; set; }
    public int VertexCount { get; set; }
}
```

<a id="api-7b4bcb448a192136"></a>

### [`int GpuVertexBufferDesc.Stride`](#api-7b4bcb448a192136)


```csharp
public int Stride { get; set; }
```

Gets or sets the stride (bytes per vertex).

<a id="api-a1cee5effe5d6609"></a>

### [`int GpuVertexBufferDesc.VertexCount`](#api-a1cee5effe5d6609)


```csharp
public int VertexCount { get; set; }
```

Gets or sets the vertex count.


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

## `interface IGpuCommandList`

Represents a GPU command list / draw context for recording rendering commands.

```csharp
public interface IGpuCommandList : IDisposable
{
    void BeginRenderPass(IGpuRenderTarget renderTarget, Xui.GPU.Shaders.Types.Color4 clearColor);
    void EndRenderPass();
    void SetPipeline(GpuPipelineDesc pipeline);
    unsafe void SetVertexBuffer(void* data, GpuVertexBufferDesc desc);
    unsafe void SetVertexBuffer<T>(ReadOnlySpan<T> vertices)
        where T : unmanaged;
    unsafe void SetConstantBuffer<T>(in T value)
        where T : unmanaged;
    unsafe void SetConstantBuffer(void* data, int sizeInBytes);
    void Draw(int vertexCount);
    void Commit();
}
```

<a id="api-27a4f81e690c319e"></a>

### [`void IGpuCommandList.BeginRenderPass(IGpuRenderTarget renderTarget, Color4 clearColor)`](#api-27a4f81e690c319e)


```csharp
void BeginRenderPass(IGpuRenderTarget renderTarget, Xui.GPU.Shaders.Types.Color4 clearColor);
```

Begins a render pass targeting the given render target.

<a id="api-d491c99a2628babd"></a>

### [`void IGpuCommandList.Commit()`](#api-d491c99a2628babd)


```csharp
void Commit();
```

Submits all recorded commands. Native presentation targets schedule presentation asynchronously; submission does not mean that the frame has finished displaying. Offscreen readback uses the backend&#39;s completion/synchronization mechanism.

<a id="api-b75818a0af0d8484"></a>

### [`void IGpuCommandList.Draw(int vertexCount)`](#api-b75818a0af0d8484)


```csharp
void Draw(int vertexCount);
```

Draws primitives using the current pipeline and vertex buffer.

- **`vertexCount`** — Number of vertices to draw.

<a id="api-9986fe384543788b"></a>

### [`void IGpuCommandList.EndRenderPass()`](#api-9986fe384543788b)


```csharp
void EndRenderPass();
```

Ends the current render pass.

<a id="api-a9bb5aeeaf69827e"></a>

### [`void IGpuCommandList.SetConstantBuffer(void* data, int sizeInBytes)`](#api-a9bb5aeeaf69827e)


```csharp
unsafe void SetConstantBuffer(void* data, int sizeInBytes);
```

Sets the uniform/constant buffer data.

- **`data`** — Pointer to constant data.

- **`sizeInBytes`** — Size of the constant data in bytes.

<a id="api-861b40aa6ca18ba7"></a>

### [`void IGpuCommandList.SetConstantBuffer<T>(in T value)`](#api-861b40aa6ca18ba7)


```csharp
unsafe void SetConstantBuffer<T>(in T value)
    where T : unmanaged;
```

Uploads one unmanaged constant-buffer value, borrowed only for this call.

<a id="api-2b7250adfbfefb88"></a>

### [`void IGpuCommandList.SetPipeline(GpuPipelineDesc pipeline)`](#api-2b7250adfbfefb88)


```csharp
void SetPipeline(GpuPipelineDesc pipeline);
```

Sets the pipeline state for subsequent draw calls.

<a id="api-5831903d32dbb64c"></a>

### [`void IGpuCommandList.SetVertexBuffer(void* data, GpuVertexBufferDesc desc)`](#api-5831903d32dbb64c)


```csharp
unsafe void SetVertexBuffer(void* data, GpuVertexBufferDesc desc);
```

Sets the vertex buffer for subsequent draw calls.

- **`data`** — Pointer to vertex data.

- **`desc`** — Vertex buffer description.

<a id="api-63a432610408fb59"></a>

### [`void IGpuCommandList.SetVertexBuffer<T>(ReadOnlySpan<T> vertices)`](#api-63a432610408fb59)


```csharp
unsafe void SetVertexBuffer<T>(ReadOnlySpan<T> vertices)
    where T : unmanaged;
```

Uploads tightly packed unmanaged vertices; the input is borrowed only for this call.

Native backends use the pointer overload by default. Managed backends may override this overload to copy non-contiguous managed storage into their upload representation.


<a id="api-0cb886cdcee628e4"></a>

## `interface IGpuDevice`

Abstract interface for a GPU hardware device. Implementations exist for Direct3D 11 (Windows) and Metal (macOS/iOS).

```csharp
public interface IGpuDevice : IDisposable
{
    string BackendName { get; }

    bool IsDisposed { get; }

    IGpuVertexShader CompileVertexShader(string source, string entryPoint);
    IGpuFragmentShader CompileFragmentShader(string source, string entryPoint);
    IGpuRenderTarget CreateRenderTarget(int width, int height);
    IGpuCommandList CreateCommandList();
}
```

<a id="api-c2b902072c6ab720"></a>

### [`string IGpuDevice.BackendName`](#api-c2b902072c6ab720)


```csharp
string BackendName { get; }
```

Gets the name of this GPU backend (e.g., &quot;D3D11&quot;, &quot;Metal&quot;).

<a id="api-c8d969eccb9ae5be"></a>

### [`IGpuFragmentShader IGpuDevice.CompileFragmentShader(string source, string entryPoint)`](#api-c8d969eccb9ae5be)


```csharp
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-cc3dbf0099237a5b"></a>

### [`IGpuVertexShader IGpuDevice.CompileVertexShader(string source, string entryPoint)`](#api-cc3dbf0099237a5b)


```csharp
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-2037c192b93e37ff"></a>

### [`IGpuCommandList IGpuDevice.CreateCommandList()`](#api-2037c192b93e37ff)


```csharp
IGpuCommandList CreateCommandList();
```

Creates a command list for recording rendering commands.

<a id="api-046b36f2e4ed2985"></a>

### [`IGpuRenderTarget IGpuDevice.CreateRenderTarget(int width, int height)`](#api-046b36f2e4ed2985)


```csharp
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-ad778c52d260be5f"></a>

### [`bool IGpuDevice.IsDisposed`](#api-ad778c52d260be5f)


```csharp
bool IsDisposed { get; }
```

Gets whether this device has been disposed.


<a id="api-4397c7c9f80356c0"></a>

## `interface IGpuFragmentShader`

Represents a compiled fragment (pixel) shader.

```csharp
public interface IGpuFragmentShader : IGpuShader
{
}
```


<a id="api-78cf4033bab286be"></a>

## `interface IGpuRenderTarget`

Represents a GPU render target backed by a texture. Offscreen targets support readback; borrowed native presentation targets may forbid it.

```csharp
public interface IGpuRenderTarget : IDisposable
{
    IGpuTexture Texture { get; }

    int Width { get; }

    int Height { get; }

    void ReadbackPixelsBgra(byte[] destination);
}
```

<a id="api-d53829f694945200"></a>

### [`int IGpuRenderTarget.Height`](#api-d53829f694945200)


```csharp
int Height { get; }
```

Gets the height of the render target in pixels.

<a id="api-a4cf39d07fedf28c"></a>

### [`void IGpuRenderTarget.ReadbackPixelsBgra(byte[] destination)`](#api-a4cf39d07fedf28c)


```csharp
void ReadbackPixelsBgra(byte[] destination);
```

Reads back the rendered pixels to a CPU byte array. Native presentation targets may throw NotSupportedException. The pixel format is BGRA (Blue, Green, Red, Alpha), 4 bytes per pixel.

- **`destination`** — A byte array of size Width * Height * 4 to receive the pixels.

<a id="api-7ed9150969838c64"></a>

### [`IGpuTexture IGpuRenderTarget.Texture`](#api-7ed9150969838c64)


```csharp
IGpuTexture Texture { get; }
```

Gets the underlying texture. Framebuffer-only presentation targets may throw NotSupportedException.

<a id="api-0afa3eeac907dd9a"></a>

### [`int IGpuRenderTarget.Width`](#api-0afa3eeac907dd9a)


```csharp
int Width { get; }
```

Gets the width of the render target in pixels.


<a id="api-81f25577e1b767bb"></a>

## `interface IGpuResourceCommandList`

Resource bindings supported by devices implementing [`Xui.GPU.Hardware.IGpuResourceDevice`](../xui-gpu-hardware/index.md#api-cbdcf1b4123afe03).

```csharp
public interface IGpuResourceCommandList : IGpuCommandList
{
    void SetVertexBuffer(IGpuVertexBuffer buffer);
    void SetTexture(int slot, IGpuTexture texture, Sampler sampler);
}
```

<a id="api-a25db098e8bd8adf"></a>

### [`void IGpuResourceCommandList.SetTexture(int slot, IGpuTexture texture, Sampler sampler)`](#api-a25db098e8bd8adf)


```csharp
void SetTexture(int slot, IGpuTexture texture, Sampler sampler);
```

Binds a sampled texture to a fragment texture and sampler slot; mip filtering is linear.

<a id="api-daf168a355aeddee"></a>

### [`void IGpuResourceCommandList.SetVertexBuffer(IGpuVertexBuffer buffer)`](#api-daf168a355aeddee)


```csharp
void SetVertexBuffer(IGpuVertexBuffer buffer);
```

Binds an immutable vertex buffer without uploading it again.


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

## `interface IGpuResourceDevice`

Optional device capability for sampled RGBA textures and immutable vertex buffers.

```csharp
public interface IGpuResourceDevice : IGpuDevice
{
    IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
    IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
}
```

<a id="api-e691dc723263ea52"></a>

### [`IGpuTexture IGpuResourceDevice.CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels)`](#api-e691dc723263ea52)


```csharp
IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
```

Uploads premultiplied RGBA8 mip levels, largest first, with tightly packed rows.

<a id="api-b52451e27003c04d"></a>

### [`IGpuVertexBuffer IGpuResourceDevice.CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride)`](#api-b52451e27003c04d)


```csharp
IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
```

Uploads immutable vertices once. The caller owns the returned buffer.


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

## `interface IGpuShader`

Represents a compiled GPU shader ready for use in a hardware pipeline.

```csharp
public interface IGpuShader : IDisposable
{
    string Name { get; }
}
```

<a id="api-9e246546aa930751"></a>

### [`string IGpuShader.Name`](#api-9e246546aa930751)


```csharp
string Name { get; }
```

Gets the name of this shader.


<a id="api-38608fc05bb88a69"></a>

## `interface IGpuTexture`

Represents a GPU texture that can be used as a render target.

```csharp
public interface IGpuTexture : IDisposable
{
    int Width { get; }

    int Height { get; }
}
```

<a id="api-abd6592653fbeb24"></a>

### [`int IGpuTexture.Height`](#api-abd6592653fbeb24)


```csharp
int Height { get; }
```

Gets the height of the texture in pixels.

<a id="api-ecc1b3a83954fa73"></a>

### [`int IGpuTexture.Width`](#api-ecc1b3a83954fa73)


```csharp
int Width { get; }
```

Gets the width of the texture in pixels.


<a id="api-79191fc55f93ca2d"></a>

## `interface IGpuVertexBuffer`

An owned immutable vertex buffer.

```csharp
public interface IGpuVertexBuffer : IDisposable
{
    int VertexCount { get; }
}
```

<a id="api-39bff431e6de3413"></a>

### [`int IGpuVertexBuffer.VertexCount`](#api-39bff431e6de3413)


```csharp
int VertexCount { get; }
```

Number of vertices in the buffer.


<a id="api-8583f7306283e7b4"></a>

## `interface IGpuVertexShader`

Represents a compiled vertex shader.

```csharp
public interface IGpuVertexShader : IGpuShader
{
}
```

