NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.48k stars 13.67k forks source link

sunshine: Missing amd and intel gpu encoding deps #343169

Open Redhawk18 opened 2 days ago

Redhawk18 commented 2 days ago

Describe the bug

sunshine is built with an override for cuda but not for amd or intel

Steps To Reproduce

Steps to reproduce the behavior:

  1. Try to encode on amd, fails

Expected behavior

For at least rocm/amd support to be added

Additional context

arch example of needed deps

Notify maintainers

@devusb

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here

Add a :+1: reaction to issues you find important.

Princemachiavelli commented 2 days ago

Sunshine seems to use CUDA exclusively for NVFBC capture. For regular GPU accelerated video encoding, the standard VAAPI driver should be sufficient for both AMD and Intel which are the drivers that the Archlinux docs mention (not ROCM).

For the VAAPI drivers, Nix uses the module system to enable these. See this page on enabling the necessary drivers.

Princemachiavelli commented 2 days ago

The AMD VAAPI driver is just part of Mesa so should be present if you have working graphics already.

I think we just need to always enable the autoAddDriverRunpath hook since we need to use the system OpenGL drivers regardless if we are using CUDA or not.

If you use the CUDA version of the package, then does the video encoding (using AMD) work? Set:

services.sunshine.package = pkgs.sunshine.overrideAttrs(p: { 
    nativeBuildInputs = p.nativeBuildInputs ++ [ pkgs.autoAddDriverRunpath ];
  }
);
devusb commented 2 days ago

@Redhawk18 what issues are you running into? I exclusively use Sunshine with AMD + VAAPI -- works out of the box with the module. These are the log lines I see at startup.

