GraphicsAPI reference
Class GraphicsDeviceBase
Namespace: MicroEngine.Graphics.Devices
Assembly: MicroEngine.Graphics.dll
Guide: The graphics device
Core half of every device: validates each call against the written rules and the declared capabilities, then hands
the backend a call it can execute. Backends derive from it and implement only the *Core members, so ownership,
disposal, ranges and capability errors behave identically on every tier.
public abstract class GraphicsDeviceBase : IGraphicsDevice, IDisposableInheritance
Derived
Implements
Constructors
GraphicsDeviceBase()
protected GraphicsDeviceBase()Properties
Capabilities
Declared capabilities.
public abstract GraphicsCapabilities Capabilities { get; }Property Value
CompletedSubmissions
The number of submitted command lists the backend has finished executing. Resources disposed after the n-th submission are released once this reaches n. The default, the number of lists submitted, suits devices that execute a list completely inside Submit; a device that executes later overrides it and calls CollectRetired when work completes.
protected virtual long CompletedSubmissions { get; }Property Value
Counters
Deterministic counts of the work submitted to this device since it was created.
public GraphicsCounters Counters { get; }Property Value
IsDisposed
True after Dispose.
public bool IsDisposed { get; }Property Value
PendingReleases
Disposed resources whose backend release still waits for submitted work.
public int PendingReleases { get; }Property Value
Methods
BeginCommands()
Starts an empty command list for this device.
public CommandList BeginCommands()Returns
CollectRetired()
Releases the disposed resources no submitted work uses any more (see CompletedSubmissions).
protected void CollectRetired()CreateBuffer(in BufferDescription)
public GpuBuffer CreateBuffer(in BufferDescription description)Parameters
description BufferDescription
Returns
CreateBufferCore(in BufferDescription)
Backend: create a validated buffer.
protected abstract GpuBuffer CreateBufferCore(in BufferDescription description)Parameters
description BufferDescription
Returns
CreateBuiltInPipelineCore(BuiltInPipeline, BlendState, TextureFormat, TextureFormat?)
Backend: create a built-in pipeline variant (core caches it).
protected abstract Pipeline CreateBuiltInPipelineCore(BuiltInPipeline kind, BlendState blend, TextureFormat colorFormat, TextureFormat? depthFormat)Parameters
kind BuiltInPipeline
blend BlendState
colorFormat TextureFormat
depthFormat TextureFormat?
Returns
CreatePipeline(PipelineDescription)
Creates a custom pipeline; requires Shaders, and DepthBuffer for depth.
public Pipeline CreatePipeline(PipelineDescription description)Parameters
description PipelineDescription
Returns
CreatePipelineCore(PipelineDescription)
Backend: create a validated custom pipeline (tier 0 is never called: core refuses first).
protected abstract Pipeline CreatePipelineCore(PipelineDescription description)Parameters
description PipelineDescription
Returns
CreateRenderTarget(in RenderTargetDescription)
public RenderTarget CreateRenderTarget(in RenderTargetDescription description)Parameters
description RenderTargetDescription
Returns
CreateRenderTargetCore(in RenderTargetDescription)
Backend: create a validated render target.
protected abstract RenderTarget CreateRenderTargetCore(in RenderTargetDescription description)Parameters
description RenderTargetDescription
Returns
CreateSamplerCore(in SamplerDescription)
Backend: create a validated sampler (core caches it).
protected abstract Sampler CreateSamplerCore(in SamplerDescription description)Parameters
description SamplerDescription
Returns
CreateShader(in ShaderDescription)
public Shader CreateShader(in ShaderDescription description)Parameters
description ShaderDescription
Returns
CreateShaderCore(in ShaderDescription)
Backend: create a validated shader (tier 0 is never called: core refuses first).
protected abstract Shader CreateShaderCore(in ShaderDescription description)Parameters
description ShaderDescription
Returns
CreateTexture(in TextureDescription, ReadOnlySpan<byte>)
public Texture CreateTexture(in TextureDescription description, ReadOnlySpan<byte> initialData = default)Parameters
description TextureDescription
initialData ReadOnlySpan<byte>
Returns
CreateTextureCore(in TextureDescription, ReadOnlySpan<byte>)
Backend: create a validated texture.
protected abstract Texture CreateTextureCore(in TextureDescription description, ReadOnlySpan<byte> initialData)Parameters
description TextureDescription
initialData ReadOnlySpan<byte>
Returns
Dispose()
Releases backend objects (waiting for the GPU first). Resources disposed later are ignored by the backend.
public void Dispose()DisposeCore(IReadOnlyList<Pipeline>, IReadOnlyList<Sampler>)
Backend: release everything, the device-owned built-ins and samplers included.
protected abstract void DisposeCore(IReadOnlyList<Pipeline> builtIns, IReadOnlyList<Sampler> samplers)Parameters
builtIns IReadOnlyList<Pipeline>
samplers IReadOnlyList<Sampler>
GetBuiltInPipeline(BuiltInPipeline, BlendState, TextureFormat, TextureFormat?)
Returns the device-owned built-in pipeline for a kind, a blend state and the attachment formats it renders to (every tier; the 2D batcher needs nothing else). A blend state outside BuiltInBlendStates requires CustomBlend.
public Pipeline GetBuiltInPipeline(BuiltInPipeline kind, BlendState blend, TextureFormat colorFormat, TextureFormat? depthFormat = null)Parameters
kind BuiltInPipeline
blend BlendState
colorFormat TextureFormat
depthFormat TextureFormat?
Returns
GetSampler(in SamplerDescription)
public Sampler GetSampler(in SamplerDescription description)Parameters
description SamplerDescription
Returns
Present()
Presents the acquired surface target (no-op when none was acquired) and expires it.
public void Present()PresentCore(RenderTarget)
Backend: present and expire the surface target.
protected abstract void PresentCore(RenderTarget surfaceTarget)Parameters
surfaceTarget RenderTarget
RaiseDeviceLost(DeviceLostReason)
For backends that detect loss.
protected void RaiseDeviceLost(DeviceLostReason reason)Parameters
reason DeviceLostReason
ReadPixels(RenderTarget, RectI)
Starts reading region of an offscreen target; completes through the returned fence. Surface
targets cannot be read: captures render offscreen, read back, then draw the target to the surface.
public ReadbackRequest ReadPixels(RenderTarget target, RectI region)Parameters
target RenderTarget
region RectI
Returns
ReadPixelsCore(RenderTarget, RectI)
Backend: start a validated readback.
protected abstract ReadbackRequest ReadPixelsCore(RenderTarget target, RectI region)Parameters
target RenderTarget
region RectI
Returns
Submit(CommandList)
Executes a finished list (no open pass) after every list submitted before it. A list is submitted once.
public void Submit(CommandList commands)Parameters
commands CommandList
SubmitCore(CommandList)
Backend: execute a validated, sealed list after everything submitted before it.
protected abstract void SubmitCore(CommandList commands)Parameters
commands CommandList
TryAcquireSurfaceTarget(out RenderTarget?)
Acquires this frame’s surface target. False when there is nothing to present to (no surface, minimised, zero size): the frame then skips its surface passes and presentation. The target expires at Present. Its ColorFormat is the format pipelines in its passes must declare; a tier-0 backend, whose built-in pipelines do not depend on the format, reports the nominal format of its back buffer.
public bool TryAcquireSurfaceTarget(out RenderTarget? target)Parameters
target RenderTarget?
Returns
TryAcquireSurfaceTargetCore()
Backend: acquire this frame’s surface target or return null.
protected abstract RenderTarget? TryAcquireSurfaceTargetCore()Returns
TryGetResource<T>(Handle<GraphicsResource>, out T?)
Finds a live resource of this device by its handle: false once the resource was disposed, even when a new
resource reuses its slot, or when it is not a T.
public bool TryGetResource<T>(Handle<GraphicsResource> handle, out T? resource) where T : GraphicsResourceParameters
handle Handle<GraphicsResource>
resource T?
Returns
Type Parameters
T
DeviceLost
Optional: raised only by backends that can detect loss (SDL_GPU never raises it); resources are marked IsLost.
public event Action<DeviceLostReason>? DeviceLost