Ptex
|
Cache for reading Ptex texture files. More...
#include <PtexCache.h>
Classes | |
struct | MruList |
struct | Purger |
Public Member Functions | |
PtexReaderCache (int maxFiles, size_t maxMem, bool premultiply, PtexInputHandler *inputHandler, PtexErrorHandler *errorHandler) | |
~PtexReaderCache () | |
virtual void | release () |
Release PtexCache. Cache will be immediately destroyed and all resources will be released. | |
virtual void | setSearchPath (const char *path) |
Set a search path for finding textures. | |
virtual const char * | getSearchPath () |
Query the search path. | |
virtual PtexTexture * | get (const char *path, Ptex::String &error) |
Access a texture. | |
virtual void | purge (PtexTexture *) |
Remove a texture file from the cache. | |
virtual void | purge (const char *) |
Remove a texture file from the cache by pathname. | |
virtual void | purgeAll () |
Remove all texture files from the cache. | |
virtual void | getStats (Stats &stats) |
Get stats. | |
void | purge (PtexCachedReader *reader) |
void | adjustMemUsed (size_t amount) |
void | adjustFilesOpen (size_t amount) |
void | logRecentlyUsed (PtexCachedReader *reader) |
virtual void | release ()=0 |
Release PtexCache. Cache will be immediately destroyed and all resources will be released. | |
virtual void | setSearchPath (const char *path)=0 |
Set a search path for finding textures. | |
virtual const char * | getSearchPath ()=0 |
Query the search path. | |
virtual PtexTexture * | get (const char *path, Ptex::String &error)=0 |
Access a texture. | |
virtual void | purge (PtexTexture *texture)=0 |
Remove a texture file from the cache. | |
virtual void | purge (const char *path)=0 |
Remove a texture file from the cache by pathname. | |
virtual void | purgeAll ()=0 |
Remove all texture files from the cache. | |
virtual void | getStats (Stats &stats)=0 |
Get stats. | |
Private Types | |
typedef PtexHashMap< StringKey, PtexCachedReader * > | FileMap |
Private Member Functions | |
bool | findFile (const char *&filename, std::string &buffer, Ptex::String &error) |
void | processMru () |
void | pruneFiles () |
void | pruneData () |
CACHE_LINE_PAD (_memUsed, size_t) | |
CACHE_LINE_PAD (_filesOpen, size_t) | |
CACHE_LINE_PAD (_mruLock, Mutex) | |
Private Attributes | |
size_t | _maxFiles |
size_t | _maxMem |
PtexInputHandler * | _io |
PtexErrorHandler * | _err |
std::string | _searchpath |
std::vector< std::string > | _searchdirs |
FileMap | _files |
bool | _premultiply |
volatile size_t | _memUsed |
volatile size_t | _filesOpen |
Mutex | _mruLock |
MruList | _mruLists [2] |
MruList *volatile | _mruList |
MruList *volatile | _prevMruList |
PtexLruList< PtexCachedReader, &PtexCachedReader::_openFilesItem > | _openFiles |
PtexLruList< PtexCachedReader, &PtexCachedReader::_activeFilesItem > | _activeFiles |
size_t | _peakMemUsed |
size_t | _peakFilesOpen |
size_t | _fileOpens |
size_t | _blockReads |
Static Private Attributes | |
static const int | numMruFiles = 50 |
Additional Inherited Members | |
Static Public Member Functions inherited from PtexCache | |
static PtexCache * | create (int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0) |
Create a cache with the specified limits. | |
Protected Member Functions inherited from PtexCache | |
virtual | ~PtexCache () |
Destructor not for public use. Use release() instead. | |
Cache for reading Ptex texture files.
Definition at line 197 of file PtexCache.h.
|
private |
Definition at line 284 of file PtexCache.h.
|
inline |
Definition at line 200 of file PtexCache.h.
References _filesOpen, _memUsed, _mruLists, _mruLock, and CACHE_LINE_PAD_INIT.
|
inline |
Definition at line 211 of file PtexCache.h.
|
inline |
Definition at line 259 of file PtexCache.h.
References _filesOpen, _peakFilesOpen, and AtomicAdd().
Referenced by processMru().
|
inline |
Definition at line 253 of file PtexCache.h.
References _memUsed, _peakMemUsed, and AtomicAdd().
Referenced by get(), processMru(), pruneData(), purge(), and purgeAll().
|
private |
|
private |
|
private |
Definition at line 91 of file PtexCache.cpp.
References _searchdirs, and Ptex::String::c_str().
Referenced by get().
|
virtual |
Access a texture.
If the specified path was previously accessed from the cache, then a pointer to the cached texture will be returned.
If the specified path hasn't been opened yet or was purged from the cache (via the purge or purgeAll methods) then the file will be opened. If the path is relative (i.e. doesn't begin with a '/') then the search path will be used to locate the file.
The texture will be accessible until the PtexTexture::release method is called, at which point the texture will be returned to the cache. Once released, the texture may have it's data pruned (immediately or some time later) to stay within the maximum cache size.
If the texture could not be opened, null will be returned and an error string will be set. If an error were previously encountered with the file (include the file not being found), null will be returned and no error string will be set.
path | File path. If path is relative, search path will be used to find the file. |
error | Error string set if texture could not be opened. |
Implements PtexCache.
Definition at line 121 of file PtexCache.cpp.
References _err, _files, _io, _premultiply, adjustMemUsed(), findFile(), PtexHashMap< Key, Value >::get(), PtexReader::invalidate(), PtexReader::logOpen(), PtexReader::needToOpen(), PtexReader::ok(), PtexReader::open(), PtexReader::pendingPurge(), purge(), PtexCachedReader::ref(), PtexHashMap< Key, Value >::tryInsert(), and PtexCachedReader::unref().
|
inlinevirtual |
Query the search path.
Returns string set via setSearchPath.
Implements PtexCache.
Definition at line 239 of file PtexCache.h.
References _searchpath.
|
virtual |
Get stats.
Implements PtexCache.
Definition at line 326 of file PtexCache.cpp.
References _blockReads, _fileOpens, _files, _filesOpen, _memUsed, _peakFilesOpen, _peakMemUsed, PtexCache::Stats::blockReads, PtexCache::Stats::fileReopens, PtexCache::Stats::filesAccessed, PtexCache::Stats::filesOpen, PtexCache::Stats::memUsed, PtexCache::Stats::peakFilesOpen, PtexCache::Stats::peakMemUsed, and PtexHashMap< Key, Value >::size().
void PtexReaderCache::logRecentlyUsed | ( | PtexCachedReader * | reader | ) |
Definition at line 188 of file PtexCache.cpp.
References _mruList, AtomicIncrement(), PtexReaderCache::MruList::files, PtexReaderCache::MruList::next, numMruFiles, and processMru().
Referenced by PtexCachedReader::release().
|
private |
Definition at line 203 of file PtexCache.cpp.
References _activeFiles, _blockReads, _fileOpens, _filesOpen, _maxFiles, _maxMem, _memUsed, _mruList, _mruLock, _openFiles, _prevMruList, adjustFilesOpen(), adjustMemUsed(), AtomicStore(), PtexReaderCache::MruList::files, PtexCachedReader::getBlockReadsChange(), PtexCachedReader::getMemUsedChange(), PtexCachedReader::getOpensChange(), PtexReaderCache::MruList::next, numMruFiles, pruneData(), pruneFiles(), PtexLruList< T, item >::push(), Mutex::trylock(), and Mutex::unlock().
Referenced by logRecentlyUsed().
|
private |
Definition at line 270 of file PtexCache.cpp.
References _activeFiles, _maxMem, _memUsed, adjustMemUsed(), PtexLruList< T, item >::pop(), and PtexCachedReader::tryPrune().
Referenced by processMru().
|
private |
Definition at line 254 of file PtexCache.cpp.
References _filesOpen, _maxFiles, _openFiles, PtexLruList< T, item >::pop(), and PtexReader::tryClose().
Referenced by processMru().
|
virtual |
Remove a texture file from the cache by pathname.
The path must match the full path as opened. This function will not search for the file, but if a search path was used, the path must match the path as found by the search path.
Implements PtexCache.
Definition at line 296 of file PtexCache.cpp.
References _files, PtexHashMap< Key, Value >::get(), and purge().
void PtexReaderCache::purge | ( | PtexCachedReader * | reader | ) |
Definition at line 303 of file PtexCache.cpp.
References adjustMemUsed(), and PtexCachedReader::tryPurge().
|
virtual |
Remove a texture file from the cache.
If the texture is in use by another thread, that reference will remain valid and the file will be purged once it is no longer in use. This texture should be released immediately after purging.
Implements PtexCache.
Definition at line 287 of file PtexCache.cpp.
References purge(), PtexCachedReader::ref(), and PtexCachedReader::unref().
|
virtual |
Remove all texture files from the cache.
Textures with active PtexTexture* handles will remain valid and will be purged upon release.
Implements PtexCache.
Definition at line 319 of file PtexCache.cpp.
References _files, adjustMemUsed(), PtexHashMap< Key, Value >::foreach(), and PtexReaderCache::Purger::memUsedChangeTotal.
|
inlinevirtual |
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
Implements PtexCache.
Definition at line 214 of file PtexCache.h.
|
inlinevirtual |
Set a search path for finding textures.
Note: if an input handler is installed the search path will be ignored.
path | colon-delimited search path. |
Implements PtexCache.
Definition at line 216 of file PtexCache.h.
References _searchdirs, and _searchpath.
|
private |
Definition at line 301 of file PtexCache.h.
Referenced by processMru(), and pruneData().
|
private |
Definition at line 306 of file PtexCache.h.
Referenced by getStats(), and processMru().
|
private |
Definition at line 281 of file PtexCache.h.
Referenced by get().
|
private |
Definition at line 305 of file PtexCache.h.
Referenced by getStats(), and processMru().
|
private |
Definition at line 285 of file PtexCache.h.
Referenced by get(), getStats(), purge(), and purgeAll().
|
private |
Definition at line 288 of file PtexCache.h.
Referenced by adjustFilesOpen(), getStats(), processMru(), pruneFiles(), and PtexReaderCache().
|
private |
Definition at line 280 of file PtexCache.h.
Referenced by get().
|
private |
Definition at line 278 of file PtexCache.h.
Referenced by processMru(), and pruneFiles().
|
private |
Definition at line 279 of file PtexCache.h.
Referenced by processMru(), and pruneData().
|
private |
Definition at line 287 of file PtexCache.h.
Referenced by adjustMemUsed(), getStats(), processMru(), pruneData(), and PtexReaderCache().
|
private |
Definition at line 297 of file PtexCache.h.
Referenced by logRecentlyUsed(), and processMru().
|
private |
Definition at line 296 of file PtexCache.h.
Referenced by PtexReaderCache().
|
private |
Definition at line 289 of file PtexCache.h.
Referenced by processMru(), and PtexReaderCache().
|
private |
Definition at line 300 of file PtexCache.h.
Referenced by processMru(), and pruneFiles().
|
private |
Definition at line 304 of file PtexCache.h.
Referenced by adjustFilesOpen(), and getStats().
|
private |
Definition at line 303 of file PtexCache.h.
Referenced by adjustMemUsed(), and getStats().
|
private |
Definition at line 286 of file PtexCache.h.
Referenced by get().
|
private |
Definition at line 298 of file PtexCache.h.
Referenced by processMru().
|
private |
Definition at line 283 of file PtexCache.h.
Referenced by findFile(), and setSearchPath().
|
private |
Definition at line 282 of file PtexCache.h.
Referenced by getSearchPath(), and setSearchPath().
|
staticprivate |
Definition at line 291 of file PtexCache.h.
Referenced by logRecentlyUsed(), and processMru().