Repository navigation
Description
Describe the bug
For interlaced modes vc4_crtc_get_scanout_position() adds htotal / 2 to hpos when vc4_hvs_get_fifo_frame_count() is odd, "to correct for field offset in interlaced mode" (rpi-7.4.y d9a4bcd, vc4_crtc.c:155-161). On BCM2712 that count is SCALER6_DISPX_STATUS.FRCNT (vc4_hvs.c:828-829), and FRCNT is not reset by SCALER6_DISPX_CTRL0_RESET (vc6_hvs_init_channel, __vc6_hvs_stop_channel): it keeps counting across modesets. Its parity therefore has no fixed relation to the field, and per modeset the correction either cancels the one-line difference between the two fields or doubles it. The vblank timestamps of an interlaced mode then alternate by two line periods in some modesets and are steady in others.
Steps to reproduce the behaviour
Pi 5, HDMI-A-1, bare KMS, a sink that takes interlaced CEA modes (I added VICs 5, 20, 6, 21 to the monitor's EDID through edid_override).
modetest -M vc4 -s <conn>@<crtc>:1920x1080i(and the other three modes), held.- 620 consecutive
DRM_IOCTL_WAIT_VBLANK(relative 1) replies; take the median of |dt(i) − dt(i+1)| over adjacent intervals. - Repeat with a fresh modeset per mode. Three runs of the four modes (µs):
| run | 1080i60 | 1080i50 | 480i | 576i |
|---|---|---|---|---|
| 1 | 1 | 0 | 1 | 1 |
| 2 | 59 | 71 | 127 | 128 |
| 3 | 60 | 71 | 127 | 128 |
59 / 71 / 127 / 128 µs = 2 · htotal / clock of the four modes. The PV interrupt rate and the DRM vblank counter matched the field rate in every run; only the timestamps are affected.
Expected: a steady field period in every modeset.
Device (s)
Raspberry Pi 5
System
Raspberry Pi 5 Model B Rev 1.1 (BCM2712 D0), 16 GB, two HDMI monitors.
- OS: Debian GNU/Linux 13 (trixie), image "Raspberry Pi reference 2026-04-21" (pi-gen 4ad56cc850fa60adcc7f07dc15879bc95cc1d281, stage4)
- Firmware:
vcgencmd version→ 2026/10/30 20:55:54, version 42d1b6a9 (release) (embedded) - Kernel:
Linux 7.4.0-rc2-v8-16k-rust+ #2 SMP PREEMPT aarch64— built by me from rpi-7.4.y d9a4bcd (bcm2712 defconfig + CONFIG_RUST, 16K pages);drivers/gpu/drm/vc4is unmodified in that build
Logs
run 1: V5:A=1.0µs V20:A=0.0µs V6:A=1.0µs V21:A=1.0µs
run 2: V5:A=59.0µs(n=621,pairs=619) V20:A=71.0µs(n=621,pairs=619) V6:A=127.0µs(n=621,pairs=619) V21:A=128.0µs(n=621,pairs=619)
run 3: V5:A=60.0µs(n=621,pairs=619) V20:A=71.0µs(n=621,pairs=619) V6:A=127.0µs(n=621,pairs=619) V21:A=128.0µs(n=621,pairs=619)
Additional context
What works here: take the field from SCALER6_DISPX_STATUS_OFIELD of the status word the function has already read, instead of FRCNT parity, on vc4->gen >= VC4_GEN_6_C:
if (vc4->gen >= VC4_GEN_6_C)
odd = !(val & SCALER6_DISPX_STATUS_OFIELD);
else
odd = vc4_hvs_get_fifo_frame_count(hvs, channel) % 2;
if (odd)
*hpos += mode->crtc_htotal / 2;With that the same test reads 0–1 µs in 12 of 12 modesets on the same kernel. The polarity (half a line when OFIELD reads clear) is empirical: at the vblank interrupt the HVS seems to still report the field that has just ended.
Questions for someone with the HVS documentation: is FRCNT meant to survive CTRL0_RESET, and is this the right reading of OFIELD? Does the same apply to SCALER_DISPSTATX on the older HVS? (Not measured; the change above leaves it alone.)
I intend to send the patch to dri-devel for mainline as well (the code is the same there since 7687a12). The measurements were taken on my own Pi 5.
Activity
popcornmix commentedon Nov 16, 2026
@njhollinghurst
6by9 commentedon Nov 16, 2026
The docs describe FRCNT as
That is consistent across all generations. There are no statements over when it gets reset.
Seeing as we're wanting to know the field, using the FIELD register would make sense.
It exists on GEN4 and GEN5 in SCALER_DISPSTAT[012] as bit 27.
GEN6 you've already found as SCALER6_DISPX_STATUS_OFIELD.
In all cases, 1=odd field, and 0=even field.
Just a thought, on GEN4 or 5, if the output is to the VEC, then NTSC is odd-field first. Should that be handled in this fixup? AIUI HDMI is always even field first, so it doesn't matter there. GEN6 HVS only drives HDMI, so it's not an issue there.
The existing
vc4_hvs_get_fifo_frame_countfunction is also used by the downstream patches for handling stale dlist entries, so it'd be appreciated to avoid modifying that function.ARFARAR commentedon Nov 16, 2026
Thanks. The change does not touch
vc4_hvs_get_fifo_frame_count();vc4_crtc_get_scanout_position()just stops calling it and takes the field from the status word it already reads.Extended as you suggest:
SCALER_DISPSTATX, GEN6 uses OFIELD.odd_field_firstvc4_crtc_config_pv()delays the even field instead of the odd one, so the correction is inverted whenPV_VCONTROL_ODD_FIRSTis set. That is one extra PV read per query; a flag stored at modeset would do as well.The only hardware I have for testing is a Raspberry Pi 5 16GB, Rev 1.1 (e04171). With this diff on rpi-7.4.y d9a4bcd the GEN6 path gives 1 us in 12 of 12 interlaced modesets (1080i60, 1080i50, 480i, 576i, three runs). The GEN4/5 and VEC paths are compiled only.
Can someone with a Pi 4 and composite out check the GEN4/5 + VEC part?
popcornmix commentedon Nov 16, 2026
@ARFARAR Thanks for the detailed report. I can reproduce this on Pi 5, Pi 4 and Pi 3B+. The frame counter is free running on all generations, and the earlier HVS has the same field bit (
SCALER_DISPSTATXbit 27). Your inverted polarity is correct on all three, including Pi 4 composite NTSC (odd field first). #7763 applies your fix to all generations.Can you wait about 40 minutes for CI to complete, then run
sudo rpi-update pulls/7763and test if that fix works.Read the rpi-update caveats first.
popcornmix commentedon Nov 16, 2026
We overlapped - but claude came up with a very similar fix to your proposal.
(I did test it on pi3, 4 and 5, hdmi and composite).
ARFARAR commentedon Nov 16, 2026
Tested the code of #7763 (a0b561d) on a Pi 5 16GB, Rev 1.1 (e04171). The board runs a self-built rpi-7.4.y d9a4bcd kernel, so instead of rpi-update I applied the PR's diff to that tree and built vc4 as a module.
The vblank timestamp intervals are steady, 1 us, in 12 of 12 interlaced modesets (1080i60, 1080i50, 480i, 576i, three runs). The stock module was off by two lines in 8 of 12.
The ODD_FIRST inversion in my diff above was a guess from the code; your composite NTSC result shows it is not needed.
No surprise that Claude landed on a similar fix. This issue came out of my research project: with Claude's assistance I have rewritten the Pi 5 graphics and video drivers in Rust, as out-of-tree modules that replace vc4, v3d, bcm2712-iommu and rpi_hevc_dec (with thin C shims where the kernel has no Rust API yet).
ARFARAR commentedon Nov 16, 2026
Also tested the CI build itself:
rpi-update pulls/7763(a0b561d, 6.18.62-v8-16k+) on the same Pi 5, stock vc4 from that build. 0-1 us in 12 of 12 interlaced modesets (1080i60, 1080i50, 480i, 576i, three runs). The fix works.drm/vc4: Use the HVS field bit for interlaced scanout position
drm/vc4: Use the HVS field bit for interlaced scanout position
drm/vc4: Use the HVS field bit for interlaced scanout position