matanui159 / ReplaySorcery

An open-source, instant-replay solution for Linux
GNU General Public License v3.0
855 stars 27 forks source link

hwaccel fails with Radeon 6800XT and mesa drivers #111

Open BrianAllred opened 3 years ago

BrianAllred commented 3 years ago

Describe the bug Using the hwaccel option with a Radeon 6800XT and latest mesa drivers results in an error in kmsgrab. Full debug output pasted below. I'm a dotnet dev professionally, so my C is a little rusty, but I have a dev environment and am happy to help debug this issue if necessary.

Desktop:

Configuration: System config: unchanged

User config:

videoInput = hwaccel
videoFramerate = 60
videoWidth = 2560
videoHeight = 1440

Logs: replay-sorcery.log This log may contain some successful runs from when videoInput was commented out.

Debug Log:

Real user ID: 1000
Effective user ID: 1000
Failed to open config file '/usr/local/etc/replay-sorcery.conf': No such file or directory
Reading config file '/home/brian/.config/replay-sorcery.conf'...
Setting 'videoInput' to 'hwaccel'...
Setting 'videoFramerate' to '60'...
Setting 'videoWidth' to '2560'...
Setting 'videoHeight' to '1440'...
ReplaySorcery  Copyright (C) 2020  ReplaySorcery developers
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; see COPYING for details.
FFmpeg version: n4.4
[kmsgrab @ 0x5555555ce640] Using plane 60 to locate framebuffers.
[kmsgrab @ 0x5555555ce640] Template framebuffer is 142: 2560x1440 format 34325258 modifier 200000020801b03 flags 2.
[kmsgrab @ 0x5555555ce640] No handle set on framebuffer: maybe you need some additional capabilities?
 - /home/brian/Documents/ReplaySorcery/src/device/ffdev.c:146 (rsFFmpegDeviceOpen)
 - /home/brian/Documents/ReplaySorcery/src/device/kmsdev.c:48 (rsKmsDeviceCreate)
 - /home/brian/Documents/ReplaySorcery/src/device/device.c:50 (rsVideoDeviceCreate)
 - /home/brian/Documents/ReplaySorcery/src/main.c:175 (main)
Unused option: framerate
Failed to create KMS device: Invalid argument
Function not implemented
 - /home/brian/Documents/ReplaySorcery/src/main.c:232 (main)
matanui159 commented 3 years ago

Looks like you don't have the correct permissions. Make sure the RS_SETUID CMake option is enabled (only applies during installation. You can manually do it with sudo chmod u+s <binary>)

BrianAllred commented 3 years ago

Uninstalled the AUR package and ran the following commands to install from a local build.

$ cmake -B bin -DCMAKE_BUILD_TYPE=Release -DRS_SETUID=ON
$ make -C bin
$ sudo make -C bin install

which resulted in the following output when running replay-sorcery

