From 634e2353a0edc0b336191d7267d567d7341b1b51 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 27 Oct 2021 12:12:30 +0200 Subject: [PATCH] virgl: Add driconf tweak to force-enable reading back R8_SRGB textures In the menu of CS:GO R8_SRGB textures are uploaded and read back, and since R8_SRGB can't be read back on GLES, because it is not a rendertarget format and glGetTexImage and siblings don't exists, we can't default to enabling reading back this format. This leads to an emulation of the glGetTexImage calls issued by CS:GO, and this slows down the menus a lot (below 1 fps on Intel XE hosts). So add this driconf tweak and enable it for CS:GO to work around the issue. It can be done safely, because in this case we actually can use the data that is stored on the host in the backing IOV. This tweak lets the CS:GO menu run at around 60 FPS when run with virgl on a Intel XE host when it would run with less than 1 FPS without the tweak. Signed-off-by: Gert Wollny Reviewed-by: John Bates Part-of: --- src/gallium/drivers/virgl/virgl_driinfo.h.in | 1 + src/gallium/drivers/virgl/virgl_screen.c | 16 ++++++++++++++-- src/gallium/drivers/virgl/virgl_screen.h | 2 ++ src/util/00-mesa-defaults.conf | 6 ++++++ src/util/driconf.h | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_driinfo.h.in b/src/gallium/drivers/virgl/virgl_driinfo.h.in index 7a1fef7eb0d..f57e5880965 100644 --- a/src/gallium/drivers/virgl/virgl_driinfo.h.in +++ b/src/gallium/drivers/virgl/virgl_driinfo.h.in @@ -7,6 +7,7 @@ // 4. Add the code to send the tweak to the host in virgl_send_tweaks // 5. Implement the tweak in virglrenderer DRI_CONF_SECTION_MISCELLANEOUS + DRI_CONF_FORMAT_L8_SRGB_ENABLE_READBACK(false) DRI_CONF_GLES_EMULATE_BGRA(true) DRI_CONF_GLES_APPLY_BGRA_DEST_SWIZZLE(true) DRI_CONF_GLES_SAMPLES_PASSED_VALUE(1024, 1, 400000000) diff --git a/src/gallium/drivers/virgl/virgl_screen.c b/src/gallium/drivers/virgl/virgl_screen.c index a832f98461d..6fe0e175975 100644 --- a/src/gallium/drivers/virgl/virgl_screen.c +++ b/src/gallium/drivers/virgl/virgl_screen.c @@ -51,6 +51,7 @@ static const struct debug_named_value virgl_debug_options[] = { { "nobgraswz", VIRGL_DEBUG_NO_BGRA_DEST_SWIZZLE,"Disable tweak to swizzle emulated BGRA on GLES hosts" }, { "sync", VIRGL_DEBUG_SYNC, "Sync after every flush" }, { "xfer", VIRGL_DEBUG_XFER, "Do not optimize for transfers" }, + { "r8srgb-readback", VIRGL_DEBUG_L8_SRGB_ENABLE_READBACK, "Enable redaback for L8 sRGB textures" }, { "nocoherent", VIRGL_DEBUG_NO_COHERENT, "Disable coherent memory"}, DEBUG_NAMED_VALUE_END }; @@ -542,8 +543,15 @@ virgl_has_readback_format(struct pipe_screen *screen, enum virgl_formats fmt) { struct virgl_screen *vscreen = virgl_screen(screen); - return has_format_bit(&vscreen->caps.caps.v2.supported_readback_formats, - fmt); + if (has_format_bit(&vscreen->caps.caps.v2.supported_readback_formats, + fmt)) + return true; + + if (fmt == VIRGL_FORMAT_L8_SRGB && vscreen->tweak_l8_srgb_readback) { + return true; + } + + return false; } static bool @@ -956,6 +964,7 @@ virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *c const char *VIRGL_GLES_EMULATE_BGRA = "gles_emulate_bgra"; const char *VIRGL_GLES_APPLY_BGRA_DEST_SWIZZLE = "gles_apply_bgra_dest_swizzle"; const char *VIRGL_GLES_SAMPLES_PASSED_VALUE = "gles_samples_passed_value"; + const char *VIRGL_FORMAT_L8_SRGB_ENABLE_READBACK = "format_l8_srgb_enable_readback"; if (!screen) return NULL; @@ -972,10 +981,13 @@ virgl_create_screen(struct virgl_winsys *vws, const struct pipe_screen_config *c driQueryOptionb(config->options, VIRGL_GLES_APPLY_BGRA_DEST_SWIZZLE); screen->tweak_gles_tf3_value = driQueryOptioni(config->options, VIRGL_GLES_SAMPLES_PASSED_VALUE); + screen->tweak_l8_srgb_readback = + driQueryOptionb(config->options, VIRGL_FORMAT_L8_SRGB_ENABLE_READBACK); } screen->tweak_gles_emulate_bgra &= !(virgl_debug & VIRGL_DEBUG_NO_EMULATE_BGRA); screen->tweak_gles_apply_bgra_dest_swizzle &= !(virgl_debug & VIRGL_DEBUG_NO_BGRA_DEST_SWIZZLE); screen->no_coherent = virgl_debug & VIRGL_DEBUG_NO_COHERENT; + screen->tweak_l8_srgb_readback |= !!(virgl_debug & VIRGL_DEBUG_L8_SRGB_ENABLE_READBACK); screen->vws = vws; screen->base.get_name = virgl_get_name; diff --git a/src/gallium/drivers/virgl/virgl_screen.h b/src/gallium/drivers/virgl/virgl_screen.h index c44509f3ffb..3881669450b 100644 --- a/src/gallium/drivers/virgl/virgl_screen.h +++ b/src/gallium/drivers/virgl/virgl_screen.h @@ -37,6 +37,7 @@ enum virgl_debug_flags { VIRGL_DEBUG_XFER = 1 << 5, VIRGL_DEBUG_NO_COHERENT = 1 << 6, VIRGL_DEBUG_NIR = 1 << 7, + VIRGL_DEBUG_L8_SRGB_ENABLE_READBACK = 1 << 8, }; extern int virgl_debug; @@ -58,6 +59,7 @@ struct virgl_screen { uint32_t sub_ctx_id; bool tweak_gles_emulate_bgra; bool tweak_gles_apply_bgra_dest_swizzle; + bool tweak_l8_srgb_readback; bool no_coherent; int32_t tweak_gles_tf3_value; diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index b7084b5c1b2..2c8350c76ee 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -893,6 +893,12 @@ TODO: document the other workarounds.