From bac2dd958af0f8692ad101e548704280984bae86 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 13 Oct 2021 14:49:50 +1000 Subject: [PATCH] llvmpipe: fix userptr for texture resources. This is needed for CL image hostptr support, but it's possible it could hit these paths from GL/Vulkan Fixes: 9a57dceeb760 ("llvmpipe: add support for user memory pointers") Reviewed-By: Mike Blumenkrantz Part-of: (cherry picked from commit 17a565e0cfb79fb8078fcf7f7cc7b6be0ef887ba) --- .pick_status.json | 2 +- src/gallium/drivers/llvmpipe/lp_texture.c | 21 ++++++++++++++------- src/gallium/drivers/llvmpipe/lp_texture.h | 2 +- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 28c6a994f61..d569b0f182f 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -976,7 +976,7 @@ "description": "llvmpipe: fix userptr for texture resources.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "9a57dceeb760a1d4f7d9d1666bec0844ee41852e" }, diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index d303e8abbd5..5bfc8dbc973 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -440,7 +440,7 @@ llvmpipe_resource_destroy(struct pipe_screen *pscreen, struct llvmpipe_screen *screen = llvmpipe_screen(pscreen); struct llvmpipe_resource *lpr = llvmpipe_resource(pt); - if (!lpr->backable) { + if (!lpr->backable && !lpr->user_ptr) { if (lpr->dt) { /* display target */ struct sw_winsys *winsys = screen->winsys; @@ -454,11 +454,9 @@ llvmpipe_resource_destroy(struct pipe_screen *pscreen, lpr->tex_data = NULL; } } - else if (!lpr->userBuffer) { - if (lpr->data) { + else if (lpr->data) { if (!lpr->imported_memory) align_free(lpr->data); - } } } #ifdef DEBUG @@ -651,9 +649,18 @@ llvmpipe_resource_from_user_memory(struct pipe_screen *_screen, pipe_reference_init(&lpr->base.reference, 1); lpr->base.screen = _screen; - lpr->data = user_memory; - lpr->userBuffer = TRUE; + if (llvmpipe_resource_is_texture(&lpr->base)) { + if (!llvmpipe_texture_layout(screen, lpr, false)) + goto fail; + + lpr->tex_data = user_memory; + } else + lpr->data = user_memory; + lpr->user_ptr = true; return &lpr->base; +fail: + FREE(lpr); + return NULL; } void * @@ -875,7 +882,7 @@ llvmpipe_user_buffer_create(struct pipe_screen *screen, buffer->base.height0 = 1; buffer->base.depth0 = 1; buffer->base.array_size = 1; - buffer->userBuffer = TRUE; + buffer->user_ptr = true; buffer->data = ptr; return &buffer->base; diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h index eabfbeca8f0..c683cdd1e03 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.h +++ b/src/gallium/drivers/llvmpipe/lp_texture.h @@ -89,7 +89,7 @@ struct llvmpipe_resource */ void *data; - boolean userBuffer; /** Is this a user-space buffer? */ + bool user_ptr; /** Is this a user-space buffer? */ unsigned timestamp; unsigned id; /**< temporary, for debugging */