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

Font rendering isn't gamma corrected when using WebGpu? #3032

Open
mrim5 opened this issue Jan 30, 2023 · 21 comments
Open

Font rendering isn't gamma corrected when using WebGpu? #3032

mrim5 opened this issue Jan 30, 2023 · 21 comments
Labels
bug Something isn't working

Comments

@mrim5
Copy link

mrim5 commented Jan 30, 2023

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

Windows

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

No response

WezTerm version

20230124-182614-9d7e613c

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

wez_gamma

Using WebGpu, font rendering appears fine when using a negative polarity (light-on-dark) color scheme. However, when using a positive polarity (dark-on-light) color scheme, fonts appear not to be properly gamma corrected, in that their opacity seems too low and so the dark text color blends too much into the light background. On the right half of the above image, I included Windows Terminal as a reference example more in line with what I would consider normal.

To Reproduce

Use a dark-on-light color scheme while using WebGpu and observe the faint text rendering.

Configuration

front_end = "WebGpu",
freetype_load_target = "Normal",
freetype_render_target = "Normal"

Expected Behavior

Light text rendered against a dark background should appear as clear and fully opaque as dark text rendered against a light background.

Logs

wezterm version: 20230124-182614-9d7e613c x86_64-pc-windows-msvc
Window Environment: Windows
OpenGL version: WebGPU: name=NVIDIA GeForce RTX 2080, device_type=DiscreteGpu, backend=Vulkan, driver=NVIDIA, driver_info=516.94, vendor=4318, device=7810

Anything else?

No response

@mrim5 mrim5 added the bug Something isn't working label Jan 30, 2023
@DerekSauer
Copy link

DerekSauer commented Feb 6, 2023

I'm getting the same effect when using the WebGpu front end across several systems and GPUs both on an older version of Wezterm and the nightly version when I tested this (2023-02-02).

WezTerm version
stable version: 20221119-145034-49b9839f
nightly version: 20230202-082731-ed444faf

Configuration
Only switching between "OpenGL" and "WebGpu" front-ends. I use default settings for font rendering. No Freetype hints.
Full config available here if needed.

Older Desktop PC - Window 10 Pro (10.0.19045)

OpenGL version:
Intel(R) HD Graphics 530 4.5.0 - Build 31.0.101.2114

OpenGL version: WebGPU:
name=Intel(R) HD Graphics 530
device_type=IntegratedGpu
backend=Vulkan
driver=Intel Corporation
driver_info=Intel driver
vendor=32902
device=6418

Work_Win32

Newer Desktop PC - Windows 10 Pro (10.0.19045)

OpenGL:
OpenGL version: NVIDIA GeForce RTX 2070/PCIe/SSE2 4.5.0 NVIDIA 522.25

OpenGL version: WebGPU:
name=NVIDIA GeForce RTX 2070
device_type=DiscreteGpu
backend=Vulkan
driver=NVIDIA
driver_info=522.25
vendor=4318
device=7943

Home_Win32

Laptop - Fedora Workstation 37

Wayland on Mutter compositor.

OpenGL version: WebGPU:
name=Intel(R) UHD Graphics (CML GT2)
device_type=IntegratedGpu, backend=Vulkan
driver=Intel open-source Mesa driver
driver_info=Mesa 21.3.9 (git-78c96ae5b6)
vendor=32902
device=39745

Laptop_Fedora


Particularly noticeable with an inherently thinner font face like Iosevka.
Work_Iosevka

@wez
Copy link
Owner

wez commented Feb 6, 2023

I think this is an upstream bug with the vulkan backend, and we're waiting on a release:

wez added a commit that referenced this issue Feb 6, 2023
This might help with #3032
@wez
Copy link
Owner

wez commented Feb 6, 2023

There was a recent wgpu release that adds some explicit control over srgb-ness, so I've updated to that.
That release doesn't include the gamma fix mentioned in the issue linked in my previous comment.
I've only tested this so far on macOS/Metal, and will test a little later on Windows/Vulkan.
Please give it a try and let me know how it works for you!

@DerekSauer
Copy link

It doesn't look like that change had any noticeable effect. This is on the same machine as the "older PC" above. Windows 10 with Intel HD integrated GPU.

Wezterm_WebGPU_NewPatch

To be on the safe side I also forced Wezterm to use the Dx12 backend which had the same results.

Wezterm_Dx12

@pragma-
Copy link

pragma- commented Feb 11, 2023

Can confirm that front_end = "WebGpu" causes my fonts to render in greyscale anti-aliasing which makes them look thick/bold. Setting front_end = "OpenGL" fixes my fonts and renders them with dark red/blue anti-aliasing which makes them look normal/thin again.

I'd been banging my head against my keyboard struggling with various incantions of freetype_render_target and freetype_load_target until I stumbled upon this issue and tried setting front_end back to "OpenGL" instead of "WebGpu".

edit: This is on Windows 10 with a GTX 1080.

imsnif pushed a commit to imsnif/wezterm that referenced this issue Feb 11, 2023
This might help with wez#3032
imsnif pushed a commit to imsnif/wezterm that referenced this issue Feb 11, 2023
@crimist
Copy link

crimist commented Feb 25, 2023

Also getting overly thick/bold fonts and odd flicker on WebGpu with Wayland & Nvidia.

Upgrading to wgpu 0.15.1 doesn't seem to help.

diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml
index 046837dc..de425b7c 100644
--- a/wezterm-gui/Cargo.toml
+++ b/wezterm-gui/Cargo.toml
@@ -101,7 +101,7 @@ wezterm-mux-server-impl = { path = "../wezterm-mux-server-impl" }
 wezterm-ssh = { path = "../wezterm-ssh" }
 wezterm-term = { path = "../term", features=["use_serde"] }
 wezterm-toast-notification = { path = "../wezterm-toast-notification" }
-wgpu = "0.15"
+wgpu = "0.15.1"
 window = { path = "../window" }
 window-funcs = { path = "../lua-api-crates/window-funcs" }

I've tried to video capture the flicker but it doesn't show up due to the video framerate and I can't get OBS working on wayland. The flicker seems to display a previous frame for a brief second. Like so.

1 -> 1 -> 1 -> 2 -> 2 -> 1* -> 2 -> 2

* Should be frame 2 but previous frame is drawn for a couple refresh cycles.

@musjj
Copy link

musjj commented Mar 7, 2023

Tried the latest nightly release (20230306-150040-c3286f1b), but I'm still experiencing this:

wezterm-gui_2023-03-07_18-34-02

2023-03-07_18-34-49

@Tomiyou
Copy link

Tomiyou commented Jul 6, 2023

I have the exact same issue on Ubuntu 22.04 running Gnome with Wayland. Using OpenGL resolves the issue. I am using the latest Nightly build.

Debug Overlay
wezterm version: 20230703-132344-9459f64c x86_64-unknown-linux-gnu
Window Environment: Wayland
WebGPU: name=Intel(R) UHD Graphics (CML GT2), device_type=IntegratedGpu, backend=Vulkan, driver=Intel open-source Mesa driver, driver_info=Mesa 22.2.5-0ubuntu0.1~22.04.3, vendor=32902, device=39745
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit

@cloudUser98
Copy link

Same problem running the nightly rpm version on Fedora 36, any solutions aside from using openGL as the front end?

@xorander00
Copy link

Throwing in my $0.02.

Snippet from wezterm.lua, with notes, after playing around with settings

local M = {}
-- M.{ ... }

-- backend(Vulkan)   device(7944)    device_type(DiscreteGpu)  vendor(4318)  name(NVIDIA GeForce RTX 2060)              driver(NVIDIA)
-- backend(Gl)       device(0)       device_type(Other)        vendor(4318)  name(NVIDIA GeForce RTX 2060/PCIe/SSE2)
-- backend(Vulkan)   device(0)       device_type(Cpu)          vendor(65541) name(llvmpipe (LLVM 15.0.7, 256 bits))     driver(llvmpipe)
-- local gpu_backend = 'Vulkan'
-- local gpu_device = 7944
local gpu_device_type = 'DiscreteGpu'

-- WebGpu | OpenGL | Software
M.front_end = 'WebGpu'
M.webgpu_power_preference = 'HighPerformance'
M.webgpu_force_fallback_adapter = false

-- NOTE: Results                                                                              Fidelity      CPU Usage     Renderer Type
-- gpu_device_type(DiscreteGpu) + front_end(WebGpu) = llvmpipe (LLVM 15.0.7, 256 bits)        OK            HIGH          Software
-- gpu_device_type(DiscreteGpu) + front_end(OpenGL) = NVIDIA GeForce RTX 2060/PCIe/SSE2       DARK          LOW           Hardware
-- gpu_device_type(DiscreteGpu) + front_end(Software) = NVIDIA GeForce RTX 2060/PCIe/SSE2     DARK          LOW           Software
-- gpu_device_type(Other) + front_end(WebGpu) = llvmpipe (LLVM 15.0.7, 256 bits)              OK            HIGH          Software
-- gpu_device_type(Other) + front_end(OpenGL) = NVIDIA GeForce RTX 2060/PCIe/SSE2             DARK          LOW           Hardware
-- gpu_device_type(Other) + front_end(Software) = NVIDIA GeForce RTX 2060/PCIe/SSE2           DARK          LOW           Software

-- NOTE: Messages
-- 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.

-- NOTE: Status & Potential Causes/Fixes
-- /usr/bin/env DISPLAY= wezterm start --always-new-process
-- WebGpu + DiscreteGpu would be ideal, but it keeps falling back to llvmpipe, which looks to use implement software-rendered Vulkan|OpenGL
-- OpenGL + DiscreteGpu works too, but the window is way too dark (probably easier to try and fix this though)
--
-- nVidia Vulkan driver is incomplete/inadequate/etc with requested surface?
-- Invalid environment variable? (e.g. DISPLAY, launch-related variables?, etc)
-- Missing a required package that bridges Wayland with nVidia/Vulkan?

