Commit Graph

2 Commits

Author SHA1 Message Date
claude-noether 656596aa6b iter3 Phase 5: sonnet review — 4 Critical findings, 4 amendments
Second-model review by sonnet-architect found 4 Critical bugs in
Phase 4 plan, all verified empirically by author before incorporation
per memory feedback_review_empirical_over_theoretical Direction 2.
Amendments applied in-place to phase4_iter3_plan.md +
phase2_iter3_situation.md.

Critical findings:

  C1 first_part_header_bits = 0 was claimed cosmetic; actually
     UNSAFE. hantro_g1_vp8_dec.c:260 + rockchip_vpu2_hw_vp8_dec.c:372
     both read this field unconditionally to compute the macroblock
     DMA offset. Setting 0 would place hardware at wrong DMA offset
     for ALL macroblock data → garbage decode.
     Fix: frame.first_part_header_bits = slice->macroblock_offset
     (verified by source identity — vaapi_vp8.c:204 and
     v4l2_request_vp8.c:83 use byte-identical formulas).

  C2 first_part_size = slice->partition_size[0] was wrong; VAAPI's
     partition_size[0] is the REMAINING bytes after parsing
     (vaapi_vp8.c:209 confirms; va_dec_vp8.h:193-196 spec confirms).
     Kernel needs the TOTAL control partition size.
     Fix: frame.first_part_size = slice->partition_size[0] +
                                  ((macroblock_offset + 7) / 8)
     Phase 3 keyframe numerics confirm: 21923 + 819 = 22742 ✓.

  C3 VAProbabilityDataBufferType does not exist as a buffer-type
     enum; it's the struct name. The actual enum constant is
     VAProbabilityBufferType (= 13 per va.h:2058). Switch case
     using the wrong identifier would have failed Phase 6 compile.
     Fix: replace globally in phase2 + phase4 docs.

  C4 (s8) cast undefined in userspace. Kernel has 's8' typedef in
     linux/types.h (kernel-internal). UAPI exposes '__s8' (double-
     underscore). Userspace portable cast is int8_t from <stdint.h>.
     Fix: replace (s8) with (int8_t) in Clauses 6+7.

Suggested:

  S3 Clause 8 comment was factually wrong: hantro_vp8.c::
     hantro_vp8_prob_update reads coeff_probs unconditionally;
     there is NO default-table fallback. If probability_set==false,
     decode produces garbage. Practical risk low (FFmpeg vaapi_vp8.c
     always sends VAProbabilityBufferType per frame), but corrected
     comment + added assert(probability_set) runtime guard for
     immediate Phase 6 surfacing.

Plus 5 minor S/Q items documented; non-blocking for iter3.

Author's 7 review questions all answered directly in the review:
  Q1 quantization derivation: correct for typical content
  Q2 first_part_header_bits=0 safety: UNSAFE → C1
  Q3 num_dct_parts off-by-one: confirmed correct
  Q4 field availability: 2 compile failures found (C3 + C4)
  Q5 quant_update[s] semantics: signed delta confirmed
  Q6 SHOW_FRAME unconditional: safe for BBB scope
  Q7 buffer order independence: confirmed

Estimated saving: 1 Phase 6 → Phase 4 loopback + 2 Phase 6 fix-
forward commits. Review pass is the right path forward per memory
rule "Reviews are never skippable" — empty-review value =
empirical-verification value, regardless of finding count.

Refs:
  phase4_iter3_plan.md (amended in-place; Phase 5 amendments
                         section appended)
  phase2_iter3_situation.md (amended C3 globally)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 21:27:53 +00:00
claude-noether 2918dda2e0 iter3 Phase 4: plan — 10 contract clauses, ~308-LOC patch, 3 commits
Locks the iter3 patch shape against Phase 3 verbatim cross-validator
payload + Phase 2 contract surface. 10 contract clauses cite kernel
UAPI + VAAPI + FFmpeg ref + Phase 3 byte anchors throughout.

Patch shape (mirrors iter1 ABCD pattern):

  Commit A: src/config.c — enumeration block + CreateConfig case +
            QueryConfigEntrypoints case (3 sites, +16 LOC, 1 file).
            After: vainfo lists VP8Version0_3.
  Commit B: NEW src/vp8.c (~200 LOC) + NEW src/vp8.h (~40 LOC) +
            meson.build sources/headers entries (+2). 3 files
            (2 new + 1 modified).
            After: vp8.o compiles standalone.
  Commit C: src/picture.c — codec_set_controls dispatch +
            codec_store_buffer 4 buffer-type cases + outer
            VAProbabilityDataBufferType case + BeginPicture
            per-frame reset (4 sites, +40 LOC) + src/surface.h
            params.vp8 union member (+10 LOC). 2 files modified.
            After: end-to-end VP8 decode through libva backend.

Total: ~308 LOC, 6 files (2 new + 4 modified), 3 commits.

Contract clauses summary:

  1. Submission shape — single VIDIOC_S_EXT_CTRLS, count=1, ctrl_class=
     V4L2_CTRL_CLASS_CODEC_STATELESS (0xf010000), id=0xa409c8,
     size=1232 bytes
  2. Local struct alloc + zero-init (memset clears all padding)
  3. Frame geometry + version + per-frame scalars (off-by-one
     num_dct_parts = num_of_partitions - 1)
  4. DPB timestamp resolution (3 refs: last/golden/alt; 0-sentinel
     when SURFACE() returns NULL — mirrors iter1 mpeg2.c pattern)
  5. Loop filter mapping (6 fields + 3 flag bits)
  6. Quantization base + delta derivation (segment 0 = base via
     iqmatrix[0][0]; deltas = iqmatrix[0][N+1] - iqmatrix[0][0]
     signed; per-segment quant_update[1..3] only when segmentation
     enabled)
  7. Segment fields (segment_probs direct copy; flags assembled +
     DELTA_VALUE_MODE set unconditionally per FFmpeg pattern)
  8. Entropy table mapping — 3 VAAPI sources (Picture: y_mode +
     uv_mode + mv_probs; ProbabilityData: coeff_probs[4][8][3][11]
     direct memcpy; IQMatrix: quant)
  9. Coder state + first-partition fields + flags (6 mainline-
     documented bits only; bit 0x40 + EXPERIMENTAL NOT replicated
     vs ffmpeg-v4l2-request-git anomaly; first_part_header_bits=0
     fallback documented as known fidelity gap)
  10. Final batched submission via v4l2_set_controls

Phase 5 review questions queued (7 items): quantization derivation
correctness, per-segment quant_update semantics, first_part_header_
bits=0 safety, probability buffer ordering, endianness, struct size
sizeof correctness, field-availability test-compile per memory
feedback_review_empirical_over_theoretical Direction 2.

Cross-cutting backlog deferred (B1, B3, B4, B5, B6, L3 inherited;
iter3-Q1 first_part_header_bits + iter3-flags 0x40 anomaly NEW).

Refs:
  phase0_findings_iter3.md (Phase 1 lock)
  phase2_iter3_situation.md (Phase 2 contract surface)
  phase3_iter3_baseline.md (Phase 3 verbatim payload anchors)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 20:39:52 +00:00