Skip to content

Commit

Permalink
Display: Allow unthrottle to skip only flipping.
Browse files Browse the repository at this point in the history
Before, it either flipped continuously, or forced frameskip on.  This
makes it so you can still draw frames, but skip actual flips.

This is useful when games draw things only in a single frame and reuse
later.  It's also useful when measuring speed improvements if you already
get 100% speed on a device.
  • Loading branch information
unknownbrackets committed May 24, 2020
1 parent 8fa84fd commit e062a12
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
30 changes: 26 additions & 4 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ static int DefaultInternalResolution() {
#endif
}

static bool DefaultFrameskipUnthrottle() {
static int DefaultUnthrottleMode() {
#if !PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(UWP)
return true;
return (int)UnthrottleMode::SKIP_DRAW;
#else
return false;
return (int)UnthrottleMode::CONTINUOUS;
#endif
}

Expand Down Expand Up @@ -704,6 +704,28 @@ struct ConfigTranslator {

typedef ConfigTranslator<GPUBackend, GPUBackendToString, GPUBackendFromString> GPUBackendTranslator;

static int UnthrottleModeFromString(const std::string &s) {
if (!strcasecmp(s.c_str(), "CONTINUOUS"))
return (int)UnthrottleMode::CONTINUOUS;
if (!strcasecmp(s.c_str(), "SKIP_DRAW"))
return (int)UnthrottleMode::SKIP_DRAW;
if (!strcasecmp(s.c_str(), "SKIP_FLIP"))
return (int)UnthrottleMode::SKIP_FLIP;
return DefaultUnthrottleMode();
}

std::string UnthrottleModeToString(int v) {
switch (UnthrottleMode(v)) {
case UnthrottleMode::CONTINUOUS:
return "CONTINUOUS";
case UnthrottleMode::SKIP_DRAW:
return "SKIP_DRAW";
case UnthrottleMode::SKIP_FLIP:
return "SKIP_FLIP";
}
return "CONTINUOUS";
}

static ConfigSetting graphicsSettings[] = {
ConfigSetting("EnableCardboardVR", &g_Config.bEnableCardboardVR, false, true, true),
ConfigSetting("CardboardScreenSize", &g_Config.iCardboardScreenSize, 50, true, true),
Expand Down Expand Up @@ -733,7 +755,7 @@ static ConfigSetting graphicsSettings[] = {
ReportedConfigSetting("AutoFrameSkip", &g_Config.bAutoFrameSkip, false, true, true),
ConfigSetting("FrameRate", &g_Config.iFpsLimit1, 0, true, true),
ConfigSetting("FrameRate2", &g_Config.iFpsLimit2, -1, true, true),
ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, &DefaultFrameskipUnthrottle, true, false),
ConfigSetting("UnthrottleMode", &g_Config.iUnthrottleMode, &DefaultUnthrottleMode, &UnthrottleModeToString, &UnthrottleModeFromString, true, true),
#if defined(USING_WIN_UI)
ConfigSetting("RestartRequired", &g_Config.bRestartRequired, false, false),
#endif
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ struct Config {
bool bVSync;
int iFrameSkip;
int iFrameSkipType;
int iUnthrottleMode; // See UnthrottleMode in ConfigValues.h.
bool bAutoFrameSkip;
bool bFrameSkipUnthrottle;

bool bEnableCardboardVR; // Cardboard Master Switch
int iCardboardScreenSize; // Screen Size (in %)
Expand Down
6 changes: 6 additions & 0 deletions Core/ConfigValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ enum class AutoLoadSaveState {
OLDEST = 1,
NEWEST = 2,
};

enum class UnthrottleMode {
CONTINUOUS = 0,
SKIP_DRAW = 1,
SKIP_FLIP = 2,
};
20 changes: 17 additions & 3 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ static void DoFrameTiming(bool &throttle, bool &skipFrame, float timestep) {
// we have nothing to do here.
bool doFrameSkip = g_Config.iFrameSkip != 0;

bool unthrottleNeedsSkip = g_Config.bFrameSkipUnthrottle;
bool unthrottleNeedsSkip = g_Config.iUnthrottleMode == (int)UnthrottleMode::SKIP_DRAW;
if (g_Config.bVSync && GetGPUBackend() == GPUBackend::VULKAN) {
// Vulkan doesn't support the interval setting, so we force frameskip.
unthrottleNeedsSkip = true;
Expand Down Expand Up @@ -755,7 +755,8 @@ void __DisplayFlip(int cyclesLate) {
const ShaderInfo *shaderInfo = g_Config.sPostShaderName == "Off" ? nullptr : GetPostShaderInfo(g_Config.sPostShaderName);
bool postEffectRequiresFlip = false;
// postEffectRequiresFlip is not compatible with frameskip unthrottling, see #12325.
if (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE && !(g_Config.bFrameSkipUnthrottle && !FrameTimingThrottled())) {
bool unthrottleSkips = g_Config.iUnthrottleMode != (int)UnthrottleMode::CONTINUOUS;
if (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE && !(unthrottleSkips && !FrameTimingThrottled())) {
if (shaderInfo) {
postEffectRequiresFlip = (shaderInfo->requires60fps || g_Config.bRenderDuplicateFrames);
} else {
Expand Down Expand Up @@ -784,11 +785,24 @@ void __DisplayFlip(int cyclesLate) {
hasNotifiedSlow = true;
}

bool forceNoFlip = false;
// Alternative to frameskip unthrottle, where we draw everything.
// Useful if skipping a frame breaks graphics or for checking drawing speed.
if (g_Config.iUnthrottleMode == (int)UnthrottleMode::SKIP_FLIP && !FrameTimingThrottled()) {
static double lastFlip = 0;
double now = time_now_d();
if ((now - lastFlip) < 1.0f / System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE)) {
forceNoFlip = true;
} else {
lastFlip = now;
}
}

// Setting CORE_NEXTFRAME causes a swap.
const bool fbReallyDirty = gpu->FramebufferReallyDirty();
if (fbReallyDirty || noRecentFlip || postEffectRequiresFlip) {
// Check first though, might've just quit / been paused.
if (coreState == CORE_RUNNING) {
if (coreState == CORE_RUNNING && !forceNoFlip) {
coreState = CORE_NEXTFRAME;
gpu->CopyDisplayToOutput(fbReallyDirty);
if (fbReallyDirty) {
Expand Down
2 changes: 1 addition & 1 deletion headless/Headless.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ int main(int argc, const char* argv[])
g_Config.iButtonPreference = PSP_SYSTEMPARAM_BUTTON_CROSS;
g_Config.iLockParentalLevel = 9;
g_Config.iInternalResolution = 1;
g_Config.bFrameSkipUnthrottle = false;
g_Config.iUnthrottleMode = (int)UnthrottleMode::CONTINUOUS;
g_Config.bEnableLogging = fullLog;
g_Config.iNumWorkerThreads = 1;
g_Config.bSoftwareSkinning = true;
Expand Down
2 changes: 1 addition & 1 deletion libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void retro_init(void) {
#endif

g_Config.bEnableLogging = true;
g_Config.bFrameSkipUnthrottle = false;
g_Config.iUnthrottleMode = (int)UnthrottleMode::CONTINUOUS;
g_Config.bMemStickInserted = PSP_MEMORYSTICK_STATE_INSERTED;
g_Config.iGlobalVolume = VOLUME_MAX - 1;
g_Config.iAltSpeedVolume = -1;
Expand Down

0 comments on commit e062a12

Please sign in to comment.