perf: improve performance

This commit is contained in:
2026-09-30 21:29:33 +02:00
parent 833859b974
commit 4a14f80b76
2 changed files with 30 additions and 3 deletions
+6 -1
View File
@@ -253,7 +253,12 @@ pixel is a handful of `f32` complex multiplies.
The deep path is exact at any depth: forcing it everywhere (raise The deep path is exact at any depth: forcing it everywhere (raise
`DEEP_PIXEL_SIZE`, raise `DEEP_EXIT_LOG2` to about -8) must reproduce the `DEEP_PIXEL_SIZE`, raise `DEEP_EXIT_LOG2` to about -8) must reproduce the
plain f32 renders on non-chaotic views. That's the check to rerun after plain f32 renders on non-chaotic views. That's the check to rerun after
changing it. Known gaps: Lambda's critical point is 1/2, so its step keeps changing it. At minibrot depths (seahorse 1e-200) this prologue is most
of the render: about 130 loop turns per pixel, one per BLA jump or plain
step around each near-zero reference point. It's ALU-bound, so
`ldexp_sat` adds to the exponent bits for normal inputs (−25% time).
Measured no help: reading `frexp`'s exponent from the bits, a branchless
`ldexp_sat`, uploading BLA levels 1–2. Known gaps: Lambda's critical point is 1/2, so its step keeps
the input scale. Lambda set mode's reference sits at the origin, so it the input scale. Lambda set mode's reference sits at the origin, so it
never reaches deep zooms anyway. never reaches deep zooms anyway.
- `src/fractal/bla.rs` — **bivariate linear approximation**: a table of - `src/fractal/bla.rs` — **bivariate linear approximation**: a table of
+24 -2
View File
@@ -298,6 +298,22 @@ fn ldexp_sat(x: f32, k: i32) -> f32 {
if x == 0.0 { if x == 0.0 {
return 0.0; return 0.0;
} }
// Normal x (the usual case): the same result by adding k to the
// exponent field, much cheaper than frexp + ldexp in this hot path.
// frexp's exponent is the biased field - 126; the checks keep the
// result's field in [1, 226], so the add can't carry into the sign.
let bits = bitcast<u32>(x);
let biased = i32((bits >> 23u) & 0xffu);
if biased != 0 && biased != 255 {
let ex = biased - 126 + k;
if ex > 100 {
return select(-LDEXP_SAT, LDEXP_SAT, x > 0.0);
}
if ex < -125 {
return 0.0;
}
return bitcast<f32>(bitcast<i32>(bits) + (k << 23u));
}
let f = frexp(x); let f = frexp(x);
let ex = f.exp + k; let ex = f.exp + k;
if ex > 100 { if ex > 100 {
@@ -629,12 +645,16 @@ fn bla_lookup(m: u32, e_log2: f32, budget: u32) -> vec2<u32> {
return best; return best;
} }
let top = min(tz - lmin, levels - 1u); let top = min(tz - lmin, levels - 1u);
// Level offsets without loading them from `bla_meta` per level (one more
// dependent load each): level 0 starts at 0 and each level has half the
// previous one's nodes, rounded down (`bla::build`).
var base = 0u;
var count = bla_meta[3];
for (var k: u32 = 0u; k <= top; k = k + 1u) { for (var k: u32 = 0u; k <= top; k = k + 1u) {
let l = lmin + k; let l = lmin + k;
let steps = 1u << l; let steps = 1u << l;
let base = bla_meta[2u + k];
let local = j >> l; let local = j >> l;
if steps > budget || local >= bla_meta[3u + k] - base { if steps > budget || local >= count {
break; break;
} }
let idx = base + local; let idx = base + local;
@@ -642,6 +662,8 @@ fn bla_lookup(m: u32, e_log2: f32, budget: u32) -> vec2<u32> {
break; break;
} }
best = vec2<u32>(idx, steps); best = vec2<u32>(idx, steps);
base = base + count;
count = count >> 1u;
} }
return best; return best;
} }