Commit Graph

26 Commits

Author SHA1 Message Date
Matthias Clasen
c0cb10262d Make gdk_dmabuf_download_mmap return status
Make this function return whether it was successful, and only emit
a debug message if we succeeded. In particular, make it return FALSE
if the dmabuf format is not linear.
2024-09-30 18:37:20 -04:00
Benjamin Otte
11543a229a texturedownloader: Add color state
... and plumb the color state through the downloading machinery, where
no matter what path it takes it ends up in
gdk_memory_convert_color_state() or gdk_memory_convert().

The 2nd of those has been expanded to optionally do colorstate
conversion when the 2 colorstates are different.
2024-07-16 21:23:44 +02:00
Benjamin Otte
fff72cf322 dmabuf: Add gdk_dmabuf_close_fds()
... and use it inside GtkGLArea

I made thatfunction available outside of HAVE_DMABUF so I don't need to
wrap it in ifdefs.
2024-07-11 13:34:36 +02:00
Benjamin Otte
ee93f88268 vulkan: Add support for enumerating dmabuf formats
This code does not add a downloader, so we do not claim support for all
the new formats.

It just queries the formats. But this can be used to import dmabufs
directly into the Vulkaan renderer.
2024-01-07 07:22:51 +01:00
Benjamin Otte
568eed9477 dmabuf: Turn the downloader into an interface
This way, we can move the actual downloader code into GSK - by just
implementing the interface in the GskGLRenderer.
2023-12-20 10:59:25 +01:00
Benjamin Otte
26561ab2e7 dmabuf: Refactor downloader vfuncs
This is in preparation for future commits. It also makes the API
clearer.
2023-12-20 01:51:46 +01:00
Benjamin Otte
210c71b856 egl: Split out a function
This makes no sense by itself, but we want to create the EGLImage at
DmabufTexture construction so that we can actually reject dmabufs that
we can't create EGLImages for.

This will make it possible to bail when the stride limitation for AMD
GPUs hits.
2023-12-20 01:51:46 +01:00
Benjamin Otte
66b992c3c0 dmabuf: Change the way downloaders work
Instead of having an add_formats() function, make the get_downloader()
function add the formats.

This allows putting the actual downloader in a different place from the
initialization code.
2023-12-16 21:36:21 +01:00
Benjamin Otte
b19f71dd24 dmabuf: Add Vulkan formats to the large table
This is done without testing, just doing my best to map all the DRM
formats to VkFormats.

Once people start using them, they'll figure it out when it's wrong.
(Somebody needs to write a testsuite.)
2023-12-16 19:16:50 +01:00
Benjamin Otte
cccec91b66 memoryformat: Put dmabuf fourccs into the big format table
I'm concentrating the data about memory formats, and this part was
missing.
2023-12-16 17:01:42 +01:00
Benjamin Otte
888b9ee352 dmabuf: Don't use a downloader for builtin downloads
When we use the builtin downloads via mmap(), it's a special case where
we don't need to initialize subsystems and query them for support. We
know what we can and can't do.

Also, we want to use these formats with the lowest priority but pick the
downloader first for supported formats, and queueing it in the
downloaders list doesn't reflect that. So don't do it.
2023-12-16 09:21:19 +01:00
Benjamin Otte
f0eceb4aa3 dmabuf: Remove out argument
The format is the same everywhere, so instead of letting every
implementation do the same thing, do it in a central place instead.
2023-12-16 09:20:36 +01:00
Benjamin Otte
81adf6be22 dmabuf: Add gdk_dmabuf_fourcc_is_yuv()
In the future, we want to be using GdkColorState instead, but for now,
let's use this.

Also remove a duplicate entry in the list of formats.
2023-12-13 05:54:06 +01:00
Benjamin Otte
5ca4ab3aaa dmabuf: Add gdk_dmabuf_import/export_sync_fd()
Vulkan needs this.

This code is following the code that compositors with Wayland support -
like wlroots - are doing.

The code was introduced to Linux in
https://lore.kernel.org/dri-devel/20220506180216.2095060-1-jason@jlekstrand.net/
2023-12-12 01:49:41 +01:00
Benjamin Otte
a37b3fb691 dmabuf: Add gdk_dmabuf_ioctl()
The function is a copy of libdrm's drmIoctl() and handles EINTR and
EAGAIN error.s

