From d9e47fae19d739f0351ae9b3a1c8cb0548ae09d3 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sun, 30 Jul 2023 17:36:06 +0200 Subject: [PATCH] frontends/va: Ignore requested size when creating VAEncCodedBufferType The buffer data is not directly accessible to application and it's internally used to only store VACodedBufferSegment struct. Ignore the size requested by application and instead allocate sizeof(VACodedBufferSegment). Use calloc to zero out the struct. This can save significant amount of memory, for example FFmpeg will request up to tens of MB for single buffer. Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6462 Reviewed-by: Thong Thai Part-of: (cherry picked from commit 7bcbfae87c9039ebb01f7287403bf5666ca8d64e) --- .pick_status.json | 2 +- src/gallium/frontends/va/buffer.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 81f97c11601..e19f64c5d6e 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1453,7 +1453,7 @@ "description": "frontends/va: Ignore requested size when creating VAEncCodedBufferType", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/gallium/frontends/va/buffer.c b/src/gallium/frontends/va/buffer.c index 6a8ca44534c..908b6bd21e2 100644 --- a/src/gallium/frontends/va/buffer.c +++ b/src/gallium/frontends/va/buffer.c @@ -57,7 +57,11 @@ vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type, buf->type = type; buf->size = size; buf->num_elements = num_elements; - buf->data = MALLOC(size * num_elements); + + if (buf->type == VAEncCodedBufferType) + buf->data = CALLOC(1, sizeof(VACodedBufferSegment)); + else + buf->data = MALLOC(size * num_elements); if (!buf->data) { FREE(buf); @@ -161,7 +165,6 @@ vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) if (buf->type == VAEncCodedBufferType) { ((VACodedBufferSegment*)buf->data)->buf = *pbuff; ((VACodedBufferSegment*)buf->data)->size = buf->coded_size; - ((VACodedBufferSegment*)buf->data)->next = NULL; *pbuff = buf->data; } } else {