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

VideoBackends: Wayland support #7452

Closed
wants to merge 8 commits into from
Closed

VideoBackends: Wayland support #7452

wants to merge 8 commits into from

Conversation

stenzek
Copy link
Contributor

@stenzek stenzek commented Oct 3, 2018

Currently, Dolphin can semi-run the Qt frontend against the Wayland QPA, however, our video backends have no such support, and just crash out.

Most of the work to support this configuration was done as part of #7450, this PR just adds Wayland WSI integration to the backends, and a basic Wayland platform for NoGUI.

@stenzek stenzek added the WIP / do not merge Work in progress (do not merge) label Oct 3, 2018
@adelpozoman
Copy link

If you really can make this it would be awesome

@@ -96,11 +96,11 @@ GLuint CompileProgram(const std::string& vertexShader, const std::string& fragme
return programID;
}

void EnablePrimitiveRestart()
void EnablePrimitiveRestart(GLContext* context)

This comment was marked as off-topic.

@stenzek
Copy link
Contributor Author

stenzek commented Oct 24, 2018

Input support added, as well as a basic platform for NoGUI. Line count is up again due to being based on PR7512.

Still have to sort out the window dimensions/resizing issue, and a few other bugs.

@delroth
Copy link
Member

delroth commented Nov 7, 2018

@linkmauve would you mind giving this a test / review / help? :)

@Sunderland93
Copy link

wl_shell is deprecated. Use xdg-shell instead.

@Sunderland93
Copy link

Any progress?

@Sunderland93
Copy link

@stenzek Any news? It would be pretty cool to have full Wayland support in Dolphin 6.0

@stenzek stenzek removed the WIP / do not merge Work in progress (do not merge) label Apr 28, 2019
@stenzek
Copy link
Contributor Author

stenzek commented Apr 28, 2019

Moved over to using xdg-shell, and the decoration manager protocol (this gets us borders/controls for NoGUI). Window size is no longer hardcoded, and resizing is supported.

The window decorations will still disappear when running with the qt frontend under gnome, but work fine on kwin. Given Qt doesn't use the wayland QPA when running under gnome anyway.. ¯_(ツ)_/¯

I'm still not sure about generating the headers and including them in the tree (approx. 2500 of the lines are from these), we might be better off generating them as part of the build process. Does anyone know what the standard practice here is?

@orbea
Copy link
Contributor

orbea commented Apr 28, 2019

I'm still not sure about generating the headers and including them in the tree (approx. 2500 of the lines are from these), we might be better off generating them as part of the build process. Does anyone know what the standard practice here is?

Not sure how to do this in cmake, but we use this script which is executed by our hand made configure script to do this in RetroArch.

https://github.com/libretro/RetroArch/blob/master/gfx/common/wayland/generate_wayland_protos.sh

It will require wayland-scanner and wayland-protocols to accomplish, the latter can be added to external. We fallback to our own copy if the user's version is not installed.

@stenzek
Copy link
Contributor Author

stenzek commented Apr 28, 2019

Yeah, I was considering using cmake to shell out to wayland-scanner.. getting the location on system without hardcoding it to /usr/share or whatever could be interesting.

@orbea
Copy link
Contributor

orbea commented Apr 28, 2019

I was worried about that too so I made it check $SHARE_DIR/wayland-protocols, /usr/local/share/wayland-protocols and /usr/share/wayland-protocols in that order where $SHARE_DIR is the output of --datarootdir. I am not sure that is perfect, but so far I haven't seen anyone complain about it not working. However it will fallback to our deps/wayland-protocols if either none of them are found or our earlier check for version >= 1.15 of wayland-protocols.pc fails (Using pkg-config/pkgconf). I've been told that earlier versions are not good enough and not all distros carry recent versions...

@linkmauve
Copy link
Member

linkmauve commented Apr 29, 2019 via email

@stenzek
Copy link
Contributor Author

stenzek commented Apr 30, 2019

