Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Cache and re-use DMA-BUF textures #2851

Merged
merged 7 commits into from
May 17, 2021

Conversation

emersion
Copy link
Member

If a client creates a wl_buffer and attaches it to a wl_surface, there's a good chance they're going to re-use it.

References: #2664

@emersion emersion force-pushed the linux-dmabuf-reuse-buffer branch 2 times, most recently from 0643907 to 66a371e Compare April 26, 2021 16:29
@emersion emersion force-pushed the linux-dmabuf-reuse-buffer branch 2 times, most recently from c84f497 to a0d6f25 Compare April 27, 2021 16:50
@emersion emersion force-pushed the linux-dmabuf-reuse-buffer branch 2 times, most recently from b0cb8e6 to 5173049 Compare April 29, 2021 18:20
@emersion emersion changed the title WIP: cache and re-use DMA-BUF textures Cache and re-use DMA-BUF textures Apr 29, 2021
@emersion
Copy link
Member Author

emersion commented Apr 29, 2021

Been testing this for a while, seems to work fine so far. Apart from the minor performance gains for most users, the main motivation for this is:

  • This PR results significant improvements on multi-GPU setups. It seems like cross-vendor EGL imports benefit a lot from this. We still have other bugs with multi-GPU though.
  • wlr_texture_from_buffer allows us to remove GL-centric assumptions from wlr_client_buffer_import. render/pixman: avoid copy when creating textures #2892 takes advantage of it.

I'll self-review this one more time before marking the PR as ready.

One gotcha is that with this change the GLES2 backend ref'counts wlr_textures. So two calls that create a wlr_texture may return the same pointer, and wlr_texture_destroy may not actually destroy the texture. This is strictly a GLES2 implementation detail for now, so not sure how best to document it, if we want to document it. The new behavior should be transparent to users. The Pixman renderer doesn't have this ref'counting implemented even in #2892, since pixman_image_create is pretty cheap.

@emersion emersion marked this pull request as ready for review May 12, 2021 14:05
render/wlr_texture.c Show resolved Hide resolved
This allows the DMA-BUF wl_buffer objects to be used directly as
wlr_buffers, without having to use wlr_client_buffer_import.
This centralizes the wlr_texture initialization.

In future commits, more fields will need to get initialized.
This adds a a function to create a wlr_texture from a wlr_buffer.

The main motivation for this is to allow the renderer to create a
single wlr_texture per wlr_buffer. This can avoid needless imports
by re-using existing textures.
Make it so wlr_gles2_texture is ref'counted (via wlr_buffer). This
is similar to wlr_gles2_buffer or wlr_drm_fb work.

When creating a wlr_texture from a wlr_buffer, first check if we
already have a texture for the buffer. If so, increase the
wlr_buffer ref'count and make sure any changes made by an external
process are made visible (by invalidating the texture).

When destroying a wlr_texture created from a wlr_buffer, decrease
the ref'count, but keep the wlr_texture around in case the caller
uses it again. When the wlr_buffer is destroyed, cleanup the
wlr_texture.
We can just use the wlr_dmabuf_v1_buffer directly, no need to wrap
it in a wlr_client_buffer.
@emersion
Copy link
Member Author

Thanks for the reviews!

@emersion emersion merged commit 9ca743f into swaywm:master May 17, 2021
@emersion emersion deleted the linux-dmabuf-reuse-buffer branch May 17, 2021 14:22
@emersion emersion added the breaking Breaking change in public API label May 19, 2021
@emersion emersion mentioned this pull request May 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking Breaking change in public API
Development

Successfully merging this pull request may close these issues.

None yet

3 participants