-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drm/vc4: Add support for scaled modes in VEC #4636
base: rpi-5.10.y
Are you sure you want to change the base?
Conversation
62abf84
to
f54340f
Compare
The Raspberry Pi firmware, when configured to output progressive composite video, scales 720x480/720x576 framebuffer into a 720x240/720x288 physical video mode. This commit adds support for replicating such behavior, as this provides square-ish virtual pixels, and some userland software rely on this. Signed-off-by: Mateusz Kwiatkowski <[email protected]>
Composite output uses non-square pixels. By allowing horizontally scaled modes, we can simulate a different pixel clock and thus make it possible to simulate square pixels at either 4:3 or 16:9 target aspect ratio. Signed-off-by: Mateusz Kwiatkowski <[email protected]>
f54340f
to
3c08549
Compare
I've rebased the code now that #4406 is merged. |
Any comments on this PR, @6by9 and @popcornmix ? I spotted a typo in the second commit message ( |
EDIT: Turns out, all works as expected. Previously it was not required adding |
@ToKe79 No problem. I only now got the time to look at it, but glad to hear the problem is solved :) |
Hey, I have a question. Could this be reimplemented for the newest update? It no longer has the fake 480p scaled to 240p |
I'd somehow totally missed this one, but it's been brought up through #6242. If I'm reading it correctly, you're effectively trying to hack the DRM mode around to influence the resolution that the framebuffer emulation ends up with. Planes and crtc modes then get unmangled to display the image. If so, then it's not the right approach. Thinking it through on #6242, I do wonder if there is an option of overriding DRM's fbdev framebuffer emulation to allow a configurable resolution and controlling where it is rendered on which displays. See that issue for further comments, but it just depends on how big the overall patch becomes. It's unlikely to be acceptable to mainline (they'll say that the client should just use the DRM APIs properly), but may be small enough to consider keeping downstream. |
@6by9 Yes, I think that's more or less it, although I'm not exactly an expert on the DRM architecture so I admit that I was working a little bit in the dark about what I'm actually doing 😅 Anyway, here's a little bit of rationale for why this PR was created:
So the tl;dr is that some software used to rely on settings available through firmware-based mode switching that is now impossible to replicate via DRM, at least not in a straightforward manner, and this PR introduces a way to do so. It is kludgy, it's a hack, it compensates for deficiencies in userland software in kernel mode, which makes it borderline evil, I can admit that myself. But it also improves compatibility with existing software. So... I can port this to the current branch, but I'd like your opinion on whether that's even something worth doing, and if so then whether to only support the progressive mode downscaling, or to retain the horizontal rescaling too. |
The first new commit in this PR adds support for recreating the "fake 480p/576p" mode that the Pi boots up with the firmware framebuffer when set to
sdtv_mode=16
/sdtv_mode=18
. This new mode is reported as720x480 (scaled)
/720x576 (scaled)
and is now the default whensdtv_mode=16
/sdtv_mode=18
is set inconfig.txt
(although it's chosen based on thevideo=
kernel command line option), to replicate the firmware behaviour. In this mode, the graphics are rendered in 720x480/720x576, but scaled to 240p/288p for display in the composite progressive mode.This closely replicates the firmware behaviour, with some differences: trapezoidal filtering is used for this scaling (as per
vc4_get_scaling_mode()
invc4_plane.c
), so the effect is that each two lines are averaged instead of every other one dropped - this actually improves image quality compared to the firmware mode; things that are separate DRM planes (like the X mouse cursor) may also be located a bit imprecisely on the screen - but that's generally not a problem in practice.This has already been accepted into Lakka (libretro's fork of LibreELEC), see libretro/Lakka-LibreELEC#1290, as it provides the preferred video mode for emulators in the KMS driver.
The second commit adds support for horizontal scaling, which makes aspect ratio correction possible. For example:
This modeline provides square (virtual) pixels for a 16:9 NTSC display. Note that it results in normal 13.5 MHz physical pixel clock (16.364 * 858 / 1040), but specifying this virtual pixel clock of 16.364 MHz makes the refresh rate display correctly in
xrandr
.I suppose that this PR might be controversial, and if you say that "scaling does not belong in the driver", then it's totally understandable and I won't push for this change. However, this replicates functionality that was there in the firmware and some software in the Pi ecosystem may rely on this kind of behaviour being available, so I thought it might be worth it to try offering this idea.