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

[Experimental] [WIP] Wayland/EGL: Auto-detect GPUs with EGL_EXT_device_enumeration #88516

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Riteo
Copy link
Contributor

@Riteo Riteo commented Feb 18, 2024

Fixes #88364.

NOTE: This has been very lightly tested as I can't get my hands on a multi-GPU setup

This is based on the approach (and probing code) proposed by @hpvb, with a bunch of changes.

In short, we use the new EGL_EXT_device_enumeration (and all of its various dependencies) to select and probe the various graphics cards a system offers. This has the advantage of giving us greater control and predictability compared to DRI_PRIME.

With this, we should also be able to probe for whether a device is DRM backed1 or just a software rasterizer2, although this is not yet plumbed in.

Note that, unlike the old DRI_PRIME approach, we can't fork to avoid driver crashes like we did there as the device handles are not guaranteed to be consistent (nor in the same order) between invocations, although I got guaranteed that this is not supposed to happen, not even on proprietary drivers3 (perhaps things just got better?)

This approach is currently only implemented in the Wayland backend, although everything has been done into the generic EGLManager. We also embed the vendor priority map into the OS_LinuxBSD class so that it can be shared with other code, such as the GLX prober.

Marking as WIP as there are some things missing or unsure (HW/SW detection, a way to disable this thing) and because I couldn't test this to its fullest extent.

Footnotes

  1. EGL_EXT_device_drm

  2. EGL_MESA_device_software

  3. https://oftc.irclog.whitequark.org/dri-devel/2024-02-10#32912345

@akien-mga
Copy link
Member

akien-mga commented Feb 18, 2024

Tested locally on a Tuxedo Sirius 16 Gen 1 (AMD Radeon 780M integrated + AMD Radeon RX 7600M XT discrete GPU), the detection seems to work as expected, but somehow it seems to pick the integrated GPU despite saying the contrary.

System specs
System:
  Host: fedora Kernel: 6.7.4-200.fc39.x86_64 arch: x86_64 bits: 64
  Desktop: KDE Plasma v: 5.27.10 Distro: Fedora Linux 39 (KDE Plasma)
CPU:
  Info: 8-core model: AMD Ryzen 7 7840HS w/ Radeon 780M Graphics bits: 64
    type: MT MCP cache: L2: 8 MiB
  Speed (MHz): avg: 971 min/max: 400/5137:6080:5293:5449:5608:5924:5764
    cores: 1: 1418 2: 1342 3: 400 4: 400 5: 400 6: 400 7: 1476 8: 400 9: 1481
    10: 2057 11: 400 12: 1361 13: 400 14: 400 15: 1435 16: 1773
Graphics:
  Device-1: AMD Navi 33 [Radeon RX 7700S/7600/7600S/7600M XT/PRO W7600]
    driver: amdgpu v: kernel
  Device-2: AMD Phoenix1 driver: amdgpu v: kernel
  Device-3: Microdia Integrated Camera driver: uvcvideo type: USB
  Display: wayland server: X.org v: 1.20.14 with: Xwayland v: 23.2.4
    compositor: kwin_wayland driver: X: loaded: amdgpu
    unloaded: fbdev,modesetting,radeon,vesa dri: radeonsi gpu: amdgpu,amdgpu
    resolution: 1707x960
  API: EGL v: 1.5 drivers: radeonsi,swrast
    platforms: wayland,x11,surfaceless,device
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: amd mesa v: 23.3.5 renderer: AMD
    Radeon Graphics (radeonsi gfx1103_r1 LLVM 17.0.6 DRM 3.57
    6.7.4-200.fc39.x86_64)
  API: Vulkan v: 1.3.268 drivers: radv,llvmpipe surfaces: xcb,xlib,wayland
$ godot-git
...

Loaded EGL 1.5
EGL supports explicit device extension, populating device list.
Auto-detecting GPUs.
Text-to-Speech: Speech Dispatcher initialized.
Found device [0xc7df370] AMD - AMD Radeon RX 7600M XT (radeonsi, navi33, LLVM 17.0.6, DRM 3.57, 6.7.4-200.fc39.x86_64) with priority 30.
Found device [0xc7df3a0] AMD - AMD Radeon Graphics (radeonsi, gfx1103_r1, LLVM 17.0.6, DRM 3.57, 6.7.4-200.fc39.x86_64) with priority 30.
Found device [0x7fca54347080] Mesa - llvmpipe (LLVM 17.0.6, 256 bits) with priority 0.
Selected device [0xc7df370]

...

OpenGL API 4.6 (Core Profile) Mesa 23.3.5 - Compatibility - Using Device: AMD - AMD Radeon Graphics (radeonsi, gfx1103_r1, LLVM 17.0.6, DRM 3.57, 6.7.4-200.fc39.x86_64)

See how it says it selected device [0xc7df370] (navi33), but then it's using the other one (gfx1103_r1).

With DRI_PRIME=1, it selects navi33 as expected, though the --verbose logs don't seem to mention that DRI_PRIME passed from the env overrides the auto-detection, it still runs the detection logic.

I notice the device IDs seem to change each time I run Godot.

@Riteo
Copy link
Contributor Author

Riteo commented Feb 19, 2024

@akien-mga uh, that's weird. Regarding DRI_PRIME overriding stuff, yeah, that makes sense, as it's driver level. I'll try to make the experience of using that env var prettier later.

I've pushed a change which hopefully tells us a little bit more about why it's ignoring our device attribute, hopefully it's at least passing the right branch :/

EDIT: Uh right BTW regarding the device IDs, that's the point, they're not IDs, they're handles. It's normal that they're not stable and that's the reason that we can't fork and do the fancy pantsy things we did before.

Co-Authored-By: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wayland: DRI_PRIME warnings raised by DetectPrimeEGL
3 participants