[2024:09:20:07:16:19]: Info: 
[2024:09:20:07:16:19]: Info: // Ignore any errors mentioned above, they are not relevant. //
[2024:09:20:07:16:19]: Info: 
[2024:09:20:07:16:19]: Info: Found H.264 encoder: h264_vaapi [vaapi]
[2024:09:20:07:16:19]: Info: Found HEVC encoder: hevc_vaapi [vaapi]
[2024:09:20:07:16:19]: Info: Found AV1 encoder: av1_vaapi [vaapi]
[2024:09:20:07:16:19]: Info: Configuration UI available at [https://localhost:47990]
[2024:09:20:07:16:19]: Info: Adding avahi service Sunshine
[2024:09:20:07:16:20]: Info: Avahi service Sunshine successfully established.

For what it's worth, the module should not be required -- if I remember correctly CAP_SYS_ADMIN may be required for Wayland, but I think it worked using VAAPI on xorg without it.

Certainly possible that there could be some idiosyncrasy of my config that makes this work, but would be surprised -- running Plasma 6 on Wayland, nothing too weird.

Redhawk18 commented 2 days ago

This is my log, the sunshine devs replied saying its because we use stock ffmpeg so take that as you will.

Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Screencasting with KMS
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found monitor for DRM screencasting
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found connector ID [107]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found cursor plane [82]
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: VA-API version 1.21.0
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Found init function __vaDriverInit_1_21
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: va_openDriver() returns 0
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: SDR color coding [Rec. 709]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Color depth: 10-bit
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Color range: [JPEG]
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: VA-API version 1.21.0
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Found init function __vaDriverInit_1_21
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: va_openDriver() returns 0
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Error: [hevc_vaapi @ 0x406cb480] No usable encoding entrypoint found for profile VAProfileHEVCMain10 (18).
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Retrying with fallback configuration options for [hevc_vaapi] after error: Function not implemented
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: VA-API version 1.21.0
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: Found init function __vaDriverInit_1_21
Sep 20 11:23:00 Mythra sunshine[2717]: libva info: va_openDriver() returns 0
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Warning: [hevc_vaapi @ 0x4070d540] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info:
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: // Ignore any errors mentioned above, they are not relevant. //
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info:
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found H.264 encoder: h264_vaapi [vaapi]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found HEVC encoder: hevc_vaapi [vaapi]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Adding avahi service Sunshine
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Configuration UI available at [https://localhost:47990]
Sep 20 11:23:01 Mythra sunshine[2717]: [2024:09:20:11:23:01]: Info: Avahi service Sunshine successfully established.

This might work, but I don't know this program well enough to really understand.

Redhawk18 commented 2 days ago

The AMD VAAPI driver is just part of Mesa so should be present if you have working graphics already.

I think we just need to always enable the autoAddDriverRunpath hook since we need to use the system OpenGL drivers regardless if we are using CUDA or not.

If you use the CUDA version of the package, then does the video encoding (using AMD) work? Set:

services.sunshine.package = pkgs.sunshine.overrideAttrs(p: { 
    nativeBuildInputs = p.nativeBuildInputs ++ [ pkgs.autoAddDriverRunpath ];
  }
);

I'll have to try this again with my friend, since together our connection is slow enough to require encoding.

devusb commented 2 days ago

@Redhawk18 your log looks like vaapi was found, so hardware encoding should be working? the bits below

Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: // Ignore any errors mentioned above, they are not relevant. //
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info:
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found H.264 encoder: h264_vaapi [vaapi]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Found HEVC encoder: hevc_vaapi [vaapi]

also FWIW we actually don't use stock ffmpeg anymore -- we use sunshine's vendored binaries and patch them with this bit -- if you look, ffmpeg isn't even an input to the derivation.

Redhawk18 commented 2 days ago

Hmm, how can I test this with that commit? I don't believe rebuilding sunshine with a local version of nixpkgs will update the service and I don't want to rebuild everything to unstable.

log from my phone

Sep 20 11:22:59 Mythra systemd[2225]: Started Self-hosted game stream host for Moonlight.
Sep 20 11:22:59 Mythra sunshine[2717]: [port] -- [47989]
Sep 20 11:22:59 Mythra sunshine[2717]: [output_name] -- [1]
Sep 20 11:22:59 Mythra sunshine[2717]: [encoder] -- [amdvce]
Sep 20 11:22:59 Mythra sunshine[2717]: [controller] -- [true]
Sep 20 11:22:59 Mythra sunshine[2717]: [amd_usage] -- [ultralowlatency]
Sep 20 11:22:59 Mythra sunshine[2717]: [min_threads] -- [8]
Sep 20 11:22:59 Mythra sunshine[2717]: [amd_quality] -- [speed]
Sep 20 11:22:59 Mythra sunshine[2717]: [sunshine_name] -- [Mythra]
Sep 20 11:22:59 Mythra sunshine[2717]: [amd_coder] -- [cavlc]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Sunshine version: 0.23.1
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found display [wayland-0]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: zxdg_output_manager_v1(31) version 3
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: wl_output(61) version 4
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: wl_output(62) version 4
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Warning: Missing Wayland wire for wlr-export-dmabuf
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card0 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found display [wayland-0]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found display [wayland-0]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: zxdg_output_manager_v1(31) version 3
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: wl_output(61) version 4
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found interface: wl_output(62) version 4
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Resolution: 1920x1080
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Resolution: 1920x1080
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Offset: 0x0
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Logical size: 1920x1080
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Name: DP-1
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found monitor: AUS VG278/16843009
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Offset: 1920x0
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Logical size: 1920x1080
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Name: HDMI-A-1
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Found monitor: ACR GN246HL/1668346451
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: -------- Start of KMS monitor list --------
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Monitor 1 is DP-1: AUS VG278/16843009
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Monitor 0 is HDMI-A-1: ACR GN246HL/1668346451
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: --------- End of KMS monitor list ---------
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Error: Couldn't find any working encoder matching [amdvce]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: // Testing for available encoders, this may generate errors. You can safely ignore those errors. //
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Trying encoder [nvenc]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Screencasting with KMS
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card0 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Error: Couldn't find monitor [1]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card0 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Error: Couldn't find monitor [1]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: System tray created
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: Screencasting with KMS
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card0 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Error: Couldn't find monitor [1]
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card1 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Info: /dev/dri/card0 -> amdgpu
Sep 20 11:22:59 Mythra sunshine[2717]: [2024:09:20:11:22:59]: Error: Couldn't find monitor [1]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Encoder [nvenc] failed
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Trying encoder [vaapi]
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: Screencasting with KMS
Sep 20 11:23:00 Mythra sunshine[2717]: [2024:09:20:11:23:00]: Info: /dev/dri/card1 -> amdgpu
devusb commented 1 day ago

sunshine from 24.05 should also use vendored ffmpeg, but again from the logs you sent it looks like yours is using vaapi correctly.