From c6cec01b1dad96204fa99f3b0524b3cd7edc1061 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:11:24 +0000 Subject: [PATCH] fix(desktop): KWin gets a render node on Mali through Venus --- .../launcher/runtime/LinuxRuntime.java | 16 ++++-- .../launcher/session/SessionService.kt | 2 +- .../runtime/LinuxRuntimeGpuStandInTest.kt | 46 ++++++++++++++++ docs/development/mali-venus.md | 6 +++ tools/desktop-kde/README.md | 5 +- tools/tests/mali_compat_layer_test.c | 53 +++++++++++++++++++ tools/venus/layer/layer.c | 19 +++++++ 7 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/runtime/LinuxRuntimeGpuStandInTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java index f0e959d0c7..e67834f70b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java +++ b/app/src/main/java/com/droiddeck/launcher/runtime/LinuxRuntime.java @@ -363,10 +363,18 @@ public final class LinuxRuntime { }; public static String gpuStandIn(Context context) { - if (new File(KGSL_DEVICE).exists()) return KGSL_DEVICE; - if (com.droiddeck.launcher.core.DeviceSupport.INSTANCE.openDriverActive(context) && new File(MALI_DEVICE).exists()) return MALI_DEVICE; - if (!com.droiddeck.launcher.core.DeviceSupport.INSTANCE.vkBridge(context)) return null; - return bridgeStandIn(path -> new File(path).exists()); + return gpuStandIn(path -> new File(path).exists(), + () -> com.droiddeck.launcher.core.DeviceSupport.INSTANCE.openDriverActive(context) + || com.droiddeck.launcher.session.VenusComponent.wanted(context), + () -> com.droiddeck.launcher.core.DeviceSupport.INSTANCE.vkBridge(context)); + } + + static String gpuStandIn(java.util.function.Predicate exists, java.util.function.BooleanSupplier maliGuestDriver, + java.util.function.BooleanSupplier bridge) { + if (exists.test(KGSL_DEVICE)) return KGSL_DEVICE; + if (maliGuestDriver.getAsBoolean() && exists.test(MALI_DEVICE)) return MALI_DEVICE; + if (!bridge.getAsBoolean()) return null; + return bridgeStandIn(exists); } static String bridgeStandIn(java.util.function.Predicate exists) { 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 38fe0b65d9..43130219ae 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1066,8 +1066,8 @@ class SessionService : Service() { Log.i(TAG, "steam: software web compositing for the open driver pair (GPU raster kept)") } guest.add("DD_OPEN_DRIVER=1") - LinuxRuntime.gpuStandIn(this)?.takeIf { it == LinuxRuntime.MALI_DEVICE }?.let { guest.add("DD_DRM_STANDIN=$it") } } + if (!bridge) LinuxRuntime.gpuStandIn(this)?.takeIf { it == LinuxRuntime.MALI_DEVICE }?.let { guest.add("DD_DRM_STANDIN=$it") } val tuOverride = tuDebugOverride() val tuDriver = sysmemDriver(linuxDriverId) if (!venus && com.droiddeck.launcher.core.DeviceSupport.adreno()) (tuOverride ?: "sysmem".takeIf { tuDriver || SessionPrefs.tuSysmem(this) })?.let { guest.add("TU_DEBUG=$it") } diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/LinuxRuntimeGpuStandInTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/LinuxRuntimeGpuStandInTest.kt new file mode 100644 index 0000000000..28956166d2 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/runtime/LinuxRuntimeGpuStandInTest.kt @@ -0,0 +1,46 @@ +package com.droiddeck.launcher.runtime + +import android.app.Application +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33], manifest = Config.NONE, application = Application::class) +class LinuxRuntimeGpuStandInTest { + private val kgsl = "/dev/kgsl-3d0" + + private fun standIn(nodes: Set, maliGuestDriver: Boolean, bridge: Boolean): String? = + LinuxRuntime.gpuStandIn({ it in nodes }, { maliGuestDriver }, { bridge }) + + @Test fun maliGuestDriverGetsTheMaliNode() { + assertEquals(LinuxRuntime.MALI_DEVICE, standIn(setOf(LinuxRuntime.MALI_DEVICE), maliGuestDriver = true, bridge = false)) + } + + @Test fun maliWithoutAGuestDriverOrBridgeGetsNoNode() { + assertNull(standIn(setOf(LinuxRuntime.MALI_DEVICE, "/dev/dri/renderD128"), maliGuestDriver = false, bridge = false)) + } + + @Test fun maliGuestDriverWithoutTheMaliNodeGetsNoNode() { + assertNull(standIn(setOf("/dev/dri/renderD128"), maliGuestDriver = true, bridge = false)) + } + + @Test fun kgslStaysTheStandInWheneverItExists() { + assertEquals(kgsl, standIn(setOf(kgsl, LinuxRuntime.MALI_DEVICE), maliGuestDriver = true, bridge = true)) + assertEquals(kgsl, standIn(setOf(kgsl), maliGuestDriver = false, bridge = false)) + } + + @Test fun bridgeKeepsItsOwnNodeChoice() { + assertEquals("/dev/dri/renderD129", standIn(setOf("/dev/dri/renderD129"), maliGuestDriver = false, bridge = true)) + assertEquals(LinuxRuntime.MALI_DEVICE, standIn(setOf(LinuxRuntime.MALI_DEVICE), maliGuestDriver = false, bridge = true)) + } + + @Test fun guestDriverIsNotAskedWhenKgslExists() { + var asked = false + LinuxRuntime.gpuStandIn({ it == kgsl }, { asked = true; true }, { asked = true; true }) + assertEquals(false, asked) + } +} diff --git a/docs/development/mali-venus.md b/docs/development/mali-venus.md index 5cdc4ab39f..b030dddd72 100644 --- a/docs/development/mali-venus.md +++ b/docs/development/mali-venus.md @@ -149,6 +149,12 @@ The SPIR-V version the driver gets: only taken out where the layer emulates them. `DROIDDECK_MALI_COMPAT=0` turns both off. - This is what Dawn ("Disable SPIR-V 1.4 on Android ARM"), ANGLE (`supportsSPIRV14`) and naga (`AVOID_SPIRV_COPY_LOGICAL`) do for a proprietary compiler they cannot trust. +- Render node: Zink binds a GBM or DRI screen (KWin, Xwayland's glamor) to the Vulkan device + whose `VkPhysicalDeviceDrmPropertiesEXT` render node matches the screen's DRM fd. Venus over + vtest reports none, so KWin 6.8, which has no QPainter compositor, drew nothing on Desktop. + When the driver reports no render node, the layer reports the stand-in node's numbers + (`DD_DRM_STANDIN=/dev/mali0`, bound into the guest as `/dev/dri/renderD`). The + extension stays unlisted, and the layer is off in gamescope, so gamescope keeps its no-DRM path. Files: - `layer.c`: loader plumbing, feature and limit reporting, device creation, the hook table. diff --git a/tools/desktop-kde/README.md b/tools/desktop-kde/README.md index 53c6c5531b..74d76eeebd 100644 --- a/tools/desktop-kde/README.md +++ b/tools/desktop-kde/README.md @@ -44,8 +44,9 @@ through `kwin_wayland_wrapper`. The package's `kwin-compositor` marker selects O Zink for KWin 6.8, which removed QPainter. Older packages retain their software compositor. KWin runs without Gallium's threaded context and without overlay layers. With the threaded context, KWin crashed uploading windows' shared-memory buffers by reading past their end, and the host shows only a single buffer. -On Android the launcher explicitly selects the KGSL render node; the nested backend can use it -when the host's dmabuf feedback cannot name a DRM device. Games and emulators from the menu go +On Android the launcher explicitly selects the GPU's render node (KGSL, or `/dev/mali0` as a +stand-in for the Mali open driver and Venus); the nested backend can use it when the host's dmabuf +feedback cannot name a DRM device. Without one, KWin 6.8 has no compositor and the desktop stays black. Games and emulators from the menu go through `droiddeck-gpu`, and Steam goes back to the app as a Steam session. `kwin.env` pins the KWin version shared by the build and packaging jobs. `build-kwin.sh` builds that version's diff --git a/tools/tests/mali_compat_layer_test.c b/tools/tests/mali_compat_layer_test.c index 9b29e5c734..d7f0c09c30 100644 --- a/tools/tests/mali_compat_layer_test.c +++ b/tools/tests/mali_compat_layer_test.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *interface); @@ -240,6 +242,16 @@ static void VKAPI_CALL mock_properties(VkPhysicalDevice physical, VkPhysicalDevi static void VKAPI_CALL mock_properties2(VkPhysicalDevice physical, VkPhysicalDeviceProperties2 *properties) { mock_properties(physical, &properties->properties); + for (VkBaseOutStructure *s = properties->pNext; s; s = s->pNext) { + if (s->sType != VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT) + continue; + VkPhysicalDeviceDrmPropertiesEXT *drm = (VkPhysicalDeviceDrmPropertiesEXT *)s; + bool own = physical == (VkPhysicalDevice)&mock_capable; + drm->hasPrimary = drm->hasRender = own; + drm->primaryMajor = drm->renderMajor = own ? 226 : 0; + drm->primaryMinor = 0; + drm->renderMinor = own ? 128 : 0; + } } static void VKAPI_CALL mock_memory_properties(VkPhysicalDevice physical, VkPhysicalDeviceMemoryProperties *properties) @@ -567,6 +579,46 @@ static void test_depth_compare_op(void) destroy_device(device); } +static VkPhysicalDeviceDrmPropertiesEXT query_drm(VkPhysicalDevice physical) +{ + VkPhysicalDeviceDrmPropertiesEXT drm = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT}; + VkPhysicalDeviceProperties2 properties = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &drm, {0}}; + ((PFN_vkGetPhysicalDeviceProperties2)layer_gipa((VkInstance)&mock_instance, "vkGetPhysicalDeviceProperties2"))( + physical, &properties); + return drm; +} + +static void test_render_node(void) +{ + VkPhysicalDevice lacking = (VkPhysicalDevice)&mock_lacking, capable = (VkPhysicalDevice)&mock_capable; + struct stat node; + assert(stat("/dev/null", &node) == 0 && S_ISCHR(node.st_mode)); + + unsetenv("DD_DRM_STANDIN"); + VkPhysicalDeviceDrmPropertiesEXT drm = query_drm(lacking); + assert(!drm.hasRender && !drm.renderMajor && !drm.renderMinor); + + setenv("DD_DRM_STANDIN", "/dev/null", 1); + drm = query_drm(lacking); + assert(drm.hasRender && !drm.hasPrimary); + assert(drm.renderMajor == (int64_t)major(node.st_rdev) && drm.renderMinor == (int64_t)minor(node.st_rdev)); + + drm = query_drm(capable); + assert(drm.hasRender && drm.hasPrimary && drm.renderMajor == 226 && drm.renderMinor == 128); + + VkPhysicalDeviceProperties2 plain = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, NULL, {0}}; + ((PFN_vkGetPhysicalDeviceProperties2)layer_gipa((VkInstance)&mock_instance, "vkGetPhysicalDeviceProperties2"))( + lacking, &plain); + + const char *not_devices[] = {"", "/", "/nonexistent/renderD128"}; + for (size_t i = 0; i < sizeof(not_devices) / sizeof(not_devices[0]); i++) { + setenv("DD_DRM_STANDIN", not_devices[i], 1); + drm = query_drm(lacking); + assert(!drm.hasRender && !drm.renderMajor && !drm.renderMinor); + } + unsetenv("DD_DRM_STANDIN"); +} + int main(int argc, char **argv) { test_spirv(argc > 1 ? argv[1] : NULL); @@ -590,6 +642,7 @@ int main(int argc, char **argv) test_lacking_device(); test_capable_device(); test_depth_compare_op(); + test_render_node(); ((PFN_vkDestroyInstance)layer_gipa(instance, "vkDestroyInstance"))(instance, NULL); free(driver_code); diff --git a/tools/venus/layer/layer.c b/tools/venus/layer/layer.c index 9aeb0bcf0e..7c6ff4dea0 100644 --- a/tools/venus/layer/layer.c +++ b/tools/venus/layer/layer.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include #define LAYER_NAME "VK_LAYER_DROIDDECK_mali_compat" @@ -389,12 +391,29 @@ static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties(VkPhysicalDevice p report_limits(&properties->limits, physical_device_gaps(inst, physical_device)); } +static void report_render_node(VkPhysicalDeviceProperties2 *properties) +{ + VkPhysicalDeviceDrmPropertiesEXT *drm = NULL; + for (VkBaseOutStructure *s = properties->pNext; s && !drm; s = s->pNext) { + if (s->sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT) + drm = (VkPhysicalDeviceDrmPropertiesEXT *)s; + } + const char *node = getenv("DD_DRM_STANDIN"); + struct stat st; + if (!drm || drm->hasRender || !node || !*node || stat(node, &st) != 0 || !S_ISCHR(st.st_mode)) + return; + drm->hasRender = VK_TRUE; + drm->renderMajor = major(st.st_rdev); + drm->renderMinor = minor(st.st_rdev); +} + static VKAPI_ATTR void VKAPI_CALL GetPhysicalDeviceProperties2(VkPhysicalDevice physical_device, VkPhysicalDeviceProperties2 *properties) { struct instance *inst = instance_from_handle(physical_device); inst->GetPhysicalDeviceProperties2(physical_device, properties); report_limits(&properties->properties.limits, physical_device_gaps(inst, physical_device)); + report_render_node(properties); if (tracing()) layer_log("trace: vkGetPhysicalDeviceProperties2: %s, Vulkan %u.%u.%u, type %d", properties->properties.deviceName, VK_API_VERSION_MAJOR(properties->properties.apiVersion), VK_API_VERSION_MINOR(properties->properties.apiVersion),