Real user ID: 1000
Effective user ID: 0
Reading config file '/usr/local/etc/replay-sorcery.conf'...
Setting 'logLevel' to 'info'...
Setting 'traceLevel' to 'error'...
Setting 'recordSeconds' to '30'...
Setting 'videoInput' to 'auto'...
Setting 'videoDevice' to 'auto'...
Setting 'videoX' to '0'...
Setting 'videoY' to '0'...
Setting 'videoWidth' to 'auto'...
Setting 'videoHeight' to 'auto'...
Setting 'videoFramerate' to '30'...
Setting 'videoEncoder' to 'auto'...
Setting 'videoProfile' to 'baseline'...
Setting 'videoPreset' to 'fast'...
Setting 'videoQuality' to '28'...
Setting 'videoBitrate' to 'auto'...
Setting 'videoGOP' to '30'...
Setting 'scaleWidth' to 'auto'...
Setting 'scaleHeight' to 'auto'...
Setting 'audioInput' to 'auto'...
Setting 'audioDevice' to 'auto'...
Setting 'audioSamplerate' to '44100'...
Setting 'audioEncoder' to 'auto'...
Setting 'audioProfile' to 'low'...
Setting 'audioBitrate' to 'auto'...
Setting 'controller' to 'auto'...
Setting 'keyName' to 'r'...
Setting 'keyMods' to 'ctrl+super'...
Setting 'outputFile' to '~/Videos/ReplaySorcery_%F_%H-%M-%S.mp4'...
Setting 'outputCommand' to 'notify-send ReplaySorcery "Saved replay as %s"'...
Reading config file '/home/brian/.config/replay-sorcery.conf'...
Setting 'videoInput' to 'hwaccel'...
Setting 'videoFramerate' to '60'...
Setting 'videoWidth' to '2560'...
Setting 'videoHeight' to '1440'...
Setting 'videoDevice' to 'card0:60'...
ReplaySorcery  Copyright (C) 2020  ReplaySorcery developers
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; see COPYING for details.
FFmpeg version: n4.4
[kmsgrab @ 0x55bed27113c0] Template framebuffer is 143: 2560x1440 format 34325258 modifier 200000020801b03 flags 2.
Created KMS device
[h264_vaapi @ 0x55bed2714980] Filter graph: hwmap=derive_device=vaapi,crop=2560:1440:0:0,scale_vaapi=2560:1440:nv12
ATTENTION: default value of option mesa_glthread overridden by environment.
[h264_vaapi @ 0x55bed2714980] H.264 baseline profile is not supported, using constrained baseline profile instead.
[h264_vaapi @ 0x55bed2714980] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).
[h264_vaapi @ 0x55bed2714980] Quality attribute is not supported: will use default quality level.
Created VA-API encoder
PulseAudio server: pulseaudio 14.2
Connecting to Pulse Audio device: alsa_output.pci-0000_0c_00.4.analog-stereo.monitor...
Created PulseAudio device
X11 version: 11.0
X11 vendor: The X.Org Foundation v12011000
Created X11 controller
Segment violation
 - /home/brian/Documents/ReplaySorcery/src/log.c:76 (logSignal)
 - /home/brian/Documents/ReplaySorcery/src/encoder/ffenc.c:110 (ffmpegEncoderSendFrame)
 - /home/brian/Documents/ReplaySorcery/src/audio/../encoder/encoder.h:34 (rsEncoderSendFrame)
 - /home/brian/Documents/ReplaySorcery/src/main.c:75 (mainStep)
 - /home/brian/Documents/ReplaySorcery/src/main.c:203 (main)
fish: Job 1, 'replay-sorcery' terminated by signal SIGABRT (Abort)
matanui159 commented 3 years ago

Huh that's weird :thinking: Potentially some form of quirk with the newest cards?

abienz commented 3 years ago

I have the same card and also Hardware Acceleration doesn't function, my log is different however.

