From 7e7a4e72a1fc3cd97377cc19e372948b39928c51 Mon Sep 17 00:00:00 2001 From: Rohan Garg Date: Fri, 12 Feb 2021 12:39:52 +0100 Subject: [PATCH] vrend: Introudce VIRGL_CAP_V2_VIDEO_MEMORY to query video memory This will allow for the virgl userspace driver to be able to respond to PIPE_CAP_VIDEO_MEMORY requests. Signed-off-by: Rohan Garg Reviewed-by: Gert Wollny --- src/virgl_hw.h | 2 ++ src/vrend_renderer.c | 11 +++++++++++ src/vrend_winsys.c | 9 +++++++++ src/vrend_winsys.h | 2 ++ src/vrend_winsys_glx.c | 12 ++++++++++++ src/vrend_winsys_glx.h | 1 + 6 files changed, 37 insertions(+) diff --git a/src/virgl_hw.h b/src/virgl_hw.h index 70bef95..7967d46 100644 --- a/src/virgl_hw.h +++ b/src/virgl_hw.h @@ -408,6 +408,7 @@ enum virgl_formats { /* These are used by the capability_bits_v2 field in virgl_caps_v2. */ #define VIRGL_CAP_V2_BLEND_EQUATION (1 << 0) #define VIRGL_CAP_V2_UNTYPED_RESOURCE (1 << 1) +#define VIRGL_CAP_V2_VIDEO_MEMORY (1 << 2) /* virgl bind flags - these are compatible with mesa 10.5 gallium. * but are fixed, no other should be passed to virgl either. @@ -559,6 +560,7 @@ struct virgl_caps_v2 { uint32_t host_feature_check_version; struct virgl_supported_format_mask supported_readback_formats; struct virgl_supported_format_mask scanout; + uint32_t max_video_memory; uint32_t capability_bits_v2; }; diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 6213ec8..91e69f5 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -58,6 +58,10 @@ #include "tgsi/tgsi_text.h" +#ifdef HAVE_EPOXY_GLX_H +#include +#endif + /* * VIRGL_RENDERER_CAPSET_VIRGL has version 0 and 1, but they are both * virgl_caps_v1 and are exactly the same. @@ -9984,6 +9988,7 @@ static void vrend_renderer_fill_caps_v2(int gl_ver, int gles_ver, union virgl_c { GLint max; GLfloat range[2]; + uint32_t video_memory; /* Count this up when you add a feature flag that is used to set a CAP in * the guest that was set unconditionally before. Then check that flag and @@ -10289,6 +10294,12 @@ static void vrend_renderer_fill_caps_v2(int gl_ver, int gles_ver, union virgl_c if (egl) caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_UNTYPED_RESOURCE; #endif + + video_memory = vrend_winsys_query_video_memory(); + if (video_memory) { + caps->v2.capability_bits_v2 |= VIRGL_CAP_V2_VIDEO_MEMORY; + caps->v2.max_video_memory = video_memory; + } } void vrend_renderer_fill_caps(uint32_t set, uint32_t version, diff --git a/src/vrend_winsys.c b/src/vrend_winsys.c index 4e4bbc1..43f2e4e 100644 --- a/src/vrend_winsys.c +++ b/src/vrend_winsys.c @@ -198,3 +198,12 @@ int vrend_winsys_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, int return -1; #endif } + +uint32_t vrend_winsys_query_video_memory(void) +{ +#ifdef HAVE_EPOXY_GLX_H + return virgl_glx_query_video_memory(glx_info); +#else + return 0; +#endif +} \ No newline at end of file diff --git a/src/vrend_winsys.h b/src/vrend_winsys.h index 6c9289f..5be90ea 100644 --- a/src/vrend_winsys.h +++ b/src/vrend_winsys.h @@ -58,4 +58,6 @@ int vrend_winsys_get_fourcc_for_texture(uint32_t tex_id, uint32_t format, int *f int vrend_winsys_get_fd_for_texture(uint32_t tex_id, int *fd); int vrend_winsys_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, int *offset); +uint32_t vrend_winsys_query_video_memory(void); + #endif /* VREND_WINSYS_H */ diff --git a/src/vrend_winsys_glx.c b/src/vrend_winsys_glx.c index 23bb983..5b907ad 100644 --- a/src/vrend_winsys_glx.c +++ b/src/vrend_winsys_glx.c @@ -102,3 +102,15 @@ int virgl_glx_make_context_current(struct virgl_glx *d, virgl_renderer_gl_contex { return glXMakeContextCurrent(d->display, d->pbuffer, d->pbuffer, virglctx); } + +uint32_t virgl_glx_query_video_memory(struct virgl_glx *d) +{ + uint32_t video_memory = 0; + if (d) { + if (epoxy_has_glx_extension(d->display, DefaultScreen(d->display), "GLX_MESA_query_renderer")) { + glXQueryCurrentRendererIntegerMESA(GLX_RENDERER_VIDEO_MEMORY_MESA, &video_memory); + } + } + + return video_memory; +} \ No newline at end of file diff --git a/src/vrend_winsys_glx.h b/src/vrend_winsys_glx.h index e5cecba..e8f7697 100644 --- a/src/vrend_winsys_glx.h +++ b/src/vrend_winsys_glx.h @@ -33,5 +33,6 @@ void virgl_glx_destroy(struct virgl_glx *ve); virgl_renderer_gl_context virgl_glx_create_context(struct virgl_glx *ve, struct virgl_gl_ctx_param *vparams); void virgl_glx_destroy_context(struct virgl_glx *ve, virgl_renderer_gl_context virglctx); int virgl_glx_make_context_current(struct virgl_glx *ve, virgl_renderer_gl_context virglctx); +uint32_t virgl_glx_query_video_memory(struct virgl_glx *ve); #endif