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

Container for the full on-disk shader cache file. More...

Public Member Functions

bool load (const std::string &path)
 Deserialise the shader cache from a binary file.
bool save (const std::string &path) const
 Serialise the entire shader cache to a binary file.

Public Attributes

bool dual_mode = false
std::vector< ShaderCacheEntry > entries
std::string gl_renderer
std::string gl_version

Static Public Attributes

static constexpr uint32_t CACHE_MAGIC = 0x53484452
 File magic: "SHDR".
static constexpr uint32_t CACHE_VERSION = 4
 Current format version.

Detailed Description

Container for the full on-disk shader cache file.

The binary file format is: [MAGIC][VERSION][gl_renderer][gl_version][dual_mode][count][entries...]

If the GL renderer or driver version changes, the cache is invalidated.

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

Member Function Documentation

◆ load()

bool ShaderCache::load ( const std::string & path)
inline

Deserialise the shader cache from a binary file.

Validates the magic number and version before reading. If either does not match (e.g. cache was written by an older version or a different application) the method returns false and leaves the object in an indeterminate state—callers should discard it.

The layout mirrors save(): magic, version, renderer string, GL version string, dual_mode flag, entry count, then each entry.

Parameters
pathFilesystem path of the cache file to read.
Returns
True on success; false if the file is missing, corrupt, or has a version / magic mismatch.

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

References CACHE_MAGIC, CACHE_VERSION, ComputeUnavailable, dual_mode, entries, gl_renderer, and gl_version.

Referenced by ShaderLibrary::loadFromCache().

◆ save()

bool ShaderCache::save ( const std::string & path) const
inline

Serialise the entire shader cache to a binary file.

File layout (all values little-endian, no padding):

Offset Field
0 uint32 CACHE_MAGIC
4 uint32 CACHE_VERSION
8 string gl_renderer
string gl_version
bool dual_mode
uint32 entry_count
entries…

Each string is written as a uint32 length followed by raw bytes. Each entry contains: shader_name (string), kind (uint8), failed (uint8), source_hash (uint64), format_2d (GLenum), binary_2d (uint32 size + raw bytes), format_3d (GLenum), binary_3d (uint32 size + raw bytes).

Parameters
pathFilesystem path for the output file (e.g. library/.shader_cache).
Returns
True if the file was written without stream errors.

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

References CACHE_MAGIC, CACHE_VERSION, dual_mode, entries, gl_renderer, and gl_version.

Referenced by ShaderLibrary::buildShaderCache(), and ShaderLibrary::loadFromCache().

Member Data Documentation

◆ CACHE_MAGIC

uint32_t ShaderCache::CACHE_MAGIC = 0x53484452
staticconstexpr

File magic: "SHDR".

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

Referenced by load(), and save().

◆ CACHE_VERSION

uint32_t ShaderCache::CACHE_VERSION = 4
staticconstexpr

Current format version.

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

Referenced by load(), and save().

◆ dual_mode

bool ShaderCache::dual_mode = false

◆ entries

std::vector<ShaderCacheEntry> ShaderCache::entries

◆ gl_renderer

std::string ShaderCache::gl_renderer

◆ gl_version

std::string ShaderCache::gl_version

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