MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / CTextureCache

Class CTextureCache

Source/HLEGraphics/TextureCache.h:34–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33
34class CTextureCache : public CSingleton< CTextureCache >
35{
36public:
37 CTextureCache();
38 virtual ~CTextureCache();
39
40 CRefPtr<CNativeTexture> GetOrCreateTexture(const TextureInfo & ti);
41
42 void PurgeOldTextures();
43 void DropTextures();
44
45
46#ifdef DAEDALUS_DEBUG_DISPLAYLIST
47 Mutex * GetDebugMutex() { return &mDebugMutex; }
48 struct STextureInfoSnapshot
49 {
50 STextureInfoSnapshot( const TextureInfo & info, CNativeTexture * texture )
51 : Info( info ), Texture( texture )
52 {
53 }
54
55 TextureInfo Info;
56 CRefPtr<CNativeTexture> Texture;
57 };
58
59 // You must have a valid lock to call Snapshot.
60 void Snapshot(const MutexLock & lock, std::vector< STextureInfoSnapshot > & snapshot) const;
61#else
62 // Don't bother locking if we're not debugging.
63 Mutex * GetDebugMutex() { return nullptr; }
64#endif
65
66private:
67 CachedTexture * GetOrCreateCachedTexture(const TextureInfo & ti);
68
69 //
70 // We implement a 2-way skewed associative cache.
71 // Each TextureInfo is hashed using two different methods, to reduce the chance of collisions
72 //
73 static const u32 HASH_TABLE_BITS {9};
74 static const u32 HASH_TABLE_SIZE {1<<HASH_TABLE_BITS};
75
76 inline static u32 MakeHashIdxA( const TextureInfo & ti );
77 inline static u32 MakeHashIdxB( const TextureInfo & ti );
78
79 // FIXME(strmnnrmn): we should have a struct of TextureInfo+CachedTexture instead -
80 // doing binary search on this array needs a memory indirect for every probe.
81 typedef std::vector< CachedTexture * > TextureVec;
82 TextureVec mTextures;
83 CachedTexture * mpCacheHashTable[HASH_TABLE_SIZE];
84#ifdef DAEDALUS_DEBUG_DISPLAYLIST
85 Mutex mDebugMutex;
86#endif
87};
88
89#endif // HLEGRAPHICS_TEXTURECACHE_H_

Callers 1

TextureCache.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected