mirror of https://github.com/RPCS3/rpcs3.git
Avoid recreating SwsContext every frame
* Applies to video decoding(`libvdec`) and post-processing(`libvpost`).
This commit is contained in:
parent
5f07f78c23
commit
754cdea435
|
@ -64,6 +64,7 @@ struct vdec_thread : ppu_thread
|
|||
{
|
||||
AVCodec* codec{};
|
||||
AVCodecContext* ctx{};
|
||||
SwsContext* sws{};
|
||||
|
||||
const s32 type;
|
||||
const u32 profile;
|
||||
|
@ -147,6 +148,7 @@ struct vdec_thread : ppu_thread
|
|||
{
|
||||
avcodec_close(ctx);
|
||||
avcodec_free_context(&ctx);
|
||||
sws_freeContext(sws);
|
||||
}
|
||||
|
||||
virtual std::string dump() const override
|
||||
|
@ -632,7 +634,7 @@ s32 cellVdecGetPicture(u32 handle, vm::cptr<CellVdecPicFormat> format, vm::ptr<u
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<SwsContext, void(*)(SwsContext*)> sws(sws_getContext(w, h, in_f, w, h, out_f, SWS_POINT, NULL, NULL, NULL), sws_freeContext);
|
||||
vdec->sws = sws_getCachedContext(vdec->sws, w, h, in_f, w, h, out_f, SWS_POINT, NULL, NULL, NULL);
|
||||
|
||||
u8* in_data[4] = { frame->data[0], frame->data[1], frame->data[2], alpha_plane.get() };
|
||||
int in_line[4] = { frame->linesize[0], frame->linesize[1], frame->linesize[2], w * 1 };
|
||||
|
@ -648,7 +650,7 @@ s32 cellVdecGetPicture(u32 handle, vm::cptr<CellVdecPicFormat> format, vm::ptr<u
|
|||
out_line[2] = w / 2;
|
||||
}
|
||||
|
||||
sws_scale(sws.get(), in_data, in_line, 0, h, out_data, out_line);
|
||||
sws_scale(vdec->sws, in_data, in_line, 0, h, out_data, out_line);
|
||||
|
||||
//const u32 buf_size = align(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1), 128);
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ s32 cellVpostExec(u32 handle, vm::cptr<u8> inPicBuff, vm::cptr<CellVpostCtrlPara
|
|||
|
||||
//u64 stamp1 = get_system_time();
|
||||
|
||||
std::unique_ptr<SwsContext, void(*)(SwsContext*)> sws(sws_getContext(w, h, AV_PIX_FMT_YUVA420P, ow, oh, AV_PIX_FMT_RGBA, SWS_BILINEAR, NULL, NULL, NULL), sws_freeContext);
|
||||
vpost->sws = sws_getCachedContext(vpost->sws, w, h, AV_PIX_FMT_YUVA420P, ow, oh, AV_PIX_FMT_RGBA, SWS_BILINEAR, NULL, NULL, NULL);
|
||||
|
||||
//u64 stamp2 = get_system_time();
|
||||
|
||||
|
@ -129,7 +129,7 @@ s32 cellVpostExec(u32 handle, vm::cptr<u8> inPicBuff, vm::cptr<CellVpostCtrlPara
|
|||
u8* out_data[4] = { outPicBuff.get_ptr(), NULL, NULL, NULL };
|
||||
int out_line[4] = { static_cast<int>(ow*4), 0, 0, 0 };
|
||||
|
||||
sws_scale(sws.get(), in_data, in_line, 0, h, out_data, out_line);
|
||||
sws_scale(vpost->sws, in_data, in_line, 0, h, out_data, out_line);
|
||||
|
||||
//ConLog.Write("cellVpostExec() perf (access=%d, getContext=%d, scale=%d, finalize=%d)",
|
||||
//stamp1 - stamp0, stamp2 - stamp1, stamp3 - stamp2, get_system_time() - stamp3);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "libswscale/swscale.h"
|
||||
}
|
||||
|
||||
namespace vm { using namespace ps3; }
|
||||
|
||||
// Error Codes
|
||||
|
@ -327,8 +332,15 @@ public:
|
|||
|
||||
const bool to_rgba;
|
||||
|
||||
SwsContext* sws{};
|
||||
|
||||
VpostInstance(bool rgba)
|
||||
: to_rgba(rgba)
|
||||
{
|
||||
}
|
||||
|
||||
~VpostInstance()
|
||||
{
|
||||
sws_freeContext(sws);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue