Table of Contents

Class GraphicsResourceAllocator

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

A GraphicsResource allocator tracking usage references and allowing to recycle unused resources based on a recycle policy.

public class GraphicsResourceAllocator : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder
Inheritance
object
GraphicsResourceAllocator
Implements
Inherited Members
Extension Methods

Remarks

This class is thread-safe. Accessing any member will acquire a global lock on this instance.

Constructors

GraphicsResourceAllocator(GraphicsDevice)

Initializes a new instance of the GraphicsResourceAllocator class.

public GraphicsResourceAllocator(GraphicsDevice graphicsDevice)

Parameters

graphicsDevice GraphicsDevice

The Graphics Device.

Exceptions

ArgumentNullException

graphicsDevice is null.

Properties

RecyclePolicy

Gets or sets the default recycle policy.

public GraphicsResourceRecyclePolicyDelegate RecyclePolicy { get; set; }

Property Value

GraphicsResourceRecyclePolicyDelegate

The recycle policy to apply by default by the Graphics Resource Allocator.

Remarks

A recycle policy is a delegate that inspects a Graphics Resource and some allocation and access information, and determines if it should be recycled (disposed) or not.

The default recycle policy (DefaultRecyclePolicy(GraphicsResourceLink)) is to always recycle a Graphics Resource irrespective of its state.

Services

Gets the services registry.

public IServiceRegistry Services { get; }

Property Value

IServiceRegistry

Methods

AddReference(GraphicsResource)

Adds a reference to a Graphics Resource tracked by this allocator.

public void AddReference(GraphicsResource resource)

Parameters

resource GraphicsResource

The Graphics Resource. It's internal reference count will be increased.

Exceptions

ArgumentException

Thrown if resource was not allocated by this allocator.

CreateBuffer(BufferDescription, PixelFormat)

Creates a Buffer.

protected virtual Buffer CreateBuffer(BufferDescription description, PixelFormat viewFormat)

Parameters

description BufferDescription

A description of the needed characteristics of the Buffer.

viewFormat PixelFormat

The data format for the View that will be seen by Shaders. Specify None to use the default format of the Buffer.

Returns

Buffer

A Buffer with the specified description.

CreateQueryPool(QueryPoolDescription, PixelFormat)

Creates a Query Pool for a specific number of GPU Queries of a given type.

protected virtual QueryPool CreateQueryPool(GraphicsResourceAllocator.QueryPoolDescription description, PixelFormat viewFormat)

Parameters

description GraphicsResourceAllocator.QueryPoolDescription

A description of the needed characteristics of the Query Pool, like the number of GPU Queries and their type.

viewFormat PixelFormat

Ignored for Query Pools, as they do not have a format.

Returns

QueryPool

A Query Pool with the specified types and count.

CreateTexture(TextureDescription, PixelFormat)

Creates a Texture.

protected virtual Texture CreateTexture(TextureDescription description, PixelFormat viewFormat)

Parameters

description TextureDescription

A description of the needed characteristics of the Texture.

viewFormat PixelFormat

The pixel format for the View that will be seen by Shaders. Specify None to use the default format of the Texture.

Returns

Texture

A Texture with the specified description.

Destroy()

Disposes the current Graphics Resource allocator by disposing all the associated resources and clearing all the caches.

protected override void Destroy()

GetQueryPool(QueryType, int)

Gets a Query Pool for a specific number of GPU Queries of a given type.

public QueryPool GetQueryPool(QueryType queryType, int queryCount)

Parameters

queryType QueryType

The type of the Queries.

queryCount int

The needed number of Queries.

Returns

QueryPool

A temporary Query Pool with the specified types and count.

GetTemporaryBuffer(BufferDescription, PixelFormat)

Gets a temporary Buffer with the specified description.

public Buffer GetTemporaryBuffer(BufferDescription description, PixelFormat viewFormat = PixelFormat.None)

Parameters

description BufferDescription

A description of the needed characteristics of the Buffer.

viewFormat PixelFormat

The data format for the View that will be seen by Shaders. Specify None to use the default format of the Buffer.

Returns

Buffer

A temporary Buffer with the specified description.

GetTemporaryTexture(TextureDescription)

Gets a temporary Texture with the specified description.

public Texture GetTemporaryTexture(TextureDescription description)

Parameters

description TextureDescription

A description of the needed characteristics of the Texture.

Returns

Texture

A temporary Texture with the specified description.

Recycle()

Recycles unused resources (those with a ReferenceCount of 0) with the RecyclePolicy.

public void Recycle()

Remarks

If no recycle policy is set (it is null), this method does not recycle anything.

Recycle(GraphicsResourceRecyclePolicyDelegate)

Recycles unused resources (those with a ReferenceCount of 0) with the specified recycle policy.

public void Recycle(GraphicsResourceRecyclePolicyDelegate recyclePolicy)

Parameters

recyclePolicy GraphicsResourceRecyclePolicyDelegate

The recycle policy.

Exceptions

ArgumentNullException

recyclePolicy is null.

ReleaseReference(GraphicsResourceBase)

Removes a reference to a Graphics Resource tracked by this allocator.

public void ReleaseReference(GraphicsResourceBase resource)

Parameters

resource GraphicsResourceBase

The Graphics Resource. It's internal reference count will be decreased.

Exceptions

ArgumentException

Thrown if resource was not allocated by this allocator.