virgl: do not cache external resources
authorChia-I Wu <olvaffe@gmail.com>
Thu, 6 Jun 2019 21:58:39 +0000 (14:58 -0700)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 11 Jun 2019 17:03:54 +0000 (10:03 -0700)
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 <olvaffe@gmail.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
src/gallium/winsys/virgl/drm/virgl_drm_winsys.h

index 0f6403f691fcd5202dc4672bebb6dd5e2b879daa..441ca69d76afaee810d49ddebde33a25da9cc993 100644 (file)
@@ -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;
 }
index de84f308d97727f01ed8d7bb83ae7c57d2eed55e..8bc874cb351e0f9c5ffa17f60b94a68247082359 100644 (file)
@@ -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