mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
Discover and propagate the actual PowerVR render node
This commit is contained in:
1 parent
5588fedf1d
commit
3ee7c4afbb
5 files changed
+148
-11
No files matched your search
@@ -14,7 +14,9 @@ import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/** Isolated glibc-to-Android Vulkan bridge. It does not replace the rootfs's Mesa libraries. */
|
||||
@@ -40,15 +42,60 @@ public final class SystemVulkanDriver {
|
||||
public static boolean isAvailable() { return isPowerVr() && renderNodeAvailable(); }
|
||||
|
||||
public static boolean renderNodeAvailable() {
|
||||
String node = "/dev/dri/renderD128";
|
||||
return renderNodePath() != null;
|
||||
}
|
||||
|
||||
/** Select the actual PowerVR node, including devices where another GPU owns renderD128. */
|
||||
public static String renderNodePath() {
|
||||
String[] nodes = new File("/dev/dri").list();
|
||||
if (nodes == null) nodes = new File("/sys/class/drm").list();
|
||||
return findRenderNode(nodes, SystemVulkanDriver::renderNodeAvailable);
|
||||
}
|
||||
|
||||
static String findRenderNode(String[] nodes, Predicate<String> available) {
|
||||
TreeSet<String> candidates = new TreeSet<>();
|
||||
// Android can deny directory listing while allowing direct access. Probe the kernel's
|
||||
// reserved render range too; directory entries also cover dynamically allocated minors.
|
||||
for (int minor = 128; minor < 192; minor++) candidates.add("renderD" + minor);
|
||||
if (nodes != null) for (String node : nodes)
|
||||
if (node.matches("renderD[0-9]+")) candidates.add(node);
|
||||
for (String node : candidates) {
|
||||
String path = "/dev/dri/" + node;
|
||||
if (available.test(path)) return path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean renderNodeAvailable(String node) {
|
||||
try {
|
||||
return renderNodeAvailable(OsConstants.S_ISCHR(Os.stat(node).st_mode),
|
||||
Os.access(node, OsConstants.R_OK), Os.access(node, OsConstants.W_OK));
|
||||
if (!renderNodeAvailable(OsConstants.S_ISCHR(Os.stat(node).st_mode),
|
||||
Os.access(node, OsConstants.R_OK), Os.access(node, OsConstants.W_OK))) return false;
|
||||
return powerVrDevice(new File("/sys/class/drm/" + new File(node).getName() + "/device"));
|
||||
} catch (ErrnoException error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean powerVrDriver(String driver) {
|
||||
return "pvrsrvkm".equals(driver) || "pvr".equals(driver) || "powervr".equals(driver);
|
||||
}
|
||||
|
||||
static boolean powerVrDevice(File device) {
|
||||
try {
|
||||
return powerVrDriver(Files.readSymbolicLink(new File(device, "driver").toPath())
|
||||
.getFileName().toString());
|
||||
} catch (IOException error) {
|
||||
// Some Android policies expose uevent but deny reading the driver symlink.
|
||||
try (BufferedReader input = Files.newBufferedReader(
|
||||
new File(device, "uevent").toPath(), StandardCharsets.US_ASCII)) {
|
||||
String line;
|
||||
while ((line = input.readLine()) != null)
|
||||
if (line.startsWith("DRIVER=")) return powerVrDriver(line.substring(7));
|
||||
} catch (IOException ignored) { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean renderNodeAvailable(boolean characterDevice, boolean readable, boolean writable) {
|
||||
return characterDevice && readable && writable;
|
||||
}
|
||||
@@ -65,7 +112,7 @@ public final class SystemVulkanDriver {
|
||||
public static synchronized File prepare(Context context) throws IOException {
|
||||
if (!isPowerVr()) throw new IOException("System PowerVR Vulkan driver is unavailable");
|
||||
if (!renderNodeAvailable()) throw new IOException(
|
||||
"System PowerVR requires a readable and writable character device at /dev/dri/renderD128");
|
||||
"System PowerVR requires an identifiable, readable and writable DRM render node");
|
||||
File target = runtimeDirectory(context);
|
||||
File base = target.getParentFile();
|
||||
if (complete(target)) return target;
|
||||
@@ -128,6 +175,8 @@ public final class SystemVulkanDriver {
|
||||
File directory;
|
||||
try { directory = prepare(context); }
|
||||
catch (IOException error) { throw new IllegalStateException("System Vulkan runtime is unavailable", error); }
|
||||
String node = renderNodePath();
|
||||
if (node == null) throw new IllegalStateException("System PowerVR render node is unavailable");
|
||||
environment.add("HYBRIS_ANDROID_SDK_VERSION=" + Build.VERSION.SDK_INT);
|
||||
environment.add("HYBRIS_VULKAN_HAL=" + HAL);
|
||||
environment.add("HYBRIS_LINKER_DIR=" + new File(directory, "lib/libhybris/linker").getPath());
|
||||
@@ -139,6 +188,7 @@ public final class SystemVulkanDriver {
|
||||
environment.add("BL_GAMESCOPE_BACKEND=sdl");
|
||||
// The Android pvr kernel accepts Vulkan DMA-BUF imports but rejects PRIME GEM handles.
|
||||
environment.add("BL_POWERVR_DRM_HANDLES=1");
|
||||
environment.add("BL_POWERVR_RENDER_NODE=" + node);
|
||||
// Inner Gamescope/Xwayland lacks the bridge's Android-buffer WSI protocols.
|
||||
environment.add("BL_STEAM_GL_PRESENT=1");
|
||||
// Only actual Proton game launches use the bundled DXVK and X11 WSI layer.
|
||||
|
||||
@@ -307,19 +307,21 @@ public final class LinuxRuntime {
|
||||
*/
|
||||
private static void bindPowerVrGpuNode(Context context, List<String> cmd) {
|
||||
if (new File("/dev/dri").list() != null) return;
|
||||
String node = "/dev/dri/renderD128";
|
||||
File dri = new File(context.getCacheDir(), "powervr-drm/dri");
|
||||
String node = SystemVulkanDriver.renderNodePath();
|
||||
if (node == null) return;
|
||||
String name = new File(node).getName();
|
||||
// Keep only this node listable even if a previous boot assigned a different minor.
|
||||
File dri = new File(context.getCacheDir(), "powervr-drm/" + name + "/dri");
|
||||
try {
|
||||
if (!SystemVulkanDriver.renderNodeAvailable()) return;
|
||||
if (!dri.isDirectory() && !dri.mkdirs()) return;
|
||||
new File(dri, "renderD128").createNewFile();
|
||||
new File(dri, name).createNewFile();
|
||||
} catch (IOException e) {
|
||||
android.util.Log.w("LinuxRuntime", "Cannot expose the PowerVR render node", e);
|
||||
return;
|
||||
}
|
||||
bind(cmd, dri.getPath() + ":/dev/dri");
|
||||
bind(cmd, node + ":" + node);
|
||||
android.util.Log.i("LinuxRuntime", "PowerVR: exposing real renderD128 through a listable directory");
|
||||
android.util.Log.i("LinuxRuntime", "PowerVR: exposing real " + name + " through a listable directory");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.droiddeck.launcher.gpu
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertFalse
|
||||
@@ -26,6 +28,66 @@ class SystemVulkanSelectionTest {
|
||||
assertFalse("a missing node is unavailable", SystemVulkanDriver.renderNodeAvailable(false, false, false))
|
||||
}
|
||||
|
||||
@Test fun renderNodeDriverMustIdentifyPowerVrExactly() {
|
||||
for (name in listOf("pvrsrvkm", "pvr", "powervr"))
|
||||
assertTrue(name, SystemVulkanDriver.powerVrDriver(name))
|
||||
for (name in listOf(null, "", "msm", "panfrost", "not-pvr"))
|
||||
assertFalse(name, SystemVulkanDriver.powerVrDriver(name))
|
||||
}
|
||||
|
||||
@Test fun renderNodeIdentityUsesTheDriverLinkOrUevent() {
|
||||
val device = Files.createTempDirectory("powervr-device").toFile()
|
||||
try {
|
||||
assertFalse("missing identity is unavailable", SystemVulkanDriver.powerVrDevice(device))
|
||||
val uevent = File(device, "uevent")
|
||||
uevent.writeText("DRIVER=pvrsrvkm\nOF_NAME=gpu0\n")
|
||||
assertTrue(SystemVulkanDriver.powerVrDevice(device))
|
||||
uevent.writeText("DRIVER=msm\nOF_COMPATIBLE_0=not-pvr\n")
|
||||
assertFalse(SystemVulkanDriver.powerVrDevice(device))
|
||||
val driver = File(device, "driver").toPath()
|
||||
Files.createSymbolicLink(driver, File("../../drivers/pvrsrvkm").toPath())
|
||||
assertTrue(SystemVulkanDriver.powerVrDevice(device))
|
||||
Files.delete(driver)
|
||||
Files.createSymbolicLink(driver, File("../../drivers/msm").toPath())
|
||||
uevent.writeText("DRIVER=pvrsrvkm\n")
|
||||
assertFalse("an unrelated driver link must not fall back", SystemVulkanDriver.powerVrDevice(device))
|
||||
} finally {
|
||||
device.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun renderNodeDiscoverySkipsOtherDriversAndDeniedNodes() {
|
||||
val drivers = mapOf(
|
||||
"/dev/dri/renderD128" to "msm",
|
||||
"/dev/dri/renderD129" to "pvr",
|
||||
"/dev/dri/renderD130" to "pvrsrvkm",
|
||||
)
|
||||
assertEquals("/dev/dri/renderD129", SystemVulkanDriver.findRenderNode(null) { path ->
|
||||
SystemVulkanDriver.powerVrDriver(drivers[path])
|
||||
})
|
||||
assertEquals("/dev/dri/renderD130", SystemVulkanDriver.findRenderNode(null) { path ->
|
||||
SystemVulkanDriver.powerVrDriver(drivers[path]) &&
|
||||
SystemVulkanDriver.renderNodeAvailable(true, path != "/dev/dri/renderD129", true)
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun renderNodesAreDiscoveredWithoutDirectoryListing() {
|
||||
for (minor in listOf(128, 129, 191)) {
|
||||
val expected = "/dev/dri/renderD$minor"
|
||||
assertEquals(expected, SystemVulkanDriver.findRenderNode(null) { it == expected })
|
||||
}
|
||||
assertNull(SystemVulkanDriver.findRenderNode(null) { false })
|
||||
}
|
||||
|
||||
@Test fun listedRenderNodesCoverExtendedMinorNumbers() {
|
||||
assertEquals("/dev/dri/renderD256", SystemVulkanDriver.findRenderNode(
|
||||
arrayOf("card0", "renderD256", "renderD128/device", "../renderD129"),
|
||||
) { path ->
|
||||
assertTrue(path, path.matches(Regex("/dev/dri/renderD[0-9]+")))
|
||||
path == "/dev/dri/renderD256"
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun defaultPowerVrResolvesToTheSystemIcd() {
|
||||
assertEquals("system/icd.json", LinuxVulkanDriver.resolveIcdPath("", true,
|
||||
{ "system/icd.json" }, { error("default must not resolve an import") }))
|
||||
|
||||
Reference in new issue
Block a user