Align the container to the disc, and find the decoder-free packed player fits
Two sessions, unrecorded until now, committed together because their edits share files and cannot be split cleanly after the fact. Session 28 (FINDINGS 60): the container is DLX5 -- every record sector-aligned, 120/120 starting on a boundary where 3/120 did, +0.48% on the wire and zero clocks -- and the ring's release rounds to RECALN so no pad is stranded. Two encoder levers measured and refused: `--spans all` buys +0.19 dB for +67% of the wire, and joint span/lam selection emits byte-identical containers because `lam` never leaves its floor on any of 120 frames. Session 29 (FINDINGS 61): the packed full-frame blit is 27.3% of a 12 fps frame, a channel fills GVRAM in buffer mode off the disc with the CPU halted, and it walks the 1,024 B line stride itself through array chaining. At the 9 clk/B dual-address floor the codec is 110.4% of a frame and a decoder-free packed literal player is 55.2%, at +4.89 dB -- 2.75 dB past a ceiling the codec's scene-wide palette cannot cross. Encoder work is parked; the codec is kept and not built on. check.sh is ALL GREEN before and after, plus one new stage that gates the ORDER of the measured paint costs rather than their values. Claude-Session: https://claude.ai/code/session_01194oWYW8DQXK1SZ2DnChW6
This commit is contained in:
@@ -157,6 +157,23 @@ JOINT_DECIDE = False
|
||||
# `--joint-bucket` turns it on.
|
||||
JOINT_BUCKET = False
|
||||
|
||||
# E3 / FINDINGS 39.3 item 5: SPAN SELECTION IS GREEDY AFTER `lam`, and this is
|
||||
# the switch that makes the two joint. The lam bisection picks a mode map
|
||||
# against a byte allowance, and the span pass then REMOVES the block payload of
|
||||
# every block it covers -- so the frame lands under the allowance by exactly
|
||||
# the bytes the spans freed, and the blocks that were NOT spanned were priced
|
||||
# at a lam chosen as if those bytes were still needed. Joint mode hands the
|
||||
# freed bytes back to the lam search and re-spans the result, to a fixed point
|
||||
# or two rounds, whichever comes first.
|
||||
#
|
||||
# It is a REFINEMENT, not a different objective: lam can only fall (the
|
||||
# allowance only grows), so the un-spanned blocks can only improve, and a round
|
||||
# is kept only if the frame still fits both ceilings it was already fitting.
|
||||
# Default OFF until measured, which is 44.3's lesson -- ask whether the lever
|
||||
# is loaded before pulling it.
|
||||
JOINT_SPANS = False
|
||||
JOINT_SPAN_ROUNDS = 2
|
||||
|
||||
|
||||
def _byte_clk():
|
||||
"""The debit the mode decision is allowed to see (0 = the old decision)."""
|
||||
@@ -287,6 +304,39 @@ def _fit_spans(m, ctx, mode, sz, room, cyc_budget, span_mode, ib):
|
||||
return nmode, nsz, H.cycles(nmode) + sel["clocks"], sel
|
||||
|
||||
|
||||
def _refit_joint(m, ctx, allow, span_allow, lam_lo, lam_hi, cyc_budget,
|
||||
span_mode, ib, mode_pre, mode, sz, cyc, sel, mu=0.0):
|
||||
"""Give the lam search back the bytes the span pass freed, then re-span.
|
||||
|
||||
`mode_pre` is the mode map BEFORE spanning and `mode` the one after, so the
|
||||
difference in frame_bytes is exactly what the spans made unnecessary. The
|
||||
ceiling the result is judged against is the one _fit_spans was already
|
||||
working to, so a kept round is never a frame that grew past a budget it was
|
||||
inside.
|
||||
"""
|
||||
ceiling = span_allow if span_allow is not None else allow
|
||||
for _ in range(JOINT_SPAN_ROUNDS):
|
||||
if sel is None:
|
||||
break
|
||||
freed = (H.frame_bytes(mode_pre, ctx["nb"], ib)
|
||||
- H.frame_bytes(mode, ctx["nb"], ib))
|
||||
if freed <= 0:
|
||||
break
|
||||
lam2, mode2, sz2, _ = _search_lam(ctx, allow + freed, lam_lo, lam_hi, mu=mu)
|
||||
if sz2 <= H.frame_bytes(mode_pre, ctx["nb"], ib):
|
||||
break # lam did not move: already at the floor
|
||||
n_pre, n_mode, n_sz, n_cyc, n_sel = (
|
||||
mode2, *_fit_spans(m, ctx, mode2, sz2, span_allow if span_allow
|
||||
is not None else allow, cyc_budget, span_mode, ib))
|
||||
if n_sel is None or n_sz > ceiling:
|
||||
break
|
||||
if cyc_budget is not None and n_cyc + DISK_CLK_BYTE * n_sz > cyc_budget \
|
||||
and cyc + DISK_CLK_BYTE * sz <= cyc_budget:
|
||||
break # round 1 made the deadline and this does not
|
||||
mode_pre, mode, sz, cyc, sel = n_pre, n_mode, n_sz, n_cyc, n_sel
|
||||
return mode_pre, mode, sz, cyc, sel
|
||||
|
||||
|
||||
def encode_rate_controlled(m, target_kbps, fps=12, bucket_frames=8,
|
||||
lam_lo=1.0, lam_hi=LAM_CLIFF, prefill=0.0,
|
||||
steps=None, verbose=False, cycle_budget=None,
|
||||
@@ -364,6 +414,10 @@ def encode_rate_controlled(m, target_kbps, fps=12, bucket_frames=8,
|
||||
mode_pre = mode
|
||||
mode, sz, cyc, sel = _fit_spans(m, ctx, mode, sz, span_allow,
|
||||
cycle_budget, span_mode, ib)
|
||||
if JOINT_SPANS:
|
||||
mode_pre, mode, sz, cyc, sel = _refit_joint(
|
||||
m, ctx, allow, span_budget and span_allow, lam_lo, lam_hi,
|
||||
cycle_budget, span_mode, ib, mode_pre, mode, sz, cyc, sel)
|
||||
if cycle_budget is not None and cyc + DISK_CLK_BYTE * sz > cycle_budget:
|
||||
# The byte allowance could not buy the frame's deadline, so fall
|
||||
# back to the controller that pays in picture -- and then offer
|
||||
@@ -374,6 +428,11 @@ def encode_rate_controlled(m, target_kbps, fps=12, bucket_frames=8,
|
||||
mode_pre = mode
|
||||
mode, sz, cyc, sel = _fit_spans(m, ctx, mode, sz, span_allow,
|
||||
cycle_budget, span_mode, ib)
|
||||
if JOINT_SPANS:
|
||||
mode_pre, mode, sz, cyc, sel = _refit_joint(
|
||||
m, ctx, allow, span_budget and span_allow, lam_lo,
|
||||
lam_hi, cycle_budget, span_mode, ib, mode_pre, mode,
|
||||
sz, cyc, sel, mu=mu)
|
||||
late = cyc + DISK_CLK_BYTE * sz > cycle_budget
|
||||
# Paint from the mode map as it was BEFORE spanning. A spanned run's
|
||||
# blocks read SKIP in the emitted header, but SKIP means "hold the
|
||||
|
||||
Reference in New Issue
Block a user