game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
ShaderCacheManager Class Reference

Service for managing shader caches. More...

#include <shader_cache_manager.h>

Classes

struct  Impl

Public Types

using ProgressCallback = std::function<void(int percent, const std::string& status)>

Public Member Functions

 ShaderCacheManager ()
 ~ShaderCacheManager ()
void addCustomCacheLocation (const std::filesystem::path &path, ShaderCacheType type)
 Add a custom cache location to scan.
std::filesystem::path backupCache (const std::filesystem::path &cachePath, const std::filesystem::path &backupDir={})
 Backup a shader cache before clearing.
CacheClearResult clearAllCaches (const ProgressCallback &progressCallback=nullptr)
 Clear all shader caches (use with caution!).
CacheClearResult clearCache (const std::filesystem::path &cachePath)
 Clear a specific cache.
CacheClearResult clearCachesByType (ShaderCacheType type, const ProgressCallback &progressCallback=nullptr)
 Clear all caches of a specific type.
CacheClearResult clearGameCache (const std::string &gameId, ShaderCacheType type=ShaderCacheType::All, const std::filesystem::path &winePrefix={}, uint32_t steamAppId=0)
 Clear shader cache for a specific game.
CacheClearResult clearStaleCaches (std::chrono::hours olderThan=std::chrono::hours(720), const ProgressCallback &progressCallback=nullptr)
 Clear old/stale caches.
std::optional< ShaderCacheInfo > findDXVKCache (const std::filesystem::path &winePrefix) const
 Find DXVK cache for a game.
std::optional< ShaderCacheInfo > findSteamShaderCache (uint32_t steamAppId) const
 Find Steam shader cache for a game.
std::optional< ShaderCacheInfo > findVKD3DCache (const std::filesystem::path &winePrefix) const
 Find VKD3D cache for a game.
std::vector< ShaderCacheInfo > getAllCaches () const
 Get all detected shader caches.
std::filesystem::path getBackupDirectory () const
 Get the backup directory.
std::vector< std::filesystem::path > getCacheBackups () const
 Get list of cache backups.
std::optional< ShaderCacheInfo > getCacheInfo (const std::filesystem::path &path) const
 Get cache info for a specific path.
std::vector< ShaderCacheInfo > getCachesByType (ShaderCacheType type) const
 Get caches by type.
int64_t getCacheSizeByType (ShaderCacheType type) const
 Get cache size by type.
std::vector< std::filesystem::path > getDefaultCacheLocations (ShaderCacheType type) const
 Get the default cache location for a type.
GameShaderCache getGameCache (const std::string &gameId, const std::filesystem::path &winePrefix={}, uint32_t steamAppId=0) const
 Get shader caches for a specific game.
ShaderCacheStats getStats () const
 Get overall shader cache statistics.
int64_t getTotalCacheSize () const
 Get total cache size.
std::optional< ShaderCacheType > identifyCacheType (const std::filesystem::path &path) const
 Check if a path is a valid shader cache.
int pruneBackups (int keepCount=3)
 Delete old cache backups.
bool restoreCache (const std::filesystem::path &backupPath, const std::filesystem::path &targetPath)
 Restore a shader cache from backup.
int scanCaches (const ProgressCallback &progressCallback=nullptr)
 Scan for all shader caches on the system.
void setBackupDirectory (const std::filesystem::path &path)
 Set the backup directory.
void setSteamLibraryPaths (const std::vector< std::filesystem::path > &paths)
 Set Steam library paths.

Detailed Description

Service for managing shader caches.

Provides methods for discovering, analyzing, and clearing shader caches to help troubleshoot graphics issues and free disk space.

Usage Example

