From 0c17ab1aa548c3e1f39398ce8a8af375e45dfaeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Sun, 15 Nov 2026 00:25:03 +0800 Subject: [PATCH 1/3] GPU probe: draw one frame's worth before the desktop leaves software A small program the login session can run before it starts Labwc on the GPU: it opens EGL on the GPU's render node, draws into a buffer and reads it back, and exits 0 only if that worked. Taken from the probe of omarchy-a PR #44 (commit 3c13c74e922b, "Desktop: matched G5P Vulkan and GL, hardware desktop after a probe", desktop/packages/mesa-g5p-orchard/gpu-probe.c) and adapted to the one GPU path every board takes, the system Mesa with Zink on the powervr Vulkan driver: - It follows that path's buffer flow: the output buffer is allocated on the GPU and handed to the display controller (prime import, AddFB2), as wlroots does, and has the panel's size instead of 32x32, because the display controller's import depends on how the memory is laid out. The original allocated on the display card and imported into the GPU, the flow of the separate Mesa in /opt. - EGL is opened as wlroots opens it (the EGL device of the render node, then GBM), with no EGL config. - It draws a quad through a shader after the clear, and refuses a software renderer by name instead of requiring "PowerVR". - It gives up DRM master on the display card at once, so that a stuck probe cannot keep Labwc from the display. - It lives next to the Vulkan driver's recipe; nothing builds it yet. Compiled in the desktop builder image; not run on a GPU. Assisted-by: LLM --- .../vulkan-powervr-orchard/gpu-probe.c | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 desktop/packages/vulkan-powervr-orchard/gpu-probe.c diff --git a/desktop/packages/vulkan-powervr-orchard/gpu-probe.c b/desktop/packages/vulkan-powervr-orchard/gpu-probe.c new file mode 100644 index 00000000..f315fe4e --- /dev/null +++ b/desktop/packages/vulkan-powervr-orchard/gpu-probe.c @@ -0,0 +1,214 @@ +/* SPDX-License-Identifier: MIT + * Generated-by: LLM + * + * gpu-probe RENDER-NODE DISPLAY-CARD + * + * Does what Labwc's GLES2 renderer does for one frame, without modesetting: + * opens EGL on the render node, allocates one output buffer of the display's + * size there, draws into it, reads it back, and hands the buffer to the + * display controller as a framebuffer. Exits 0 only if all of that worked and + * the renderer is not a software one. The caller bounds the run time and sets + * the environment the desktop would run with. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CHECK(x) do { if (!(x)) { fprintf(stderr, "GPU-PROBE FAIL: %s\n", #x); return 1; } } while (0) + +static const EGLint context_attrs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + +/* wlroots' order: the EGL device that is this DRM node, then GBM. */ +static EGLContext open_egl(int render, struct gbm_device *gbm, int use_device, EGLDisplay *dpy) +{ + *dpy = EGL_NO_DISPLAY; + if (use_device) { + const char *client = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); + if (!client || !strstr(client, "EGL_EXT_device_enumeration") || !strstr(client, "EGL_EXT_platform_device")) + return EGL_NO_CONTEXT; + PFNEGLQUERYDEVICESEXTPROC devices = (void *)eglGetProcAddress("eglQueryDevicesEXT"); + PFNEGLQUERYDEVICESTRINGEXTPROC string = (void *)eglGetProcAddress("eglQueryDeviceStringEXT"); + drmDevice *node = NULL; + EGLDeviceEXT list[16]; + EGLint count = 0; + if (!devices || !string || drmGetDevice2(render, 0, &node) || !devices(16, list, &count)) return EGL_NO_CONTEXT; + for (EGLint i = 0; i < count && *dpy == EGL_NO_DISPLAY; i++) { + const char *extensions = string(list[i], EGL_EXTENSIONS); + const char *file = extensions && strstr(extensions, "EGL_EXT_device_drm") ? + string(list[i], EGL_DRM_DEVICE_FILE_EXT) : NULL; + for (int n = 0; file && n < DRM_NODE_MAX; n++) + if ((node->available_nodes & (1 << n)) && !strcmp(node->nodes[n], file)) + *dpy = eglGetPlatformDisplay(EGL_PLATFORM_DEVICE_EXT, list[i], NULL); + } + drmFreeDevice(&node); + } else { + *dpy = eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR, gbm, NULL); + } + if (*dpy == EGL_NO_DISPLAY || !eglInitialize(*dpy, NULL, NULL)) return EGL_NO_CONTEXT; + EGLContext ctx = EGL_NO_CONTEXT; + if (eglBindAPI(EGL_OPENGL_ES_API)) ctx = eglCreateContext(*dpy, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, context_attrs); + if (ctx != EGL_NO_CONTEXT && !eglMakeCurrent(*dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) { + eglDestroyContext(*dpy, ctx); + ctx = EGL_NO_CONTEXT; + } + if (ctx == EGL_NO_CONTEXT) eglTerminate(*dpy); + return ctx; +} + +static GLuint shader(GLenum type, const char *source) +{ + GLuint id = glCreateShader(type); + GLint ok = 0; + glShaderSource(id, 1, &source, NULL); + glCompileShader(id); + glGetShaderiv(id, GL_COMPILE_STATUS, &ok); + return ok ? id : 0; +} + +int main(int argc, char **argv) +{ + CHECK(argc == 3); + int render = open(argv[1], O_RDWR | O_CLOEXEC); + int kms = open(argv[2], O_RDWR | O_CLOEXEC); + CHECK(render >= 0 && kms >= 0); + /* The first to open a card becomes its DRM master. Nothing here needs + * that, and Labwc must get it even if this process were to get stuck. */ + drmDropMaster(kms); + + /* The size Labwc's output buffers will have: the panel's mode. */ + uint32_t width = 0, height = 0; + drmModeRes *resources = drmModeGetResources(kms); + for (int i = 0; resources && i < resources->count_connectors && !width; i++) { + drmModeConnector *connector = drmModeGetConnectorCurrent(kms, resources->connectors[i]); + if (connector && connector->connection == DRM_MODE_CONNECTED && connector->count_modes > 0) { + width = connector->modes[0].hdisplay; + height = connector->modes[0].vdisplay; + } + drmModeFreeConnector(connector); + } + drmModeFreeResources(resources); + if (!width || !height) { width = 2048; height = 1536; } + + struct gbm_device *gbm = gbm_create_device(render); + CHECK(gbm); + EGLDisplay dpy; + const char *platform = "device"; + EGLContext ctx = open_egl(render, gbm, 1, &dpy); + if (ctx == EGL_NO_CONTEXT) { platform = "gbm"; ctx = open_egl(render, gbm, 0, &dpy); } + CHECK(ctx != EGL_NO_CONTEXT); + const char *renderer = (const char *)glGetString(GL_RENDERER); + CHECK(renderer); + if (!strstr(renderer, "zink") || strstr(renderer, "llvmpipe") || strstr(renderer, "softpipe")) { + fprintf(stderr, "GPU-PROBE FAIL: not Zink on a GPU: renderer=%s\n", renderer); + return 1; + } + + /* The output buffer, allocated on the GPU as wlroots' GBM allocator does. */ + struct gbm_bo *bo = gbm_bo_create(gbm, width, height, GBM_FORMAT_XRGB8888, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + if (!bo) { + const uint64_t linear = DRM_FORMAT_MOD_LINEAR; + bo = gbm_bo_create_with_modifiers2(gbm, width, height, GBM_FORMAT_XRGB8888, &linear, 1, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + } + CHECK(bo); + int dma = gbm_bo_get_fd(bo); + CHECK(dma >= 0); + uint64_t modifier = gbm_bo_get_modifier(bo); + uint32_t stride = gbm_bo_get_stride(bo); + const char *egl_extensions = eglQueryString(dpy, EGL_EXTENSIONS); + CHECK(egl_extensions && strstr(egl_extensions, "EGL_EXT_image_dma_buf_import")); + EGLint ia[32], n = 0; + ia[n++] = EGL_WIDTH; ia[n++] = (EGLint)width; + ia[n++] = EGL_HEIGHT; ia[n++] = (EGLint)height; + ia[n++] = EGL_LINUX_DRM_FOURCC_EXT; ia[n++] = GBM_FORMAT_XRGB8888; + ia[n++] = EGL_DMA_BUF_PLANE0_FD_EXT; ia[n++] = dma; + ia[n++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; ia[n++] = 0; + ia[n++] = EGL_DMA_BUF_PLANE0_PITCH_EXT; ia[n++] = (EGLint)stride; + if (modifier != DRM_FORMAT_MOD_INVALID && strstr(egl_extensions, "EGL_EXT_image_dma_buf_import_modifiers")) { + ia[n++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT; ia[n++] = (EGLint)(modifier & 0xffffffff); + ia[n++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT; ia[n++] = (EGLint)(modifier >> 32); + } + ia[n] = EGL_NONE; + PFNEGLCREATEIMAGEKHRPROC create = (void *)eglGetProcAddress("eglCreateImageKHR"); + PFNEGLDESTROYIMAGEKHRPROC destroy = (void *)eglGetProcAddress("eglDestroyImageKHR"); + PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC storage = + (void *)eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES"); + CHECK(create && destroy && storage); + EGLImageKHR image = create(dpy, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, ia); + CHECK(image != EGL_NO_IMAGE_KHR); + GLuint rb, fb; + glGenRenderbuffers(1, &rb); glBindRenderbuffer(GL_RENDERBUFFER, rb); + storage(GL_RENDERBUFFER, image); + glGenFramebuffers(1, &fb); glBindFramebuffer(GL_FRAMEBUFFER, fb); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb); + CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); + + /* A clear, then geometry through a shader: a desktop is drawn quads. */ + glViewport(0, 0, (GLsizei)width, (GLsizei)height); + glClearColor(1, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); + GLuint vs = shader(GL_VERTEX_SHADER, "attribute vec2 p; void main() { gl_Position = vec4(p, 0.0, 1.0); }"); + GLuint fs = shader(GL_FRAGMENT_SHADER, "void main() { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); }"); + CHECK(vs && fs); + GLuint program = glCreateProgram(); + GLint linked = 0; + glAttachShader(program, vs); glAttachShader(program, fs); + glBindAttribLocation(program, 0, "p"); + glLinkProgram(program); + glGetProgramiv(program, GL_LINK_STATUS, &linked); + CHECK(linked); + static const GLfloat quad[] = {-1, -1, 1, -1, -1, 1, 1, 1}; + glUseProgram(program); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, quad); + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + unsigned char pixel[4] = {0}; + glReadPixels((GLint)width / 2, (GLint)height / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); + CHECK(glGetError() == GL_NO_ERROR); + if (pixel[0] > 5 || pixel[1] < 250 || pixel[2] > 5) { + fprintf(stderr, "GPU-PROBE FAIL: drew green, read back %u,%u,%u\n", pixel[0], pixel[1], pixel[2]); + return 1; + } + + /* The display controller must take the buffer, as at Labwc's first commit. */ + uint32_t handle = 0, fb_id = 0, handles[4] = {0}, pitches[4] = {0}, offsets[4] = {0}; + uint64_t modifiers[4] = {0}, addfb2_modifiers = 0; + if (drmPrimeFDToHandle(kms, dma, &handle)) { + fprintf(stderr, "GPU-PROBE FAIL: the display controller cannot import a GPU buffer: %m\n"); + return 1; + } + handles[0] = handle; pitches[0] = stride; modifiers[0] = modifier; + int added = -1; + if (modifier != DRM_FORMAT_MOD_INVALID && !drmGetCap(kms, DRM_CAP_ADDFB2_MODIFIERS, &addfb2_modifiers) && + addfb2_modifiers) + added = drmModeAddFB2WithModifiers(kms, width, height, DRM_FORMAT_XRGB8888, handles, pitches, offsets, + modifiers, &fb_id, DRM_MODE_FB_MODIFIERS); + if (added) added = drmModeAddFB2(kms, width, height, DRM_FORMAT_XRGB8888, handles, pitches, offsets, &fb_id, 0); + if (added) added = drmModeAddFB(kms, width, height, 24, 32, stride, handle, &fb_id); + if (added) { + fprintf(stderr, "GPU-PROBE FAIL: the display controller cannot scan out a GPU buffer: %m\n"); + return 1; + } + drmModeRmFB(kms, fb_id); + drmCloseBufferHandle(kms, handle); + + printf("GPU-PROBE PASS renderer=%s egl=%s size=%ux%u render=%s display=%s\n", renderer, platform, + width, height, argv[1], argv[2]); + glDeleteProgram(program); glDeleteShader(vs); glDeleteShader(fs); + glDeleteFramebuffers(1, &fb); glDeleteRenderbuffers(1, &rb); destroy(dpy, image); + close(dma); gbm_bo_destroy(bo); + eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(dpy, ctx); eglTerminate(dpy); + gbm_device_destroy(gbm); close(kms); close(render); + return 0; +} From ffb0eae07f6437f0353500bbfd2a056f0484b04d Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sun, 15 Nov 2026 00:28:29 +0800 Subject: [PATCH 2/3] Desktop: GPU or software per boot, decided by a test frame, on every board The login session chose the GPU desktop wherever the powervr kernel driver had a render node and the image had the Vulkan driver. That was safe while only the A10 had the kernel driver. With the A9 in the same kernel driver (orchard PR #138) a bound driver no longer says that the desktop can draw: Mesa has to speak the chip's job format and the display controller has to take the GPU's buffers. The session now runs gpu-probe first, with the environment the desktop would get (Zink on the powervr Vulkan driver, the system Mesa). If the probe draws its frame, the session exports exactly what it exported before; an A10 board ends up as it did. If the probe fails, crashes or has not ended after 10 s, the desktop starts in software. The session polls the probe instead of waiting on it, so a probe stuck in the kernel cannot hold the login. One line per login goes to the journal (journalctl -t omarchy-gpu-probe): the decision and the probe's reason. There is no board or chip name in this: the A9 takes the A10's path as soon as kernel and Mesa carry it. A board without a powervr render node runs no probe and logs nothing. The probe is built and shipped with the Vulkan driver package (/usr/lib/omarchy-a/gpu-probe), one binary for all boards, linked to the system's EGL, GLES, GBM and libdrm. Tested: the session's decisions with a mocked probe (pass, fail, crash, never ending, no probe, no display card); the probe compiles with the package's flags in the desktop builder image and refuses llvmpipe there. Not built as a package, not run on a GPU. Assisted-by: LLM --- NOTICE | 2 +- README.md | 14 ++- desktop/build | 2 +- desktop/build-sources | 4 +- desktop/configuration/login-session | 57 +++++++++-- .../packages/vulkan-powervr-orchard/PKGBUILD | 26 +++-- system/assemble-rootfs | 2 +- tests/test_gpu_video_session.py | 95 ++++++++++++++++--- 8 files changed, 158 insertions(+), 44 deletions(-) diff --git a/NOTICE b/NOTICE index 6edf1a1d..27c04026 100644 --- a/NOTICE +++ b/NOTICE @@ -2,6 +2,6 @@ Default project license: GPL-2.0-or-later (LICENSE). Omarchy shell: David Heinemeier Hansson, MIT (desktop/shell/LICENSE). m1n1: boot/m1n1/LICENSE. PongoOS and its components (pongo.bin, built by OrchardLinux/orchard): boot/pongo/LICENSE.md. -Vulkan driver for the Apple A10 GPU (vulkan-powervr-orchard): Mesa, MIT; built from https://github.com/OrchardLinux/mesa, license in the package. +Vulkan driver for the Apple PowerVR GPUs (vulkan-powervr-orchard): Mesa, MIT; built from https://github.com/OrchardLinux/mesa, license in the package. The GPU probe in the same package is this repository's, MIT. libva-v4l2_request (desktop/arm64/inputs/libva-v4l2_request-*.tar.gz): Ondrej Jirman and contributors, GPL-3.0; COPYING in the archive and the package. Omacalc package licenses: embedded usr/share/licenses/omacalc/LICENSE and OFL.txt in desktop/arm64/inputs/omacalc.pkg.tar.zst. diff --git a/README.md b/README.md index 9ed2e9b3..6a081ccb 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,15 @@ anything. Today the iPad 6 Wi-Fi (`iPad7,5`, J71b) is supported; the others are experimental. See orchard's [devices](https://github.com/OrchardLinux/orchard/tree/main/devices). -The desktop finds the hardware at login. On the iPad 6 and iPad 7 (A10) it -draws on the GPU, and Firefox plays H.264 video, YouTube included, through the -hardware video decoder. On every other device it draws in software, as before. -To start an A10 device on the software desktop once, boot with -`modprobe.blacklist=powervr`. +The desktop finds the hardware at login. Where orchard's kernel runs the GPU +(the iPad 6 and iPad 7, A10; the iPad 5, A9, once its GPU support has landed +in orchard and in the Mesa fork), the login first draws one test frame on the +GPU, within 10 s at most. If that works the desktop draws on the GPU; if not, +and on every other device, it draws in software, as before. +`journalctl -t omarchy-gpu-probe` shows what a login decided and why. To start +such a device on the software desktop once, boot with +`modprobe.blacklist=powervr`. On the iPad 6 and iPad 7 Firefox plays H.264 +video, YouTube included, through the hardware video decoder. Firefox reaches the video decoder only with its media decoding sandbox switched off (`MOZ_DISABLE_RDD_SANDBOX=1`, set by the login session on those diff --git a/desktop/build b/desktop/build index 79b10e04..896695ab 100755 --- a/desktop/build +++ b/desktop/build @@ -21,7 +21,7 @@ FILES = { 'omafox_xpi': INPUTS / '@omafox.xpi', 'libva_v4l2_request_source': INPUTS / 'libva-v4l2_request-1.2-2-gcac6ece.tar.gz', } -# Source-built on 64-bit boards only: the A10 GPU's Vulkan driver and the VA-API video bridge. +# Source-built on 64-bit boards only: the GPU's Vulkan driver (with the GPU probe) and the VA-API video bridge. HARDWARE_PACKAGES = {'vulkan-powervr-orchard.pkg.tar.zst': ('gpu_recipe_sha256', 'packages/vulkan-powervr-orchard'), 'libva-v4l2-request.pkg.tar.zst': ('video_bridge_recipe_sha256', 'packages/libva-v4l2-request')} # Prebuilt on 64-bit boards: packages published by their own repositories, diff --git a/desktop/build-sources b/desktop/build-sources index bd600472..5e699a00 100755 --- a/desktop/build-sources +++ b/desktop/build-sources @@ -156,11 +156,11 @@ package=$(ls "$build"/result/libva-v4l2-request-*-$OMARCHY_ARCH.pkg.tar.zst) bsdtar -tf "$package" usr/lib/dri/v4l2_request_drv_video.so >/dev/null cp "$package" "$ORCHARD_WORK/result/libva-v4l2-request.pkg.tar.zst" echo 'Building the GPU Vulkan driver (several minutes)...' -cp "$ORCHARD_RECIPE/packages/vulkan-powervr-orchard/PKGBUILD" "$ORCHARD_WORK"/sources/mesa-*.tar.gz "$build/gpu/" +cp "$ORCHARD_RECIPE"/packages/vulkan-powervr-orchard/{PKGBUILD,gpu-probe.c} "$ORCHARD_WORK"/sources/mesa-*.tar.gz "$build/gpu/" cd "$build/gpu" PKGDEST="$build/result" PKGEXT='.pkg.tar.zst' makepkg --noconfirm --nodeps > "$build/gpu.log" 2>&1 || { tail -60 "$build/gpu.log"; exit 1; } package=$(ls "$build"/result/vulkan-powervr-orchard-*-$OMARCHY_ARCH.pkg.tar.zst) -bsdtar -tf "$package" usr/lib/libvulkan_powervr_mesa.so usr/share/vulkan/icd.d/powervr_mesa_icd.json >/dev/null +bsdtar -tf "$package" usr/lib/libvulkan_powervr_mesa.so usr/share/vulkan/icd.d/powervr_mesa_icd.json usr/lib/omarchy-a/gpu-probe >/dev/null cp "$package" "$ORCHARD_WORK/result/vulkan-powervr-orchard.pkg.tar.zst" ''' buildenv.run(image, ['bash', '-euc', script], diff --git a/desktop/configuration/login-session b/desktop/configuration/login-session index eee9f14c..7d9060bd 100644 --- a/desktop/configuration/login-session +++ b/desktop/configuration/login-session @@ -20,25 +20,62 @@ export WLR_RENDERER=pixman QT_QUICK_BACKEND=software QT_QPA_PLATFORM=wayland export QT_QPA_PLATFORMTHEME=gtk3 export OMARCHY_TOUCH_MODE=1 export LIBGL_ALWAYS_SOFTWARE=1 LIBSEAT_BACKEND=seatd MOZ_ENABLE_WAYLAND=1 -# A board with a GPU this image has a Vulkan driver for (the A10's, kernel -# driver powervr): Labwc draws on wlroots' GLES2 renderer and applications on -# OpenGL, both through Zink on that driver. Every other board, and a boot with -# modprobe.blacklist=powervr, keeps the software desktop above. The shell stays -# on Qt's software renderer either way; the apps it starts don't (uwsm-app). +# A board with a GPU this image has a Vulkan driver for (kernel driver powervr, +# the A10's and the A9's): Labwc draws on wlroots' GLES2 renderer and +# applications on OpenGL, both through Zink on that driver, once gpu-probe has +# drawn a frame that way in this boot and the display took its buffer. Every +# other board, a boot with modprobe.blacklist=powervr and a boot whose probe +# fails or does not finish keep the software desktop above; the journal says +# which (journalctl -t omarchy-gpu-probe). The shell stays on Qt's software +# renderer either way; the apps it starts don't (uwsm-app). gpu= for node in /sys/class/drm/renderD*; do if [[ $(basename "$(readlink -f "$node/device/driver")") == powervr ]]; then gpu=$node; fi done -if [[ -n $gpu && -e /usr/share/vulkan/icd.d/powervr_mesa_icd.json ]]; then - export WLR_RENDERER=gles2 WLR_RENDER_DRM_DEVICE=/dev/dri/${gpu##*/} - export MESA_LOADER_DRIVER_OVERRIDE=zink PVR_I_WANT_A_BROKEN_VULKAN_DRIVER=1 - unset LIBGL_ALWAYS_SOFTWARE +if [[ -n $gpu ]]; then + gpu_probe=/usr/lib/omarchy-a/gpu-probe + gpu_log=$XDG_RUNTIME_DIR/omarchy-gpu-probe.log # The GPU has no display outputs: Labwc must open the display's card only. + display= for card in /sys/class/drm/card*; do if [[ ${card##*/} =~ ^card[0-9]+$ && $(readlink -f "$card/device") != "$(readlink -f "$gpu/device")" ]]; then - export WLR_DRM_DEVICES=/dev/dri/${card##*/} + display=/dev/dri/${card##*/} fi done + gpu_desktop=(WLR_RENDERER=gles2 "WLR_RENDER_DRM_DEVICE=/dev/dri/${gpu##*/}" + MESA_LOADER_DRIVER_OVERRIDE=zink PVR_I_WANT_A_BROKEN_VULKAN_DRIVER=1) + if [[ -n $display ]]; then gpu_desktop+=("WLR_DRM_DEVICES=$display"); fi + if [[ ! -e /usr/share/vulkan/icd.d/powervr_mesa_icd.json ]]; then + gpu_verdict='software desktop: this image has no Vulkan driver for the GPU' + elif [[ -z $display || ! -x $gpu_probe ]]; then + gpu_verdict='software desktop: no display card or no gpu-probe to test the GPU with' + else + # The probe runs with the environment the desktop would get. The login + # waits for it 10 s at most and does not depend on it ending: a probe + # stuck in the kernel is left behind. + env -u LIBGL_ALWAYS_SOFTWARE "${gpu_desktop[@]}" "$gpu_probe" "/dev/dri/${gpu##*/}" "$display" \ + >"$gpu_log" 2>&1 /dev/null; then + gpu_detail=$(grep -m 1 GPU-PROBE "$gpu_log" 2>/dev/null || tail -n 1 "$gpu_log" 2>/dev/null || true) + gpu_ended=1 + if wait "$gpu_pid"; then + gpu_verdict="GPU desktop after $((tick / 10)).$((tick % 10)) s: $gpu_detail" + export "${gpu_desktop[@]}" + unset LIBGL_ALWAYS_SOFTWARE + else + gpu_verdict="software desktop: ${gpu_detail:-the GPU probe failed}" + fi + break + fi + sleep 0.1 + done + if [[ -z $gpu_ended ]]; then kill -KILL "$gpu_pid" 2>/dev/null || true; fi + fi + logger -t omarchy-gpu-probe -- "$gpu_verdict" 2>/dev/null || true fi # A hardware video decoder (kernel driver apple-vxd, H.264): VA-API # applications reach it through libva-v4l2-request. Firefox uses it only when diff --git a/desktop/packages/vulkan-powervr-orchard/PKGBUILD b/desktop/packages/vulkan-powervr-orchard/PKGBUILD index 2787983b..2fc05456 100644 --- a/desktop/packages/vulkan-powervr-orchard/PKGBUILD +++ b/desktop/packages/vulkan-powervr-orchard/PKGBUILD @@ -1,26 +1,29 @@ -# omarchy-a: the Vulkan driver for the Apple A10 GPU (iPad 6, iPad 7) from -# OrchardLinux's Mesa fork, and only that driver: EGL, GBM and Zink stay -# Arch's own Mesa and draw through it. The kernel side is orchard's. +# omarchy-a: the Vulkan driver for the Apple PowerVR GPUs orchard's powervr +# kernel driver runs, from OrchardLinux's Mesa fork, and only that driver: EGL, +# GBM and Zink stay Arch's own Mesa and draw through it. With it gpu-probe, the +# login session's test that this stack draws on the board it runs on, linked +# to Arch's Mesa. The kernel side is orchard's. pkgname=vulkan-powervr-orchard _commit=7446eebebec5722cbdc6d3670e834c08d6ea9607 pkgver=27.0.0.dev.7446eebebec -pkgrel=1 -pkgdesc="Vulkan driver for the Apple A10 GPU, from the OrchardLinux Mesa fork" +pkgrel=2 +pkgdesc="Vulkan driver for the Apple PowerVR GPUs, from the OrchardLinux Mesa fork, and the desktop's GPU probe" url="https://github.com/OrchardLinux/mesa" license=('MIT') arch=('aarch64') options=('!lto' '!debug') -depends=('expat' 'gcc-libs' 'glibc' 'libdisplay-info' 'libdrm' 'spirv-tools' 'systemd-libs' 'vulkan-icd-loader' - 'wayland' 'zlib' 'zstd') +depends=('expat' 'gcc-libs' 'glibc' 'libdisplay-info' 'libdrm' 'libglvnd' 'mesa' 'spirv-tools' 'systemd-libs' + 'vulkan-icd-loader' 'wayland' 'zlib' 'zstd') # LLVM, Clang and libclc compile the driver's internal shaders at build time only. makedepends=('bison' 'clang' 'flex' 'glslang' 'libclc' 'libdisplay-info' 'libelf' 'libxkbcommon' 'llvm' 'meson' - 'ninja' 'python-mako' 'python-packaging' 'python-ply' 'python-yaml' 'spirv-llvm-translator' + 'ninja' 'pkgconf' 'python-mako' 'python-packaging' 'python-ply' 'python-yaml' 'spirv-llvm-translator' 'spirv-tools' 'vulkan-headers' 'wayland-protocols') provides=('vulkan-driver') conflicts=('vulkan-powervr') -source=("mesa-${_commit}.tar.gz::${url}/archive/${_commit}.tar.gz") -sha256sums=('7aa55f09aae7be33399136311a5b507c0846fb777dc6a1d36ded66d7546480f2') +source=("mesa-${_commit}.tar.gz::${url}/archive/${_commit}.tar.gz" gpu-probe.c) +sha256sums=('7aa55f09aae7be33399136311a5b507c0846fb777dc6a1d36ded66d7546480f2' + '85a82faaf046de658e139df0f185793a9aca857129a7c90c76aaf98d74152633') build() { # Not arch-meson: its --auto-features=enabled turns on Mesa features that @@ -31,6 +34,8 @@ build() { -Dopengl=false -Degl=disabled -Dgbm=disabled -Dglx=disabled -Dgles1=disabled \ -Dgles2=disabled -Dllvm=enabled -Dvideo-codecs= -Dtools= -Dvulkan-layers= ninja -C build + # The system's EGL, GLES, GBM and libdrm: the ones the desktop draws through. + cc ${CFLAGS} -Wall -Wextra gpu-probe.c -o gpu-probe ${LDFLAGS} $(pkg-config --cflags --libs egl glesv2 gbm libdrm) } package() { @@ -41,5 +46,6 @@ package() { build/src/imagination/vulkan/powervr_mesa_icd.*.json > powervr_mesa_icd.json grep -q '"library_path": "/usr/lib/libvulkan_powervr_mesa.so"' powervr_mesa_icd.json install -Dm 644 powervr_mesa_icd.json "${pkgdir}/usr/share/vulkan/icd.d/powervr_mesa_icd.json" + install -Dm 755 gpu-probe "${pkgdir}/usr/lib/omarchy-a/gpu-probe" install -Dm 644 "mesa-${_commit}/docs/license.rst" "${pkgdir}/usr/share/licenses/${pkgname}/license.rst" } diff --git a/system/assemble-rootfs b/system/assemble-rootfs index d4a9534a..19599f41 100755 --- a/system/assemble-rootfs +++ b/system/assemble-rootfs @@ -31,7 +31,7 @@ printf '%s\n' "${requested[@]}" | grep -Eq '^linux(-aarch64|-armv7|-rpi)?$' && { local_packages=("$desktop/packages/omafox.pkg.tar.xz" "$desktop/packages/wlroots0.20.pkg.tar.xz") # Omacalc: upstream Omarchy publishes it for aarch64 only; ARMv7 builds it from source. [[ $architecture == aarch64 ]] || local_packages+=("$desktop/packages/omacalc.pkg.tar.zst") -# 64-bit boards: the A10 GPU's Vulkan driver and the VA-API bridge to the +# 64-bit boards: the GPU's Vulkan driver with the login's GPU probe, and the VA-API bridge to the # hardware video decoders. Both sit unused on a board without that hardware. [[ $architecture != aarch64 ]] || local_packages+=("$desktop/packages/vulkan-powervr-orchard.pkg.tar.zst" "$desktop/packages/libva-v4l2-request.pkg.tar.zst") # 64-bit boards: Omactivity, the touch task manager, as its repository publishes it. diff --git a/tests/test_gpu_video_session.py b/tests/test_gpu_video_session.py index d431997a..129350cc 100644 --- a/tests/test_gpu_video_session.py +++ b/tests/test_gpu_video_session.py @@ -1,4 +1,5 @@ -"""The login session picks the GPU and the video decoder from what the board has; software stays the default.""" +"""The login session picks the GPU and the video decoder from what the board has and a probe shows to work; software stays the default.""" +import hashlib import os from pathlib import Path import subprocess @@ -10,17 +11,22 @@ START, END = '# A board with a GPU', 'export PATH=/usr/local/bin:/usr/bin' +PROBE = '/usr/lib/omarchy-a/gpu-probe' +PASS = 'echo "GPU-PROBE PASS renderer=zink"' + + def detection(): - """The hardware block of the session, reading a fake /sys and printing what it exported.""" + """The hardware block of the session, reading a fake /sys, running a fake probe and printing what it exported.""" text = SESSION.read_text() block = text[text.index(START):text.index(END)] - return block.replace('/sys/', '"$FAKE"/sys/').replace( - '-e /usr/share/vulkan/icd.d/powervr_mesa_icd.json', '-n ${ICD:-}') + assert PROBE in block and 'tick < 100' in block + return block.replace('/sys/', '"$FAKE"/sys/').replace(PROBE, '"$FAKE"/gpu-probe').replace( + '-e /usr/share/vulkan/icd.d/powervr_mesa_icd.json', '-n ${ICD:-}').replace('tick < 100', 'tick < ${TICKS:-100}') class Session(unittest.TestCase): - def run_session(self, devices, icd=True): - """devices: {sysfs class path: (device path, driver name)}.""" + def run_session(self, devices, icd=True, probe=PASS, ticks=None): + """devices: {sysfs class path: (device path, driver name)}; probe: the probe's shell text, None for no probe.""" with tempfile.TemporaryDirectory() as tmp: root = Path(tmp) for name, (device, driver) in devices.items(): @@ -31,24 +37,81 @@ def run_session(self, devices, icd=True): if not (target / 'driver').exists(): (target / 'driver').symlink_to(target / 'driver-dir' / driver) (node / 'device').symlink_to(target) - script = ('set -euo pipefail\nexport WLR_RENDERER=pixman LIBGL_ALWAYS_SOFTWARE=1\n' + detection() + + if probe is not None: + (root / 'gpu-probe').write_text('#!/bin/sh\necho "$@" > "$FAKE/probe-args"\n' + 'env > "$FAKE/probe-env"\n' + probe + '\n') + (root / 'gpu-probe').chmod(0o755) + # The journal is a file here: the session's logger call lands in it. + script = ('set -euo pipefail\nlogger() { shift 3; echo "$*" >> "$FAKE/journal"; }\n' + 'export WLR_RENDERER=pixman LIBGL_ALWAYS_SOFTWARE=1\n' + detection() + '\nenv | grep -E "^(WLR_|MESA_|PVR_|LIBGL_|LIBVA_|MOZ_)" | sort') - env = {'PATH': os.environ['PATH'], 'FAKE': str(root), **({'ICD': '1'} if icd else {})} - result = subprocess.run(['bash', '-c', script], env=env, text=True, capture_output=True, check=True) + env = {'PATH': os.environ['PATH'], 'FAKE': str(root), 'XDG_RUNTIME_DIR': str(root), + **({'ICD': '1'} if icd else {}), **({'TICKS': str(ticks)} if ticks else {})} + result = subprocess.run(['bash', '-c', script], env=env, text=True, capture_output=True, check=True, + timeout=30) + read = lambda name: (root / name).read_text() if (root / name).exists() else None + self.journal, self.probe_args, self.probe_env = read('journal'), read('probe-args'), read('probe-env') return dict(line.split('=', 1) for line in result.stdout.splitlines()) GPU = {'drm/renderD128': ('soc/gpu', 'powervr'), 'drm/card0': ('soc/gpu', 'powervr'), 'drm/card1': ('soc/display', 'apple-adbe'), 'drm/card1-eDP-1': ('soc/display/drm/card1', 'none')} DECODER = {'video4linux/video0': ('soc/video-codec', 'apple-vxd')} + SOFTWARE = {'WLR_RENDERER': 'pixman', 'LIBGL_ALWAYS_SOFTWARE': '1'} + def test_software_desktop_without_the_hardware(self): - expected = {'WLR_RENDERER': 'pixman', 'LIBGL_ALWAYS_SOFTWARE': '1'} - self.assertEqual(self.run_session({}), expected) + self.assertEqual(self.run_session({}), self.SOFTWARE) # A display controller alone, or another driver's render node, is no reason to leave pixman. self.assertEqual(self.run_session({'drm/card0': ('soc/display', 'apple-adbe'), - 'drm/renderD128': ('soc/other', 'other-gpu')}), expected) + 'drm/renderD128': ('soc/other', 'other-gpu')}), self.SOFTWARE) + # Such a board runs no probe and gets no journal line: nothing changes for it. + self.assertEqual((self.probe_args, self.journal), (None, None)) + + def test_software_desktop_when_the_image_cannot_test_the_gpu(self): # The kernel driver without this image's Vulkan driver cannot draw. - self.assertEqual(self.run_session(self.GPU, icd=False), expected) + self.assertEqual(self.run_session(self.GPU, icd=False), self.SOFTWARE) + self.assertEqual(self.probe_args, None) + self.assertIn('software desktop: this image has no Vulkan driver', self.journal) + # Without the probe, or without a display card, nothing vouches for the GPU. + self.assertEqual(self.run_session(self.GPU, probe=None), self.SOFTWARE) + self.assertIn('software desktop: no display card or no gpu-probe', self.journal) + gpu_only = {name: device for name, device in self.GPU.items() if not name.startswith('drm/card1')} + self.assertEqual(self.run_session(gpu_only), self.SOFTWARE) + self.assertEqual(self.probe_args, None) + + def test_probe_runs_as_the_desktop_would(self): + env = self.run_session(self.GPU) + self.assertEqual(self.probe_args.split(), ['/dev/dri/renderD128', '/dev/dri/card1']) + probe_env = dict(line.split('=', 1) for line in self.probe_env.splitlines() if '=' in line) + for name in ('WLR_RENDERER', 'WLR_RENDER_DRM_DEVICE', 'WLR_DRM_DEVICES', 'MESA_LOADER_DRIVER_OVERRIDE', + 'PVR_I_WANT_A_BROKEN_VULKAN_DRIVER'): + self.assertEqual(probe_env[name], env[name]) + self.assertNotIn('LIBGL_ALWAYS_SOFTWARE', probe_env) + self.assertRegex(self.journal, r'^GPU desktop after \d+\.\d s: GPU-PROBE PASS renderer=zink\n$') + + def test_failed_probe_keeps_the_software_desktop(self): + # Any board: the kernel driver is there, but drawing through it does not work in this boot. + env = self.run_session(self.GPU, probe='echo "mesa: some warning"\n' + 'echo "GPU-PROBE FAIL: the display controller cannot import" >&2\nexit 1') + self.assertEqual(env, self.SOFTWARE) + self.assertEqual(self.journal, 'software desktop: GPU-PROBE FAIL: the display controller cannot import\n') + # A probe that dies without a word (a crash in a driver) is a failure too. + self.assertEqual(self.run_session(self.GPU, probe='kill -SEGV $$'), self.SOFTWARE) + self.assertEqual(self.journal, 'software desktop: the GPU probe failed\n') + + def test_probe_that_never_ends_does_not_hold_the_login(self): + # It ignores TERM and would run for a minute; the session moves on after its wait (0.3 s here). + env = self.run_session(self.GPU, probe="trap '' TERM\nexec sleep 60", ticks=3) + self.assertEqual(env, self.SOFTWARE) + self.assertEqual(self.journal, 'software desktop: the GPU probe did not finish within 10 s\n') + + def test_probe_recipe_is_the_file_next_to_it(self): + # makepkg checks gpu-probe.c against the recipe: both must change together. + recipe = PROJECT / 'desktop/packages/vulkan-powervr-orchard' + self.assertIn(hashlib.sha256((recipe / 'gpu-probe.c').read_bytes()).hexdigest(), + (recipe / 'PKGBUILD').read_text()) + self.assertIn(f'"${{pkgdir}}{PROBE}"', (recipe / 'PKGBUILD').read_text()) + self.assertIn(PROBE.lstrip('/'), (PROJECT / 'desktop/build-sources').read_text()) def test_gpu_desktop_opens_only_the_display_card(self): env = self.run_session(self.GPU) @@ -61,11 +124,15 @@ def test_gpu_desktop_opens_only_the_display_card(self): self.assertNotIn('MOZ_DISABLE_RDD_SANDBOX', env) def test_decoder_without_gpu_keeps_firefox_sandboxed(self): - # The iPad 5: VA-API applications get the decoder, Firefox (software-drawn) keeps its sandbox. + # A software desktop: VA-API applications get the decoder, Firefox (software-drawn) keeps its sandbox. env = self.run_session(self.DECODER) self.assertEqual(env['LIBVA_DRIVER_NAME'], 'v4l2_request') self.assertEqual(env['WLR_RENDERER'], 'pixman') self.assertNotIn('MOZ_DISABLE_RDD_SANDBOX', env) + # The same holds on a board whose GPU fails the probe. + env = self.run_session({**self.GPU, **self.DECODER}, probe='exit 1') + self.assertEqual((env['LIBVA_DRIVER_NAME'], env['WLR_RENDERER']), ('v4l2_request', 'pixman')) + self.assertNotIn('MOZ_DISABLE_RDD_SANDBOX', env) def test_decoder_on_the_gpu_desktop(self): env = self.run_session({**self.GPU, **self.DECODER}) From 5a42f39654dd54ed0d941f73722e9d2af65aeec2 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sun, 15 Nov 2026 01:36:35 +0800 Subject: [PATCH 3/3] GPU driver: the iPad 5 (A9) GPU in the same Vulkan driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mesa fork 2c1aa767d8d (OrchardLinux/mesa #8): Berkay Kösebay's A9 driver on the powervr kernel interface (orchard #138), next to the A10 one. The iPad 6/7 path is unchanged. --- desktop/arm64/sources.json | 6 +++--- desktop/packages/vulkan-powervr-orchard/PKGBUILD | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/desktop/arm64/sources.json b/desktop/arm64/sources.json index bb41a8ed..c20e5ecc 100644 --- a/desktop/arm64/sources.json +++ b/desktop/arm64/sources.json @@ -1,10 +1,10 @@ { "mesa": { "version": "27.0.0-devel", - "commit": "7446eebebec5722cbdc6d3670e834c08d6ea9607", + "commit": "2c1aa767d8d8836739260177144716271e05f686", "urls": [ - "https://github.com/OrchardLinux/mesa/archive/7446eebebec5722cbdc6d3670e834c08d6ea9607.tar.gz" + "https://github.com/OrchardLinux/mesa/archive/2c1aa767d8d8836739260177144716271e05f686.tar.gz" ], - "sha256": "7aa55f09aae7be33399136311a5b507c0846fb777dc6a1d36ded66d7546480f2" + "sha256": "e6a6481bcbe736342146b8000725e739ebf389384d3a9fe3ae36def2e4c6cd2a" } } diff --git a/desktop/packages/vulkan-powervr-orchard/PKGBUILD b/desktop/packages/vulkan-powervr-orchard/PKGBUILD index 2fc05456..07ff5f3f 100644 --- a/desktop/packages/vulkan-powervr-orchard/PKGBUILD +++ b/desktop/packages/vulkan-powervr-orchard/PKGBUILD @@ -5,9 +5,9 @@ # to Arch's Mesa. The kernel side is orchard's. pkgname=vulkan-powervr-orchard -_commit=7446eebebec5722cbdc6d3670e834c08d6ea9607 -pkgver=27.0.0.dev.7446eebebec -pkgrel=2 +_commit=2c1aa767d8d8836739260177144716271e05f686 +pkgver=27.0.0.dev.2c1aa767d8d +pkgrel=1 pkgdesc="Vulkan driver for the Apple PowerVR GPUs, from the OrchardLinux Mesa fork, and the desktop's GPU probe" url="https://github.com/OrchardLinux/mesa" license=('MIT') @@ -22,7 +22,7 @@ makedepends=('bison' 'clang' 'flex' 'glslang' 'libclc' 'libdisplay-info' 'libelf provides=('vulkan-driver') conflicts=('vulkan-powervr') source=("mesa-${_commit}.tar.gz::${url}/archive/${_commit}.tar.gz" gpu-probe.c) -sha256sums=('7aa55f09aae7be33399136311a5b507c0846fb777dc6a1d36ded66d7546480f2' +sha256sums=('e6a6481bcbe736342146b8000725e739ebf389384d3a9fe3ae36def2e4c6cd2a' '85a82faaf046de658e139df0f185793a9aca857129a7c90c76aaf98d74152633') build() {