TextureCacheBase: Eliminate static state

This commit is contained in:
Lioncash
2016-09-06 18:57:58 -04:00
parent 1fa61af413
commit 58a5395173
21 changed files with 141 additions and 163 deletions

View File

@ -127,16 +127,13 @@ public:
const MathUtil::Rectangle<int>& srcrect,
const MathUtil::Rectangle<int>& dstrect) = 0;
virtual void Load(unsigned int width, unsigned int height, unsigned int expanded_width,
unsigned int level) = 0;
virtual void Load(const u8* buffer, u32 width, u32 height, u32 expanded_width, u32 level) = 0;
virtual void FromRenderTarget(u8* dst, PEControl::PixelFormat srcFormat,
const EFBRectangle& srcRect, bool scaleByHalf,
unsigned int cbufid, const float* colmat) = 0;
bool OverlapsMemoryRange(u32 range_address, u32 range_size) const;
TextureCacheBase::TCacheEntryBase* ApplyPalette(u8* palette, u32 tlutfmt);
bool IsEfbCopy() const { return is_efb_copy; }
u32 NumBlocksY() const;
u32 BytesPerRow() const;
@ -146,13 +143,13 @@ public:
virtual ~TextureCacheBase(); // needs virtual for DX11 dtor
static void OnConfigChanged(VideoConfig& config);
void OnConfigChanged(VideoConfig& config);
// Removes textures which aren't used for more than TEXTURE_KILL_THRESHOLD frames,
// frameCount is the current frame number.
static void Cleanup(int _frameCount);
void Cleanup(int _frameCount);
static void Invalidate();
void Invalidate();
virtual TCacheEntryBase* CreateTexture(const TCacheEntryConfig& config) = 0;
@ -163,13 +160,12 @@ public:
virtual bool CompileShaders() = 0;
virtual void DeleteShaders() = 0;
static TCacheEntryBase* Load(const u32 stage);
static void UnbindTextures();
TCacheEntryBase* Load(const u32 stage);
void UnbindTextures();
virtual void BindTextures();
static void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
PEControl::PixelFormat srcFormat,
const EFBRectangle& srcRect, bool isIntensity,
bool scaleByHalf);
void CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat, u32 dstStride,
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
bool isIntensity, bool scaleByHalf);
virtual void ConvertTexture(TCacheEntryBase* entry, TCacheEntryBase* unconverted, void* palette,
TlutFormat format) = 0;
@ -177,46 +173,52 @@ public:
protected:
TextureCacheBase();
alignas(16) static u8* temp;
static size_t temp_size;
alignas(16) u8* temp = nullptr;
size_t temp_size = 0;
static TCacheEntryBase* bound_textures[8];
TCacheEntryBase* bound_textures[8] = {};
private:
typedef std::multimap<u64, TCacheEntryBase*> TexCache;
typedef std::unordered_multimap<TCacheEntryConfig, TCacheEntryBase*, TCacheEntryConfig::Hasher>
TexPool;
static void ScaleTextureCacheEntryTo(TCacheEntryBase** entry, u32 new_width, u32 new_height);
static TCacheEntryBase* DoPartialTextureUpdates(TexCache::iterator iter, u8* palette,
u32 tlutfmt);
static void DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level);
static void CheckTempSize(size_t required_size);
static TCacheEntryBase* AllocateTexture(const TCacheEntryConfig& config);
static TexPool::iterator FindMatchingTextureFromPool(const TCacheEntryConfig& config);
static TexCache::iterator GetTexCacheIter(TCacheEntryBase* entry);
void SetBackupConfig(const VideoConfig& config);
TCacheEntryBase* ApplyPaletteToEntry(TCacheEntryBase* entry, u8* palette, u32 tlutfmt);
void ScaleTextureCacheEntryTo(TCacheEntryBase** entry, u32 new_width, u32 new_height);
TCacheEntryBase* DoPartialTextureUpdates(TexCache::iterator iter, u8* palette, u32 tlutfmt);
void DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level);
void CheckTempSize(size_t required_size);
TCacheEntryBase* AllocateTexture(const TCacheEntryConfig& config);
TexPool::iterator FindMatchingTextureFromPool(const TCacheEntryConfig& config);
TexCache::iterator GetTexCacheIter(TCacheEntryBase* entry);
// Removes and unlinks texture from texture cache and returns it to the pool
static TexCache::iterator InvalidateTexture(TexCache::iterator t_iter);
TexCache::iterator InvalidateTexture(TexCache::iterator t_iter);
static TCacheEntryBase* ReturnEntry(unsigned int stage, TCacheEntryBase* entry);
TCacheEntryBase* ReturnEntry(unsigned int stage, TCacheEntryBase* entry);
static TexCache textures_by_address;
static TexCache textures_by_hash;
static TexPool texture_pool;
TexCache textures_by_address;
TexCache textures_by_hash;
TexPool texture_pool;
// Backup configuration values
static struct BackupConfig
struct BackupConfig
{
int s_colorsamples;
bool s_texfmt_overlay;
bool s_texfmt_overlay_center;
bool s_hires_textures;
bool s_cache_hires_textures;
bool s_copy_cache_enable;
bool s_stereo_3d;
bool s_efb_mono_depth;
} backup_config;
int color_samples;
bool texfmt_overlay;
bool texfmt_overlay_center;
bool hires_textures;
bool cache_hires_textures;
bool copy_cache_enable;
bool stereo_3d;
bool efb_mono_depth;
};
BackupConfig backup_config = {};
};
extern std::unique_ptr<TextureCacheBase> g_texture_cache;