// Get overall stats
auto stats = manager.getStats();
std::cout << "Total cache size: " << stats.getFormattedTotalSize() << std::endl;
// Clear DXVK cache for a game
manager.clearGameCache("doom-eternal", ShaderCacheType::DXVK);
// Clear all caches (careful!)
manager.clearAllCaches();
ShaderCacheStats getStats() const
Get overall shader cache statistics.
CacheClearResult clearAllCaches(const ProgressCallback &progressCallback=nullptr)
Clear all shader caches (use with caution!).
CacheClearResult clearGameCache(const std::string &gameId, ShaderCacheType type=ShaderCacheType::All, const std::filesystem::path &winePrefix={}, uint32_t steamAppId=0)
Clear shader cache for a specific game.
@ DXVK
DXVK Vulkan-based D3D implementation.
std::string getFormattedTotalSize() const

Definition at line 150 of file shader_cache_manager.h.

Member Typedef Documentation

◆ ProgressCallback

using ShaderCacheManager::ProgressCallback = std::function<void(int percent, const std::string& status)>

Definition at line 153 of file shader_cache_manager.h.

Constructor & Destructor Documentation

◆ ShaderCacheManager()

ShaderCacheManager::ShaderCacheManager ( )

Definition at line 201 of file shader_cache_manager.cpp.

References scanCaches().

◆ ~ShaderCacheManager()

ShaderCacheManager::~ShaderCacheManager ( )
default

Member Function Documentation

◆ addCustomCacheLocation()

void ShaderCacheManager::addCustomCacheLocation ( const std::filesystem::path & path,
ShaderCacheType type )

Add a custom cache location to scan.

Parameters
pathPath to scan
typeCache type

Definition at line 837 of file shader_cache_manager.cpp.

◆ backupCache()

std::filesystem::path ShaderCacheManager::backupCache ( const std::filesystem::path & cachePath,
const std::filesystem::path & backupDir = {} )

Backup a shader cache before clearing.

Parameters
cachePathCache to backup
backupDirBackup destination
Returns
Backup path, or empty on failure

Definition at line 700 of file shader_cache_manager.cpp.

◆ clearAllCaches()

CacheClearResult ShaderCacheManager::clearAllCaches ( const ProgressCallback & progressCallback = nullptr)

Clear all shader caches (use with caution!).

Parameters
progressCallbackProgress updates
Returns
Clear result

Definition at line 626 of file shader_cache_manager.cpp.

References CacheClearResult::bytesCleared, clearCache(), CacheClearResult::directoriesCleared, CacheClearResult::errors, CacheClearResult::filesCleared, getAllCaches(), and CacheClearResult::success.

◆ clearCache()

CacheClearResult ShaderCacheManager::clearCache ( const std::filesystem::path & cachePath)

Clear a specific cache.

Parameters
cachePathPath to cache directory
Returns
Clear result

Definition at line 515 of file shader_cache_manager.cpp.

References CacheClearResult::bytesCleared, CacheClearResult::directoriesCleared, CacheClearResult::errors, CacheClearResult::filesCleared, and CacheClearResult::success.

Referenced by clearAllCaches(), clearCachesByType(), clearGameCache(), clearStaleCaches(), and restoreCache().

◆ clearCachesByType()

CacheClearResult ShaderCacheManager::clearCachesByType ( ShaderCacheType type,
const ProgressCallback & progressCallback = nullptr )

Clear all caches of a specific type.

Parameters
typeCache type to clear
progressCallbackProgress updates
Returns
Clear result

Definition at line 568 of file shader_cache_manager.cpp.

References CacheClearResult::bytesCleared, clearCache(), CacheClearResult::directoriesCleared, CacheClearResult::errors, CacheClearResult::filesCleared, getCachesByType(), and CacheClearResult::success.

◆ clearGameCache()

CacheClearResult ShaderCacheManager::clearGameCache ( const std::string & gameId,
ShaderCacheType type = ShaderCacheType::All,
const std::filesystem::path & winePrefix = {},
uint32_t steamAppId = 0 )

Clear shader cache for a specific game.

Parameters
gameIdGame ID
typeCache type (or All)
winePrefixWine prefix path
steamAppIdSteam app ID
Returns
Clear result

Definition at line 600 of file shader_cache_manager.cpp.

References All, CacheClearResult::bytesCleared, clearCache(), CacheClearResult::directoriesCleared, CacheClearResult::errors, CacheClearResult::filesCleared, getGameCache(), and CacheClearResult::success.

