[Mesa-dev] [PATCH] virgl: native fence fd support

Stefan Schake stschake at gmail.com
Tue Feb 20 18:13:09 UTC 2018


Hi Gustavo,


On Fri, Feb 16, 2018 at 4:01 PM, Gustavo Padovan <gustavo at padovan.org> wrote:
> From: Gustavo Padovan <gustavo.padovan at collabora.com>
>
> Following the support for fences on the virtio driver add support
> for native fence on virgl. This was somewhat based on the freedeno one.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan at collabora.com>
> ---
>
>  static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
> -                                       struct virgl_cmd_buf *_cbuf)
> +                                       struct virgl_cmd_buf *_cbuf,
> +                                       int in_fence_fd, int *out_fence_fd)
>  {
>     struct virgl_drm_winsys *qdws = virgl_drm_winsys(qws);
>     struct virgl_drm_cmd_buf *cbuf = virgl_drm_cmd_buf(_cbuf);
> @@ -687,12 +695,24 @@ static int virgl_drm_winsys_submit_cmd(struct virgl_winsys *qws,
>     eb.size = cbuf->base.cdw * 4;
>     eb.num_bo_handles = cbuf->cres;
>     eb.bo_handles = (unsigned long)(void *)cbuf->res_hlist;
> +   eb.fence_fd = -1;
> +
> +   if (in_fence_fd != -1) {
> +       eb.flags |= VIRTGPU_EXECBUF_FENCE_FD_IN;
> +       eb.fence_fd = in_fence_fd;
> +   }
> +
> +   if (out_fence_fd != NULL)
> +       eb.flags |= VIRTGPU_EXECBUF_FENCE_FD_OUT;
>
>     ret = drmIoctl(qdws->fd, DRM_IOCTL_VIRTGPU_EXECBUFFER, &eb);
>     if (ret == -1)
>        fprintf(stderr,"got error from kernel - expect bad rendering %d\n", errno);
>     cbuf->base.cdw = 0;
>
> +   if (out_fence_fd != NULL)
> +      *out_fence_fd = eb.fence_fd;
> +

I'm not very familiar with the virgl code, but I think this is after
the cbuf->base.cdw == 0 early return and will only obtain a correct
out fence when there was actually work to be flushed on the context.
As I understand the spec, you always have to return a valid fence fd
after flush, even if no work was submitted otherwise.

Unfortunately, there is no straightforward way to obtain a dummy
signalled fence fd outside of sw_sync. Freedreno has a no-op submit
function for this:

https://cgit.freedesktop.org/mesa/mesa/commit/?id=534917495dca07bb63dbec49450c706fce36f176

Regards,
Stefan


More information about the mesa-dev mailing list