(view as text)
diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp
index 27bee72..5e8c2c5 100644
--- a/Source/Core/VideoBackends/D3D/TextureCache.cpp
+++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp
@@ -81,33 +81,17 @@ void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
- unsigned int height, unsigned int expanded_width,
- unsigned int tex_levels, PC_TexFormat pcfmt)
+ unsigned int height, unsigned int tex_levels)
{
- D3D11_USAGE usage = D3D11_USAGE_DEFAULT;
- D3D11_CPU_ACCESS_FLAG cpu_access = (D3D11_CPU_ACCESS_FLAG)0;
- D3D11_SUBRESOURCE_DATA srdata, *data = NULL;
-
- if (tex_levels == 1)
- {
- usage = D3D11_USAGE_DYNAMIC;
- cpu_access = D3D11_CPU_ACCESS_WRITE;
-
- srdata.pSysMem = TextureCache::temp;
- srdata.SysMemPitch = 4 * expanded_width;
-
- data = &srdata;
- }
-
const D3D11_TEXTURE2D_DESC texdesc = CD3D11_TEXTURE2D_DESC(DXGI_FORMAT_R8G8B8A8_UNORM,
- width, height, 1, tex_levels, D3D11_BIND_SHADER_RESOURCE, usage, cpu_access);
+ width, height, 1, tex_levels, D3D11_BIND_SHADER_RESOURCE, D3D11_USAGE_DEFAULT, (D3D11_CPU_ACCESS_FLAG)0);
ID3D11Texture2D *pTexture;
- const HRESULT hr = D3D::device->CreateTexture2D(&texdesc, data, &pTexture);
+ const HRESULT hr = D3D::device->CreateTexture2D(&texdesc, NULL, &pTexture);
CHECK(SUCCEEDED(hr), "Create texture of the TextureCache");
- TCacheEntry* const entry = new TCacheEntry(new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE));
- entry->usage = usage;
+ TCacheEntry* const entry = new TCacheEntry(new D3DTexture2D(pTexture, D3D11_BIND_SHADER_RESOURCE), width, height, tex_levels, false);
+ entry->usage = D3D11_USAGE_DEFAULT;
// TODO: better debug names
D3D::SetDebugObjectName((ID3D11DeviceChild*)entry->texture->GetTex(), "a texture of the TextureCache");
@@ -115,9 +99,6 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
SAFE_RELEASE(pTexture);
- if (tex_levels != 1)
- entry->Load(width, height, expanded_width, 0);
-
return entry;
}
@@ -192,7 +173,8 @@ TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
{
return new TCacheEntry(D3DTexture2D::Create(scaled_tex_w, scaled_tex_h,
(D3D11_BIND_FLAG)((int)D3D11_BIND_RENDER_TARGET | (int)D3D11_BIND_SHADER_RESOURCE),
- D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM));
+ D3D11_USAGE_DEFAULT, DXGI_FORMAT_R8G8B8A8_UNORM),
+ scaled_tex_w, scaled_tex_h, 1, true);
}
TextureCache::TextureCache()
diff --git a/Source/Core/VideoBackends/D3D/TextureCache.h b/Source/Core/VideoBackends/D3D/TextureCache.h
index 91603bc..2475c1c 100644
--- a/Source/Core/VideoBackends/D3D/TextureCache.h
+++ b/Source/Core/VideoBackends/D3D/TextureCache.h
@@ -24,7 +24,8 @@ private:
D3D11_USAGE usage;
- TCacheEntry(D3DTexture2D *_tex) : texture(_tex) {}
+ inline TCacheEntry(D3DTexture2D *_tex, u32 width, u32 height, u32 _num_mipmaps, bool _is_efb_copy)
+ : TCacheEntryBase(width, height, _num_mipmaps, _is_efb_copy), texture(_tex) {}
~TCacheEntry();
void Load(unsigned int width, unsigned int height,
@@ -40,7 +41,7 @@ private:
};
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
- unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt);
+ unsigned int tex_levels);
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h);
u64 EncodeToRamFromTexture(u32 address, void* source_texture, u32 SourceW, u32 SourceH, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source) {return 0;};
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp
index c4a89b0..6d6ae56 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.cpp
+++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp
@@ -96,7 +96,8 @@ TextureCache::TCacheEntry::~TCacheEntry()
}
}
-TextureCache::TCacheEntry::TCacheEntry()
+TextureCache::TCacheEntry::TCacheEntry(u32 width, u32 height, u32 _num_mipmaps, bool _is_efb_copy)
+: TCacheEntryBase(width, height, _num_mipmaps, _is_efb_copy)
{
glGenTextures(1, &texture);
GL_REPORT_ERRORD();
@@ -125,76 +126,15 @@ bool TextureCache::TCacheEntry::Save(const std::string filename, unsigned int le
}
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
- unsigned int height, unsigned int expanded_width,
- unsigned int tex_levels, PC_TexFormat pcfmt)
+ unsigned int height, unsigned int tex_levels)
{
- int gl_format = 0,
- gl_iformat = 0,
- gl_type = 0;
-
- if (pcfmt != PC_TEX_FMT_DXT1)
- {
- switch (pcfmt)
- {
- default:
- case PC_TEX_FMT_NONE:
- PanicAlert("Invalid PC texture format %i", pcfmt);
- case PC_TEX_FMT_BGRA32:
- gl_format = GL_BGRA;
- gl_iformat = GL_RGBA;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_RGBA32:
- gl_format = GL_RGBA;
- gl_iformat = GL_RGBA;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- case PC_TEX_FMT_I4_AS_I8:
- gl_format = GL_LUMINANCE;
- gl_iformat = GL_INTENSITY4;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_IA4_AS_IA8:
- gl_format = GL_LUMINANCE_ALPHA;
- gl_iformat = GL_LUMINANCE4_ALPHA4;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_I8:
- gl_format = GL_LUMINANCE;
- gl_iformat = GL_INTENSITY8;
- gl_type = GL_UNSIGNED_BYTE;
- break;
-
- case PC_TEX_FMT_IA8:
- gl_format = GL_LUMINANCE_ALPHA;
- gl_iformat = GL_LUMINANCE8_ALPHA8;
- gl_type = GL_UNSIGNED_BYTE;
- break;
- case PC_TEX_FMT_RGB565:
- gl_format = GL_RGB;
- gl_iformat = GL_RGB;
- gl_type = GL_UNSIGNED_SHORT_5_6_5;
- break;
- }
- }
-
- TCacheEntry &entry = *new TCacheEntry;
- entry.gl_format = gl_format;
- entry.gl_iformat = gl_iformat;
- entry.gl_type = gl_type;
- entry.pcfmt = pcfmt;
+ TCacheEntry &entry = *new TCacheEntry(width, height, tex_levels, false);
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D, entry.texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex_levels - 1);
- entry.Load(width, height, expanded_width, 0);
-
- // This isn't needed as Load() also reset the stage in the end
- //TextureCache::SetStage();
+ TextureCache::SetStage();
return &entry;
}
@@ -202,45 +142,32 @@ TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
unsigned int expanded_width, unsigned int level)
{
- if (pcfmt != PC_TEX_FMT_DXT1)
- {
- glActiveTexture(GL_TEXTURE0+9);
- glBindTexture(GL_TEXTURE_2D, texture);
+ glActiveTexture(GL_TEXTURE0+9);
+ glBindTexture(GL_TEXTURE_2D, texture);
- if (expanded_width != width)
- glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
+ if (expanded_width != width)
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
- glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
+ glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
- if (expanded_width != width)
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
- }
- else
- {
- PanicAlert("PC_TEX_FMT_DXT1 support disabled");
- //glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
- //width, height, 0, expanded_width * expanded_height/2, temp);
- }
- TextureCache::SetStage();
+ if (expanded_width != width)
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+ TextureCache::SetStage();
GL_REPORT_ERRORD();
}
TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
unsigned int scaled_tex_w, unsigned int scaled_tex_h)
{
- TCacheEntry *const entry = new TCacheEntry;
+ TCacheEntry *const entry = new TCacheEntry(scaled_tex_w, scaled_tex_h, 1, true);
+
glActiveTexture(GL_TEXTURE0+9);
glBindTexture(GL_TEXTURE_2D, entry->texture);
GL_REPORT_ERRORD();
- const GLenum
- gl_format = GL_RGBA,
- gl_iformat = GL_RGBA,
- gl_type = GL_UNSIGNED_BYTE;
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
- glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, scaled_tex_w, scaled_tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glGenFramebuffers(1, &entry->framebuffer);
diff --git a/Source/Core/VideoBackends/OGL/TextureCache.h b/Source/Core/VideoBackends/OGL/TextureCache.h
index 3c0e421..a2bb34e 100644
--- a/Source/Core/VideoBackends/OGL/TextureCache.h
+++ b/Source/Core/VideoBackends/OGL/TextureCache.h
@@ -28,16 +28,9 @@ private:
GLuint texture;
GLuint framebuffer;
- PC_TexFormat pcfmt;
+ int m_tex_levels;
- int gl_format;
- int gl_iformat;
- int gl_type;
-
- //TexMode0 mode; // current filter and clamp modes that texture is set to
- //TexMode1 mode1; // current filter and clamp modes that texture is set to
-
- TCacheEntry();
+ TCacheEntry(u32 width, u32 height, u32 _num_mipmaps, bool _is_efb_copy);
~TCacheEntry();
void Load(unsigned int width, unsigned int height,
@@ -55,7 +48,7 @@ private:
~TextureCache();
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
- unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt) override;
+ unsigned int tex_levels) override;
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
};
diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp
index 8121920..01088a6 100644
--- a/Source/Core/VideoCommon/Statistics.cpp
+++ b/Source/Core/VideoCommon/Statistics.cpp
@@ -28,6 +28,7 @@ char *Statistics::ToString(char *ptr)
char *p = ptr;
ptr+=sprintf(ptr,"Textures created: %i\n",stats.numTexturesCreated);
ptr+=sprintf(ptr,"Textures alive: %i\n",stats.numTexturesAlive);
+ ptr+=sprintf(ptr,"Textures uploaded: %i\n",stats.numTexturesUploaded);
ptr+=sprintf(ptr,"pshaders created: %i\n",stats.numPixelShadersCreated);
ptr+=sprintf(ptr,"pshaders alive: %i\n",stats.numPixelShadersAlive);
ptr+=sprintf(ptr,"pshaders (unique, delete cache first): %i\n",stats.numUniquePixelShaders);
diff --git a/Source/Core/VideoCommon/Statistics.h b/Source/Core/VideoCommon/Statistics.h
index daa8700..aba98dc 100644
--- a/Source/Core/VideoCommon/Statistics.h
+++ b/Source/Core/VideoCommon/Statistics.h
@@ -17,6 +17,7 @@ struct Statistics
int numTexturesCreated;
int numTexturesAlive;
+ int numTexturesUploaded;
int numRenderTargetsCreated;
int numRenderTargetsAlive;
diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp
index a3224bc..6050c41 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.cpp
+++ b/Source/Core/VideoCommon/TextureCacheBase.cpp
@@ -29,6 +29,7 @@ GC_ALIGNED16(u8 *TextureCache::temp) = NULL;
unsigned int TextureCache::temp_size;
TextureCache::TexCache TextureCache::textures;
+TextureCache::TexPool TextureCache::texPool;
TextureCache::BackupConfig TextureCache::backup_config;
@@ -61,13 +62,13 @@ void TextureCache::RequestInvalidateTextureCache()
void TextureCache::Invalidate()
{
- TexCache::iterator
- iter = textures.begin(),
- tcend = textures.end();
- for (; iter != tcend; ++iter)
- delete iter->second;
-
+ for (auto i : textures)
+ delete i.second;
textures.clear();
+
+ for(auto i : texPool)
+ delete i.second;
+ texPool.clear();
}
TextureCache::~TextureCache()
@@ -133,9 +134,9 @@ void TextureCache::Cleanup()
if ( frameCount > TEXTURE_KILL_THRESHOLD + iter->second->frameCount
// EFB copies living on the host GPU are unrecoverable and thus shouldn't be deleted
- && ! iter->second->IsEfbCopy() )
+ && ! iter->second->is_efb_copy )
{
- delete iter->second;
+ PoolTexture(iter->second);
textures.erase(iter++);
}
else
@@ -155,7 +156,7 @@ void TextureCache::InvalidateRange(u32 start_address, u32 size)
const int rangePosition = iter->second->IntersectsMemoryRange(start_address, size);
if (0 == rangePosition)
{
- delete iter->second;
+ PoolTexture(iter->second);
textures.erase(iter++);
}
else
@@ -215,7 +216,7 @@ void TextureCache::ClearRenderTargets()
{
if (iter->second->type == TCET_EC_VRAM)
{
- delete iter->second;
+ PoolTexture(iter->second);
textures.erase(iter++);
}
else
@@ -400,11 +401,11 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
{
// 1. Calculate reference hash:
// calculated from RAM texture data for normal textures. Hashes for paletted textures are modified by tlut_hash. 0 for virtual EFB copies.
- if (g_ActiveConfig.bCopyEFBToTexture && entry->IsEfbCopy())
+ if (g_ActiveConfig.bCopyEFBToTexture && entry->is_efb_copy)
tex_hash = TEXHASH_INVALID;
// 2. a) For EFB copies, only the hash and the texture address need to match
- if (entry->IsEfbCopy() && tex_hash == entry->hash && address == entry->addr)
+ if (entry->is_efb_copy && tex_hash == entry->hash && address == entry->addr)
{
entry->type = TCET_EC_VRAM;
@@ -422,22 +423,9 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
}
// 3. If we reach this line, we'll have to upload the new texture data to VRAM.
- // If we're lucky, the texture parameters didn't change and we can reuse the internal texture object instead of destroying and recreating it.
- //
- // TODO: Don't we need to force texture decoding to RGBA8 for dynamic EFB copies?
- // TODO: Actually, it should be enough if the internal texture format matches...
- if ((entry->type == TCET_NORMAL && width == entry->virtual_width && height == entry->virtual_height
- && full_format == entry->format && entry->num_mipmaps > maxlevel)
- || (entry->type == TCET_EC_DYNAMIC && entry->native_width == width && entry->native_height == height))
- {
- // reuse the texture
- }
- else
- {
- // delete the texture and make a new one
- delete entry;
- entry = NULL;
- }
+ // delete the texture and make a new one
+ PoolTexture(entry);
+ entry = NULL;
}
bool using_custom_texture = false;
@@ -452,13 +440,6 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
{
expandedWidth = width;
expandedHeight = height;
-
- // If we thought we could reuse the texture before, make sure to pool it now!
- if(entry)
- {
- delete entry;
- entry = NULL;
- }
}
using_custom_texture = true;
}
@@ -485,33 +466,20 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
texLevels = (use_native_mips || using_custom_lods) ? texLevels : 1; // TODO: Should be forced to 1 for non-pow2 textures (e.g. efb copies with automatically adjusted IR)
// create the entry/texture
- if (NULL == entry)
- {
- textures[texID] = entry = g_texture_cache->CreateTexture(width, height, expandedWidth, texLevels, pcfmt);
+ textures[texID] = entry = GetOrCreateTexture ( width, height, texLevels, false );
- // Sometimes, we can get around recreating a texture if only the number of mip levels changes
- // e.g. if our texture cache entry got too many mipmap levels we can limit the number of used levels by setting the appropriate render states
- // Thus, we don't update this member for every Load, but just whenever the texture gets recreated
+ entry->type = TCET_NORMAL;
- // TODO: This is the wrong value. We should be storing the number of levels our actual texture has.
- // But that will currently make the above "existing entry" tests fail as "texLevels" is not calculated until after.
- // Currently, we might try to reuse a texture which appears to have more levels than actual, maybe..
- entry->num_mipmaps = maxlevel + 1;
- entry->type = TCET_NORMAL;
+ GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
+
+ // load texture lvl 0
+ entry->Load(width, height, expandedWidth, 0);
- GFX_DEBUGGER_PAUSE_AT(NEXT_NEW_TEXTURE, true);
- }
- else
- {
- // load texture (CreateTexture also loads level 0)
- entry->Load(width, height, expandedWidth, 0);
- }
-
- entry->SetGeneralParameters(address, texture_size, full_format, entry->num_mipmaps);
- entry->SetDimensions(nativeW, nativeH, width, height);
+ entry->SetGeneralParameters(address, texture_size, full_format);
+ entry->SetDimensions(nativeW, nativeH);
entry->hash = tex_hash;
- if (entry->IsEfbCopy() && !g_ActiveConfig.bCopyEFBToTexture)
+ if (entry->is_efb_copy && !g_ActiveConfig.bCopyEFBToTexture)
entry->type = TCET_EC_DYNAMIC;
else
entry->type = TCET_NORMAL;
@@ -567,9 +535,8 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage,
}
}
- INCSTAT(stats.numTexturesCreated);
- SETSTAT(stats.numTexturesAlive, textures.size());
-
+ SETSTAT(stats.numTexturesAlive, textures.size() + texPool.size());
+ INCSTAT(stats.numTexturesUploaded);
return ReturnEntry(stage, entry);
}
@@ -866,7 +833,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
else if (!(entry->type == TCET_EC_VRAM && entry->virtual_width == scaled_tex_w && entry->virtual_height == scaled_tex_h))
{
// remove it and recreate it as a render target
- delete entry;
+ PoolTexture(entry);
entry = NULL;
}
}
@@ -874,11 +841,11 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
if (NULL == entry)
{
// create the texture
- textures[dstAddr] = entry = g_texture_cache->CreateRenderTargetTexture(scaled_tex_w, scaled_tex_h);
+ textures[dstAddr] = entry = GetOrCreateTexture ( scaled_tex_w, scaled_tex_h, 1, true );
// TODO: Using the wrong dstFormat, dumb...
- entry->SetGeneralParameters(dstAddr, 0, dstFormat, 1);
- entry->SetDimensions(tex_w, tex_h, scaled_tex_w, scaled_tex_h);
+ entry->SetGeneralParameters(dstAddr, 0, dstFormat);
+ entry->SetDimensions(tex_w, tex_h);
entry->SetHashes(TEXHASH_INVALID);
entry->type = TCET_EC_VRAM;
}
@@ -887,3 +854,38 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat
entry->FromRenderTarget(dstAddr, dstFormat, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);
}
+
+TextureCache::TCacheEntryBase* TextureCache::GetOrCreateTexture ( u32 width, u32 height, u32 maxlevel, bool isEfbCopy )
+{
+ TCacheEntryBase* entry = NULL;
+ std::pair<TexPool::iterator, TexPool::iterator> bounds;
+ bounds = texPool.equal_range(std::make_pair(width, height));
+ while(bounds.first != bounds.second) {
+ entry = bounds.first->second;
+ if (isEfbCopy == entry->is_efb_copy && entry->num_mipmaps == maxlevel)
+ {
+ texPool.erase(bounds.first);
+ return entry;
+ }
+ bounds.first++;
+ }
+
+ // no matching texture found, so create a new one
+ if(isEfbCopy)
+ {
+ entry = g_texture_cache->CreateRenderTargetTexture(width, height);
+ }
+ else
+ {
+ entry = g_texture_cache->CreateTexture(width, height, maxlevel);
+ }
+
+ INCSTAT(stats.numTexturesCreated);
+ return entry;
+}
+
+void TextureCache::PoolTexture(TextureCache::TCacheEntryBase* entry)
+{
+ entry->frameCount = frameCount;
+ texPool.insert(std::make_pair(std::make_pair(entry->virtual_width, entry->virtual_height), entry));
+}
diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h
index f459dab..5d7dc72 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.h
+++ b/Source/Core/VideoCommon/TextureCacheBase.h
@@ -38,28 +38,29 @@ public:
enum TexCacheEntryType type;
- unsigned int num_mipmaps;
unsigned int native_width, native_height; // Texture dimensions from the GameCube's point of view
- unsigned int virtual_width, virtual_height; // Texture dimensions from OUR point of view - for hires textures or scaled EFB copies
+ const unsigned int virtual_width, virtual_height; // Texture dimensions from OUR point of view - for hires textures or scaled EFB copies
+ const unsigned int num_mipmaps;
+ const bool is_efb_copy;
// used to delete textures which haven't been used for TEXTURE_KILL_THRESHOLD frames
int frameCount;
+
+ inline TCacheEntryBase(u32 width, u32 height, u32 _num_mipmaps, bool _is_efb_copy)
+ : virtual_width(width), virtual_height(height), num_mipmaps(_num_mipmaps), is_efb_copy(_is_efb_copy)
+ {}
-
- void SetGeneralParameters(u32 _addr, u32 _size, u32 _format, unsigned int _num_mipmaps)
+ void SetGeneralParameters(u32 _addr, u32 _size, u32 _format)
{
addr = _addr;
size_in_bytes = _size;
format = _format;
- num_mipmaps = _num_mipmaps;
}
- void SetDimensions(unsigned int _native_width, unsigned int _native_height, unsigned int _virtual_width, unsigned int _virtual_height)
+ void SetDimensions(unsigned int _native_width, unsigned int _native_height)
{
native_width = _native_width;
native_height = _native_height;
- virtual_width = _virtual_width;
- virtual_height = _virtual_height;
}
void SetHashes(u64 _hash/*, u32 _pal_hash*/)
@@ -82,8 +83,6 @@ public:
const float *colmat) = 0;
int IntersectsMemoryRange(u32 range_address, u32 range_size) const;
-
- bool IsEfbCopy() { return (type == TCET_EC_VRAM || type == TCET_EC_DYNAMIC); }
};
virtual ~TextureCache(); // needs virtual for DX11 dtor
@@ -98,7 +97,7 @@ public:
static bool Find(u32 start_address, u64 hash);
virtual TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
- unsigned int expanded_width, unsigned int tex_levels, PC_TexFormat pcfmt) = 0;
+ unsigned int tex_levels) = 0;
virtual TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) = 0;
static TCacheEntryBase* Load(unsigned int stage, u32 address, unsigned int width, unsigned int height,
@@ -118,9 +117,13 @@ private:
static bool CheckForCustomTextureLODs(u64 tex_hash, int texformat, unsigned int levels);
static PC_TexFormat LoadCustomTexture(u64 tex_hash, int texformat, unsigned int level, unsigned int& width, unsigned int& height);
static void DumpTexture(TCacheEntryBase* entry, unsigned int level);
-
typedef std::map<u32, TCacheEntryBase*> TexCache;
+ static TCacheEntryBase* GetOrCreateTexture(u32 width, u32 height, u32 maxlevel, bool isEfbCopy);
+ static void PoolTexture(TCacheEntryBase *entry);
+ typedef std::multimap<std::pair<u32,u32>, TCacheEntryBase*> TexPool;
+ static TexPool texPool;
+
static TexCache textures;
// Backup configuration values