Skip to content

tu/kgsl, wsi/x11: wait for rendering before presenting in every mode - #122

Merged
lfdevs merged 2 commits into
lfdevs:dev/adreno-mainfrom
gramarye-os:upstream/turnip-kgsl-present-wait
Nov 17, 2026
Merged

lfdevs merged 2 commits into
lfdevs:dev/adreno-mainfrom
gramarye-os:upstream/turnip-kgsl-present-wait

Conversation

@injinj

@injinj injinj commented Nov 16, 2026

Copy link
Copy Markdown

Follow-up to #96, for Vulkan. kgsl puts no fence on a dma-buf, and the X11 WSI waits for an image's fence itself only in mailbox mode. In fifo and immediate mode the X server can read a frame the GPU is still drawing, which shows as tearing. Zink presents through the same swapchain.

This adds wsi_device::x11.wait_for_fences, which makes the X11 WSI wait in every present mode, and sets it in turnip on kgsl. TU_KGSL_PRESENT_WAIT=0 turns it off.

Adreno 830, Debian trixie, built on b84f02a. Torn frames of 150, with a test client that gives the GPU about 15 ms of work per frame:

  • immediate: 129 before, 0 after
  • fifo: 125 before, 0 after
  • mailbox: 0 before, 0 after
  • Zink: 4 before, 0 after

Things to know:

  • Tested with one X server only, a Termux:X11 fork that copies the pixmap on the CPU. Not tested with stock Termux:X11 or XWayland. The flag also makes turnip wait under XWayland, where the WSI does not wait today.
  • Cost: with vsync, no change. Without vsync, glxgears on Zink went from about 2800 to 1950 fps.
  • It touches shared WSI code: one flag, off unless a driver sets it.

Test client: https://github.com/gramarye-os/tessera-linux/blob/gramarye-env/gramarye/vkteartest.c

kgsl puts no fence on a dma-buf, so an X server cannot wait for the GPU
before it reads a presented image. The X11 WSI waits for the image's
fence itself only in mailbox mode. In fifo and immediate mode the server
can read a frame that is still being drawn, which shows as tearing.

Add wsi_device::x11.wait_for_fences, which makes the X11 WSI wait in
every present mode, and set it in turnip on kgsl. Zink presents through
the same swapchain, so it is covered too. TU_KGSL_PRESENT_WAIT=0 turns
the wait off.

Adreno 830, Termux:X11-based server that copies on the CPU, torn frames
of 150 at about 15 ms of GPU work per frame:
  immediate: 129 before, 0 after
  fifo:      125 before, 0 after
  mailbox:   0 before, 0 after
@lfdevs

lfdevs commented Nov 17, 2026

Copy link
Copy Markdown
Owner

I tested it in a Debian 13 Chroot container on the Xiaomi Pad 6 Pro (Adreno 730), and here are my findings:

x11_needs_wait_for_fences() now returns true for KGSL in every present mode (src/vulkan/wsi/wsi_common_x11.c:2060). The same predicate is used by x11_requires_mailbox_image_count() (:2139), so the swapchain creation path raises IMMEDIATE, FIFO, and FIFO_RELAXED from three to four images (:3382).

This is a compatibility and latency regression. The surrounding comment already notes that changing image counts for IMMEDIATE/FIFO can break applications and increase memory usage. On the Xiaomi Pad 6 Pro, requesting three images produced:

  • Before: IMMEDIATE 3, MAILBOX 4, FIFO 3, FIFO_RELAXED 3
  • This PR: IMMEDIATE 4, MAILBOX 4, FIFO 4, FIFO_RELAXED 4

Please decouple the rendering-wait decision from the mailbox image-count decision, keeping the four-image requirement limited to MAILBOX.

x11.wait_for_fences made x11_needs_wait_for_fences() true in every present
mode. x11_requires_mailbox_image_count() uses the same function, so
immediate, fifo and fifo_relaxed swapchains went from three images to four.

Check the flag where the present queue waits for the fence, and leave
x11_needs_wait_for_fences() as it was. Only mailbox asks for four images
again.
@injinj

injinj commented Nov 17, 2026

Copy link
Copy Markdown
Author

You are right, thanks for testing it. x11_needs_wait_for_fences() also feeds x11_requires_mailbox_image_count(), and I missed that. I pushed a second commit that leaves x11_needs_wait_for_fences() as it was and checks the flag only where the present queue waits for the fence. On an Adreno 830, asking for 3 images: before 4/4/4 (IMMEDIATE/FIFO/MAILBOX), now 3/3/4. Still 0 torn frames of 150 in all three modes at four loads, and in Zink. I have not tested FIFO_RELAXED. I can squash the two commits if you prefer.

@lfdevs
lfdevs merged commit 0be364b into lfdevs:dev/adreno-main Nov 17, 2026
17 checks passed
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.

2 participants