<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 15, 2018 at 4:42 PM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
This checks the kernel api is new enough and asks for the<br>
larger caps size since the kernel won't mess it up now.<br>
<br>
Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
---<br>
 src/gallium/winsys/virgl/drm/<wbr>virgl_drm_winsys.c | 77 +++++++++++++++----------<br>
 src/gallium/winsys/virgl/drm/<wbr>virgl_drm_winsys.h |  1 +<br>
 src/gallium/winsys/virgl/drm/<wbr>virtgpu_drm.h      |  2 +-<br>
 3 files changed, 50 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.c<br>
index fd6ae98a515..94098fc5e98 100644<br>
--- a/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.c<br>
+++ b/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.c<br>
@@ -699,52 +699,59 @@ static int virgl_drm_winsys_submit_cmd(<wbr>struct virgl_winsys *qws,<br>
    return ret;<br>
 }<br>
<br>
+/* this defaults all newer caps,<br>
+ * the kernel will overwrite these if newer version is available.<br></blockquote><div><br></div><div>FWIW, here is the set of caps I see which are smaller than the existing ones:</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ */<br>
+static void fill_new_caps_defaults(struct virgl_drm_caps *caps)<br>
+{<br>
+   caps->caps.v2.min_aliased_<wbr>point_size = 0.f;<br></blockquote><div><br></div><div>1.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_aliased_<wbr>point_size = 255.f;<br></blockquote><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.min_smooth_<wbr>point_size = 0.f;<br></blockquote><div><br></div><div>1.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_smooth_<wbr>point_size = 255.f;<br></blockquote><div><br></div><div>190.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.min_aliased_<wbr>line_width = 0.f;<br></blockquote><div>1. </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_aliased_<wbr>line_width = 255.f;<br></blockquote><div>10.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.min_smooth_line_<wbr>width = 0.f;<br></blockquote><div>1.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_smooth_line_<wbr>width = 255.f;<br></blockquote><div><br></div><div>10.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_texture_lod_<wbr>bias = 16.0f;<br></blockquote><div><br></div><div>15.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_geom_output_<wbr>vertices = 256;<br>
+   caps->caps.v2.max_geom_total_<wbr>output_components = 16384;<br></blockquote><div>1024</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+   caps->caps.v2.max_vertex_<wbr>outputs = 32;<br>
+   caps->caps.v2.max_vertex_<wbr>attribs = 16;<br>
+   caps->caps.v2.max_shader_<wbr>patch_varyings = 0;<br>
+   caps->caps.v2.min_texel_offset = -8;<br>
+   caps->caps.v2.max_texel_offset = 7;<br>
+   caps->caps.v2.min_texture_<wbr>gather_offset = -8;<br>
+   caps->caps.v2.max_texture_<wbr>gather_offset = 7;<br>
+}<br>
+<br>
 static int virgl_drm_get_caps(struct virgl_winsys *vws,<br>
                               struct virgl_drm_caps *caps)<br>
 {<br>
    struct virgl_drm_winsys *vdws = virgl_drm_winsys(vws);<br>
    struct drm_virtgpu_get_caps args;<br>
    int ret;<br>
-   bool fill_v2 = false;<br>
<br>
-   memset(&args, 0, sizeof(args));<br>
+   fill_new_caps_defaults(caps);<br>
<br>
-   args.cap_set_id = 1;<br>
+   memset(&args, 0, sizeof(args));<br>
+   if (vdws->has_capset_query_fix) {<br>
+      /* if we have the query fix - try and get cap set id 2 first */<br>
+      args.cap_set_id = 2;<br>
+      args.size = sizeof(union virgl_caps);<br>
+   } else {<br>
+      args.cap_set_id = 1;<br>
+      args.size = sizeof(struct virgl_caps_v1);<br>
+   }<br>
    args.addr = (unsigned long)&caps->caps;<br>
-   args.size = sizeof(union virgl_caps);<br>
<br>
    ret = drmIoctl(vdws->fd, DRM_IOCTL_VIRTGPU_GET_CAPS, &args);<br>
-<br>
    if (ret == -1 && errno == EINVAL) {<br>
       /* Fallback to v1 */<br>
+      args.cap_set_id = 1;<br>
       args.size = sizeof(struct virgl_caps_v1);<br>
       ret = drmIoctl(vdws->fd, DRM_IOCTL_VIRTGPU_GET_CAPS, &args);<br>
       if (ret == -1)<br>
           return ret;<br>
-      fill_v2 = true;<br>
-   }<br>
-   if (caps->caps.max_version == 1)<br>
-       fill_v2 = true;<br>
-<br>
-   if (fill_v2) {<br>
-      caps->caps.v2.min_aliased_<wbr>point_size = 0.f;<br>
-      caps->caps.v2.max_aliased_<wbr>point_size = 255.f;<br>
-      caps->caps.v2.min_smooth_<wbr>point_size = 0.f;<br>
-      caps->caps.v2.max_smooth_<wbr>point_size = 255.f;<br>
-      caps->caps.v2.min_aliased_<wbr>line_width = 0.f;<br>
-      caps->caps.v2.max_aliased_<wbr>line_width = 255.f;<br>
-      caps->caps.v2.min_smooth_line_<wbr>width = 0.f;<br>
-      caps->caps.v2.max_smooth_line_<wbr>width = 255.f;<br>
-      caps->caps.v2.max_texture_lod_<wbr>bias = 16.0f;<br>
-      caps->caps.v2.max_geom_output_<wbr>vertices = 256;<br>
-      caps->caps.v2.max_geom_total_<wbr>output_components = 16384;<br>
-      caps->caps.v2.max_vertex_<wbr>outputs = 32;<br>
-      caps->caps.v2.max_vertex_<wbr>attribs = 16;<br>
-      caps->caps.v2.max_shader_<wbr>patch_varyings = 0;<br>
-      caps->caps.v2.min_texel_offset = -8;<br>
-      caps->caps.v2.max_texel_offset = 7;<br>
-      caps->caps.v2.min_texture_<wbr>gather_offset = -8;<br>
-      caps->caps.v2.max_texture_<wbr>gather_offset = 7;<br>
    }<br>
    return ret;<br>
 }<br>
