<div dir="ltr">Hi Mike,<div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 20, 2016 at 5:45 PM, Mike Lothian <span dir="ltr"><<a href="mailto:mike@fireburn.co.uk" target="_blank">mike@fireburn.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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></blockquote><div>I have a prime system and I don't need to specify any drivers in my system. </div><div>Though I am not the right person to answer this question. </div><div>Maybe Michel can answer this.</div><div><br></div><div>Cheers,</div><div>Nayan Â Â </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>Cheers</div><div><br></div><div>Mike</div></div><br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Tue, 20 Sep 2016 at 05:52 Nayan Deshmukh <<a href="mailto:nayan26deshmukh@gmail.com" target="_blank">nayan26deshmukh@gmail.com</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">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_<wbr>winsys_dri3.c | 66 +++++++++++++++++++++++++-----<wbr>-<br>
 1 file changed, 53 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..191a64b 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>
<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]<wbr>;<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-><wbr>conn, buffer->sync_fence);<br>
  Â  xshmfence_unmap_shm(buffer-><wbr>shm_fence);<br>
  Â  pipe_resource_reference(&<wbr>buffer->texture, NULL);<br>
+  Â if (buffer->linear_texture)<br>
+  Â  Â  Â pipe_resource_reference(&<wbr>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_<wbr>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_<wbr>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_<wbr>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_<wbr>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_<wbr>FLUSH | 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>
<br>
  Â  return buffer;<br>
<br>
+no_linear_texture:<br>
+  Â pipe_resource_reference(&<wbr>buffer->texture, NULL);<br>
 unmap_shm:<br>
  Â  xshmfence_unmap_shm(shm_fence)<wbr>;<br>
 close_fd:<br>
@@ -474,6 +499,7 @@ vl_dri3_flush_frontbuffer(<wbr>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_<wbr>back];<br>
  Â  if (!back)<br>
@@ -485,6 +511,16 @@ vl_dri3_flush_frontbuffer(<wbr>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_<wbr>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_<wbr>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_<wbr>event(scrn->conn, scrn->special_event);<br>
  Â  }<br>
+  Â scrn->pipe->destroy(scrn-><wbr>pipe);<br>
  Â  scrn->base.pscreen->destroy(<wbr>scrn->base.pscreen);<br>
  Â  pipe_loader_release(&scrn-><wbr>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(<wbr>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(<wbr>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-><wbr>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_<wbr>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_<wbr>drawable = vl_dri3_screen_texture_from_<wbr>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(<wbr>scrn->base.pscreen);<br>
 release_pipe:<br>
  Â  if (scrn->base.dev) {<br>
  Â  Â  Â pipe_loader_release(&scrn-><wbr>base.dev, 1);<br>
--<br>
2.7.4<br>
<br></div></div>
______________________________<wbr>_________________<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/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div>
</blockquote></div><br></div></div>