Xui.GPU.Hardware
Assembly: Xui.Core · C# declarations · Assembly overview
Types
enum GpuCullModeclass GpuPipelineDescclass GpuTextureValidationclass GpuVertexBufferDescinterface IGpuCommandListinterface IGpuDeviceinterface IGpuFragmentShaderinterface IGpuRenderTargetinterface IGpuResourceCommandListinterface IGpuResourceDeviceinterface IGpuShaderinterface IGpuTextureinterface IGpuVertexBufferinterface IGpuVertexShader
enum GpuCullMode
Specifies which triangle faces to cull during rasterization.
public enum GpuCullMode
{
None = 0,
Back = 1,
Front = 2,
}
GpuCullMode.Back
Back = 1
Back-facing triangles are culled (default).
GpuCullMode.Front
Front = 2
Front-facing triangles are culled.
GpuCullMode.None
None = 0
No culling — all triangles are rendered.
class GpuPipelineDesc
Describes a hardware GPU render pipeline, binding shaders and state together.
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; }
}
GpuCullMode GpuPipelineDesc.CullMode
public GpuCullMode CullMode { get; set; }
Gets or sets the triangle cull mode.
bool GpuPipelineDesc.DepthTestEnabled
public bool DepthTestEnabled { get; set; }
Gets or sets whether depth testing is enabled.
bool GpuPipelineDesc.DepthWriteEnabled
public bool DepthWriteEnabled { get; set; }
Gets or sets whether depth writing is enabled.
IGpuFragmentShader? GpuPipelineDesc.FragmentShader
public IGpuFragmentShader? FragmentShader { get; set; }
Gets or sets the compiled fragment (pixel) shader.
bool GpuPipelineDesc.PremultipliedAlpha
public bool PremultipliedAlpha { get; set; }
Enables premultiplied source-over blending. Requires the resource-device capability.
int[]? GpuPipelineDesc.VertexComponents
public int[]? VertexComponents { get; set; }
Vertex attribute component counts in location order; null selects Float3 + Float4.
IGpuVertexShader? GpuPipelineDesc.VertexShader
public IGpuVertexShader? VertexShader { get; set; }
Gets or sets the compiled vertex shader.
class GpuTextureValidation
Shared validation for tightly packed RGBA8 mip chains.
public static class GpuTextureValidation
{
public static void Validate(int width, int height, IReadOnlyList<byte[]> levels);
}
void GpuTextureValidation.Validate(int width, int height, IReadOnlyList<byte[]> levels)
public static void Validate(int width, int height, IReadOnlyList<byte[]> levels);
Checks dimensions and each mip's byte length before any native allocation.
class GpuVertexBufferDesc
Describes the vertex buffer layout for a GPU draw call.
public sealed class GpuVertexBufferDesc
{
public int Stride { get; set; }
public int VertexCount { get; set; }
}
int GpuVertexBufferDesc.Stride
public int Stride { get; set; }
Gets or sets the stride (bytes per vertex).
int GpuVertexBufferDesc.VertexCount
public int VertexCount { get; set; }
Gets or sets the vertex count.
interface IGpuCommandList
Represents a GPU command list / draw context for recording rendering commands.
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();
}
void IGpuCommandList.BeginRenderPass(IGpuRenderTarget renderTarget, Color4 clearColor)
void BeginRenderPass(IGpuRenderTarget renderTarget, Xui.GPU.Shaders.Types.Color4 clearColor);
Begins a render pass targeting the given render target.
void IGpuCommandList.Commit()
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's completion/synchronization mechanism.
void IGpuCommandList.Draw(int vertexCount)
void Draw(int vertexCount);
Draws primitives using the current pipeline and vertex buffer.
vertexCount— Number of vertices to draw.
void IGpuCommandList.EndRenderPass()
void EndRenderPass();
Ends the current render pass.
void IGpuCommandList.SetConstantBuffer(void* data, int sizeInBytes)
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.
void IGpuCommandList.SetConstantBuffer<T>(in T value)
unsafe void SetConstantBuffer<T>(in T value)
where T : unmanaged;
Uploads one unmanaged constant-buffer value, borrowed only for this call.
void IGpuCommandList.SetPipeline(GpuPipelineDesc pipeline)
void SetPipeline(GpuPipelineDesc pipeline);
Sets the pipeline state for subsequent draw calls.
void IGpuCommandList.SetVertexBuffer(void* data, GpuVertexBufferDesc desc)
unsafe void SetVertexBuffer(void* data, GpuVertexBufferDesc desc);
Sets the vertex buffer for subsequent draw calls.
data— Pointer to vertex data.desc— Vertex buffer description.
void IGpuCommandList.SetVertexBuffer<T>(ReadOnlySpan<T> vertices)
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.
interface IGpuDevice
Abstract interface for a GPU hardware device. Implementations exist for Direct3D 11 (Windows) and Metal (macOS/iOS).
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();
}
string IGpuDevice.BackendName
string BackendName { get; }
Gets the name of this GPU backend (e.g., "D3D11", "Metal").
IGpuFragmentShader IGpuDevice.CompileFragmentShader(string source, string entryPoint)
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.
IGpuVertexShader IGpuDevice.CompileVertexShader(string source, string entryPoint)
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.
IGpuCommandList IGpuDevice.CreateCommandList()
IGpuCommandList CreateCommandList();
Creates a command list for recording rendering commands.
IGpuRenderTarget IGpuDevice.CreateRenderTarget(int width, int height)
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.
bool IGpuDevice.IsDisposed
bool IsDisposed { get; }
Gets whether this device has been disposed.
interface IGpuFragmentShader
Represents a compiled fragment (pixel) shader.
public interface IGpuFragmentShader : IGpuShader
{
}
interface IGpuRenderTarget
Represents a GPU render target backed by a texture. Offscreen targets support readback; borrowed native presentation targets may forbid it.
public interface IGpuRenderTarget : IDisposable
{
IGpuTexture Texture { get; }
int Width { get; }
int Height { get; }
void ReadbackPixelsBgra(byte[] destination);
}
int IGpuRenderTarget.Height
int Height { get; }
Gets the height of the render target in pixels.
void IGpuRenderTarget.ReadbackPixelsBgra(byte[] destination)
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.
IGpuTexture IGpuRenderTarget.Texture
IGpuTexture Texture { get; }
Gets the underlying texture. Framebuffer-only presentation targets may throw NotSupportedException.
int IGpuRenderTarget.Width
int Width { get; }
Gets the width of the render target in pixels.
interface IGpuResourceCommandList
Resource bindings supported by devices implementing Xui.GPU.Hardware.IGpuResourceDevice.
public interface IGpuResourceCommandList : IGpuCommandList
{
void SetVertexBuffer(IGpuVertexBuffer buffer);
void SetTexture(int slot, IGpuTexture texture, Sampler sampler);
}
void IGpuResourceCommandList.SetTexture(int slot, IGpuTexture texture, Sampler sampler)
void SetTexture(int slot, IGpuTexture texture, Sampler sampler);
Binds a sampled texture to a fragment texture and sampler slot; mip filtering is linear.
void IGpuResourceCommandList.SetVertexBuffer(IGpuVertexBuffer buffer)
void SetVertexBuffer(IGpuVertexBuffer buffer);
Binds an immutable vertex buffer without uploading it again.
interface IGpuResourceDevice
Optional device capability for sampled RGBA textures and immutable vertex buffers.
public interface IGpuResourceDevice : IGpuDevice
{
IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
}
IGpuTexture IGpuResourceDevice.CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels)
IGpuTexture CreateSampledTexture(int width, int height, IReadOnlyList<byte[]> mipLevels);
Uploads premultiplied RGBA8 mip levels, largest first, with tightly packed rows.
IGpuVertexBuffer IGpuResourceDevice.CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride)
IGpuVertexBuffer CreateVertexBuffer(ReadOnlySpan<byte> vertices, int stride);
Uploads immutable vertices once. The caller owns the returned buffer.
interface IGpuShader
Represents a compiled GPU shader ready for use in a hardware pipeline.
public interface IGpuShader : IDisposable
{
string Name { get; }
}
string IGpuShader.Name
string Name { get; }
Gets the name of this shader.
interface IGpuTexture
Represents a GPU texture that can be used as a render target.
public interface IGpuTexture : IDisposable
{
int Width { get; }
int Height { get; }
}
int IGpuTexture.Height
int Height { get; }
Gets the height of the texture in pixels.
int IGpuTexture.Width
int Width { get; }
Gets the width of the texture in pixels.
interface IGpuVertexBuffer
An owned immutable vertex buffer.
public interface IGpuVertexBuffer : IDisposable
{
int VertexCount { get; }
}
int IGpuVertexBuffer.VertexCount
int VertexCount { get; }
Number of vertices in the buffer.
interface IGpuVertexShader
Represents a compiled vertex shader.
public interface IGpuVertexShader : IGpuShader
{
}