Skip to content

Color pipeline P6: embedded streaming pipeline core #4040

Closed

Description

@zackees

Phase P6 of the color pipeline implementation (see parent issue). Independently mergeable.

Scope

The embedded wide-precision core, on the normative working domain, executing as a streaming transform.

  • Decode: RGB8 + source profile -> u16 linear as one semantic conversion (normalize + inverse transfer); no intermediate RGB8 linear buffer, no RGB8→RGB8 correction (B3 structural test).
  • Working domain (B2): signed s16.16-class accumulators through primaries→XYZ (Bradford), conversion, and (once P7 lands) gamut stages; defined clamping/overflow rules; bounded RGB16 only after gamut mapping.
  • Streaming execution (C2): per-pixel inside show() via the existing PixelController iteration; no RGB16 framebuffer; optional small bounded per-channel line buffer reserved for P8 dithering, tier-gated.
  • Brightness/power stage (C4): setBrightness(b) applied as linear flux scalar b/255; power limiter contributes a second linear scalar composed multiplicatively at the same single stage; chromaticity preserved by construction; electrical power uses the profile's separate per-channel model. This is the only insertion point — nothing downstream rescales channels independently.
  • Effects contract (B8): buffer math stays in the declared space; .fled sRGB frames decode into the working domain before any blend with generated content; cross-space compositing rejected in v1.
  • Error budget vs P5 reference, inclusive of the brightness stage (A1): max ΔE2000 ≤ 0.5 / luminance ≤ 0.5% at identity brightness; ≤ 1.0 ΔE2000 at 1/32 brightness.

Decisions implemented

B2, B3, B6 (behavior half: CM-enabled .fled playback goes through sRGB decode), B8, C2, C4.

Acceptance criteria owned

  • Embedded implementation within documented ΔE/luminance budget vs reference.
  • Normative path: no intermediate RGB8 buffer, single final quantization (B3 restatement).
  • Brightness/power limiting chromaticity-preserving; separate electrical model.

Dependencies

P2 (types/binding), P5 (golden vectors gate every PR in this phase).

Deliverables

Streaming pipeline core wired from ChannelOptions through show(), with a pass-through final encoder stub until P8; budget-conformance test suite.

