core: fix an old shortcoming in texcache where games that burned through sprites memory with lots of tiny sprites could use gigabytes of texcache buffers (metal slug)

This commit is contained in:
zeromus 2009-12-16 05:41:59 +00:00
parent 18b544b251
commit d0c111ebf6
5 changed files with 28 additions and 16 deletions

View File

@ -7,6 +7,7 @@ General/Core:
bug: fix div and sqrt busy flag bug
bug: fix vectest
bug: fix lid savestate desync
bug: fix texcache memory GB explosion when games use tons of tiny 3d sprites
enh: support devkitpro argv
enh: add gbaslot-rom commandline
@ -24,8 +25,10 @@ Windows:
Linux/OSX:
bug: fix building for nosse2 systems
bug: fix --num-cores
enh: add --nojoy=1 to fix laptops with accelerometers
0.9.4 -> 0.9.5 (r2437-r3075)
0.9.5 introduces an entirely rewritten main emulation loop

View File

@ -84,7 +84,7 @@ public:
engine.updateFogTable();
engine.initFramebuffer(kViewportWidth,kViewportHeight,gfx3d.state.enableClearImage);
engine.initFramebuffer(kViewportWidth,kViewportHeight,gfx3d.state.enableClearImage?true:false);
engine.updateToonTable();
engine.updateFloatColors();
engine.performClipping(checkMaterialInterpolate->IsChecked());

View File

@ -1437,7 +1437,7 @@ static void SoftRastRender()
if(gfx3d.state.enableFog && CommonSettings.GFX3D_Fog)
mainSoftRasterizer.updateFogTable();
mainSoftRasterizer.initFramebuffer(256,192,gfx3d.state.enableClearImage);
mainSoftRasterizer.initFramebuffer(256,192,gfx3d.state.enableClearImage?true:false);
mainSoftRasterizer.updateToonTable();
mainSoftRasterizer.updateFloatColors();
mainSoftRasterizer.performClipping(CommonSettings.GFX3D_HighResolutionInterpolateColor);

View File

@ -193,7 +193,11 @@ public:
TTexCacheItemMultimap index;
//this ought to be enough for anyone
static const u32 kMaxCacheSize = 64*1024*1024;
//static const u32 kMaxCacheSize = 64*1024*1024;
//changed by zeromus on 15-dec. I couldnt find any games that were getting anywhere NEAR 64
static const u32 kMaxCacheSize = 16*1024*1024;
//metal slug burns through sprites so fast, it can test it pretty quickly though
//this is not really precise, it is off by a constant factor
u32 cache_size;
@ -307,7 +311,7 @@ public:
if(mspal.size != 0 && memcmp(curr->dump.palette,pal,mspal.size)) goto REJECT;
//when the texture data doesn't match
if(ms.memcmp(curr->dump.texture,sizeof(curr->dump.texture))) goto REJECT;
if(ms.memcmp(&curr->dump.texture[0],sizeof(curr->dump.texture))) goto REJECT;
//if the texture is 4x4 then the index data must match
if(textureMode == TEXMODE_4X4)
@ -342,7 +346,6 @@ public:
newitem->sizeY=sizeY;
newitem->invSizeX=1.0f/((float)(sizeX));
newitem->invSizeY=1.0f/((float)(sizeY));
newitem->dump.textureSize = ms.dump(newitem->dump.texture,sizeof(newitem->dump.texture));
newitem->decode_len = sizeX*sizeY*4;
newitem->mode = textureMode;
newitem->decoded = new u8[newitem->decode_len];
@ -356,13 +359,15 @@ public:
{
memcpy(newitem->dump.palette, pal, palSize*2);
}
//dump 4x4 index data for cache keying
newitem->dump.indexSize = 0;
//dump texture and 4x4 index data for cache keying
const int texsize = newitem->dump.textureSize = ms.size;
const int indexsize = newitem->dump.indexSize = msIndex.size;
newitem->dump.texture = new u8[texsize+indexsize];
ms.dump(&newitem->dump.texture[0],newitem->dump.maxTextureSize); //dump texture
if(textureMode == TEXMODE_4X4)
{
newitem->dump.indexSize = min(msIndex.size,(int)sizeof(newitem->dump.texture) - newitem->dump.textureSize);
msIndex.dump(newitem->dump.texture+newitem->dump.textureSize,newitem->dump.indexSize);
}
msIndex.dump(newitem->dump.texture+newitem->dump.textureSize,newitem->dump.indexSize); //dump 4x4
//============================================================================
//Texture conversion
@ -637,6 +642,7 @@ public:
void evict(u32 target = kMaxCacheSize)
{
printf("%d %d/%d\n",index.size(),cache_size/1024,target/1024);
//dont do anything unless we're over the target
if(cache_size<target) return;

View File

@ -44,11 +44,14 @@ public:
TexCache_TexFormat cacheFormat;
//TODO - this is a little wasteful
struct {
int textureSize, indexSize;
u8 texture[128*1024]; // 128Kb texture slot
u8 palette[256*2];
struct Dump {
~Dump() {
delete[] texture;
}
int textureSize, indexSize;
static const int maxTextureSize=128*1024;
u8* texture;
u8 palette[256*2];
} dump;
};