Render Cache Configuration

In Scaleform 4.4 and higher, both the mesh and glyph caches are associated with HAL and are maintained on the render thread. This behavior is different from Scaleform 3.x where these states were configured on GFxLoader, in Scaleform 4.0-4.3, these are configured on the Renderer2D. Caches are created when the associated Render::HAL is configured by a call to InitHAL; their memory is freed when ShutdownHAL is called.

The mesh cache stores vertex and index buffer data and is usually allocated directly from video memory; it is managed by system-specific logic as part of Render::HAL. Mesh cache memory is allocated in large chunks, with the first chunk pre-allocated on HAL initialization and can then grow up to a fixed limit. Mesh cache is configured as follows:

MeshCacheParams mcp;
mcp.MemReserve          = 1024 * 1024 * 3;
mcp.MemLimit            = 1024 * 1024 * 12;
mcp.MemGranularity      = 1024 * 1024 * 3;
mcp.LRUTailSize         = 1024 * 1024 * 4;
mcp.StagingBufferSize   = 1024 * 1024 * 2;

pHAL->->SetMeshCacheParams(mcp);

Here, MemReserve defines the initial amount of cache memory allocated and MemLimit defines the maximum locatable amount. If both of these values are the same, no cache allocation will take place after initialization. MeshCache grows in blocks, specified by MemGranularity, and shrinks once there is more LRU cache content than provided for by LRUTailSize. StagingBufferSize is a system-memory buffer used for building batches; it can be set to 64K on consoles (the default value there), but must be larger on PC as it also serves as a secondary cache.

The glyph cache is used for rasterizing fonts, allowing them to be drawn efficiently from textures. Glyph cache is updated dynamically and has a fixed size determined at initialization time. It is configured as follows:

GlyphCacheParams gcp;
gcp.TextureWidth  = 1024;
gcp.TextureHeight = 1024;
gcp.NumTextures   = 1;
gcp.MaxSlotHeight = 48;

pHAL->->SetGlyphCacheParams(gcp);

TextureWidth, TextureHeight, and NumTextures define the size and number of alpha-only textures that will be allocated. MaxSlotHeight specifies the maximum height of a slot, in pixels, that will be allocated for a single glyph.

For initial settings to be modified, both caches should be configured before InitHAL is called. If SetParams is called after InitHAL, the associated cache will be flushed and memory re-allocated.