virgl: handle getting new capsets.

This checks the kernel api is new enough and asks for the
larger caps size since the kernel won't mess it up now.

Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Dave Airlie 2018-02-15 14:20:37 +10:00
parent 70190a6567
commit cd32258ec1
6 changed files with 52 additions and 31 deletions

View File

@ -109,5 +109,28 @@ struct virgl_winsys {
struct pipe_box *sub_box);
};
/* this defaults all newer caps,
* the kernel will overwrite these if newer version is available.
*/
static inline void virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps *caps)
{
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;
}
#endif

View File

@ -705,46 +705,28 @@ static int virgl_drm_get_caps(struct virgl_winsys *vws,
struct virgl_drm_winsys *vdws = virgl_drm_winsys(vws);
struct drm_virtgpu_get_caps args;
int ret;
bool fill_v2 = false;
virgl_ws_fill_new_caps_defaults(caps);
memset(&args, 0, sizeof(args));
args.cap_set_id = 1;
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 +795,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 +831,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;
}

View File

@ -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 {

View File

@ -60,6 +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;

View File

@ -142,7 +142,7 @@ int virgl_vtest_send_get_caps(struct virgl_vtest_winsys *vws,
if (ret <= 0)
return 0;
ret = virgl_block_read(vws->sock_fd, &caps->caps, sizeof(union virgl_caps));
ret = virgl_block_read(vws->sock_fd, &caps->caps, sizeof(struct virgl_caps_v1));
return 0;
}

View File

@ -519,6 +519,8 @@ static int virgl_vtest_get_caps(struct virgl_winsys *vws,
struct virgl_drm_caps *caps)
{
struct virgl_vtest_winsys *vtws = virgl_vtest_winsys(vws);
virgl_ws_fill_new_caps_defaults(caps);
return virgl_vtest_send_get_caps(vtws, caps);
}