
Open source from Noise Factor · more projects
noisemaker-for-cpp
This package supports the "Export Shader Pipeline" feature in Noisedeck.app. The feature runs shader compositions on other platforms. Noise Factor derives this package from the upstream Noisemaker Engine project. Use the CPU renderer directly or through Noisedeck's C++ export kit; see Coverage for the reference and verification scope.
A C++20 CPU port of the Noisemaker shader engine.
This renders Noisemaker's GLSL effect catalog on the CPU, with no GPU, no
GLSL driver, and no runtime shader compilation. It is a sibling of
noisemaker-for-cpu (JavaScript) and targets bit-level parity with it.
The library has no dependencies beyond a C++20 compiler and zlib.
How it works
Effects are not hand-written C++. A typed generator in tools/glslcpp/ compiles the pinned GLSL corpus ahead of time into C++20:
- Each GLSL program is parsed and semantically analyzed into a typed IR.
- A per-program structural profile authenticates the exact AST closure that
program uses.
- A validator admits only that authenticated closure and independently
rejects nearby unsupported shapes.
- An emitter — which re-authenticates from scratch rather than trusting the
validator — lowers the typed AST to C++20.
The generated output is committed to the tree, so building this repository
requires no Python and no code generation:
src/typed_generated/typed_slice.cpp
src/typed_generated/typed_manifest.json
include/noisemaker/generated/catalog.hpp
Generation is deterministic. python -m tools.glslcpp.generate_typed_slice --check regenerates everything in memory and fails if the committed output
differs by a single byte. CI runs that check on pushes affecting source or validation.
Coverage
The CPU renderer is available as a source library, command-line tool and Noisedeck export kit.
Compatibility is measured against a pinned noisemaker-for-cpu reference.
python3 scripts/authority-pins github reports and validates the CPU and shader revisions used
by the current source. CI checks out those exact commits. The Authority drift workflow compares
the behavioral lock and upstream revision with the authority's main daily and on relevant
pushes, so a newer authority fails it until the port is synced to that authority.
The kit's supported effects are listed in export-kit/compat-effects.json, with sweep evidence
in export-kit/verified-effects.json. export-kit/check-authority-coverage.mjs compares that
list with the effects the authority renders. Kernel coverage is recorded in
src/effects/generated/effect_catalog.provenance.json; the typed program inventory is in
src/typed_generated/typed_manifest.json.
The kit claims an effect only when the parameter sweep verified it. An admitted kernel is not enough.
Published export kits require a successful full CI run, including the parameter sweep and define
enumeration against the pinned authority. A passing push CI run alone does not run those sweeps,
and the latest source can be newer than the published kit. Check the
CI runs and the
published kit's source revision for the
version you use. The sweep coverage has these limits:
- Debug evidence: the corpus lane and both sweeps run a Release build of the C++ driver only.
- Render options and state: the sweeps render frame 0 at
renderScale 1. Later frames and other render scales are not measured.
Open gaps are tracked as GitHub issues labelled gap.
How parity is measured
- Corpus lane (
tests/test_dsl_corpus_parity.py): every admitted effect renders once at 17x11 with default parameters, and must match the authority byte for byte. This single point is not enough on its own to prove parity.
- Parameter sweep (
tools/parity/sweep.py --gate kit): every authority effect renders at many sizes, including 1x1 and non-square, with many seeds and times, randomized parameter values, and generator/filter/mixer chains. Each render is compared on RGBA8 and on the float32 surface behind it.
- Define enumeration (
--define-enum): every compile-define parameter renders at each value in its domain. The gate also fails when no draw gives two or more distinct byte-exact outputs across a parameter's values.
- Whole-port summary (
scripts/parity-summary with no arguments): counts the corpus lane, every case of both sweep gates, each claimed define parameter's liveness, and each kit effect that no case renders, in one PARITY-SUMMARY line.
- Automation lane (
tests/test_osc_automation_parity.py): osc(...) parameter automation renders byte for byte at several times, including nested, frequency-modulated and noise oscillators.
- Gates: both sweeps run in CI with
--gate kit, which checks cases whose participating effects are all claimed by the kit. Cases outside that set remain reported gaps. Full closure requires --gate all, complete authority coverage, and Debug and Release evidence.
- Kit coverage (
export-kit/check-authority-coverage.mjs): fails until the kit claims every effect the authority renders.
The corpus itself is vendored, not authored here. Its GLSL sources under tools/glslcpp/corpus/
come from noisefactorllc/noisemaker at the shader
revision reported by scripts/authority-pins, and are MIT-licensed there.
Parity and its documented exceptions
Pixel-level fixtures check ported programs against the JavaScript reference implementation. Compilation alone is insufficient. The project admits capabilities one authenticated closure at a time.
The project records each emitted kernel's measured divergence from the reference in code. kMeasuredParityExclusions in src/graph/executor.cpp lists each affected program and its measured divergence. The DSL graph
executor refuses to run an excluded program, raising unavailable_pass.
Read that list before treating any kernel's output as authority-exact. The guard applies only in the graph executor. The generated catalog still exposes an excluded program's bind_* factory. The guard does not apply to a direct noisemaker::generated::bind() call by key.
Build
Requires CMake 3.20+, a C++20 compiler, and zlib.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
ctest --test-dir build --output-on-failure
The project compiles with -Wall -Wextra -Wpedantic -Werror -ffp-contract=off. Floating-point contraction is disabled deliberately:
fused multiply-add would silently change results and break parity with the
reference.
Use
Render a DSL program
noisemaker-render is the command-line front end. Build it. Run it with a DSL program to produce a PNG:
cmake --build build --target noisemaker-render
./build/noisemaker-render tests/fixtures/dsl/blur.dsl # writes blur.png
cmake --install build --prefix <prefix> also installs it to
<prefix>/bin/noisemaker-render, so the build-tree path below is a
convenience, not the only way to run it. The install is optional: a
library-only build (cmake --build build --target noisemaker-cpu) still
installs cleanly, without the executable.
With no options, it renders 512x512 at time 0, frame 0, seed 1. It writes to the current directory, using the program's own name with a .png extension. Every
option is optional and paths may be relative:
./build/noisemaker-render program.dsl -o out.png
./build/noisemaker-render program.dsl --width 512 --height 512 --seed 7 \
--time 0.5 --frame 3
| option |
default |
meaning |
-o, --output PATH |
the program's basename + .png |
PNG to write |
--width N |
512 |
pixels across |
--height N |
512 |
pixels down |
--time D |
0 |
animation time in seconds |
--frame N |
0 |
frame counter |
--seed D |
1 |
seed |
--raw-rgba8 PATH |
— |
also write raw top-down RGBA8 bytes |
--metadata PATH |
— |
also write a JSON document describing the render |
No environment variables are needed to render. The renderer reads nothing
but the program file you name. (The parity lane in
Tests is the only thing that needs the external JS authority.)
A DSL program names effects from the catalog. To see what is available:
./build/noisemaker-render --list-effects # every catalog key, sorted
Float and int parameters also accept osc(type, min, max, speed, offset, seed) automation. It resolves per render at the normalized time, as the authority does.
Rendering is fail-closed. If the executor refuses a program, the command reports the executor's reason and returns a nonzero exit status. It writes nothing:
For example, a program that reads o0 before any chain writes it (read(o0).blur(radiusX: 2, radiusY: 5).write(o1)) is refused with the reason named read surface is missing and exit code 4.
--help prints the full option list and these exit codes:
0: rendered.
2: unusable command line.
4: refused.
5: plan authentication failure.
6: output could not be written.
noisemaker-render uses the same compile/execute/export path as the corpus parity driver noisemaker-dsl-cpu-case. It produces the bytes that the parity lane validates. That driver is a harness tool. It requires absolute paths and a --source-sha256 of its input to prove which bytes a corpus record ran. Use it only for the parity lane. To render a program, use noisemaker-render.
Use the library directly
Much of this library is header-inline: every noisemaker::glsl:: helper and the matrix and vector operators. These compile in your translation unit under your flags. -ffp-contract=off is therefore part of the public contract, not just this project's build. Without it, the compiler may fuse a multiply and an add into a single FMA and silently change results.
The exported CMake target carries the flag for you. Consuming the package with
find_package(noisemaker-for-cpp CONFIG REQUIRED) and linking
NoisemakerForCpp::noisemaker-cpu propagates both -ffp-contract=off and the
C++20 requirement to your targets. If you build without CMake, pass
-std=c++20 -ffp-contract=off yourself.
Bind a kernel by name. Run a pass. Encode the result:
#include "noisemaker/generated/catalog.hpp"
#include "noisemaker/pass_runner.hpp"
#include "noisemaker/png.hpp"
noisemaker::glsl::Bindings bindings;
bindings.set_uniform("resolution", noisemaker::glsl::Vec2(256.0f, 256.0f));
bindings.set_uniform("scale", 4.0f);
bindings.set_uniform("seed", std::int32_t{7});
// ... remaining uniforms for this kernel
const noisemaker::BoundKernel kernel =
noisemaker::generated::bind_synth_perlin_perlin(bindings);
const noisemaker::Surface surface =
noisemaker::run_pass(kernel, 256, 256);
const std::vector<std::uint8_t> png = noisemaker::encode_png(surface);
You can also find kernels dynamically:
const noisemaker::BoundKernel kernel =
noisemaker::generated::bind("synth/perlin:perlin", bindings);
for (const auto& factory : noisemaker::generated::catalog()) {
// factory.key, factory.bind
}
Binding is fail-closed with respect to uniforms: a missing or wrongly-typed
uniform throws noisemaker::glsl::KernelBindingError rather than rendering
something plausible. It does not consult the measured-parity exclusion list
described under Coverage.
BoundKernel is a stateful execution handle, matching the JavaScript bound
factory it ports. It retains fragment output state across pixels and repeated
passes, and copies of one BoundKernel share that same state. Do not render
through the same bound instance, or any of its copies, concurrently. Bind a
fresh kernel for each concurrent worker instead. Both run_pass and the lower-level run_pixel preserve this stateful contract. The library intentionally hides the raw generated callback and its state.
Bindings::set_texture does not take ownership. The caller must keep the
Surface alive, at a stable address, and unmodified for the lifetime of any
kernel bound from it.
A complete, buildable example is in examples/perlin.cpp:
cmake --build build --target noisemaker-cpu-example-perlin
./build/noisemaker-cpu-example-perlin # writes perlin.png
Tests
Native tests (fixtures, parity, binding ABI, fail-closed behavior):
ctest --test-dir build --output-on-failure
Generator tests (parser, validator, emitter, mutation barriers, historical
reconstruction, determinism) require Python 3.12+:
python -m unittest discover -s tests -p 'test_*.py' -q