Repository navigation
Description
docs/color-pipeline-contracts.md states:
The electrical contract bounds modeled demand for each latched output frame, including upward quantization/dither choices.
It does not. calculate_unscaled_power_mW() takes the source CRGB span — pre-dither, pre-quantization — while PixelController::dither() is
return b ? fl::qadd8(b, pc.d[RO(SLOT)]) : 0;applied before scaling. qadd8 saturates upward, so dither can only ever raise a channel above the value the limiter modelled, never lower it. This is #4156 R4's second half, stated there as "many sub-LSB emitters can dither upward together".
Measured
64 LEDs of CRGB(40, 40, 40), BINARY_DITHER, walking the full 8-frame dither cycle via advanceDitherFrame(), comparing calculate_unscaled_power_mW of the actually-latched bytes against the same function applied to the source scaled by brightness:
| brightness | modelled | worst latched frame | overshoot |
|---|---|---|---|
| 255 | 2400 mW | 2430 mW | +1.25% |
| 64 | 600 mW | 630 mW | +5.0% |
| 16 | 120 mW | 180 mW | +50% |
The absolute overshoot is roughly constant — about one output LSB per channel per LED — because e[i] = 256/s + 1 scales the offset up as brightness falls and the subsequent scale8 scales it back down. So the relative error grows without bound as brightness drops.
Why the direction matters
The power limiter's job is to lower brightness until demand fits a budget. The lower it goes, the more it under-reports. A budget tight enough to force brightness to 16 is precisely where the model is 50% optimistic, and the limiter has no reason to stop there — nothing feeds the discrepancy back.
That is the opposite of conservative, and the contract claims otherwise in as many words.
Caveats, stated rather than buried
- The real limiter computes
scale_power_for_brightness(unscaled_mW, brightness); my "modelled" column powers the brightness-scaled pixels instead. Same function, same inputs in spirit, but they can differ by rounding — the comparison is apples-to-apples between two uses ofcalculate_unscaled_power_mW, not a reproduction of the limiter's exact arithmetic. - My first probe recreated the
PixelControllereach iteration without advancing the global dither phase, so all eight "frames" were identical and I measured +25% at brightness 16 rather than the true +50%. Advancing the phase is what found the worse frame. Recorded because the first number looked plausible. - One LSB per channel is small in absolute terms. Whether a reserve is worth its cost is a judgement about how tight the budget is meant to be — hence an issue rather than a patch.
Fix direction
Either charge a dither reserve in the estimate (bounded by e[i] per channel, known before encode), or narrow the contract sentence to say the bound is on pre-dither demand and that dither may exceed it by up to one output LSB per channel. The current text and the current code disagree; both are defensible, only one can be written down.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Sep 11, 2026
Correction: the contracts doc is normative, so there is no doc defect here
I framed this as the document claiming something the code does not do, and said the present tense should not persist. That was wrong, and it is wrong for a reason I could have checked in one line —
docs/color-pipeline-contracts.mdopens with:So "the managed implementation uses two-pass streaming" and "the electrical contract bounds modeled demand ... including upward quantization/dither choices" are requirements, stated the way requirements normally are. An unimplemented one is exactly what the preamble says to expect. There is nothing to narrow and no present tense to remove.
What survives, and it is the part worth having
The measurements. They are unchanged and they were the point:
qadd8only adds — worst frame +50% at brightness 16 (R4: the power model reads pre-dither pixels, and dither only ever adds — 50% under-report at low brightness #4342)Those quantify what it costs to ship managed output before the prepass exists, which is useful for ordering the remaining work. They do not describe a defect in the document.
So read this as "requirement not yet met, here is the current exposure", not "doc and code disagree". Retitling is not needed — the titles describe the behaviour, which is accurate — but the framing in the body above is not, and I would rather say so than leave it.
This is the third time this session I have reported a defect from the wrong layer: #4326 (looked for a guard in the wrong file), #4333 (looked for a log capture hook in
log.hwhen it is incstdio.h), and now reading a requirements doc as a description. The common failure is concluding from where I looked instead of checking what the thing is for.zackees commentedon Sep 11, 2026
Same correction as I have just posted on #4344, since this issue carries the same error.
I wrote that "the contract claims otherwise in as many words", offered "narrow the contract sentence" as one of two fixes, and closed with "the current text and the current code disagree; both are defensible, only one can be written down."
That reads
docs/color-pipeline-contracts.mdas a description of current behaviour. It is not, and its preamble says so:The whole file is written in that voice. A requirement the code has not met yet is the document working as intended, not a disagreement between two defensible statements. So narrowing the sentence is not one of the options — it would weaken a requirement to match an implementation gap, which is the opposite of what the addendum is for.
Which leaves the other half of my own "either/or" as the actual work: charge a dither reserve in the estimate, bounded by
e[i]per channel and known before encode. That is not an invention either — the same contract section names it directly in the two-pass text:So the requirement already exists and is unmet, and this issue is the measurement of what it costs while it stays that way: up to +50% under-report at brightness 16, in the direction a limiter drives you.
The caveats in the original text still stand as written — particularly that my first probe measured +25% because it never advanced the dither phase, and that one LSB per channel is small in absolute terms. What does not stand is the suggestion that editing the doc is an equally valid outcome.
test(power): pin the draw the estimate misses when dithering is on (#…
zackees commentedon Sep 12, 2026
Pinned the exposure in #4391, and in doing so measured a figure that does not match this issue's headline. Recording that rather than quietly asserting agreement.
What I measure
Brightness 16, 200-LED strip, dither off against the worst frame of a full cycle, both sides through
calculate_unscaled_power_mW:+16% at worst, not +50%.
The shape is exactly as this issue describes, and it is the part that matters: the 1000 mW floor is the idle term for 200 dark LEDs, and the dither adds a near-constant ~162 mW on top, because what it does is lift channels off zero and how far barely depends on how dim the source is. So the relative error grows as the signal shrinks — a limiter pushing brightness down walks toward the worse end.
Why the number differs, as far as I can tell
Two things move it a lot, and I hit both:
scale_power_for_brightness— what the real limiter does — treats the estimator's per-LED idle term differently from powering an already-scaled pixel. Done that way I get 2.4x, which is not the dither; it is the comparison. This issue's own caveat flags the same hazard, which is what made me check.I do not know the strip length or source value behind the +50%, so I cannot say which of those accounts for it — only that either is sufficient. If the original probe is still around, the difference should be recoverable from those two knobs.
What is pinned
Two cases: that the worst dithered frame exceeds the undithered draw by more than 15% at a dim operating point, and that the ratio is larger at source 8 than at source 64 — the shape, not just the magnitude. Both fail if the dither is made to contribute nothing.
The fix this issue points at is untouched: a quantization reserve in the estimate, which the contract names directly in the two-pass prepass text.
fix(power): charge BINARY_DITHER's upward reserve in the limiter and …
feat(color): pipeline temporal dither on managed channels (P8, C5)
feat(color): pipeline temporal dither on managed channels (P8, C5) (#…