<div dir="ltr">Hi Leo,<div><br></div><div>Could you push the patches? I don't have the push access. </div><div><br></div><div>Regards,</div><div>Nayan.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 16, 2016 at 7:44 PM, Leo Liu <span dir="ltr"><<a href="mailto:leo.liu@amd.com" target="_blank">leo.liu@amd.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This Patch is Reviewed-by: Leo Liu <<a href="mailto:leo.liu@amd.com" target="_blank">leo.liu@amd.com</a>><div class="HOEnZb"><div class="h5"><br>
<br>
On 09/16/2016 08:51 AM, Nayan Deshmukh wrote:<br>
<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>
<br>
Signed-off-by: Nayan Deshmukh <<a href="mailto:nayan26deshmukh@gmail.com" target="_blank">nayan26deshmukh@gmail.com</a>><br>
---<br>
  src/gallium/auxiliary/vl/vl_wi<wbr>nsys_dri3.c | 61 ++++++++++++++++++++++++------<wbr>-<br>
  1 file changed, 48 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/src/gallium/auxiliary/vl/vl_<wbr>winsys_dri3.c b/src/gallium/auxiliary/vl/vl_<wbr>winsys_dri3.c<br>
index 3d596a6..e0aaad8 100644<br>
--- a/src/gallium/auxiliary/vl/vl_<wbr>winsys_dri3.c<br>
+++ b/src/gallium/auxiliary/vl/vl_<wbr>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>
       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>
  +   struct pipe_context *pipe;<br>
+<br>
     struct vl_dri3_buffer *back_buffers[BACK_BUFFER_NUM]<wbr>;<br>
     int cur_back;<br>
  @@ -82,6 +85,7 @@ struct vl_dri3_screen<br>
     int64_t last_ust, ns_frame, last_msc, next_msc;<br>
       bool flushed;<br>
+   bool is_different_gpu;<br>
  };<br>
    static void<br>
@@ -102,6 +106,8 @@ dri3_free_back_buffer(struct vl_dri3_screen *scrn,<br>
     xcb_sync_destroy_fence(scrn-><wbr>conn, buffer->sync_fence);<br>
     xshmfence_unmap_shm(buffer->s<wbr>hm_fence);<br>
     pipe_resource_reference(&buff<wbr>er->texture, NULL);<br>
+   if (buffer->linear_texture)<br>
+       pipe_resource_reference(&buff<wbr>er->linear_texture, NULL);<br>
     FREE(buffer);<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>
  @@ -226,8 +232,7 @@ dri3_alloc_back_buffer(struct vl_dri3_screen *scrn)<br>
        goto close_fd;<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_c<wbr>reate(scrn->base.pscreen,<br>
-                                                         &templ);<br>
-   if (!buffer->texture)<br>
-      goto unmap_shm;<br>
  +   if (scrn->is_different_gpu) {<br>
+      buffer->texture = scrn->base.pscreen->resource_c<wbr>reate(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_c<wbr>reate(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_c<wbr>reate(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_FLU<wbr>SH | PIPE_HANDLE_USAGE_READ;<br>
     scrn->base.pscreen->resource_<wbr>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>
       return buffer;<br>
  +no_linear_texture:<br>
+   pipe_resource_reference(&buff<wbr>er->texture, NULL);<br>
  unmap_shm:<br>
     xshmfence_unmap_shm(shm_<wbr>fence);<br>
  close_fd:<br>
@@ -474,6 +499,7 @@ vl_dri3_flush_frontbuffer(stru<wbr>ct 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>
       back = scrn->back_buffers[scrn->cur_b<wbr>ack];<br>
     if (!back)<br>
@@ -485,6 +511,16 @@ vl_dri3_flush_frontbuffer(stru<wbr>ct pipe_screen *screen,<br>
              return;<br>
     }<br>
  +   if (scrn->is_different_gpu) {<br>
+      u_box_origin_2d(scrn->width, scrn->height, &src_box);<br>
+      scrn->pipe->resource_copy_regi<wbr>on(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_fen<wbr>ce);<br>
     back->busy = true;<br>
  @@ -638,7 +674,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>
       assert(display);<br>
@@ -677,10 +712,7 @@ vl_dri3_screen_create(Display *display, int screen)<br>
     fcntl(fd, F_SETFD, FD_CLOEXEC);<br>
     free(open_reply);<br>
  -   fd = loader_get_user_preferred_fd(f<wbr>d, &is_different_gpu);<br>
-   /* TODO support different GPU */<br>
-   if (is_different_gpu)<br>
-      goto close_fd;<br>
+   fd = loader_get_user_preferred_fd(f<wbr>d, &scrn->is_different_gpu);<br>
       geom_cookie = xcb_get_geometry(scrn->conn, RootWindow(display, screen));<br>
     geom_reply = xcb_get_geometry_reply(scrn->c<wbr>onn, geom_cookie, NULL);<br>
@@ -699,6 +731,9 @@ vl_dri3_screen_create(Display *display, int screen)<br>
     if (!scrn->base.pscreen)<br>
        goto release_pipe;<br>
  +   scrn->pipe = scrn->base.pscreen->context_cr<wbr>eate(scrn->base.pscreen,<br>
+                                                   &scrn->base, 0);<br>
+<br>
     scrn->base.destroy = vl_dri3_screen_destroy;<br>
     scrn->base.texture_from_drawa<wbr>ble = vl_dri3_screen_texture_from_dr<wbr>awable;<br>
     scrn->base.get_dirty_area = vl_dri3_screen_get_dirty_area;<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>