virgl: add resource_reference to virgl_winsys
authorChia-I Wu <olvaffe@gmail.com>
Wed, 15 May 2019 22:28:52 +0000 (15:28 -0700)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 17 Jun 2019 16:36:31 +0000 (09:36 -0700)
It works similar to pipe_resource_reference but is for virgl_hw_res.
It can also replace resource_unref.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_winsys.h
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
src/gallium/winsys/virgl/vtest/virgl_vtest_winsys.c

index 4d427894dacf64a85b0bdf974f3fbc17612ca3e4..1c8e264e5731f6aaf0bb642fd294595e30860a27 100644 (file)
@@ -459,7 +459,7 @@ void virgl_resource_destroy(struct pipe_screen *screen,
    if (res->u.b.target == PIPE_BUFFER)
       util_range_destroy(&res->valid_buffer_range);
 
-   vs->vws->resource_unref(vs->vws, res->hw_res);
+   vs->vws->resource_reference(vs->vws, &res->hw_res, NULL);
    FREE(res);
 }
 
index bab3dbaa2d13a64cc47c98c54ef9ee64a5682c23..d880648d59d36356848bdd1180bd405e1975e739 100644 (file)
@@ -70,7 +70,9 @@ struct virgl_winsys {
                                uint32_t last_level, uint32_t nr_samples,
                                uint32_t size);
 
-   void (*resource_unref)(struct virgl_winsys *vws, struct virgl_hw_res *res);
+   void (*resource_reference)(struct virgl_winsys *qws,
+                              struct virgl_hw_res **dres,
+                              struct virgl_hw_res *sres);
 
    void *(*resource_map)(struct virgl_winsys *vws, struct virgl_hw_res *res);
    void (*resource_wait)(struct virgl_winsys *vws, struct virgl_hw_res *res);
index 4ce2302f317fbfe95327a895616457834e84984a..41e47837acfe4c70a7f40bcb438916127abd0056 100644 (file)
@@ -121,11 +121,13 @@ virgl_drm_winsys_destroy(struct virgl_winsys *qws)
    FREE(qdws);
 }
 
