Skip to content

linux: show dmabuf frames from another process - #862

Merged
thdxr merged 2 commits into
devfrom
linux-dmabuf
Nov 18, 2026
Merged

thdxr merged 2 commits into
devfrom
linux-dmabuf

Conversation

@thdxr

@thdxr thdxr commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

adds NativeSurface::push_dmabuf on linux, same shape as the windows shared textures. a producer renders DRM_FORMAT_ARGB8888 into single-plane linear dmabufs on the gpu native_surface::linux::import_target() names (the window device's render node, from VK_EXT_physical_device_drm). rune imports each buffer once with wgpu-hal's texture_from_dmabuf_fd, copies a frame into its own texture the first time it draws it and draws that copy from then on, and calls the frame's on_read once the gpu finished the copy. vulkan devices on linux ask for VULKAN_EXTERNAL_MEMORY_DMA_BUF when the driver has it.

  • on_read runs from a small waiter thread (device.poll(Wait { submission_index })), so an idle window that draws nothing more still frees the producer's buffer
  • every failure (size limit, no dmabuf support, bad buffer, import error) reaches on_read as Err
  • the copy lives on the Dmabuf per device, so a redraw or a second window never re-reads a buffer the producer may be writing again
  • imported buffers are dropped every prepare once their frames are gone, and capped at 16 / 512 MB
  • only linear argb8888 is accepted; DmabufBuffer::new takes a DmabufPlane and fourcc and checks stride >= width4 and offset + strideheight against the fd's size, so bad input is a clean error
  • ImportTarget is #[non_exhaustive]

checked on an amd 8060s (radv) with opencode (rune)'s chromium engine: 60 fps, pixels match the bgra path for css, webgl and webgpu pages, idle-then-update works, engine kill and restart keeps flowing. used by anomalyco/opencode-rune#107.

the imported image starts undefined and stays in copy-source; fine for linear buffers (no compression metadata), noted in the code.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr
thdxr merged commit 4a2e437 into dev Nov 18, 2026
1 check 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.

1 participant