perf: Add BLA rendering for other fractals

This commit is contained in:
2026-09-30 18:50:15 +02:00
parent 21f08eb3d9
commit 5f4207b6fd
5 changed files with 756 additions and 222 deletions
+29 -15
View File
@@ -246,24 +246,36 @@ pixel is a handful of `f32` complex multiplies.
the input scale. Lambda set mode's reference sits at the origin, so it
never reaches deep zooms anyway.
- `src/fractal/bla.rs` — **bivariate linear approximation**: a table of
merged linear steps `e' = A·e + B·dc` (valid while `|e| < R`) built on
the CPU from the reference orbit, so the shader's `bla_lookup` jumps each
pixel over whole runs of steps. Plain Mandelbrot only (set + Julia, no
morph; `bla::applies`, the `BLA` override). This is what makes deep zoom
fast: every pixel follows the reference for tens of thousands of steps
before diverging (1e-200: 12.7 s → 0.7 s at 960×540). Level `l` node `i`
covers steps `1 + i·2^l ..`, and only levels ≥ 3 are uploaded (bindings 4/5,
`bla_meta` = `[min_level, levels, offsets…]`). Coefficients are
floatexp (f32 mantissa + i32 exponent), so a jump in the deep prologue
lands straight at its output scale. `R` depends on the view's largest
`|dc|` (`dc_max_log2`), so `FractalApp::bla_table` rebuilds on reference
change or when the dc range grows (or shrinks by `BLA_DC_SLACK` binades);
exports/headless build per frame via `bla::for_uniforms`. The table stops
merged linear steps `e' = M·e + N·dc` (real 2×2 matrices; valid while
`|e| < R`) built on the CPU from the reference orbit, so the shader's
`bla_lookup` jumps each pixel over whole runs of steps. Every kind but
Phoenix (two-term map), no morph (`bla::applies`, the `BLA` override).
`M` is the map's Jacobian at `X`: `C(f'(X))` for the holomorphic kinds, a
sign fold of `C(2X)` for the abs/conjugate ones. Each kind's `M` and
radius live in `Node::step`, which must match `advance_delta_kind`. The
abs kinds' radius also keeps the delta off their fold lines (where
`diffabs` switches branch), and Complex Multibrot's keeps it off the
branch cut. So Burning Ship / Perpendicular / Buffalo can't jump along the
real axis (their fold), where their orbits often sit. Merges use the exact
2×2 spectral norm (Frobenius would lose √2 of radius per level). This is
what makes deep zoom fast: every pixel follows the reference for tens of
thousands of steps before diverging (Mandelbrot 1e-200: 12.7 s → 0.7 s
at 960×540). Level `l` node `i` covers steps `1 + i·2^l ..`, and only
levels ≥ 3 are uploaded (bindings 4/5, 48 B nodes, `bla_meta` =
`[min_level, levels, offsets…]`). Coefficients are floatexp (f32
mantissas + i32 exponent), so a jump in the deep prologue lands straight
at its output scale. `R` depends on the view's largest `|dc|`
(`dc_max_log2`), so `FractalApp::bla_table` rebuilds on reference or kind
change or when the dc range grows (or shrinks by `BLA_DC_SLACK` binades).
Exports/headless build per frame via `bla::for_uniforms`. The table stops
before the reference crosses the pixel bailout, so a jump never skips an
escape. Measure `|e|` with `log2_mag`, never `log2(dot(e, e))`: a
2^-100 delta squares to 0 in f32 and passed every radius test.
`--no-bla` / the "Skip iterations (BLA)" checkbox upload an empty table
for A/B checks (it must render like `--no-bla` up to f32 noise).
for A/B checks. BLA must render like `--no-bla` up to f32 noise; on
chaotic views, compare against a `--no-bla` render nudged by ~0.01 px,
which differs by more. `escape_counts_match_all_kinds` checks every
kind on the CPU against the plain loop with f32 rounding.
- `src/fractal/renderer.rs` — `FractalRenderer` (wgpu pipelines, uniform +
storage buffers, bind groups), `Uniforms` (repr(C) layout that must match
the WGSL `Uniforms` struct field-for-field, including padding; it includes
@@ -305,7 +317,9 @@ arms), `reference.rs` (CPU iteration formula arm, and a test comparing
against a naive `f64` iteration), `common.wgsl` (matching `KIND_*` const),
`mandelbrot.wgsl` (matching `advance_delta`/`fprime` arms, plus the deep
path's `advance_delta_scaled_kind` arm, its degree in `deep_step_kind` and,
if not z²-like, a `deep_fprime` arm), `buddhabrot.wgsl`
if not z²-like, a `deep_fprime` arm), `bla.rs` (a `Node::step` arm: the
step's Jacobian and linearity radius, plus a case in
`escape_counts_match_all_kinds`; or exclude the kind in `applies`), `buddhabrot.wgsl`
(matching arm in `advance()`, if the kind makes sense as a Buddhabrot),
`renderer.rs` `Uniforms` (only if the kind needs a new per-kind constant,
e.g. Phoenix's `phoenix_p`), `app.rs` (`JULIA_PRESETS`/`SET_PRESETS` slot,
+3
View File
@@ -56,6 +56,7 @@ const BLA_DC_SLACK: i32 = 2;
#[derive(Clone, Copy, PartialEq)]
struct BlaKey {
generation: u64,
kind: u32,
on: bool,
julia: bool,
dc_log2: i32,
@@ -1304,12 +1305,14 @@ impl FractalApp {
fn bla_table(&mut self, u: &Uniforms) -> Arc<BlaTable> {
let want = BlaKey {
generation: self.generation,
kind: u.kind,
on: self.use_bla && bla::applies(u),
julia: u.is_julia != 0,
dc_log2: bla::dc_max_log2(u),
};
let fresh = self.bla_key.as_ref().is_some_and(|k| {
k.generation == want.generation
&& k.kind == want.kind
&& k.on == want.on
&& k.julia == want.julia
&& (!want.on
+685 -181
View File
File diff suppressed because it is too large Load Diff
+32 -19
View File
@@ -32,14 +32,16 @@
@group(0) @binding(3) var<storage, read> ref_exp: array<i32>;
// Bivariate linear approximation table (`fractal::bla`): node i of level l
// maps the delta at reference step 1 + i·2^l to the one 2^l steps later as
// e' = A·e + B·dc, valid while log2|e| < r_log2. `bla_meta` is
// e' = M·e + N·dc, valid while log2|e| < r_log2. M = m·2^m_exp and
// N = n·2^n_exp are real 2x2 matrices, row-major (the Jacobian of the map,
// so the abs/conjugate kinds are covered too). `bla_meta` is
// [min_level, level_count, off_0, ..., off_{level_count}]; only `BLA`
// pipelines read either.
struct Bla {
a: vec2<f32>,
b: vec2<f32>,
a_exp: i32,
b_exp: i32,
m: vec4<f32>,
n: vec4<f32>,
m_exp: i32,
n_exp: i32,
r_log2: f32,
_pad: u32,
};
@@ -64,8 +66,8 @@ override MORPH: bool = false;
// and `u.span` / `u.dc_offset` are all in units of 2^scale_exp, and each pixel
// starts in the rescaled deep phase (see `iterate_sample`).
override DEEP: bool = false;
// Jump over runs of reference steps with the BLA table (plain Mandelbrot,
// no morph; see `bla_lookup`).
// Jump over runs of reference steps with the BLA table (every kind but
// Phoenix, no morph; see `bla_lookup`).
override BLA: bool = false;
struct VsOut {
@@ -596,6 +598,11 @@ const DEEP_RENORM_LOG2: i32 = 16;
// binades above the delta's scale (|w| < 2^DEEP_RENORM_LOG2).
const DEEP_NEAR_LOG2: i32 = 24;
// Row-major 2x2 matrix times vector (a BLA node's M or N).
fn mat2v(m: vec4<f32>, v: vec2<f32>) -> vec2<f32> {
return vec2<f32>(dot(m.xy, v), dot(m.zw, v));
}
// log2|v|, from above (|v| <= sqrt(2)·max component). Not via dot(v, v):
// a delta ~2^-100 (a pixel offset at 1e-30 zoom) squares below f32's range,
// and log2(0) = -inf passed every radius test, jumping pixels far too early.
@@ -862,9 +869,9 @@ fn iterate_sample(offset: vec2<f32>, px: f32) -> Sample {
if hit.y != 0u {
let nd = bla_nodes[hit.x];
if DE {
var accv = fe_make(cmul(nd.a, v), nd.a_exp + sv);
var accv = fe_make(mat2v(nd.m, v), nd.m_exp + sv);
if !IS_JULIA {
accv = fe_add(accv, fe_make(nd.b * px, nd.b_exp + scale_e));
accv = fe_add(accv, fe_make(mat2v(nd.n, vec2<f32>(px, 0.0)), nd.n_exp + scale_e));
}
v = accv.m;
if accv.m.x != 0.0 || accv.m.y != 0.0 {
@@ -874,9 +881,9 @@ fn iterate_sample(offset: vec2<f32>, px: f32) -> Sample {
}
}
}
var acc = fe_make(cmul(nd.a, w), nd.a_exp + sx);
var acc = fe_make(mat2v(nd.m, w), nd.m_exp + sx);
if !IS_JULIA {
acc = fe_add(acc, fe_make(cmul(nd.b, offset), nd.b_exp + scale_e));
acc = fe_add(acc, fe_make(mat2v(nd.n, offset), nd.n_exp + scale_e));
}
w = acc.m;
if acc.m.x != 0.0 || acc.m.y != 0.0 {
@@ -1099,9 +1106,14 @@ fn iterate_sample(offset: vec2<f32>, px: f32) -> Sample {
// f'(z) of this step, shared by DE and the periodicity multiplier.
// BLA jump (see the deep phase). dc and px are taken unscaled from
// `offset`/`px`: at depth `step_add`/`px_t` have flushed to 0, but
// B·dc hasn't. The skipped steps' |f'|^2 product is |A|^2. No
// skipped iterate can be the window's closest to the critical point:
// a run's radius is below ε·|X| for every X in it.
// N·dc hasn't. The skipped steps' |f'|^2 product is |det M| (the
// steps are conformal, or folds of conformal maps). No skipped
// iterate can be the window's closest to the critical point: a run's
// radius is below ε·|X| for every X in it.
//
// With DE, dzs goes through M, the map's true Jacobian, where the
// plain loop multiplies by `fprime` (|2Z| for the abs kinds): same
// magnitude, since the folds are isometries.
let e_old = e;
let z_old = z;
var jumped = false;
@@ -1111,20 +1123,21 @@ fn iterate_sample(offset: vec2<f32>, px: f32) -> Sample {
let nd = bla_nodes[hit.x];
let se = select(0, u.scale_exp, DEEP);
if periodic {
let a2 = ldexp_sat(dot(nd.a, nd.a), 2 * nd.a_exp);
let det = abs(nd.m.x * nd.m.w - nd.m.y * nd.m.z);
let a2 = ldexp_sat(det, 2 * nd.m_exp);
mult2 = mult2 * a2;
mult2_cand = mult2_cand * a2;
}
if DE {
var dn = ldexp2_sat(cmul(nd.a, dzs), nd.a_exp);
var dn = ldexp2_sat(mat2v(nd.m, dzs), nd.m_exp);
if !IS_JULIA {
dn = dn + ldexp2_sat(nd.b * px, nd.b_exp + se);
dn = dn + ldexp2_sat(mat2v(nd.n, vec2<f32>(px, 0.0)), nd.n_exp + se);
}
dzs = dn;
}
var en = ldexp2_sat(cmul(nd.a, e), nd.a_exp);
var en = ldexp2_sat(mat2v(nd.m, e), nd.m_exp);
if !IS_JULIA {
en = en + ldexp2_sat(cmul(nd.b, offset), nd.b_exp + se);
en = en + ldexp2_sat(mat2v(nd.n, offset), nd.n_exp + se);
}
e = en;
m = m + hit.y;
+2 -2
View File
@@ -86,8 +86,8 @@ fn mandelbrot_shader_specializations_compile() {
for de in [0.0, 1.0] {
for morph in [0.0, 1.0] {
for deep in [0.0, 1.0] {
// BLA only exists for plain Mandelbrot (`bla::supported`).
let blas: &[f64] = if kind == 0 && morph == 0.0 {
// BLA: every kind but Phoenix (7), no morph (`bla::applies`).
let blas: &[f64] = if kind != 7 && morph == 0.0 {
&[0.0, 1.0]
} else {
&[0.0]