[PATCH 8/8] modesetting: Use GBM for buffer allocations if Glamor supports it.

Kenneth Graunke kenneth at whitecape.org
Tue Dec 9 16:55:31 PST 2014


For performance, Glamor wants to render to tiled buffers, not linear
ones.  Using GBM allows us to pick the 3D driver's preferred tiling
modes.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 hw/xfree86/drivers/modesetting/driver.c          | 20 +++++++--
 hw/xfree86/drivers/modesetting/drmmode_display.c | 56 ++++++++++++++++++++++--
 hw/xfree86/drivers/modesetting/drmmode_display.h |  8 ++++
 3 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index dea709e..34a079e 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -877,7 +877,7 @@ CreateScreenResources(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap;
     Bool ret;
-    void *pixels;
+    void *pixels = NULL;
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
@@ -893,9 +893,16 @@ CreateScreenResources(ScreenPtr pScreen)
 
     if (!ms->drmmode.sw_cursor)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
-    pixels = drmmode_map_front_bo(&ms->drmmode);
-    if (!pixels)
-        return FALSE;
+
+#ifdef GLAMOR_HAS_GBM
+    if (!ms->drmmode.gbm) {
+#else
+    if (1) {
+#endif
+        pixels = drmmode_map_front_bo(&ms->drmmode);
+        if (!pixels)
+            return FALSE;
+    }
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
@@ -985,6 +992,11 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
     if (!SetMaster(pScrn))
         return FALSE;
 
+#ifdef GLAMOR_HAS_GBM
+    if (ms->drmmode.glamor)
+        ms->drmmode.gbm = glamor_egl_get_gbm_device(pScreen);
+#endif
+
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 29b8844..94d857b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -53,6 +53,9 @@
 #ifdef GLAMOR
 #define GLAMOR_FOR_XORG 1
 #include "glamor.h"
+#ifdef GLAMOR_HAS_GBM
+#include <gbm.h>
+#endif
 #endif
 
 static int
@@ -60,6 +63,13 @@ drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 {
     int ret;
 
+#ifdef GLAMOR_HAS_GBM
+    if (bo->gbm) {
+        gbm_bo_destroy(bo->gbm);
+        bo->gbm = NULL;
+    }
+#endif
+
     if (bo->dumb) {
         ret = dumb_bo_destroy(drmmode->fd, bo->dumb);
         if (ret == 0)
@@ -72,12 +82,22 @@ drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 static uint32_t
 drmmode_bo_get_pitch(drmmode_bo *bo)
 {
+#ifdef GLAMOR_HAS_GBM
+    if (bo->gbm)
+        return gbm_bo_get_stride(bo->gbm);
+#endif
+
     return bo->dumb->pitch;
 }
 
 uint32_t
 drmmode_bo_get_handle(drmmode_bo *bo)
 {
+#ifdef GLAMOR_HAS_GBM
+    if (bo->gbm)
+        return gbm_bo_get_handle(bo->gbm).u32;
+#endif
+
     return bo->dumb->handle;
 }
 
@@ -85,6 +105,15 @@ static Bool
 drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
                   unsigned width, unsigned height, unsigned bpp)
 {
+#ifdef GLAMOR_HAS_GBM
+    if (drmmode->glamor) {
+        bo->gbm = gbm_bo_create(drmmode->gbm, width, height,
+                                GBM_FORMAT_ARGB8888,
+                                GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT);
+        return bo->gbm != NULL;
+    }
+#endif
+
     bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp);
     return bo->dumb != NULL;
 }
@@ -1110,10 +1139,22 @@ drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode)
 #ifdef GLAMOR
     ScrnInfoPtr scrn = drmmode->scrn;
     ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn);
+    PixmapPtr screen_pixmap;
+    void *gbm_bo;
 
     if (!drmmode->glamor)
         return TRUE;
 
+#ifdef GLAMOR_HAS_GBM
+    gbm_bo = drmmode->front_bo.gbm;
+    screen_pixmap = screen->GetScreenPixmap(screen);
+
+    if (!glamor_egl_create_textured_pixmap_from_gbm_bo(screen_pixmap, gbm_bo)) {
+        xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed");
+        return FALSE;
+    }
+    glamor_set_screen_pixmap(screen_pixmap, NULL);
+#else
     if (!glamor_egl_create_textured_screen(screen,
                                            drmmode_bo_get_handle(&drmmode->front_bo),
                                            scrn->displayWidth *
@@ -1123,6 +1164,7 @@ drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode)
         return FALSE;
     }
 #endif
+#endif
 
     return TRUE;
 }
@@ -1142,7 +1184,7 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
     int i, pitch, old_width, old_height, old_pitch;
     int cpp = (scrn->bitsPerPixel + 7) / 8;
     PixmapPtr ppix = screen->GetScreenPixmap(screen);
-    void *new_pixels;
+    void *new_pixels = NULL;
 
     if (scrn->virtualX == width && scrn->virtualY == height)
         return TRUE;
@@ -1178,9 +1220,15 @@ drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
     if (ret)
         goto fail;
 
-    new_pixels = drmmode_map_front_bo(drmmode);
-    if (!new_pixels)
-        goto fail;
+#ifdef GLAMOR_HAS_GBM
+    if (!drmmode->gbm) {
+#else
+    if (1) {
+#endif
+        new_pixels = drmmode_map_front_bo(drmmode);
+        if (!new_pixels)
+            goto fail;
+    }
 
     if (drmmode->shadow_enable) {
         uint32_t size = scrn->displayWidth * scrn->virtualY *
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 7c1ff05..401b09b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -36,6 +36,9 @@
 
 typedef struct {
     struct dumb_bo *dumb;
+#ifdef GLAMOR_HAS_GBM
+    struct gbm_bo *gbm;
+#endif
 } drmmode_bo;
 
 typedef struct {
@@ -46,6 +49,11 @@ typedef struct {
     drmModeFBPtr mode_fb;
     int cpp;
     ScrnInfoPtr scrn;
+
+#ifdef GLAMOR_HAS_GBM
+    struct gbm_device *gbm;
+#endif
+
 #ifdef CONFIG_UDEV_KMS
     struct udev_monitor *uevent_monitor;
     InputHandlerProc uevent_handler;
-- 
2.1.3



More information about the xorg-devel mailing list