Use it for the sync ioctls in the dmabuf mmaping calls.
2023-12-12 01:49:41 +01:00
Benjamin Otte
50ee872978 dmabuf: Add gdk_dmabuf_get_fourcc()
Returns the fourcc for a given GdkMemoryFormat.

Not sure if this is the best name, but I didn't know a better one.
2023-11-25 01:44:34 +01:00
Benjamin Otte
1bf94b045c dmabuf: Refactor function
1. Don't require passing in a GdkDisplay

2. return TRUE/FALSE if a format was found, so calling code can
   decide how to handle failure itself
2023-11-25 01:44:34 +01:00
Matthias Clasen
b24ae31716 dmabuf: Improve consistency of debug messages
Make sure all our dmabuf debug messages are display-scoped so the
inspector doesn't trigger them, use the same formatting throughout,
and improve consistency of wording here and there.
2023-11-12 13:02:58 +01:00
Matthias Clasen
6ae9cbfe0f dmabuf: NV12 is opaque
Getting this wrong matters, since we won't offload textures in
non-opaque formats. Found by Robert Mader. At the same time,
unify the two places we have for mapping from fourcc to memory
format.
2023-11-11 23:56:01 +01:00
Matthias Clasen
494154beb6 dmabuf: Add an EGL downloader
Add an implementation of GdkDmabufDownloader that uses
gsk_renderer_render_texture + GL texture download.

Since gsk isn't threadsafe, we do the download in the main thread,
taking care to not disturb the current GL context of whatever is
going on there at the time.

And since gsk renderers are expensive to create, we cache it
in the display.

Note that gsk does not yet have any special support for
dmabuf textures, so for now, they will always get downloaded
and then reuploaded as GL textures.
2023-10-22 16:42:17 -04:00
Benjamin Otte
32ba1e389c build: Check for drm/drm_fourcc.h too
It's part of the kernel headers package so I did not check for libdrm.

As a side effect I checked the #define to HAVE_DMABUF.
2023-10-22 17:27:11 +02:00
Benjamin Otte
beb9e0c906 dmabuf: Add gdk_dmabuf_is_disjoint()
No users yet, but Vulkan will use this later. So have it available
already.
2023-10-22 17:03:15 +02:00
Benjamin Otte
13848969f4 dmabuf: Allow downloaders to fail initialization
When adding the formats of a downloader, allow them to return FALSE to
mean "This method is not supported", which is a useful way to opt out
when checking GL or Vulkan extensions and finding out that the desired
one isn't supported.
2023-10-22 17:03:13 +02:00
Matthias Clasen
9e3f537a15 dmabuf: Give downloaders a name
Add name to the downloader struct, and add it
to the debug spew for newly created dmabuf
textures.
2023-10-21 19:19:21 -04:00
Benjamin Otte
dd8c6e9f51 dmabuf: Add gdk_dmabuf_sanitize()
Tries to sanitize the dmabuf to conform to the values expected
by Vulkan/EGL which should also be the values expected by
Wayland compositors

We put these sanitized values into the GdkDmabufTexture, by
sanitizing the input from GdkDmabufTextureBuilder, which are
controlled by the callers.

Things we do here:

1. Disallow any dmabuf format that we do not know.

1. Treat the INVALID modifier the same as LINEAR.

2. Ignore all other modifiers.

3. Try and fix various inconsistencies between V4L and Mesa,
   like NV12.

*** WARNING ***

This function is not absolutely perfect, you do not have a
perfect dmabuf afterwards.

In particular, it doesn't check sizes.
2023-10-20 13:58:22 +02:00
Benjamin Otte
570e80a9ff dmabuf: Split out GdkDmabuf and GdkDmabufDownloader
GdkDmabuf is a struct encapsulating all the values of a dmabuf, so
nothing to see here.

GdkDmabufDownloader is a vtable for a thing that can download dmabufs.
For now only one implementation exists, so this just looks like a ton
of work for no benefit.

The only neat thing is that gdkdmabuftexture.c got a whole lot tidier.
2023-10-16 18:56:52 -04:00