fix(flatpak): expose the runtime GPU to accelerated desktop windows (#2699)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-17 11:09:12 -05:00
1 parent 637f4b21ee
commit 2be0ba58c7
2 files changed
+40 -3

No files matched your search

@@ -218,12 +218,15 @@ object BwrapSpawner {
private fun runtimeLib(rootfs: String, name: String): File? =
LIB_DIRS.map { File(rootfs, "$it/$name") }.firstOrNull { it.exists() }
private fun gpu(rootfs: String, root: File, env: MutableMap<String, String>): List<Bind>? {
internal fun gpu(
rootfs: String, root: File, env: MutableMap<String, String>,
kgslAvailable: Boolean = File("/dev/kgsl-3d0").exists(),
): List<Bind>? {
env["VKBRIDGE_SOCKET"]?.let { sock -> if (File(sock).exists()) return bridgeGpu(rootfs, root, env, sock) }
val driver = runtimeLib(rootfs, "libvulkan_freedreno.so")
if (driver == null || !File("/dev/kgsl-3d0").exists()) return null
if (driver == null || !kgslAvailable) return null
if (env.containsKey("VK_ICD_FILENAMES") || env.containsKey("VK_DRIVER_FILES")) return null
if (env["BL_DESKTOP"] == "1" && env["GAMESCOPE_WAYLAND_DISPLAY"] == null) return null
if (env["LIBGL_ALWAYS_SOFTWARE"] == "1" && env["GAMESCOPE_WAYLAND_DISPLAY"] == null) return null
val binds = arrayListOf(Bind(driver.canonicalPath, "$GPU_DIR/libvulkan_freedreno.so"))
for (name in GPU_LIBS) {
val f = runtimeLib(rootfs, name) ?: continue
@@ -112,6 +112,40 @@ class BwrapSpawnerPlanTest {
.put("cwd", "/app")
.put("ops", JSONArray().apply { ops.forEach { put(it) } })
@Test fun desktopSandboxesGetTheRuntimeGpuWithoutReplacingExplicitChoices() {
val lib = File(runtime, "usr/lib/aarch64-linux-gnu/libvulkan_freedreno.so")
lib.parentFile!!.mkdirs()
lib.writeText("")
val root = File(dir, "root").apply { mkdirs() }
for (session in listOf(emptyMap(), mapOf("BL_DESKTOP" to "1"),
mapOf("BL_DESKTOP" to "1", "GALLIUM_DRIVER" to "zink", "MESA_LOADER_DRIVER_OVERRIDE" to "zink"))) {
val env = session.toMutableMap()
val binds = BwrapSpawner.gpu(runtime.path, root, env, true)!!
assertTrue(binds.any { it.host == lib.canonicalPath && it.guest == "/run/droiddeck-gpu/libvulkan_freedreno.so" })
assertEquals("/run/droiddeck-gpu/freedreno_icd.json", env["VK_DRIVER_FILES"])
assertEquals("zink", env["GALLIUM_DRIVER"])
assertEquals(session["BL_DESKTOP"], env["BL_DESKTOP"])
}
for (choice in listOf(mapOf("VK_DRIVER_FILES" to "/custom/icd.json"),
mapOf("VK_ICD_FILENAMES" to ""), mapOf("LIBGL_ALWAYS_SOFTWARE" to "1"))) {
val env = (choice + ("BL_DESKTOP" to "1")).toMutableMap()
val original = env.toMap()
assertEquals(null, BwrapSpawner.gpu(runtime.path, root, env, true))
assertEquals(original, env)
}
val env = mutableMapOf("BL_DESKTOP" to "1", "GALLIUM_DRIVER" to "llvmpipe")
assertTrue(BwrapSpawner.gpu(runtime.path, root, env, true)!!.isNotEmpty())
assertEquals("llvmpipe", env["GALLIUM_DRIVER"])
val gamescope = mutableMapOf("BL_DESKTOP" to "1", "LIBGL_ALWAYS_SOFTWARE" to "1", "GAMESCOPE_WAYLAND_DISPLAY" to "gamescope-0")
assertTrue(BwrapSpawner.gpu(runtime.path, root, gamescope, true)!!.isNotEmpty())
val unavailable = mutableMapOf("BL_DESKTOP" to "1")
assertEquals(null, BwrapSpawner.gpu(runtime.path, root, unavailable, false))
assertEquals(mapOf("BL_DESKTOP" to "1"), unavailable)
assertTrue(lib.delete())
assertEquals(null, BwrapSpawner.gpu(runtime.path, root, unavailable, true))
assertEquals(mapOf("BL_DESKTOP" to "1"), unavailable)
}
@Test fun buildsTheTreeFlatpakAsksFor() {
val context = RuntimeEnvironment.getApplication()
val info = Base64.encodeToString("[Application]\nname=org.example.Game\n".toByteArray(), Base64.NO_WRAP)