Commits
2026-09-04
perf(av1): whole-pel axes skip the pass they do not needAhmet Kaan Gümüş · c8bf4a0
perf(av1): whole-pel axes skip the pass they do not need A motion vector with a whole-pel component still ran the full two-pass filter. Fraction 0 is the identity tap, so each axis has an exact shortcut: Round2(128 * s, InterRound0) == 16 * s horizontally, and vertically Round2(128 * a, InterRound1) == Round2(a, InterRound1 - 7) (== a for the compound round), which also means the 3 rows above and 4 below the block never have to be filtered -- a 4-tall chroma block drops from 11 horizontal rows to 4. Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp identical to the pre-lane binary. Interleaved medians on the 1080p segment, 6 pairs against the previous commit: 19.08 s -> 17.42 s (faster in 5 of 6).
perf(av1): horizontal MC taps multiply at 16 bitsAhmet Kaan Gümüş · dcac6b3
perf(av1): horizontal MC taps multiply at 16 bits The interior horizontal row had auto-vectorised, but into pmuludq/pshufd chains: an i32 x i32 lane multiply is three instructions on SSE2. A tap is |x| <= 128 and a sample is bounded by the bit depth (<= 4095 at 12-bit), so narrowing both factors to i16 before the widening multiply gives exactly the same products and one instruction per pair. Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp identical to the pre-lane binary. Interleaved medians on the 1080p segment: 22.25 s base -> 16.64 s.
perf(av1): unscaled compound MC leaves the scaled walkAhmet Kaan Gümüş · 8c7cbe4
perf(av1): unscaled compound MC leaves the scaled walk horizontal_scaled_pass was 14% of decode self time, and almost none of that was scaling: every compound prediction routed through it whatever the reference's scale, so an unscaled block paid a per-column integer-position derivation, a per-column filter-phase lookup, a column-major read of the reference and a per-tap clamp. At REF_NO_SCALE that walk reduces algebraically to the fixed x0/xfrac split (pos_x_q10 == x_q4 * 64 + 32 makes int_pel == x_q4 / 16 and (x_qn & 1023) >> 6 == x_q4 % 16 for every column), so a new horizontal_pass router sends it to the contiguous unscaled pass and leaves the general walk for superres. Both vertical passes now accumulate tap-major over contiguous slices and reuse the thread-local scratch, as the single-reference one does. Byte-exact: 1080p 10-bit (299 frames) and 2160p HDR EC_PROBE_OUT16 dumps both cmp identical to the pre-lane binary. Interleaved medians on the 1080p segment: 23.39 s base -> 18.21 s (12.8 -> 16.4 fps).
perf(av1): unscaled MC does one contiguous horizontal pass, no per-call allocAhmet Kaan Gümüş · 62f159c
perf(av1): unscaled MC does one contiguous horizontal pass, no per-call alloc predict_with_filters_kern spent 17% of decode self time in a doubly nested per-sample loop: every tap re-read the filter table, every sample went through the Clip3 edge helper, and each call allocated its own (h+7)-row intermediate. Restructured dav1d style, keeping the rounding chain untouched: taps are fetched once into a [i32; 8]; a row whose whole 8-tap footprint is inside the reference's true extent is one contiguous slice walked with windows(8) (the clamped form stays for edge rows and is what a past-the-edge motion vector still takes); the vertical pass accumulates tap-major over two contiguous i32 slices and skips the zero taps the 4-tap kernels carry; the whole-pel case copies a row at a time. The intermediate is a thread-local scratch buffer instead of a per-call Vec. Byte-exact: EC_PROBE_OUT16 dumps of a 299-frame 1080p 10-bit segment and a 4 s 2160p HDR segment both cmp identical to the pre-change binary. Interleaved medians on the 1080p segment: 22.61 s -> 20.66 s.
perf(av1): read every EC_* debug flag once instead of per blockAhmet Kaan Gümüş · ba458d2
perf(av1): read every EC_* debug flag once instead of per block `std::env::var*` is a getenv + strlen + CStr validation on every call, and this crate reads its trace flags from per-block, per-TU and per-MC-call paths -- 11.6% of a 1080p10 decode's self time went to that, with the two worst sites inside the motion-compensation kernels themselves. Nothing in the crate or its tests calls `set_var`, so each name is a process constant. New `envflags` module: `env_flag!(NAME)` keeps one `LazyLock<bool>` per CALL SITE (atomic load after the first call, no hashing), `envflags::var` serves the value sites from a single snapshot of the environment. Semantics are unchanged at every site -- `is_some()`, `is_none()` and the `Result<String, VarError>` shape are preserved -- and the decoder's output is byte-identical. 160 sites in decode.rs, 2 in mc.rs. Header/tool-lookup sites that run once per stream are left alone. 1080p10 299-frame segment, interleaved medians of 3: 24.47 s -> 22.03 s (12.2 -> 13.6 fps), output byte-exact. (cherry picked from commit 318e0cce54fe7697a2d23c02d3b0d385f0e1401a)
2026-09-02
Merge branch 'lane-mc64' (2be1f92): pinned 192x128 stream with a 64x64 intra block in an inter frameAhmet Kaan Gümüş · 361f8be
Merge branch 'lane-mc64' (2be1f92): pinned 192x128 stream with a 64x64 intra block in an inter frame Adds crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu and its gate, plus the EC_MC_TRACE rung. Conflicts: kept main's per-var dump_stage_idx over the lane's single-counter stage_dump_idx, and main's sub-8x8 strip chroma footprint (the lane branched before it) with the lane's MC trace line. Gates: pinned_rect_stream (1), refusal_inventory (3), gate_coverage (9), base_ctx_rect_offsets (1) -- 14 passed, 0 failed.
fix(av1): rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the blockAhmet Kaan Gümüş · 759e688
fix(av1): rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the block decode_inter_block predicts a rectangular block over its enclosing square buffer (side x side, chroma_side x chroma_side; write_w/write_h govern only the pixel write). The narrow-block decision lived in mc::predict_with_filters and read that buffer's dimensions, while libaom av1_get_interp_filter_params_with_block_size takes it per axis from the prediction block's own w/h -- so the chroma of an 8x16 / 16x8 inter block (4x8 / 8x4) used the 8-tap kernel where libaom uses the 4-tap one. Luma is never <= 4 wide on this path, which is why such streams decoded luma-exact and differed by +-1 on scattered chroma samples (lane-interedge r1's 192x128 control, no frame-edge node, cdef/LR off). mc gains predict_with_filters_kern / predict_scaled_kern / predict_compound_intermediate_kern (old entry points delegate with kern = block dims) plus a RECT_NARROW_KERN_HITS counter; decode_inter_block's 12 prediction calls pass write_w/write_h and write_chroma_w/write_chroma_h. New gate a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact: real aomenc mandelbrot 192x128 and 128x192, 8- and 10-bit, cq 20/32/45, 6 frames, lag-in-frames=0, every decode-order frame compared on Y, U and V; 12/12 arms exact, narrow-kernel counter nonzero at both depths and in both orientations. Same recipe mismatched chroma in all arms before the fix.
fix(av1): per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA blockAhmet Kaan Gümüş · f866759
fix(av1): per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA block EC_AV1_POSTDEBLOCK_DUMP/EC_AV1_POSTCDEF_DUMP wrote .f0 for every frame, so any per-frame filter-stage bisection silently compared the last decoded frame; they are now keyed on the decode-order picture index like the prefilt dump. EC_MC_TRACE prints every mc::predict_with_filters / predict_compound_intermediate / warp_affine call with its q4 position, block size, subpel fractions and kernels, placed before the whole-pel fast path, plus EC_IB at decode_inter_block entry and is_inter/skip on EC_MODE -- an absent MC call is now visible. With that: the 192x128 8-bit stream's frame-2 luma-only mismatch at px(128,64) is a 64x64 PARTITION_NONE INTRA block in an inter frame, not the inter NEWMV block the charter described (that mv belongs to frame 1's split superblock, which is exact). Zero MC calls for the block in either decoder; chroma bit-exact, so the 64-length luma transform is the suspect. Stream pinned as a fixture because its aomenc recipe does not reproduce it.
2026-09-01
fix(av1): a prediction block 4 or fewer samples wide reads the REGULAR narrow subpel kernel under EIGHTTAP_SHARP too -- spec 7.11.3.4 filterIdx sends EIGHTTAP and EIGHTTAP_SHARP to filter index 4, and libaom's av1_interp_4tap[MULTITAP_SHARP] is av1_sub_pel_filters_4 (filter.h:239-244, comment "For w<=4, MULTITAP_SHARP is the same as EIGHTTAP_REGULAR"); we used the 8-tap sharp table there, invisible above 4 samples so it only bit 4-wide chroma. Cherry-picked from lane-gmaffine 3bb10f1; unit test pins all four narrow mappings (regular->4, smooth->4smooth, sharp->4, bilinear->bilinear).Ahmet Kaan Gümüş · 53b4e56
fix(av1): a prediction block 4 or fewer samples wide reads the REGULAR narrow subpel kernel under EIGHTTAP_SHARP too -- spec 7.11.3.4 filterIdx sends EIGHTTAP and EIGHTTAP_SHARP to filter index 4, and libaom's av1_interp_4tap[MULTITAP_SHARP] is av1_sub_pel_filters_4 (filter.h:239-244, comment "For w<=4, MULTITAP_SHARP is the same as EIGHTTAP_REGULAR"); we used the 8-tap sharp table there, invisible above 4 samples so it only bit 4-wide chroma. Cherry-picked from lane-gmaffine 3bb10f1; unit test pins all four narrow mappings (regular->4, smooth->4smooth, sharp->4, bilinear->bilinear).
Merge branch 'lane-scaledref': compound/OBMC/interintra under scaled references; WARPED_CAUSAL alphabet dropped when the ref is scaled (was silent wrong pixels); one-sided chroma OBMC for 8x8 luma; EC_PROBE_OUT (verifier PASS, 268/0/23)Ahmet Kaan Gümüş · ea8bda8Browse files
fix(av1): combine_compound folded two shifts libaom keeps separateAhmet Kaan Gümüş · cc39f29
fix(av1): combine_compound folded two shifts libaom keeps separate libaom's `av1_highbd_dist_wtd_convolve_2d_c` (and its lowbd twin) applies a TRUNCATING `>> DIST_PRECISION_BITS` to the weighted sum and only then `ROUND_POWER_OF_TWO(.., round_bits)`. We folded both into `Round2(sum, 8)`, which rounds one LSB high whenever `(sum >> 4) + 8` is one below a multiple of 16 and the dropped low 4 bits are non-zero. Bit-depth independent (the CONV_BUF round_offset cancels exactly in this crate's unbiased intermediate domain), so it is a rare off-by-one at any depth -- raised by lane-cwarp's measurement that 10-bit compound still mismatches frame 1 luma while single-reference 10-bit is 6/6 exact. Unverified against that fixture. cargo test -p ec-av1 --lib -j3 compound: 16 passed, 0 failed, 73.58s (includes the real-aomenc 8-bit compound and masked-compound gates).
fix(av1): 10-bit loop restoration, diffwtd mask and warp all ran with 8-bit constantsAhmet Kaan Gümüş · 42752a0
fix(av1): 10-bit loop restoration, diffwtd mask and warp all ran with 8-bit constants lane-hbdinter r1. The charter's premise (a 10-bit inter frame 2 mismatch) did NOT reproduce with the tool-restricted inter recipe; widening the recipe to real loop restoration did, and the defect turned out to be bit-depth-wide, not inter-specific -- it fires on the KEY frame too, and lane-hbd's 10-bit gate simply had `--enable-restoration=0`. Four sites carried hardcoded 8-bit constants, all checked against the oracle source (~/.cache/aom-oracle/src): - restoration.rs `compute_ab`: libaom `restoration.c:660-662` scales the box sums back to the 8-bit range before forming `p` (`a = Round2(A, 2*(bd-8))`, `b = Round2(B, bd-8)`; `B[k]` keeps the raw sum). We never did -> wrong `z`, wrong blend factor at 10-bit. This is the site the gate attributes the mismatch to (ablation below). - restoration.rs `apply_wiener_stripe`: the horizontal intermediate was clamped to a fixed `[0, 8191]`, i.e. `WIENER_CLAMP_LIMIT(3, bd=8) - 1` (`convolve.h:43`), in this crate's *unbiased* domain. Correct bounds are the libaom limit shifted down by its `1 << (bd + 3)` bias. At 8-bit neither end is reachable (which is why every 8-bit gate passed); at 10-bit the top of the range is 16368, so most Wiener intermediates were truncated. - mc.rs `diffwtd_mask`: libaom `reconinter.c:307` rounds the CONV_BUF difference by `INTER_POST_ROUND + (bd - 8)`; we used the constant 4. - warp.rs `warp_affine`: `const BD: i32 = 8` fed both offset terms and the final `sum - (1<<(bd-1)) - (1<<bd)` (tip from lane-gmaffine, confirmed against `av1_warp_affine_c`). Non-compound sub-pel MC needs no change: libaom only shifts round_0/round_1 when `bd + FILTER_BITS - round_0 + 2 > 16` (`convolve.h:83`), which is 12-bit only -- 10-bit keeps 3/11 and 3/7. Gate: `a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact` (stream.rs) -- real aomenc yuv420p10le, 128x64, 16 frames, forward P frames, deblock + loop restoration on, hard-asserting the new `mc::inter_pred_hits` counter, `deblock_hits`, and a non-RESTORE_NONE LR filter, comparing all 16 frames against ffmpeg's own 10-bit decode. Green with the fix; reverting only the `compute_ab` scaling turns it red at frame 0 (V plane, sample 52: ours 289, ffmpeg 288). cargo test -p ec-av1 --lib: 268 passed, 0 failed, 23 ignored (664s).
2026-08-30
Merge branch 'main' into lane-superresAhmet Kaan Gümüş · 17c9a9c
Merge branch 'main' into lane-superres Resolves the scaled-MC conflict in decode.rs in favour of the lane's structure, and widens predict_scaled to u16 for main's high-bit-depth sample type (fixture included). Lane state after the merge: 264 passed, 1 failed -- the lane's own gate a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact. That is the lane's deliverable, not merge fallout, so this does not go to main yet.
feat(av1): u16 widen compiles clean, 263/263 tests pass, 8-bit output bit-exactAhmet Kaan Gümüş · 35100f3
feat(av1): u16 widen compiles clean, 263/263 tests pass, 8-bit output bit-exact Closes the 42-error checkpoint from r1's saved diff. decode.rs/warp.rs/mc.rs call sites widened through OBMC and interintra blend chains; encode.rs and motion.rs's own buffers stay u8 (encoder is 8-bit only this round) with a local u16 round-trip box (intra_predict_u8 in encode.rs, inline conversion in mc_trial and motion::search_traced_from_step) at their 4 call sites into the now-widened intra::predict/mc::predict. bit_depth != 8 refusal untouched, no 10-bit gate added.
wip(hbd): r1's u16 widen in flight at the cap (does not compile; error count is the progress metric)Ahmet Kaan Gümüş · 31976a1Browse files
wip(superres): builder's in-flight edits, committed verbatim at the 75-turn cap (state unverified by me)Ahmet Kaan Gümüş · ddad1b5Browse files
feat(av1): mc::predict_scaled + frame_width threaded through decode_inter_blockAhmet Kaan Gümüş · bc2ef3d
feat(av1): mc::predict_scaled + frame_width threaded through decode_inter_block mc::predict_scaled/scale_factor/REF_NO_SCALE per r8's derived spec 7.11.3.3 algorithm (horizontal-only scaled sampling grid, vertical pass untouched); pinned at REF_NO_SCALE reproducing predict_with_filters bit-exact for every subpel fraction and block width 4/8/16. decode_inter_block gains a frame_width: usize parameter (18 call sites end allow_screen_content_tools, one test call site ends false,), not yet consumed -- prediction and refusal wiring is next.
2026-08-28
feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refusedAhmet Kaan Gümüş · ddb5bef
feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused diffwtd_mask/blend_masked_compound in mc.rs, algebraically re-derived onto this crate's unbiased predict_compound_intermediate domain (libaom's round_offset bias cancels exactly in both the mask diff and the blend weight sum, proven in the doc comments -- no offset bookkeeping needed). Both comp_group_idx==1 decode.rs sites now build+apply the real blend for COMPOUND_DIFFWTD; COMPOUND_WEDGE still refuses by name (wedge codebook out of r2 scope per the charter's mergeable-partial fallback). Fixed a real latent bug while wiring this in: compound_idx was read unconditionally, missing libaom's comp_group_idx==0 outer gate (dead code before this round since the masked path always errored earlier). Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact flipped to hard assert (masked_compound_hits() > 0) with DIFFWTD refusals now forbidden; hammered 8/8 green, zero pixel mismatches. Full ec-av1 lib suite: 220 passed, 0 failed, 17 ignored.
feat(av1): compound CONV_BUF blend + distance-weight assign, not wired yetAhmet Kaan Gümüş · 181a784
feat(av1): compound CONV_BUF blend + distance-weight assign, not wired yet mc.rs: predict_compound_intermediate (round_1=7, no clip, mirrors libaom's COMPOUND_ROUND1_BITS path) and combine_compound (spec 7.11.3.15 weighted average, shift = InterPostRound + DIST_PRECISION_BITS) -- pinned against a whole-pel identity case that round-trips exactly through both stages. compound.rs (new): dist_wtd_comp_weight_assign, a pure port of libaom's av1_dist_wtd_comp_weight_assign (quant_dist_weight/quant_dist_lookup_table search), tested standalone against hand-worked order-hint cases. Neither is wired into decode.rs yet -- comp_group_idx/compound_idx reads, Neighbours compound_idx tracking, and the reconstruction call sites are still open (see HANDOFF).
2026-08-27
feat(av1): interpolation filters beyond REGULAR, incl. per-block SWITCHABLEAhmet Kaan Gümüş · 10f24e6
feat(av1): interpolation filters beyond REGULAR, incl. per-block SWITCHABLE The ~13% decodes-but-wrong inter flake was a whole missing filter family: motion compensation always used the REGULAR subpel tables, while real encoders pick SMOOTH/SHARP per frame -- or SWITCHABLE, reading a per-block filter symbol pair this decoder never read (the silently-unread class again; our own encoder writes one fixed filter). All four table sets land in mc.rs with an aomdec-pinned unit test, the switchable_interp CDFs and neighbour context follow libaom's read_mb_interp_filter, and the filter threads from the frame header through both inter block paths. The forwarding gate ran 10/10 with zero pixel mismatches and no vacuous skips.
fix(av1): filter-intra was already correct -- gate against a real aomenc streamAhmet Kaan Gümüş · 2adf290
fix(av1): filter-intra was already correct -- gate against a real aomenc stream The straddling-boundary mismatch against ffmpeg's decode was never the filter-intra predictor: it's a real AV1 deblocking-filter artifact, and this decoder has no in-loop deblocking at all. `--loopfilter-control=0` on the aomenc fixture makes the two decodes byte-exact with zero source changes to intra.rs/decode.rs's prediction math. Adds a permanent gate (crates/ec-av1/src/stream.rs) that shells out to a real standalone aomenc build (ffmpeg's own libaom-av1 wrapper on this box doesn't expose enable-tx-size-search/loopfilter-control through -aom-params), asserts the use_filter_intra symbol actually fired via a new process-global counter (decode::filter_intra_hits), and checks pixel-exact luma/U/V against ffmpeg's own decode of the identical bytes. The encoder's screen-content-tools decision is a real internal PSNR trial, occasionally flips even with palette/intrabc off; the test skips (not fails) the still-unsupported-gap runs the same way the existing CDEF gate test does.
fix(av1): 4-tap subpel filters for blocks 4 wide or tallAhmet Kaan Gümüş · aad8b59
fix(av1): 4-tap subpel filters for blocks 4 wide or tall Spec 7.11.3.4 selects the filter table per axis: an output dimension of 4 or less reads Subpel_Filters' narrow counterpart (av1_sub_pel_filters_4), whose outer two taps on each side are zero. We fed every block the 8-tap table, so 4:2:0 chroma under an 8x8 luma leaf -- the common chroma shape, not a corner -- reached 3 samples past its edge with nonzero weights and came out +-1 against the reference decoder wherever the extra taps mattered. Found by diffing libaom's dec_calc_subpel_params against ours: the phase matched, the tap table did not. Closes the 640x360 inter straddle sequence's frame-2 U-plane desync; the whole sequence now round-trips through ffmpeg pixel-exact.
perf(av1): bypass sub-pel filtering for whole-pel motion predictionAhmet Kaan Gümüş · ef383d9
perf(av1): bypass sub-pel filtering for whole-pel motion prediction Profiled the inter path (stage_timing_breakdown_inter, 720p GOP): 403 of a 408ms motion-search bucket was crate::mc::predict, almost entirely from the search's own whole-pel log/diamond stage. SUBPEL_FILTERS[0] is the identity tap and both rounding shifts are exactly that filter's gain, so the two 8-tap passes reproduce the reference sample byte-for-byte at zero fraction (integer_mv_is_identity already pinned this) -- a clamped direct copy is bit-identical, not an approximation. Motion search bucket 408.55ms -> 181.85ms, frame total 818.88ms -> 585.24ms, same 997 output bytes.
perf(av1): stop repricing an inter block's chroma trial 13 times overAhmet Kaan Gümüş · cc09bf2
perf(av1): stop repricing an inter block's chroma trial 13 times over An inter frame's intra-candidate loop in search_inter_block always coded both chroma planes as DC_PRED, independent of which of the 13 luma modes the loop was on -- so the identical transform/quantize/coeff_bits call ran twelve times for nothing on every inter block. Hoist it out of the loop and clone the one result in (bit-identical: same call, same inputs, same output, verified by the full 129-test suite and an equal output byte count on the stage_timing_breakdown_inter probe, 1356 bytes before and after). Also add stage_timing_breakdown_inter, an #[ignore]d probe that breaks one inter frame's time into motion search / mc::predict / transform+ quantize / coeff_bits buckets, which is how this was found: transform+ quantize was the largest bucket (454.78ms of 980.36ms), not motion search (267.26ms, of which 257.01ms is genuine sub-pel interpolation work already spent inside the diamond search). 1280x720 inter frame: 980.36ms -> 772.05ms (-21%).
fix(av1): clamp inter MC reads to the reference's true extent, not its coding strideAhmet Kaan Gümüş · 8d520ef
fix(av1): clamp inter MC reads to the reference's true extent, not its coding stride sequence_round_trips_at_a_non_multiple_size (160x96) failed on inter-frame chroma/luma content: a spec decoder's reference buffer holds exactly FrameWidth x FrameHeight (mi_cols*4 x mi_rows*4) -- a superblock's partition stops early at has_cols/has_rows and never codes syntax for padding columns/rows beyond the true edge, so those samples are never part of the decoded picture. MC's Clip3 (spec 7.11.3.4) must clamp reference reads to that true extent, replicating the true edge, not to this crate's own padded-to-SUPERBLOCK coding surface. `mc::sample`/`mc::predict` used one width/height pair for both the buffer's row stride and the Clip3 clamp bound, conflating the two; split into a `stride` param (the buffer's real row length, unchanged) plus `true_width`/`true_height` (the clamp bound, now `Plane::true_width`/ `true_height` at the call site) threaded through `motion::search` and `encode::mc_trial`. Gate: 126 passed/1 failed/4 ignored -> 127 passed/0 failed/4 ignored.
2026-08-26
feat(av1): sub-pel motion compensation (spec 7.11.3, EIGHTTAP regular)Ahmet Kaan Gümüş · 082d993
feat(av1): sub-pel motion compensation (spec 7.11.3, EIGHTTAP regular) Two-stage separable 8-tap filter, InterRound0=3/InterRound1=11 for 8-bit non-compound per spec 7.11.3.2, edge samples clamped rather than read out of range. Not yet wired into encode.rs (later lane).