Vencord / Vesktop

Vesktop is a custom Discord App aiming to give you better performance and improve linux support
GNU General Public License v3.0
4.24k stars 189 forks source link

--enable-features flags not passed into Electron #526

Closed takase1121 closed 6 months ago

takase1121 commented 6 months ago

Describe the bug

I am trying to get VAAPI Video Decoding to work on amdgpu, which needs a bunch of flags and some amount of prayers. Since Vesktop tries to append it's own enable-features flags this caused it to override the previous (user added) flags. I have no proof of this happening, but in my testing removing this line made it work:

https://github.com/Vencord/Vesktop/blob/8eaa5206b98ce7029b6879cc2ce361c2ae5f6239/src/main/index.ts#L33

Those flags has good intentions, but it will take more flags (to force Electron to use ANGLE and ANGLE to use Vulkan) to make it work, and it's not possible to set them if it got overridden by the flags above.

To Reproduce

Not working

  1. Install vesktop-git from AUR.
  2. run vesktop --use-gl=angle --use-angle=vulkan --ignore-gpu-blocklist --enable-gpu-rasterization --enable-zero-copy --enable-features=Vulkan,VulkanFromANGLE,DefaultANGLEVulkan,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport,UseMultiPlaneFormatForHardwareVideo
  3. womp womp womp womp

Making it work

  1. clone Vesktop, remove the line in https://github.com/Vencord/Vesktop/blob/8eaa5206b98ce7029b6879cc2ce361c2ae5f6239/src/main/index.ts#L33
  2. pnpm i && pnpm build
  3. electron29 --use-gl=angle --use-angle=vulkan --ignore-gpu-blocklist --enable-gpu-rasterization --enable-zero-copy --enable-features=Vulkan,VulkanFromANGLE,DefaultANGLEVulkan,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport,UseMultiPlaneFormatForHardwareVideo .
  4. Electron tries to use GPU to decode (good effort but still terrible)

Expected behavior

Vesktop can detect if --enable-features is set, get all the flags and append its own flags. After that, Vesktop will append it back to app.cmdLine.

Screenshots

Working image

Not Working image

Desktop (please complete the following information):

Command line output

Not working:

[takase@nijika Vesktop]$ vesktop --use-gl=angle --use-angle=vulkan --ignore-gpu-blocklist --enable-hagpu-rasterization --enable-zero-copy --enable-features=Vulkan,VulkanFromANGLE,DefaultANGLEVulkan,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport,UseMultiPlaneFormatatForHardwareVideo .
[34770:0420/222341.067069:ERROR:gl_surface_egl.cc(430)] eglCreateWindowSurface failed with error EGL_BAD_CONFIG
[34770:0420/222341.068479:ERROR:gl_surface_egl.cc(430)] eglCreateWindowSurface failed with error EGL_BAD_CONFIG

Working:

[takase@nijika Vesktop]$ electron29 --use-gl=angle --use-angle=vulkan --ignore-gpu-blocklist --enable-hagpu-rasterization --enable-zero-copy --enable-features=Vulkan,VulkanFromANGLE,DefaultANGLEVulkan,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport,UseMultiPlaneFormatForHardwareVideo .
[32876:0420/214736.951896:ERROR:gl_utils.cc(424)] [.RendererMainThread-0xf0001a54e00]GL DriverMessage (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels
[32876:0420/214736.955938:ERROR:gl_utils.cc(424)] [.RendererMainThread-0xf0001a54e00]GL DriverMessage (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels
[32876:0420/214736.960205:ERROR:gl_utils.cc(424)] [.RendererMainThread-0xf0001a54e00]GL DriverMessage (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels
[32876:0420/214739.618146:ERROR:gl_utils.cc(424)] [.RendererMainThread-0xf0001a54e00]GL DriverMessage (OpenGL, Performance, GL_CLOSE_PATH_NV, High): GPU stall due to ReadPixels (this message will no longer repeat)
[32876:0420/222323.142360:ERROR:angle_vulkan_image_backing.cc(653)] Importing textures with external sampling into GL is not possible
[32876:0420/222323.142536:ERROR:shared_image_manager.cc(228)] SharedImageManager::ProduceSkia:Trying to produce a Skia representation from an incompatible backing: AngleVulkanImageBacking
[32876:0420/222323.142866:ERROR:gl_utils.cc(420)] [.RendererMainThread-0xf0001a54e00] GL_INVALID_VALUE: unknown source image mailbox.

Additional context

At this point I am not even sure if Electron is using GPU acceleration. It's barely using any VRAM and all the stuff is stored in GTT (RAM). Testing with powertop does give me a 2W decrease in power consumption, so I'll take it.

For reference:

  1. PR to support hardware video decoding in amdgpu: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26165#note_2367572
  2. Command to enable it in Chromium/Electron: https://bbs.archlinux.org/viewtopic.php?id=244031&p=40
Vendicated commented 6 months ago

you should figure out which of these flags are necessary for it to work and open a pr that adds them to the source code. this way it can benefit everyone

takase1121 commented 6 months ago

In my testing, all the flags I placed there is necessary, but it will have to know if the driver is amdgpu (because the whole ANGLE Vulkan dance is only needed (probably for now) for AMD only). Besides, this is using mesa-git and not generally available which is why I'm not comfortable with adding it to Vesktop yet.

I'm suggesting a way to passthrough enable-feature flags to Vesktop. I believe that Vesktop is doing great with the flags, but if the user tries to pass something to Electron, Vesktop should not override it. Maybe detecting if enable-features is present will be a better solution (assuming that Chromium actually only take the last enable-feature flags).

takase1121 commented 6 months ago

Yep, confirmed that the last switch will override all previous switches: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line.h;l=9;drc=515737a1eff38ecfffef07d7dbf5717742cab958

hypevhs commented 6 months ago

As for your proposal to add that long list of flags to Vesktop, on my machine, it prints that the settings for angle/vulkan are not an allowed combination. AMD Arch KDE Wayland electron29. Just my 2c of unsolicited feedback.

takase1121 commented 6 months ago

As for your proposal to add that long list of flags to Vesktop, on my machine, it prints that the settings for angle/vulkan are not an allowed combination. AMD Arch KDE Wayland electron29. Just my 2c of unsolicited feedback.

  1. You need mesa-git, specifically 24.1-devel
  2. Wayland is currently out of the question, you need to at least run it in XWayland, sorry
  3. You need to use system Electron.
  4. Make sure you have a Vulkan driver installed.

Now you get the idea why these flags must not be added to Vesktop for now. They're highly experienmental and one wrong move will disable GPU acceleration completely.