wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.84k stars 799 forks source link

Wayland + WebGpu #3917

Open xorander00 opened 1 year ago

xorander00 commented 1 year ago

What Operating System(s) are you seeing this problem on?

FreeBSD Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

Hyprland 0.26.0

WezTerm version

20230408-112425-69ae8472

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

(I also tried with the nightly version f376468f461d668ef3748c82fa40eab5b955d677 from last night with the same results)

CPU usage is high when using WezTerm under Wayland with nVidia. Guessing there's an issue with it getting and keeping a rendering context, but not sure yet, just started investigating. Works fine under Xorg with Picom + Awesome WM, which is what I just switched over from a few days ago.

wezterm.gui.enumerate_gpus():

[
    {
        "backend": "Vulkan",
        "device": 7944,
        "device_type": "DiscreteGpu",
        "driver": "NVIDIA",
        "driver_info": "530.41.03",
        "name": "NVIDIA GeForce RTX 2060",
        "vendor": 4318,
    },
    {
        "backend": "Vulkan",
        "device": 0,
        "device_type": "Cpu",
        "driver": "llvmpipe",
        "driver_info": "Mesa 22.3.7 (LLVM 15.0.7)",
        "name": "llvmpipe (LLVM 15.0.7, 256 bits)",
        "vendor": 65541,
    },
    {
        "backend": "Gl",
        "device": 0,
        "device_type": "Other",
        "name": "NVIDIA GeForce RTX 2060/PCIe/SSE2",
        "vendor": 4318,
    },
]

To Reproduce

Issue is observable via normal usage under the environment as follows:

Configuration

-- > wezterm.gui.enumerate_gpus() -- [ -- { -- "backend": "Vulkan", -- "device": 7944, -- "device_type": "DiscreteGpu", -- "driver": "NVIDIA", -- "driver_info": "530.41.03", -- "name": "NVIDIA GeForce RTX 2060", -- "vendor": 4318, -- }, -- { -- "backend": "Vulkan", -- "device": 0, -- "device_type": "Cpu", -- "driver": "llvmpipe", -- "driver_info": "Mesa 22.3.7 (LLVM 15.0.7)", -- "name": "llvmpipe (LLVM 15.0.7, 256 bits)", -- "vendor": 65541, -- }, -- { -- "backend": "Gl", -- "device": 0, -- "device_type": "Other", -- "name": "NVIDIA GeForce RTX 2060/PCIe/SSE2", -- "vendor": 4318, -- }, -- ]

local webgpu_adapters = wezterm.gui.enumerate_gpus() local webgpu_adapter = webgpu_adapters[1]

return { check_for_updates = false, automatically_reload_config = false,

-- prefer_egl = true, front_end = 'WebGpu', -- WebGpu | OpenGL | Software webgpu_preferred_adapter = webgpu_adapter, enable_wayland = true, animation_fps = 1, cursor_blink_ease_in = 'Constant', cursor_blink_ease_out = 'Constant', swallow_mouse_click_on_window_focus = true, swallow_mouse_click_on_pane_focus = true, adjust_window_size_when_changing_font_size = true, hide_tab_bar_if_only_one_tab = true, window_padding = { top = 0, right = 0, bottom = 0, left = 0, }, warn_about_missing_glyphs = false, allow_square_glyphs_to_overflow_width = 'WhenFollowedBySpace', -- WhenFollowedBySpace | Always | Never

color_scheme = 'tokyonight', -- nightfox | tokyonight | tokyonight-storm colors = { compose_cursor = 'orange', },

term = 'xterm-256color', -- xterm-256color | wezterm

exit_behavior = 'CloseOnCleanExit', quick_select_patterns = _defs.quick_select_patterns, }

Expected Behavior

No response

Logs

08:29:28.207 WARN wezterm_gui::termwindow::webgpu > name=NVIDIA GeForce RTX 2060/PCIe/SSE2, device_type=Other, backend=Gl, vendor=4318, device=0 is not compatible with surface 08:29:28.207 WARN wezterm_gui::termwindow::webgpu > Your webgpu preferred adapter 'name=NVIDIA GeForce RTX 2060, device_type=DiscreteGpu, backend=Vulkan, driver=NVIDIA, driver_info=530.41.03, vendor=4318, device=7944' was either not found or is not compatible with your display. Available: name=llvmpipe (LLVM 15.0.7, 256 bits), device_type=Cpu, backend=Vulkan, driver=llvmpipe, driver_info=Mesa 22.3.7 (LLVM 15.0.7), vendor=65541, device=0, compatible=yes name=NVIDIA GeForce RTX 2060/PCIe/SSE2, device_type=Other, backend=Gl, vendor=4318, device=0, compatible=NO

Anything else?

It wouldn't totally surprise me if there's an issue with nVidia driver support under Wayland, but before I completely write it off as that I'd like to make sure it's not something that can be addressed via WezTerm configuration and/or minor code patch.

I did try all possibly combinations of...

Basically, the rendering output with WebGpu looks great (same as Xorg), but my CPU usage shoots up. When set to Software, it renders with lower fidelity and much darker (as expected).

Last night, before setting front_end=Software, and the rendering output looked great but the CPU usage shot up, I thought it was falling back to software rendering. But then this morning when I explicitly changed it to Software from WebGpu, the CPU usage went down to nothing and the rendering output...definitely looked like it was software rendered.

So now I'm wondering if front_end=WebGpu (high-fidelity output) with high CPU usage is actually getting an OpenGL rendering context and using it, but the underlying implementation is incomplete/crappy/etc and using the software implementation.

Anyway, any further thoughts/comments/etc would be appreciated. Would ideally like to get this resolved. Going to do some quick looking through of the source to see if I can find more ideas.

xorander00 commented 1 year ago

Had a chance to look at it a bit more earlier today. I suspect wgpu is returning false when checking surface compatibility due to the nVidia driver, though I haven't 100% confirmed it yet. Will look and see if there's a trivial way to workaround it for now, and if so, then I'll submit a PR, otherwise I might just change to an AMD GPU instead.

xorander00 commented 1 year ago

Related to #3032, I think.