From f9e38b11d96d8158879a919e3ad106cc6250d11a Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Sun, 15 May 2022 13:37:58 +0200 Subject: [PATCH] pvr: restore TA_context pool fixes performance regression on android --- core/hw/pvr/ta_ctx.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/core/hw/pvr/ta_ctx.cpp b/core/hw/pvr/ta_ctx.cpp index bed58a1d0..d5cd184bf 100644 --- a/core/hw/pvr/ta_ctx.cpp +++ b/core/hw/pvr/ta_ctx.cpp @@ -101,13 +101,28 @@ void FinishRender(TA_context* ctx) frame_finished.Set(); } +static std::mutex mtx_pool; + +static std::vector ctx_pool; static std::vector ctx_list; static TA_context *tactx_Alloc() { - TA_context *ctx = new TA_context(); - ctx->Alloc(); + TA_context *ctx = nullptr; + mtx_pool.lock(); + if (!ctx_pool.empty()) + { + ctx = ctx_pool.back(); + ctx_pool.pop_back(); + } + mtx_pool.unlock(); + + if (ctx == nullptr) + { + ctx = new TA_context(); + ctx->Alloc(); + } return ctx; } @@ -115,7 +130,17 @@ static void tactx_Recycle(TA_context* ctx) { if (ctx->nextContext != nullptr) tactx_Recycle(ctx->nextContext); - delete ctx; + mtx_pool.lock(); + if (ctx_pool.size() > 3) + { + delete ctx; + } + else + { + ctx->Reset(); + ctx_pool.push_back(ctx); + } + mtx_pool.unlock(); } static TA_context *tactx_Find(u32 addr, bool allocnew) @@ -162,6 +187,12 @@ void tactx_Term() for (TA_context *ctx : ctx_list) delete ctx; ctx_list.clear(); + + mtx_pool.lock(); + for (TA_context *ctx : ctx_pool) + delete ctx; + ctx_pool.clear(); + mtx_pool.unlock(); } const u32 NULL_CONTEXT = ~0u;