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

Change VaapiVideoEncoder to AcceleratedVideoEncoder #1007

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ImUrX
Copy link

@ImUrX ImUrX commented Dec 14, 2024

From what I checked VaapiVideoEncoder doesn't seem to work when checking chrome://gpu, it keeps saying Video Encode: Software only. Hardware acceleration disabled. But if you use AcceleratedVideoEncoder it does say Video Encode: Hardware accelerated.

I tried verifying if this actually does something, and when using nvtop it does show activity on the ENC section when using AcceleratedVideoEncoder but it doesn't when using VaapiVideoEncoder.

For debugging purposes I leave my output of vainfo:

$ vainfo 
Trying display: wayland
libva info: VA-API version 1.22.0
libva info: Trying to open /run/opengl-driver/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_1_22
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: Mesa Gallium driver 24.2.6 for AMD Radeon RX 7900 XTX (radeonsi, navi31, LLVM 18.1.8, DRM 3.59, 6.11.10-xanmod1)
vainfo: Supported profile and entrypoints
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileHEVCMain               : VAEntrypointVLD
      VAProfileHEVCMain               : VAEntrypointEncSlice
      VAProfileHEVCMain10             : VAEntrypointVLD
      VAProfileHEVCMain10             : VAEntrypointEncSlice
      VAProfileJPEGBaseline           : VAEntrypointVLD
      VAProfileVP9Profile0            : VAEntrypointVLD
      VAProfileVP9Profile2            : VAEntrypointVLD
      VAProfileAV1Profile0            : VAEntrypointVLD
      VAProfileAV1Profile0            : VAEntrypointEncSlice
      VAProfileNone                   : VAEntrypointVideoProc

@ImUrX
Copy link
Author

ImUrX commented Dec 14, 2024

@ImUrX
Copy link
Author

ImUrX commented Dec 14, 2024

I want to also specify that I wasn't able to make --enable-features work on Vesktop, I'm not even sure that they are passed to Chromium.
But the feature I suggest to use does work when using Discord Web on Chromium

@Covkie
Copy link
Collaborator

Covkie commented Dec 15, 2024

The 'Vaapi' -> 'Accelerated' flag change is for a later version of chromium than electron33 currently runs. This change will need to be made when we bump to 34 or later.

@Covkie Covkie closed this Dec 15, 2024
@Vendicated Vendicated reopened this Dec 15, 2024
@Vendicated Vendicated marked this pull request as draft December 15, 2024 02:04
@danielfrrrr
Copy link

Although the VaapiVideoDecoder and VaapiVideoDecodeLinuxGL options are enabled by default, they have also been renamed: AcceleratedVideoDecoder and AcceleratedVideoDecodeLinuxGL.

See: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/gpu/vaapi.md#vaapi-on-linux

@Sid127
Copy link

Sid127 commented Jan 20, 2025

Electron 34 is out with the chromium version that has these new flags

@ninja-
Copy link

ninja- commented Jan 20, 2025

I would appreciate fixing AMD VA-API encoding even before Electron 34 is used, so adding PlatformHEVCDecoderSupport,VaapiVideoDecoder,VaapiVideoEncoder,VaapiIgnoreDriverChecks, there is no way to override these flags without building whole Vesktop manually

@Vendicated
Copy link
Member

there is no way to override these flags without building whole Vesktop manually

this is just not true. you can pass them via command line flag vesktop --enable-features=Feat1,Feat2,Feat3

@ninja-
Copy link

ninja- commented Jan 20, 2025

ok, I missed the part where Vesktop reads passed enable-features and merges them now I see it. without it, Chrome doesn't merge enable-featuers and would pick the first one or last one or something

@ninja-
Copy link

ninja- commented Jan 20, 2025

Unfortunately, this segfaults with no stacktrace or useful logs after which Vencord restarts with disabled hardware acceleration. I'll try again later with Electron 34.

flatpak run dev.vencord.Vesktop --enable-features=VaapiVideoEncoder,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport

@ninja-
Copy link

ninja- commented Jan 20, 2025

after bumping electron 34 it seems to work correctly without segfault with this set of flags:

