roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.42k stars 310 forks source link

editor: render_format GPU issue on PopOS / AMD mobile system #2015

Open jthegedus opened 2 years ago

jthegedus commented 2 years ago

I got this error when building the editor on PopOS 21.04 system:

➜ uname -a
Linux art 5.13.0-7620-generic #20~1634827117~21.04~874b071-Ubuntu SMP Fri Oct 29 15:06:55 UTC  x86_64 x86_64 x86_64 GNU/Linux

➜ npx envinfo --system

  System:
    OS: Linux 5.13 Pop!_OS 21.04
    CPU: (8) x64 AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx
    Memory: 2.78 GB / 15.26 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh

➜ RUST_BACKTRACE=1 cargo run edit
    Blocking waiting for file lock on build directory
   Compiling roc_editor v0.1.0 (/home/jthegedus/projects/roc/editor)
   Compiling roc_cli v0.1.0 (/home/jthegedus/projects/roc/cli)
    Finished dev [unoptimized + debuginfo] target(s) in 43.34s
     Running `target/debug/roc edit`
thread 'main' panicked at 'Error in Surface::configure: requested format Bgra8Unorm is not in list of supported formats: [Rgba8UnormSrgb, Bgra8UnormSrgb]', /home/jthegedus/.asdf/installs/rust/1.56.1/registry/src/github.com-1ecc6299db9ec823/wgpu-0.11.0/src/backend/direct.rs:204:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:460:5
   2: wgpu::backend::direct::Context::handle_error_fatal
             at /home/jthegedus/.asdf/installs/rust/1.56.1/registry/src/github.com-1ecc6299db9ec823/wgpu-0.11.0/src/backend/direct.rs:204:9
   3: <wgpu::backend::direct::Context as wgpu::Context>::surface_configure
             at /home/jthegedus/.asdf/installs/rust/1.56.1/registry/src/github.com-1ecc6299db9ec823/wgpu-0.11.0/src/backend/direct.rs:910:13
   4: wgpu::Surface::configure
             at /home/jthegedus/.asdf/installs/rust/1.56.1/registry/src/github.com-1ecc6299db9ec823/wgpu-0.11.0/src/lib.rs:3184:9
   5: roc_editor::editor::main::run_event_loop
             at ./editor/src/editor/main.rs:117:5
   6: roc_editor::editor::main::launch
             at ./editor/src/editor/main.rs:53:5
   7: roc_editor::launch
             at ./editor/src/lib.rs:19:5
   8: roc::launch_editor
             at ./cli/src/main.rs:179:5
   9: roc::main
             at ./cli/src/main.rs:86:21
  10: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Replacing with one of the values in the "supported formats" list got it working for me:

    // Prepare swap chain
-    let render_format = wgpu::TextureFormat::Bgra8Unorm;
+    let render_format = wgpu::TextureFormat::Rgba8UnormSrgb;
    let mut size = window.inner_size();

https://github.com/rtfeldman/roc/blob/5b19337089a8f6f9dbcb51a282802f89496528d8/editor/src/editor/main.rs#L106

Unfortunately I do now know Rust or GPU libs well enough to contribute the correct cross-platform fix for this.

rtfeldman commented 2 years ago

Based on the error message, maybe we could find one that's in the supported list on the current system, and choose that? 🤔

I don't know that implications of changing that value though. 😅

Anton-4 commented 2 years ago

@jthegedus can you try sudo ubuntu-drivers autoinstall? That fixed the error for me albeit with an Nvidia graphics card. I'll try to show my suggestion when that error occurs.

trgwii commented 2 years ago

I have the same issue on Debian + KDE. (My system lists the same supported formats). I'm also using an AMD CPU with integrated graphics (AMD Ryzen 5 5600G with Radeon Graphics)

Anton-4 commented 2 years ago

This appears to be a bug in mesa. Fixing this on your end could take some time. I don't think we can fix this on our end because we need a specific TextureFormat to render colors correctly, accepting any available TextureFormat could produce very strange colors in the editor.

Another note: the editor is an early work in progress, current editing functionality is very minimal.

Fix options: Option 1 (changing the source code): You can apply the following change in editor/src/editor/main.rs:

-    let render_format = wgpu::TextureFormat::Bgra8Unorm;
+    let render_format = wgpu::TextureFormat::Rgba8UnormSrgb;

This will likely make the colors look different though. See BUILDING_FROM_SOURCE.md to set up building.

Option 2 (updating mesa): Fair warning; updating graphics drivers can "break" them, it is possible that attempting this could leave you only with the option to log in with the terminal (using Ctrl+Alt+F1 or Ctrl+Alt+F2). In this case a complete re-install of the OS is often the easiest fix. So I recommend having everything important backed up. If you still want to try this, execute the following commands:

sudo add-apt-repository ppa:kisak/kisak-mesa
sudo apt update
sudo apt upgrade -y