From 37996c757fb890e4780ef9d6920a73257f3fe1b4 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 9 Oct 2023 17:28:06 +0200 Subject: [PATCH] frontends/va: Implement vaMapBuffer2 Reviewed-by: Sil Vilerino Part-of: --- src/gallium/frontends/va/buffer.c | 35 ++++++++++++++++++++++++++++++----- src/gallium/frontends/va/context.c | 4 ++++ src/gallium/frontends/va/va_private.h | 1 + 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/gallium/frontends/va/buffer.c b/src/gallium/frontends/va/buffer.c index ca0f79d..dd16043 100644 --- a/src/gallium/frontends/va/buffer.c +++ b/src/gallium/frontends/va/buffer.c @@ -39,6 +39,12 @@ #include #endif +#ifndef VA_MAPBUFFER_FLAG_DEFAULT +#define VA_MAPBUFFER_FLAG_DEFAULT 0 +#define VA_MAPBUFFER_FLAG_READ 1 +#define VA_MAPBUFFER_FLAG_WRITE 2 +#endif + VAStatus vlVaCreateBuffer(VADriverContextP ctx, VAContextID context, VABufferType type, unsigned int size, unsigned int num_elements, void *data, @@ -112,6 +118,12 @@ vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id, VAStatus vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) { + return vlVaMapBuffer2(ctx, buf_id, pbuff, VA_MAPBUFFER_FLAG_DEFAULT); +} + +VAStatus vlVaMapBuffer2(VADriverContextP ctx, VABufferID buf_id, + void **pbuff, uint32_t flags) +{ vlVaDriver *drv; vlVaBuffer *buf; @@ -135,6 +147,7 @@ vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) if (buf->derived_surface.resource) { struct pipe_resource *resource; struct pipe_box box; + unsigned usage = 0; void *(*map_func)(struct pipe_context *, struct pipe_resource *resource, unsigned level, @@ -153,11 +166,23 @@ vlVaMapBuffer(VADriverContextP ctx, VABufferID buf_id, void **pbuff) else map_func = drv->pipe->texture_map; - /* For VAImageBufferType, use PIPE_MAP_WRITE for now, - * PIPE_MAP_READ_WRITE degradate perf with two copies when map/unmap. */ - *pbuff = map_func(drv->pipe, resource, 0, - buf->type == VAEncCodedBufferType ? - PIPE_MAP_READ : PIPE_MAP_WRITE, + if (flags == VA_MAPBUFFER_FLAG_DEFAULT) { + /* For VAImageBufferType, use PIPE_MAP_WRITE for now, + * PIPE_MAP_READ_WRITE degradate perf with two copies when map/unmap. */ + if (buf->type == VAEncCodedBufferType) + usage = PIPE_MAP_READ; + else + usage = PIPE_MAP_WRITE; + } + + if (flags & VA_MAPBUFFER_FLAG_READ) + usage |= PIPE_MAP_READ; + if (flags & VA_MAPBUFFER_FLAG_WRITE) + usage |= PIPE_MAP_WRITE; + + assert(usage); + + *pbuff = map_func(drv->pipe, resource, 0, usage, &box, &buf->derived_surface.transfer); mtx_unlock(&drv->mutex); diff --git a/src/gallium/frontends/va/context.c b/src/gallium/frontends/va/context.c index b206d2a..4f4f0ff 100644 --- a/src/gallium/frontends/va/context.c +++ b/src/gallium/frontends/va/context.c @@ -106,6 +106,10 @@ static struct VADriverVTable vtable = NULL, /* vaSyncSurface2 */ &vlVaSyncBuffer, #endif +#if VA_CHECK_VERSION(1, 21, 0) + NULL, /* vaCopy */ + &vlVaMapBuffer2, +#endif }; static struct VADriverVTableVPP vtable_vpp = diff --git a/src/gallium/frontends/va/va_private.h b/src/gallium/frontends/va/va_private.h index 54abc4c..37c0aec 100644 --- a/src/gallium/frontends/va/va_private.h +++ b/src/gallium/frontends/va/va_private.h @@ -503,6 +503,7 @@ VAStatus vlVaQueryVideoProcFilterCaps(VADriverContextP ctx, VAContextID context, VAStatus vlVaQueryVideoProcPipelineCaps(VADriverContextP ctx, VAContextID context, VABufferID *filters, unsigned int num_filters, VAProcPipelineCaps *pipeline_cap); VAStatus vlVaSyncBuffer(VADriverContextP ctx, VABufferID buf_id, uint64_t timeout_ns); +VAStatus vlVaMapBuffer2(VADriverContextP ctx, VABufferID buf_id, void **pbuf, uint32_t flags); // internal functions VAStatus vlVaHandleVAProcPipelineParameterBufferType(vlVaDriver *drv, vlVaContext *context, vlVaBuffer *buf); -- 2.7.4