Sep 16 13:40:01 arch-desk systemd[1211]: Stopped ReplaySorcery: an open-source, instant-replay solution for Linux..
Sep 16 13:40:01 arch-desk systemd[1211]: Started ReplaySorcery: an open-source, instant-replay solution for Linux..
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Real user ID: 1000
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Effective user ID: 1000
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Reading config file '/usr/etc/replay-sorcery.conf'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'logLevel' to 'info'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'traceLevel' to 'error'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'recordSeconds' to '30'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoInput' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoDevice' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoX' to '0'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoY' to '0'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoWidth' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoHeight' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoFramerate' to '30'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoEncoder' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoProfile' to 'baseline'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoPreset' to 'fast'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoQuality' to '28'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoBitrate' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoGOP' to '30'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'scaleWidth' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'scaleHeight' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioInput' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioDevice' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioSamplerate' to '44100'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioEncoder' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioProfile' to 'low'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'audioBitrate' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'controller' to 'auto'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'keyName' to 'r'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'keyMods' to 'ctrl+super'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'outputFile' to '~/Videos/ReplaySorcery/%F_%H-%M-%S.mp4'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'outputCommand' to 'notify-send ReplaySorcery "Saved replay as %s"'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Reading config file '/home/alex/.config/replay-sorcery.conf'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Setting 'videoInput' to 'kms_service'...
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: ReplaySorcery  Copyright (C) 2020-2021  ReplaySorcery developers
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: This program comes with ABSOLUTELY NO WARRANTY.
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: This is free software, and you are welcome to redistribute it
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: under certain conditions; see COPYING for details.
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: FFmpeg version: n4.4
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: [h264_vaapi @ 0x5596c25e7380] Filter graph: hwmap=derive_device=vaapi,crop=3440:1440:0:0,scale_vaapi=3440:1440:nv12
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: [AVHWDeviceContext @ 0x5596c25f3000] Failed to initialise VAAPI connection: -1 (unknown libva error).
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: [Parsed_hwmap_0 @ 0x5596c25ed640] Failed to created derived device context: -5.
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: [Parsed_hwmap_0 @ 0x5596c25ed640] Failed to configure output pad on Parsed_hwmap_0
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: [AVFilterGraph @ 0x5596c25ea440] Failed to configure filter graph: Input/output error
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Unused option: rc_mode
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Failed to create VA-API encoder: Input/output error
Sep 16 13:40:01 arch-desk replay-sorcery[19391]: Function not implemented
Sep 16 13:40:01 arch-desk systemd[1211]: replay-sorcery.service: Main process exited, code=exited, status=1/FAILURE
Sep 16 13:40:01 arch-desk systemd[1211]: replay-sorcery.service: Failed with result 'exit-code'.
Sep 16 13:40:01 arch-desk systemd[1211]: replay-sorcery.service: Scheduled restart job, restart counter is at 5.
Sep 16 13:40:01 arch-desk systemd[1211]: Stopped ReplaySorcery: an open-source, instant-replay solution for Linux..
Sep 16 13:40:01 arch-desk systemd[1211]: replay-sorcery.service: Start request repeated too quickly.
Sep 16 13:40:01 arch-desk systemd[1211]: replay-sorcery.service: Failed with result 'exit-code'.
Sep 16 13:40:01 arch-desk systemd[1211]: Failed to start ReplaySorcery: an open-source, instant-replay solution for Linux..

and my replay-sorcery-kms service status is as follows:

● replay-sorcery-kms.service - ReplaySorcery KMS service
     Loaded: loaded (/usr/lib/systemd/system/replay-sorcery-kms.service; enabled; vendor preset: disabled)
     Active: active (running) since Thu 2021-09-16 13:38:50 BST; 7min ago
   Main PID: 19209 (replay-sorcery)
      Tasks: 1 (limit: 38392)
     Memory: 10.2M
        CPU: 30ms
     CGroup: /system.slice/replay-sorcery-kms.service
             └─19209 /usr/bin/replay-sorcery kms-service

Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Framerate = 30, Device = auto
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: [kmsgrab @ 0x5628b42f0680] Using plane 65 to locate framebuffers.
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: [kmsgrab @ 0x5628b42f0680] Template framebuffer is 123: 3440x1440 format 34325258 modifier 200000020937b03 flags 2.
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Failed to send message: Broken pipe
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Disconnected: Broken pipe
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Framerate = 30, Device = auto
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: [kmsgrab @ 0x5628b42f0680] Using plane 65 to locate framebuffers.
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: [kmsgrab @ 0x5628b42f0680] Template framebuffer is 123: 3440x1440 format 34325258 modifier 200000020937b03 flags 2.
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Failed to send message: Broken pipe
Sep 16 13:45:42 arch-desk replay-sorcery[19209]: Disconnected: Broken pipe
matanui159 commented 3 years ago

Can you see what vainfo produces (you might have to install a package for it)?

abienz commented 3 years ago

hmm when I run that I get an error

vaInitialize failed with error code -1 (unknown libva error),exit
matanui159 commented 3 years ago

Yeah just seems to be an issue with the drivers

abienz commented 3 years ago

Ah ok, so I'm running this on mesa drivers with amdgpu, does Hardware Acceleration on Replay Sorcery work with the OSS drivers?

abienz commented 3 years ago

OK after a bit of reading and research thanks to @matanui159 I have solved my issue with this.

Simply put I didn't have va-api support installed, only vdpau.

This is why I had that error earlier, so simply installing the libva-mesa-driver package and restarting the service worked for me.

Now replay-sorcery is running while I'm idle on desktop at 0.10% cpu utilization, which is much more reasonable.

Resource here: https://wiki.archlinux.org/title/Hardware_video_acceleration#ATI/AMD