Skip to content

Color pipeline P9: fixed-point float-free tier and budgets #4043

Closed

Description

@zackees

Phase P9 of the color pipeline implementation (see parent issue). Independently mergeable. This is the explicitly named phase required by decision B11 — not inherited implicitly from the TINY-tier criterion.

Scope

Make the pipeline real on float-free and memory-constrained tiers, and record the budgets.

  • Fixed-point re-implementation of the colorimetric cache build and solve (the existing stack is float32 throughout): profile→matrix construction, response LUT generation, and the per-pixel matrix path, in integer/fixed-point arithmetic meeting the A1 budget.
  • TINY tier: no per-controller state added, no float or iterative-solver symbols linked when color management is unused or used in its minimal configuration; verified by symbol-level inspection (bash bloat).
  • Tree-shaking proof at full scale: unused profiles, unused named source spaces, and the whole pipeline cost zero flash when unreferenced.
  • Record bloat and throughput budgets for representative AVR, SAMD51, ESP32, and high-throughput parallel output (C2's streaming model makes throughput measurable on the real path); LUT/profile memory usage mapped to platform memory tiers.

Decisions implemented

B11, the TINY-tier and budget halves of #4032 §3, C2 (throughput verification side).

Acceptance criteria owned

  • TINY tier: no per-controller state, no float/solver symbols; bloat and throughput budgets recorded for representative platforms.

Dependencies

P2 (types), P6 (core), P7 (solve to convert).

Deliverables

Fixed-point build/solve implementation, symbol-inspection tests, recorded budget tables per platform.

Activity

  1. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Where this phase actually stands, after a survey

    Opening this with the survey rather than a plan, because the phase description says "the existing stack is float32 throughout" and that is no longer true — P6 and P7 changed the picture, and the remaining work is narrower and differently shaped than the bullet suggests.

    Already done, by P6/P7

    The per-pixel path is fixed-point end to end. All eleven streaming entry points — decodeTransferU16, linearRgbToXyzQ16, adaptXyzQ16, solveRgbDrivesQ16, applyFluxScalar, the OKLab pair, the three gamut mappers, the two white allocations — carry no float. That was verified by scanning each function body, not assumed.

    #4257 makes it a guard so it cannot regress silently.

    The real remaining work is bind-time, not per-pixel

    What still uses float is the derivation that runs once per profile:

    // src/fl/gfx/device_solve.cpp.hpp — buildRgbSolveMatrixQ16
    float emitter[3][3]; float inverse[3][3];
    invert3x3(emitter, inverse);   // then quantized to s16.16

    B11 permits that per-pixel, but the TINY-tier criterion is about linked symbols, so bind-time float still counts against it.

    Converting it is bigger than it looks, and worth stating before someone starts: EmitterProfile itself stores float xy_r[2], lum_r and so on. It is P2's public type and the whole legacy RGBW stack consumes it. A float-free bind-time derivation needs a fixed-point profile representation, which is a cross-cutting P2/P9 change rather than a rewrite of one 129-line file.

    And the verification half needs hardware

    "Verified by symbol-level inspection (bash bloat)" and the recorded AVR / SAMD51 / ESP32 / parallel-output budgets are device measurements. I cannot produce those here, and a source-level test cannot substitute for them — #4257 says so explicitly rather than implying coverage it does not have.

    Suggested split

    1. source-level guard that the per-pixel path stays float-free — test(color): enforce a float-free per-pixel path (P9, #4043) #4257
    2. fixed-point EmitterProfile + bind-time derivation (cross-cutting with P2)
    3. symbol inspection and budget tables (needs a bench)

    Item 3 overlaps P10's measurement gate; item 2 is the one that is genuinely blocked on nothing but effort.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Item 2's premise is now measured, and it holds (#4275)

    Your split lists item 2 as "the one that is genuinely blocked on nothing but effort", with the reason it is not small:

    EmitterProfile itself stores float xy_r[2], lum_r and so on. It is P2's public type and the whole legacy RGBW stack consumes it.

    That is about the profile. It assumes a narrower thing is already settled: that a Q16 3×3 inverse is accurate enough to replace the float one at all. If it were not, converting the profile would buy nothing — the derivation would still have to reach float to stay inside A1 — and item 2 would not be effort, it would be impossible as scoped. So it seemed worth measuring before anyone spends the effort.

    Both paths end in s16.16, so this is not about the output format; it is about where the arithmetic happens.

    primaries worst coefficient error worst ΔE2000
    sRGB 0 ULP 0.0000
    BT.2020 1 ULP 0.0057
    Display P3 1 ULP 0.0064

    against A1's 0.5, of which the mapper already spends 0.15.

    Where it gives out did not go the way I expected

    Conditioning is what decides a fixed-point inverse's accuracy, so I walked green onto the red–blue line until the matrix was nearly singular:

    green collapsed coefficient error ΔE2000
    90% 6 ULP 0.0421
    99% 575 ULP 0.0270
    99.9% 28 487 ULP 0.0914

    The coefficients lose four orders of magnitude of precision and the colour error does not follow. Those ULPs sit in directions a near-collinear device can barely produce, so they never become visible error — at the edge of singularity the two derivations are still an order of magnitude inside the budget.

    So item 2's premise holds. The profile conversion is the only thing in the way, and it can be scoped as the cross-cutting P2/P9 change you describe rather than as a question with an unknown answer.

    Two things this deliberately does not claim: it compares the two derivations against each other rather than against float64 (the shipped path is itself Q16-quantised, and "can this replace that" is the question asked), and every target is in gamut by construction — an out-of-gamut one goes through the mapper, measured separately.

  3. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    One piece of item 2 needed no conversion at all (#4279)

    Following the measurement above. While enumerating what the bind path actually spends float on, one call turned out not to need converting — it needed deleting.

    buildAdaptationMatrixQ16 inverted kBradford on every profile bind:

    float inverse[3][3];
    if (!colorimetric_response::invert3x3(kBradford, inverse)) {
        return false;
    }

    kBradford is a compile-time constant. That is a float determinant, a reciprocal, three column-scale divisions and nine multiplies, run to recompute a matrix that cannot change. #4279 puts the inverse next to it as a constant.

    The values are what invert3x3 produces from kBradford in float32 to the last bit, so the adaptation matrix is identical and nothing downstream moves. The solver's failure return went with it and could not have fired: a constant is either singular always or never.

    Two things stated rather than implied

    The case that checks the constant reads the value it was handed, not the shipped one — the implementation's namespace is not visible from the test, which is why that file already re-declares kBradford. So it verifies the number is correct and does not guard against an edit in the implementation. The adaptation behaviour cases do, and the mutations confirm it: one wrong digit fails the identity case, a transposition fails three.

    And this does not close item 2. It removes one float inverse from the bind path; buildRgbSolveMatrixQ16 still builds and inverts a per-profile matrix in float, and that is the part that waits on the fixed-point EmitterProfile.

  4. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Item 2's other precondition is measured, and the cost is 17x the first one (#4292)

    #4275 above measured whether a Q16 3×3 inverse can replace the float one: it can, at 0.0064 dE2000. That kept the forward matrix float — it quantised a matrix float had already built from float chromaticities.

    Item 2 needs the other half. EmitterProfile stores float xy_r[2], so a float-free bind path must hold those as Q16 and run xyY_to_XYZ in Q16 too. That is a different question, with a specific reason to doubt it: xyY_to_XYZ divides by y, BT.2020's blue sits at y = 0.046, and one Q16 step there is a 2.5e-04 relative perturbation on a divisor.

    primaries chroma q16 err coef ULP drive err worst dE2000
    srgb 4.07e-05 1 2.14e-04 0.0172
    bt2020 1.14e-04 2 3.66e-04 0.1085
    display_p3 4.07e-05 1 7.63e-05 0.0037
    narrow 1.53e-05 34 9.16e-05 0.0025

    It holds. 0.1085 against A1's 0.5, and against the ~0.35 the derivation has once the mapper's 0.15 is counted. Item 2 is feasible as scoped.

    But size it against 0.109, not 0.0064. The profile quantisation, not the inverse, is where item 2's error budget goes — seventeen times the figure #4275 reported for the same corpus. A conversion that also changes anything else in the bind path has much less room than the earlier number suggests.

    One thing that did not go the way the earlier measurement would predict

    narrow — the near-degenerate set — takes 34 coefficient ULP and still only 0.0025 dE2000. #4275's degeneracy walk found coefficient error and dE2000 rising together; here they separate. Conditioning moves the coefficients, the small divisor moves the colour, and the two are different failures. Worth recording so nobody uses one as a proxy for the other.

    Still not converted

    buildRgbSolveMatrixQ16 still builds and inverts in float, and EmitterProfile still stores floats. This says the effort is worth spending and what it has to fit inside; it remains cross-cutting with P2 because the legacy RGBW stack consumes the same type.

  5. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Item 2's inverse is written and merged-pending (#4305) — the float-free half

    #4275 measured that a Q16 3×3 inverse can replace the float one at 0.0064 dE2000, and #4292 measured the profile-quantisation half at 0.1085. Both were studies. This is the first of the two actually implemented.

    The thing the study left unwritten

    invert3x3_q16's docstring says it plainly:

    Python's integers are unbounded, so the cofactors and determinant here are exact; a C++ implementation needs i64 for the cofactors (Q32) and the determinant (Q48) and a staged or 128-bit divide for the last step. That is the cost this study is pricing.

    AVR has no __int128, so it is staged: the inverse is (cofactor << 32) / determinant, the cofactor is already Q32, and each of the 32 doublings is spent on the numerator while it fits and on the denominator otherwise.

    Validated against the exact divide before writing any C++ — the study's four profiles, six degrees of primary collapse, and 20,000 random primary sets: zero ULP disagreement, with 72% of coefficients needing at least one denominator halving (up to 11). So the staged path is the one being exercised, not a branch nothing reaches.

    Float-freeness, actually demonstrated

    This phase's whole point is that no float symbol is reachable, and the host cannot show that — x86 hardware float leaves no call behind. So the test compiles the translation unit for a Cortex-M0+ and reads the disassembly. GCC 16.1, -Os:

    function instructions float-runtime calls
    invert3x3Q16 383 none (__aeabi_ldivmod/__aeabi_lmul are integer)
    buildRgbSolveMatrixQ16 503 11 distinct __aeabi_f*/__aeabi_d*

    The second row is a positive control. Without it, a mistyped symbol makes the first row pass by disassembling nothing — which is what happened on my first run, so the helper now raises when the symbol is absent.

    On the input bound, which I got wrong first

    My first design bounded the input so the determinant provably fits i64. That bound works out to 16.0, and a deep-blue LED at xy = (0.14, 0.03) already has a Z column near 28 — so a conservative bound would reject real parts. It detects overflow instead, by division, which is exact everywhere and needs no builtin MSVC lacks.

    What remains of item 2

    buildRgbSolveMatrixQ16 still builds its forward matrix in float and EmitterProfile still stores float chromaticities. That is the 0.1085 half — seventeen times this one's error, and where item 2's budget actually goes. It stays cross-cutting with P2 because the legacy RGBW stack consumes the same type.

    And the phase's other criterion is still blocked

    P9's acceptance criterion is "no float or iterative-solver symbols linked … verified by symbol-level inspection (bash bloat)", plus recorded bloat and throughput budgets for AVR, SAMD51, ESP32 and parallel output. The symbol-inspection technique in #4305 is the same idea at translation-unit scale and is a useful piece of it, but it is not the whole-image verification the criterion asks for, and I am not claiming it is.

  6. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Item 2's luminance half is now priced too (#4309), and it does not move the answer

    The study behind item 2 held every emitter's luminance at 1.0. EmitterProfile carries lum_r, lum_g and lum_b and does not require that, so the precondition was priced halfway — quantising a luminance is a second perturbation and it lands on the same columns the division by y already stresses.

    Measured across four luminance sets and the same corpus:

    primaries worst dE2000 over the four sets where
    srgb 0.0172 unit
    bt2020 0.1085 unit
    display_p3 0.0304 typical
    narrow 0.0135 lopsided

    Non-unit luminance never makes it worse. The binding case is still BT.2020 at unit luminance, 0.1085 — the number already reported above — and every non-unit set lands at or below 0.031. The unit column reproduces the previous figures exactly, so generalising did not disturb what was measured.

    The coefficient/colour separation is now a rule rather than a note

    I recorded above that narrow took 34 coefficient ULP and only 0.0025 dE2000, and said the two were different failures. The luminance sets make it unmissable: narrow/lopsided moves 1515 ULPs and lands 0.0135, while BT.2020/unit moves 2 and lands 0.1085 — eight times the colour error for a seven-hundredth of the coefficient movement.

    A case pins it, so a change to the bind path cannot read a small ULP count as evidence the colour is fine, nor a large one as evidence it is not.

    Where item 2 stands

    • Inverse, implemented: feat(gfx): float-free s16.16 3x3 inverse, the first half of P9 item 2 (#4043) #4305 (float-free invert3x3Q16, staged divide, verified against the study bit-for-bit and float-free on a Cortex-M0+).
    • Forward build, priced: this, including luminance. Not implemented.
    • EmitterProfile storing Q16: not started, and the part that stays cross-cutting with P2 because the legacy RGBW stack consumes the same type.

    The forward build is the natural next piece and now has both halves of its budget measured. It is deliberately not in #4305, which is only the inverse.

    Correcting myself on one point

    I annotated the new Q16 build as dividing by y before scaling because "reversing it would stop modelling the shipped path" — which reads as though the order carries the budget. Mutation testing said otherwise: reversing it passed every other case. Measured, it moves 30 of 144 coefficients by at most 10 raw units and no dE2000 that matters. The order is worth keeping for fidelity to xyY_to_XYZ, which is a different claim from accuracy, and the comment now says so.

  7. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    P9's per-pixel path reaches no float runtime (#4315)

    #4305 and #4312 proved float-freeness for the matrix build. This measures the thing the criterion is actually about — what runs for every pixel of every frame.

    processPixelQ16 reaches no float-runtime helper at all, across the 19 functions the walk visits: decode, source matrix, gamut map, device solve, flux. buildStreamingPipelineQ16 in the same object reaches 33, which is the control — if both reported nothing the walk would have stopped rather than the pipeline being clean.

    So the float is confined to bind time, and that is item 2's remaining work rather than a defect: buildRgbSolveMatrixFromQ16 is the float-free counterpart and nothing routes to it yet.

    A correction to the method #4312 merged

    The reachability walk was wrong. In an unlinked object a call to an undefined symbol disassembles as bl 0 <name>, and objdump resolves that 0 against the symbol table — so when a defined function sits at address zero, every unrelocated call appears to go to it. My first run of this measurement reported the per-pixel path reaching isUsableSolveChromaticity through signedCbrtQ16: a cube root calling a chromaticity validator, which is what gave it away rather than the number, which looked plausible.

    It reads relocation records now. #4312's assertions were unaffected — phantom edges only add reachable helpers, making "reaches none" harder to pass — but its control was at risk and is now correct.

    Where P9 stands

    item state
    Q16 3×3 inverse done, #4305
    Q16 forward build from Q16 chromaticities done, #4312
    luminance half of the precondition priced done, #4309
    per-pixel path float-free measured, #4315
    EmitterProfile stores Q16 not started — cross-cutting with P2, the legacy RGBW stack consumes the same type
    a public route to the float-free bind path not started — nothing calls buildRgbSolveMatrixFromQ16
    TINY-tier symbol inspection and per-platform budgets (bash bloat) blocked

    The last two are what stand between this and the phase's acceptance criterion. The route question is an API decision (the Public Settings Pattern puts new setters on CFastLED), and the budget table needs whole-image inspection rather than the translation-unit scale everything above works at. I am not claiming either is done.

  8. zackees commented on Sep 19, 2026

    @zackees
    MemberAuthor

    P9 closed: the criterion is met, with measured evidence

    Acceptance criterion: TINY tier: no per-controller state, no float/solver symbols; bloat and throughput budgets recorded for representative platforms.

    part evidence
    TINY: no float/solver symbols #4454, docs/color-pipeline-budgets.md. Symbol inspection of attiny85 and uno Blink finds no pipeline symbols and no float runtime (__*sf3, __fix*, __float*). On TINY, FL_COLOR_PROFILE_RUNTIME is 0 and the pipeline is compiled out.
    TINY: no per-controller state the profile binding in ChannelOptions exists only under FL_COLOR_PROFILE_RUNTIME. The shared-ownership parts are compiled out below the large tier too (FL_COLOR_PIPELINE_SHARED, #4438). uno Blink is byte-identical to before the pipeline existed.
    bloat budgets, representative platforms examples/ColorProfile built with and without the binding: ESP32 +10,436 B / +544 B; ESP32-S3 +10,708 / +536; SAMD51 +11,200 / +540; Teensy 4.1 +10,240 / +2,624.
    throughput on the real path (C2) AutoResearch colorPipelinePerf on the bench: ESP32-C6 4.76 µs/px, RP2350 4.71 µs/px (about 210k px/s, 14–18× legacy). The dither-off output hashes match across RISC-V and ARM.
    per-pixel path fixed point #4315 measured it reaching no float runtime; #4305 and #4312 added the Q16 inverse and build.

    Re-assigned, per P10's rule ("every parent acceptance-criteria row checked or explicitly re-assigned by a follow-up decision issue"): the bind-time derivation still inverts in float once per profile, and nothing routes to the float-free buildRgbSolveMatrixFromQ16 yet. That is an API change to P2's public profile type, so it is tracked in #4458. It does not affect the TINY criterion, where the pipeline does not exist.

  9. moved this from Triage to Done in FastLED Trackeron Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions