Class GraphicsResourceAllocator
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
-
objectGraphicsResourceAllocator
- 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
graphicsDeviceGraphicsDeviceThe Graphics Device.
Exceptions
- ArgumentNullException
graphicsDeviceis 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
Methods
AddReference(GraphicsResource)
Adds a reference to a Graphics Resource tracked by this allocator.
public void AddReference(GraphicsResource resource)
Parameters
resourceGraphicsResourceThe Graphics Resource. It's internal reference count will be increased.
Exceptions
- ArgumentException
Thrown if
resourcewas not allocated by this allocator.
CreateBuffer(BufferDescription, PixelFormat)
Creates a Buffer.
protected virtual Buffer CreateBuffer(BufferDescription description, PixelFormat viewFormat)
Parameters
descriptionBufferDescriptionA description of the needed characteristics of the Buffer.
viewFormatPixelFormatThe 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
descriptionGraphicsResourceAllocator.QueryPoolDescriptionA description of the needed characteristics of the Query Pool, like the number of GPU Queries and their type.
viewFormatPixelFormatIgnored 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
descriptionTextureDescriptionA description of the needed characteristics of the Texture.
viewFormatPixelFormatThe 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
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
descriptionBufferDescriptionA description of the needed characteristics of the Buffer.
viewFormatPixelFormatThe 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
descriptionTextureDescriptionA 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
recyclePolicyGraphicsResourceRecyclePolicyDelegateThe recycle policy.
Exceptions
- ArgumentNullException
recyclePolicyis null.
ReleaseReference(GraphicsResourceBase)
Removes a reference to a Graphics Resource tracked by this allocator.
public void ReleaseReference(GraphicsResourceBase resource)
Parameters
resourceGraphicsResourceBaseThe Graphics Resource. It's internal reference count will be decreased.
Exceptions
- ArgumentException
Thrown if
resourcewas not allocated by this allocator.