Rework buffer size allocations to only allocate as much space as is actually required.

This commit is contained in:
SuuperW 2018-06-27 11:23:36 -05:00
parent 0f4b3ead00
commit 8622a334a2
1 changed files with 186 additions and 174 deletions

View File

@ -44,6 +44,7 @@ public:
int prescaleTotal; int prescaleTotal;
size_t scratchBufferSize; size_t scratchBufferSize;
size_t rawBufferSize;
u8* srcBuffer; u8* srcBuffer;
size_t srcBufferSize; size_t srcBufferSize;
u32 *buffer, *buffer_raw; u32 *buffer, *buffer_raw;
@ -59,25 +60,35 @@ public:
prescaleTotal = prescaleHD; prescaleTotal = prescaleHD;
const int kInflationFactor = 5; //the largest filter is going up 5x in each dimension ResizeBuffers();
setfilter(currentfilter);
}
void ResizeBuffers()
{
// all these stupid video filters read outside of their buffer. let's allocate too much and hope it stays filled with black. geeze // all these stupid video filters read outside of their buffer. let's allocate too much and hope it stays filled with black. geeze
const int kPadSize = 4; const int kPadSize = 4;
size_t scratchBufferWidth = 256*kInflationFactor*prescaleHD + (kPadSize*2); // raw buffer
size_t scratchBufferHeight = 192*2*prescaleHD*kInflationFactor + (kPadSize*2); size_t rawBufferWidth = 256 * prescaleHD + (kPadSize * 2);
scratchBufferSize = scratchBufferWidth * scratchBufferHeight * 4; size_t rawBufferHeight = 192 * 2 * prescaleHD + (kPadSize * 2);
rawBufferSize = rawBufferWidth * rawBufferHeight * 4;
buffer_raw = buffer = (u32*)malloc_alignedCacheLine(rawBufferSize);
//why are these the same size, anyway? // display buffer
buffer_raw = buffer = (u32*)malloc_alignedCacheLine(scratchBufferSize); size_t scratchBufferWidth = width + (kPadSize * 2);
size_t scratchBufferHeight = height + (kPadSize * 2);
scratchBufferSize = scratchBufferWidth * scratchBufferHeight * 4;
filteredbuffer = (u32*)malloc_alignedCacheLine(scratchBufferSize); filteredbuffer = (u32*)malloc_alignedCacheLine(scratchBufferSize);
clear();
//move the buffer pointer inside it's padded area so that earlier reads won't go out of the buffer we allocated //move the buffer pointer inside it's padded area so that earlier reads won't go out of the buffer we allocated
buffer += (kPadSize*scratchBufferWidth + kPadSize)*4; buffer += (kPadSize*rawBufferWidth + kPadSize) * 4;
setfilter(currentfilter); // clean the new buffers
clear();
// prevent crashing when reducing the scaling
srcBufferSize = 0;
} }
enum { enum {
@ -114,7 +125,7 @@ public:
//{ //{
// memset(srcBuffer, 0xFF, size() * 2); // memset(srcBuffer, 0xFF, size() * 2);
//} //}
memset(buffer_raw, 0, scratchBufferSize); memset(buffer_raw, 0, rawBufferSize);
memset(filteredbuffer, 0, scratchBufferSize); memset(filteredbuffer, 0, scratchBufferSize);
} }
@ -170,6 +181,7 @@ public:
width *= prescaleHD; width *= prescaleHD;
height *= prescaleHD; height *= prescaleHD;
ResizeBuffers();
} }
SSurface src; SSurface src;