◆ clearStaleCaches()

CacheClearResult ShaderCacheManager::clearStaleCaches ( std::chrono::hours olderThan = std::chrono::hours(720),
const ProgressCallback & progressCallback = nullptr )

Clear old/stale caches.

Parameters
olderThanClear caches older than this duration
progressCallbackProgress updates
Returns
Clear result

Definition at line 657 of file shader_cache_manager.cpp.

References CacheClearResult::bytesCleared, clearCache(), CacheClearResult::directoriesCleared, CacheClearResult::errors, CacheClearResult::filesCleared, getAllCaches(), and CacheClearResult::success.

◆ findDXVKCache()

std::optional< ShaderCacheInfo > ShaderCacheManager::findDXVKCache ( const std::filesystem::path & winePrefix) const

Find DXVK cache for a game.

Parameters
winePrefixWine prefix path
Returns
DXVK cache info if found

Definition at line 355 of file shader_cache_manager.cpp.

References DXVK, ShaderCacheInfo::exists, ShaderCacheInfo::fileCount, getCacheInfo(), ShaderCacheInfo::lastModified, ShaderCacheInfo::name, ShaderCacheInfo::path, ShaderCacheInfo::size, ShaderCacheInfo::type, and Logger::warn().

Referenced by getGameCache().

◆ findSteamShaderCache()

std::optional< ShaderCacheInfo > ShaderCacheManager::findSteamShaderCache ( uint32_t steamAppId) const

Find Steam shader cache for a game.

Parameters
steamAppIdSteam app ID
Returns
Steam shader cache info if found

Definition at line 425 of file shader_cache_manager.cpp.

References ShaderCacheInfo::exists, ShaderCacheInfo::fileCount, ShaderCacheInfo::lastModified, ShaderCacheInfo::name, ShaderCacheInfo::path, ShaderCacheInfo::size, SteamShader, and ShaderCacheInfo::type.

Referenced by getGameCache().

◆ findVKD3DCache()

std::optional< ShaderCacheInfo > ShaderCacheManager::findVKD3DCache ( const std::filesystem::path & winePrefix) const

Find VKD3D cache for a game.

Parameters
winePrefixWine prefix path
Returns
VKD3D cache info if found

Definition at line 405 of file shader_cache_manager.cpp.

References getCacheInfo().

Referenced by getGameCache().

◆ getAllCaches()

std::vector< ShaderCacheInfo > ShaderCacheManager::getAllCaches ( ) const

Get all detected shader caches.

Returns
Vector of cache info

Definition at line 212 of file shader_cache_manager.cpp.

Referenced by clearAllCaches(), and clearStaleCaches().

◆ getBackupDirectory()

std::filesystem::path ShaderCacheManager::getBackupDirectory ( ) const

Get the backup directory.

Definition at line 832 of file shader_cache_manager.cpp.

◆ getCacheBackups()

std::vector< std::filesystem::path > ShaderCacheManager::getCacheBackups ( ) const

Get list of cache backups.

Returns
Vector of backup paths

Definition at line 765 of file shader_cache_manager.cpp.

References Logger::warn().

Referenced by pruneBackups().

◆ getCacheInfo()

std::optional< ShaderCacheInfo > ShaderCacheManager::getCacheInfo ( const std::filesystem::path & path) const

Get cache info for a specific path.

Parameters
pathCache directory path
Returns
Cache info if valid cache directory

Definition at line 235 of file shader_cache_manager.cpp.

References ShaderCacheInfo::exists, ShaderCacheInfo::fileCount, identifyCacheType(), ShaderCacheInfo::lastModified, ShaderCacheInfo::name, ShaderCacheInfo::path, shaderCacheTypeName(), ShaderCacheInfo::size, and ShaderCacheInfo::type.

Referenced by findDXVKCache(), and findVKD3DCache().

◆ getCachesByType()

std::vector< ShaderCacheInfo > ShaderCacheManager::getCachesByType ( ShaderCacheType type) const