local is_wayland = os.getenv('WAYLAND_DISPLAY') and true or false
M.enable_wayland = is_wayland
if is_wayland then
  local adapter
  local webgpu_adapters = wezterm.gui.enumerate_gpus()
  for idx, gpu in ipairs(webgpu_adapters) do
    if gpu.device_type == gpu_device_type then
      wezterm.log_info(string.format('Selected adapter: name(%s) device_type(%s) backend(%s)', gpu.name, gpu.device_type, gpu.backend))
      M.webgpu_preferred_adapter = gpu
      break
    else
      wezterm.log_info(string.format('Skipping adapter: name(%s) device_type(%s) backend(%s)', gpu.name, gpu.device_type, gpu.backend))
    end
  end
end

return M

Screenshot demonstrating the the results
20230707_183831

  • Left window is the terminal I'm currently using for now (foot).
  • Upper-right window is Wezterm hardware-rendered via OpenGL (too dark to use).
  • Lower-right window is Wezterm software-rendered via Vulkan+llvmpipe (high CPU usage, but looks like I'm used to).

It does look like it has something to do with the wgpu crate (and this is only occuring in Wezterm), as it's flagging it as incompatible. Though I do wonder why the first enumeration of the GPUs at launch returns three devices, but when I enumerate it in the debug overlay it only shows two devices (DiscreteGpu being filtered out). Is it filtering out the incompatible GPU in the overlay or it somehow unable to enumerate it and not seeing it to begin with?

@wez
Copy link
Owner

wez commented Jul 9, 2023

@xorander00 see also this issue, which may also apply to fbsd:

@xorander00
Copy link

@wez just looked at #1701 and yup, looks likely that applies to me too. FreeBSD-ported nVidia driver package is only up to 525, but I'm currently running an unofficial port of 530. Will look at updating the patches to 535 and see if that fixes it.

Thanks for the tip!

@xorander00
Copy link

@wez Confirmed, upgrading the driver fixed it. For future reference to anyone else, this worked for me...

  • FreeBSD 13.2-STABLE (1302505)
  • nvidia-driver-535.54.03 + nvidia-drm.ko built manually.
  • hyprland-0.27.0
  • wezterm.lua: front_end = 'OpenGL'
wezterm version: 20230408-112425-69ae8472 x86_64-unknown-freebsd
Window Environment: Wayland
OpenGL version: NVIDIA GeForce RTX 2060/PCIe/SSE2 4.6.0 NVIDIA 535.54.03
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
18:07:50.579 INFO logging > lua: Selected adapter: name(NVIDIA GeForce RTX 2060) device_type(DiscreteGpu) backend(Vulkan)
18:07:50.680 INFO logging > lua: Selected adapter: name(NVIDIA GeForce RTX 2060) device_type(DiscreteGpu) backend(Vulkan)
18:15:19.132 INFO logging > lua: Skipping adapter: name(llvmpipe (LLVM 15.0.7, 256 bits)) device_type(Cpu) backend(Vulkan)
18:15:19.132 INFO logging > lua: Skipping adapter: name(NVIDIA GeForce RTX 2060/PCIe/SSE2) device_type(Other) backend(Gl)

@duarteocarmo
Copy link

Getting the same issue on M2 Pro. Decided to downgrade from most recent release. Very weird font behavior..

@wez - happy to provide more details if you have time (I don't expect) to look into this.

Thanks for a great f*ing terminal! Been loving it after ~3 years on Alacritty.

@wez
Copy link
Owner

wez commented Jan 29, 2024

when you say "the most recent release" are you talking about the one made today, or the one from the other day?

@duarteocarmo
Copy link

I'm talking about this one, which changed the default front-end.

  1. an update appeared in my terminal
  2. ran brew upgrade wezterm
  3. Noticed that the fonts gotten much thinner
  4. Changed config to config.front_end = "OpenGL"
  5. Something was still not quite write with the colors
  6. Downgraded from GitHub releases

I can provide some screenshots of the process if you interested, least I can do with the great work you've done here!

@wez
Copy link
Owner

wez commented Jan 29, 2024

I think that's a different issue that relates to macOS font fallback; please file a separate issue

@duarteocarmo
Copy link

duarteocarmo commented Jan 30, 2024

@wez, tested things again this morning, but issue seems to be gone since you changed the front end back to OpenGL.

I still notice a little issue but not sure if worth reporting. Let me know what you think (notice the different colors in the prompt)

giant image Frame 7

@wez
Copy link
Owner

wez commented Jan 30, 2024

Sorry, but I can't really see anything in that image: it's too big. If you want to highlight differences, please keep the screenshots focused in a small region around the area of interest so that it is much easier to see at a glance.

@duarteocarmo
Copy link

Before/after update

image
image

@gabrieldlima
Copy link

Using Wezterm in last commit (X11 - AwesomeWM) with WebGPU still has this same problem.

Fonts are all bold

2024-12-28_12-25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests