ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
FrameCache Class Reference

Fixed-capacity ring buffer of GL textures for temporal shaders. More...

Public Member Functions

std::size_t capacity () const
 Maximum number of frames retained by the ring.
void cleanup ()
 Release all GL textures and reset the ring state.
void fill (const cv::Mat &frame)
 Pre-fill every slot with copies of a single frame.
 FrameCache (const FrameCache &)=delete
 FrameCache (std::size_t num, bool use_array=false)
GLuint historyTexture () const
 Array texture containing the physical history ring layers.
void init (int w, int h, bool hdr=false)
 Allocate the ring of GL textures sized to w x h.
bool isFull () const
 True when the ring is fully populated.
int oldestLayer () const
 Physical array layer corresponding to logical history index zero.
FrameCache & operator= (const FrameCache &)=delete
void push (const cv::Mat &frame)
 Upload frame (BGR) into the next ring slot.
void pushFromFBO (GLuint src_fbo, int w, int h)
 GPU-side push from a source FBO into the next ring slot.
void pushFromTexture (GLuint src_tex, int w, int h)
 GPU-side push from an existing GL texture into the next ring slot.
std::size_t size () const
 Number of frames currently retained (0 ≤ n ≤ capacity).
GLuint textureAt (std::size_t index) const
 Return the GL texture at logical index index.
 ~FrameCache ()

Private Member Functions

void advance ()
void allocateHistoryTexture ()
 Allocate the optional array texture using the cache's dimensions and pixel format.
void finishPush ()
bool hasStorage () const

Private Attributes

std::size_t count = 0
std::size_t head = 0
int height = 0
GLuint history_texture = 0
 Optional array-backed history ring.
bool is_hdr = false
std::size_t num_frames
GLuint scratch_fbo = 0
 Scratch FBO used by pushFromTexture().
std::vector< GLuint > textures
bool use_history_array = false
int width = 0

Detailed Description

Fixed-capacity ring buffer of GL textures for temporal shaders.

Legacy shaders whose filename contains "cache" receive previous frames as separate sampler2D uniforms. Array-cache shaders instead receive one sampler2DArray whose layers form the ring. In either mode only the newest frame is uploaded into the next physical slot. The "oldest → newest" indexing used by shaders is preserved via a logical-to-physical offset.

This mirrors the texture-ring approach used by gl_compute_cv and eliminates 7 BGR→RGBA conversions plus 7 texture uploads per push.

Definition at line 2052 of file ACMX2/acmx.cpp.

Constructor & Destructor Documentation

◆ FrameCache() [1/2]

FrameCache::FrameCache ( std::size_t num,
bool use_array = false )
inlineexplicit
Parameters
numMaximum number of frames to retain.
use_arrayStore the ring in one GL_TEXTURE_2D_ARRAY instead of separate GL_TEXTURE_2D objects.

Definition at line 2059 of file ACMX2/acmx.cpp.

References num_frames, and use_history_array.

Referenced by FrameCache(), and operator=().

◆ ~FrameCache()

FrameCache::~FrameCache ( )
inline

Definition at line 2060 of file ACMX2/acmx.cpp.

References cleanup().

◆ FrameCache() [2/2]

FrameCache::FrameCache ( const FrameCache & )
delete

References FrameCache().

Member Function Documentation

◆ advance()

void FrameCache::advance ( )
inlineprivate

Definition at line 2382 of file ACMX2/acmx.cpp.

References count, head, and num_frames.

Referenced by finishPush(), and push().

◆ allocateHistoryTexture()

void FrameCache::allocateHistoryTexture ( )
inlineprivate

Allocate the optional array texture using the cache's dimensions and pixel format.

Definition at line 2401 of file ACMX2/acmx.cpp.

References height, history_texture, is_hdr, num_frames, use_history_array, and width.

Referenced by fill(), init(), pushFromFBO(), and pushFromTexture().

◆ capacity()

std::size_t FrameCache::capacity ( ) const
inline

Maximum number of frames retained by the ring.

Definition at line 2324 of file ACMX2/acmx.cpp.

References num_frames.

◆ cleanup()

void FrameCache::cleanup ( )
inline

Release all GL textures and reset the ring state.

Definition at line 2111 of file ACMX2/acmx.cpp.

References count, head, height, history_texture, is_hdr, scratch_fbo, textures, and width.

Referenced by init(), and ~FrameCache().

◆ fill()

void FrameCache::fill ( const cv::Mat & frame)
inline

Pre-fill every slot with copies of a single frame.

Seeds the entire cache with one frame and marks the ring as full.

Definition at line 2340 of file ACMX2/acmx.cpp.

References allocateHistoryTexture(), count, hasStorage(), head, height, history_texture, num_frames, textures, use_history_array, and width.

Referenced by push().

◆ finishPush()

void FrameCache::finishPush ( )
inlineprivate

Definition at line 2388 of file ACMX2/acmx.cpp.

References advance(), count, head, and num_frames.

Referenced by pushFromFBO(), and pushFromTexture().

◆ hasStorage()

bool FrameCache::hasStorage ( ) const
inlineprivate

Definition at line 2380 of file ACMX2/acmx.cpp.

References history_texture, textures, and use_history_array.

Referenced by fill(), push(), pushFromFBO(), and pushFromTexture().

◆ historyTexture()

GLuint FrameCache::historyTexture ( ) const
inline

Array texture containing the physical history ring layers.

Definition at line 2330 of file ACMX2/acmx.cpp.

References history_texture.

Referenced by ACView::bindPassHistoryTextures().

◆ init()

void FrameCache::init ( int w,
int h,
bool hdr = false )
inline

Allocate the ring of GL textures sized to w x h.

Must be called once a GL context is current. Existing textures (if any) are released first. The ring remains empty until the first source frame is replicated into every slot by one of the push methods.

Parameters
wTexture width in pixels.
hTexture height in pixels.
hdrWhen true, allocate textures as GL_RGBA16F (matching the HDR linear-light pipeline) instead of GL_RGBA.

Definition at line 2077 of file ACMX2/acmx.cpp.

References allocateHistoryTexture(), cleanup(), count, head, height, is_hdr, num_frames, textures, use_history_array, and width.

◆ isFull()

bool FrameCache::isFull ( ) const
inline

True when the ring is fully populated.

Definition at line 2327 of file ACMX2/acmx.cpp.

References count, and num_frames.

Referenced by ACView::bindPassHistoryTextures(), and oldestLayer().

◆ oldestLayer()

int FrameCache::oldestLayer ( ) const
inline

Physical array layer corresponding to logical history index zero.

Definition at line 2333 of file ACMX2/acmx.cpp.

References head, and isFull().

◆ operator=()

FrameCache & FrameCache::operator= ( const FrameCache & )
delete

References FrameCache().

◆ push()

void FrameCache::push ( const cv::Mat & frame)
inline

Upload frame (BGR) into the next ring slot.

When the ring is full this overwrites the oldest slot in place, which becomes the new "newest" frame. Only one BGR→RGBA conversion and one texture upload occur per call.

Definition at line 2209 of file ACMX2/acmx.cpp.

References advance(), count, fill(), hasStorage(), head, height, history_texture, textures, use_history_array, and width.

◆ pushFromFBO()

void FrameCache::pushFromFBO ( GLuint src_fbo,
int w,
int h )
inline

GPU-side push from a source FBO into the next ring slot.

Used by the HDR pipeline to copy the post-decode linear BT.2020 texture into an RGBA16F ring without any CPU readback or pixel format conversion. The source FBO must have a colour attachment sized at least w x h and using a compatible internal format (e.g. GL_RGBA16F when the cache was initialised with hdr=true).

Parameters
src_fboRead framebuffer object containing the new frame.
w,hRegion to copy (typically the full FBO dimensions).

Definition at line 2143 of file ACMX2/acmx.cpp.

References allocateHistoryTexture(), count, finishPush(), hasStorage(), head, height, history_texture, is_hdr, num_frames, textures, use_history_array, and width.

◆ pushFromTexture()

void FrameCache::pushFromTexture ( GLuint src_tex,
int w,
int h )
inline

GPU-side push from an existing GL texture into the next ring slot.

Uses a small scratch FBO so the per-frame BGR->RGBA conversion and second host->GPU upload that push() performs can be avoided entirely once the camera texture has already been populated for the shader chain. This is the path that keeps zero-copy interop intact when expensive CPU passes (e.g. ONNX) run earlier in the frame and the redundant cv::Mat upload starts dropping frames.

Parameters
src_texGL texture currently containing the new frame.
w,hRegion to copy (typically the full texture size).

Definition at line 2245 of file ACMX2/acmx.cpp.

References allocateHistoryTexture(), count, finishPush(), hasStorage(), head, height, history_texture, is_hdr, num_frames, scratch_fbo, textures, use_history_array, and width.

◆ size()

std::size_t FrameCache::size ( ) const
inline

Number of frames currently retained (0 ≤ n ≤ capacity).

Definition at line 2321 of file ACMX2/acmx.cpp.

References count.

◆ textureAt()

GLuint FrameCache::textureAt ( std::size_t index) const
inline

Return the GL texture at logical index index.

Parameters
index0 = oldest retained frame, size()-1 = newest.

Definition at line 2315 of file ACMX2/acmx.cpp.

References count, head, num_frames, and textures.

Referenced by ACView::bindPassHistoryTextures().

Member Data Documentation

◆ count

std::size_t FrameCache::count = 0
private

◆ head

std::size_t FrameCache::head = 0
private

◆ height

int FrameCache::height = 0
private

◆ history_texture

GLuint FrameCache::history_texture = 0
private

Optional array-backed history ring.

Definition at line 2427 of file ACMX2/acmx.cpp.

Referenced by allocateHistoryTexture(), cleanup(), fill(), hasStorage(), historyTexture(), push(), pushFromFBO(), and pushFromTexture().

◆ is_hdr

bool FrameCache::is_hdr = false
private

Definition at line 2421 of file ACMX2/acmx.cpp.

Referenced by allocateHistoryTexture(), cleanup(), init(), pushFromFBO(), and pushFromTexture().

◆ num_frames

std::size_t FrameCache::num_frames
private

◆ scratch_fbo

GLuint FrameCache::scratch_fbo = 0
private

Scratch FBO used by pushFromTexture().

Definition at line 2426 of file ACMX2/acmx.cpp.

Referenced by cleanup(), and pushFromTexture().

◆ textures

std::vector<GLuint> FrameCache::textures
private

◆ use_history_array

bool FrameCache::use_history_array = false
private

◆ width

int FrameCache::width = 0
private

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