[virglrenderer-devel] [PATCH] virgl: handle getting new capsets.

Stéphane Marchesin marcheu at chromium.org
Fri Feb 16 00:47:14 UTC 2018


On Thu, Feb 15, 2018 at 4:42 PM, Dave Airlie <airlied at gmail.com> wrote:

> From: Dave Airlie <airlied at redhat.com>
>
> This checks the kernel api is new enough and asks for the
> larger caps size since the kernel won't mess it up now.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 77
> +++++++++++++++----------
>  src/gallium/winsys/virgl/drm/virgl_drm_winsys.h |  1 +
>  src/gallium/winsys/virgl/drm/virtgpu_drm.h      |  2 +-
>  3 files changed, 50 insertions(+), 30 deletions(-)
>
> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> index fd6ae98a515..94098fc5e98 100644
> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
> @@ -699,52 +699,59 @@ static int virgl_drm_winsys_submit_cmd(struct
> virgl_winsys *qws,
>     return ret;
>  }
>
> +/* this defaults all newer caps,
> + * the kernel will overwrite these if newer version is available.
>

FWIW, here is the set of caps I see which are smaller than the existing
ones:


> + */
> +static void fill_new_caps_defaults(struct virgl_drm_caps *caps)
> +{
> +   caps->caps.v2.min_aliased_point_size = 0.f;
>

1.


> +   caps->caps.v2.max_aliased_point_size = 255.f;
>


> +   caps->caps.v2.min_smooth_point_size = 0.f;
>

1.


> +   caps->caps.v2.max_smooth_point_size = 255.f;
>

190.



> +   caps->caps.v2.min_aliased_line_width = 0.f;
>
1.

+   caps->caps.v2.max_aliased_line_width = 255.f;
>
10.


> +   caps->caps.v2.min_smooth_line_width = 0.f;
>
1.


> +   caps->caps.v2.max_smooth_line_width = 255.f;
>

10.


> +   caps->caps.v2.max_texture_lod_bias = 16.0f;
>

15.



> +   caps->caps.v2.max_geom_output_vertices = 256;
> +   caps->caps.v2.max_geom_total_output_components = 16384;
>
1024


> +   caps->caps.v2.max_vertex_outputs = 32;
> +   caps->caps.v2.max_vertex_attribs = 16;
> +   caps->caps.v2.max_shader_patch_varyings = 0;
> +   caps->caps.v2.min_texel_offset = -8;
> +   caps->caps.v2.max_texel_offset = 7;
> +   caps->caps.v2.min_texture_gather_offset = -8;
> +   caps->caps.v2.max_texture_gather_offset = 7;
> +}
> +
>  static int virgl_drm_get_caps(struct virgl_winsys *vws,
>                                struct virgl_drm_caps *caps)
>  {
>     struct virgl_drm_winsys *vdws = virgl_drm_winsys(vws);
>     struct drm_virtgpu_get_caps args;
>     int ret;
> -   bool fill_v2 = false;
>
> -   memset(&args, 0, sizeof(args));
> +   fill_new_caps_defaults(caps);
>
> -   args.cap_set_id = 1;
> +   memset(&args, 0, sizeof(args));
> +   if (vdws->has_capset_query_fix) {
> +      /* if we have the query fix - try and get cap set id 2 first */
> +      args.cap_set_id = 2;
> +      args.size = sizeof(union virgl_caps);
> +   } else {
> +      args.cap_set_id = 1;
> +      args.size = sizeof(struct virgl_caps_v1);
> +   }
>     args.addr = (unsigned long)&caps->caps;
> -   args.size = sizeof(union virgl_caps);
>
>     ret = drmIoctl(vdws->fd, DRM_IOCTL_VIRTGPU_GET_CAPS, &args);
> -
>     if (ret == -1 && errno == EINVAL) {
>        /* Fallback to v1 */
> +      args.cap_set_id = 1;
>        args.size = sizeof(struct virgl_caps_v1);
>        ret = drmIoctl(vdws->fd, DRM_IOCTL_VIRTGPU_GET_CAPS, &args);
>        if (ret == -1)
>            return ret;
> -      fill_v2 = true;
> -   }
> -   if (caps->caps.max_version == 1)
> -       fill_v2 = true;
> -
> -   if (fill_v2) {
> -      caps->caps.v2.min_aliased_point_size = 0.f;
> -      caps->caps.v2.max_aliased_point_size = 255.f;
> -      caps->caps.v2.min_smooth_point_size = 0.f;
> -      caps->caps.v2.max_smooth_point_size = 255.f;
> -      caps->caps.v2.min_aliased_line_width = 0.f;
> -      caps->caps.v2.max_aliased_line_width = 255.f;
> -      caps->caps.v2.min_smooth_line_width = 0.f;
> -      caps->caps.v2.max_smooth_line_width = 255.f;
> -      caps->caps.v2.max_texture_lod_bias = 16.0f;
> -      caps->caps.v2.max_geom_output_vertices = 256;
> -      caps->caps.v2.max_geom_total_output_components = 16384;
> -      caps->caps.v2.max_vertex_outputs = 32;
> -      caps->caps.v2.max_vertex_attribs = 16;
> -      caps->caps.v2.max_shader_patch_varyings = 0;
> -      caps->caps.v2.min_texel_offset = -8;
> -      caps->caps.v2.max_texel_offset = 7;
> -      caps->caps.v2.min_texture_gather_offset = -8;
> -      caps->caps.v2.max_texture_gather_offset = 7;
>     }
>     return ret;
>  }
> @@ -813,6 +820,8 @@ static struct virgl_winsys *
>  virgl_drm_winsys_create(int drmFD)
>  {
>     struct virgl_drm_winsys *qdws;
> +   int ret;
> +   struct drm_virtgpu_getparam getparam = {0};
>
>     qdws = CALLOC_STRUCT(virgl_drm_winsys);
>     if (!qdws)
> @@ -847,6 +856,16 @@ virgl_drm_winsys_create(int drmFD)
>     qdws->base.fence_reference = virgl_fence_reference;
>
>     qdws->base.get_caps = virgl_drm_get_caps;
> +
> +   uint32_t value;
> +   getparam.param = VIRTGPU_PARAM_CAPSET_QUERY_FIX;
> +   getparam.value = (uint64_t)(uintptr_t)&value;
> +   ret = drmIoctl(qdws->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &getparam);
> +   if (ret == 0) {
> +      if (value == 1)
> +         qdws->has_capset_query_fix = true;
> +   }
> +
>     return &qdws->base;
>
>  }
> diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
> b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
> index f6772153a42..b28e7127ca0 100644
> --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
> +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.h
> @@ -64,6 +64,7 @@ struct virgl_drm_winsys
>     struct util_hash_table *bo_handles;
>     struct util_hash_table *bo_names;
>     mtx_t bo_handles_mutex;
> +   bool has_capset_query_fix;
>  };
>
>  struct virgl_drm_cmd_buf {
> diff --git a/src/gallium/winsys/virgl/drm/virtgpu_drm.h
> b/src/gallium/winsys/virgl/drm/virtgpu_drm.h
> index 30bc3afdd81..f4b885a300c 100644
> --- a/src/gallium/winsys/virgl/drm/virtgpu_drm.h
> +++ b/src/gallium/winsys/virgl/drm/virtgpu_drm.h
> @@ -60,7 +60,7 @@ struct drm_virtgpu_execbuffer {
>  };
>
>  #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */
> -
> +#define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2
>  struct drm_virtgpu_getparam {
>         uint64_t param;
>         uint64_t value;
> --
> 2.14.3
>
> _______________________________________________
> virglrenderer-devel mailing list
> virglrenderer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/virglrenderer-devel/attachments/20180215/89380318/attachment.html>


More information about the virglrenderer-devel mailing list