vl/dri: add 10 bits format supports
authorLeo Liu <leo.liu@amd.com>
Fri, 7 Sep 2018 19:17:31 +0000 (15:17 -0400)
committerLeo Liu <leo.liu@amd.com>
Thu, 13 Sep 2018 18:28:32 +0000 (14:28 -0400)
v2: Tell B10G10R10X2 and R10G10B10X2 formats for different HW.

Signed-off-by: Leo Liu <leo.liu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/auxiliary/vl/vl_winsys.h
src/gallium/auxiliary/vl/vl_winsys_dri.c

index 77277cefe8b8f2a4eb34ae24b28d16455175ea5c..bfb6018007941a6578b5d3b540386c3225327d71 100644 (file)
@@ -68,9 +68,14 @@ struct vl_screen
 
    struct pipe_screen *pscreen;
    struct pipe_loader_device *dev;
+
+   void *xcb_screen;
 };
 
 #ifdef HAVE_X11_PLATFORM
+uint32_t
+vl_dri2_format_for_depth(struct vl_screen *vscreen, int depth);
+
 struct vl_screen *
 vl_dri2_screen_create(Display *display, int screen);
 #else
index bb1ff504886256b30b8363ba03b27432b0cdf2f0..cb779010a9c73a7fc9fd782583c3ff3324549692 100644 (file)
@@ -186,6 +186,7 @@ vl_dri2_screen_texture_from_drawable(struct vl_screen *vscreen, void *drawable)
    xcb_dri2_get_buffers_reply_t *reply;
    xcb_dri2_dri2_buffer_t *buffers, *back_left;
 
+   unsigned depth = ((xcb_screen_t *)(vscreen->xcb_screen))->root_depth;
    unsigned i;
 
    assert(scrn);
@@ -237,7 +238,7 @@ vl_dri2_screen_texture_from_drawable(struct vl_screen *vscreen, void *drawable)
 
    memset(&templ, 0, sizeof(templ));
    templ.target = PIPE_TEXTURE_2D;
-   templ.format = PIPE_FORMAT_B8G8R8X8_UNORM;
+   templ.format = vl_dri2_format_for_depth(vscreen, depth);
    templ.last_level = 0;
    templ.width0 = reply->width;
    templ.height0 = reply->height;
@@ -314,6 +315,58 @@ get_xcb_screen(xcb_screen_iterator_t iter, int screen)
     return NULL;
 }
 
+static xcb_visualtype_t *
+get_xcb_visualtype_for_depth(struct vl_screen *vscreen, int depth)
+{
+   xcb_visualtype_iterator_t visual_iter;
+   xcb_screen_t *screen = vscreen->xcb_screen;
+   xcb_depth_iterator_t depth_iter;
+
+   if (!screen)
+      return NULL;
+
+   depth_iter = xcb_screen_allowed_depths_iterator(screen);
+   for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
+      if (depth_iter.data->depth != depth)
+         continue;
+
+      visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
+      if (visual_iter.rem)
+         return visual_iter.data;
+   }
+
+   return NULL;
+}
+
+static uint32_t
+get_red_mask_for_depth(struct vl_screen *vscreen, int depth)
+{
+   xcb_visualtype_t *visual = get_xcb_visualtype_for_depth(vscreen, depth);
+
+   if (visual) {
+      return visual->red_mask;
+   }
+
+   return 0;
+}
+
+uint32_t
+vl_dri2_format_for_depth(struct vl_screen *vscreen, int depth)
+{
+   switch (depth) {
+   case 24:
+      return PIPE_FORMAT_B8G8R8X8_UNORM;
+   case 30:
+      /* Different preferred formats for different hw */
+      if (get_red_mask_for_depth(vscreen, 30) == 0x3ff)
+         return PIPE_FORMAT_R10G10B10X2_UNORM;
+      else
+         return PIPE_FORMAT_B10G10R10X2_UNORM;
+   default:
+      return PIPE_FORMAT_NONE;
+   }
+}
+
 struct vl_screen *
 vl_dri2_screen_create(Display *display, int screen)
 {
@@ -326,7 +379,6 @@ vl_dri2_screen_create(Display *display, int screen)
    xcb_dri2_authenticate_cookie_t authenticate_cookie;
    xcb_dri2_authenticate_reply_t *authenticate = NULL;
    xcb_screen_iterator_t s;
-   xcb_screen_t *xcb_screen;
    xcb_generic_error_t *error = NULL;
    char *device_name;
    int fd, device_name_length;
@@ -358,8 +410,8 @@ vl_dri2_screen_create(Display *display, int screen)
       goto free_query;
 
    s = xcb_setup_roots_iterator(xcb_get_setup(scrn->conn));
-   xcb_screen = get_xcb_screen(s, screen);
-   if (!xcb_screen)
+   scrn->base.xcb_screen = get_xcb_screen(s, screen);
+   if (!scrn->base.xcb_screen)
       goto free_query;
 
    driverType = XCB_DRI2_DRIVER_TYPE_DRI;
@@ -375,9 +427,8 @@ vl_dri2_screen_create(Display *display, int screen)
       }
    }
 
-   connect_cookie = xcb_dri2_connect_unchecked(scrn->conn,
-                                               xcb_screen->root,
-                                               driverType);
+   connect_cookie = xcb_dri2_connect_unchecked(
+      scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, driverType);
    connect = xcb_dri2_connect_reply(scrn->conn, connect_cookie, NULL);
    if (connect == NULL ||
        connect->driver_name_length + connect->device_name_length == 0)
@@ -397,9 +448,8 @@ vl_dri2_screen_create(Display *display, int screen)
    if (drmGetMagic(fd, &magic))
       goto close_fd;
 
-   authenticate_cookie = xcb_dri2_authenticate_unchecked(scrn->conn,
-                                                         xcb_screen->root,
-                                                         magic);
+   authenticate_cookie = xcb_dri2_authenticate_unchecked(
+      scrn->conn, ((xcb_screen_t *)(scrn->base.xcb_screen))->root, magic);
    authenticate = xcb_dri2_authenticate_reply(scrn->conn, authenticate_cookie, NULL);
 
    if (authenticate == NULL || !authenticate->authenticated)