Get caches by type.

Parameters
typeCache type to filter
Returns
Vector of matching caches

Definition at line 218 of file shader_cache_manager.cpp.

References All.

Referenced by clearCachesByType(), and getCacheSizeByType().

◆ getCacheSizeByType()

int64_t ShaderCacheManager::getCacheSizeByType ( ShaderCacheType type) const

Get cache size by type.

Parameters
typeCache type
Returns
Size in bytes

Definition at line 500 of file shader_cache_manager.cpp.

References getCachesByType().

◆ getDefaultCacheLocations()

std::vector< std::filesystem::path > ShaderCacheManager::getDefaultCacheLocations ( ShaderCacheType type) const

Get the default cache location for a type.

Parameters
typeCache type
Returns
Default path(s) for this cache type

Definition at line 913 of file shader_cache_manager.cpp.

References DXVK, Fossilize, Mesa, NVIDIA, SteamShader, VKD3D, and WineState.

◆ getGameCache()

GameShaderCache ShaderCacheManager::getGameCache ( const std::string & gameId,
const std::filesystem::path & winePrefix = {},
uint32_t steamAppId = 0 ) const

Get shader caches for a specific game.

Parameters
gameIdGame ID
winePrefixWine prefix path (for DXVK/VKD3D)
steamAppIdSteam app ID (for Steam shader cache)
Returns
Game shader cache info

Definition at line 312 of file shader_cache_manager.cpp.

References GameShaderCache::caches, findDXVKCache(), findSteamShaderCache(), findVKD3DCache(), GameShaderCache::gameId, GameShaderCache::hasDXVK, GameShaderCache::hasSteamCache, GameShaderCache::hasVKD3D, and GameShaderCache::totalSize.

Referenced by clearGameCache().

◆ getStats()

◆ getTotalCacheSize()

int64_t ShaderCacheManager::getTotalCacheSize ( ) const

Get total cache size.

Returns
Size in bytes

Definition at line 495 of file shader_cache_manager.cpp.

References getStats(), and ShaderCacheStats::totalSize.

◆ identifyCacheType()

std::optional< ShaderCacheType > ShaderCacheManager::identifyCacheType ( const std::filesystem::path & path) const

Check if a path is a valid shader cache.

Parameters
pathPath to check
Returns
Cache type if valid, nullopt otherwise

Definition at line 855 of file shader_cache_manager.cpp.

References DXVK, Fossilize, Mesa, NVIDIA, SteamShader, VKD3D, and WineState.

Referenced by getCacheInfo().

◆ pruneBackups()

int ShaderCacheManager::pruneBackups ( int keepCount = 3)

Delete old cache backups.

Parameters
keepCountNumber of recent backups to keep per cache
Returns
Number of backups deleted

Definition at line 795 of file shader_cache_manager.cpp.

References getCacheBackups().

◆ restoreCache()

bool ShaderCacheManager::restoreCache ( const std::filesystem::path & backupPath,
const std::filesystem::path & targetPath )

Restore a shader cache from backup.

Parameters
backupPathBackup to restore
targetPathTarget cache location
Returns
True on success

Definition at line 738 of file shader_cache_manager.cpp.

References clearCache().

◆ scanCaches()

int ShaderCacheManager::scanCaches ( const ProgressCallback & progressCallback = nullptr)

Scan for all shader caches on the system.

Parameters
progressCallbackProgress updates
Returns
Number of caches found

Definition at line 260 of file shader_cache_manager.cpp.

Referenced by ShaderCacheManager().

◆ setBackupDirectory()

void ShaderCacheManager::setBackupDirectory ( const std::filesystem::path & path)

Set the backup directory.

Parameters
pathDirectory for cache backups

Definition at line 823 of file shader_cache_manager.cpp.

◆ setSteamLibraryPaths()

void ShaderCacheManager::setSteamLibraryPaths ( const std::vector< std::filesystem::path > & paths)

Set Steam library paths.

Parameters
pathsSteam library root paths

Definition at line 844 of file shader_cache_manager.cpp.


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