|
Ptex
|
Cache for reading Ptex texture files. More...
#include <PtexCache.h>
Classes | |
| struct | Purger |
| struct | MruList |
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) |
Private Types | |
| typedef PtexHashMap< StringKey, PtexCachedReader * > | FileMap |
Private Member Functions | |
| bool | findFile (const char *&filename, std::string &buffer, Ptex::String &error) |
| void | processMru () |
| void | pruneFilesIfNeeded () |
| void | pruneDataIfNeeded () |
| 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 | maxMruFiles = 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 210 of file PtexCache.h.
|
private |
Definition at line 297 of file PtexCache.h.
|
inline |
Definition at line 213 of file PtexCache.h.
References _blockReads, _err, _fileOpens, _filesOpen, _io, _maxFiles, _maxMem, _memUsed, _mruList, _mruLists, _mruLock, _peakFilesOpen, _peakMemUsed, _premultiply, _prevMruList, and CACHE_LINE_PAD_INIT.
|
inline |
Definition at line 224 of file PtexCache.h.
|
inline |
Definition at line 272 of file PtexCache.h.
References _filesOpen, _peakFilesOpen, and AtomicAdd().
Referenced by processMru().
|
inline |
Definition at line 266 of file PtexCache.h.
References _memUsed, _peakMemUsed, and AtomicAdd().
Referenced by get(), processMru(), pruneDataIfNeeded(), purge(), and purgeAll().
|
private |
|
private |
|
private |
|
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 125 of file PtexCache.cpp.
References _err, _files, _io, _premultiply, adjustMemUsed(), findFile(), PtexReader::invalidate(), PtexReader::logOpen(), PtexReader::needToOpen(), PtexReader::ok(), PtexReader::open(), PtexReader::pendingPurge(), purge(), PtexCachedReader::ref(), and PtexCachedReader::unref().
|
inlinevirtual |
Query the search path.
Returns string set via setSearchPath.
Implements PtexCache.
Definition at line 252 of file PtexCache.h.
References _searchpath.
|
virtual |
Get stats.
Implements PtexCache.
Definition at line 331 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, and PtexCache::Stats::peakMemUsed.
| void PtexReaderCache::logRecentlyUsed | ( | PtexCachedReader * | reader | ) |
Definition at line 184 of file PtexCache.cpp.
References _mruList, AtomicIncrement(), PtexReaderCache::MruList::files, maxMruFiles, PtexReaderCache::MruList::next, and processMru().
|
private |
Definition at line 200 of file PtexCache.cpp.
References _activeFiles, _blockReads, _fileOpens, _maxMem, _mruList, _mruLock, _openFiles, _prevMruList, adjustFilesOpen(), adjustMemUsed(), AtomicStore(), PtexReaderCache::MruList::files, PtexCachedReader::getBlockReadsChange(), PtexCachedReader::getMemUsedChange(), PtexCachedReader::getOpensChange(), maxMruFiles, PtexReaderCache::MruList::next, pruneDataIfNeeded(), and pruneFilesIfNeeded().
Referenced by logRecentlyUsed().
|
private |
Definition at line 268 of file PtexCache.cpp.
References _activeFiles, _maxMem, _memUsed, _mruLock, adjustMemUsed(), and PtexCachedReader::tryPrune().
Referenced by processMru().
|
private |
Definition at line 249 of file PtexCache.cpp.
References _filesOpen, _maxFiles, _mruLock, _openFiles, 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 301 of file PtexCache.cpp.
| void PtexReaderCache::purge | ( | PtexCachedReader * | reader | ) |
Definition at line 308 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 292 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 324 of file PtexCache.cpp.
References _files, adjustMemUsed(), and PtexReaderCache::Purger::memUsedChangeTotal.
|
inlinevirtual |
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
Implements PtexCache.
Definition at line 227 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 229 of file PtexCache.h.
References _searchdirs, and _searchpath.
|
private |
Definition at line 314 of file PtexCache.h.
Referenced by processMru(), and pruneDataIfNeeded().
|
private |
Definition at line 319 of file PtexCache.h.
Referenced by getStats(), processMru(), and PtexReaderCache().
|
private |
Definition at line 294 of file PtexCache.h.
Referenced by get(), and PtexReaderCache().
|
private |
Definition at line 318 of file PtexCache.h.
Referenced by getStats(), processMru(), and PtexReaderCache().
|
private |
Definition at line 298 of file PtexCache.h.
Referenced by get(), getStats(), purge(), and purgeAll().
|
private |
Definition at line 301 of file PtexCache.h.
Referenced by adjustFilesOpen(), getStats(), pruneFilesIfNeeded(), and PtexReaderCache().
|
private |
Definition at line 293 of file PtexCache.h.
Referenced by get(), and PtexReaderCache().
|
private |
Definition at line 291 of file PtexCache.h.
Referenced by pruneFilesIfNeeded(), and PtexReaderCache().
|
private |
Definition at line 292 of file PtexCache.h.
Referenced by processMru(), pruneDataIfNeeded(), and PtexReaderCache().
|
private |
Definition at line 300 of file PtexCache.h.
Referenced by adjustMemUsed(), getStats(), pruneDataIfNeeded(), and PtexReaderCache().
|
private |
Definition at line 310 of file PtexCache.h.
Referenced by logRecentlyUsed(), processMru(), and PtexReaderCache().
|
private |
Definition at line 309 of file PtexCache.h.
Referenced by PtexReaderCache().
|
private |
Definition at line 302 of file PtexCache.h.
Referenced by processMru(), pruneDataIfNeeded(), pruneFilesIfNeeded(), and PtexReaderCache().
|
private |
Definition at line 313 of file PtexCache.h.
Referenced by processMru(), and pruneFilesIfNeeded().
|
private |
Definition at line 317 of file PtexCache.h.
Referenced by adjustFilesOpen(), getStats(), and PtexReaderCache().
|
private |
Definition at line 316 of file PtexCache.h.
Referenced by adjustMemUsed(), getStats(), and PtexReaderCache().
|
private |
Definition at line 299 of file PtexCache.h.
Referenced by get(), and PtexReaderCache().
|
private |
Definition at line 311 of file PtexCache.h.
Referenced by processMru(), and PtexReaderCache().
|
private |
Definition at line 296 of file PtexCache.h.
Referenced by findFile(), and setSearchPath().
|
private |
Definition at line 295 of file PtexCache.h.
Referenced by getSearchPath(), and setSearchPath().
|
staticprivate |
Definition at line 304 of file PtexCache.h.
Referenced by logRecentlyUsed(), and processMru().