-static void virgl_drm_resource_reference(struct virgl_drm_winsys *qdws,
-                                       struct virgl_hw_res **dres,
-                                       struct virgl_hw_res *sres)
+static void virgl_drm_resource_reference(struct virgl_winsys *qws,
+                                         struct virgl_hw_res **dres,
+                                         struct virgl_hw_res *sres)
 {
+   struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
    struct virgl_hw_res *old = *dres;
+
    if (pipe_reference(&(*dres)->reference, &sres->reference)) {
 
       if (!can_cache_resource_with_bind(old->bind) ||
@@ -338,7 +340,7 @@ virgl_drm_winsys_resource_create_handle(struct virgl_winsys *qws,
 
    if (res) {
       struct virgl_hw_res *r = NULL;
-      virgl_drm_resource_reference(qdws, &r, res);
+      virgl_drm_resource_reference(&qdws->base, &r, res);
       goto done;
    }
 
@@ -429,14 +431,6 @@ static boolean virgl_drm_winsys_resource_get_handle(struct virgl_winsys *qws,
    return TRUE;
 }
 
-static void virgl_drm_winsys_resource_unref(struct virgl_winsys *qws,
-                                            struct virgl_hw_res *hres)
-{
-   struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
-
-   virgl_drm_resource_reference(qdws, &hres, NULL);
-}
-
 static void *virgl_drm_resource_map(struct virgl_winsys *qws,
                                     struct virgl_hw_res *res)
 {
@@ -503,12 +497,11 @@ static bool virgl_drm_alloc_res_list(struct virgl_drm_cmd_buf *cbuf,
 
 static void virgl_drm_free_res_list(struct virgl_drm_cmd_buf *cbuf)
 {
-   struct virgl_drm_winsys *qdws = virgl_drm_winsys(cbuf->ws);
    int i;
 
    for (i = 0; i < cbuf->cres; i++) {
       p_atomic_dec(&cbuf->res_bo[i]->num_cs_references);
-      virgl_drm_resource_reference(qdws, &cbuf->res_bo[i], NULL);
+      virgl_drm_resource_reference(cbuf->ws, &cbuf->res_bo[i], NULL);
    }
    FREE(cbuf->res_hlist);
    FREE(cbuf->res_bo);
@@ -564,7 +557,7 @@ static void virgl_drm_add_res(struct virgl_drm_winsys *qdws,
    }
 
    cbuf->res_bo[cbuf->cres] = NULL;
-   virgl_drm_resource_reference(qdws, &cbuf->res_bo[cbuf->cres], res);
+   virgl_drm_resource_reference(&qdws->base, &cbuf->res_bo[cbuf->cres], res);
    cbuf->res_hlist[cbuf->cres] = res->bo_handle;
    cbuf->is_handle_added[hash] = TRUE;
 
@@ -576,7 +569,6 @@ static void virgl_drm_add_res(struct virgl_drm_winsys *qdws,
 /* This is called after the cbuf is submitted. */
 static void virgl_drm_clear_res_list(struct virgl_drm_cmd_buf *cbuf)
 {
-   struct virgl_drm_winsys *qdws = virgl_drm_winsys(cbuf->ws);
    int i;
 
    for (i = 0; i < cbuf->cres; i++) {
@@ -584,7 +576,7 @@ static void virgl_drm_clear_res_list(struct virgl_drm_cmd_buf *cbuf)
       p_atomic_set(&cbuf->res_bo[i]->maybe_busy, true);
 
       p_atomic_dec(&cbuf->res_bo[i]->num_cs_references);
-      virgl_drm_resource_reference(qdws, &cbuf->res_bo[i], NULL);
+      virgl_drm_resource_reference(cbuf->ws, &cbuf->res_bo[i], NULL);
    }
 
    cbuf->cres = 0;
@@ -983,7 +975,7 @@ virgl_drm_winsys_create(int drmFD)
    qdws->base.transfer_put = virgl_bo_transfer_put;
    qdws->base.transfer_get = virgl_bo_transfer_get;
    qdws->base.resource_create = virgl_drm_winsys_resource_cache_create;
-   qdws->base.resource_unref = virgl_drm_winsys_resource_unref;
+   qdws->base.resource_reference = virgl_drm_resource_reference;
    qdws->base.resource_create_from_handle = virgl_drm_winsys_resource_create_handle;
    qdws->base.resource_get_handle = virgl_drm_winsys_resource_get_handle;
    qdws->base.resource_map = virgl_drm_resource_map;
index 8bc28af45de684f8afec42adc94e8438e5ee8a35..b6f5a8324e798956b7c3f088517be80fb4b99deb 100644 (file)
@@ -202,11 +202,13 @@ static boolean virgl_vtest_resource_is_busy(struct virgl_winsys *vws,
    return ret == 1 ? TRUE : FALSE;
 }
 
-static void virgl_vtest_resource_reference(struct virgl_vtest_winsys *vtws,
+static void virgl_vtest_resource_reference(struct virgl_winsys *vws,
                                            struct virgl_hw_res **dres,
                                            struct virgl_hw_res *sres)
 {
+   struct virgl_vtest_winsys *vtws = virgl_vtest_winsys(vws);
    struct virgl_hw_res *old = *dres;
+
    if (pipe_reference(&(*dres)->reference, &sres->reference)) {
       if (!can_cache_resource_with_bind(old->bind)) {
          virgl_hw_res_destroy(vtws, old);
@@ -296,13 +298,6 @@ out:
    return res;
 }
 
-static void virgl_vtest_winsys_resource_unref(struct virgl_winsys *vws,
-                                              struct virgl_hw_res *hres)
-{
-   struct virgl_vtest_winsys *vtws = virgl_vtest_winsys(vws);
-   virgl_vtest_resource_reference(vtws, &hres, NULL);
-}
-
 static void *virgl_vtest_resource_map(struct virgl_winsys *vws,
                                       struct virgl_hw_res *res)
 {
@@ -409,7 +404,7 @@ static void virgl_vtest_release_all_res(struct virgl_vtest_winsys *vtws,
 
    for (i = 0; i < cbuf->cres; i++) {
       p_atomic_dec(&cbuf->res_bo[i]->num_cs_references);
-      virgl_vtest_resource_reference(vtws, &cbuf->res_bo[i], NULL);
+      virgl_vtest_resource_reference(&vtws->base, &cbuf->res_bo[i], NULL);
    }
    cbuf->cres = 0;
 }
@@ -435,7 +430,7 @@ static void virgl_vtest_add_res(struct virgl_vtest_winsys *vtws,
    }
 
    cbuf->res_bo[cbuf->cres] = NULL;
-   virgl_vtest_resource_reference(vtws, &cbuf->res_bo[cbuf->cres], res);
+   virgl_vtest_resource_reference(&vtws->base, &cbuf->res_bo[cbuf->cres], res);
    cbuf->is_handle_added[hash] = TRUE;
 
    cbuf->reloc_indices_hashlist[hash] = cbuf->cres;
@@ -586,7 +581,7 @@ static void virgl_fence_reference(struct virgl_winsys *vws,
                                   struct pipe_fence_handle *src)
 {
    struct virgl_vtest_winsys *vdws = virgl_vtest_winsys(vws);
-   virgl_vtest_resource_reference(vdws, (struct virgl_hw_res **)dst,
+   virgl_vtest_resource_reference(&vdws->base, (struct virgl_hw_res **)dst,
                                   virgl_hw_res(src));
 }
 
@@ -678,7 +673,7 @@ virgl_vtest_winsys_wrap(struct sw_winsys *sws)
    vtws->base.transfer_get = virgl_vtest_transfer_get;
 
    vtws->base.resource_create = virgl_vtest_winsys_resource_cache_create;
-   vtws->base.resource_unref = virgl_vtest_winsys_resource_unref;
+   vtws->base.resource_reference = virgl_vtest_resource_reference;
    vtws->base.resource_map = virgl_vtest_resource_map;
    vtws->base.resource_wait = virgl_vtest_resource_wait;
    vtws->base.resource_is_busy = virgl_vtest_resource_is_busy;