ZZust

Mandelbrot Example

A full Zust GPU numeric example

The Mandelbrot set shows Zust generics, BigFloat arithmetic, GPU kernel shape, typed vector output, and the SPIR-V, Metal, and Vulkan backend path.

Zust BigFloat Mandelbrot detail
BigFloat Mandelbrot detail
BigFloat keeps deep coordinates stable so pixel offsets can still reveal boundary detail.
Mandelbrot spiral field
Higher iteration counts expose slow-escaping points, spirals, and fine structure.

Parameter struct

pub struct Params<N> {
    x: bigfloat::BigFloat<N>,
    y: bigfloat::BigFloat<N>,
    step: bigfloat::BigFloat<N>,
    max_iter: u32,
}

Mapping pixels to the complex plane

The GPU thread locates a sample, converts its pixel offset into BigFloat, and adds that offset to the high-precision center coordinate.

let px = group[0] * 16u32 + local[0];
let py = group[1] * 16u32 + local[1];

let x_bf = params.x.add(x_offset.mul(params.step));
let y_bf = params.y.add(y_offset.mul(params.step));

Escape iteration

The recurrence is `z = z² + c`. When `zx² + zy² > 4`, the point escapes; the escape count becomes the basis for smooth coloring.

Why BigFloat matters

In deep zooms, the complex-plane distance between neighboring pixels can be smaller than ordinary `f32` can preserve. BigFloat keeps the offsets meaningful.

Run it

cargo run -p vm-spirv --example mandelbrot

MANDEL_ZS=zusts/gpu/mandelbrot_bigfloat8.zs \
MANDEL_MODULE=mandelbrot_bigfloat8 \
cargo run -p vulkan --example run_mandel