diff --git a/src/main/index.ts b/src/main/index.ts
index 4eb863d..2c04a98 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -35,7 +35,7 @@ function init() {
     if (hardwareAcceleration === false) {
         app.disableHardwareAcceleration();
     } else {
-        enabledFeatures.push("VaapiVideoDecodeLinuxGL", "VaapiVideoEncoder", "VaapiVideoDecoder");
+        enabledFeatures.push("AcceleratedVideoDecodeLinuxGL", "VaapiIgnoreDriverChecks", "AcceleratedVideoEncoder", "AcceleratedVideoDecoder");
     }
 
     if (disableSmoothScroll) {
(END)

@Vendicated
Copy link
Member

We definitely should not add likely unstable flags like VaapiIgnoreDriverChecks. Users should experiment with such flags themselves if needed

@ninja-
Copy link

ninja- commented Jan 20, 2025

This flag is nothing else than a whitelist of vendors being just "Intel". This combination of flags is known to be fully stable in recent Chromium versions with AMD.
You can't get around Google's stubbornness in heavy feature gating of this stuff and they don't plan on changing policy any time soon no matter how stable VA-API is and no matter how much testing it gets.

https://source.chromium.org/chromium/chromium/src/+/main:media/mojo/services/gpu_mojo_media_client_linux.cc;l=144?q=VaapiIgnoreDriverChecks&ss=chromium

@Vendicated
Copy link
Member

that piece of code explicitly states it is broken on Novideo though. Does that mean it will possibly crash on NVIDIA GPUs? If yes, that would be unacceptable. Perhaps it should only be enabled if not using Novideo

@ninja-
Copy link

ninja- commented Jan 20, 2025

This does nothing on Nvidia because Nvidia does not ship any VA-API backends.

There's a community driver but it doesnt support encoding so not useful for streaming https://github.com/elFarto/nvidia-vaapi-driver

src/main/index.ts Outdated Show resolved Hide resolved
@ImUrX
Copy link
Author

ImUrX commented Jan 23, 2025

From what I see this argument is only needed if Vulkan is used, I'm not sure if electron or vesktop even come with vulkan enabled

@Vendicated
Copy link
Member

you can verify if it works by opening chrome://gpu with Vesktop

just launch a new window with that as url to test

@Vendicated
Copy link
Member

I added a Button to the Vesktop settings to open this page via 030ffca

image

@notpeelz
Copy link

image

Seems to work on my machine.
GPU: Radeon 6900 XT

@Covkie
Copy link
Collaborator

Covkie commented Jan 24, 2025

That UI lies sometimes. Try streaming and use nvtop and watch the encode bar

Vaapi on amd is only fully supported with vulkan so you might need to enable that. https://wiki.archlinux.org/title/Chromium#Hardware_video_acceleration (Encode seems to work fine with GL for me so ymmv)

Nvidia drivers do not support vaapi so anyone on pure nvidia is out of luck there.

Anyway beyond these generic flags we can't really do more as that may break other setups. Youll have to find flags that work for you.

@notpeelz
Copy link

notpeelz commented Jan 24, 2025

Yeah... looks like it's not using my GPU encoder at all.

If I pass --enable-features=Vulkan, I get this error on startup (with Wayland enabled):

[82043:0124/014124.666709:ERROR:wayland_surface_factory.cc(237)] '--ozone-platform=wayland' is not compatible with Vulkan. Consider switching to '--ozone-platform=x11' or disabling Vulkan

Ignoring the error above, it seems to use about 10-20% of my encoder when I screen share, but my friend tells me there's a lot of datamoshed/"black" frames like this:
Capture

Any hardware-accelerated video stream (including my own stream preview) renders as a white image and spams this error:

[82043:0124/014354.248613:ERROR:shared_image_manager.cc(256)] SharedImageManager::ProduceSkia: Trying to produce a Skia representation from an incompatible backing: CompoundImageBacking

image

@Covkie
Copy link
Collaborator

Covkie commented Jan 24, 2025

you need quite a few more flags for full vulkan support. follow the archwiki entry

@notpeelz
Copy link

Do you mean these flags?

I'm running vesktop from this PR branch like this:

pnpm start --ozone-platform=wayland --enable-features=VaapiVideoDecoder,VaapiIgnoreDriverChecks,Vulkan,DefaultANGLEVulkan,VulkanFromANGLE

I still get a ton of datamoshing/black frames.
What flags do you use? Does it work on your end?

@ImUrX
Copy link
Author

ImUrX commented Jan 24, 2025

@ninja-
Copy link

ninja- commented Jan 25, 2025

[82043:0124/014354.248613:ERROR:shared_image_manager.cc(256)] SharedImageManager::ProduceSkia: Trying to produce a Skia representation from an incompatible backing: CompoundImageBacking

mine works correctly, confirmed by nvtop. have you all guys bumped package.json to electron 34 first before testing like I did?

@ninja-
Copy link

ninja- commented Jan 25, 2025

I wouldn't bet on Vulkan too much. First Chromium build to support AMD VA-API few months back required Vulkan, but lately they added missing OpenGL support and balanced that out by breaking Vulkan-Wayland integration again symbolized by that ugly warning

[82043:0124/014124.666709:ERROR:wayland_surface_factory.cc(237)] '--ozone-platform=wayland' is not compatible with Vulkan. Consider switching to '--ozone-platform=x11' or disabling Vulkan

but if I force Vulkan, everything continues to work after this warning and chrome://gpu shows Vulkan as enabled, so idk

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.

7 participants