shdr
GLSL compute on CPU and OpenGL GPU, with a C++11 single-header runtime.
About This Project
GLSL compute for CPU and OpenGL
shdr is an MIT-licensed compute library by Vojtěch Vrba. It provides a single-header C++11 runtime for running supported GLSL compute kernels on the CPU, an OpenGL GPU, or an ordered pipeline combining both.
The supplied CMake/Python build frontend generates a C++11 CPU adapter and embeds the GPU program from the shader source. The host application binds typed buffers or images, sets uniforms, and connects producer and consumer stages through shared resources.
What you can build
Elementwise transforms and multi-stage buffer/image processing.
Out-of-place filters and vision pipelines, with CPU reference cases.
Processing integrated into an existing OpenGL application, using its current context and function resolver.
Optional headless GPU execution through EGL.
The repository includes runnable examples for image filtering and Harris corners, Bayer processing, signal filters and FFTs, event-camera processing, and small neural pipelines.
Try the CPU example
Clone the source repository, then run these commands in that checkout:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSHDR_BUILD_GPU=OFF
cmake --build build --target example_pipeline -j2
./build/example_pipeline
The example composes an affine transform, a clamp, and a reduction. A separate complete first-kernel tutorial supplies a small two-stage scaling application, its shader and CMake file, expected output, and optional OpenGL/mixed modes.
Requirements and portable model
The CPU path uses C++11 and host memory. Native shader builds also need the supplied CMake/Python tools. The GPU baseline is OpenGL ES 3.1 or desktop OpenGL 4.3, with a compatible context and driver. The optional headless backend additionally requires EGL.
Portable kernels use independent invocations, supported storage layouts, and ordered dispatches for communication between stages. Workgroup shared memory, shader barriers, atomics, and subgroup algorithms need adaptation. Floating-point comparisons need tolerances suited to the algorithm.
Source and documentation
Project description prepared with AI assistance from the source and documentation. Verification for revision 01652c119dad9662f48e3c056c5f988593c630d8: all 23 configured upstream CPU tests passed, and the tutorial example returned its expected results in CPU, EGL OpenGL ES 3.1, and mixed modes. These are correctness checks for those cases.
Discussion