@@ -813,6 +820,8 @@ static struct virgl_winsys *<br>
 virgl_drm_winsys_create(int drmFD)<br>
 {<br>
    struct virgl_drm_winsys *qdws;<br>
+   int ret;<br>
+   struct drm_virtgpu_getparam getparam = {0};<br>
<br>
    qdws = CALLOC_STRUCT(virgl_drm_<wbr>winsys);<br>
    if (!qdws)<br>
@@ -847,6 +856,16 @@ virgl_drm_winsys_create(int drmFD)<br>
    qdws->base.fence_reference = virgl_fence_reference;<br>
<br>
    qdws->base.get_caps = virgl_drm_get_caps;<br>
+<br>
+   uint32_t value;<br>
+   getparam.param = VIRTGPU_PARAM_CAPSET_QUERY_<wbr>FIX;<br>
+   getparam.value = (uint64_t)(uintptr_t)&value;<br>
+   ret = drmIoctl(qdws->fd, DRM_IOCTL_VIRTGPU_GETPARAM, &getparam);<br>
+   if (ret == 0) {<br>
+      if (value == 1)<br>
+         qdws->has_capset_query_fix = true;<br>
+   }<br>
+<br>
    return &qdws->base;<br>
<br>
 }<br>
diff --git a/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.h b/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.h<br>
index f6772153a42..b28e7127ca0 100644<br>
--- a/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.h<br>
+++ b/src/gallium/winsys/virgl/<wbr>drm/virgl_drm_winsys.h<br>
@@ -64,6 +64,7 @@ struct virgl_drm_winsys<br>
    struct util_hash_table *bo_handles;<br>
    struct util_hash_table *bo_names;<br>
    mtx_t bo_handles_mutex;<br>
+   bool has_capset_query_fix;<br>
 };<br>
<br>
 struct virgl_drm_cmd_buf {<br>
diff --git a/src/gallium/winsys/virgl/<wbr>drm/virtgpu_drm.h b/src/gallium/winsys/virgl/<wbr>drm/virtgpu_drm.h<br>
index 30bc3afdd81..f4b885a300c 100644<br>
--- a/src/gallium/winsys/virgl/<wbr>drm/virtgpu_drm.h<br>
+++ b/src/gallium/winsys/virgl/<wbr>drm/virtgpu_drm.h<br>
@@ -60,7 +60,7 @@ struct drm_virtgpu_execbuffer {<br>
 };<br>
<br>
 #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */<br>
-<br>
+#define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2<br>
 struct drm_virtgpu_getparam {<br>
        uint64_t param;<br>
        uint64_t value;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.14.3<br>
<br>
______________________________<wbr>_________________<br>
virglrenderer-devel mailing list<br>
<a href="mailto:virglrenderer-devel@lists.freedesktop.org">virglrenderer-devel@lists.<wbr>freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/virglrenderer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/<wbr>virglrenderer-devel</a><br>
</font></span></blockquote></div><br></div></div>