XII Release 0.1.0
Loading...
Searching...
No Matches
xiiRenderGraphResourceCache Class Reference

Copyright (c) Theophilus Eriata. All Rights Reserved. More...

#include <RenderGraphResourceCache.h>

Public Member Functions

 xiiRenderGraphResourceCache (xiiSharedPtr< xiiGALDevice > pDevice)
 Copyright (c) Theophilus Eriata. All Rights Reserved.
void BeginFrame (xiiUInt64 uiFrameIndex)
void BeginFrame (xiiUInt64 uiFrameIndex, xiiUInt64 uiCompletedFrameIndex)
void EndFrame ()
 Called once at the end of a frame after Execute(). Returns all active resources to the pool.
xiiSharedPtr< xiiGALTexture > AcquireTexture (const xiiGALTextureCreationDescription &description)
void ReturnTexture (xiiSharedPtr< xiiGALTexture > pTexture)
 Returns a texture to the pool for potential reuse in subsequent frames.
xiiSharedPtr< xiiGALBuffer > AcquireBuffer (const xiiGALBufferCreationDescription &description)
void ReturnBuffer (xiiSharedPtr< xiiGALBuffer > pBuffer)
 Returns a buffer to the pool for potential reuse in subsequent frames.
void ReleaseStaleResources (xiiUInt32 uiMinAgeFrames=4U)
xiiUInt32 GetActiveResourceCount () const
 Returns the number of resources currently acquired (not yet returned this frame).
xiiUInt32 GetPooledResourceCount () const
 Returns the number of resources sitting idle in the pool.

Detailed Description

Copyright (c) Theophilus Eriata. All Rights Reserved.

Frame-scoped GPU resource pool dedicated to the render graph's transient resource needs.

Transient resources are GPU textures and buffers that are created for a single frame, used by one or more render graph passes, and then returned to the pool for reuse in subsequent frames. The cache uses the resource creation description hash as a key, so resources with identical descriptions are reused without re-allocation.

Frame lifecycle

cache.BeginFrame(uiFrameIndex); // Prepare pool for this frame.
// ... graph executes, passes call AcquireTexture / ReturnTexture ...
cache.EndFrame(); // Return all still-active resources back to pool.

Thread safety

AcquireTexture, ReturnTexture, AcquireBuffer, ReturnBuffer are all protected by an internal mutex and are safe to call concurrently from parallel pass execution threads.

Stale eviction

BeginFrame() evicts completed pooled resources unused for at least four frames. This bounds retention when viewport dimensions or upload sizes change continuously. ReleaseStaleResources() can additionally trim idle resources; it never releases active or GPU-in-flight resources.

Member Function Documentation

◆ AcquireBuffer()

xiiSharedPtr< xiiGALBuffer > xiiRenderGraphResourceCache::AcquireBuffer ( const xiiGALBufferCreationDescription & description)
nodiscard

Returns a buffer matching the given description, creating one if no pool entry exists. Returns null if allocation fails or the cache is uninitialized. The caller must handle failure.

◆ AcquireTexture()

xiiSharedPtr< xiiGALTexture > xiiRenderGraphResourceCache::AcquireTexture ( const xiiGALTextureCreationDescription & description)
nodiscard

Returns a texture matching the given description, creating one if no pool entry exists. Returns null if allocation fails or the cache is uninitialized. The caller must handle failure.

◆ BeginFrame() [1/2]

void xiiRenderGraphResourceCache::BeginFrame ( xiiUInt64 uiFrameIndex)

Called once at the start of a frame before Execute(). Uses a conservative three-frame retirement window for callers that do not expose an exact completed-frame index.

◆ BeginFrame() [2/2]

void xiiRenderGraphResourceCache::BeginFrame ( xiiUInt64 uiFrameIndex,
xiiUInt64 uiCompletedFrameIndex )

Starts a frame, promotes resources whose last GPU frame is known to be complete, and evicts idle allocations unused for at least four frames. This overload is preferred by render loops with explicit frame fences.

◆ ReleaseStaleResources()

void xiiRenderGraphResourceCache::ReleaseStaleResources ( xiiUInt32 uiMinAgeFrames = 4U)

Destroys pooled resources that have not been acquired for more than uiMinAgeFrames frames.

Parameters
uiMinAgeFramesResources unused for at least this many frames are released. Default is 4.

The documentation for this class was generated from the following files:
  • /home/runner/work/XII/XII/Source/Engine/GraphicsCore/Pipeline/RenderGraphResourceCache.h
  • /home/runner/work/XII/XII/Source/Engine/GraphicsCore/Pipeline/Implementation/RenderGraphResourceCache.cpp