Skip to content

freedreno/kgsl: opt in to linear dma-buf sharing#85

Merged
lfdevs merged 1 commit into
dev/adreno-mainfrom
test/support-xwayland-surfaceless
Jul 9, 2026
Merged

freedreno/kgsl: opt in to linear dma-buf sharing#85
lfdevs merged 1 commit into
dev/adreno-mainfrom
test/support-xwayland-surfaceless

Conversation

@lfdevs

@lfdevs lfdevs commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Also see: lfdevs/xwayland#1

Summary

This teaches the freedreno KGSL path to expose a narrow dma-buf import/export contract for surfaceless/XWayland consumers: shared linear buffers only.

The KGSL stack can allocate shareable buffers through dma-heap/ION and import them into KGSL, but native KGSL allocations are not directly exportable as dma-bufs. This change makes that distinction explicit, constrains exported/imported modifiers to LINEAR when the KGSL dma-buf path is enabled, and shadows non-shared resources into shared linear resources before export.

The KGSL dma-buf sharing behavior is intentionally opt-in, so the normal chroot DRM/GBM path keeps its previous behavior.

Changes

  • Add an explicit FD_FEATURE_KGSL winsys feature and store it as screen->is_kgsl.
  • Add a separate screen->kgsl_dmabuf flag for the opt-in dma-buf sharing path.
  • Enable the KGSL dma-buf path with either:
    • FD_KGSL_ENABLE_DMABUF=1
    • XWAYLAND_FORCE_KGSL_SURFACELESS=1
  • Advertise dma-buf import/export caps for KGSL only when screen->kgsl_dmabuf is enabled.
  • Restrict KGSL dma-buf modifier queries to DRM_FORMAT_MOD_LINEAR.
  • Force KGSL shared/scanout resources to use a linear layout when the opt-in path is enabled.
  • Reject KGSL dma-buf imports with non-linear modifiers on the opt-in path.
  • Make KGSL BO dma-buf export fail for native KGSL BOs instead of duplicating an invalid import fd.
  • Shadow non-shared KGSL resources into shared linear resources before dma-buf export, avoiding the noisy failed native export attempt.

Why

XWayland/KWin surfaceless paths need a stable dma-buf contract for KGSL-backed rendering. The safe contract currently is:

  • exported buffers are dma-heap/ION backed,
  • modifiers are LINEAR,
  • native KGSL-only BOs are not exported directly.

At the same time, enabling these rules unconditionally can break the chroot DRM/GBM path. In testing, the modified Mesa path made glmark2 render black under DRM/GBM while still producing a score, whereas forcing XWayland's KGSL surfaceless backend restored correct output.

For that reason, this keeps the surfaceless-oriented KGSL dma-buf behavior behind an explicit opt-in and leaves existing DRM/GBM behavior unchanged by default.

Testing

Tested with KGSL surfaceless/XWayland flow on Adreno 830 and 730:

  • surfaceless EGL KGSL renderer initializes
  • dma-buf export/import roundtrip succeeds
  • XWayland glamor imports KGSL dma-bufs
  • glmark2 runs through XWayland with hardware rendering

Also tested the chroot DRM/GBM path on Adreno 730:

  • default DRM/GBM path remains separate from the opt-in KGSL dma-buf sharing path
  • XWAYLAND_FORCE_KGSL_SURFACELESS=1 EGL_PLATFORM=surfaceless enables the surfaceless flow

The shadow-before-export change also removes the expected-but-noisy first export failure:

failed to get dmabuf fd: -1

@lfdevs
lfdevs marked this pull request as ready for review July 8, 2026 17:26
@lfdevs lfdevs changed the title [WIP] freedreno/kgsl: add KGSL surfaceless path for XWayland hardware acceleration freedreno/kgsl: add KGSL surfaceless path for XWayland hardware acceleration Jul 8, 2026
@lfdevs lfdevs changed the title freedreno/kgsl: add KGSL surfaceless path for XWayland hardware acceleration freedreno/kgsl: make dma-buf export usable for linear shared buffers Jul 8, 2026
Add an explicit KGSL screen flag and gate the surfaceless/XWayland dma-buf
sharing contract behind a separate opt-in path.

When enabled, KGSL advertises PRIME import/export support even if the
control fd cannot report it through DRM caps, restricts dma-buf modifiers to
LINEAR, forces shared/scanout resources to use linear layouts, rejects
non-linear KGSL dma-buf imports, and shadows non-shared resources into
shared linear resources before export.

Keep native KGSL BOs non-exportable directly: only imported or
dma-heap/ION-backed KGSL BOs can provide a dma-buf fd. This avoids
duplicating an invalid import fd and removes the noisy failed first export
attempt for resources that need to be shadowed.

The KGSL dma-buf path is enabled with either:

  FD_KGSL_ENABLE_DMABUF=1
  XWAYLAND_FORCE_KGSL_SURFACELESS=1

It is intentionally not enabled by XWAYLAND_KGSL_SURFACELESS alone, because
that variable only allows Xwayland to fall back to surfaceless after GBM
setup fails. If the chroot DRM/GBM path succeeds, it should keep the normal
DRM behavior instead of applying the surfaceless-oriented sharing rules.
@lfdevs
lfdevs force-pushed the test/support-xwayland-surfaceless branch from 59fa0b2 to 69aaa92 Compare July 9, 2026 07:27
@lfdevs lfdevs changed the title freedreno/kgsl: make dma-buf export usable for linear shared buffers freedreno/kgsl: opt in to linear dma-buf sharing Jul 9, 2026
@lfdevs
lfdevs merged commit bc177b4 into dev/adreno-main Jul 9, 2026
8 checks passed
@lfdevs
lfdevs deleted the test/support-xwayland-surfaceless branch July 12, 2026 18:12
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