iter2 Fix 1: invalidate format cache on DestroyContext + REQBUFS(0) on CAPTURE in resolution-change path

Fix 1 of iteration 2 per phase4_iter2_plan.md.

Adds surface_reset_format_cache() exposed from src/surface.h. Called
from RequestDestroyContext after the dual REQBUFS(0). Without this,
multi-video Firefox sessions on mozilla.org corrupted the next
session's CAPTURE format query: the kernel reset to defaults but
our LAST_OUTPUT_WIDTH/HEIGHT cache still said 'already 1920x1088,'
so the next G_FMT returned 48x48 and the exported descriptor
encoded wrong pitch/offset.

Also adds REQBUFS(0) on CAPTURE in the resolution-change path of
RequestCreateSurfaces2 (Sonnet Phase 5 review iter2 9.1). The
existing code only did REQBUFS(0) on OUTPUT before re-S_FMTting;
hantro derives CAPTURE format from OUTPUT format, so leftover
CAPTURE buffers from the prior resolution would also block the
implicit format change. Pre-existing bug surfaced by Sonnet's
audit; Fix 3 pool refactor would have exposed it more often.

Limitation noted in surface.h docblock: the LAST_OUTPUT_WIDTH/
HEIGHT cache is a static process-global, so concurrent multi-
context use still races (Sonnet 7.3 / 9.6). Iteration 2 only
addresses sequential sessions. Multi-context safety is iteration 3+.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-04 19:11:03 +00:00
parent c036a44f98
commit 06beef6248
3 changed files with 50 additions and 4 deletions
+12
View File
@@ -248,5 +248,17 @@ VAStatus RequestDestroyContext(VADriverContextP context, VAContextID context_id)
if (rc < 0)
return VA_STATUS_ERROR_OPERATION_FAILED;
/*
* Iteration 2 Fix 1: the kernel CAPTURE format state is no longer
* guaranteed after the dual REQBUFS(0). Invalidate the
* LAST_OUTPUT_WIDTH/HEIGHT cache so the next CreateSurfaces2 will
* unconditionally re-S_FMT on OUTPUT. Without this, multi-video
* Firefox sessions on mozilla.org corrupted the next session's
* CAPTURE format query (kernel returned 48x48 instead of the
* cached "already 1920x1088"); the exported descriptor encoded
* wrong pitch/offset.
*/
surface_reset_format_cache();
return VA_STATUS_SUCCESS;
}