Module: Mesa
Branch: main
Commit: d7fa2561a5e31b22b84b5735e2cdcbe27b8a7dfb
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=d7fa2561a5e31b22b84b5735e2cdcbe27b8a7dfb

Author: Feng Jiang <[email protected]>
Date:   Wed Aug 17 09:54:09 2022 +0800

virgl: Only PIPE_BUFFER with VIRGL_BIND_CUSTOM flag is considered busy during 
creation

When the virglrenderer performs the attach action for the PIPE_BUFFER
with the VIRGL_BIND_CUSTOM flag, it will synchronize the data from
res->ptr to res->iov, at this time we need to treat it as busy,
otherwise it will cause some race conditions.

This optimizes commit:
fe9333f7b5e ("virgl: Set res->maybe_busy to true when creating resources")

Signed-off-by: Feng Jiang <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18098>

---

 src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 10 +++++++++-
 1 file changed, 9 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 f827e719139..e3bbd34f00e 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
@@ -415,6 +415,7 @@ virgl_drm_winsys_resource_cache_create(struct virgl_winsys 
*qws,
                                        uint32_t flags,
                                        uint32_t size)
 {
+   bool need_sync = false;
    struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
    struct virgl_hw_res *res;
    struct virgl_resource_cache_entry *entry;
@@ -446,6 +447,13 @@ virgl_drm_winsys_resource_cache_create(struct virgl_winsys 
*qws,
    mtx_unlock(&qdws->mutex);
 
 alloc:
+   /* PIPE_BUFFER with VIRGL_BIND_CUSTOM flag will access data when attaching,
+    * in order to avoid race conditions we need to treat it as busy during
+    * creation
+    */
+   if (target == PIPE_BUFFER && (bind & VIRGL_BIND_CUSTOM))
+       need_sync = true;
+
    if (flags & (VIRGL_RESOURCE_FLAG_MAP_PERSISTENT |
                 VIRGL_RESOURCE_FLAG_MAP_COHERENT))
       res = virgl_drm_winsys_resource_create_blob(qws, target, format, bind,
@@ -456,7 +464,7 @@ alloc:
       res = virgl_drm_winsys_resource_create(qws, target, format, bind, width,
                                              height, depth, array_size,
                                              last_level, nr_samples, size,
-                                             true);
+                                             need_sync);
    return res;
 }
 

Reply via email to