libsnes: move tile cache out of savestates. saves like 400kB. meh.

This commit is contained in:
nattthebear 2017-06-11 11:28:29 -04:00
parent cf608bfca9
commit 8cf1e43e70
7 changed files with 32 additions and 27 deletions

View File

@ -21,6 +21,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public abstract void CopyBuffer(int id, void* ptr, int size);
[BizImport(CallingConvention.Cdecl, Compatibility = true)]
public abstract void SetBuffer(int id, void* ptr, int size);
[BizImport(CallingConvention.Cdecl)]
public abstract void PostLoadState();
}
public unsafe partial class LibsnesApi : IDisposable, IMonitor, IBinaryStateable
@ -57,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
Filename = "libsnes.wbx",
Path = dllPath,
SbrkHeapSizeKB = 4 * 1024,
InvisibleHeapSizeKB = 1024,
InvisibleHeapSizeKB = 2048,
MmapHeapSizeKB = 32 * 1024, // TODO: see if we can safely make libco stacks smaller
PlainHeapSizeKB = 2 * 1024, // TODO: wasn't there more in here?
SealedHeapSizeKB = 128 * 1024
@ -374,6 +376,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
public void LoadStateBinary(BinaryReader reader)
{
_exe.LoadStateBinary(reader);
_core.PostLoadState();
}
}
}

Binary file not shown.

View File

@ -127,12 +127,12 @@ void PPU::flush_pixel_cache() {
}
void PPU::alloc_tiledata_cache() {
bg_tiledata[TILE_2BIT] = new uint8_t[262144]();
bg_tiledata[TILE_4BIT] = new uint8_t[131072]();
bg_tiledata[TILE_8BIT] = new uint8_t[ 65536]();
bg_tiledata_state[TILE_2BIT] = new uint8_t[ 4096]();
bg_tiledata_state[TILE_4BIT] = new uint8_t[ 2048]();
bg_tiledata_state[TILE_8BIT] = new uint8_t[ 1024]();
bg_tiledata[TILE_2BIT] = (uint8_t*)alloc_invisible(262144);
bg_tiledata[TILE_4BIT] = (uint8_t*)alloc_invisible(131072);
bg_tiledata[TILE_8BIT] = (uint8_t*)alloc_invisible( 65536);
bg_tiledata_state[TILE_2BIT] = (uint8_t*)alloc_invisible( 4096);
bg_tiledata_state[TILE_4BIT] = (uint8_t*)alloc_invisible( 2048);
bg_tiledata_state[TILE_8BIT] = (uint8_t*)alloc_invisible( 1024);
}
//marks all tiledata cache entries as dirty
@ -143,12 +143,7 @@ void PPU::flush_tiledata_cache() {
}
void PPU::free_tiledata_cache() {
delete[] bg_tiledata[TILE_2BIT];
delete[] bg_tiledata[TILE_4BIT];
delete[] bg_tiledata[TILE_8BIT];
delete[] bg_tiledata_state[TILE_2BIT];
delete[] bg_tiledata_state[TILE_4BIT];
delete[] bg_tiledata_state[TILE_8BIT];
abort();
}
#endif

View File

@ -112,22 +112,23 @@ uint8* PPU::Cache::tile(unsigned bpp, unsigned tile) {
}
PPU::Cache::Cache(PPU &self) : self(self) {
tiledata[0] = new uint8[262144]();
tiledata[1] = new uint8[131072]();
tiledata[2] = new uint8[ 65536]();
tilevalid[0] = new uint8[ 4096]();
tilevalid[1] = new uint8[ 2048]();
tilevalid[2] = new uint8[ 1024]();
tiledata[0] = (uint8*)alloc_invisible(262144);
tiledata[1] = (uint8*)alloc_invisible(131072);
tiledata[2] = (uint8*)alloc_invisible(65536);
tilevalid[0] = (uint8*)alloc_invisible(4096);
tilevalid[1] = (uint8*)alloc_invisible(2048);
tilevalid[2] = (uint8*)alloc_invisible(1024);
}
PPU::Cache::invalidate() {
memset(tilevalid[0], 0, 4096);
memset(tilevalid[1], 0, 2048);
memset(tilevalid[2], 0, 1024);
}
PPU::Cache::~Cache()
{
delete[] tiledata[0];
delete[] tiledata[1];
delete[] tiledata[2];
delete[] tilevalid[0];
delete[] tilevalid[1];
delete[] tilevalid[2];
abort();
}
#endif

View File

@ -7,6 +7,7 @@ public:
uint8* tile_4bpp(unsigned tile);
uint8* tile_8bpp(unsigned tile);
uint8* tile(unsigned bpp, unsigned tile);
void invalidate();
Cache(PPU &self);
~Cache();

View File

@ -214,9 +214,9 @@ void snes_set_cartridge_basename(const char *basename) {
}
template<typename T> inline void reconstruct(T* t) {
t->~T();
/*t->~T();
memset(t,0,sizeof(*t));
new(t) T();
new(t) T();*/
}
void snes_init(void) {

View File

@ -659,6 +659,11 @@ EXPORT void SetBuffer(int id, void* ptr, int32 size)
comm.SetBuffer(id, ptr, size);
}
EXPORT void PostLoadState()
{
SNES::ppu.flush_tiledata_cache();
}
int main()
{
return 0;