From: Qiang Yu Date: Sat, 28 Mar 2020 06:09:22 +0000 (+0800) Subject: lima: fix buffer import with offset X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e46b2ef7243a7f916b7d77f3495bea26f4f24d62;p=mesa.git lima: fix buffer import with offset With EGL_EXT_image_dma_buf_import, user can import dma_buf with offset. This is also used by AOSP GLConsumer::updateTexImage with HAL_PIXEL_FORMAT_YV12 buffer which store YUV planes in the same buffer with offset. Render sample from it using GL_OES_EGL_image_external. This should fix some video display problem when using MediaCodec soft decoding which generates HAL_PIXEL_FORMAT_YV12 buffer and render it on screen. Test program: https://github.com/yuq/gfx/tree/master/yuv2rgb/dma-buf Reviewed-by: Vasily Khoruzhick Signed-off-by: Qiang Yu Part-of: --- diff --git a/src/gallium/drivers/lima/lima_resource.c b/src/gallium/drivers/lima/lima_resource.c index bd3549db448..fb416652e53 100644 --- a/src/gallium/drivers/lima/lima_resource.c +++ b/src/gallium/drivers/lima/lima_resource.c @@ -291,10 +291,20 @@ lima_resource_from_handle(struct pipe_screen *pscreen, const struct pipe_resource *templat, struct winsys_handle *handle, unsigned usage) { - struct lima_resource *res; - struct lima_screen *screen = lima_screen(pscreen); + if (templat->bind & (PIPE_BIND_SAMPLER_VIEW | + PIPE_BIND_RENDER_TARGET | + PIPE_BIND_DEPTH_STENCIL)) { + /* sampler hardware need offset alignment 64, while render hardware + * need offset alignment 8, but due to render target may be reloaded + * which uses the sampler, set alignment requrement to 64 for all + */ + if (handle->offset & 0x3f) { + debug_error("import buffer offset not properly aligned\n"); + return NULL; + } + } - res = CALLOC_STRUCT(lima_resource); + struct lima_resource *res = CALLOC_STRUCT(lima_resource); if (!res) return NULL; @@ -302,9 +312,10 @@ lima_resource_from_handle(struct pipe_screen *pscreen, *pres = *templat; pres->screen = pscreen; pipe_reference_init(&pres->reference, 1); - res->levels[0].offset = 0; + res->levels[0].offset = handle->offset; res->levels[0].stride = handle->stride; + struct lima_screen *screen = lima_screen(pscreen); res->bo = lima_bo_import(screen, handle); if (!res->bo) { FREE(res);