From 9c987fa92e998283f2b707ccd28742875b7f530f Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Sun, 25 Oct 2026 00:54:36 +0900 Subject: [PATCH] Fall back automatically on Qualcomm drivers with fewer capabilities Older Adreno drivers such as the 8 Gen 2's 0.676.1 lack VK_EXT_external_memory_dma_buf, DRM modifiers and calibrated timestamps. They failed device creation in the WSI layer, failed Proton games on the zero-copy path, and corrupted the Steam UI under GPU compositing. - WSI patch 0005 makes the Wayland platform optional per device, so a device without its extensions stays usable for X11 swapchains instead of failing vkCreateDevice. - droiddeck-qualcomm-caps checks DMA-BUF export and import, the swapchain extensions and Gamescope's linux-dmabuf once per session; Proton games use the zero-copy WSI path only when it passes and stay on X11 SHM otherwise. The session log records the verdict. - The Steam browser uses software compositing when Zink offers less than OpenGL 4.0, with BL_STEAM_CEF_SOFTWARE as the manual override. Verified on the Adreno 740 (falls back to SHM and software compositing, UI correct) and the Adreno 840 (zero-copy and GPU compositing unchanged). (cherry picked from commit d8d0b10cced1f21a1e9bc7dca00efd89b389adb3) (cherry picked from commit 00775f05118ace13f22e3064791da6d34ab05a7f) --- .../launcher/session/SessionFiles.kt | 1 + .../usr/local/bin/droiddeck-qualcomm-caps | 242 ++++++++++++++++++ .../overlay/usr/local/bin/droiddeck-session | 19 ++ .../overlay/usr/local/bin/steam-compatibility | 6 +- tools/qualcomm/README.md | 16 +- tools/qualcomm/runtime.json | 10 +- .../0005-optional-wayland-platform.patch | 118 +++++++++ tools/tests/test_qualcomm_browser.py | 57 +++++ tools/tests/test_qualcomm_caps.py | 39 +++ tools/tests/test_qualcomm_present.py | 27 +- 10 files changed, 525 insertions(+), 10 deletions(-) create mode 100755 tools/linuxfs/overlay/usr/local/bin/droiddeck-qualcomm-caps create mode 100644 tools/qualcomm/wsi-patches/0005-optional-wayland-platform.patch create mode 100644 tools/tests/test_qualcomm_browser.py create mode 100644 tools/tests/test_qualcomm_caps.py diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 4ef2c34945..e8d3a4efc9 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -58,6 +58,7 @@ object SessionFiles { "usr/local/bin/droiddeck-steam-install" to "usr/local/bin/droiddeck-steam-install", "usr/local/bin/droiddeck-steam-taskset" to "usr/local/bin/droiddeck-steam-taskset", "usr/local/bin/droiddeck-steam-taskset" to "usr/local/libexec/droiddeck-steam/taskset", + "usr/local/bin/droiddeck-qualcomm-caps" to "usr/local/bin/droiddeck-qualcomm-caps", "usr/local/bin/droiddeck-steam-ui-scale" to "usr/local/bin/droiddeck-steam-ui-scale", "usr/local/bin/droiddeck-steam-language" to "usr/local/bin/droiddeck-steam-language", "usr/local/bin/droiddeck-steam-shaders" to "usr/local/bin/droiddeck-steam-shaders", diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-qualcomm-caps b/tools/linuxfs/overlay/usr/local/bin/droiddeck-qualcomm-caps new file mode 100755 index 0000000000..821d1cc602 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-qualcomm-caps @@ -0,0 +1,242 @@ +#!/usr/bin/env python3 +"""Decide whether this Qualcomm session can present Proton games zero-copy through Gamescope's WSI layer. + +Prints one line and exits 0 only when every check passes; anything else keeps games on X11 SHM. +""" +import ctypes as c +import os +import subprocess +import sys + +U = c.c_uint32 +H = c.c_void_p +Q = c.c_uint64 + +REQUIRED = ('VK_KHR_external_memory_fd', 'VK_EXT_external_memory_dma_buf', 'VK_KHR_image_format_list', + 'VK_KHR_external_fence_fd') +# The WSI layer implements these at vkCreateDevice without listing them, so only device creation can confirm them. +PRESENT = ('VK_KHR_swapchain', 'VK_EXT_swapchain_maintenance1') +SURFACES = ('VK_KHR_surface', 'VK_KHR_wayland_surface', 'VK_KHR_xcb_surface', 'VK_KHR_xlib_surface', + 'VK_KHR_get_surface_capabilities2', 'VK_EXT_surface_maintenance1') +DMA_BUF = 0x200 +EXPORTABLE, IMPORTABLE = 0x2, 0x4 +B8G8R8A8_UNORM, LINEAR, IMAGE_2D = 44, 1, 1 +TRANSFER_SRC, TRANSFER_DST, SAMPLED, COLOR_ATTACHMENT = 0x1, 0x2, 0x4, 0x10 +WIDTH = 256 + + +def structure(name, fields): + return type(name, (c.Structure,), {'_fields_': fields}) + + +Application = structure('Application', [('type', U), ('next', H), ('name', c.c_char_p), ('version', U), + ('engine', c.c_char_p), ('engineVersion', U), ('api', U)]) +Instance = structure('Instance', [('type', U), ('next', H), ('flags', U), ('application', c.POINTER(Application)), + ('layerCount', U), ('layers', H), ('extensionCount', U), + ('extensions', c.POINTER(c.c_char_p))]) +Extension = structure('Extension', [('name', c.c_char * 256), ('version', U)]) +Family = structure('Family', [('flags', U), ('count', U), ('timestampBits', U), ('granularity', U * 3)]) +QueueCreate = structure('QueueCreate', [('type', U), ('next', H), ('flags', U), ('family', U), ('count', U), + ('priorities', c.POINTER(c.c_float))]) +DeviceCreate = structure('DeviceCreate', [('type', U), ('next', H), ('flags', U), ('queueCount', U), + ('queues', c.POINTER(QueueCreate)), ('layerCount', U), ('layers', H), + ('extensionCount', U), ('extensions', c.POINTER(c.c_char_p)), + ('features', H)]) +Maintenance1 = structure('Maintenance1', [('type', U), ('next', H), ('enabled', U)]) +FormatInfo = structure('FormatInfo', [('type', U), ('next', H), ('format', U), ('imageType', U), ('tiling', U), + ('usage', U), ('flags', U)]) +ExternalInfo = structure('ExternalInfo', [('type', U), ('next', H), ('handle', U)]) +ExternalProperties = structure('ExternalProperties', [('type', U), ('next', H), ('features', U), ('exportFrom', U), + ('compatible', U)]) +FormatProperties = structure('FormatProperties', [('type', U), ('next', H), ('extent', U * 3), ('mipLevels', U), + ('arrayLayers', U), ('samples', U), ('maxSize', Q)]) +ImageCreate = structure('ImageCreate', [('type', U), ('next', H), ('flags', U), ('imageType', U), ('format', U), + ('extent', U * 3), ('mipLevels', U), ('arrayLayers', U), ('samples', U), + ('tiling', U), ('usage', U), ('sharing', U), ('familyCount', U), + ('families', H), ('layout', U)]) +ExternalImage = structure('ExternalImage', [('type', U), ('next', H), ('handles', U)]) +Requirements = structure('Requirements', [('size', Q), ('alignment', Q), ('types', U)]) +Allocate = structure('Allocate', [('type', U), ('next', H), ('size', Q), ('index', U)]) +ExportAllocate = structure('ExportAllocate', [('type', U), ('next', H), ('handles', U)]) +Dedicated = structure('Dedicated', [('type', U), ('next', H), ('image', Q), ('buffer', Q)]) +GetFd = structure('GetFd', [('type', U), ('next', H), ('memory', Q), ('handle', U)]) +Subresource = structure('Subresource', [('aspect', U), ('mip', U), ('layer', U)]) +Layout = structure('Layout', [('offset', Q), ('size', Q), ('rowPitch', Q), ('arrayPitch', Q), ('depthPitch', Q)]) + + +def decide(caps): + """Return (enabled, reasons) for the probed capabilities.""" + if caps.get('error'): + return False, ['probe failed: ' + caps['error']] + reasons = ['missing ' + name for name in REQUIRED if name not in caps.get('extensions', ())] + if not reasons: + if not caps.get('linear_export'): + reasons.append('LINEAR DMA-BUF images are not exportable') + if not caps.get('linear_import'): + reasons.append('LINEAR DMA-BUF images are not importable') + if not caps.get('export_fd'): + reasons.append(caps.get('export_error') or 'DMA-BUF export failed') + if not caps.get('gamescope_dmabuf'): + reasons.append('Gamescope offers no linux-dmabuf') + return not reasons, reasons + + +def gamescope_dmabuf(): + if not os.environ.get('WAYLAND_DISPLAY'): + return False + try: + info = subprocess.run(['wayland-info'], capture_output=True, text=True, timeout=5) + except (OSError, subprocess.TimeoutExpired): + return False + return 'zwp_linux_dmabuf_v1' in info.stdout + + +def probe(): + vk = c.CDLL('libvulkan.so.1') + + def function(name, arguments, result=c.c_int): + f = getattr(vk, name) + f.argtypes, f.restype = arguments, result + return f + + def check(result, operation): + if result != 0: + raise RuntimeError(f'{operation} returned {result}') + + def names(values): + return (c.c_char_p * len(values))(*[value.encode() for value in values]) + + caps = {'gamescope_dmabuf': gamescope_dmabuf()} + count = U() + enumerate_instance = function('vkEnumerateInstanceExtensionProperties', [c.c_char_p, c.POINTER(U), H]) + check(enumerate_instance(None, c.byref(count), None), 'vkEnumerateInstanceExtensionProperties') + available = (Extension * count.value)() + check(enumerate_instance(None, c.byref(count), available), 'vkEnumerateInstanceExtensionProperties') + surfaces = [name for name in SURFACES if name in {e.name.decode() for e in available}] + application = Application(0, None, b'droiddeck-qualcomm-caps', 1, b'droiddeck', 1, (1 << 22) | (1 << 12)) + instance_names = names(surfaces) + instance_info = Instance(1, None, 0, c.pointer(application), 0, None, len(surfaces), instance_names) + instance = H() + check(function('vkCreateInstance', [c.POINTER(Instance), H, c.POINTER(H)])( + c.byref(instance_info), None, c.byref(instance)), 'vkCreateInstance') + try: + devices = (H * 1)() + count = U(1) + result = function('vkEnumeratePhysicalDevices', [H, c.POINTER(U), H])(instance, c.byref(count), devices) + if result not in (0, 5) or count.value == 0: + raise RuntimeError(f'vkEnumeratePhysicalDevices returned {result}') + physical = devices[0] + properties = (c.c_uint8 * 1024)() + function('vkGetPhysicalDeviceProperties', [H, H], None)(physical, properties) + driver = int.from_bytes(bytes(properties[4:8]), 'little') + caps['device'] = bytes(properties[20:276]).split(b'\0')[0].decode(errors='replace') + caps['driver'] = f'{(driver >> 22) & 0x7f}.{(driver >> 12) & 0x3ff}.{driver & 0xfff}' + enumerate_device = function('vkEnumerateDeviceExtensionProperties', [H, c.c_char_p, c.POINTER(U), H]) + count = U() + check(enumerate_device(physical, None, c.byref(count), None), 'vkEnumerateDeviceExtensionProperties') + extensions = (Extension * count.value)() + check(enumerate_device(physical, None, c.byref(count), extensions), 'vkEnumerateDeviceExtensionProperties') + caps['extensions'] = {e.name.decode() for e in extensions} + if any(name not in caps['extensions'] for name in REQUIRED): + return caps + + format_properties = function('vkGetPhysicalDeviceImageFormatProperties2', + [H, c.POINTER(FormatInfo), c.POINTER(FormatProperties)]) + + def external_features(usage): + external = ExternalInfo(1000071000, None, DMA_BUF) + info = FormatInfo(1000059004, c.cast(c.pointer(external), H), B8G8R8A8_UNORM, IMAGE_2D, LINEAR, usage, 0) + result = ExternalProperties(1000071001, None, 0, 0, 0) + output = FormatProperties(1000059003, c.cast(c.pointer(result), H)) + return result.features if format_properties(physical, c.byref(info), c.byref(output)) == 0 else 0 + + caps['linear_export'] = bool(external_features(COLOR_ATTACHMENT | TRANSFER_SRC | TRANSFER_DST) & EXPORTABLE) + caps['linear_import'] = bool(external_features(SAMPLED | TRANSFER_SRC) & IMPORTABLE) + + families = (Family * 16)() + count = U(16) + function('vkGetPhysicalDeviceQueueFamilyProperties', [H, c.POINTER(U), H], None)( + physical, c.byref(count), families) + family = next((i for i in range(count.value) if families[i].flags & 1), 0) + priority = c.c_float(1.0) + queue = QueueCreate(2, None, 0, family, 1, c.pointer(priority)) + maintenance1 = Maintenance1(1000275000, None, 1) + device_names = names(REQUIRED + PRESENT) + device_info = DeviceCreate(3, c.cast(c.pointer(maintenance1), H), 0, 1, c.pointer(queue), 0, None, + len(REQUIRED + PRESENT), device_names, None) + device = H() + result = function('vkCreateDevice', [H, c.POINTER(DeviceCreate), H, c.POINTER(H)])( + physical, c.byref(device_info), None, c.byref(device)) + if result != 0: + caps['export_error'] = f'device with the zero-copy extensions failed ({result})' + return caps + try: + caps['export_fd'], caps['export_error'] = export_linear_image(function, device) + finally: + function('vkDestroyDevice', [H, H], None)(device, None) + finally: + function('vkDestroyInstance', [H, H], None)(instance, None) + return caps + + +def export_linear_image(function, device): + external = ExternalImage(1000072001, None, DMA_BUF) + info = ImageCreate(14, c.cast(c.pointer(external), H), 0, IMAGE_2D, B8G8R8A8_UNORM, (U * 3)(WIDTH, WIDTH, 1), + 1, 1, 1, LINEAR, COLOR_ATTACHMENT | TRANSFER_SRC | TRANSFER_DST, 0, 0, None, 0) + image = Q() + result = function('vkCreateImage', [H, c.POINTER(ImageCreate), H, c.POINTER(Q)])( + device, c.byref(info), None, c.byref(image)) + if result != 0: + return False, f'LINEAR exportable image creation failed ({result})' + memory = Q() + try: + requirements = Requirements() + function('vkGetImageMemoryRequirements', [H, Q, c.POINTER(Requirements)], None)( + device, image, c.byref(requirements)) + if not requirements.types: + return False, 'no memory type for the exportable image' + dedicated = Dedicated(1000127001, None, image.value, 0) + export = ExportAllocate(1000072002, c.cast(c.pointer(dedicated), H), DMA_BUF) + index = (requirements.types & -requirements.types).bit_length() - 1 + allocate = Allocate(5, c.cast(c.pointer(export), H), requirements.size, index) + result = function('vkAllocateMemory', [H, c.POINTER(Allocate), H, c.POINTER(Q)])( + device, c.byref(allocate), None, c.byref(memory)) + if result != 0: + return False, f'exportable dedicated allocation failed ({result})' + result = function('vkBindImageMemory', [H, Q, Q, Q])(device, image, memory, 0) + if result != 0: + return False, f'binding the exportable image failed ({result})' + layout = Layout() + function('vkGetImageSubresourceLayout', [H, Q, c.POINTER(Subresource), c.POINTER(Layout)], None)( + device, image, c.byref(Subresource(1, 0, 0)), c.byref(layout)) + if layout.rowPitch < WIDTH * 4: + return False, f'LINEAR row pitch {layout.rowPitch} is too small' + address = function('vkGetDeviceProcAddr', [H, c.c_char_p], H)(device, b'vkGetMemoryFdKHR') + if not address: + return False, 'vkGetMemoryFdKHR is unavailable' + get_fd = c.CFUNCTYPE(c.c_int, H, c.POINTER(GetFd), c.POINTER(c.c_int))(address) + fd = c.c_int(-1) + result = get_fd(device, c.byref(GetFd(1000074002, None, memory.value, DMA_BUF)), c.byref(fd)) + if result != 0 or fd.value < 0: + return False, f'vkGetMemoryFdKHR failed ({result})' + os.close(fd.value) + return True, None + finally: + if memory.value: + function('vkFreeMemory', [H, Q, H], None)(device, memory, None) + function('vkDestroyImage', [H, Q, H], None)(device, image, None) + + +def main(): + try: + caps = probe() + except Exception as error: + caps = {'error': str(error)} + enabled, reasons = decide(caps) + where = f" ({caps['device']}, driver {caps['driver']})" if caps.get('device') else '' + print(('zero-copy on' if enabled else 'zero-copy off: ' + '; '.join(reasons)) + where) + return 0 if enabled else 1 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session index fa84fa819e..d1f1a674b9 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session @@ -297,7 +297,25 @@ if [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ]; then export VK_LOADER_DEBUG=error export WSI_X11_FORCE_SHM=1 DISABLE_GAMESCOPE_WSI=1 . "$DROIDDECK_QUALCOMM_ROOT/mesa/qualcomm-gl.sh" + DROIDDECK_QUALCOMM_ZERO_COPY=0 + bl_caps=$(timeout 20 /usr/local/bin/droiddeck-qualcomm-caps 2>/dev/null) && DROIDDECK_QUALCOMM_ZERO_COPY=1 + echo "== qualcomm: ${bl_caps:-zero-copy off: the capability probe gave no answer}" + export DROIDDECK_QUALCOMM_ZERO_COPY + unset bl_caps fi +# Chromium's GPU compositor corrupts the Steam UI on Qualcomm drivers where Zink stops below OpenGL 4.0. +# An explicit BL_STEAM_CEF_SOFTWARE decides instead. +bl_qualcomm_browser_gpu() { + [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ] && [ -z "${BL_STEAM_CEF_SOFTWARE+x}" ] || return 0 + local gl + gl=$(timeout 15 glxinfo -B 2>/dev/null | sed -n 's/^ *Max core profile version: *\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1) + if [ "${gl%%.*}" -ge 4 ] 2>/dev/null; then + echo "== steam: browser GPU compositing on (Zink OpenGL $gl)" + return 0 + fi + echo "== steam: browser software compositing (Zink offers OpenGL ${gl:-unknown}; GPU compositing needs 4.0)" + return 1 +} reap_orphans() { local round p stat pid left for round in 1 2 3 4 5; do @@ -396,6 +414,7 @@ case $mode in [ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ] && steam_x64=1 steam_cef_gpu=1 [ "${BL_STEAM_CEF_SOFTWARE:-0}" != 1 ] || steam_cef_gpu=0 + bl_qualcomm_browser_gpu || steam_cef_gpu=0 if [ "$steam_x64" = 1 ]; then step "checking the Steam client's arm64 parts (first run downloads them, ~1-2 min)" # droiddeck-steam-install removes the repair request: read it first so Repair Steam covers both clients. diff --git a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility index 197de6c2b3..09b07aa96f 100755 --- a/tools/linuxfs/overlay/usr/local/bin/steam-compatibility +++ b/tools/linuxfs/overlay/usr/local/bin/steam-compatibility @@ -201,10 +201,12 @@ bl_libpath() { } """ -# Qualcomm sessions copy the Steam client's frames through X11 SHM; games hand Gamescope LINEAR DMA-BUFs instead. +# Qualcomm sessions copy the Steam client's frames through X11 SHM. Games hand Gamescope LINEAR DMA-BUFs only when +# the session's capability probe found DMA-BUF export, so drivers without it keep games on SHM too. BL_PRESENT_SETUP = """ bl_present() { - [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ] && [ "${BL_QUALCOMM_SHM:-0}" != 1 ] || return 0 + [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ] && [ "${DROIDDECK_QUALCOMM_ZERO_COPY:-0}" = 1 ] && + [ "${BL_QUALCOMM_SHM:-0}" != 1 ] || return 0 unset DISABLE_GAMESCOPE_WSI WSI_X11_FORCE_SHM } """ diff --git a/tools/qualcomm/README.md b/tools/qualcomm/README.md index b6e7f19700..2fa89680d8 100644 --- a/tools/qualcomm/README.md +++ b/tools/qualcomm/README.md @@ -22,6 +22,8 @@ Earlier RedMagic 11 Pro/v891.7 trials on 2026-10-24 failed to produce a stable h On Adreno 740/Qualcomm 0.676.1, session `2026-10-24-13-steam` enabled the regular browser GPU path with the private Mesa integration and retained the SDL workaround. Steam reached its visible library and the user confirmed faster interaction, then reported UI corruption. Captures show persistent black rectangles obscuring portions of the library. The browser command line lacked `--disable-gpu` and `--disable-gpu-compositing`; its process mapped the Qualcomm HAL, libhybris ICD, private Zink library and Steam's ANGLE libraries, held an open `/dev/kgsl-3d0` descriptor, and did not map SwiftShader. Disabling partial swap in session `2026-10-24-14-steam` did not remove the visible corruption; that flag is not packaged. Investigation was paused at the user's request to prepare an Adreno 840 test APK. This path is experimental and has not passed rendering acceptance. An explicit `BL_STEAM_CEF_SOFTWARE=1` session environment override remains available for diagnosis or fallback. +The GPU path is gated on Zink's OpenGL level. Before Steam starts, `droiddeck-session` reads Zink's maximum core profile version with `glxinfo -B`; below 4.0, or when the version cannot be read, the browser starts with `-cef-disable-gpu` and the log says why, for example `== steam: browser software compositing (Zink offers OpenGL 3.2; GPU compositing needs 4.0)`. Setting `BL_STEAM_CEF_SOFTWARE` to `0` or `1` skips the gate. On the vivo V2243A (Adreno 740, system driver 0.676.1) Zink reaches OpenGL 3.2 and GPU compositing left the library without its background, tabs and parts of covers, with stale regions while moving between items. Software compositing rendered it correctly. Disabling the compat layer's shader rewrites, Zink's render-pass tracking, compact descriptors, threaded GL, Mesa's no-error mode or command reordering, or forcing synchronous Zink flushes, did not change the corruption, and the runtime from before the zero-copy work showed it too. The Adreno 840 with v891.7 reaches OpenGL 4.6 and keeps GPU compositing. + Qualcomm sessions also leave the Steam client CPU affinity unrestricted by default, preserving explicitly saved overrides. The previous SM8550 default pinned Steam, its browser and Gamescope to one core. The affinity loop now applies client masks only to Steam and its browser. A startup recording after that fix showed the complete six-second DroidDeck animation followed by the library; a brief initial white window remained before playback. ### Pixmap binding without DRI3 @@ -79,14 +81,24 @@ The recipes pin upstream source revisions and retain local outputs under `build/ ## Zero-copy game presentation -Proton games in Qualcomm sessions present through Gamescope's WSI layer instead of X11 shared memory. The Steam client, its browser and other session programs keep `WSI_X11_FORCE_SHM=1` and `DISABLE_GAMESCOPE_WSI=1`; the Proton wrapper's `bl_present` drops both for the game. Set `BL_QUALCOMM_SHM=1` in the session environment to keep games on the shared-memory path. +Proton games in Qualcomm sessions present through Gamescope's WSI layer instead of X11 shared memory when the driver can export LINEAR DMA-BUFs. The Steam client, its browser and other session programs keep `WSI_X11_FORCE_SHM=1` and `DISABLE_GAMESCOPE_WSI=1`; the Proton wrapper's `bl_present` drops both for the game only when `DROIDDECK_QUALCOMM_ZERO_COPY=1`. Set `BL_QUALCOMM_SHM=1` in the session environment to keep games on the shared-memory path regardless. -The Qualcomm HAL has DMA-BUF export but no `VK_EXT_image_drm_format_modifier`, and Android has no DRM device. The WSI layer is therefore rebuilt with its Wayland backend and `wsi-patches`: +`droiddeck-session` sets `DROIDDECK_QUALCOMM_ZERO_COPY` from `droiddeck-qualcomm-caps`, which runs once per session through the bridge ICD and the session's layers, so an imported AdrenoTools driver is judged rather than the system one. Zero-copy is enabled only when all of these hold: + +- The driver offers `VK_KHR_external_memory_fd`, `VK_EXT_external_memory_dma_buf`, `VK_KHR_image_format_list` and `VK_KHR_external_fence_fd`. +- LINEAR `B8G8R8A8_UNORM` images are exportable as DMA-BUF colour attachments and importable as sampled images. +- A device with those extensions, `VK_KHR_swapchain` and `VK_EXT_swapchain_maintenance1` with its feature (which Gamescope's WSI layer forces on) is created through the session's layers, and a LINEAR image's dedicated memory is exported with `vkGetMemoryFdKHR`. The WSI layer implements the swapchain extensions without listing them, so only device creation confirms them. +- Gamescope's Wayland display offers `zwp_linux_dmabuf_v1`. + +Any failure, timeout or crash leaves games on SHM. The session log records the result, for example `== qualcomm: zero-copy off: missing VK_EXT_external_memory_dma_buf; Gamescope offers no linux-dmabuf (Adreno (TM) 740, driver 0.676.1)`. + +The Qualcomm HAL used for development has DMA-BUF export but no `VK_EXT_image_drm_format_modifier`, and Android has no DRM device. The WSI layer is therefore rebuilt with its Wayland backend and `wsi-patches`: - `0001` allocates swapchain images in the driver as LINEAR images with exportable dedicated memory, exports them with `vkGetMemoryFdKHR`, takes offset and stride from `vkGetImageSubresourceLayout`, and sends them as LINEAR `zwp_linux_dmabuf_v1` buffers. The modifier extension is no longer required at `vkCreateDevice`. X11 DRI3 keeps its previous behavior. - `0002` removes the `__STDC_VERSION__` workaround that GCC 16 rejects. - `0003` opens `/dev/dma_heap/system` read-only, the only access Android grants apps. - `0004` exposes `vkAcquireNextImage2KHR` on Vulkan 1.0 devices; Gamescope's WSI layer acquires every image through it. +- `0005` keeps devices without the Wayland backend's extensions usable. Upstream fails `vkCreateDevice` for any instance that enables `VK_KHR_wayland_surface` (Zink always does) when an extension is missing. Calibrated timestamps are now optional because only present timing uses them. When the remaining requirements are missing, the device is created without them, Wayland surfaces report no presentation support, and swapchain creation on them fails. Other platforms keep the upstream behaviour. `gamescope-linear-dmabuf.patch` makes the private Gamescope create a version 3 `linux-dmabuf` global without a DRM device (wlroots otherwise creates none), advertise LINEAR beside the implicit layout, and import LINEAR buffers as LINEAR images. Without modifiers the stride cannot be imposed, so an import is refused when the buffer's offset or stride differs from the driver's own LINEAR layout. diff --git a/tools/qualcomm/runtime.json b/tools/qualcomm/runtime.json index f5de69c26f..cbb5d58a85 100644 --- a/tools/qualcomm/runtime.json +++ b/tools/qualcomm/runtime.json @@ -24,7 +24,7 @@ "mode": 420, "name": "libVkLayer_window_system_integration.so", "path": "wsi/libVkLayer_window_system_integration.so", - "sha256": "431bc41d8ccb4ae0f35b1aa76bb30770926159e3e3b045084910bf0da6bc6436", + "sha256": "5990b32d6e0ce8fe250214a6f07d71ebf6cfcc6f03c3a3c573495721510c5b3b", "size": 397384, "built": true }, @@ -109,6 +109,14 @@ "path": "licenses/wsi-patches/0004-acquire-next-image2-on-vulkan-1-0.patch", "sha256": "30e968889e22f3ba4ea2e0c3b80e3752c4d61898e256230392a0242d125ec239", "size": 1541 + }, + { + "built": true, + "mode": 420, + "name": "0005-optional-wayland-platform.patch", + "path": "licenses/wsi-patches/0005-optional-wayland-platform.patch", + "sha256": "ab634299e5a6f1156f4d435314c50c893c60a43e8a6726498c9a39109f5676e0", + "size": 5882 } ], "id": "wsi", diff --git a/tools/qualcomm/wsi-patches/0005-optional-wayland-platform.patch b/tools/qualcomm/wsi-patches/0005-optional-wayland-platform.patch new file mode 100644 index 0000000000..f80876fddb --- /dev/null +++ b/tools/qualcomm/wsi-patches/0005-optional-wayland-platform.patch @@ -0,0 +1,118 @@ +diff --git a/layer/surface_api.cpp b/layer/surface_api.cpp +index 119b9ce..de23905 100644 +--- a/layer/surface_api.cpp ++++ b/layer/surface_api.cpp +@@ -228,6 +228,12 @@ wsi_layer_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, + } + + *pSupported = queueFamilyIndex == instance.get_best_queue_family(physicalDevice); ++ wsi::surface_properties *props = wsi::get_surface_properties(instance, surface); ++ if (*pSupported && props != nullptr && ++ !wsi::device_supports_surface_platform(physicalDevice, *props, instance.api_version)) ++ { ++ *pSupported = VK_FALSE; ++ } + return VK_SUCCESS; + } + +diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp +index 0e53a1a..6abeecc 100644 +--- a/layer/swapchain_api.cpp ++++ b/layer/swapchain_api.cpp +@@ -59,6 +59,14 @@ wsi_layer_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR * + return device_data.disp.CreateSwapchainKHR(device_data.device, pSwapchainCreateInfo, pAllocator, pSwapchain); + } + ++ wsi::surface_properties *props = wsi::get_surface_properties(device_data.instance_data, surface); ++ if (props != nullptr && !wsi::device_supports_surface_platform(device_data.physical_device, *props, ++ device_data.instance_data.api_version)) ++ { ++ WSI_LOG_ERROR("The device lacks the extensions that swapchains on this surface require."); ++ return VK_ERROR_INITIALIZATION_FAILED; ++ } ++ + auto sc = wsi::allocate_surface_swapchain(surface, device_data, pAllocator); + if (sc == nullptr) + { +diff --git a/wsi/wsi_factory.cpp b/wsi/wsi_factory.cpp +index 53666be..8f9c856 100644 +--- a/wsi/wsi_factory.cpp ++++ b/wsi/wsi_factory.cpp +@@ -166,6 +166,37 @@ VkResult get_available_device_extensions(VkPhysicalDevice physical_device, util: + return VK_SUCCESS; + } + ++static void remove_optional_device_extensions(const util::extension_list &available, ++ util::extension_list &required) ++{ ++ /* Without DRM format modifiers, Wayland swapchains export driver-allocated LINEAR images instead. */ ++ if (!available.contains(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME)) ++ { ++ required.remove(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME); ++ } ++ /* Only VK_EXT_present_timing uses calibrated timestamps, and it checks its own dependencies. */ ++ if (!available.contains(VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) ++ { ++ required.remove(VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME); ++ } ++} ++ ++bool device_supports_surface_platform(VkPhysicalDevice phys_dev, surface_properties &props, ++ const uint32_t api_version) ++{ ++ util::allocator allocator{ layer::instance_private_data::get(phys_dev).get_allocator(), ++ VK_SYSTEM_ALLOCATION_SCOPE_COMMAND }; ++ util::extension_list available{ allocator }; ++ util::extension_list required{ allocator }; ++ if (get_available_device_extensions(phys_dev, available) != VK_SUCCESS || ++ props.get_required_device_extensions(required, api_version) != VK_SUCCESS) ++ { ++ return false; ++ } ++ remove_optional_device_extensions(available, required); ++ return available.contains(required); ++} ++ + VkResult add_device_extensions_required_by_layer(VkPhysicalDevice phys_dev, + const util::wsi_platform_set enabled_platforms, + util::extension_list &extensions_to_enable, const uint32_t api_version) +@@ -216,15 +247,18 @@ VkResult add_device_extensions_required_by_layer(VkPhysicalDevice phys_dev, + TRY_LOG(props->get_required_device_extensions(extensions_required_by_layer, api_version), + "Failed to acquire required device extensions"); + +- /* Without DRM format modifiers, Wayland swapchains export driver-allocated LINEAR images instead. */ +- if (!available_device_extensions.contains(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME)) +- { +- extensions_required_by_layer.remove(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME); +- } ++ remove_optional_device_extensions(available_device_extensions, extensions_required_by_layer); + + bool supported = available_device_extensions.contains(extensions_required_by_layer); + if (!supported) + { ++ /* Drivers without DMA-BUF export cannot back Wayland swapchains. Keep the device usable for the other ++ * platforms; Wayland surfaces then report no support and refuse swapchain creation on it. */ ++ if (wsi_ext.platform == VK_ICD_WSI_PLATFORM_WAYLAND) ++ { ++ WSI_LOG_WARNING("Wayland swapchains are unavailable on this device: required device extensions are missing."); ++ continue; ++ } + /* Can we accept failure? The layer unconditionally advertises support for this platform and the loader uses + * this information to enable its own support of the vkCreate*SurfaceKHR entrypoints. The rest of the Vulkan + * stack may not support this extension so we cannot blindly fall back to it. +diff --git a/wsi/wsi_factory.hpp b/wsi/wsi_factory.hpp +index e285765..70a3f64 100644 +--- a/wsi/wsi_factory.hpp ++++ b/wsi/wsi_factory.hpp +@@ -88,6 +88,11 @@ util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo * + */ + VkResult get_available_device_extensions(VkPhysicalDevice physical_device, util::extension_list &available_extensions); + ++/** ++ * @brief Whether @p phys_dev provides the device extensions that swapchains on @p props' platform require. ++ */ ++bool device_supports_surface_platform(VkPhysicalDevice phys_dev, surface_properties &props, uint32_t api_version); ++ + /** + * @brief Add extra extensions that the layer requires to support the specified list of enabled platforms. + * diff --git a/tools/tests/test_qualcomm_browser.py b/tools/tests/test_qualcomm_browser.py new file mode 100644 index 0000000000..c4f876ad9e --- /dev/null +++ b/tools/tests/test_qualcomm_browser.py @@ -0,0 +1,57 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + +SESSION = (Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session").read_text() +GATE = SESSION[SESSION.index("bl_qualcomm_browser_gpu() {"):SESSION.index("reap_orphans() {")] + + +class QualcommBrowserTest(unittest.TestCase): + def gate(self, glxinfo=None, **extra): + with tempfile.TemporaryDirectory() as directory: + env = dict(os.environ) + for name in ("DROIDDECK_SYSTEM_QUALCOMM", "BL_STEAM_CEF_SOFTWARE"): + env.pop(name, None) + if glxinfo is not None: + stub = Path(directory) / "glxinfo" + stub.write_text("#!/bin/sh\necho 'touched' > \"$0.ran\"\n" + glxinfo, newline="\n") + stub.chmod(0o755) + env["PATH"] = directory + os.pathsep + env["PATH"] + env.update(extra) + result = subprocess.run(["bash", "-c", GATE + "\nbl_qualcomm_browser_gpu; echo \"rc=$?\""], + env=env, capture_output=True, text=True) + ran = glxinfo is not None and (Path(directory) / "glxinfo.ran").exists() + return result.stdout.strip(), ran + + def test_zink_below_opengl_4_selects_software_compositing(self): + out, _ = self.gate("printf ' Max core profile version: 3.2\\n'\n", DROIDDECK_SYSTEM_QUALCOMM="1") + self.assertIn("browser software compositing (Zink offers OpenGL 3.2; GPU compositing needs 4.0)", out) + self.assertTrue(out.endswith("rc=1")) + + def test_zink_at_opengl_4_keeps_gpu_compositing(self): + out, _ = self.gate("printf ' Max core profile version: 4.6\\n'\n", DROIDDECK_SYSTEM_QUALCOMM="1") + self.assertIn("browser GPU compositing on (Zink OpenGL 4.6)", out) + self.assertTrue(out.endswith("rc=0")) + + def test_an_unreadable_version_selects_software_compositing(self): + out, _ = self.gate("exit 1\n", DROIDDECK_SYSTEM_QUALCOMM="1") + self.assertIn("Zink offers OpenGL unknown", out) + self.assertTrue(out.endswith("rc=1")) + + def test_an_explicit_override_and_other_drivers_skip_the_probe(self): + for extra in ({"DROIDDECK_SYSTEM_QUALCOMM": "1", "BL_STEAM_CEF_SOFTWARE": "0"}, + {"DROIDDECK_SYSTEM_QUALCOMM": "1", "BL_STEAM_CEF_SOFTWARE": "1"}, + {"DROIDDECK_SYSTEM_QUALCOMM": "0"}, {}): + with self.subTest(extra=extra): + out, ran = self.gate("printf ' Max core profile version: 3.2\\n'\n", **extra) + self.assertEqual(out, "rc=0") + self.assertFalse(ran) + + def test_the_steam_launch_applies_the_gate(self): + self.assertIn("bl_qualcomm_browser_gpu || steam_cef_gpu=0", SESSION) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_qualcomm_caps.py b/tools/tests/test_qualcomm_caps.py new file mode 100644 index 0000000000..54150f8a30 --- /dev/null +++ b/tools/tests/test_qualcomm_caps.py @@ -0,0 +1,39 @@ +from pathlib import Path +import runpy +import unittest + +CAPS = runpy.run_path(str(Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-qualcomm-caps")) +decide = CAPS["decide"] +REQUIRED = set(CAPS["REQUIRED"]) +CAPABLE = {"extensions": REQUIRED | {"VK_EXT_image_drm_format_modifier"}, "linear_export": True, + "linear_import": True, "export_fd": True, "gamescope_dmabuf": True} + + +class QualcommCapsTest(unittest.TestCase): + def test_a_driver_with_working_dma_buf_export_enables_zero_copy(self): + self.assertEqual(decide(CAPABLE), (True, [])) + + def test_adreno_740_without_dma_buf_keeps_shm(self): + extensions = REQUIRED - {"VK_EXT_external_memory_dma_buf"} + enabled, reasons = decide({"extensions": extensions, "gamescope_dmabuf": False}) + self.assertFalse(enabled) + self.assertEqual(reasons, ["missing VK_EXT_external_memory_dma_buf", "Gamescope offers no linux-dmabuf"]) + + def test_every_check_must_pass(self): + for key, reason in (("linear_export", "LINEAR DMA-BUF images are not exportable"), + ("linear_import", "LINEAR DMA-BUF images are not importable"), + ("export_fd", "DMA-BUF export failed"), + ("gamescope_dmabuf", "Gamescope offers no linux-dmabuf")): + with self.subTest(key=key): + self.assertEqual(decide(dict(CAPABLE, **{key: False})), (False, [reason])) + self.assertEqual(decide(dict(CAPABLE, export_fd=False, export_error="vkGetMemoryFdKHR failed (-1)")), + (False, ["vkGetMemoryFdKHR failed (-1)"])) + + def test_a_failed_probe_never_enables_zero_copy(self): + self.assertEqual(decide({"error": "vkCreateInstance returned -9"}), + (False, ["probe failed: vkCreateInstance returned -9"])) + self.assertFalse(decide({})[0]) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/tests/test_qualcomm_present.py b/tools/tests/test_qualcomm_present.py index aab23620bf..fe989349d8 100644 --- a/tools/tests/test_qualcomm_present.py +++ b/tools/tests/test_qualcomm_present.py @@ -8,22 +8,31 @@ BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin" COMPAT = runpy.run_path(str(BIN / "steam-compatibility")) SHOW = 'echo "DISABLE_GAMESCOPE_WSI=${DISABLE_GAMESCOPE_WSI-unset} WSI_X11_FORCE_SHM=${WSI_X11_FORCE_SHM-unset}"\n' SESSION_DEFAULT = "DISABLE_GAMESCOPE_WSI=1 WSI_X11_FORCE_SHM=1" +ZERO_COPY = "DISABLE_GAMESCOPE_WSI=unset WSI_X11_FORCE_SHM=unset" class QualcommPresentTest(unittest.TestCase): def present(self, **extra): env = dict(os.environ, DISABLE_GAMESCOPE_WSI="1", WSI_X11_FORCE_SHM="1") - env.pop("DROIDDECK_SYSTEM_QUALCOMM", None) - env.pop("BL_QUALCOMM_SHM", None) + for name in ("DROIDDECK_SYSTEM_QUALCOMM", "DROIDDECK_QUALCOMM_ZERO_COPY", "BL_QUALCOMM_SHM"): + env.pop(name, None) env.update(extra) script = COMPAT["BL_PRESENT_SETUP"] + "\nbl_present\n" + SHOW return subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True).stdout.strip() - def test_qualcomm_games_present_through_gamescope_wsi(self): - self.assertEqual(self.present(DROIDDECK_SYSTEM_QUALCOMM="1"), "DISABLE_GAMESCOPE_WSI=unset WSI_X11_FORCE_SHM=unset") + def test_qualcomm_games_present_zero_copy_when_the_probe_passed(self): + self.assertEqual(self.present(DROIDDECK_SYSTEM_QUALCOMM="1", DROIDDECK_QUALCOMM_ZERO_COPY="1"), ZERO_COPY) + + def test_drivers_without_a_passing_probe_keep_the_session_default(self): + for extra in ({"DROIDDECK_SYSTEM_QUALCOMM": "1"}, + {"DROIDDECK_SYSTEM_QUALCOMM": "1", "DROIDDECK_QUALCOMM_ZERO_COPY": "0"}, + {"DROIDDECK_SYSTEM_QUALCOMM": "1", "DROIDDECK_QUALCOMM_ZERO_COPY": ""}): + with self.subTest(extra=extra): + self.assertEqual(self.present(**extra), SESSION_DEFAULT) def test_turnip_sessions_and_the_shm_override_keep_the_session_default(self): - for extra in ({}, {"DROIDDECK_SYSTEM_QUALCOMM": "0"}, {"DROIDDECK_SYSTEM_QUALCOMM": "1", "BL_QUALCOMM_SHM": "1"}): + for extra in ({}, {"DROIDDECK_SYSTEM_QUALCOMM": "0", "DROIDDECK_QUALCOMM_ZERO_COPY": "1"}, + {"DROIDDECK_SYSTEM_QUALCOMM": "1", "DROIDDECK_QUALCOMM_ZERO_COPY": "1", "BL_QUALCOMM_SHM": "1"}): with self.subTest(extra=extra): self.assertEqual(self.present(**extra), SESSION_DEFAULT) @@ -37,6 +46,14 @@ class QualcommPresentTest(unittest.TestCase): for index in launches: self.assertIn("bl_present", lines[max(0, index - 6):index]) + def test_the_qualcomm_session_exports_the_probe_result(self): + session = (BIN / "droiddeck-session").read_text() + block = session[session.index('if [ "${DROIDDECK_SYSTEM_QUALCOMM:-0}" = 1 ]; then\n export VK_LAYER_PATH'):] + block = block[:block.index("\nfi\n")] + self.assertIn("DROIDDECK_QUALCOMM_ZERO_COPY=0", block) + self.assertIn("droiddeck-qualcomm-caps", block) + self.assertIn("export DROIDDECK_QUALCOMM_ZERO_COPY", block) + if __name__ == "__main__": unittest.main()