<div dir="ltr">Hi<div><br></div><div>I've just confirmed this works for getting details from vainfo and vdpauinfo using DRI_PRIME=1 without needing to set up offloading with xrandr</div><div><br></div><div>I do however need to specify the driver still, is that something being worked on? It would be great if it autoselected based on the card running at DRI_PRIME=1 (or x if there's more than one card)</div><div><br></div><div>Cheers</div><div><br></div><div>Mike</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 20 Sep 2016 at 05:52 Nayan Deshmukh <<a href="mailto:nayan26deshmukh@gmail.com">nayan26deshmukh@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In case of prime when rendering is done on GPU other then the<br>
server GPU, use a seprate linear buffer for each back buffer<br>
which will be displayed using present extension.<br>
<br>
v2: Use a seprate linear buffer for each back buffer (Michel)<br>
v3: Change variable names and fix coding style (Leo and Emil)<br>
v4: Use PIPE_BIND_SAMPLER_VIEW for back buffer in case when<br>
    a seprate linear buffer is used (Michel)<br>
v4.1: remove empty line<br>
v4.2: destroy the context and handle the case when<br>
      create_context fails (Emil)<br>
<br>
Signed-off-by: Nayan Deshmukh <<a href="mailto:nayan26deshmukh@gmail.com" target="_blank">nayan26deshmukh@gmail.com</a>><br>
Reviewed-by: Leo Liu <<a href="mailto:leo.liu@amd.com" target="_blank">leo.liu@amd.com</a>><br>
Acked-by: Michel Dänzer <<a href="mailto:michel.daenzer@amd.com" target="_blank">michel.daenzer@amd.com</a>><br>
---<br>
 src/gallium/auxiliary/vl/vl_winsys_dri3.c | 66 +++++++++++++++++++++++++------<br>
 1 file changed, 53 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/src/gallium/auxiliary/vl/vl_winsys_dri3.c b/src/gallium/auxiliary/vl/vl_winsys_dri3.c<br>
index 3d596a6..191a64b 100644<br>
--- a/src/gallium/auxiliary/vl/vl_winsys_dri3.c<br>
+++ b/src/gallium/auxiliary/vl/vl_winsys_dri3.c<br>
@@ -49,6 +49,7 @@<br>
 struct vl_dri3_buffer<br>
 {<br>
    struct pipe_resource *texture;<br>
+   struct pipe_resource *linear_texture;<br>
<br>
    uint32_t pixmap;<br>
    uint32_t sync_fence;<br>
@@ -69,6 +70,8 @@ struct vl_dri3_screen<br>
    xcb_present_event_t eid;<br>
    xcb_special_event_t *special_event;<br>
<br>
+   struct pipe_context *pipe;<br>
+<br>
    struct vl_dri3_buffer *back_buffers[BACK_BUFFER_NUM];<br>
    int cur_back;<br>
<br>
@@ -82,6 +85,7 @@ struct vl_dri3_screen<br>
    int64_t last_ust, ns_frame, last_msc, next_msc;<br>
<br>
    bool flushed;<br>
+   bool is_different_gpu;<br>
 };<br>
<br>
 static void<br>
@@ -102,6 +106,8 @@ dri3_free_back_buffer(struct vl_dri3_screen *scrn,<br>
    xcb_sync_destroy_fence(scrn->conn, buffer->sync_fence);<br>
    xshmfence_unmap_shm(buffer->shm_fence);<br>
    pipe_resource_reference(&buffer->texture, NULL);<br>
+   if (buffer->linear_texture)<br>
+       pipe_resource_reference(&buffer->linear_texture, NULL);<br>
    FREE(buffer);<br>
 }<br>
<br>
@@ -209,7 +215,7 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)<br>
    xcb_sync_fence_t sync_fence;<br>
    struct xshmfence *shm_fence;<br>
    int buffer_fd, fence_fd;<br>
-   struct pipe_resource templ;<br>
+   struct pipe_resource templ, *pixmap_buffer_texture;<br>
    struct winsys_handle whandle;<br>
    unsigned usage;<br>
<br>
@@ -226,8 +232,7 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)<br>
       goto close_fd;<br>
<br>
    memset(&templ, 0, sizeof(templ));<br>
-   templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW |<br>
-                PIPE_BIND_SCANOUT | PIPE_BIND_SHARED;<br>
+   templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;<br>
    templ.format = PIPE_FORMAT_B8G8R8X8_UNORM;<br>
    templ.target = PIPE_TEXTURE_2D;<br>
    templ.last_level = 0;<br>
@@ -235,16 +240,34 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)<br>
    templ.height0 = scrn->height;<br>
    templ.depth0 = 1;<br>
    templ.array_size = 1;<br>
