Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wayland: add support for linux-dmabuf #790

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

emersion
Copy link
Contributor

@emersion emersion commented Jan 8, 2024

wl_drm is a legacy protocol, and wlroots is getting rid of it 1. Use the newer and standard linux-dmabuf protocol if available to get the DRM device.

@emersion
Copy link
Contributor Author

emersion commented Jan 8, 2024

Ubuntu 20.04 has a very old libdrm. Should I make this new backend optional, or should I bump the Ubuntu version, or something else?

@emersion
Copy link
Contributor Author

Gentle ping, any chance to get this reviewed?

@emersion
Copy link
Contributor Author

emersion commented Feb 1, 2024

Gentle ping, would you have the time to have another look at this?

struct zwp_linux_dmabuf_v1 *linux_dmabuf;
struct zwp_linux_dmabuf_feedback_v1 *feedback;

if (strcmp(interface, zwp_linux_dmabuf_v1_interface.name) == 0 &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I am not familiar with this interface, but from code logic,
looks , it could be combined together with va_wayland_drm? add interface check inside registry_handle_global
if it is linuxdmabuf ,xxxx ; if it is wl_drm xxxx?

from libva perspective: it should retrieve the device fd though these function, then get the driver name though device fd. looks both wl_drm and linuxdma buffer could do it. but wl_drm interface will be deprecated?

from driver implementation perspective. what's the difference to implement vaGetSurfaceBufferWl and vaGetImageBufferWl? previously, we use "wl_proxy_create" and "wl_proxy_marshal" interface to share the dma buffer fd from vaSurface to wl_buffer, just like https://github.com/intel/intel-vaapi-driver/blob/master/src/i965_output_wayland.c#L231-L263. looks we need new implementation now?

Copy link
Contributor Author

@emersion emersion Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks , it could be combined together with va_wayland_drm? add interface check inside registry_handle_global
if it is linuxdmabuf ,xxxx ; if it is wl_drm xxxx?

That's possible indeed, but not sure it's a good idea. It would entangle the two implementations and make it more complicated to understand the code and drop the wl_drm part in the future.

from libva perspective: it should retrieve the device fd though these function, then get the driver name though device fd. looks both wl_drm and linuxdma buffer could do it. but wl_drm interface will be deprecated?

Yes, wl_drm was never supposed to be used by clients such as libva, it was supposed to be an internal Mesa protocol.

Some Wayland compositors like Sway have already dropped support for wl_drm.

from driver implementation perspective. what's the difference to implement vaGetSurfaceBufferWl and vaGetImageBufferWl? previously, we use "wl_proxy_create" and "wl_proxy_marshal" interface to share the dma buffer fd from vaSurface to wl_buffer, just like https://github.com/intel/intel-vaapi-driver/blob/master/src/i965_output_wayland.c#L231-L263. looks we need new implementation now?

Hm, yeah. This would need a new implementation indeed.

mpv seems to work just fine without this new implementation though. Maybe because they grab the DMA-BUFs directly, instead of vaGetImageBufferWl/vaGetSurfaceBufferWl?

There is nothing driver-specific in vaGetSurfaceBufferWl/vaGetImageBufferWl by the way. The implementation should be identical for all VA-API drivers. Turning a DMA-BUF into a wl_buffer can be done generically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it seems like Mesa doesn't implement VADriverVTableWayland.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More details: it seems only intel-vaapi-driver implements vaGetSurfaceBufferWl, intel-media-driver doesn't. So, think it's reasonable to loose this functionality when wl_drm is not available. The fix for intel-vaapi-driver is intel/intel-vaapi-driver#566.

@emersion
Copy link
Contributor Author

Gentle ping

@emersion
Copy link
Contributor Author

Gentle ping

@emersion
Copy link
Contributor Author

emersion commented Mar 6, 2024

Any chance you'd have time to look at this again @XinfengZhang @xhaihao?

@XinfengZhang
Copy link
Contributor

Any chance you'd have time to look at this again @XinfengZhang @xhaihao?

sorry for slow response, TBH, I am not familiar with this part, so, I plan to release 2.21.0, then pay some time to check the details. then merge it and keep it in master branch , and it will be a part of next release. suppose I could finish at early of next week.
is it urgent for your usage?

@emersion
Copy link
Contributor Author

emersion commented Mar 12, 2024

Thanks for the reply. It's not super urgent, but the next wlroots release planned in May will not have wl_drm, so would be nice to have the fix merged/released by then!

@emersion
Copy link
Contributor Author

Hi again, please have another look at this PR when you get this chance.

Copy link
Contributor

@XinfengZhang XinfengZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides some questions.

uint32_t size
)
{
close(fd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close the fd here? not record the modifier and format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the modifiers/formats in libva, we just need the DRM device.

if (!(dev->available_nodes & (1 << DRM_NODE_RENDER)))
goto end;

dev_path = dev->nodes[DRM_NODE_RENDER];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always render node? will not touch drm master node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, DRM master nodes are for KMS only nowadays.

wl_registry_bind(registry, name, &zwp_linux_dmabuf_v1_interface, 4);
feedback = zwp_linux_dmabuf_v1_get_default_feedback(linux_dmabuf);
zwp_linux_dmabuf_feedback_v1_add_listener(feedback, &feedback_listener, data);
zwp_linux_dmabuf_v1_destroy(linux_dmabuf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destroy here? or in handle_global_remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle_global_remove is irrelevant here, the linux-dmabuf global is never removed by the compositor.

We destroy the zwp_linux_dmabuf_v1 as soon as we don't need it anymore (ie, as soon as we've created a feedback object).

Copy link
Contributor

@XinfengZhang XinfengZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

wl_drm is a legacy protocol, and wlroots is getting rid of it [1].
Use the newer and standard linux-dmabuf protocol if available to
get the DRM device.

[1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4397

Signed-off-by: Simon Ser <[email protected]>
@XinfengZhang XinfengZhang merged commit 1b7d71f into intel:master Mar 22, 2024
14 checks passed
@emersion emersion deleted the linux-dmabuf branch March 22, 2024 09:55
@emersion
Copy link
Contributor Author

Thank you!

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.

3 participants