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

Submitted by Rob Herring on Aug. 7, 2017, 10:58 p.m.

Details

Message ID 20170807225819.13831-21-robh@kernel.org
State New
Headers show
Series "Common pipe screen ref counting" ( rev: 5 ) in Mesa

Not browsing as part of any series.

Commit Message

Rob Herring Aug. 7, 2017, 10:58 p.m.
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@anholt.net>
Signed-off-by: Rob Herring <robh@kernel.org>
---
 src/gallium/winsys/vc4/drm/vc4_drm_winsys.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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;
 }