From b383604175e0c3466c5dc5c850e96f0b82b559f0 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Tue, 13 Oct 2026 06:35:25 -0400 Subject: [PATCH] Mali: Venus gamescope without robustness2, the bridge switch honoured and kept, clean driver switches - gamescope 0128: VK_EXT_robustness2 is optional. A Mali driver through Venus has none, and gamescope stopped at "Missing required extension: VK_EXT_robustness2" (the wayland_surface error after it was only the knock-on). Without it, unused descriptor slots point at a 1x1 texture instead of VK_NULL_HANDLE. (David Cimo's Pixel 9 driver has robustness2, so his build never needed this.) gamescope component rebuilt and pinned by sha. - Open-files limit: on a GPU that is not an Adreno the session script raises the soft limit to the hard limit for the whole session tree (a PanVK-kbase session froze on "Too many open files" after ten minutes) and graphics-report.txt shows before and after. A stopgap; the driver leak is fixed separately. - The Mali bridge switch is honoured: when on and usable it wins over a PanVK pair for the session (Venus still wins over it). Selecting a pair no longer switches the bridge off, which is why the switch did not survive an app restart (Auto re-selected the pair at start). Setup says when this phone cannot use the bridge at all. - Driver switching: picking a Mali pair by hand keeps the display on the phone's own driver, as Auto does (a PanVK Android display stalls on Mali gralloc at "Waiting for Steam's first frame", and stayed set after switching back); installing a bundle again replaces it instead of adding a "-2" copy beside the old one. - graphics-report.txt names the runtime driver's folder and libraries, and the previous session's drivers, flagged when they changed. --- .../com/droiddeck/launcher/DriverMenus.kt | 9 +- .../droiddeck/launcher/core/DeviceSupport.kt | 8 +- .../droiddeck/launcher/gpu/DriverBundle.kt | 7 ++ .../launcher/session/GraphicsReport.kt | 14 ++- .../launcher/session/SessionService.kt | 4 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 7 +- app/src/main/res/values/strings.xml | 1 + .../patches/0128-robustness2-optional.patch | 96 +++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-session | 10 ++ 9 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 tools/gamescope/patches/0128-robustness2-optional.patch diff --git a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt index 3aa3077c8d..ed9cc6a405 100644 --- a/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt +++ b/app/src/main/java/com/droiddeck/launcher/DriverMenus.kt @@ -292,12 +292,15 @@ internal class DriverMenus(private val activity: Activity, private val ui: Handl // A Mali pair under Auto: the compositor draws on the phone's own Mali driver // (dma-buf, modifiers and AHB all work there) and the guest runs the pair's // PanVK. Its Android half stays installed for a manual pick. - val displayId = if (auto && gpu.family.mali && DriverPairs.isNonAdreno(pair.key)) TurnipDriver.AUTO else pairDisplayId + // The same when the pair is picked by hand: a PanVK Android half on the display + // stalls Mali gralloc ("Waiting for Steam's first frame"); it stays a manual pick + // under "Runtime and display drivers separately". + val displayId = if (gpu.family.mali && DriverPairs.isNonAdreno(pair.key)) TurnipDriver.AUTO else pairDisplayId val displayChanged = SessionPrefs.androidDriver(activity) != displayId SessionPrefs.setAndroidDriver(activity, displayId) SessionPrefs.setLinuxDriver(activity, linuxId) - // An open Mali/Xclipse driver and the Mali bridge are alternatives: the pair wins. - if (DriverPairs.isNonAdreno(pair.key)) SessionPrefs.setVkBridge(activity, false) + // The Mali bridge switch is the user's and is left as it is: when it is on, the + // bridge wins for the session (DeviceSupport.vkBridge) and the pair waits. val restart = displayChanged && CompositorHost.isStarted if (auto) { val previous = SessionPrefs.gpuAutoInstalled(activity) diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt index 967a392ff1..aee88dd337 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceSupport.kt @@ -23,10 +23,12 @@ object DeviceSupport { * Xclipse) already handles. An Adreno keeps Turnip whatever the setting says. */ fun vkBridge(context: Context): Boolean = - !adreno() && !SystemVulkanDriver.isAvailable() && !openDriverActive(context) && - !com.droiddeck.launcher.session.VenusComponent.wanted(context) && + bridgeUsable() && !com.droiddeck.launcher.session.VenusComponent.wanted(context) && com.droiddeck.launcher.session.SessionPrefs.vkBridge(context) + /** Whether this phone can use the Mali bridge at all: a Mali (kbase) without a system-driver route. */ + fun bridgeUsable(): Boolean = !adreno() && !SystemVulkanDriver.isAvailable() && File("/dev/mali0").exists() + /** * Whether an open non-Adreno driver pair (PanVK for Mali, RADV for Xclipse) is the one in use: * it and the bridge are alternatives, and the pair wins. Always false on an Adreno. @@ -34,6 +36,8 @@ object DeviceSupport { fun openDriverActive(context: Context): Boolean { if (adreno()) return false if (com.droiddeck.launcher.session.VenusComponent.wanted(context)) return false + // The Mali bridge switch, when on and usable, wins over a pair (the user's choice in Setup). + if (bridgeUsable() && com.droiddeck.launcher.session.SessionPrefs.vkBridge(context)) return false // The runtime half is what counts: a Mali pair may run with the system driver as its display. val linux = com.droiddeck.launcher.session.SessionPrefs.linuxDriver(context).ifEmpty { return false } return com.droiddeck.launcher.gpu.DriverPairs.isNonAdreno(com.droiddeck.launcher.gpu.DriverBundle.containing(context, linux, true)?.id) diff --git a/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt b/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt index cc269e1700..1bfe8fd2f9 100644 --- a/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt +++ b/app/src/main/java/com/droiddeck/launcher/gpu/DriverBundle.kt @@ -86,6 +86,13 @@ object DriverBundle { val manifest = File(work, MANIFEST).takeIf { it.isFile } ?.let { runCatching { parseManifest(JSONObject(FileUtils.readString(it))) }.getOrNull() } ?: throw IllegalArgumentException(context.getString(R.string.bundle_no_manifest)) + // The same bundle again (a pair picked again after another one): replace it rather + // than keeping a "-2" copy whose drivers sit beside the old ones. + val sameId = LinuxVulkanDriverManager.sanitizeId(manifest.tag.ifEmpty { "${manifest.name}-${manifest.version}" }) + get(context, sameId)?.let { old -> + Log.i(TAG, "replacing bundle ${old.id} (display ${old.androidId}, runtime ${old.linuxId})") + remove(context, old) + } val androidDir = File(work, manifest.androidPath) val linuxDir = File(work, manifest.linuxPath) diff --git a/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt index 5ecdf7edea..5e5b7f9c17 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GraphicsReport.kt @@ -59,7 +59,17 @@ object GraphicsReport { appendLine("display driver (compositor): " + SessionPrefs.androidDriver(context).ifEmpty { if (DeviceSupport.adreno()) "(auto: bundled Turnip)" else "(auto: the phone's own Vulkan driver, ${SystemVulkanDriver.hal() ?: "vendor HAL"})" }) - appendLine("runtime driver: " + SessionPrefs.linuxDriver(context).ifEmpty { "(runtime default)" }) + val linux = SessionPrefs.linuxDriver(context) + appendLine("runtime driver: " + linux.ifEmpty { "(runtime default)" }) + if (linux.isNotEmpty()) { + val dir = com.droiddeck.launcher.gpu.LinuxVulkanDriverManager(context).getDriverDir(linux) + appendLine("runtime driver dir: ${dir.path} (" + (dir.listFiles()?.filter { it.name.endsWith(".so") }?.joinToString { it.name } ?: "missing") + ")") + } + val prefs = context.getSharedPreferences("graphics_report", Context.MODE_PRIVATE) + val previous = prefs.getString("lastDrivers", null) + val now = "display ${SessionPrefs.androidDriver(context).ifEmpty { "(auto)" }}, runtime ${linux.ifEmpty { "(default)" }}, bridge ${DeviceSupport.vkBridge(context)}, venus ${VenusComponent.wanted(context)}" + appendLine("previous session's drivers: " + (previous ?: "(none recorded)") + if (previous != null && previous != now) " << CHANGED" else "") + prefs.edit().putString("lastDrivers", now).apply() DriverBundle.active(context)?.let { b -> appendLine("pair: ${b.name} ${b.version} (bundle ${b.id})") release(context, b.id)?.let { appendLine("pair release: $it") } @@ -161,8 +171,10 @@ object GraphicsReport { val guestLines = File(dir, "session.log").takeIf { it.isFile }?.useLines { seq -> seq.filter { GUEST.containsMatchIn(it) }.take(200).toList() }.orEmpty() + val limits = File(dir, "limits.txt").takeIf { it.isFile }?.readText()?.trim() val audio = File(dir, "audio.log").takeIf { it.isFile }?.readText().orEmpty() report.appendText(buildString { + limits?.let { appendLine("open files limit: $it") } if (audio.contains("AAUDIO_ERROR_DISCONNECTED")) { appendLine("!! SOUND: Android refused the audio output (AAUDIO_ERROR_DISCONNECTED) - rebooting the phone usually fixes this") } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index ed53c5cd37..532c3a77fe 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -679,6 +679,10 @@ class SessionService : Service() { guest.add("XWAYLAND_NO_GLAMOR=1") Log.w(TAG, "xwayland: the last session's Xwayland crashed; glamor off for this one (XWAYLAND_NO_GLAMOR=1)") } + // A Mali PanVK session ran out of file descriptors after ten minutes (sync files and + // dma-bufs, "Too many open files"): the session script raises its open-files limit to the + // hard limit for the whole session tree. Never on an Adreno. + if (!com.droiddeck.launcher.core.DeviceSupport.adreno()) guest.add("BL_RAISE_NOFILE=1") // gamescope's explicit sync waits on DRM syncobj timelines through // DRM_IOCTL_SYNCOBJ_EVENTFD, which a kernel before 6.6 does not have (Exynos 2400e on 6.1: // hundreds of "timeline ... failed" and a game stuck at black), and Mali's stand-in node diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 286429ef1e..60dc5ae84a 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -211,8 +211,11 @@ internal fun SetupPanel( }, when (gpu.support) { com.droiddeck.launcher.gpu.GpuInfo.Support.TESTED -> stringResource(R.string.setup_gpu_detail, gpu.displayName(ctx), gpuName) - com.droiddeck.launcher.gpu.GpuInfo.Support.UNTESTED -> stringResource(R.string.setup_gpu_untested_detail, gpu.displayName(ctx), gpu.supportText(ctx).replaceFirstChar { it.lowercase() }) - else -> if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName) + com.droiddeck.launcher.gpu.GpuInfo.Support.UNTESTED -> + if (!s.adreno && s.vkBridge && !com.droiddeck.launcher.core.DeviceSupport.bridgeUsable()) stringResource(R.string.setup_gpu_bridge_unusable, gpu.displayName(ctx)) + else stringResource(R.string.setup_gpu_untested_detail, gpu.displayName(ctx), gpu.supportText(ctx).replaceFirstChar { it.lowercase() }) + else -> if (s.vkBridge && !com.droiddeck.launcher.core.DeviceSupport.bridgeUsable()) stringResource(R.string.setup_gpu_bridge_unusable, gpuName) + else if (s.vkBridge) stringResource(R.string.setup_gpu_bridge_detail, gpuName) else stringResource(R.string.setup_gpu_unsupported_detail, gpuName) }, divider = divider, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 33643c66d3..717f7f67a2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2329,6 +2329,7 @@ Mali (Venus): off Mali (Venus): on Mali bridge: off + %1$s cannot use the Mali bridge (it needs a Mali GPU without a system-driver route), so this switch has no effect here. Mali bridge: on %1$s is not an Adreno. The experimental Vulkan bridge is on: the session draws through the phone\'s own driver. Expect bugs; send the session logs. diff --git a/tools/gamescope/patches/0128-robustness2-optional.patch b/tools/gamescope/patches/0128-robustness2-optional.patch new file mode 100644 index 0000000000..35e8a7cd55 --- /dev/null +++ b/tools/gamescope/patches/0128-robustness2-optional.patch @@ -0,0 +1,96 @@ +diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp +index 41294f7..42b2ec6 100644 +--- a/src/rendervulkan.cpp ++++ b/src/rendervulkan.cpp +@@ -435,6 +435,9 @@ bool CVulkanDevice::selectPhysDev(VkSurfaceKHR surface) + return true; + } + ++// Stands in for VK_NULL_HANDLE in descriptor slots when the device has no nullDescriptor. ++static gamescope::OwningRc s_nullDescriptorFallback; ++ + bool CVulkanDevice::createDevice() + { + uint32_t supportedExtensionCount; +@@ -459,6 +462,9 @@ bool CVulkanDevice::createDevice() + if ( strcmp(ext.extensionName, VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME) == 0 ) + m_bSupportsModifiers = true; + ++ if ( strcmp(ext.extensionName, VK_EXT_ROBUSTNESS_2_EXTENSION_NAME) == 0 ) ++ m_bSupportsNullDescriptor = true; ++ + if ( strcmp(ext.extensionName, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME) == 0 ) + supportsForeignQueue = true; + +@@ -622,7 +628,10 @@ bool CVulkanDevice::createDevice() + + enabledExtensions.push_back( VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME ); + +- enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME ); ++ if ( m_bSupportsNullDescriptor ) ++ enabledExtensions.push_back( VK_EXT_ROBUSTNESS_2_EXTENSION_NAME ); ++ else ++ vk_log.infof( "no VK_EXT_robustness2: unused descriptor slots use a 1x1 texture" ); + #if 0 + enabledExtensions.push_back( VK_KHR_MAINTENANCE_5_EXTENSION_NAME ); + #endif +@@ -711,9 +720,10 @@ bool CVulkanDevice::createDevice() + + VkPhysicalDeviceRobustness2FeaturesEXT robustness2Features = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT, +- .pNext = std::exchange(features2.pNext, &robustness2Features), + .nullDescriptor = VK_TRUE, + }; ++ if ( m_bSupportsNullDescriptor ) ++ robustness2Features.pNext = std::exchange(features2.pNext, &robustness2Features); + + VkResult res = vk.CreateDevice(physDev(), &deviceCreateInfo, nullptr, &m_device); + if ( res == VK_ERROR_NOT_PERMITTED_KHR && useRealtimeVulkanQueue ) +@@ -1861,6 +1871,15 @@ void CVulkanCmdBuffer::dispatch(uint32_t x, uint32_t y, uint32_t z) + lut3DDescriptor[i].imageView = m_lut3D[i] ? m_lut3D[i]->srgbView() : VK_NULL_HANDLE; + } + ++ if ( !m_device->supportsNullDescriptor() && s_nullDescriptorFallback != nullptr ) ++ { ++ VkImageView fallback = s_nullDescriptorFallback->srgbView(); ++ for (auto &d : imageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : ycbcrImageDescriptors) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : shaperLutDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ for (auto &d : lut3DDescriptor) if (d.imageView == VK_NULL_HANDLE) d.imageView = fallback; ++ } ++ + if (!m_target->isYcbcr()) + { + targetDescriptors[0].imageView = m_target->srgbView(); +@@ -3546,6 +3565,9 @@ static bool vulkan_make_output_images( VulkanOutput_t *pOutput ) + // Oh no. + pOutput->temporaryHackyBlankImage = vulkan_create_debug_blank_texture(); + ++ if ( !g_device.supportsNullDescriptor() && s_nullDescriptorFallback == nullptr ) ++ s_nullDescriptorFallback = vulkan_create_flat_texture( 1, 1, 0, 0, 0, 0 ); ++ + if ( pOutput->uOutputFormatOverlay != VK_FORMAT_UNDEFINED && !kDisablePartialComposition ) + { + uint32_t uPartialDRMFormat = pOutput->uOutputFormatOverlay; +diff --git a/src/rendervulkan.hpp b/src/rendervulkan.hpp +index 5ffec4a..901e6a6 100644 +--- a/src/rendervulkan.hpp ++++ b/src/rendervulkan.hpp +@@ -866,6 +866,9 @@ public: + inline VkPipelineLayout pipelineLayout() {return m_pipelineLayout;} + inline int drmRenderFd() {return m_drmRendererFd;} + inline bool supportsModifiers() {return m_bSupportsModifiers;} ++ // VK_EXT_robustness2's nullDescriptor. A Mali driver through Venus has no robustness2: unused ++ // descriptor slots then point at a 1x1 texture instead of VK_NULL_HANDLE. ++ inline bool supportsNullDescriptor() {return m_bSupportsNullDescriptor;} + inline uint32_t vendorID() const {return m_uVendorID;} + inline const VkPhysicalDeviceMemoryProperties &memoryProperties() const {return m_memoryProperties;} + inline bool supportsMutableSwapchain() {return m_bSupportsMutableSwapchain;} +@@ -938,6 +941,7 @@ protected: + uint32_t m_uVendorID = 0; + bool m_bHasDrmPrimaryDevId = false; + bool m_bSupportsModifiers = false; ++ bool m_bSupportsNullDescriptor = false; + bool m_bSupportsMutableSwapchain = false; + bool m_bSupportsPresentWait = false; + bool m_bInitialized = false; diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index ad349d23b2..aff2f38a4b 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -7,6 +7,16 @@ # droiddeck-session lxqt the KDE Plasma desktop (DroidDeck's desktop package) # BL_WIDTH / BL_HEIGHT size the output, BL_FPS limits it, BL_LOG collects everything said here. set -u +# A GPU that is not an Adreno (BL_RAISE_NOFILE=1): the open-files limit goes up to the hard limit +# for the whole session tree (gamescope, Steam, games). A Mali PanVK session ran out after ten +# minutes ("Too many open files" importing sync files and dma-bufs) and froze. +if [ "${BL_RAISE_NOFILE:-0}" = 1 ] && [ -z "${BL_INSIDE:-}" ]; then + bl_nofile_was="$(ulimit -Sn)/$(ulimit -Hn)" + ulimit -Sn "$(ulimit -Hn)" 2>/dev/null || true + echo "== open files: soft/hard $bl_nofile_was -> soft $(ulimit -Sn)" + [ -n "${BL_DEBUG_DIR:-}" ] && echo "soft/hard $bl_nofile_was -> soft $(ulimit -Sn) (session tree)" > "$BL_DEBUG_DIR/limits.txt" 2>/dev/null + unset bl_nofile_was +fi export HOME=${HOME:-/root} mode=${1:-desktop} shift || true