wgpu-py icon indicating copy to clipboard operation
wgpu-py copied to clipboard

Problems with creating a surface

Open almarklein opened this issue 9 months ago • 2 comments

We're seeing several reports where people have issues related to wgpu creating a surface. I created this as a meta-issue.

Issues in wgpu-py / rendercanvas / pygfx

  • https://github.com/pygfx/pygfx/issues/642
  • https://github.com/pygfx/wgpu-py/issues/663
  • https://github.com/pygfx/rendercanvas/issues/62
  • https://github.com/pygfx/rendercanvas/issues/55
  • https://github.com/pygfx/pygfx/issues/951

Known upstream issues

TODO

Improvements made

  • https://github.com/pygfx/rendercanvas/pull/73
  • https://github.com/pygfx/wgpu-py/pull/705

Specific cases

Linux

Make sure you've done

sudo apt install mesa-vulkan-drivers
sudo apt install xserver-xorg-core libvulkan1

WSL

wgpu does not really work on WSL yet, see https://github.com/gfx-rs/wgpu/issues/1443. I think you can use a limited subset with the OpenGL backend.

Qt subwidgets

Qt does not like it when we claim a widget as a native widget, and this can cause some nasty side-effects. I think the best solution is a bitmap-present, maybe combined with an QGLWidget.

Wayland

The glfw GUI backend works via the x11 compat layer. But other backends don't work because the display id cannot be obtained. With the Qt backend it automatically fall back to bitmap on wayland.

Solutions

Using the bitmap mode

The simples approach (and one that we can control) is the present_method="bitmap" in rendercanvas. It does suffer a performance penalty, but we already know how we can reduce that penalty: https://github.com/pygfx/rendercanvas/issues/66

Solutions to actually allow rendering to a surface

Wait 🤷 Except for the specific cases above, wgpu-core will likely improve on this front.

Maybe some tricks can be read in https://github.com/gfx-rs/wgpu/issues

almarklein avatar Mar 19 '25 10:03 almarklein

there was a release upstream with one Bugfix that sounds similar https://github.com/gfx-rs/wgpu/releases/tag/v24.0.3

Vipitis avatar Mar 19 '25 18:03 Vipitis

Yeah, "Fix drop order in Surface, solving segfaults on exit on some systems." sounds very familiar to https://github.com/pygfx/pygfx/issues/642. I think wgpu-native can bump without much work. So we can get this in wgpu-py pretty quick.

almarklein avatar Mar 20 '25 08:03 almarklein