From 57643730605c9092a14bcdec7137324a77f76d2e Mon Sep 17 00:00:00 2001 From: K11MCH1 <81425424+K11MCH1@users.noreply.github.com> Date: Sat, 24 Oct 2026 09:17:12 +0900 Subject: [PATCH] Fix accelerated Qualcomm browser pixmaps without X11 DRI3 (cherry picked from commit b2b033d675a04d201eb07672b57a93ec1983d86f) --- tools/qualcomm/README.md | 20 +++- tools/qualcomm/build_zink.py | 12 +- tools/qualcomm/pixmap_probe.c | 113 ++++++++++++++++++ tools/qualcomm/runtime.json | 13 +- tools/qualcomm/zink-pixmap-without-dri3.patch | 50 ++++++++ 5 files changed, 197 insertions(+), 11 deletions(-) create mode 100644 tools/qualcomm/pixmap_probe.c create mode 100644 tools/qualcomm/zink-pixmap-without-dri3.patch diff --git a/tools/qualcomm/README.md b/tools/qualcomm/README.md index c3f9120c9..ec80b8ba3 100644 --- a/tools/qualcomm/README.md +++ b/tools/qualcomm/README.md @@ -16,14 +16,28 @@ The import's metadata advertises Vulkan **1.4.359**, but this device's Linux Vul ## Steam browser hardware-rendering investigation -Games, Gamescope and Android presentation use Vulkan hardware acceleration. Experimental builds now also use Steam's regular GPU-enabled browser launch path for both system and imported Qualcomm drivers. This is a shared backend default with no GPU-model allowlist. The helper's `SDL_FRAMEBUFFER_ACCELERATION=0` workaround remains scoped to its SDL window surface; it does not disable Chromium GPU compositing. Browser rendering correctness is not yet established. +Games, Gamescope and Android presentation use Vulkan hardware acceleration. Experimental builds also use Steam's regular GPU-enabled browser launch path for both system and imported Qualcomm drivers. This is a shared backend default with no GPU-model allowlist. The helper's `SDL_FRAMEBUFFER_ACCELERATION=0` workaround remains scoped to its SDL window surface; it does not disable Chromium GPU compositing. The Adreno 840 browser verification and remaining limits are described below. -Earlier RedMagic 11 Pro/v891.7 trials on 2026-10-24 failed to produce a stable hardware-rendered Steam UI. They tried ANGLE Vulkan and OpenGL/Zink, explicit Chromium backend switches, removing the in-process GPU switch, and removing the SDL workaround. The browser restarted or exited; logs include command-buffer creation and X11 connection errors. Those trials preceded the private Mesa integration. Evidence remains in ignored `build/research/qualcomm/cef-gpu-*` and `cef-trial-*`, device sessions `2026-10-24-04-steam` through `2026-10-24-08-steam`. The current components still require retesting on Adreno 840. Chromium/ANGLE switches are documented in [ANGLE debugging tips](https://github.com/google/angle/blob/main/doc/DebuggingTips.md). +Earlier RedMagic 11 Pro/v891.7 trials on 2026-10-24 failed to produce a stable hardware-rendered Steam UI. They tried ANGLE Vulkan and OpenGL/Zink, explicit Chromium backend switches, removing the in-process GPU switch, and removing the SDL workaround. The browser restarted or exited; logs include command-buffer creation and X11 connection errors. Those trials preceded the private Mesa integration. Evidence remains in ignored `build/research/qualcomm/cef-gpu-*` and `cef-trial-*`, device sessions `2026-10-24-04-steam` through `2026-10-24-08-steam`. Chromium/ANGLE switches are documented in [ANGLE debugging tips](https://github.com/google/angle/blob/main/doc/DebuggingTips.md). 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. 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 + +The subsequent Adreno 840/v891.7 test APK failed during browser startup. Tracing isolated `xcb_dri3_buffer_from_pixmap` from Mesa's Kopper texture-from-pixmap path: the GPU supports DMA-BUF, but the nested X11 server does not advertise DRI3. XCB closed that connection with `XCB_CONN_CLOSED_EXT_NOTSUPPORTED`, causing the later `Fatal IO error 11` in `XGetWindowAttributes`. Gamescope faulted after Steam exited. Disabling GL threading did not help. Forcing ANGLE Vulkan instead failed with `EGL_BAD_CONFIG`. + +`zink-pixmap-without-dri3.patch` checks both GPU DMA-BUF capability and the server's DRI3 extension before pixmap import. When import is unavailable, it allocates a normal GPU texture and uses Mesa's existing pixmap pixel-copy update path. Other GPU rendering remains accelerated. No X11 extension or Vulkan capability is fabricated. The check is shared across GPU models and both Qualcomm driver sources. + +Verification on RedMagic 11 Pro/Adreno 840 with the imported v891.7 driver: + +- `pixmap_probe.c` binds a 17×9 X11 pixmap to a GPU texture, checks two different image contents and verifies all 306 GPU readback pixels on a server without DRI3. The original libraries returned black pixels; the patched libraries pass. Build it with `cc -O2 pixmap_probe.c -o pixmap-probe -lGL -lX11`, then run inside the selected Qualcomm session. +- Steam reaches its visible library, opens its main menu and survives a session restart. Device sessions are `2026-10-24-29-pixmap-probe`, `2026-10-24-30-steam` and `2026-10-24-31-steam`. +- Chromium `SystemInfo.getInfo` reports GPU compositing and rasterization enabled. Its renderer is `ANGLE (Mesa, zink Vulkan 1.3(Adreno (TM) 840 (QUALCOMM_PROPRIETARY)), OpenGL 4.6 (Core Profile) Mesa 26.2.3)`; WebGL independently reports the same hardware path. No software-browser override or tracing preload is used. + +Evidence is retained under ignored `build/research/qualcomm/adreno840`. The earlier Adreno 740 corruption requires retesting with this patch; this result does not validate every Adreno model, driver version or game. + `runtime.json` pins the downloaded bridge and WSI archives, the locally built private Gamescope binary and corresponding source archive, and every private Mesa runtime file. `fetch_runtime.py` checks these pins before Gradle stages them. Missing local build outputs fail the build. Qualcomm's proprietary device libraries are loaded from the phone and are not included in these archives. The bridge archive includes its licenses, source snapshot and patches. The same lock pins a vendor-neutral X11 WSI layer and upstream Gamescope shader source. `build_shaders.py` applies `constant-yuv-samplers.patch` and builds six replacement SPIR-V modules with the configured NDK's `glslc`. It builds a small ARM64 glibc Vulkan layer using the NDK compiler without Android runtime linkage. The layer matches the six original Gamescope module fingerprints before substituting a shader; ordinary applications use the WSI/compatibility layers instead. Source archives, patches and licenses are packaged with the runtime. The patch can also be applied during a full Gamescope source build. @@ -43,7 +57,7 @@ The connected vivo V2243A/SM8550 reports Adreno 740, proprietary Qualcomm 0.676. Mesa 26.2.3 made maintenance5 mandatory for Zink. `zink-optional-maintenance5.patch` restores the earlier optional extension check, preserves point-size shader stores without that feature, and omits the maintenance5 buffer-view usage structure when unsupported. The private build uses the same Mesa release as the installed runtime, exposes a distinct GLVND vendor, and includes only Zink as its Gallium driver. `qualcomm-gl.sh` selects its libraries for applications and Mangoapp in Qualcomm sessions. It does not change the Vulkan device's reported features or enable software rendering. This does not establish full OpenGL conformance or game compatibility. -Hardware verification on 2026-10-24 installed the full-runtime development APK and reached the visible Steam Big Picture library on this Adreno 740. Steam and Gamescope mapped `/vendor/lib64/hw/vulkan.adreno.so` through the bridge; Steam also mapped the private GLX vendor and `libgallium-26.2.3.so`. `egl_probe.c` reported **OpenGL 3.2 Compatibility Profile**, rendered a triangle through `zink Vulkan 1.3(Adreno (TM) 740 (QUALCOMM_PROPRIETARY))`, and verified all 256 readback pixels. Evidence is under ignored `build/research/qualcomm/adreno740`, initially device session `2026-10-24-05-steam`, followed by the browser GPU trial described above. Games have not been verified on this phone, and the newly rebuilt components have not yet been retested on Adreno 840. +Hardware verification on 2026-10-24 installed the full-runtime development APK and reached the visible Steam Big Picture library on this Adreno 740. Steam and Gamescope mapped `/vendor/lib64/hw/vulkan.adreno.so` through the bridge; Steam also mapped the private GLX vendor and `libgallium-26.2.3.so`. `egl_probe.c` reported **OpenGL 3.2 Compatibility Profile**, rendered a triangle through `zink Vulkan 1.3(Adreno (TM) 740 (QUALCOMM_PROPRIETARY))`, and verified all 256 readback pixels. Evidence is under ignored `build/research/qualcomm/adreno740`, initially device session `2026-10-24-05-steam`, followed by the browser GPU trial described above. Games have not been verified on this phone. The later DRI3 pixmap fix has been verified on Adreno 840 as described above, but not yet on this Adreno 740. Build the private components on ARM64 Linux with their normal development dependencies (GCC/C++, Meson, Ninja, pkg-config, Wayland/X11/SDL2 headers, Vulkan headers, glslang, and Mesa's Python Mako/packaging/PyYAML, Flex and Bison requirements): diff --git a/tools/qualcomm/build_zink.py b/tools/qualcomm/build_zink.py index 8481aa41c..bf0b8680a 100644 --- a/tools/qualcomm/build_zink.py +++ b/tools/qualcomm/build_zink.py @@ -1,4 +1,4 @@ -"""Build private ARM64 Zink libraries with the pre-maintenance5 fallback.""" +"""Build private ARM64 Zink libraries with Qualcomm and X11 compatibility fixes.""" import argparse import hashlib import json @@ -9,6 +9,7 @@ import subprocess ROOT = Path(__file__).resolve().parents[2] HERE = Path(__file__).resolve().parent REVISION = '31e9a6b2e95e30d84bf3177d1f497d063e59b6b2' +PATCHES = ('zink-optional-maintenance5.patch', 'zink-pixmap-without-dri3.patch') OPTIONS = ['-Dbuildtype=release', '-Dgallium-drivers=zink', '-Dvulkan-drivers=[]', '-Dllvm=disabled', '-Dplatforms=x11,wayland', '-Dglvnd=enabled', '-Dglvnd-vendor-name=droiddeck_qualcomm', '-Dgallium-va=disabled', @@ -34,7 +35,8 @@ def prepare(source): run(['git', 'remote', 'add', 'origin', 'https://gitlab.freedesktop.org/mesa/mesa.git'], source) run(['git', 'fetch', '--depth', '1', 'origin', REVISION], source) run(['git', 'checkout', '--detach', 'FETCH_HEAD'], source) - run(['git', 'apply', HERE / 'zink-optional-maintenance5.patch'], source) + for patch in PATCHES: + run(['git', 'apply', HERE / patch], source) def package(source, output, strip_tool): output.mkdir(parents=True, exist_ok=True) @@ -48,11 +50,13 @@ def package(source, output, strip_tool): shutil.copyfile(HERE / 'qualcomm-gl.sh', output / 'qualcomm-gl.sh') shutil.copytree(source / 'licenses', output / 'licenses', dirs_exist_ok=True) shutil.copyfile(source / 'docs/license.rst', output / 'licenses/Mesa-license.rst') - shutil.copyfile(HERE / 'zink-optional-maintenance5.patch', output / 'licenses/zink-optional-maintenance5.patch') + for patch in PATCHES: + shutil.copyfile(HERE / patch, output / 'licenses' / patch) (output / 'licenses/source.json').write_text(json.dumps({ 'url': 'https://gitlab.freedesktop.org/mesa/mesa/-/tree/' + REVISION, 'source_commit': REVISION, 'options': OPTIONS, - 'patch_sha256': hashlib.sha256((HERE / 'zink-optional-maintenance5.patch').read_bytes()).hexdigest()}, indent=2) + '\n') + 'patches': [{'path': patch, 'sha256': hashlib.sha256((HERE / patch).read_bytes()).hexdigest()} + for patch in PATCHES]}, indent=2) + '\n') files = [{'path': p.relative_to(output).as_posix(), 'sha256': hashlib.sha256(p.read_bytes()).hexdigest(), 'size': p.stat().st_size} for p in sorted(output.rglob('*')) if p.is_file() and p.name != 'build.json'] (output / 'build.json').write_text(json.dumps({'source_commit': REVISION, 'files': files}, indent=2) + '\n') diff --git a/tools/qualcomm/pixmap_probe.c b/tools/qualcomm/pixmap_probe.c new file mode 100644 index 000000000..01b96b899 --- /dev/null +++ b/tools/qualcomm/pixmap_probe.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include + +int main(void) +{ + XInitThreads(); + Display *display = XOpenDisplay(NULL); + int opcode, event, error; + if (!display || XQueryExtension(display, "DRI3", &opcode, &event, &error)) { + fprintf(stderr, "This probe requires an X11 server without DRI3\n"); + return 1; + } + const int attributes[] = { + GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_BIND_TO_TEXTURE_RGB_EXT, True, + GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, None + }; + int count; + GLXFBConfig *configs = glXChooseFBConfig(display, DefaultScreen(display), attributes, &count); + XVisualInfo *visual = NULL; + GLXFBConfig config = NULL; + for (int i = 0; configs && i < count; ++i) { + visual = glXGetVisualFromFBConfig(display, configs[i]); + if (visual && visual->depth == 24) { + config = configs[i]; + break; + } + if (visual) XFree(visual); + visual = NULL; + } + if (!config) return 1; + const int width = 17, height = 9; + Colormap colormap = XCreateColormap(display, RootWindow(display, visual->screen), visual->visual, AllocNone); + XSetWindowAttributes window_attributes = { .colormap = colormap }; + Window output = XCreateWindow(display, RootWindow(display, visual->screen), 0, 0, width, height, + 0, visual->depth, InputOutput, visual->visual, CWColormap, &window_attributes); + XMapWindow(display, output); + XSync(display, False); + GLXContext context = glXCreateNewContext(display, config, GLX_RGBA_TYPE, NULL, True); + if (!context || !glXMakeContextCurrent(display, output, output, context)) return 1; + const char *renderer = (const char *)glGetString(GL_RENDERER); + printf("Renderer: %s\n", renderer ? renderer : "unknown"); + if (!renderer || !strstr(renderer, "zink") || !strstr(renderer, "Adreno")) return 1; + Pixmap pixmap = XCreatePixmap(display, RootWindow(display, visual->screen), width, height, visual->depth); + GC gc = XCreateGC(display, pixmap, 0, NULL); + const int texture_attributes[] = { + GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, + GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, None + }; + GLXPixmap texture_pixmap = glXCreatePixmap(display, config, pixmap, texture_attributes); + PFNGLXBINDTEXIMAGEEXTPROC bind = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXBindTexImageEXT"); + PFNGLXRELEASETEXIMAGEEXTPROC release = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddressARB((const GLubyte *)"glXReleaseTexImageEXT"); + if (!texture_pixmap || !bind || !release) { + fprintf(stderr, "GLX pixmap setup failed\n"); + return 1; + } + GLuint texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glEnable(GL_TEXTURE_2D); + glDisable(GL_DITHER); + glViewport(0, 0, width, height); + for (int phase = 0; phase < 2; ++phase) { + XSetForeground(display, gc, phase ? visual->blue_mask : visual->red_mask); + XFillRectangle(display, pixmap, gc, 0, 0, 8, height); + XSetForeground(display, gc, phase ? visual->red_mask | visual->green_mask : visual->green_mask); + XFillRectangle(display, pixmap, gc, 8, 0, width - 8, height); + XSync(display, False); + bind(display, texture_pixmap, GLX_FRONT_LEFT_EXT, NULL); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2f(-1, -1); + glTexCoord2f(1, 0); glVertex2f(1, -1); + glTexCoord2f(1, 1); glVertex2f(1, 1); + glTexCoord2f(0, 1); glVertex2f(-1, 1); + glEnd(); + unsigned char pixels[17 * 9 * 4]; + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + if (glGetError() != GL_NO_ERROR) return 1; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + unsigned char *pixel = &pixels[(y * width + x) * 4]; + int red = phase ? x >= 8 : x < 8; + int green = x >= 8; + int blue = phase && x < 8; + if (pixel[0] != red * 255 || pixel[1] != green * 255 || pixel[2] != blue * 255 || pixel[3] != 255) { + fprintf(stderr, "Phase %d pixel %d,%d: %u %u %u %u\n", phase, x, y, pixel[0], pixel[1], pixel[2], pixel[3]); + return 1; + } + } + } + release(display, texture_pixmap, GLX_FRONT_LEFT_EXT); + } + puts("Pixmap bind/update: all 306 GPU readback pixels passed without DRI3"); + glXDestroyPixmap(display, texture_pixmap); + XFreeGC(display, gc); + XFreePixmap(display, pixmap); + glDeleteTextures(1, &texture); + glXMakeContextCurrent(display, None, None, NULL); + glXDestroyContext(display, context); + XDestroyWindow(display, output); + XFreeColormap(display, colormap); + XFree(visual); + XFree(configs); + XCloseDisplay(display); + return 0; +} diff --git a/tools/qualcomm/runtime.json b/tools/qualcomm/runtime.json index cbc03d47f..6c0568fd4 100644 --- a/tools/qualcomm/runtime.json +++ b/tools/qualcomm/runtime.json @@ -142,8 +142,8 @@ }, { "path": "libgallium-26.2.3.so", - "sha256": "bcda320860b051725ca49fd546937cc6512373bc21ce0d1e7f9c097341f3e9bc", - "size": 21578336 + "sha256": "c2367279e61cad9d2fa16ff1bc247b565ff86e38f5a6b6aff5e63c5f1607e869", + "size": 21578352 }, { "path": "libgbm.so.1", @@ -197,14 +197,19 @@ }, { "path": "licenses/source.json", - "sha256": "6bb1d1549c264228466853656258f1e3c6822c2bf314260e4900cd0eed3a393c", - "size": 658 + "sha256": "699c0d6096f573cb768ae2e3f625a65a34fef8cebb618f6a611d0f8b6ced787a", + "size": 890 }, { "path": "licenses/zink-optional-maintenance5.patch", "sha256": "25f0733bc42199344f205a916f6674d578a9a78250fd6b4cecbfb1cbbc8f8cf5", "size": 1682 }, + { + "path": "licenses/zink-pixmap-without-dri3.patch", + "sha256": "8a0b0480be2823cc5df2bb5510c2f39a1402da9cb9199602d7bf691c5c486100", + "size": 1907 + }, { "path": "qualcomm-gl.sh", "sha256": "2ed84bb2a5fa20cde52f18733fe3e8d1fda22f3f0d0bdad47363ff71a04522f5", diff --git a/tools/qualcomm/zink-pixmap-without-dri3.patch b/tools/qualcomm/zink-pixmap-without-dri3.patch new file mode 100644 index 000000000..72a9b579f --- /dev/null +++ b/tools/qualcomm/zink-pixmap-without-dri3.patch @@ -0,0 +1,50 @@ +--- a/src/gallium/frontends/dri/kopper.c ++++ b/src/gallium/frontends/dri/kopper.c +@@ -43,6 +43,7 @@ + + #ifdef VK_USE_PLATFORM_XCB_KHR + #include ++#include + #include + #include + #include +@@ -97,6 +98,15 @@ + unsigned statts_count); + + #ifdef VK_USE_PLATFORM_XCB_KHR ++static bool ++kopper_has_dri3(struct dri_drawable *drawable) ++{ ++ VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&drawable->info.bos; ++ const xcb_query_extension_reply_t *extension = ++ xcb_get_extension_data(xcb->connection, &xcb_dri3_id); ++ return extension && extension->present; ++} ++ + /* Translate from the pipe_format enums used by Gallium to the DRM FourCC + * codes used by dmabuf import */ + static int +@@ -321,7 +331,8 @@ + drawable->window_valid = !!drawable->textures[statts[i]]; + } + #ifdef VK_USE_PLATFORM_XCB_KHR +- else if (is_pixmap && statts[i] == ST_ATTACHMENT_FRONT_LEFT && !screen->is_sw) { ++ else if (is_pixmap && statts[i] == ST_ATTACHMENT_FRONT_LEFT && ++ screen->has_dmabuf && kopper_has_dri3(drawable)) { + drawable->textures[statts[i]] = kopper_get_pixmap_buffer(drawable, format); + if (drawable->textures[statts[i]]) + dri_image_fence_sync(ctx, drawable->image); +@@ -451,8 +462,12 @@ + struct pipe_resource *res) + { + struct dri_screen *screen = drawable->screen; +- if (screen->has_dmabuf || drawable->is_window || drawable->info.bos.sType != VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR) ++ if (drawable->is_window || drawable->info.bos.sType != VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR) + return; ++#ifdef VK_USE_PLATFORM_XCB_KHR ++ if (screen->has_dmabuf && kopper_has_dri3(drawable)) ++ return; ++#endif + drisw_update_tex_buffer(drawable, ctx, res); + } +