For years, we have looked at something solid to be able to implement 3D colour science visualisation. We used Vispy, but encountered some issues when interacting with the scenegraph, then a quick stint with Three.js which required doing dirty things to pass Python data to Javascript, and finally, Pygfx is the one that enabled us to do what we wanted: https://github.com/colour-science/colour-visuals
There are some tickets about it: https://github.com/pygfx/pygfx/issues/650 https://github.com/pygfx/wgpu-py/issues/407
[1]: https://vpython.org/
[1] https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QRhiWidget...
I've been using it for 4-ish years now in https://ossia.io (just the RHI part)
Pros:
- Integrates with Qt (of course).
- Really really easy API compared to the average C++ API.
- Works absolutely everywhere.
- Many provided examples: https://github.com/qt/qtbase/tree/dev/tests/manual/rhi
- Shader language is SPIRV-compatible GLSL 4.x thus it makes it fairly trivial to import existing GL shaders (one of my requirements was support for https://editor.isf.video shaders).
Cons:
- Was developed before Vulkan Dynamic Rendering was introduced so the whole API is centered around the messy renderpass thing which while powerful is sometimes a bit more tedious than necessary when your focus is desktop app development. However, Qt also has a huge focus on embedded so it makes sense to keep the API this way.
- Most likely there are some unnecessary buffer copies here and there compared to doing things raw.
- Does not abstract many texture formats. For instance still no support for YUV textures e.g. VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM and friends :'(
So, from the standpoint of someone using PySide6, QRhi and pygfx seem to be alternative paths to doing GPU-enabled rendering, on the exact same range of GPU APIs.
Thus my question: How do they compare? How should I make an informed comparison between them?
[1] https://doc.qt.io/qt-6/qrhi.html
[2] https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QRhiWidget...
Pygfx provides higher level rendering primitives. The more apples to apples comparison would be wgpu-py versus QtRhi, both of which are middleware that abstract the underlying graphics API.
The natural question is are you already using Qt? You say you are, so IMHO the pros and cons of the specific implementations don't matter unless you have some very specific exotic requirements. Stick with the solution that "just works" in the existing ecosystem and you can jump into implementing your specific business logic right away. The other option is getting lost in the weeds writing glue code to blit a wgpu-py render surface into your Qt GUI and debugging that code across multiple different render backends.
It sounds to me that Qt created their own abstraction over Vulkan and co, because wgpu did not exist yet.
I can't really compare them from a technical pov, because I'd have to read more into QRhi. But QRhi is obviously tight to / geared towards Qt, which has advantages, as well as disadvantages.
Wgpu is more geared towards the web, so it likely has more attention to e.g. safety. WebGPU is also based on a specification, there is a spec for the JS API as well as a spec for webgpu.h. There's actually two implementations (that I know of) that implement webgpu.h: wgpu-native (which runs WebGPU in firefox) and Dawn (which runs WebGPU in Chrome).
Also, wgpu forces you to prepare visualizations in pipeline objects, which at drawtime require just a few calls. In OpenGL there is way more work for each object being visualized at drawtime. This overhead is particularly bad on Python. So this particular advantage of wgpu is extra advantageous for Python.
We deliberately don't try to create an API that allows you to write visualizations with as few lines as possible. We focus on a flexible generic API instead, even if it's sometimes a bit verbose.
We leave it up to others to create higher level (domain specific) APIs. Fastplotlib is one example: https://github.com/fastplotlib/fastplotlib
> Pygfx (pronounced “py-graphics”) is built on wgpu, enabling superior performance and reliability compared to OpenGL-based solutions.
pygfx/wgpu-py: https://github.com/pygfx/wgpu-py/ :
> A Python implementation of WebGPU
gfx-rs/wgpu: https://github.com/gfx-rs/wgpu :
> wgpu is a cross-platform, safe, pure-rust graphics API. It runs natively on Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.
> The API is based on the WebGPU standard. It serves as the core of the WebGPU integration in Firefox and Deno
> Technically speaking, wgpu-py is a wrapper for wgpu-native, exposing its functionality with a Pythonic API closely resembling the WebGPU spec.
`wgpu-native` is a wrapper with FFI/bindings for the Rust `wgpu` per their READMEs
/?PyPI wgpu: https://pypi.org/search/?q=wgpu
Looks like xgpu is where it's actually at.
xgpu: https://github.com/pyrym/xgpu :
> xgpu is an aggressively typed, red-squiggle-free Python binding of wgpu-native, autogenerated from the upstream C headers
wgpu-py has a conda-forge package: https://anaconda.org/conda-forge/wgpu-py