PPGe: Decimate early if kernel alloc fails.

This commit is contained in:
Unknown W. Brackets 2021-02-07 23:17:53 -08:00
parent c87b53a9fe
commit f7c17817fe
2 changed files with 14 additions and 8 deletions

View File

@ -125,7 +125,7 @@ struct PPGeTextDrawerImage {
TextStringEntry entry;
u32 ptr;
};
std::map<PPGeTextDrawerCacheKey, PPGeTextDrawerImage> textDrawerImages;
static std::map<PPGeTextDrawerCacheKey, PPGeTextDrawerImage> textDrawerImages;
void PPGeSetDrawContext(Draw::DrawContext *draw) {
g_draw = draw;
@ -199,9 +199,16 @@ static void EndVertexDataAndDraw(int prim) {
static u32 __PPGeDoAlloc(u32 &size, bool fromTop, const char *name) {
u32 ptr = kernelMemory.Alloc(size, fromTop, name);
// Didn't get it.
if (ptr == (u32)-1)
return 0;
// Didn't get it, try again after decimating images.
if (ptr == (u32)-1) {
PPGeDecimateTextImages(4);
PPGeImage::Decimate(4);
ptr = kernelMemory.Alloc(size, fromTop, name);
if (ptr == (u32)-1) {
return 0;
}
}
return ptr;
}
@ -1283,9 +1290,8 @@ void PPGeImage::CompatLoad(u32 texture, int width, int height) {
height_ = height;
}
void PPGeImage::Decimate() {
static const int TOO_OLD_AGE = 30;
int tooOldFrame = gpuStats.numFlips - TOO_OLD_AGE;
void PPGeImage::Decimate(int age) {
int tooOldFrame = gpuStats.numFlips - age;
for (size_t i = 0; i < loadedTextures_.size(); ++i) {
if (loadedTextures_[i]->lastFrame_ < tooOldFrame) {
loadedTextures_[i]->Free();

View File

@ -133,7 +133,7 @@ public:
return height_;
}
static void Decimate();
static void Decimate(int age = 30);
private:
static std::vector<PPGeImage *> loadedTextures_;