@linkmauve thanks for the tip, I did come across the ECM modules but wasn't sure how widespread the support was. Sounds like the most straightforward method.

@soreau
Copy link
Contributor

soreau commented May 1, 2019

Here's what I've come up with so far. It uses subsurfaces and runs but

  • Size is hard coded to 640x480. Need to get the inner dimensions of the render window somehow and the size when it goes fullscreen.
  • Likewise, the offsets passed to wl_subsurface_set_position() are hard coded, so the emulation window isn't perfectly affixed to the render window providing the decorations.
  • Moving the pointer over the emulation window causes a crash with the message QObject::connect(QtWaylandClient::QWaylandWindow, QtWaylandClient::QWaylandInputDevice::Pointer): invalid null parameter and I don't know why.
  • Vulkan currently does not work, only GL does.

There's also the matter of hooking up keybindings etc. but since it runs, I'd say it's about half way there. Any help solving these problems is welcome.

@stenzek
Copy link
Contributor Author

stenzek commented May 1, 2019

I decided against using subsurfaces for this case, because to me it seems like it creates a bunch of problems, e.g. what size are the decorations? are the decorations round or square? I also wanted to avoid having a large chunk of wayland code in the qt frontend. It's also the only system where this is even a question, no other OS/display manager has this problem.

I'm guessing Qt creates subsurfaces itself for the render-to-main-window case, because this works fine in my branch when taking over the surface for Dolphin's rendering. The separate window works as expected with server-side decorations.

Size is hard coded to 640x480. Need to get the inner dimensions of the render window somehow and the size when it goes fullscreen.

Implemented in this PR. The size is passed as part of the WSI info at startup, with resize events being passed to the backend, updating the surface as needed. See e81c726 and 6c8aec0

Vulkan currently does not work, only GL does.

Also implemented in this PR.

@soreau
Copy link
Contributor

soreau commented May 1, 2019

Great. You might check the cmake code I have, it might give you some ideas.

@soreau
Copy link
Contributor

soreau commented May 1, 2019

@stenzek I tested your code, it built fine and works (mostly). Mousing over and Vulkan with Qt is good but trying nogui ended up with xwayland. The keyboard did not work except in fullscreen, Esc caused crash and Alt+Enter got out of fullscreen but restarted emulation and left the main gui unresponsive (had to ctrl+c to stop emulation and exit). The keyboard should be hooked up for save/load state, Esc to quit properly and toggle fullscreen etc. Click to move emulation window would be nice to have too. It's a shame to see subsurfaces are more or less a waste of time but at least SSD is (apparently) an option now.

@stenzek
Copy link
Contributor Author

stenzek commented May 2, 2019

Great. You might check the cmake code I have, it might give you some ideas.

I've been planning to move it over to the ECM module, just haven't had time yet.

Mousing over and Vulkan with Qt is good but trying nogui ended up with xwayland.

dolphin-emu-nogui -p wayland .... It'll default to X11 otherwise.

@stenzek
Copy link
Contributor Author

stenzek commented May 2, 2019

Now using ECM's scripts for wayland, as suggested by @linkmauve. I think this can be considered complete now, since CSD is outside the scope.

@soreau
Copy link
Contributor

soreau commented May 2, 2019

It pulls in xkbcommon without hooking up the keyboard. Keyboard bindings need to be hooked up still. I'm not entirely sure but judging from latest simple-egl.c in weston, xkbcommon isn't needed to get key events.

@soreau
Copy link
Contributor

soreau commented May 2, 2019

Another problem I have found is that after building (with wayland enabled), fullscreen no longer works in x11. With wayland disabled, emulation video is broken with x11. The window doesn't come up when audio starts and if it does show up, it only displays a single frame and never updates. So this PR breaks 'normal' x11 functionality quite badly.

EDIT: With latest changes it's even worse. I get audio and a window, but the window receives no frames so it ends up showing garbage (remnants of the desktop). I also tried disabling EGL but it makes no real difference.

