KMS GLSL is a command line tool that runs OpenGL fragment shaders, using the DRM/KMS Linux kernel subsystem. It runs shaders fullscreen, and does not require any windowing system, like X or Wayland.
It has initially been developed to run shaders from Shadertoy, on the Raspberry Pi, using the VC4/V3D KMS driver, that supports OpenGL ES 3.1 (as of January 2023). However, it should work with any GPU and display controller hardware, provided a DRM/KMS driver is available.
In the following picture, this Shadertoy shader runs on the official Raspberry Pi 7″ touchscreen monitor, connected to a Raspberry Pi 41:
$ sudo apt update # Install the build tools $ sudo apt install gcc make # Install the required DRM, GBM, EGL and OpenGL ES API headers $ sudo apt install libdrm-dev libgbm-dev libegl-dev libgles2-mesa-dev # Install the X C binding and RandR extension header / library files (optional) $ sudo apt install libxcb-randr0-dev # Build the glsl CLI binary $ make
$ ./glsl -h Usage: ./glsl [-aAcDfmpvx] <shader_file> options: -a, --async use async page flipping -A, --atomic use atomic modesetting and fencing -c, --count run for the specified number of frames -D, --device=DEVICE use the given device -f, --format=FOURCC framebuffer format -h, --help print usage -m, --modifier=MODIFIER hardcode the selected modifier -p, --perfcntr=LIST sample specified performance counters using the AMD_performance_monitor extension (comma separated list) -v, --vmode=VMODE specify the video mode in the format <mode>[-<vrefresh>] -x, --surfaceless use surfaceless mode, instead of GBM surface
You can try with the shaders copied from Shadertoy into the
examples directory, e.g.:
$ ./glsl examples/stripey_torus_interior.glsl
Press Ctrl+c to exit the program. You can explore shadertoy.com to find additional shaders.
⚠️Image shaders from Shadertoy are currently expected as input shader files.
Note the shaders from the
examplesdirectory assume OpenGL ES 3.1 support, and may not work with lower versions of the specification.
Assuming you've installed Raspberry Pi OS, the DRM/KMS VC4/V3D driver can be configured by running the following commands:
$ sudo vi /boot/config.txt
Set the following properties:
# Required: Enable the DRM/KMS VC4 V3D driver dtoverlay=vc4-kms-v3d # Optional: Increase the memory reserved for the GPU gpu_mem=128
Reboot your Raspberry Pi, so that the changes are taken into account, e.g.:
$ sudo reboot
Note this also works with the Raspberry Pi OS Lite versions, as it does not need any compositor like X, Wayland or similar.
It has successfully been tested on the RPi 4, running the Raspberry Pi OS 2023-09-22, Linux kernel 5.15.
- Feed the mouse uniform with touchscreen events from tslib
- Forward keyboard events to the input keyboard texture
- Feed audio / video inputs to microphone / camera textures
- Package Shadertoy default media files
- Load arbitrary input texture files
- Ability to load multiple shaders into a carousel-like experience
The DRM/KMS ceremony code is copied from kmscube.
The shader examples are copied from the Shadertoy website URLs commented at the top of each file.
1. The setup is described in the Anatomy of my Kubernetes cluster.