CPU-based Rendering Support
This release adds EGL CPU rendering (via llvmpipe, "surfaceless") and also osMesa support for older systems. The advantage of EGL over osMesa is that it can do both GPU and CPU off-screen rendering, while osMesa is CPU only (and often osMesa libraries are not installed). This allows rendering without DISPLAY, no xvfb wrappers needed, with or without GPU. Specifically:
- You can render on a workstation via ssh login (no supported DISPLAY, either with GPU acceleration or CPU based)
- You can render in Docker (EGL CPU based or when
--gpus allis passed also with GPU) - You can render in Singularity (same, GPU requires passing
--nv) - You can render off screen in Windows (after installing the necessary dll (see our test CI workflow)
- You can render with DISPLAY and window manager on a Mac (or use a container for complete off-screen)
Note: osMesa might not be supported for very long, it is recommended to use EGL instead.
Together with this upgrade, we changed a few interfaces (breaking full backward-compatibility, in a few places). Since 2.0 was released last week, we think it is not widely adopted yet anyway and therefore proceed to 2.1 instead of 3.0. as the changes are too minor to warrant a major release.
What's Changed
- Add support for EGL CPU-based rendering (llvmpipe MESA) on Linux
- Add OSMesa for CPU rendering on Linux
- Make
get_view_matrixtop level import - In snap1 remove
viewmatparamter and pass it viaview(either a view type or matrix) (! breaks backward compatibility!) - In
snap_rotatealso allow passing a matrix viastart_view - Add
gl/osmesa_context.pyas a drop-in with the same public API (make_current, read_pixels, destroy). Raises a clear RuntimeError with a platform-specific install hint if libOSMesa is not found - Delete
gl/_platform.py— the PYOPENGL_PLATFORM=egl env-var setter is no longer needed - Delete
gl/views.py— redistributed its contents to their natural homes:get_view_matrices/get_view_matrix→utils/types.py(pure numpy, no GL, lives alongsideViewTypewhich it maps over)ViewState,arcball_*,compute_view_matrix→cli/whippersnap.py(only consumer; no reason to be in a shared module)
- Rename
_egl_context→_offscreen_contextin gl/utils.py — the old name was a historical artefact. - Fix
snap4to look like v1 images (slightly enlarge top views, remove padding, center colorbar) - unify parameter names
fthreshandfmax(also inplot3d, breaks backward compatibility) - Fix license syntax in
pyproject.toml - Bump action versions
- Set default visible false for snap functions (don't show on screen), visible window is only for the Qt GUI.
- Refactor some internal files (file names in the gl module and function names).
- Docs: Update README.md, DOCKER.md
- Docker: include only required dependencies and update to allow
--gpus allto run EGL GPU-based also.
CI (pytest.yml):
- Ubuntu installs libegl1 for headless CPU rendering.
- macOS requires a GLFW invisible window backed by GPU drivers (no headless, therefore skipping rendering in CI). If you need headless on Mac, use linux docker.
- Windows: we install the necessary dll and can do offscreen rendering also in CI.
Migration from 2.0 (breaking changes)
- Instead passing
viewmatinsnap1-> migrate to usingview - rename command line and function parameter
brain_scaletoscaleas we plot other geometries, not just brains. - In plot3d use
fthreshinstead ofminvalandfmaxinstead ofmaxvalfor consistency with other methods
Full Changelog: v2.0.0...v2.1.0