From 42e8bc3f781e971341ff96ee1339ae5fc597b728 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Sat, 3 Oct 2026 17:33:08 -0400 Subject: [PATCH] Add experimental kbase PanVK build and wired G52 validation --- .gitattributes | 1 + docs/testing/mali-software-steam.md | 9 ++ tools/panvk/README.md | 118 ++++++++++++++++++ tools/panvk/build-in-runtime.sh | 51 ++++++++ tools/panvk/patches/0001-glibc-link.patch | 17 +++ .../patches/0002-jm-v2-atom-layout.patch | 95 ++++++++++++++ .../0003-kbase-disable-placed-mapping.patch | 26 ++++ 7 files changed, 317 insertions(+) create mode 100644 tools/panvk/README.md create mode 100755 tools/panvk/build-in-runtime.sh create mode 100644 tools/panvk/patches/0001-glibc-link.patch create mode 100644 tools/panvk/patches/0002-jm-v2-atom-layout.patch create mode 100644 tools/panvk/patches/0003-kbase-disable-placed-mapping.patch diff --git a/.gitattributes b/.gitattributes index 228186e37b..ca533101e3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ # Patch context includes the indentation and blank lines of the source being patched. tools/gamescope/patches/*.patch -whitespace +tools/panvk/patches/*.patch -whitespace diff --git a/docs/testing/mali-software-steam.md b/docs/testing/mali-software-steam.md index 63b12a7c62..1b94ef472f 100644 --- a/docs/testing/mali-software-steam.md +++ b/docs/testing/mali-software-steam.md @@ -61,3 +61,12 @@ That disables the Vulkan Xwayland-bypass layer for the game while keeping the ou The Android presenter reported roughly 3–5 displayed frames per second in representative gameplay samples. Movement and shooting work, but CPU-rendered performance is insufficient for normal play. Audio was not verified. The game was left paused with scrcpy running. Follow-up logs are in `Download/DroidDeck/2026-10-03-11-steam/`; screenshots and raw logs are retained locally, outside Git. A guest glibc Mali ICD and compatible image transport remain necessary for hardware acceleration. This patch does not install Steam-ARM's feature layers or validate other Mali generations; the gameplay result establishes one Windows D3D9 title through software rendering, not general Proton/DXVK compatibility. The Android presenter also caps its requested Vulkan API to the loader's supported version and withholds dma-buf advertisement when the complete import extension set is missing; that missing-extension branch has not been exercised on this G52 driver. + +## GPU acceleration follow-up + +The [kbase/JM driver lab](../../tools/panvk/README.md) now includes a pinned +source build and three fixes validated on this wired G52. GPU compute, +offscreen draw/readback, indexed draw and visible VKCube presentation work. +Geometry Wars remains blocked: the bundled DXVK requires an unsupported +feature, while an isolated older DXVK reaches rendering and loses the GPU +device. The software Steam/Gamescope settings remain the recovery path. diff --git a/tools/panvk/README.md b/tools/panvk/README.md new file mode 100644 index 0000000000..93d2e4ea8c --- /dev/null +++ b/tools/panvk/README.md @@ -0,0 +1,118 @@ +# Experimental Mali kbase/JM driver + +This lab builds the Linux Vulkan ICD from +[FristOneRR-Panvk-Source](https://github.com/FristOneRR-Admin/FristOneRR-Panvk-Source) +at `efd07bab401b263a9ac114560ecdb9a2934f5d43`. The fork includes the older Job +Manager submission path needed by Mali-G52. It talks to `/dev/mali0` through +the proprietary kbase kernel interface; upstream DRM-only PanVK cannot use +that device node. + +The local patches make Android `liblog` conditional, fix the JM atom ABI, +and withhold placed mapping on kbase. +The original fork padded its v2 layout to 64 bytes, which this kernel interprets +as v3 with an eight-byte sequence-number prefix. Jobs arrived under atom 0 and +timed out after a configuration fault. The patch submits the actual 56-byte v2 +structure on JM 11.19 and later (48 bytes on older JM), as specified in +[Arm's kbase UAPI header](https://nest-open-source.googlesource.com/manifest_repos/mali-driver/+/0f8397eced2de6bc649a9cc32d0fae77a1dc34dc/bifrost/r44p0/kernel/include/uapi/gpu/arm/midgard/jm/mali_base_jm_kernel.h). + +Build inside an AArch64 glibc environment with Clang/LLVM 22, Meson, Ninja, +libclc, SPIRV-Tools, SPIRV-LLVM-Translator, Vulkan headers, Python Mako/YAML, +and the X11/Wayland development dependencies installed. The tested DroidDeck +runtime already supplied several of these dependencies. Avoid installing an +entire development toolchain into a user's runtime by default. + +```sh +git clone https://github.com/FristOneRR-Admin/FristOneRR-Panvk-Source.git panvk-src +git -C panvk-src checkout efd07bab401b263a9ac114560ecdb9a2934f5d43 +JOBS=2 tools/panvk/build-in-runtime.sh "$PWD/panvk-src" "$PWD/panvk-build" +``` + +The build stays under `panvk-build`; it does not install or replace a global +ICD. Its manifest selects the newly built driver explicitly: + +```sh +PAN_I_WANT_A_BROKEN_VULKAN_DRIVER=1 PANVK_KBASE_DRI3=0 \ +VK_DRIVER_FILES="$PWD/panvk-build/panvk-g52-icd.json" \ +VK_ICD_FILENAMES="$PWD/panvk-build/panvk-g52-icd.json" \ +vulkaninfo --summary +``` + +To launch the tested GPU cube from the Mac against this device's lab build: + +```sh +ADB_SERIAL=RGB05001607258 tools/droiddeckctl run /usr/bin/env -- \ + PAN_I_WANT_A_BROKEN_VULKAN_DRIVER=1 PANVK_KBASE_DRI3=0 \ + VK_DRIVER_FILES=/opt/panvk-g52-lab/panvk-g52-icd.json \ + VK_ICD_FILENAMES=/opt/panvk-g52-lab/panvk-g52-icd.json \ + DISABLE_GAMESCOPE_WSI=1 LD_LIBRARY_PATH=/usr/lib \ + /usr/bin/vkcube --wsi xcb --width 640 --height 480 +``` + +Stop the current session before using `droiddeckctl run`. + +`PANVK_KBASE_DRI3=0` selects shared-memory presentation. DroidDeck's Xwayland +does not implement the fork's private Termux:X11 raw dma-buf protocol. GPU +rendering and CPU presentation copies are separate: choosing this presentation +path does not select Lavapipe. + +Before selecting this driver for a session, validate GPU compute and offscreen +render readback, then X11 presentation, then the desired game. Device detection +alone is insufficient. The wired Unisoc T618 / Mali-G52 MC2 reports kbase UAPI +11.31, while the separate +[G52 reference project](https://github.com/LukeValen/panvk-mali-g52) was tested +on MediaTek with UAPI 11.38. Keep `BL_STEAM_SOFTWARE=1` available for recovery. + +The Linux ICD is distinct from the Android Vulkan driver used by DroidDeck's +presenter. Android/Bionic driver packages cannot be loaded by the glibc Steam +runtime. + +## Wired G52 results (2026-10-03) + +Built natively in DroidDeck's AArch64 glibc runtime with Clang/LLVM 22.1.8. +The app UID can open `/dev/mali0` and submit jobs without root. No DRM render +node or dma-heap was available. This is experimental driver work, with the +Steam UI and outer Gamescope still running in software mode. + +| Test | Result | +| --- | --- | +| Vulkan enumeration | Mali-G52 r1 MC2, integrated GPU, Vulkan 1.3.354 | +| Compute shader and host readback | Expected integer 777 returned | +| Vertex/fragment draw and image readback | Expected red pixel 255,0,0,255 returned | +| Indexed triangle and image readback | Expected red pixel returned | +| X11 VKCube inside a DroidDeck Gamescope session | Rotating cube visible; about 15–17 displayed FPS through SHM | +| Geometry Wars, bundled DXVK 3.1.1 | Adapter rejected: `multiDrawIndirect` is unsupported | +| Geometry Wars, isolated DXVK 1.10.3 | Device and 640×480 swapchain created; rendering loses the GPU device | + +The fork advertises `VK_EXT_map_memory_placed` although its kbase mapping code +rejects caller-selected addresses for ordinary SAME_VA allocations. Wine's +WoW64 Vulkan path selects that extension and DXVK buffer mapping fails with +`VK_ERROR_MEMORY_MAP_FAILED`. The third patch withholds the extension and +features on kbase, keeping them on DRM. Wine then uses its fallback mapping +path and reaches real game submissions. + +The remaining Geometry Wars failure includes terminated jobs (`0x04`) and +`BASE_JD_EVENT_JOB_READ_FAULT` (`0x42`), followed by +`VK_ERROR_DEVICE_LOST`. A diagnostic build that waits after each batch showed +successful uploads and clears, then termination of the first vertex/tiler +chain. Its compute job completed, but its vertex job, tiler job and dependent +fragment job did not complete. Basic indexed rendering also passes with IDVS +disabled, so a generic indexed-draw or separate-vertex-job failure was not +reproduced. The complex vertex workload remains unresolved. Disabling submission overlap and compiler IDVS or +optimizations did not recover rendering. Native draw/readback and VKCube +success therefore do not establish working Proton game acceleration. + +Do not advertise missing Vulkan features just to pass DXVK's adapter check. +Keep game overrides and legacy DXVK trials isolated from the Proton depot, +and restore the working software launch option when the trial fails: + +```sh +DISABLE_GAMESCOPE_WSI=1 %command% +``` + +The tested three-patch build has SHA-256 +`5fc3f57fe335ebf524871ca24fd38b3c384c31baaebe9a2220e8e482e09e5ad6`. +That identifies the retained evidence binary; rebuilds need not be byte-identical. + +The patched driver remains a private lab ICD. It is not bundled in the APK, +selected globally, or production-ready. A compatible DXVK path and reliable +complex rendering must be validated before adding automatic Mali selection. diff --git a/tools/panvk/build-in-runtime.sh b/tools/panvk/build-in-runtime.sh new file mode 100755 index 0000000000..c1536f83e3 --- /dev/null +++ b/tools/panvk/build-in-runtime.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Experimental kbase/JM PanVK build. Run inside an AArch64 glibc environment. +# Output stays private to the supplied build directory; no system ICD is installed. +set -euo pipefail + +source_dir=${1:?Usage: build-in-runtime.sh SOURCE_DIR BUILD_DIR} +build_dir=${2:?Usage: build-in-runtime.sh SOURCE_DIR BUILD_DIR} +revision=efd07bab401b263a9ac114560ecdb9a2934f5d43 +script_dir=$(cd -- "$(dirname -- "$0")" && pwd) +source_dir=$(cd -- "$source_dir" && pwd) +mkdir -p "$build_dir" +build_dir=$(cd -- "$build_dir" && pwd) + +if [ "$(uname -m)" != aarch64 ]; then + echo 'This script needs a native AArch64 Linux build environment.' >&2 + exit 1 +fi +if [ "$(git -C "$source_dir" rev-parse HEAD)" != "$revision" ]; then + echo "Expected FristOneRR-Panvk-Source revision $revision." >&2 + exit 1 +fi +for patch_file in "$script_dir"/patches/*.patch; do + if git -C "$source_dir" apply --reverse --check "$patch_file" 2>/dev/null; then + continue + fi + git -C "$source_dir" apply --check "$patch_file" + git -C "$source_dir" apply "$patch_file" +done + +# The fork's SPIRV-Tools probe contains Clang-only warning options. +export CC=clang CXX=clang++ +meson setup "$build_dir" "$source_dir" --buildtype=release \ + --prefix="$build_dir/install" --libdir=lib \ + -Dbuild-tests=false -Dgallium-drivers= -Dvulkan-drivers=panfrost \ + -Dpanfrost-kmds=kbase -Dplatforms=x11,wayland \ + -Dglx=disabled -Degl=disabled -Dgbm=disabled \ + -Dgles1=disabled -Dgles2=disabled -Dopengl=false \ + -Dllvm=enabled -Dmesa-clc=enabled -Dprecomp-compiler=enabled \ + -Dpanfrost-rust=false -Dvalgrind=disabled -Dzstd=enabled +ninja -C "$build_dir" -j"${JOBS:-2}" src/panfrost/vulkan/libvulkan_panfrost.so + +python3 - "$build_dir" <<'PY' +import json, pathlib, sys +root = pathlib.Path(sys.argv[1]) +driver = root / 'src/panfrost/vulkan/libvulkan_panfrost.so' +manifest = {'file_format_version': '1.0.0', 'ICD': { + 'library_path': str(driver), 'api_version': '1.4.0'}} +(root / 'panvk-g52-icd.json').write_text(json.dumps(manifest, indent=2) + '\n') +PY +sha256sum "$build_dir/src/panfrost/vulkan/libvulkan_panfrost.so" +echo "Private ICD: $build_dir/panvk-g52-icd.json" diff --git a/tools/panvk/patches/0001-glibc-link.patch b/tools/panvk/patches/0001-glibc-link.patch new file mode 100644 index 0000000000..56932d6633 --- /dev/null +++ b/tools/panvk/patches/0001-glibc-link.patch @@ -0,0 +1,17 @@ +diff --git a/meson.build b/meson.build +--- a/meson.build ++++ b/meson.build +@@ -16,10 +16,9 @@ project( + 'build.rust_std=2021', + ], + ) +-add_project_link_arguments( +- '-llog', +- language : ['c', 'cpp'], +-) ++if host_machine.system() == 'android' ++ add_project_link_arguments('-llog', language : ['c', 'cpp']) ++endif + project_version = meson.project_version() + + if host_machine.system() == 'darwin' diff --git a/tools/panvk/patches/0002-jm-v2-atom-layout.patch b/tools/panvk/patches/0002-jm-v2-atom-layout.patch new file mode 100644 index 0000000000..d41e48c74d --- /dev/null +++ b/tools/panvk/patches/0002-jm-v2-atom-layout.patch @@ -0,0 +1,95 @@ +diff --git a/src/panfrost/lib/kmod/kbase_kmod.c b/src/panfrost/lib/kmod/kbase_kmod.c +--- a/src/panfrost/lib/kmod/kbase_kmod.c ++++ b/src/panfrost/lib/kmod/kbase_kmod.c +@@ -97,6 +97,7 @@ + + struct base_jd_udata { __u64 blob[2]; }; + ++/* kbase atom v2: 56 bytes, without the v3 sequence-number prefix. */ + struct base_jd_atom { + __u64 jc; + struct base_jd_udata udata; +@@ -110,11 +111,12 @@ + __u8 jobslot; + __u32 core_req; + __u8 renderpass_id; +- __u8 padding[15]; /* pad struct to 64 bytes total; this kernel rejects any other JOB_SUBMIT stride */ ++ __u8 padding[7]; + }; + +-/* Some kbase builds (e.g. r49 on 6.6 kernels) expect a 56-byte atom +- * stride instead of 64. PANVK_ATOM_STRIDE overrides the default. */ ++/* JM 11.19 added renderpass_id and extended v2 from 48 to 56 bytes. ++ * A 64-byte atom is v3: it has a leading seq_nr and a different layout. ++ * Do not submit a padded v2 as v3. */ + static unsigned g_atom_stride; + + static unsigned +@@ -123,7 +125,7 @@ + if (!g_atom_stride) { + const char *e = getenv("PANVK_ATOM_STRIDE"); + unsigned v = e ? (unsigned)atoi(e) : 0; +- g_atom_stride = (v == 48 || v == 56 || v == 64) ? v : 64; ++ g_atom_stride = (v == 48 || v == 56) ? v : 56; + if (e) + dprintf(2, "[FristOneRR] atom stride = %u\n", g_atom_stride); + } +@@ -1223,43 +1225,6 @@ + } + + +-/* Probe the JOB_SUBMIT atom stride once per process: submit an empty +- * dependency-only atom (no GPU work) with stride 64. Kernels that expect +- * 56 (e.g. r49 on 6.6) answer with a config fault (0x40) or reject the +- * ioctl; then we switch to 56. PANVK_ATOM_STRIDE always wins. */ +-static void +-kbase_probe_atom_stride(int fd) +-{ +- if (g_atom_stride || getenv("PANVK_ATOM_STRIDE")) { +- (void)kbase_atom_stride(); +- return; +- } +- +- struct base_jd_atom atom = { .atom_number = 255, .core_req = 0 }; +- struct kbase_ioctl_job_submit sub = { +- .addr = (uint64_t)(uintptr_t)&atom, +- .nr_atoms = 1, +- .stride = 64, +- }; +- unsigned result = 64; +- +- if (ioctl(fd, KBASE_IOCTL_JOB_SUBMIT, &sub) < 0) { +- result = 56; +- } else { +- struct pollfd pfd = { .fd = fd, .events = POLLIN }; +- if (poll(&pfd, 1, 1000) > 0) { +- struct base_jd_event_v2 ev = { 0 }; +- if (read(fd, &ev, sizeof(ev)) == (ssize_t)sizeof(ev) && +- (ev.event_code & BASE_JD_EVENT_ERR_MASK)) +- result = 56; +- } +- } +- +- g_atom_stride = result; +- if (result != 64) +- dprintf(2, "[FristOneRR] atom stride auto-detected: %u\n", result); +-} +- + static struct pan_kmod_dev * + kbase_kmod_dev_create(int fd, uint32_t flags, + UNUSED const struct pan_kmod_driver *drv_info, +@@ -1307,8 +1272,12 @@ + return NULL; + } + +- if (!is_csf) +- kbase_probe_atom_stride(fd); ++ STATIC_ASSERT(sizeof(struct base_jd_atom) == 56); ++ if (!is_csf) { ++ if (!g_atom_stride && !getenv("PANVK_ATOM_STRIDE")) ++ g_atom_stride = ver.minor < 19 ? 48 : 56; ++ (void)kbase_atom_stride(); ++ } + + /* Empirically, this Mali-G57 kbase JM backend needs ~2s of real + * wall-clock time after context creation before the GPU power domain diff --git a/tools/panvk/patches/0003-kbase-disable-placed-mapping.patch b/tools/panvk/patches/0003-kbase-disable-placed-mapping.patch new file mode 100644 index 0000000000..a3d68b0020 --- /dev/null +++ b/tools/panvk/patches/0003-kbase-disable-placed-mapping.patch @@ -0,0 +1,26 @@ +diff --git a/src/panfrost/vulkan/panvk_vX_physical_device.c b/src/panfrost/vulkan/panvk_vX_physical_device.c +--- a/src/panfrost/vulkan/panvk_vX_physical_device.c ++++ b/src/panfrost/vulkan/panvk_vX_physical_device.c +@@ -198,7 +198,9 @@ + .EXT_legacy_dithering = true, + .EXT_line_rasterization = true, + .EXT_load_store_op_none = true, +- .EXT_map_memory_placed = true, ++ /* kbase SAME_VA allocations cannot be mapped at a caller-chosen ++ * address. Wine WoW64 selects that path when this extension exists. */ ++ .EXT_map_memory_placed = !device->kbase_node_path[0], + .EXT_external_memory_host = true, + .EXT_nested_command_buffer = PAN_ARCH >= 10, + .EXT_memory_budget = true, +@@ -729,9 +731,9 @@ + .nestedCommandBufferSimultaneousUse = PAN_ARCH >= 10, + + /* VK_EXT_map_memory_placed */ +- .memoryMapPlaced = true, ++ .memoryMapPlaced = !device->kbase_node_path[0], + .memoryMapRangePlaced = false, +- .memoryUnmapReserve = true, ++ .memoryUnmapReserve = !device->kbase_node_path[0], + + /* VK_EXT_non_seamless_cube_map */ + .nonSeamlessCubeMap = true,