Skip to content

Commit

Permalink
Enable configuration of hardware IPU scaler 'filter' setting via menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgleaver committed Nov 25, 2020
1 parent a30897d commit c0b778c
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 13 deletions.
49 changes: 44 additions & 5 deletions src/port/sdl/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ static int videoscaling_alter(u32 keys)
}

static char *videoscaling_show() {
const char* str[] = {"hardware", "nearest"};
const char* str[] = {"hardware", "software"};
int vs = Config.VideoScaling;
if (vs < 0) vs = 0;
else if (vs > 1) vs = 1;
Expand All @@ -1533,7 +1533,7 @@ static char *videoscaling_show() {
static void videoscaling_hint() {
switch(Config.VideoScaling) {
case 0:
port_printf(4 * 8, 10 * 8, "Hardware scaling (fast)");
port_printf(4 * 8, 10 * 8, "Hardware IPU scaling (fast)");
break;
case 1:
port_printf(4 * 8, 10 * 8, "Software nearest-neighbour");
Expand All @@ -1543,7 +1543,8 @@ static void videoscaling_hint() {

#ifdef GCW_ZERO

extern void set_keep_aspect_ratio(bool n);
extern void set_ipu_keep_aspect_ratio(bool n);
extern void set_ipu_filter_type(enum ipu_filter_type filter_type);

static int VideoHwKeepAspect_alter(u32 keys)
{
Expand All @@ -1554,7 +1555,7 @@ static int VideoHwKeepAspect_alter(u32 keys)
if (Config.VideoHwKeepAspect == true) Config.VideoHwKeepAspect = false;
}
if (Config.VideoHwKeepAspect != last_keep_aspect) {
set_keep_aspect_ratio(Config.VideoHwKeepAspect);
set_ipu_keep_aspect_ratio(Config.VideoHwKeepAspect);
}
return 0;
}
Expand All @@ -1570,6 +1571,42 @@ static void VideoHwKeepAspect_hint() {
port_printf(4 * 8, 10 * 8, "Keep pixel aspect ratio (hardware)");
}

static int VideoHwFilter_alter(u32 keys)
{
enum ipu_filter_type last_filter_type = (enum ipu_filter_type)Config.VideoHwFilter;
if (keys & KEY_RIGHT) {
if (Config.VideoHwFilter < IPU_FILTER_NEAREST) Config.VideoHwFilter++;
} else if (keys & KEY_LEFT) {
if (Config.VideoHwFilter > IPU_FILTER_BICUBIC) Config.VideoHwFilter--;
}
if ((enum ipu_filter_type)Config.VideoHwFilter != last_filter_type) {
set_ipu_filter_type((enum ipu_filter_type)Config.VideoHwFilter);
}
return 0;
}

static char *VideoHwFilter_show()
{
static char buf[16] = "\0";
switch ((enum ipu_filter_type)Config.VideoHwFilter) {
case IPU_FILTER_BILINEAR:
sprintf(buf, "%s", "bilinear");
break;
case IPU_FILTER_NEAREST:
sprintf(buf, "%s", "nearest");
break;
case IPU_FILTER_BICUBIC:
default:
sprintf(buf, "%s", "bicubic");
break;
}
return buf;
}

static void VideoHwFilter_hint() {
port_printf(4 * 8, 10 * 8, "Image filtering method (hardware)");
}

#endif //GCW_ZERO

#endif //USE_GPULIB
Expand Down Expand Up @@ -1725,6 +1762,7 @@ static int gpu_settings_defaults()
Config.FrameSkip = FRAMESKIP_OFF;
Config.VideoScaling = 0;
Config.VideoHwKeepAspect = true;
Config.VideoHwFilter = (u8)IPU_FILTER_BICUBIC;

#ifdef GPU_UNAI
#ifndef USE_GPULIB
Expand All @@ -1750,7 +1788,8 @@ static MENUITEM gui_GPUSettingsItems[] = {
{(char *)"Frame skip ", NULL, &frameskip_alter, &frameskip_show, NULL},
{(char *)"Video Scaling ", NULL, &videoscaling_alter, &videoscaling_show, &videoscaling_hint},
#ifdef GCW_ZERO
{(char *)"Keep Aspect (HW) ", NULL, &VideoHwKeepAspect_alter, &VideoHwKeepAspect_show, &VideoHwKeepAspect_hint},
{(char *)"(HW) Keep Aspect ", NULL, &VideoHwKeepAspect_alter, &VideoHwKeepAspect_show, &VideoHwKeepAspect_hint},
{(char *)"(HW) Video Filter ", NULL, &VideoHwFilter_alter, &VideoHwFilter_show, &VideoHwFilter_hint},
#endif
#endif
#ifdef GPU_UNAI
Expand Down
73 changes: 65 additions & 8 deletions src/port/sdl/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,61 @@ void update_window_size(int w, int h, bool ntsc_fix);

#ifdef GCW_ZERO

#define DINGUX_KEEP_ASPECT_FILE "/sys/devices/platform/jz-lcd.0/keep_aspect_ratio"
#define DINGUX_KEEP_ASPECT_FILE "/sys/devices/platform/jz-lcd.0/keep_aspect_ratio"
#define DINGUX_SHARPNESS_UPSCALING_FILE "/sys/devices/platform/jz-lcd.0/sharpness_upscaling"
#define DINGUX_SHARPNESS_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/sharpness_downscaling"

void set_keep_aspect_ratio(bool n) {
void set_ipu_keep_aspect_ratio(bool n) {
FILE *keep_aspect_file = fopen(DINGUX_KEEP_ASPECT_FILE, "wb");
if (keep_aspect_file) {
fputs(n ? "1" : "0", keep_aspect_file);
fclose(keep_aspect_file);
}
}

void set_ipu_filter_type(enum ipu_filter_type filter_type)
{
/* Sharpness settings range is [0,32]
* - 0: nearest-neighbour
* - 1: bilinear
* - 2...32: bicubic (translating to a sharpness
* factor of -0.25..-4.0 internally)
* Default bicubic sharpness factor is
* (-0.125 * 8) = -1.0 */
const char *sharpness_str = "8";
FILE *sharpness_upscaling_file = NULL;
FILE *sharpness_downscaling_file = NULL;

/* Check filter type */
switch (filter_type) {
case IPU_FILTER_BILINEAR:
sharpness_str = "1";
break;
case IPU_FILTER_NEAREST:
sharpness_str = "0";
break;
case IPU_FILTER_BICUBIC:
default:
/* sharpness_str is already set to 8
* by default */
break;
}

/* Set upscaling sharpness */
sharpness_upscaling_file = fopen(DINGUX_SHARPNESS_UPSCALING_FILE, "wb");
if (sharpness_upscaling_file) {
fputs(sharpness_str, sharpness_upscaling_file);
fclose(sharpness_upscaling_file);
}

/* Set downscaling sharpness */
sharpness_downscaling_file = fopen(DINGUX_SHARPNESS_DOWNSCALING_FILE, "wb");
if (sharpness_downscaling_file) {
fputs(sharpness_str, sharpness_downscaling_file);
fclose(sharpness_downscaling_file);
}
}

#endif

static char *home = NULL;
Expand Down Expand Up @@ -195,9 +240,13 @@ static void pcsx4all_exit(void)

#ifdef GCW_ZERO
/* It is good manners to leave IPU scaling in
* the default 'keep aspect' state when quitting
* an application */
set_keep_aspect_ratio(true);
* the default state when quitting an application */
if (!Config.VideoHwKeepAspect) {
set_ipu_keep_aspect_ratio(true);
}
if ((enum ipu_filter_type)Config.VideoHwFilter != IPU_FILTER_BICUBIC) {
set_ipu_filter_type(IPU_FILTER_BICUBIC);
}
#endif

if (SDL_MUSTLOCK(screen))
Expand Down Expand Up @@ -422,6 +471,9 @@ int config_load(const char *diskname)
} else if (!strcmp(line, "VideoHwKeepAspect")) {
sscanf(arg, "%d", &value);
Config.VideoHwKeepAspect = value;
} else if (!strcmp(line, "VideoHwFilter")) {
sscanf(arg, "%d", &value);
Config.VideoHwFilter = value;
}
#ifdef SPU_PCSXREARMED
else if (!strcmp(line, "SpuUseInterpolation")) {
Expand Down Expand Up @@ -563,13 +615,15 @@ int config_save(const char *diskname)
"FrameLimit %d\n"
"FrameSkip %d\n"
"VideoScaling %d\n"
"VideoHwKeepAspect %d\n",
"VideoHwKeepAspect %d\n"
"VideoHwFilter %d\n",
CONFIG_VERSION, Config.Xa, Config.Mdec, Config.PsxAuto, Config.Cdda,
Config.HLE, Config.SlowBoot, Config.AnalogArrow, Config.AnalogMode, Config.MenuToggleCombo,
Config.RCntFix, Config.VSyncWA, Config.Cpu, Config.PsxType,
Config.McdSlot1, Config.McdSlot2, Config.SpuIrq, Config.SyncAudio,
Config.SpuUpdateFreq, Config.ForcedXAUpdates, Config.ShowFps,
Config.FrameLimit, Config.FrameSkip, Config.VideoScaling, Config.VideoHwKeepAspect);
Config.FrameLimit, Config.FrameSkip, Config.VideoScaling,
Config.VideoHwKeepAspect, Config.VideoHwFilter);

#ifdef SPU_PCSXREARMED
fprintf(f, "SpuUseInterpolation %d\n", spu_config.iUseInterpolation);
Expand Down Expand Up @@ -1163,6 +1217,7 @@ int main (int argc, char **argv)
Config.FrameSkip = FRAMESKIP_OFF;
Config.VideoScaling = 0;
Config.VideoHwKeepAspect = true;
Config.VideoHwFilter = (u8)IPU_FILTER_BICUBIC;

//zear - Added option to store the last visited directory.
strncpy(Config.LastDir, home, MAXPATHLEN); /* Defaults to home directory. */
Expand Down Expand Up @@ -1584,7 +1639,9 @@ int main (int argc, char **argv)

#ifdef GCW_ZERO
/* Apply hardware scaling 'keep aspect' setting */
set_keep_aspect_ratio(Config.VideoHwKeepAspect);
set_ipu_keep_aspect_ratio(Config.VideoHwKeepAspect);
/* Apply hardware scaling 'filter' setting */
set_ipu_filter_type((enum ipu_filter_type)Config.VideoHwFilter);
#endif

//NOTE: spu_pcsxrearmed will handle audio initialization
Expand Down
7 changes: 7 additions & 0 deletions src/port/sdl/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ INLINE int string_is_empty(const char *data)
int path_file_exists(const char *path);
void set_cdrom_name(const char *filepath);

enum ipu_filter_type
{
IPU_FILTER_BICUBIC = 0,
IPU_FILTER_BILINEAR = 1,
IPU_FILTER_NEAREST = 2
};

#define CONFIG_VERSION 0

void config_get_override_filename(const char *diskname, char *filename);
Expand Down
6 changes: 6 additions & 0 deletions src/psxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ typedef struct {
* false: Stretch to fill screen */
boolean VideoHwKeepAspect;

/* When using 'Hardware' video scaling:
* 0: IPU_FILTER_BICUBIC
* 1: IPU_FILTER_BILINEAR
* 2: IPU_FILTER_NEAREST */
u8 VideoHwFilter;

// Options for performance monitor
boolean PerfmonConsoleOutput;
boolean PerfmonDetailedStats;
Expand Down

0 comments on commit c0b778c

Please sign in to comment.