drm: align plane destination size to even pixels - #142
Conversation
PR Summary by QodoDRM: round plane destination rect to even pixels for RK3566/3568 VOP2
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Unconditional even-size rounding
|
| *dst_w = (uint32_t)(fit_w * out->video_scale_factor) & ~1u; | ||
| *dst_h = (uint32_t)(fit_h * out->video_scale_factor) & ~1u; | ||
| *dst_x = (out->video_crtc_width - (int)*dst_w) / 2; | ||
| *dst_y = (out->video_crtc_height - (int)*dst_h) / 2; |
There was a problem hiding this comment.
1. Unconditional even-size rounding 🐞 Bug ≡ Correctness
video_dst_rect() always rounds the fitted destination width/height down to even pixels, even when the fitted size equals the CRTC size and no downscaling is happening. On odd-sized modes (out->mode.hdisplay/vdisplay), this changes the requested plane size by 1px and can leave a 1px unused border / off-by-one centering compared to the pre-PR behavior.
Agent Prompt
### Issue description
`video_dst_rect()` unconditionally forces `dst_w`/`dst_h` to be even via `& ~1u`. This changes output geometry on odd-sized modes even when scaling isn’t happening (e.g., scale_factor==1.0 and aspect-fit yields the full mode size), shrinking by 1px.
### Issue Context
The PR’s motivation is to avoid RK3566/3568 VOP2 warnings when *scaling down* to an odd destination width. That constraint does not necessarily apply when no downscaling occurs.
### Fix Focus Areas
- src/drm.c[690-706]
### Suggested change
1. Compute the unaligned `dst_w_unaligned` / `dst_h_unaligned` first.
2. Apply even alignment only when the operation is actually downscaling for that dimension, e.g.:
- `if (dst_w_unaligned < src_w) dst_w_unaligned &= ~1u;`
- `if (dst_h_unaligned < src_h) dst_h_unaligned &= ~1u;`
(or, if the HW restriction is width-only, gate only width).
3. Keep centering based on the final aligned values.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
There was a problem hiding this comment.
Rechecked: this is addressed. video_dst_rect() now computes the unaligned dimensions first and only rounds the width down to an even value when w < src_w, i.e. during horizontal downscaling. Pass-through and upscaled odd-sized modes retain their original geometry, while the RK VOP2 downscaling constraint is still handled.
RK3566/3568 VOP2 Esmart/Smart windows cannot scale down to an odd destination width. When they are asked to, the driver shaves the pixel itself and logs [drm] vp0 Esmart0-win0 dsp_w[1843] MODE 2 == 1 at scale down mode on every atomic commit, so a running ground station floods dmesg at frame rate. An odd width is easy to hit: --video-scale 0.96 on a 1920 wide mode gives 1843, and the aspect fit alone yields 1905 for a 1920x1088 source even at scale factor 1.0. Both the video and the OSD plane are affected, since modeset_atomic_prepare_commit applies the scale factor to whatever plane it is handed. Round the destination width down to even in the shared helper both call sites now use. The two copies of the aspect-fit math were already meant to be identical, so this keeps them from drifting. The alignment is deliberately narrow. The driver gates the warning on actual_w > dsp_w and has no matching constraint on the destination height, so only a width that is actually being scaled down is touched. Shaving a pixel off an upscaled or 1:1 width, or off the height, would shrink the picture to no purpose -- a 1920x1088 source fitted to a 2560x1440 mode is upscaled to an odd 2541 and must stay there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2e9d3c6 to
c95f8ed
Compare
RK3566/3568 VOP2 Esmart/Smart windows cannot scale down to an odd destination width. When they are asked to, the driver shaves the pixel itself and logs
[drm] vp0 Esmart0-win0 dsp_w[1843] MODE 2 == 1 at scale down mode
on every atomic commit, so a running ground station floods dmesg at frame rate.
An odd width is easy to hit: --video-scale 0.96 on a 1920 wide mode gives 1843, and the aspect fit alone yields 1905 for a 1920x1088 source even at scale factor 1.0. Both the video and the OSD plane are affected, since modeset_atomic_prepare_commit applies the scale factor to whatever plane it is handed.
Round the destination width and height down to even in the shared helper both call sites now use. The two copies of the aspect-fit math were already meant to be identical, so this keeps them from drifting.