Skip to content

Commit

Permalink
vi: fix validator to correctly report the XSCALE bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Dec 9, 2024
1 parent f952ba5 commit c8d82cc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,27 @@ static void __vi_validate_config(void)
#endif

// Check for some common mistakes in VI configuration. Since they are based
// on VI_CTRL and VI_X_SCALE, do that only if they have been changed.
if (!(cfg_pending & ((1 << VI_TO_INDEX(VI_CTRL)) | (1 << VI_TO_INDEX(VI_X_SCALE)))))
// on VI_CTRL, VI_X_SCALE and VI_H_VIDEO, do that only if they have been changed.
if (!(cfg_pending & ((1 << VI_TO_INDEX(VI_CTRL)) |
(1 << VI_TO_INDEX(VI_X_SCALE)) |
(1 << VI_TO_INDEX(VI_H_VIDEO)))))
return;

uint32_t ctrl = vi_read(VI_CTRL);
uint32_t xscale = vi_read(VI_X_SCALE);
uint32_t hstart = vi_read(VI_H_VIDEO) >> 16;
bool bpp16 = (ctrl & VI_CTRL_TYPE) == VI_CTRL_TYPE_16_BPP;
bool dedither = ctrl & VI_DEDITHER_FILTER_ENABLE;
bool divot = ctrl & VI_DIVOT_ENABLE;
int mode = ctrl & VI_AA_MODE_MASK;

switch (mode) {
case VI_AA_MODE_NONE:
if (xscale <= 0x200 && bpp16)
debugf("VI WARNING: setting VI_AA_MODE_NONE with 16 bpp and VI_X_SCALE <= 0x200 (aka: framebuffer widths <= 320) can cause artifacts on NTSC\n");
if (xscale <= 0x200 && bpp16 && hstart <= 128) {
debugf("VI WARNING: setting VI_AA_MODE_NONE with 16 bpp, X_SCALE <= 0x200 and H_START <= 128 can cause visual artifacts\n");
debugf("A common scenario where this happens: NTSC units, with default output area, and 320x240 framebuffer.\n");
debugf("Possible workarounds: activate resampling with VI_AA_MODE_RESAMPLE, increase X_SCALE\n");
}
if (divot)
debugf("VI WARNING: divot filter is only useful when the AA filter is enabled\n");
break;
Expand Down

0 comments on commit c8d82cc

Please sign in to comment.