summaryrefslogtreecommitdiff
path: root/libavcodec/nvenc.c
diff options
context:
space:
mode:
authorTimo Rothenpieler <timo@rothenpieler.org>2019-04-24 19:00:25 +0200
committerTimo Rothenpieler <timo@rothenpieler.org>2019-04-27 12:33:08 +0200
commit23ed147e8fc2b6b51a88af66b40f99049e5fa0d8 (patch)
tree0d8b4c5be70cf4ba6f1b2396035c9a2d7628d408 /libavcodec/nvenc.c
parentd6489ddb7a6cdfb6bd4e5b8095d765e0ba1aba4a (diff)
avcodec/nvenc: only unregister input resources when absolutely needed
This reverts nvenc to old behaviour, which in some super rare edge cases performs better. The implication of this is that any potential API user who relies on nvenc cleaning up every frames device resources after it's done using them will have to change their usage pattern. That should not be a problem, since pretty much every normal usage pattern automatically implies that surfaces are reused from a common pool, since constant re-allocation is also very expensive.
Diffstat (limited to 'libavcodec/nvenc.c')
-rw-r--r--libavcodec/nvenc.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index d3413b3fd7..626662f02c 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1560,12 +1560,15 @@ static int nvenc_find_free_reg_resource(AVCodecContext *avctx)
NV_ENCODE_API_FUNCTION_LIST *p_nvenc = &dl_fn->nvenc_funcs;
NVENCSTATUS nv_status;
- int i;
+ int i, first_round;
if (ctx->nb_registered_frames == FF_ARRAY_ELEMS(ctx->registered_frames)) {
+ for (first_round = 1; first_round >= 0; first_round--) {
for (i = 0; i < ctx->nb_registered_frames; i++) {
if (!ctx->registered_frames[i].mapped) {
if (ctx->registered_frames[i].regptr) {
+ if (first_round)
+ continue;
nv_status = p_nvenc->nvEncUnregisterResource(ctx->nvencoder, ctx->registered_frames[i].regptr);
if (nv_status != NV_ENC_SUCCESS)
return nvenc_print_error(avctx, nv_status, "Failed unregistering unused input resource");
@@ -1575,6 +1578,7 @@ static int nvenc_find_free_reg_resource(AVCodecContext *avctx)
return i;
}
}
+ }
} else {
return ctx->nb_registered_frames++;
}
@@ -1846,13 +1850,6 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, NvencSur
res = nvenc_print_error(avctx, nv_status, "Failed unmapping input resource");
goto error;
}
- nv_status = p_nvenc->nvEncUnregisterResource(ctx->nvencoder, ctx->registered_frames[tmpoutsurf->reg_idx].regptr);
- if (nv_status != NV_ENC_SUCCESS) {
- res = nvenc_print_error(avctx, nv_status, "Failed unregistering input resource");
- goto error;
- }
- ctx->registered_frames[tmpoutsurf->reg_idx].ptr = NULL;
- ctx->registered_frames[tmpoutsurf->reg_idx].regptr = NULL;
} else if (ctx->registered_frames[tmpoutsurf->reg_idx].mapped < 0) {
res = AVERROR_BUG;
goto error;