From 5f3112fb4b8e33bd3db234da5f8d1915ede6b52e Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Sat, 3 Oct 2026 14:22:02 -0400 Subject: [PATCH] Add software Steam rendering and optional Gamescope present timing --- app/src/main/cpp/waylandcomp/src/compositor.c | 3 +- app/src/main/cpp/waylandcomp/src/vk_loader.h | 2 +- app/src/main/cpp/waylandcomp/src/vk_present.c | 37 ++++-- app/src/main/cpp/waylandcomp/src/vk_present.h | 2 + .../droiddeck/launcher/gpu/TurnipDriver.java | 4 + .../patches/0114-optional-present-wait.patch | 119 ++++++++++++++++++ .../overlay/usr/local/bin/bannerlator-session | 14 ++- .../usr/local/bin/bannerlator-steam-launch | 4 +- 8 files changed, 166 insertions(+), 19 deletions(-) create mode 100644 tools/gamescope/patches/0114-optional-present-wait.patch diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 75a16311ea..0249091624 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -3478,7 +3478,8 @@ int banner_wayland_run(void) { /* libdecor binds wl_output at 4; a lower version is a protocol error for the client. */ wl_global_create(display, &wl_output_interface, 4, NULL, bind_output); wl_global_create(display, &xdg_wm_base_interface, 1, NULL, bind_xdg_wm_base); - wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf); + if (vkp_dmabuf_supported()) + wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 4, NULL, bind_dmabuf); /* gamescope's Wayland backend refuses a seat older than 8. */ wl_global_create(display, &wl_seat_interface, 9, NULL, bind_seat); wl_global_create(display, &banner_desktop_v1_interface, 1, NULL, bind_desktop); diff --git a/app/src/main/cpp/waylandcomp/src/vk_loader.h b/app/src/main/cpp/waylandcomp/src/vk_loader.h index 32a15ae874..3d47bd4cec 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_loader.h +++ b/app/src/main/cpp/waylandcomp/src/vk_loader.h @@ -9,7 +9,7 @@ #define VK_USE_PLATFORM_ANDROID_KHR #include -#define VK_GLOBAL_FUNCS(X) X(CreateInstance) X(EnumerateInstanceExtensionProperties) +#define VK_GLOBAL_FUNCS(X) X(CreateInstance) X(EnumerateInstanceExtensionProperties) X(EnumerateInstanceVersion) #define VK_INSTANCE_FUNCS(X) \ X(EnumeratePhysicalDevices) X(GetPhysicalDeviceProperties) \ diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.c b/app/src/main/cpp/waylandcomp/src/vk_present.c index 7a2ecfd48b..242d7b1677 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.c +++ b/app/src/main/cpp/waylandcomp/src/vk_present.c @@ -40,6 +40,7 @@ struct vkp_image { static ANativeWindow *g_window; /* the window frames go to; compositor thread only */ static char *g_driver_path, *g_library_name, *g_native_lib_dir; static int g_dev_state; /* 0 = not yet, 1 = ok, -1 = failed, -2 = lost (VK_ERROR_DEVICE_LOST) */ +static int g_dmabuf_import; static VkInstance g_inst; static VkPhysicalDevice g_pd; static VkDevice g_dev; @@ -411,11 +412,13 @@ static int dev_init(void) { "generation %s)", g_colorspace_ext ? "enables" : "has no", g_colorspace_ext ? "is possible where the screen surface offers one" : "is not possible: tone-mapped instead"); } - /* 1.3 like the X11 renderer's instance: the frame-generation probe (framegen_engine.cpp) - * queries VkPhysicalDeviceVulkan12Features, and a 1.1 instance may be answered as 1.1. */ + /* Prefer 1.3 for the frame-generation feature probe, but respect older system loaders. */ + uint32_t loader_api = VK_API_VERSION_1_0; + if (g_vk.EnumerateInstanceVersion) + g_vk.EnumerateInstanceVersion(&loader_api); VkApplicationInfo app = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pApplicationName = "banner-wayland-present", - .apiVersion = VK_API_VERSION_1_3}; + .apiVersion = loader_api < VK_API_VERSION_1_3 ? loader_api : VK_API_VERSION_1_3}; VkInstanceCreateInfo ici = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app, .enabledExtensionCount = n_inst_exts, @@ -450,18 +453,25 @@ static int dev_init(void) { } g_vk.GetPhysicalDeviceMemoryProperties(g_pd, &g_memprops); - /* Verify the dmabuf-import extensions are present, and log any that are missing. */ - const char *dev_exts[7] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, "VK_KHR_external_memory_fd", - "VK_EXT_external_memory_dma_buf", "VK_EXT_image_drm_format_modifier", - "VK_KHR_image_format_list", NULL, NULL}; - uint32_t n_dev_exts = 5; + /* Shared-memory clients need only a swapchain. Advertise dma-buf import only when its + * complete extension set is available, rather than failing device creation on older GPUs. */ + const char *import_exts[] = {"VK_KHR_external_memory_fd", "VK_EXT_external_memory_dma_buf", + "VK_EXT_image_drm_format_modifier", "VK_KHR_image_format_list"}; + const char *dev_exts[7] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; + uint32_t n_dev_exts = 1; uint32_t ne = 0; g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL); VkExtensionProperties *exts = calloc(ne ? ne : 1, sizeof(*exts)); g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, exts); - for (unsigned i = 0; i < 5; i++) - if (!has_ext(exts, ne, dev_exts[i])) - LOGE("present: driver MISSING %s (dmabuf import will fail)", dev_exts[i]); + g_dmabuf_import = 1; + for (unsigned i = 0; i < sizeof(import_exts) / sizeof(import_exts[0]); i++) { + if (has_ext(exts, ne, import_exts[i])) + dev_exts[n_dev_exts++] = import_exts[i]; + else { + g_dmabuf_import = 0; + banner_log("gpu", "driver has no %s; shared-memory clients remain available", import_exts[i]); + } + } /* HDR sessions only: the HDR10 swapchain (frame generation) can carry the game's metadata. */ int want_hdr_md = 0; if (banner_color_requested()) { @@ -538,6 +548,7 @@ static int dev_init(void) { } int vkp_ready(void) { return dev_init(); } +int vkp_dmabuf_supported(void) { return dev_init() == 0 && g_dmabuf_import; } static int swap_init_locked(void); @@ -899,7 +910,7 @@ static int modifier_importable(VkFormat fmt, uint64_t modifier, VkImageUsageFlag } int vkp_dmabuf_modifiers(uint32_t drm_format, uint64_t *out, int max) { - if (max <= 0 || dev_init() != 0 || !g_vk.GetPhysicalDeviceFormatProperties2) return 0; + if (max <= 0 || !vkp_dmabuf_supported() || !g_vk.GetPhysicalDeviceFormatProperties2) return 0; VkFormat fmt = drm_to_vk(drm_format); VkDrmFormatModifierPropertiesListEXT list = { .sType = VK_STRUCTURE_TYPE_DRM_FORMAT_MODIFIER_PROPERTIES_LIST_EXT}; @@ -941,7 +952,7 @@ int vkp_image_is_dmabuf(const struct vkp_image *img) { return img && img->dmabuf struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t modifier, int w, int h, uint32_t stride, uint32_t offset, int as_blit_dst) { if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL; - if (dev_init() != 0) return NULL; + if (!vkp_dmabuf_supported()) return NULL; struct vkp_image *img = calloc(1, sizeof(*img)); if (!img) return NULL; diff --git a/app/src/main/cpp/waylandcomp/src/vk_present.h b/app/src/main/cpp/waylandcomp/src/vk_present.h index eef9c80cca..77d8fd95e2 100644 --- a/app/src/main/cpp/waylandcomp/src/vk_present.h +++ b/app/src/main/cpp/waylandcomp/src/vk_present.h @@ -87,6 +87,8 @@ const char *vkp_gpu_name(void); // 0 if the renderer can create images (device up), -1 otherwise. int vkp_ready(void); +/* Whether the selected driver supports the complete dma-buf import extension set. */ +int vkp_dmabuf_supported(void); /* Whether an output window is attached (or requested); without one vkp_render() draws nothing. */ int vkp_has_window(void); /* 1 once the Vulkan device was lost: nothing is presented any more (the session must restart). */ diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java index 52d8129ff4..c39e0b2c32 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java +++ b/app/src/main/java/com/droiddeck/launcher/gpu/TurnipDriver.java @@ -337,6 +337,10 @@ public final class TurnipDriver { if (forced.startsWith("a8")) return DRIVER_A8XX; if (forced.startsWith("a7")) return DRIVER_A7XX; } + if (!com.droiddeck.launcher.core.DeviceSupport.INSTANCE.adreno()) { + Log.i(TAG, "non-Adreno GPU: using system Vulkan for the compositor"); + return null; + } String model = gpuModel(); Log.i(TAG, "gpu model: " + (model == null ? "unknown" : model)); if (model != null) { diff --git a/tools/gamescope/patches/0114-optional-present-wait.patch b/tools/gamescope/patches/0114-optional-present-wait.patch new file mode 100644 index 0000000000..55839f6779 --- /dev/null +++ b/tools/gamescope/patches/0114-optional-present-wait.patch @@ -0,0 +1,119 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 54e4efc..226f9b7 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -349,6 +349,25 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) + } + + for (auto cphysDev : physDevs) ++ if ( supportsPresentId && supportsPresentWait ) ++ { ++ VkPhysicalDevicePresentWaitFeaturesKHR waitFeatures = { ++ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_FEATURES_KHR, ++ }; ++ VkPhysicalDevicePresentIdFeaturesKHR idFeatures = { ++ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, ++ .pNext = &waitFeatures, ++ }; ++ VkPhysicalDeviceFeatures2 features = { ++ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, ++ .pNext = &idFeatures, ++ }; ++ vk.GetPhysicalDeviceFeatures2( physDev(), &features ); ++ m_bSupportsPresentWait = idFeatures.presentId && waitFeatures.presentWait; ++ } ++ if ( GetBackend()->UsesVulkanSwapchain() && !m_bSupportsPresentWait ) ++ vk_log.infof( "Present ID/wait unavailable; using timer-based pacing." ); ++ + { + VkPhysicalDeviceProperties deviceProperties; + vk.GetPhysicalDeviceProperties(cphysDev, &deviceProperties); +@@ -450,7 +469,13 @@ bool CVulkanDevice::createDevice() + bool hasDrmProps = vulkan_has_drm_props(); + bool supportsForeignQueue = false; + bool supportsHDRMetadata = false; ++ bool supportsPresentId = false; ++ bool supportsPresentWait = false; + for (const auto& ext : m_supportedExts) { ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_ID_EXTENSION_NAME) == 0 ) ++ supportsPresentId = true; ++ if ( strcmp(ext.extensionName, VK_KHR_PRESENT_WAIT_EXTENSION_NAME) == 0 ) ++ supportsPresentWait = true; + if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 ) + m_bSupportsModifiers = true; + +@@ -570,8 +595,11 @@ bool CVulkanDevice::createDevice() + enabledExtensions.push_back( VK_KHR_SWAPCHAIN_EXTENSION_NAME ); + enabledExtensions.push_back( VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME ); + +- enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); +- enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); ++ if ( m_bSupportsPresentWait ) ++ { ++ enabledExtensions.push_back( VK_KHR_PRESENT_ID_EXTENSION_NAME ); ++ enabledExtensions.push_back( VK_KHR_PRESENT_WAIT_EXTENSION_NAME ); ++ } + + if ( supportsHDRMetadata ) + enabledExtensions.push_back( VK_EXT_HDR_METADATA_EXTENSION_NAME ); +@@ -646,7 +674,7 @@ bool CVulkanDevice::createDevice() + + VkPhysicalDeviceFeatures2 features2 = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, +- .pNext = &presentIdFeatures, ++ .pNext = m_bSupportsPresentWait ? static_cast( &presentIdFeatures ) : static_cast( &features13 ), + .features = { + .shaderInt16 = m_bSupportsFp16, + }, +@@ -3086,7 +3114,7 @@ void vulkan_present_to_window( void ) + + VkPresentInfoKHR presentInfo = { + .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, +- .pNext = &presentIdInfo, ++ .pNext = g_device.supportsPresentWait() ? &presentIdInfo : nullptr, + .swapchainCount = 1, + .pSwapchains = &g_output.swapChain, + .pImageIndices = &g_output.nOutImage, +@@ -3094,8 +3122,11 @@ void vulkan_present_to_window( void ) + + if ( g_device.vk.QueuePresentKHR( g_device.queue(), &presentInfo ) == VK_SUCCESS ) + { +- g_currentPresentWaitId = presentId; +- g_currentPresentWaitId.notify_all(); ++ if ( g_device.supportsPresentWait() ) ++ { ++ g_currentPresentWaitId = presentId; ++ g_currentPresentWaitId.notify_all(); ++ } + } + else + vulkan_remake_swapchain(); +@@ -3662,7 +3693,7 @@ bool vulkan_init( VkInstance instance, VkSurfaceKHR surface ) + if (!init_nis_data()) + return false; + +- if ( GetBackend()->UsesVulkanSwapchain() ) ++ if ( GetBackend()->UsesVulkanSwapchain() && g_device.supportsPresentWait() ) + { + std::thread present_wait_thread( present_wait_thread_func ); + present_wait_thread.detach(); +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index fa519db..91f7793 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -862,6 +862,7 @@ public: + inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} + inline int drmRenderFd() {return m_drmRendererFd;} + inline bool supportsModifiers() {return m_bSupportsModifiers;} ++ inline bool supportsPresentWait() {return m_bSupportsPresentWait;} + inline bool hasDrmPrimaryDevId() {return m_bHasDrmPrimaryDevId;} + inline dev_t primaryDevId() {return m_drmPrimaryDevId;} + inline bool supportsFp16() {return m_bSupportsFp16;} +@@ -930,6 +931,7 @@ protected: + uint32_t m_uVendorID = 0; + bool m_bHasDrmPrimaryDevId = false; + bool m_bSupportsModifiers = false; ++ bool m_bSupportsPresentWait = false; + bool m_bInitialized = false; + + diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index 322f14554d..a0ad3a7529 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -639,6 +639,15 @@ BUSCONF # desktop's launchers ask for; gamescope shows one window at a time and the game takes over. _bl_ui=(-gamepadui) [ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=() + # A diagnostic client on a pixman desktop: CEF uses CPU frames through Xwayland. + # This does not give games a Vulkan device or make Gamescope work on this GPU. + _bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan) + if [ "${BL_STEAM_SOFTWARE:-0}" = 1 ]; then + _bl_cef=(-cef-disable-gpu -cef-disable-gpu-compositing) + export LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=llvmpipe + export MESA_LOADER_DRIVER_OVERRIDE=swrast SDL_RENDER_DRIVER=software SDL_VIDEODRIVER=x11 + echo "== steam: software rendering requested" + fi # Deck mode (BL_STEAMDECK=1, the Steam page's Client settings): -steamdeck is the flag that puts # the Quick Access Menu and the Deck settings pages on screen; the QAM's performance overlay # controls stay greyed out without -steamos3, as SteamOS and Armada launch it. -steamos3 makes @@ -698,7 +707,7 @@ BUSCONF done ) & fi - echo "== steam args: ${_bl_ui[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 -cef-use-gl=angle -cef-use-angle=vulkan $*" + echo "== steam args: ${_bl_ui[*]} -clientbeta $steam_channel -no-cef-sandbox -cef-ozone-platform=x11 ${_bl_cef[*]} $*" # An update that cannot install asks for a restart (rc=42) every time; the count is capped so a # session can never again loop in silence, which reads as a menu opening and closing by itself. steam_updates=0 @@ -745,8 +754,7 @@ BUSCONF fi step "starting the Steam client${BL_STEAM_UI:+ ($BL_STEAM_UI UI)}" "$steam_root/steamrtarm64/steam" "${_bl_ui[@]}" -clientbeta "$steam_channel" \ - -no-cef-sandbox -cef-force-gpu -cef-ozone-platform=x11 \ - -cef-use-gl=angle -cef-use-angle=vulkan "$@" + -no-cef-sandbox -cef-ozone-platform=x11 "${_bl_cef[@]}" "$@" rc=$? echo "== steam exited rc=$rc" collect_steam_logs diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch index 92d1c9d22d..4534e6f0a2 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-steam-launch @@ -13,6 +13,7 @@ # On a software desktop (pixman: the GPU renderers failed on this device) there is no dma-buf, so a # game - or the client's own Vulkan window - would die at its first frame. There the request goes # to the app, which ends the desktop and starts a Steam session under gamescope in its place. +# BL_STEAM_SOFTWARE=1 opts into a CPU-rendered client on that desktop for compatibility testing. set -u ui=${1:-desktop} target=${2:-} @@ -28,7 +29,8 @@ esac steam_root=${XDG_DATA_HOME:-${HOME:-/root}/.local/share}/Steam client=$steam_root/steamrtarm64/steam -if [ "${BL_DESKTOP:-}" = 1 ] && [ -n "${WLR_RENDERER:-}" ] && [ "$WLR_RENDERER" != pixman ]; then +if [ "${BL_DESKTOP:-}" = 1 ] && [ -n "${WLR_RENDERER:-}" ] \ + && { [ "$WLR_RENDERER" != pixman ] || [ "${BL_STEAM_SOFTWARE:-0}" = 1 ]; }; then log=${BL_DEBUG_DIR:-$HOME/.cache/droiddeck}/steam-desktop.log mkdir -p "$(dirname "$log")" 2>/dev/null if pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && [ -x "$client" ]; then