From 551e92d8a6b8dc2d1eb27539d7a6e4cdd57de822 Mon Sep 17 00:00:00 2001 From: Ryan Neph Date: Thu, 27 Apr 2023 12:02:19 -0700 Subject: [PATCH] virgl: check a debug option again at context creation Android apps commonly use HWUI (a GLES-based UI framework provided by the system), that generally performs eglInitialize() before the app can do the same for its custom rendering needs. If an app is going to set VIRGL_DEBUG to enable case-by-case driver behaviors (e.g. experimental shader_sync option), it should be checked again during context creation. Signed-off-by: Ryan Neph Part-of: --- src/gallium/drivers/virgl/virgl_context.c | 14 +++++++++++++ src/gallium/drivers/virgl/virgl_screen.c | 24 +++++++++++------------ src/gallium/drivers/virgl/virgl_screen.h | 1 + 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c index ba831ca3fb7..8d6f4a77409 100644 --- a/src/gallium/drivers/virgl/virgl_context.c +++ b/src/gallium/drivers/virgl/virgl_context.c @@ -1786,6 +1786,20 @@ struct pipe_context *virgl_context_create(struct pipe_screen *pscreen, if (rs->caps.caps.v2.capability_bits & VIRGL_CAP_APP_TWEAK_SUPPORT) virgl_send_tweaks(vctx, rs); + /* On Android, a virgl_screen is generally created first by the HWUI + * service, followed by the application's no-op attempt to do the same with + * eglInitialize(). To retain the ability for apps to set their own driver + * config procedurally right before context creation, we must check the + * envvar again. + */ +#if DETECT_OS_ANDROID + if (!rs->shader_sync) { + uint64_t debug_options = debug_get_flags_option("VIRGL_DEBUG", + virgl_debug_options, 0); + rs->shader_sync |= !!(debug_options & VIRGL_DEBUG_SHADER_SYNC); + } +#endif + return &vctx->base; fail: virgl_context_destroy(&vctx->base); diff --git a/src/gallium/drivers/virgl/virgl_screen.c b/src/gallium/drivers/virgl/virgl_screen.c index 6acaa38e7c2..679b6dfe6d5 100644 --- a/src/gallium/drivers/virgl/virgl_screen.c +++ b/src/gallium/drivers/virgl/virgl_screen.c @@ -44,18 +44,18 @@ #include "virgl_encode.h" int virgl_debug = 0; -static const struct debug_named_value virgl_debug_options[] = { - { "verbose", VIRGL_DEBUG_VERBOSE, NULL }, - { "tgsi", VIRGL_DEBUG_TGSI, NULL }, - { "use_tgsi", VIRGL_DEBUG_USE_TGSI, NULL }, - { "noemubgra", VIRGL_DEBUG_NO_EMULATE_BGRA, "Disable tweak to emulate BGRA as RGBA on GLES hosts"}, - { "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"}, - { "video", VIRGL_DEBUG_VIDEO, "Video codec"}, - { "shader_sync", VIRGL_DEBUG_SHADER_SYNC, "Sync after every shader link"}, +const struct debug_named_value virgl_debug_options[] = { + { "verbose", VIRGL_DEBUG_VERBOSE, NULL }, + { "tgsi", VIRGL_DEBUG_TGSI, NULL }, + { "use_tgsi", VIRGL_DEBUG_USE_TGSI, NULL }, + { "noemubgra", VIRGL_DEBUG_NO_EMULATE_BGRA, "Disable tweak to emulate BGRA as RGBA on GLES hosts" }, + { "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" }, + { "video", VIRGL_DEBUG_VIDEO, "Video codec" }, + { "shader_sync", VIRGL_DEBUG_SHADER_SYNC, "Sync after every shader link" }, DEBUG_NAMED_VALUE_END }; DEBUG_GET_ONCE_FLAGS_OPTION(virgl_debug, "VIRGL_DEBUG", virgl_debug_options, 0) diff --git a/src/gallium/drivers/virgl/virgl_screen.h b/src/gallium/drivers/virgl/virgl_screen.h index 7b32e3d8294..491d7202eb5 100644 --- a/src/gallium/drivers/virgl/virgl_screen.h +++ b/src/gallium/drivers/virgl/virgl_screen.h @@ -44,6 +44,7 @@ enum virgl_debug_flags { VIRGL_DEBUG_SHADER_SYNC = 1 << 10, }; +extern const struct debug_named_value virgl_debug_options[]; extern int virgl_debug; struct virgl_screen {