From 71465fe569d782e798895ed7d06805b42a1eabec Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 6 Jun 2019 14:58:39 -0700 Subject: [PATCH] virgl: do not cache external resources We should not reuse a resource for other purposes when it can still be accessed by another process or device. Signed-off-by: Chia-I Wu Reviewed-by: Alexandros Frantzis --- src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 8 +++++++- src/gallium/winsys/virgl/drm/virgl_drm_winsys.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index 0f6403f691f..441ca69d76a 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -160,7 +160,8 @@ static void virgl_drm_resource_reference(struct virgl_drm_winsys *qdws, struct virgl_hw_res *old = *dres; if (pipe_reference(&(*dres)->reference, &sres->reference)) { - if (!can_cache_resource_with_bind(old->bind)) { + if (!can_cache_resource_with_bind(old->bind) || + p_atomic_read(&old->external)) { virgl_hw_res_destroy(qdws, old); } else { mtx_lock(&qdws->mutex); @@ -226,6 +227,7 @@ virgl_drm_winsys_resource_create(struct virgl_winsys *qws, res->size = size; res->stride = stride; pipe_reference_init(&res->reference, 1); + p_atomic_set(&res->external, false); p_atomic_set(&res->num_cs_references, 0); return res; } @@ -456,6 +458,7 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws, res->size = info_arg.size; res->stride = info_arg.stride; pipe_reference_init(&res->reference, 1); + p_atomic_set(&res->external, true); res->num_cs_references = 0; if (res->flink_name) @@ -502,6 +505,9 @@ static boolean virgl_drm_winsys_resource_get_handle(struct virgl_winsys *qws, util_hash_table_set(qdws->bo_handles, (void *)(uintptr_t)res->bo_handle, res); mtx_unlock(&qdws->bo_handles_mutex); } + + p_atomic_set(&res->external, true); + whandle->stride = stride; return TRUE; } diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h index de84f308d97..8bc874cb351 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h @@ -47,6 +47,9 @@ struct virgl_hw_res { uint32_t bind; int64_t start, end; uint32_t flink_name; + + /* true when the resource is imported or exported */ + int external; }; struct virgl_drm_winsys -- 2.30.2