#glsl #graphics #shader #rendering #language

rpu

RPU is a GLSL-compatible language for rendering procedural graphics on the CPU

12 releases

0.3.0 May 13, 2024
0.2.5 May 7, 2024
0.1.5 Apr 30, 2024
0.1.1 Jul 20, 2023
0.1.0 Jul 31, 2022

#64 in Graphics APIs

Download history 7/week @ 2024-02-18 3/week @ 2024-02-25 10/week @ 2024-03-10 18/week @ 2024-03-31 1/week @ 2024-04-07 542/week @ 2024-04-28 735/week @ 2024-05-05 141/week @ 2024-05-12 25/week @ 2024-05-19

1,443 downloads per month
Used in rpuc

MIT license

320KB
8K SLoC

header

RPU is a GLSL compatible programming language for rendering procedural graphics on the CPU.

For more information visit rpu-lang.org.

Usage

To execute a function:

let fib = r#"
int fib(int n) {
  if (n <= 1) return n;
  return fib(n - 2) + fib(n - 1);
}

export int main(int x) {
    return fib(x);
}"#;

let rpu = RPU::new();
let use_64_bit = true;
if let Ok(rc) = rpu.compile_and_run(source, "main", [WasmValue::I64(10)], use_64_bit) {
    assert_eq!(
        rc, Ok(vec![WasmValue::I64(55)])
    );
}

If you only want to compile to WAT you can call:

let rc = compile_to_wat(source);

It returns a String containing the WAT source code.

To run the WAT source as a shader use

let mut buffer = ColorBuffer::new(800, 600);
let rc = rpu.compile_wat_and_run_as_shader(&wat, "shader", &mut buffer, use_64_bit);

The color buffer will contain the shader output. This runs the shader in a single thread. To run the shader in parallel use:

let mut buffer = Arc::new(Mutex::new(ColorBuffer::new(800, 600)));
let rc = rpu.compile_wat_and_run_as_tiled_shader(&wat, "shader", &mut buffer, (80, 80), 1, use_64_bit);

Where (80, 80) is the tile size. The buffer is wrapped in an Arc<Mutex<>> to allow multiple threads to write to it. The '1' is the number of iterations to compute (in case the shader is a path tracer).

Dependencies

~13–25MB
~238K SLoC