Compare commits

..
Author SHA1 Message Date
The412Banner c80014953c fix(venus): report a pipeline the Mali driver refuses instead of losing the context
Venus sent pipeline creates from the device's own thread without waiting and
assumed they succeeded. When the phone's Mali driver refused one, the render
server had no object for its id and the next vkCmdBindPipeline killed the
whole context: Steam's web helper died two seconds after Big Picture appeared
on a Mali-G52 MC2. Under vtest every thread now waits for the result, so the
application gets the driver's error, and the render server logs each refused
pipeline with its VkResult.
2026-11-26 11:51:16 +00:00
8 changed files with 106 additions and 36 deletions

No files matched your search

@@ -59,8 +59,19 @@ class GpuMemComponent(private val file: File, private val root: File) : SessionP
private fun sessionPids(): List<String> =
File("/proc").list()?.filter { it.isNotEmpty() && it.all(Char::isDigit) }.orEmpty()
private fun kgslMappedKb(pid: String): Long? =
runCatching { File("/proc/$pid/maps").useLines(MemoryReadout::gpuMappedKb) }.getOrNull()
private fun kgslMappedKb(pid: String): Long? = runCatching {
var bytes = 0L
File("/proc/$pid/maps").forEachLine { line ->
if (line.endsWith("kgsl-3d0") || line.contains("/dev/dri/renderD")) {
val dash = line.indexOf('-')
val space = line.indexOf(' ')
if (dash > 0 && space > dash) {
bytes += line.substring(dash + 1, space).toLong(16) - line.substring(0, dash).toLong(16)
}
}
}
bytes / 1024
}.getOrNull()
private fun write(bytes: Long) {
try {
@@ -73,27 +73,9 @@ internal object MemoryReadout {
}
children[pid]?.let(queue::addAll)
}
return Split(game, droiddeck, gpuKb() ?: mappedGpuKb(seen))
return Split(game, droiddeck, gpuKb())
}
fun gpuMappedKb(maps: Sequence<String>): Long {
var bytes = 0L
maps.forEach { line ->
if (line.endsWith("kgsl-3d0") || line.contains("/dev/dri/renderD")) {
val dash = line.indexOf('-')
val space = line.indexOf(' ')
if (dash > 0 && space > dash) {
bytes += line.substring(dash + 1, space).toLong(16) - line.substring(0, dash).toLong(16)
}
}
}
return bytes / 1024
}
private fun mappedGpuKb(pids: Collection<Int>): Long? =
pids.sumOf { pid -> runCatching { File("/proc/$pid/maps").useLines(::gpuMappedKb) }.getOrDefault(0L) }
.takeIf { it > 0 }
private fun parentOf(pid: Int): Int? {
val stat = runCatching { File("/proc/$pid/stat").readText() }.getOrNull() ?: return null
val close = stat.lastIndexOf(')')
@@ -54,20 +54,6 @@ class MemoryReadoutTest {
assertEquals(0L, MemoryReadout.androidKb(device, MemoryReadout.Split(gameKb = 6_000, droiddeckKb = 2_000, gpuKb = 1_000)))
}
@Test fun gpuMemoryIsWhatTheGpuNodesMapIntoAProcess() {
val maps = """
7a00000000-7a00200000 rw-s 100000000 00:0c 512 /dev/dri/renderD128
7a00200000-7a00600000 rw-s 100200000 00:0c 512 /dev/dri/renderD128
7b00000000-7b00100000 rw-s 00000000 00:0d 300 /dev/kgsl-3d0
7c00000000-7c40000000 rw-p 00000000 00:00 0 [anon:dalvik-main space]
7d00000000-7d00400000 rw-s 00000000 00:0e 77 /dmabuf:
7e00000000-7e00100000 r--p 00000000 fd:00 1234 /data/app/lib/arm64/libdroiddeck.so
""".trimIndent()
assertEquals(2048L + 4096L + 1024L, MemoryReadout.gpuMappedKb(maps.lineSequence()))
assertEquals(0L, MemoryReadout.gpuMappedKb(maps.lineSequence().drop(3)))
assertEquals(0L, MemoryReadout.gpuMappedKb(emptySequence()))
}
@Test fun theLogLineSaysEveryPartInMegabytes() {
val device = MemoryReadout.Device(totalKb = 11_379_920, availableKb = 1_048_576, swapTotalKb = 16_777_212, swapFreeKb = 8_388_606)
val split = MemoryReadout.Split(gameKb = 2_097_152, droiddeckKb = 524_288, gpuKb = 3_145_728)
+6
View File
@@ -199,6 +199,10 @@ App (Kotlin/C):
- `vn_queue_submission_init_syncs` submits only the sync slots it filled.
- Timeline semaphores free all `queue_count + 1` renderer syncs. Upstream freed one too few and leaked a vtest sync each.
- `vn_queue_submit` runs under a per-queue `submit_mutex`. The async present thread raced the app's submits; see Status.
- Pipelines are created synchronously under vtest, on the thread that created the device too.
- Upstream sends that thread's creates without waiting and assumes they succeed. A phone's Mali driver can refuse one, and the render server then has no object for the id.
- The next command that names it, such as `vkCmdBindPipeline`, is fatal to the whole context. A Mali-G52 MC2 lost Steam's web helper this way two seconds after Big Picture appeared.
- Waiting returns the driver's error to the application, and Venus frees the failed handles.
- WSI's CPU readback buffer goes to Mali's hidden cached memory type; see Performance.
- `vn_physical_device`: keeps the renderer's real memory flags, and picks the hidden type under vtest.
- `vn_renderer_vtest.c`: flush and invalidate of incoherent memory are `DMA_BUF_IOCTL_SYNC` on the bo's dma-buf.
@@ -220,6 +224,8 @@ App (Kotlin/C):
- Exports of any memory type go through that allocator.
- Logs what the driver reports, and failed allocations.
`tools/venus/virglrenderer-log-refused-pipeline.patch`: when the driver refuses a graphics or compute pipeline, the render server logs the `VkResult` and the number of pipelines.
`tools/gamescope/patches/0927-shm-buffers-upload-every-commit.patch`:
- Xwayland has no glamor here, so it reuses about three wl_shm buffers with new pixels.
- gamescope cached one texture per buffer, copied at first import.
+42
View File
@@ -0,0 +1,42 @@
import re
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[2]
VENUS = ROOT / "tools/venus"
def added_lines(patch, path):
lines = []
in_file = False
for line in patch.splitlines():
if line.startswith("diff --git "):
in_file = line.endswith(" b/" + path)
elif in_file and line.startswith("+") and not line.startswith("+++"):
lines.append(line[1:].strip())
return lines
class VenusPatchesTest(unittest.TestCase):
def test_the_build_applies_every_virglrenderer_patch(self):
script = (VENUS / "ci-build.sh").read_text()
applied = set(re.findall(r'apply "\$REPO/tools/venus/(virglrenderer-[^"]+\.patch)"', script))
shipped = {path.name for path in VENUS.glob("virglrenderer-*.patch")}
self.assertEqual(shipped, applied)
def test_pipelines_are_created_synchronously_over_vtest(self):
patch = (VENUS / "mesa-venus-vtest.patch").read_text()
added = added_lines(patch, "src/virtio/vulkan/vn_device.c")
gate = added.index("if (!VN_DEBUG(VTEST))")
self.assertEqual("vn_tls_set_async_pipeline_create();", added[gate + 1])
def test_the_render_server_logs_every_pipeline_the_driver_refuses(self):
patch = (VENUS / "virglrenderer-log-refused-pipeline.patch").read_text()
added = "\n".join(added_lines(patch, "src/venus/vkr_pipeline.c"))
for kind in ("Graphics", "Compute"):
self.assertIn(f'vkr_log("vkCreate{kind}Pipelines failed with %d for %u pipelines"', added)
if __name__ == "__main__":
unittest.main()
+1
View File
@@ -80,6 +80,7 @@ git clone -q --depth 1 -b virglrenderer-1.3.0 https://gitlab.freedesktop.org/vir
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-android.patch"
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-unknown-pipeline.patch"
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-destroy-mutex-after-objects.patch"
git -C virglrenderer apply "$REPO/tools/venus/virglrenderer-log-refused-pipeline.patch"
cat > compat/log/log.h <<'EOC'
#pragma once
#include <android/log.h>
+11 -1
View File
@@ -1,5 +1,5 @@
diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c
index f42b9f9..6ed3051 100644
index f42b9f9..73f91e9 100644
--- a/src/virtio/vulkan/vn_device.c
+++ b/src/virtio/vulkan/vn_device.c
@@ -45,6 +45,7 @@ vn_queue_fini(struct vn_queue *queue)
@@ -18,6 +18,16 @@ index f42b9f9..6ed3051 100644
if (dev->physical_device->emulate_second_queue ==
queue_info->queueFamilyIndex &&
@@ -613,7 +615,8 @@ vn_CreateDevice(VkPhysicalDevice physicalDevice,
vn_log(instance, "%s", physical_dev->base.vk.properties.driverInfo);
}
- vn_tls_set_async_pipeline_create();
+ if (!VN_DEBUG(VTEST))
+ vn_tls_set_async_pipeline_create();
*pDevice = vn_device_to_handle(dev);
diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c
index 8b6eb4c..be146b6 100644
--- a/src/virtio/vulkan/vn_device_memory.c
@@ -0,0 +1,32 @@
diff --git a/src/venus/vkr_pipeline.c b/src/venus/vkr_pipeline.c
index 76709b9..4dbd0f6 100644
--- a/src/venus/vkr_pipeline.c
+++ b/src/venus/vkr_pipeline.c
@@ -114,8 +114,12 @@ vkr_dispatch_vkCreateGraphicsPipelines(struct vn_dispatch_context *dispatch,
struct vkr_device *dev = vkr_device_from_handle(args->device);
struct object_array arr;
- if (vkr_graphics_pipeline_create_array(ctx, args, &arr) < VK_SUCCESS)
+ const VkResult result = vkr_graphics_pipeline_create_array(ctx, args, &arr);
+ if (result < VK_SUCCESS) {
+ vkr_log("vkCreateGraphicsPipelines failed with %d for %u pipelines", result,
+ args->createInfoCount);
return;
+ }
vkr_pipeline_add_array(ctx, dev, &arr, args->pPipelines);
}
@@ -129,8 +133,12 @@ vkr_dispatch_vkCreateComputePipelines(struct vn_dispatch_context *dispatch,
struct vkr_device *dev = vkr_device_from_handle(args->device);
struct object_array arr;
- if (vkr_compute_pipeline_create_array(ctx, args, &arr) < VK_SUCCESS)
+ const VkResult result = vkr_compute_pipeline_create_array(ctx, args, &arr);
+ if (result < VK_SUCCESS) {
+ vkr_log("vkCreateComputePipelines failed with %d for %u pipelines", result,
+ args->createInfoCount);
return;
+ }
vkr_pipeline_add_array(ctx, dev, &arr, args->pPipelines);
}