Plasma Engine  2.0
Loading...
Searching...
No Matches
plGPUResourcePool Class Reference

This class serves as a pool for GPU related resources (e.g. buffers and textures required for rendering). Note that the functions creating and returning render targets are thread safe (by using a mutex). More...

#include <GPUResourcePool.h>

Classes

struct  BufferHandleWithAge
 
struct  TextureHandleWithAge
 

Public Member Functions

plGALTextureHandle GetRenderTarget (const plGALTextureCreationDescription &textureDesc)
 Returns a render target handle for the given texture description Note that you should return the handle to the pool and never destroy it directly with the device.
 
plGALTextureHandle GetRenderTarget (plUInt32 uiWidth, plUInt32 uiHeight, plGALResourceFormat::Enum format, plGALMSAASampleCount::Enum sampleCount=plGALMSAASampleCount::None, plUInt32 uiSliceColunt=1)
 Convenience functions which creates a texture description fit for a 2d render target without a mip chains.
 
void ReturnRenderTarget (plGALTextureHandle hRenderTarget)
 Returns a render target to the pool so other consumers can use it. Note that targets which are returned to the pool are susceptible to destruction due to garbage collection.
 
plGALBufferHandle GetBuffer (const plGALBufferCreationDescription &bufferDesc)
 Returns a buffer handle for the given buffer description.
 
void ReturnBuffer (plGALBufferHandle hBuffer)
 Returns a buffer to the pool so other consumers can use it.
 
void RunGC (plUInt32 uiMinimumAge)
 Tries to free resources which are currently in the pool. Triggered automatically due to allocation number / size thresholds but can be triggered manually (e.g. after editor window resize)
 

Static Public Member Functions

static plGPUResourcePoolGetDefaultInstance ()
 
static void SetDefaultInstance (plGPUResourcePool *pDefaultInstance)
 

Protected Member Functions

void CheckAndPotentiallyRunGC ()
 
void UpdateMemoryStats () const
 
void GALDeviceEventHandler (const plGALDeviceEvent &e)
 

Protected Attributes

plEventSubscriptionID m_GALDeviceEventSubscriptionID = 0
 
plUInt64 m_uiMemoryThresholdForGC = 256 * 1024 * 1024
 
plUInt64 m_uiCurrentlyAllocatedMemory = 0
 
plUInt16 m_uiNumAllocationsThresholdForGC = 128
 
plUInt16 m_uiNumAllocationsSinceLastGC = 0
 
plUInt16 m_uiFramesThresholdSinceLastGC = 60
 Every 60 frames resources unused for more than 10 frames in a row are GCed.
 
plUInt16 m_uiFramesSinceLastGC = 0
 
plMap< plUInt32, plDynamicArray< TextureHandleWithAge > > m_AvailableTextures
 
plSet< plGALTextureHandlem_TexturesInUse
 
plMap< plUInt32, plDynamicArray< BufferHandleWithAge > > m_AvailableBuffers
 
plSet< plGALBufferHandlem_BuffersInUse
 
plMutex m_Lock
 
plGALDevicem_pDevice
 

Detailed Description

This class serves as a pool for GPU related resources (e.g. buffers and textures required for rendering). Note that the functions creating and returning render targets are thread safe (by using a mutex).

Member Function Documentation

◆ RunGC()

void plGPUResourcePool::RunGC ( plUInt32 uiMinimumAge)

Tries to free resources which are currently in the pool. Triggered automatically due to allocation number / size thresholds but can be triggered manually (e.g. after editor window resize)

Parameters
uiMinimumAgeHow many frames at least the resource needs to have been unused before it will be GCed.

The documentation for this class was generated from the following files: