Skip to content

perf: optimize IPC socket buffers, enable async compile & desc batch in perf mode, inline wire decoders, add Mali-Gxxx presets - #39

Open
wwmaxik wants to merge 3 commits into
ASEbrahim:mainfrom
wwmaxik:perf-opt-pipeline-ipc
Open

wwmaxik wants to merge 3 commits into
ASEbrahim:mainfrom
wwmaxik:perf-opt-pipeline-ipc

Conversation

@wwmaxik

@wwmaxik wwmaxik commented Oct 28, 2026 •

Copy link
Copy Markdown

Overview

This pull request brings several targeted performance, stability, and latency optimizations to MaliBridge, particularly beneficial for Valhall and 5th Gen ARM Mali GPUs (e.g. Mali-G610, G710, G720, G925) when running games under Proton / DXVK / vkd3d:

1. IPC Socket Buffer Tuning (SO_SNDBUF / SO_RCVBUF)

  • Increases UNIX domain socket buffer sizes (SO_SNDBUF & SO_RCVBUF) to 2 MB on both the client (client/conn.c) and server (server/server_conn.c).
  • Default Linux AF_UNIX buffers (~212 KB) frequently trigger client blocking and thread context switching under high-throughput draw call / descriptor streams. A 2 MB buffer eliminates these stalls and lowers IPC overhead.

2. Enable Descriptor Batching by Default in Performance Mode

  • Updates desc_batch() in client/conn.c so that VKB_CLIENT_MODE_PERFORMANCE enables descriptor batching (by_mode[VKB_CLIENT_MODE_PERFORMANCE] = 1).
  • Reduces repeated single-descriptor update traffic between client and server by over 130x (from ~40k messages to 248 messages in high-draw benchmarks).

3. Default Asynchronous Pipeline Compilation in Performance Mode

  • In server/server_async.c, automatically enables asynchronous graphics pipeline compilation (on = 1) when vkb_mode() == VKB_MODE_PERFORMANCE, unless explicitly overridden by VKBRIDGE_ASYNC_COMPILE.
  • Greatly reduces shader compilation stutter and frame-time spikes on Mali devices lacking VK_EXT_graphics_pipeline_library.

4. Fast-path Inlined Wire Scalar Decoders & Alignment

  • Inlined vkb_dec_u8, vkb_dec_u32, and vkb_dec_u64 in common/vkb_wire.h with direct bounds check and unaligned word loading.
  • Fast 8-byte aligned recording in client/cmdbuf.c.
  • Eliminates repeated function call overhead on hotpath wire deserialization during draw call processing.

5. Built-in Tested Mali Valhall / 5th Gen Presets

  • Updated server/presets_builtin.inc to match Mali GPUs (Mali-G610,Mali-G710,Mali-G720,Mali-G925) with ASTC 6x6 texture compression block size and fast BC transcoding (VKBRIDGE_BC_ASTC_BLOCK=6x6 VKBRIDGE_BC_TRANSCODE_QUALITY=fast).

6. Linked GPL Pipeline Library Retention (server/server_errata_flip.c)

  • Unconditionally retain and reference count links->pLibraries in r->libs via obj_ref_locked on executable pipelines linked from pipeline libraries (VK_EXT_graphics_pipeline_library).
  • Ensures underlying library pipeline objects on the driver remain valid until the executable linked pipeline is destroyed, fixing state degradation and viewport/depth range issues.

7. Thread-Safety & UAF Fix in Pipeline Cache Saver (server/server_pcache.c)

  • Hold save_lock throughout device destruction in vkb_pcache_device_destroy, and hold pc_lock while stepping the list in the saver thread.
  • Eliminates a race condition and use-after-free crash when devices are destroyed while the background saver thread is running.

8. Vertex Input Dynamic State Device Cleanup on Process Exit (server/server_conn.c)

  • Added missing vkb_vidyn_device_destroy(t) call in vkb_proc_cleanup when a process exits abruptly without calling vkDestroyDevice.
  • Eliminates dangling pointers in the global all list and fixes SIGSEGV during survivor cleanup.

Testing

  • Verified on host test suite (make -C host && out/hotpath_bench).
  • Verified with regression suite (viewport_test.sh, mode_test.sh, flicker_check, desc_traffic_check, exitclean_check).
  • Tested on physical hardware (Xiaomi 13T, MT6896, Mali-G610 MC6, Vulkan 1.3.305).

wwmaxik added 3 commits October 28, 2026 15:06
…in perf mode, inline wire decoders, add Mali-Gxxx presets
…d dead-process cleanup

- server_errata_flip: unconditionally retain and refcount linked GPL pipeline
  libraries so underlying driver objects remain valid on Mesa and Mali until
  the executable linked pipeline is destroyed.
- server_pcache: hold save_lock throughout device destroy and pc_lock during
  saver iteration, eliminating a race condition and use-after-free when
  devices are destroyed while the saver thread is active.
- server_conn: call vkb_vidyn_device_destroy during dead-process device
  cleanup in vkb_proc_cleanup to unlink from global list, preventing SIGSEGV.
- host/mode_test.sh: update step 6 assertions for descriptor batching enabled
  in performance mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant