From e0104c45fd9db52ef3cac914ba05d960d154d513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 16:32:29 +0300 Subject: [PATCH] feat(av1): pre-deblock full-buffer oracle rung -- EC_AV1_PREFILT_WIDE_DUMP Rung 7: same anchor as the existing EC_AV1_PREFILT_DUMP (before loop filter/CDEF/superres), but dumps y_width/y_height (full aligned buffer) instead of y_crop_width/y_crop_height, so the margin region [FrameWidth, true mi-aligned width) is visible pre-deblock too -- separates a reconstruction bug in the margin from a deblock bug in the margin. Additive/new env var; the existing EC_AV1_PREFILT_DUMP rung other lanes already use is untouched. Rebuilt and verified clean. --- scripts/instrument-aom-oracle.sh | 85 ++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/scripts/instrument-aom-oracle.sh b/scripts/instrument-aom-oracle.sh index ab3c9d34..01771756 100755 --- a/scripts/instrument-aom-oracle.sh +++ b/scripts/instrument-aom-oracle.sh @@ -28,13 +28,16 @@ # read and the first coefficient block, which is precisely the gap a # rect-strip desync hides in. # EC_AV1_POSTDEBLOCK_DUMP= -> .f per frame, Y then U then -# V, full coded-width rows (cm->cur_frame->buf at this point is still -# the pre-superres, frame_width-wide buffer). Written right after -# av1_loop_filter_frame_mt returns and before CDEF/superres run -- -# ground truth for the post-deblock, pre-superres row content over -# frame_width..true_width that decode.rs stashes as its superres -# margin (lane-superres r5: hand-tracing the arithmetic could only -# prove our own self-consistency, not correctness against libaom). +# V, full ALIGNED-buffer rows (y_width/y_height, not y_crop_width -- +# cm->cur_frame->buf at this point is still the pre-superres buffer, +# but its aligned width already extends past FrameWidth out to the +# mi-aligned true width, which is exactly the margin content we need). +# Written right after av1_loop_filter_frame_mt returns and before +# CDEF/superres run -- ground truth for the post-deblock, pre-superres +# row content over frame_width..true_width that decode.rs stashes as +# its superres margin (lane-superres r5: hand-tracing the arithmetic +# could only prove our own self-consistency, not correctness against +# libaom). # # Idempotent: re-running is a no-op. Rebuild afterwards with # ninja -C ~/.cache/aom-oracle/build aomdec @@ -299,16 +302,20 @@ dump = """ FILE *ec_f = fopen(ec_path, "wb"); if (ec_f) { const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf; - for (int ec_r = 0; ec_r < ec_b->y_crop_height; ++ec_r) - fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, - ec_b->y_crop_width, ec_f); + /* Dump the FULL aligned buffer (y_width/y_height), not the + * crop_width/crop_height (== FrameWidth/FrameHeight): the + * superres margin (columns [FrameWidth, true mi-aligned width)) + * only exists in the aligned buffer -- lane-superres r5. */ + for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r) + fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width, + ec_f); if (num_planes > 1) { - for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r) + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1, - ec_b->uv_crop_width, ec_f); - for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r) + ec_b->uv_width, ec_f); + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1, - ec_b->uv_crop_width, ec_f); + ec_b->uv_width, ec_f); } fclose(ec_f); } @@ -320,3 +327,53 @@ s = s.replace(anchor, anchor + dump, 1) open(path, "w").write(s) print("postdeblock dump instrumented") PYD + +# --- rung 7: pre-deblock, FULL aligned-buffer row dump (lane-superres r5) - +# EC_AV1_PREFILT_DUMP (rung 1) is used by other lanes at its existing +# y_crop_width/y_crop_height shape -- left untouched. This adds a second, +# additive env var at the SAME anchor (pre-loop-filter) but dumping the full +# y_width/y_height aligned buffer, so a margin-region reconstruction bug can +# be told apart from a margin-region deblock bug. +python3 - "$F" <<'PYW' +import sys +path = sys.argv[1] +s = open(path).read() +if "EC_INSTRUMENTED_PREFILT_WIDE" in s: + print("prefilt-wide dump already instrumented (no-op)") + sys.exit(0) + +anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, + pbi->num_workers, 1);""" +dump = """ /* EC_INSTRUMENTED_PREFILT_WIDE */ + { + const char *ec_dump = getenv("EC_AV1_PREFILT_WIDE_DUMP"); + if (ec_dump) { + static int ec_prefilt_wide_idx = 0; + char ec_path[1024]; + snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, + ec_prefilt_wide_idx++); + FILE *ec_f = fopen(ec_path, "wb"); + if (ec_f) { + const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf; + for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r) + fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width, + ec_f); + if (num_planes > 1) { + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) + fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1, + ec_b->uv_width, ec_f); + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) + fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1, + ec_b->uv_width, ec_f); + } + fclose(ec_f); + } + } + } + +""" +assert anchor in s, "cdef alloc anchor moved" +s = s.replace(anchor, dump + anchor, 1) +open(path, "w").write(s) +print("prefilt-wide dump instrumented") +PYW