diff --git a/tools/tests/test_ubuntu_patches.py b/tools/tests/test_ubuntu_patches.py new file mode 100644 index 0000000000..d5b219f3cf --- /dev/null +++ b/tools/tests/test_ubuntu_patches.py @@ -0,0 +1,85 @@ +import pathlib +import re +import unittest + + +ROOT = pathlib.Path(__file__).resolve().parents[2] +PATCHES = ROOT / "tools/ubuntu/patches" +HUNK = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@") + + +def hunks(text): + lines = text.splitlines() + i = 0 + while i < len(lines): + m = HUNK.match(lines[i]) + if not m: + i += 1 + continue + old = int(m.group(2) or 1) + new = int(m.group(4) or 1) + seen_old = seen_new = 0 + i += 1 + while i < len(lines) and (seen_old < old or seen_new < new): + line = lines[i] + if line.startswith("\\"): + i += 1 + continue + tag = line[:1] + if tag in (" ", ""): + seen_old += 1 + seen_new += 1 + elif tag == "-": + seen_old += 1 + elif tag == "+": + seen_new += 1 + else: + break + i += 1 + yield m.group(0), old, new, seen_old, seen_new + + +class UbuntuPatchesTest(unittest.TestCase): + def patch_files(self): + files = sorted(PATCHES.glob("*/*.patch")) + self.assertTrue(files) + return files + + def test_every_hunk_matches_its_line_counts(self): + for path in self.patch_files(): + text = path.read_text() + found = list(hunks(text)) + self.assertTrue(found, path.name) + for header, old, new, seen_old, seen_new in found: + with self.subTest(patch=path.name, hunk=header): + self.assertEqual((old, new), (seen_old, seen_new)) + + def test_every_patch_names_files_for_p1(self): + for path in self.patch_files(): + text = path.read_text() + sources = re.findall(r"^--- (\S+)", text, re.M) + targets = re.findall(r"^\+\+\+ (\S+)", text, re.M) + with self.subTest(patch=path.name): + self.assertTrue(sources) + self.assertEqual(len(sources), len(targets)) + for name in sources + targets: + self.assertRegex(name, r"^(a|b)/") + + def test_patch_numbers_are_unique(self): + for folder in sorted(p for p in PATCHES.iterdir() if p.is_dir()): + numbers = [p.name.split("-", 1)[0] for p in folder.glob("*.patch")] + self.assertEqual(len(numbers), len(set(numbers)), folder.name) + + def test_zink_never_imports_into_a_missing_semaphore(self): + text = (PATCHES / "mesa/0006-zink-skip-dmabuf-implicit-sync-without-a-semaphore.patch").read_text() + added = "\n".join(l[1:] for l in text.splitlines() if l.startswith("+") and not l.startswith("+++")) + self.assertIn("if (unlikely(!sem))", added) + self.assertIn("close(export.fd);", added) + self.assertIn("return VK_NULL_HANDLE;", added) + context = text.split("sem = zink_create_exportable_semaphore(screen);", 1) + self.assertEqual(len(context), 2) + self.assertLess(context[1].index("if (unlikely(!sem))"), context[1].index("VkImportSemaphoreFdInfoKHR")) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/ubuntu/README.md b/tools/ubuntu/README.md index eefff4c6c7..614b88d508 100644 --- a/tools/ubuntu/README.md +++ b/tools/ubuntu/README.md @@ -10,7 +10,8 @@ Steam on the desktop). The app installs it into `files/linuxfs` and runs it unde scroll source/discrete forwarding). Both get a `+droiddeck` version. `patches/mesa` adds KGSL UBWC 5/6 (backported from upstream Mesa) and the KGSL device numbers for WSI (from [Droid-Deck/Drivers](https://github.com/Droid-Deck/Drivers)). It also carries Icenowy Zheng's upstream - Zink fix that keeps the Imagination depth/stencil swizzle off colour views (Mesa d55418dae7). + Zink fix that keeps the Imagination depth/stencil swizzle off colour views (Mesa d55418dae7), and + a Zink fix that skips dma-buf implicit sync when the driver cannot create an exportable semaphore. - The runtime's built-in Vulkan driver is DroidDeck's DD-Turnip Linux build (`DD_TURNIP_URL` and `DD_TURNIP_SHA256` in `base.env`): Ubuntu's Turnip is diverted to `libvulkan_freedreno.so.distrib` because it lacks the Adreno 8xx fixes. Zink, EGL and llvmpipe stay Ubuntu's. diff --git a/tools/ubuntu/patches/mesa/0006-zink-skip-dmabuf-implicit-sync-without-a-semaphore.patch b/tools/ubuntu/patches/mesa/0006-zink-skip-dmabuf-implicit-sync-without-a-semaphore.patch new file mode 100644 index 0000000000..8573df9dae --- /dev/null +++ b/tools/ubuntu/patches/mesa/0006-zink-skip-dmabuf-implicit-sync-without-a-semaphore.patch @@ -0,0 +1,37 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: The412Banner <205237651+The412Banner@users.noreply.github.com> +Date: Tue, 24 Nov 2026 21:15:00 +0000 +Subject: [PATCH] zink: skip dma-buf implicit sync when no exportable semaphore + can be created + +zink_screen_export_dmabuf_semaphore() exports the dma-buf's sync file and +imports it into a semaphore from zink_create_exportable_semaphore(). That +returns VK_NULL_HANDLE when the driver's vkCreateSemaphore() fails for a +SYNC_FD-exportable semaphore, and the null handle went straight into +vkImportSemaphoreFdKHR() with VK_SEMAPHORE_IMPORT_TEMPORARY_BIT. The +common runtime then reads the semaphore's type through a null pointer. + +On PanVK for Arm's kbase driver (Mali-G57 MC2, MT6789) Xwayland's glamor +crashed this way, at address 0x40 in vk_common_ImportSemaphoreFdKHR(), the +first time it used a client's dma-buf, and gamescope aborted with it. Treat +the failure like a failed sync file export: close the sync file and return +VK_NULL_HANDLE, which the caller already skips. Still present in Mesa main. +--- +--- a/src/gallium/drivers/zink/zink_screen.c ++++ b/src/gallium/drivers/zink/zink_screen.c +@@ -2458,6 +2458,15 @@ + } + + sem = zink_create_exportable_semaphore(screen); ++ if (unlikely(!sem)) { ++ static bool warned; ++ if (!warned) { ++ warned = true; ++ mesa_loge("MESA: Unable to create an exportable semaphore; skipping implicit sync for dma-bufs"); ++ } ++ close(export.fd); ++ return VK_NULL_HANDLE; ++ } + + const VkImportSemaphoreFdInfoKHR sdi = { + .sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,