-   buffer->texture = scrn->base.pscreen->resource_create(scrn->base.pscreen,<br>
-                                                         &templ);<br>
-   if (!buffer->texture)<br>
-      goto unmap_shm;<br>
<br>
+   if (scrn->is_different_gpu) {<br>
+      buffer->texture = scrn->base.pscreen->resource_create(scrn->base.pscreen,<br>
+                                                            &templ);<br>
+      if (!buffer->texture)<br>
+         goto unmap_shm;<br>
+<br>
+      templ.bind |= PIPE_BIND_SCANOUT | PIPE_BIND_SHARED |<br>
+                    PIPE_BIND_LINEAR;<br>
+      buffer->linear_texture = scrn->base.pscreen->resource_create(scrn->base.pscreen,<br>
+                                                                  &templ);<br>
+      pixmap_buffer_texture = buffer->linear_texture;<br>
+<br>
+      if (!buffer->linear_texture)<br>
+         goto no_linear_texture;<br>
+   } else {<br>
+      templ.bind |= PIPE_BIND_SCANOUT | PIPE_BIND_SHARED;<br>
+      buffer->texture = scrn->base.pscreen->resource_create(scrn->base.pscreen,<br>
+                                                            &templ);<br>
+      if (!buffer->texture)<br>
+         goto unmap_shm;<br>
+      pixmap_buffer_texture = buffer->texture;<br>
+   }<br>
    memset(&whandle, 0, sizeof(whandle));<br>
    whandle.type= DRM_API_HANDLE_TYPE_FD;<br>
    usage = PIPE_HANDLE_USAGE_EXPLICIT_FLUSH | PIPE_HANDLE_USAGE_READ;<br>
    scrn->base.pscreen->resource_get_handle(scrn->base.pscreen, NULL,<br>
-                                           buffer->texture, &whandle,<br>
+                                           pixmap_buffer_texture, &whandle,<br>
                                            usage);<br>
    buffer_fd = whandle.handle;<br>
    buffer->pitch = whandle.stride;<br>
@@ -271,6 +294,8 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)<br>
<br>
    return buffer;<br>
<br>
+no_linear_texture:<br>
+   pipe_resource_reference(&buffer->texture, NULL);<br>
 unmap_shm:<br>
    xshmfence_unmap_shm(shm_fence);<br>
 close_fd:<br>
@@ -474,6 +499,7 @@ vl_dri3_flush_frontbuffer(struct pipe_screen *screen,<br>
    struct vl_dri3_screen *scrn = (struct vl_dri3_screen *)context_private;<br>
    uint32_t options = XCB_PRESENT_OPTION_NONE;<br>
    struct vl_dri3_buffer *back;<br>
+   struct pipe_box src_box;<br>
<br>
    back = scrn->back_buffers[scrn->cur_back];<br>
    if (!back)<br>
@@ -485,6 +511,16 @@ vl_dri3_flush_frontbuffer(struct pipe_screen *screen,<br>
             return;<br>
    }<br>
<br>
+   if (scrn->is_different_gpu) {<br>
+      u_box_origin_2d(scrn->width, scrn->height, &src_box);<br>
+      scrn->pipe->resource_copy_region(scrn->pipe,<br>
+                                       back->linear_texture,<br>
+                                       0, 0, 0, 0,<br>
+                                       back->texture,<br>
+                                       0, &src_box);<br>
+<br>
+      scrn->pipe->flush(scrn->pipe, NULL, 0);<br>
+   }<br>
    xshmfence_reset(back->shm_fence);<br>
    back->busy = true;<br>
<br>
@@ -622,6 +658,7 @@ vl_dri3_screen_destroy(struct vl_screen *vscreen)<br>
       xcb_discard_reply(scrn->conn, cookie.sequence);<br>
       xcb_unregister_for_special_event(scrn->conn, scrn->special_event);<br>
    }<br>
+   scrn->pipe->destroy(scrn->pipe);<br>
    scrn->base.pscreen->destroy(scrn->base.pscreen);<br>
    pipe_loader_release(&scrn->base.dev, 1);<br>
    FREE(scrn);<br>
@@ -638,7 +675,6 @@ vl_dri3_screen_create(Display *display, int screen)<br>
    xcb_dri3_open_reply_t *open_reply;<br>
    xcb_get_geometry_cookie_t geom_cookie;<br>
    xcb_get_geometry_reply_t *geom_reply;<br>
-   int is_different_gpu;<br>
    int fd;<br>
<br>
    assert(display);<br>
@@ -677,10 +713,7 @@ vl_dri3_screen_create(Display *display, int screen)<br>
    fcntl(fd, F_SETFD, FD_CLOEXEC);<br>
    free(open_reply);<br>
<br>
-   fd = loader_get_user_preferred_fd(fd, &is_different_gpu);<br>
-   /* TODO support different GPU */<br>
-   if (is_different_gpu)<br>
-      goto close_fd;<br>
+   fd = loader_get_user_preferred_fd(fd, &scrn->is_different_gpu);<br>
<br>
    geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));<br>
    geom_reply = xcb_get_geometry_reply(scrn->conn, geom_cookie, NULL);<br>
@@ -699,6 +732,11 @@ vl_dri3_screen_create(Display *display, int screen)<br>
    if (!scrn->base.pscreen)<br>
       goto release_pipe;<br>
<br>
+   scrn->pipe = scrn->base.pscreen->context_create(scrn->base.pscreen,<br>
+                                                   &scrn->base, 0);<br>
+   if (!scrn->pipe)<br>
+       goto no_context;<br>
+<br>
    scrn->base.destroy = vl_dri3_screen_destroy;<br>
    scrn->base.texture_from_drawable = vl_dri3_screen_texture_from_drawable;<br>
    scrn->base.get_dirty_area = vl_dri3_screen_get_dirty_area;<br>
@@ -709,6 +747,8 @@ vl_dri3_screen_create(Display *display, int screen)<br>
<br>
    return &scrn->base;<br>
<br>
+no_context:<br>
+   scrn->base.pscreen->destroy(scrn->base.pscreen);<br>
 release_pipe:<br>
    if (scrn->base.dev) {<br>
       pipe_loader_release(&scrn->base.dev, 1);<br>
--<br>
2.7.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>