[Mesa-dev] [PATCH v5 12/12] vc4: add pipe_screen ref counting

Rob Herring robh at kernel.org
Mon Aug 7 22:58:19 UTC 2017


Use the common pipe_screen ref counting and fd hashing functions for
vc4. This is necessary to only create a single pipe_screen for a
process and avoid multiple imports of same prime fd.

Cc: Eric Anholt <eric at anholt.net>
Signed-off-by: Rob Herring <robh at kernel.org>
---
 src/gallium/winsys/vc4/drm/vc4_drm_winsys.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
index b2ffa90fe19e..51c6414ad848 100644
--- a/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
+++ b/src/gallium/winsys/vc4/drm/vc4_drm_winsys.c
@@ -27,15 +27,32 @@
 #include "renderonly/renderonly.h"
 #include "vc4_drm_public.h"
 #include "vc4/vc4_screen.h"
+#include "util/u_screen.h"
 
 struct pipe_screen *
 vc4_drm_screen_create(int fd)
 {
-   return vc4_screen_create(fcntl(fd, F_DUPFD_CLOEXEC, 3), NULL);
+   int dupfd;
+   struct pipe_screen *pscreen = pipe_screen_reference(fd);
+   if (pscreen)
+      return pscreen;
+
+   dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
+   pscreen = vc4_screen_create(dupfd, NULL);
+   pipe_screen_reference_init(pscreen, dupfd);
+   return pscreen;
 }
 
 struct pipe_screen *
 vc4_drm_screen_create_renderonly(struct renderonly *ro)
 {
-   return vc4_screen_create(fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3), ro);
+   int dupfd;
+   struct pipe_screen *pscreen = pipe_screen_reference(ro->gpu_fd);
+   if (pscreen)
+      return pscreen;
+
+   dupfd = fcntl(ro->gpu_fd, F_DUPFD_CLOEXEC, 3);
+   pscreen = vc4_screen_create(dupfd, ro);
+   pipe_screen_reference_init(pscreen, dupfd);
+   return pscreen;
 }
-- 
2.11.0



More information about the mesa-dev mailing list