Activity

  1. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    The streaming core (#4195) and the binding adapter (#4199) are in. What remains in this phase is the show() wiring, and having gone looking for the seam I want to record what it actually requires, because it is more constrained than "call the pipeline from showPixels".

    The transform cannot go where the existing rewrite goes

    Channel::showPixels already has a place where pixels get rewritten: ReorderingPixelIteratorAny materializes a thread-local fl::vector<CRGB> for XYMap addressing and builds a fresh PixelController over it.

    That is the wrong home for this. C2 asks for per-pixel work inside the existing iteration with no framebuffer, and writing the pipeline's output into a CRGB buffer is both a frame-sized buffer and an 8-bit intermediate — the shape B3 rules out and that ci/tests/test_no_rgb8_intermediate.py already guards the gfx stages against.

    The seam that does fit

    PixelIterator is a hand-built vtable over a duck-typed source, and its constructor is templated on that type. So a source that pulls a raw pixel, runs processPixelQ16, and yields the quantized result satisfies it with no buffer at all — genuinely streaming, which is what C2 asks for.

    The interface such a source has to provide is the whole vtable:

    • loadAndScaleRGB(u8*, u8*, u8*)
    • loadAndScaleRGBW(const Rgbw&, u8*, u8*, u8*, u8*)
    • loadAndScaleRGBWW(Rgbww, u8*, u8*, u8*, u8*, u8*)
    • stepDithering(), advanceData(), size(), has(int)
    • under FASTLED_HD_COLOR_MIXING: loadRGBScaleAndBrightness(u8*, u8*, u8*, u8* brightness) and the deprecated getHdScale

    Two things that need deciding, not guessing

    Brightness must not apply twice. loadAndScale0/1/2 fold in mColorAdjustment, whose premixed carries brightness. The pipeline carries brightness too, as C4's flux scalar. So the managed source has to read raw mData and never call loadAndScale*, with the frame's brightness pushed into the flux scalar instead. That part is clear; it just has to be tested explicitly, because getting it wrong is a visible regression for every channel with a profile bound.

    The legacy correction and temperature are already handled — binding a profile clears them, which is what the LegacyClearedByProfile warning is about — so brightness is the only overlap.

    The HD path is genuinely open. loadRGBScaleAndBrightness hands the encoder a colour triple and a separate 5-bit brightness for APA102-HD. What that should mean once a colour pipeline owns the amplitude stage is a P8 question (chipset-aware quantization and 5-bit semantics), not something to decide by whatever makes the wiring compile. Options are to leave HD chipsets on the legacy path until P8, or to derive the brightness field from the flux scalar — the second needs the 5-bit semantics settled first.

    Suggested shape

    1. A ColorManagedPixelSource implementing the vtable interface over PixelController<RGB> plus a StreamingPipelineQ16, reading raw and quantizing once at the end — the "pass-through final encoder stub" this phase's deliverables call for.
    2. showPixels selecting it when buildPipelineForBinding succeeds, leaving every channel without a bound profile bit-identical.
    3. HD chipsets explicitly excluded until P8, rather than silently taking a path nobody designed.

    Deliberately not started as a partial: a half-wired hot path that double-applies brightness on some chipsets is worse than an unwired one, and the HD question is not mine to answer by default.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The budget deliverable is in #4287 — and A1 needs a black floor

    The three implementation PRs are in (#4195 streaming core, #4199 binding adapter, #4200 show() wiring). What was left is this phase's other deliverable, the budget-conformance suite. #4287 is that.

    It also found that the criterion cannot be met as literally written, for a reason worth recording here.

    What was standing in for it

    The conformance case bounded drive error and converted to A1's units in a comment — "A1's luminance budget is 0.5%; this is 0.13%" — a conversion it never computed. There was no dE2000 in C++ at all. And it read 48 hand-typed literals out of the corpus's 285, with ci/golden/color-reference-v1.json named only in a comment, so the two could diverge silently.

    Both are fixed: the vectors are generated from the corpus (all 57 for this device), a guard fails on a stale or subset header, and the case now computes dE2000 and luminance.

    The measurements

    measured A1
    identity brightness, dE2000 0.3951 ≤ 0.5
    identity brightness, luminance 3.66e-04 in Y (0.037%) ≤ 0.5%
    dim (8/255), dE2000 0.29 ≤ 1.0

    The dim half had never been measured against the reference at all.

    A1 has no black floor, and it needs one

    Unfloored the worst is 1.3055 dE2000, at bt2020-rgb-03 — code (0,0,1) in BT.2020. The mechanism is not darkness as such:

    • its reference drives are (0, 5.242e-05, 1.447e-05);
    • one s16.16 unit is 1.5259e-05;
    • so the blue drive is below one representable step. The implementation can answer 0 or a whole unit where the reference asks for 0.95 of one, and CIELAB's kappa branch turns that into a whole unit of L*.

    A luminance threshold does not separate these — bt2020-rgb-02 misses at Y = 5.4e-04 while srgb_bt709-rgb-00 passes at Y = 3.0e-04. What distinguishes them is a sub-ULP drive. Eight of 57 have one; excluding those, nothing exceeds 0.3951.

    So this is not an implementation defect. No fixed-point implementation of this width can meet 0.5 dE2000 on a target it cannot represent. What A1 is missing is the floor #4156 R8 already asked for — "define the luminance-error denominator and black floor … and unsupported low-light region" — and this puts a number on it: the s16.16 resolution itself, 1/65536 in drive.

    #4287 asserts both figures, so the floored result and the unfloored miss are each pinned and neither can drift while the other passes.

    What remains in P6

    The other acceptance criteria — no intermediate RGB8 buffer, single final quantization, chromaticity-preserving brightness with a separate electrical model — have their own cases already. If you want P6 closed on the A1 criterion, the open question is whether to amend A1 with the floor above or to record the two vectors as a known and bounded exception. That is a decision, not a measurement, so I have left it to you rather than editing the criterion.

    One coverage note, stated rather than hidden: the corpus has five device profiles and #4287 covers rgb only. rgbw, rgbww, rgbww_two_white and non_d65_white need emitter profiles on the C++ side that do not exist there yet, and the generator refuses to emit vectors nothing can run rather than emitting them silently.

  3. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    P6's criteria are all met now — proposing closure, with the evidence

    The last thing I left open here was whether A1 needed amending with a black floor. #4296 answered it by stating the floor in docs/color-pipeline-contracts.md, which is where the implementation contract lives. With that in, every criterion this phase owns has an artifact behind it. Checked against master rather than carried forward from the PRs:

    criterion evidence
    Embedded implementation within documented ΔE/luminance budget vs reference tests/fl/gfx/pipeline.cpp — 0.3951 dE2000 and 3.66e-04 in Y against A1's 0.5 and 0.5%, over all 57 corpus vectors for the rgb device, generated from the golden rather than transcribed (#4287)
    …documented docs/color-pipeline-contracts.md → "The black floor, stated": the floor is one s16.16 unit, with both the floored (0.3951) and unfloored (1.3055) figures published (#4296)
    …inclusive of the brightness stage "A1's dim budget holds with the brightness stage in the chain" — 0.29 dE2000 against A1's 1.0
    Normative path: no intermediate RGB8 buffer, single final quantization (B3) ci/tests/test_no_rgb8_intermediate.py — 6 cases, 20 subtests, including a self-check that the check can fail and a false-positive guard
    Brightness/power limiting chromaticity-preserving tests/fl/gfx/flux_scalar.cpp — ratios preserved, composition multiplicative and order-independent, full brightness bit-exact identity
    Separate electrical model power_mgt honours a declared PowerModelRGBW rather than dropping white_mW, and charges the emitters the strip actually lights (#4284)
    Deliverable: wired from ChannelOptions through show() fl::Channel::mPipeline, built in reconcileColorProfile and used in showPixels (#4200)
    Deliverable: budget-conformance suite the pipeline cases above (#4287)

    One thing I tried and threw away, because it would have been misleading

    Before finding test_no_rgb8_intermediate.py I started writing a numeric B3 test — checking that the drives land off the 8-bit grid (134 of 171 do, worst 127 against a 257 step) and that adjacent source codes never collide (0 collisions over 256).

    Both properties hold. I discarded it anyway, because the existing checker's docstring is right and my framing was not:

    That is a structural property, not something a numeric test can see: a pipeline that quantized to 8 bits somewhere in the middle would still produce plausible colours, just worse ones.

    The grid check only catches an 8-bit stage that is last; a mid-pipeline round would be scrambled by the matrices that follow and pass. Landing it would have added a case that looks like it guards B3 and does not. Recording the measurement here since it is a real property, and it is a fact about the pipeline worth having — just not a guard.

    What is not P6's

    The remaining pipeline work that touches this phase belongs elsewhere and should not hold it open:

    Unless one of those is meant to gate P6, I think this closes.

  4. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    One line in the closure evidence needs narrowing (#4330)

    Re-reading my own closure case above rather than adding to it. This row:

    Normative path: no intermediate RGB8 buffer, single final quantization (B3) — ci/tests/test_no_rgb8_intermediate.py — 6 cases, 20 subtests, including a self-check that the check can fail and a false-positive guard

    The checks are sound and the self-check is real. The scope is narrower than the row implies. The file scans eight stage files under src/fl/gfx — the pipeline's interior. B3's claim covers the normative path and includes "single final quantization", and the handoff from the pipeline to a chipset encoder is outside what the file looks at.

    That handoff is where a round trip survives:

    encoder fed by width
    writeWS2816 makeScaledPixelRangeRGB16 16-bit
    writeHD108 makeScaledPixelRangeRGB 8-bit, widened again by gamma 2.8
    UCS7604 16-bit makeScaledPixelRangeRGB 8-bit, widened again by a Gamma8 LUT

    On those two the wide output is quantized to 8 bits and then expanded — an intermediate quantization, which is the thing B3 names. Tracked separately as #4326.

    #4330 narrows the docstring so a green run stops being quotable for more than it inspected. It changes no check: 6 passed, 20 subtests, unchanged.

    What this does and does not do to the closure case

    It does not move the ΔE/luminance rows, the brightness-stage row, or the electrical-model row — those stand on measurements, not on this file.

    It does mean the B3 row should read as "the pipeline's interior does not round-trip through RGB8", with the encoder boundary open under #4326. Whether that gates P6 or belongs to P8 with the rest of the encoder integration ("Encoder integrations replacing P6's pass-through stub" is P8's deliverable) is a call for whoever closes this — I lean P8, but I would rather say so than quietly bank the narrower claim as though it were the whole one.

    The rule that would catch it is "a 16-bit encoder is fed the 16-bit adapter", which is not a property of the stage files. It is not in #4330 because it fails today on two of the three, and it belongs with the fix.

  5. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Two of P6's power criteria are documented but not implemented (#4342, #4344)

    The closure case above lists:

    Brightness/power limiting chromaticity-preserving — tests/fl/gfx/flux_scalar.cpp ...
    Separate electrical model — power_mgt honours a declared PowerModelRGBW ...

    Both rows are true and I am not withdrawing them. What they do not cover is whether the limiter's input is the right quantity, and on the contracts addendum's own wording it is not, twice over.

    #4344 — the limiter never sees the solve. docs/color-pipeline-contracts.md says "the managed implementation uses two-pass streaming"; there is no prepass. CFastLED::show() calls the power function on the raw CRGB array before any traversal, and the managed transform runs later inside showPixels. Measured on one LED, same estimator both sides:

    source emitter luminances charged drawn ratio
    (40,40,40) 1.00 36 mW 13 mW 0.36x
    (40,40,40) 0.10 36 mW 89 mW 2.47x
    (20,20,20) 0.05 20 mW 89 mW 4.45x

    The direction is set by emitter luminance relative to the rendering white — a property of the bound profile the limiter never reads.

    #4342 — the estimate is pre-dither. dither() is qadd8(b, d) applied before scaling and only ever raises. Worst frame over the 8-frame cycle, 64 LEDs: +1.25% at brightness 255, +5% at 64, +50% at 16. The limiter's job is to lower brightness until demand fits, so it walks toward its own worst case.

    Both under-estimate, and they compose.

    What this means for closure

    Neither is a regression in what P6 built; both are P6 criteria the addendum describes in the present tense and the code does not do. Whether that gates this phase or belongs to P8 alongside the encoder-width work (#4326) is the same judgement I flagged on the B3 row in #4330 — and my lean is the same: P8, because the prepass is an architecture change and the dither reserve wants the pipeline-dither decision settled first.

    What should not survive either way is the doc's present tense. That part is cheap and does not need the architecture to be decided.

  6. zackees commented on Sep 11, 2026

    @zackees
    MemberAuthor

    Correcting my own comment above

    I wrote that the addendum "describes in the present tense" things the code does not do, and that "what should not survive either way is the doc's present tense". That is wrong. docs/color-pipeline-contracts.md opens by saying it is a list of implementation requirements, not a description, and that "unimplemented requirements remain open". Requirements are normally written in the present tense; an unmet one is what the preamble tells you to expect.

    So there is no documentation defect in #4342 or #4344, and nothing to change in the addendum. Corrected on both issues.

    The measurements stand, and they are what I should have led with:

    measured
    limiter charges source RGB, not solved drives (#4344) up to 4.45x under-estimate, dim emitters
    estimate is pre-dither, qadd8 only adds (#4342) worst frame +50% at brightness 16

    Read as "two P6 requirements are unmet, and here is the current exposure" rather than "the doc is wrong". That does not change my lean on sequencing — the prepass is an architecture change and the dither reserve wants the pipeline-dither decision first, so both sit with P8 alongside #4326 — but it does change what needs doing: implementation, not editing.

    Nothing here alters the closure rows in my earlier comment; the ΔE, brightness-stage and electrical-model rows stand on their measurements.

  7. zackees commented on Sep 19, 2026

    @zackees
    MemberAuthor

    P6 closed: the last two requirements have landed

    The closure case above (2026-09-10) listed every criterion with its artifact. What held the phase open afterwards were two unmet power requirements from the contracts addendum. Both are now implemented, tested, and merged:

    requirement fixed by evidence
    R3 / #4344: the limiter must charge solved drives, not source RGB #4438 [#4344] cases in tests/fl/power_estimation.cpp. Before the fix, a red-heavy frame was charged 7561 mW against about 18230 mW of drive.
    R4 / #4342: the bound must cover upward dither choices ("quantization reserve") #4450 [#4342] cases. The reserve bounds the worst frame of a full dither cycle over a 7×7 source × brightness grid. A token reserve fails at the issue's own figure: 1001 mW charged vs 1162 mW latched.

    Along the way, #4440 (a pipeline could be freed under a reader; it is now held by shared_ptr and compiled out on small tiers) merged in #4438.

    Unchanged from the earlier closure case:

    • ΔE and luminance within A1: 0.3951 dE2000 at identity brightness, 0.29 at 1/32.
    • No RGB8 intermediate inside the pipeline.
    • Brightness and power scaling preserve chromaticity; the electrical model is separate.
    • Wired from ChannelOptions through show().

    The encoder-boundary quantization noted in #4330 was resolved under P8 (#4368, #4387).

  8. moved this from Triage to Done in FastLED Trackeron Sep 19, 2026
  9. zackees commented on Sep 19, 2026

    @zackees
    MemberAuthor

    Correcting my closure comment above: I did not check B6, and its behaviour half ("CM-enabled .fled playback goes through sRGB decode") is not implemented. video.color is resolved (P4), but it never reaches a channel's source profile, and the default source is linear sRGB. The workaround is documented, and the implementation is tracked in #4460, linked under #4034. The rest of the closure evidence stands.

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