@stenzek
Copy link
Contributor Author

stenzek commented May 3, 2019

It is hooked up to the keyboard. See 6d51b71. Did you change the input device in the controller options? Wayland will show up as a different device to xinput.

I'll look into the X11 issues.

@soreau
Copy link
Contributor

soreau commented May 3, 2019

Now that I changed the keyboard in hotkey config, the keybindings work. One other bug I noticed though, when I press Super key (while running under wayland) while in main dolphin window when emulation is not running, dolphin segfaults (regardless what 'keyboard' I select). I built with debug symbols to get this back trace http://ix.io/1HSQ

@stenzek
Copy link
Contributor Author

stenzek commented May 4, 2019

@soreau I'm unable to reproduce any of the X11 issues you've mentioned, regardless of egl/wayland/etc config options.

@soreau
Copy link
Contributor

soreau commented May 4, 2019

@stenzek After trying various things I did manage to get it 'working' by disabling compositing window manager but it's extra slow (tww) and dolphin 5c5e6df works fine with compositing at expected speeds. With your code, while the compositing wm is running and the emulation window displaying garbage, the audio is still slowed. Are you using a compositing window manager? I am surprised you can't reproduce because the problem is obvious on my end.

@stenzek
Copy link
Contributor Author

stenzek commented May 4, 2019

I tried both kwin and mutter? (or whatever the gnome compositor is) on Ubuntu 19.04.

edit: fwiw, I looked through the changes again, and I can't really how anything would affect X11 using GLX compared to master.

Whether ENABLE_WAYLAND is set or not should definitely not change anything for X11.

@Helios747
Copy link
Contributor

Worth noting that the earliest ubuntu that will support this without PPAs is 19.04. This shouldn't be a problem once CMake can just flip it on/off at configure time but for people not on rolling release distros, it may be worth sticking a small note in the README for ubuntu users hoping to leverage wayland support.

@soreau
Copy link
Contributor

soreau commented May 4, 2019

@stenzek You sure you weren't using kwin and mutter wayland compositors? I'll try to bisect on my end if I can find a good commit.

@newperson1746
Copy link

Oh hi Stenzek, good to see you back on this PR! Are there any tweaks left we could help with?

@LaserEyess
Copy link

I got a crash when pressing ctrl+q to quit. Unfortunately the trace is not very helpful since I didn't have libwayland debug symbols. I will try to reproduce.

https://0x0.st/-AlV.txt

@soreau
Copy link
Contributor

soreau commented Apr 20, 2021

I notice this when building:

[ 80%] Generating wayland-xdg-shell-protocol.c
[ 80%] Generating wayland-xdg-decoration-protocol.c
Using "code" is deprecated - use private-code or public-code.
See the help page for details.
Using "code" is deprecated - use private-code or public-code.
See the help page for details.

Reference

@soreau
Copy link
Contributor

soreau commented Apr 20, 2021

I got a crash when pressing ctrl+q to quit. Unfortunately the trace is not very helpful since I didn't have libwayland debug symbols. I will try to reproduce.

https://0x0.st/-AlV.txt

Here's what I get with Ctrl+Q. I didn't see this in the Dolphin keybinding settings which makes me wonder if Qt is listening and taking action, and Dolphin isn't expecting it.

@soreau
Copy link
Contributor

soreau commented Apr 20, 2021

Also in my case, even if all the required wayland development packages are installed, wayland is still not automatically enabled. I had to manually enable wayland with -DENABLE_WAYLAND=1 or else there is this message when attempting to start emulation:

snapshot

@LaserEyess
Copy link

ctrl+q is a shortcut to send sigterm to the focused window on my compositor, and a general shortcut on many qt/qtk programs. If dolphin itself doesn't implement it as a shortcut it should still handle it properly.

@v1993
Copy link
Contributor

v1993 commented Apr 21, 2021

I think it makes sense to enable Wayland by default until there's a good reason not to.

@tobiasjakobi
Copy link

Just voicing my interest in this PR as a fellow Wayland (sway) user.

@ghost
Copy link

ghost commented Jun 29, 2021

+1 any progress on this?

@MatthewCroughan
Copy link

If anybody wants to build or run this PR using nix, they can do so like this:

Build (Puts it in ./result/bin/dolphin-emu)

nix build github:matthewcroughan/nixpkgs/dolphin-wayland-hack#dolphinEmuMaster

Run (Just runs dolphin-emu)

nix shell github:matthewcroughan/nixpkgs/dolphin-wayland-hack#dolphinEmuMaster --command dolphin-emu

@Nefsen402
Copy link

Nefsen402 commented Jul 19, 2021

I created a .patch that is based on this pr's work and rebased on 6e7698a. Here's the patch:
https://pastebin.com/yChuyxcu.

My efforts were like a monkey smashing a keyboard. I just fixed some function signatures and it seems to compile on gcc11. I'm not sure how stable it is, but it seems to launch opengl/vulkan on wayland now on a couple of games I tried. This is running archlinux and sway (HiDPI seems to work as well)
I did make one change from the original patch, and that is to have cmake enable wayland by default. Before you had to set the ENABLE_WAYLAND option. I just decided to do that because people using this .patch would probably already want to be doing that.

MatthewCroughan added a commit to MatthewCroughan/nixpkgs that referenced this pull request Jul 19, 2021
@MatthewCroughan
Copy link

@Need4Speed402 Thank you so much. I have made a commit here MatthewCroughan/nixpkgs@3863ef1 that will allow anyone viewing this PR to use Nix on any distribution (including Arch 😄) to test your patch. I've tested it as working under Sway on NixOS too.

Build Need4Speed402's patch (Puts it in ./result/bin/dolphin-emu)

nix build github:matthewcroughan/nixpkgs/dolphin-wayland-hack-n4s#dolphinEmuMaster

Run Need4Speed402's patch (Just runs dolphin-emu after building it)

nix shell github:matthewcroughan/nixpkgs/dolphin-wayland-hack-n4s#dolphinEmuMaster --command dolphin-emu

@stenzek stenzek closed this Jul 31, 2021
@4e554c4c
Copy link

Any indication on why this was closed?
Is the patch nonviable or does it just need someone to clean it up before it can be pulled?

@AdmiralCurtiss
Copy link
Contributor

Feel free to rebase this as a new PR if you're willing to get this into a mergeable state.

@soreau
Copy link
Contributor

soreau commented Aug 28, 2021

Feel free to rebase this as a new PR if you're willing to get this into a mergeable state.

It would be nice to know from upstream maintainers if this work would even be accepted if such a PR exists, before doing the work.

@JosJuice
Copy link
Member

Any indication on why this was closed?

Stenzek closed all his open PRs. So it's not because something was wrong with this PR specifically.

@Nefsen402
Copy link

I did rebase this PR recently here and it seems to apply cleanly on current dolphin still. I have played some games through it and I can say that the only issue is really just the mouse cursor not hiding itself when it should be. I know there was some chit chat about the PR not rendering window decorations on Gnome? Maybe somebody should test that. I would be willing to clean this up and put up a new PR but life's kinda busy right now so I'd rather not.

@iMonZ
Copy link

iMonZ commented Jan 5, 2022

Any news here?

@Nefsen402
Copy link

I rebased the patches again on commit 3da6487. Works fine on sway git.

@iMonZ
Copy link

iMonZ commented Jan 10, 2022

I rebased the patches again on commit 3da6487. Works fine on sway git.

Thanks.
So what step should be done afterwards?

kira-bruneau added a commit to kira-bruneau/nixos-config that referenced this pull request Apr 23, 2022
@TheSunCat
Copy link

What's holding this back from being merged currently?

@tobiasjakobi
Copy link

What's holding this back from being merged currently?

The fact that this PR is closed.

@dolphin-emu dolphin-emu locked as resolved and limited conversation to collaborators Aug 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.