remove a bunch of static buffers, reducing ram usage for those from 256 to 32. also add an ancient backwards compatibility hack to savestates; but, this will break savestates made within the past couple of days.

This commit is contained in:
zeromus 2009-05-04 07:07:48 +00:00
parent 9e8e46f1c0
commit db6fa0a017
6 changed files with 79 additions and 46 deletions

View File

@ -207,10 +207,10 @@ static CACHE_ALIGN float cacheHalfVector[4][4];
//-------------poly and vertex lists and such things //-------------poly and vertex lists and such things
POLYLIST polylists[2]; POLYLIST* polylists = NULL;
POLYLIST* polylist = &polylists[0]; POLYLIST* polylist = NULL;
VERTLIST vertlists[2]; VERTLIST* vertlists = NULL;
VERTLIST* vertlist = &vertlists[0]; VERTLIST* vertlist = NULL;
int listTwiddle = 1; int listTwiddle = 1;
int triStripToggle; int triStripToggle;
@ -278,6 +278,8 @@ static void makeTables() {
void gfx3d_init() void gfx3d_init()
{ {
if(polylists == NULL) { polylists = new POLYLIST[2]; polylist = &polylists[0]; }
if(vertlists == NULL) { vertlists = new VERTLIST[2]; vertlist = &vertlists[0]; }
makeTables(); makeTables();
gfx3d_reset(); gfx3d_reset();
} }
@ -2328,6 +2330,9 @@ SFORMAT SF_GFX3D[]={
//-------------savestate //-------------savestate
void gfx3d_savestate(std::ostream* os) void gfx3d_savestate(std::ostream* os)
{ {
//version
write32le(1,os);
//dump the render lists //dump the render lists
OSWRITE(vertlist->count); OSWRITE(vertlist->count);
for(int i=0;i<vertlist->count;i++) for(int i=0;i<vertlist->count;i++)
@ -2339,6 +2344,11 @@ void gfx3d_savestate(std::ostream* os)
bool gfx3d_loadstate(std::istream* is, int size) bool gfx3d_loadstate(std::istream* is, int size)
{ {
int version;
if(read32le(&version,is) != 1) return false;
if(size==8) version = 0;
gfx3d_glPolygonAttrib_cache(); gfx3d_glPolygonAttrib_cache();
gfx3d_glTexImage_cache(); gfx3d_glTexImage_cache();
gfx3d_Control_cache(); gfx3d_Control_cache();
@ -2352,12 +2362,15 @@ bool gfx3d_loadstate(std::istream* is, int size)
polylist = &polylists[listTwiddle]; polylist = &polylists[listTwiddle];
vertlist = &vertlists[listTwiddle]; vertlist = &vertlists[listTwiddle];
OSREAD(vertlist->count); if(version==1)
for(int i=0;i<vertlist->count;i++) {
vertlist->list[i].load(is); OSREAD(vertlist->count);
OSREAD(polylist->count); for(int i=0;i<vertlist->count;i++)
for(int i=0;i<polylist->count;i++) vertlist->list[i].load(is);
polylist->list[i].load(is); OSREAD(polylist->count);
for(int i=0;i<polylist->count;i++)
polylist->list[i].load(is);
}
gfx3d.polylist = &polylists[listTwiddle^1]; gfx3d.polylist = &polylists[listTwiddle^1];
gfx3d.vertlist = &vertlists[listTwiddle^1]; gfx3d.vertlist = &vertlists[listTwiddle^1];

View File

@ -69,6 +69,17 @@ static u8 decal_table[32][32][32];
static u8 index_lookup_table[65]; static u8 index_lookup_table[65];
static u8 index_start_table[8]; static u8 index_start_table[8];
static struct TClippedPoly
{
int type;
POLY* poly;
VERT clipVerts[MAX_CLIPPED_VERTS];
} *clippedPolys = NULL;
static int clippedPolyCounter;
TClippedPoly tempClippedPoly;
TClippedPoly outClippedPoly;
////optimized float floor useful in limited cases ////optimized float floor useful in limited cases
////from http://www.stereopsis.com/FPU.html#convert ////from http://www.stereopsis.com/FPU.html#convert
////(unfortunately, it relies on certain FPU register settings) ////(unfortunately, it relies on certain FPU register settings)
@ -895,6 +906,9 @@ static char SoftRastInit(void)
if(!tables_generated) if(!tables_generated)
{ {
tables_generated = true; tables_generated = true;
clippedPolys = new TClippedPoly[POLYLIST_SIZE*2];
for(int i=0;i<32;i++) for(int i=0;i<32;i++)
{ {
for(int j=0;j<32;j++) for(int j=0;j<32;j++)
@ -968,16 +982,6 @@ static void SoftRastConvertFramebuffer()
} }
} }
static struct TClippedPoly
{
int type;
POLY* poly;
VERT clipVerts[MAX_CLIPPED_VERTS];
} clippedPolys[POLYLIST_SIZE*2];
static int clippedPolyCounter;
TClippedPoly tempClippedPoly;
TClippedPoly outClippedPoly;
template<typename T> template<typename T>
static T interpolate(const float ratio, const T& x0, const T& x1) { static T interpolate(const float ratio, const T& x0, const T& x1) {

View File

@ -132,10 +132,10 @@ static MemSpan MemSpan_TexPalette(u32 ofs, u32 len)
return ret; return ret;
} }
TextureCache texcache[MAX_TEXTURE+1]; TextureCache *texcache;
u32 texcache_start; u32 texcache_start;
u32 texcache_stop; u32 texcache_stop;
u8 TexCache_texMAP[1024*2048*4]; u8 *TexCache_texMAP = NULL;
#if defined (DEBUG_DUMP_TEXTURE) && defined (WIN32) #if defined (DEBUG_DUMP_TEXTURE) && defined (WIN32)
@ -575,6 +575,9 @@ REJECT:
void TexCache_Reset() void TexCache_Reset()
{ {
if(TexCache_texMAP == NULL) TexCache_texMAP = new u8[1024*2048*4];
if(texcache == NULL) texcache = new TextureCache[MAX_TEXTURE+1];
memset(texcache,0,sizeof(texcache)); memset(texcache,0,sizeof(texcache));
texcache_start=0; texcache_start=0;

View File

@ -36,7 +36,7 @@ struct ALIGN(8) TextureCache
}; };
extern TextureCache texcache[MAX_TEXTURE+1]; extern TextureCache *texcache;
extern void (*TexCache_BindTexture)(u32 texnum); extern void (*TexCache_BindTexture)(u32 texnum);
extern void (*TexCache_BindTextureData)(u32 texnum, u8* data); extern void (*TexCache_BindTextureData)(u32 texnum, u8* data);
@ -48,7 +48,7 @@ void TexCache_SetTexture(u32 format, u32 texpal);
void TexCache_Invalidate(); void TexCache_Invalidate();
extern u8 TexCache_texMAP[1024*2048*4]; extern u8 *TexCache_texMAP;
TextureCache* TexCache_Curr(); TextureCache* TexCache_Curr();
#endif #endif

View File

@ -114,6 +114,7 @@ void DRV_AviVideoUpdate(const u16* buffer);
DWORD hKeyInputTimer; DWORD hKeyInputTimer;
extern LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); extern LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
void InitRamSearch();
CRITICAL_SECTION win_sync; CRITICAL_SECTION win_sync;
@ -3092,6 +3093,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
case ID_RAM_SEARCH: case ID_RAM_SEARCH:
if(!RamSearchHWnd) if(!RamSearchHWnd)
{ {
InitRamSearch();
RamSearchHWnd = CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_RAMSEARCH), hwnd, (DLGPROC) RamSearchProc); RamSearchHWnd = CreateDialog(hAppInst, MAKEINTRESOURCE(IDD_RAMSEARCH), hwnd, (DLGPROC) RamSearchProc);
} }
else else

View File

@ -63,10 +63,12 @@ struct MemoryRegion
unsigned int itemIndex; // index into listbox items, valid when s_itemIndicesInvalid is false unsigned int itemIndex; // index into listbox items, valid when s_itemIndicesInvalid is false
}; };
static unsigned char s_prevValues [MAX_RAM_SIZE+4] = {0}; // values at last search or reset static struct Buffers {
static unsigned char s_curValues [MAX_RAM_SIZE+4] = {0}; // values at last frame update unsigned char s_prevValues [MAX_RAM_SIZE+4]; // values at last search or reset
static unsigned short s_numChanges [MAX_RAM_SIZE+4] = {0}; // number of changes of the item starting at this virtual index address unsigned char s_curValues [MAX_RAM_SIZE+4]; // values at last frame update
static MemoryRegion* s_itemIndexToRegionPointer [MAX_RAM_SIZE+4] = {0}; // used for random access into the memory list (trading memory size to get speed here, too bad it's so much memory), only valid when s_itemIndicesInvalid is false unsigned short s_numChanges [MAX_RAM_SIZE+4]; // number of changes of the item starting at this virtual index address
MemoryRegion* s_itemIndexToRegionPointer [MAX_RAM_SIZE+4]; // used for random access into the memory list (trading memory size to get speed here, too bad it's so much memory), only valid when s_itemIndicesInvalid is false
} *buffers = NULL;
static BOOL s_itemIndicesInvalid = true; // if true, the link from listbox items to memory regions (s_itemIndexToRegionPointer) and the link from memory regions to list box items (MemoryRegion::itemIndex) both need to be recalculated static BOOL s_itemIndicesInvalid = true; // if true, the link from listbox items to memory regions (s_itemIndexToRegionPointer) and the link from memory regions to list box items (MemoryRegion::itemIndex) both need to be recalculated
static BOOL s_prevValuesNeedUpdate = true; // if true, the "prev" values should be updated using the "cur" values on the next frame update signaled static BOOL s_prevValuesNeedUpdate = true; // if true, the "prev" values should be updated using the "cur" values on the next frame update signaled
static unsigned int s_maxItemIndex = 0; // max currently valid item index, the listbox sometimes tries to update things past the end of the list so we need to know this to ignore those attempts static unsigned int s_maxItemIndex = 0; // max currently valid item index, the listbox sometimes tries to update things past the end of the list so we need to know this to ignore those attempts
@ -92,6 +94,15 @@ static int s_undoType = 0; // 0 means can't undo, 1 means can undo, 2 means can
void RamSearchSaveUndoStateIfNotTooBig(HWND hDlg); void RamSearchSaveUndoStateIfNotTooBig(HWND hDlg);
static const int tooManyRegionsForUndo = 10000; static const int tooManyRegionsForUndo = 10000;
void InitRamSearch()
{
if(buffers == NULL)
{
buffers = new Buffers;
memset(buffers,0,sizeof(Buffers));
}
}
void ResetMemoryRegions() void ResetMemoryRegions()
{ {
// Clear_Sound_Buffer(); // Clear_Sound_Buffer();
@ -200,7 +211,7 @@ void CalculateItemIndices(int itemSize)
unsigned int start = startSkipSize; unsigned int start = startSkipSize;
unsigned int end = region.size; unsigned int end = region.size;
for(unsigned int i = start; i < end; i += itemSize) for(unsigned int i = start; i < end; i += itemSize)
s_itemIndexToRegionPointer[itemIndex++] = &region; buffers->s_itemIndexToRegionPointer[itemIndex++] = &region;
} }
s_maxItemIndex = itemIndex; s_maxItemIndex = itemIndex;
s_itemIndicesInvalid = FALSE; s_itemIndicesInvalid = FALSE;
@ -210,7 +221,7 @@ template<typename stepType, typename compareType, int swapXOR>
void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr) void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr)
{ {
if(s_prevValuesNeedUpdate) if(s_prevValuesNeedUpdate)
memcpy(s_prevValues + region.virtualIndex, s_curValues + region.virtualIndex, region.size + sizeof(compareType) - sizeof(stepType)); memcpy(buffers->s_prevValues + region.virtualIndex, buffers->s_curValues + region.virtualIndex, region.size + sizeof(compareType) - sizeof(stepType));
unsigned int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType); unsigned int startSkipSize = ((unsigned int)(sizeof(stepType) - region.hardwareAddress)) % sizeof(stepType);
@ -222,11 +233,11 @@ void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr
{ {
for(unsigned int i = indexStart; i < indexEnd; i++) for(unsigned int i = indexStart; i < indexEnd; i++)
{ {
if(s_curValues[i] != sourceAddr[i^swapXOR]) // if value changed if(buffers->s_curValues[i] != sourceAddr[i^swapXOR]) // if value changed
{ {
s_curValues[i] = sourceAddr[i^swapXOR]; // update value buffers->s_curValues[i] = sourceAddr[i^swapXOR]; // update value
//if(s_numChanges[i] != 0xFFFF) //if(s_numChanges[i] != 0xFFFF)
s_numChanges[i]++; // increase change count buffers->s_numChanges[i]++; // increase change count
} }
} }
} }
@ -253,10 +264,10 @@ void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr
for(unsigned int i = indexStart, j = 0; i < lastIndexToRead; i++, j++) for(unsigned int i = indexStart, j = 0; i < lastIndexToRead; i++, j++)
{ {
if(s_curValues[i] != sourceAddr[i^swapXOR]) // if value of this byte changed if(buffers->s_curValues[i] != sourceAddr[i^swapXOR]) // if value of this byte changed
{ {
if(i < lastIndexToCopy) if(i < lastIndexToCopy)
s_curValues[i] = sourceAddr[i^swapXOR]; // update value buffers->s_curValues[i] = sourceAddr[i^swapXOR]; // update value
for(int k = 0; k < sizeof(compareType); k++) // loop through the previous entries that contain this byte for(int k = 0; k < sizeof(compareType); k++) // loop through the previous entries that contain this byte
{ {
if(i >= indexEnd+k) if(i >= indexEnd+k)
@ -265,7 +276,7 @@ void UpdateRegionT(const MemoryRegion& region, const MemoryRegion* nextRegionPtr
if(nextValidChange[m]+sizeof(compareType) <= i+sizeof(compareType)) // if we didn't already increase the change count for this entry if(nextValidChange[m]+sizeof(compareType) <= i+sizeof(compareType)) // if we didn't already increase the change count for this entry
{ {
//if(s_numChanges[i-k] != 0xFFFF) //if(s_numChanges[i-k] != 0xFFFF)
s_numChanges[i-k]++; // increase the change count for this entry buffers->s_numChanges[i-k]++; // increase the change count for this entry
nextValidChange[m] = i+sizeof(compareType); // and remember not to increase it again nextValidChange[m] = i+sizeof(compareType); // and remember not to increase it again
} }
} }
@ -333,7 +344,7 @@ void ItemIndexToVirtualRegion(unsigned int itemIndex, MemoryRegion& virtualRegio
return; return;
} }
const MemoryRegion* regionPtr = s_itemIndexToRegionPointer[itemIndex]; const MemoryRegion* regionPtr = buffers->s_itemIndexToRegionPointer[itemIndex];
const MemoryRegion& region = *regionPtr; const MemoryRegion& region = *regionPtr;
int bytesWithinRegion = (itemIndex - region.itemIndex) * sizeof(stepType); int bytesWithinRegion = (itemIndex - region.itemIndex) * sizeof(stepType);
@ -375,19 +386,19 @@ template<> unsigned char ReadBigEndian(const unsigned char* data) { return *data
template<typename stepType, typename compareType> template<typename stepType, typename compareType>
compareType GetPrevValueFromVirtualIndex(unsigned int virtualIndex) compareType GetPrevValueFromVirtualIndex(unsigned int virtualIndex)
{ {
return ReadBigEndian<compareType>(s_prevValues + virtualIndex); return ReadBigEndian<compareType>(buffers->s_prevValues + virtualIndex);
//return *(compareType*)(s_prevValues+virtualIndex); //return *(compareType*)(s_prevValues+virtualIndex);
} }
template<typename stepType, typename compareType> template<typename stepType, typename compareType>
compareType GetCurValueFromVirtualIndex(unsigned int virtualIndex) compareType GetCurValueFromVirtualIndex(unsigned int virtualIndex)
{ {
return ReadBigEndian<compareType>(s_curValues + virtualIndex); return ReadBigEndian<compareType>(buffers->s_curValues + virtualIndex);
// return *(compareType*)(s_curValues+virtualIndex); // return *(compareType*)(s_curValues+virtualIndex);
} }
template<typename stepType, typename compareType> template<typename stepType, typename compareType>
unsigned short GetNumChangesFromVirtualIndex(unsigned int virtualIndex) unsigned short GetNumChangesFromVirtualIndex(unsigned int virtualIndex)
{ {
unsigned short num = s_numChanges[virtualIndex]; unsigned short num = buffers->s_numChanges[virtualIndex];
//for(unsigned int i = 1; i < sizeof(stepType); i++) //for(unsigned int i = 1; i < sizeof(stepType); i++)
// if(num < s_numChanges[virtualIndex+i]) // if(num < s_numChanges[virtualIndex+i])
// num = s_numChanges[virtualIndex+i]; // num = s_numChanges[virtualIndex+i];
@ -970,14 +981,14 @@ void CompactAddrs()
void soft_reset_address_info () void soft_reset_address_info ()
{ {
ResetMemoryRegions(); ResetMemoryRegions();
memset(s_numChanges, 0, sizeof(s_numChanges)); memset(buffers->s_numChanges, 0, sizeof(buffers->s_numChanges));
CompactAddrs(); CompactAddrs();
} }
void reset_address_info () void reset_address_info ()
{ {
SetRamSearchUndoType(RamSearchHWnd, 0); SetRamSearchUndoType(RamSearchHWnd, 0);
s_activeMemoryRegionsBackup.clear(); // not necessary, but we'll take the time hit here instead of at the next thing that sets up an undo s_activeMemoryRegionsBackup.clear(); // not necessary, but we'll take the time hit here instead of at the next thing that sets up an undo
memcpy(s_prevValues, s_curValues, sizeof(s_prevValues)); memcpy(buffers->s_prevValues, buffers->s_curValues, sizeof(buffers->s_prevValues));
s_prevValuesNeedUpdate = false; s_prevValuesNeedUpdate = false;
ResetMemoryRegions(); ResetMemoryRegions();
if(!RamSearchHWnd) if(!RamSearchHWnd)
@ -992,7 +1003,7 @@ void reset_address_info ()
s_prevValuesNeedUpdate = true; s_prevValuesNeedUpdate = true;
signal_new_frame(); signal_new_frame();
} }
memset(s_numChanges, 0, sizeof(s_numChanges)); memset(buffers->s_numChanges, 0, sizeof(buffers->s_numChanges));
CompactAddrs(); CompactAddrs();
} }
@ -1663,7 +1674,7 @@ LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
{rv = true; break;} {rv = true; break;}
} }
case IDC_C_RESET_CHANGES: case IDC_C_RESET_CHANGES:
memset(s_numChanges, 0, sizeof(s_numChanges)); memset(buffers->s_numChanges, 0, sizeof(buffers->s_numChanges));
ListView_Update(GetDlgItem(hDlg,IDC_RAMLIST), -1); ListView_Update(GetDlgItem(hDlg,IDC_RAMLIST), -1);
//SetRamSearchUndoType(hDlg, 0); //SetRamSearchUndoType(hDlg, 0);
{rv = true; break;} {rv = true; break;}