2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include <vector>
|
2013-09-04 06:35:39 +00:00
|
|
|
#include <map>
|
2012-11-26 16:35:08 +00:00
|
|
|
#include <cmath>
|
2013-11-12 23:37:06 +00:00
|
|
|
#include <algorithm>
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-01 07:52:10 +00:00
|
|
|
// TODO: Move this somewhere else, cleanup.
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-23 09:33:19 +00:00
|
|
|
// TODO: Move the relevant parts into common. Don't want the core
|
|
|
|
// to be dependent on "native", I think. Or maybe should get rid of common
|
|
|
|
// and move everything into native...
|
2013-08-15 23:00:26 +00:00
|
|
|
#include "base/logging.h"
|
2012-11-23 09:33:19 +00:00
|
|
|
#include "base/timeutil.h"
|
2015-07-03 19:05:08 +00:00
|
|
|
#include "profiler/profiler.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2015-09-06 10:23:14 +00:00
|
|
|
#include "gfx_es2/gpu_features.h"
|
2013-10-25 03:00:38 +00:00
|
|
|
|
2013-12-29 22:28:31 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2013-07-29 15:09:33 +00:00
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
#include "Core/CoreParameter.h"
|
2013-05-05 06:35:46 +00:00
|
|
|
#include "Core/Reporting.h"
|
2013-07-29 15:09:33 +00:00
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/HLE/HLE.h"
|
2014-03-15 18:22:19 +00:00
|
|
|
#include "Core/HLE/FunctionWrappers.h"
|
2013-07-29 15:09:33 +00:00
|
|
|
#include "Core/HLE/sceDisplay.h"
|
|
|
|
#include "Core/HLE/sceKernel.h"
|
|
|
|
#include "Core/HLE/sceKernelThread.h"
|
|
|
|
#include "Core/HLE/sceKernelInterrupt.h"
|
|
|
|
|
2015-07-26 20:38:40 +00:00
|
|
|
#include "GPU/GPU.h"
|
2013-07-29 15:09:33 +00:00
|
|
|
#include "GPU/GPUState.h"
|
|
|
|
#include "GPU/GPUInterface.h"
|
2015-02-09 22:10:57 +00:00
|
|
|
#include "GPU/Common/FramebufferCommon.h"
|
2012-11-18 12:04:49 +00:00
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
struct FrameBufferState {
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 topaddr;
|
2013-07-29 15:09:33 +00:00
|
|
|
GEBufferFormat pspFramebufFormat;
|
2012-11-01 15:19:01 +00:00
|
|
|
int pspFramebufLinesize;
|
|
|
|
};
|
|
|
|
|
2015-07-24 19:48:39 +00:00
|
|
|
struct WaitVBlankInfo {
|
2013-02-11 03:02:00 +00:00
|
|
|
WaitVBlankInfo(u32 tid) : threadID(tid), vcountUnblock(1) {}
|
|
|
|
WaitVBlankInfo(u32 tid, int vcount) : threadID(tid), vcountUnblock(vcount) {}
|
2013-09-08 05:31:22 +00:00
|
|
|
SceUID threadID;
|
2013-09-04 06:22:56 +00:00
|
|
|
// Number of vcounts to block for.
|
|
|
|
int vcountUnblock;
|
2013-02-04 09:39:52 +00:00
|
|
|
|
2015-07-24 19:48:39 +00:00
|
|
|
void DoState(PointerWrap &p) {
|
2013-09-15 03:23:03 +00:00
|
|
|
auto s = p.Section("WaitVBlankInfo", 1);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2013-02-04 09:39:52 +00:00
|
|
|
p.Do(threadID);
|
|
|
|
p.Do(vcountUnblock);
|
|
|
|
}
|
2012-12-28 10:22:39 +00:00
|
|
|
};
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// STATE BEGIN
|
|
|
|
static FrameBufferState framebuf;
|
|
|
|
static FrameBufferState latchedFramebuf;
|
|
|
|
static bool framebufIsLatched;
|
|
|
|
|
|
|
|
static int enterVblankEvent = -1;
|
|
|
|
static int leaveVblankEvent = -1;
|
2013-02-18 22:25:06 +00:00
|
|
|
static int afterFlipEvent = -1;
|
2014-06-01 07:52:10 +00:00
|
|
|
static int lagSyncEvent = -1;
|
|
|
|
|
|
|
|
static double lastLagSync = 0.0;
|
|
|
|
static bool lagSyncScheduled = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-03-06 19:29:40 +00:00
|
|
|
// hCount is computed now.
|
2012-12-23 10:16:32 +00:00
|
|
|
static int vCount;
|
2013-09-03 07:09:50 +00:00
|
|
|
// The "AccumulatedHcount" can be adjusted, this is the base.
|
2013-11-18 16:12:49 +00:00
|
|
|
static u32 hCountBase;
|
2012-12-23 10:16:32 +00:00
|
|
|
static int isVblank;
|
2013-02-18 22:44:32 +00:00
|
|
|
static int numSkippedFrames;
|
2012-12-23 10:16:32 +00:00
|
|
|
static bool hasSetMode;
|
2013-04-30 13:29:18 +00:00
|
|
|
static int resumeMode;
|
|
|
|
static int holdMode;
|
2014-02-04 14:22:06 +00:00
|
|
|
static int brightnessLevel;
|
2013-03-05 13:31:13 +00:00
|
|
|
static int mode;
|
|
|
|
static int width;
|
|
|
|
static int height;
|
2014-06-14 22:03:55 +00:00
|
|
|
static bool wasPaused;
|
2014-06-14 21:55:16 +00:00
|
|
|
|
2014-06-26 07:36:17 +00:00
|
|
|
// 1.001f to compensate for the classic 59.94 NTSC framerate that the PSP seems to have.
|
|
|
|
static const double timePerVblank = 1.001f / 60.0f;
|
|
|
|
|
2013-02-12 09:23:05 +00:00
|
|
|
// Don't include this in the state, time increases regardless of state.
|
2013-02-18 23:44:22 +00:00
|
|
|
static double curFrameTime;
|
2014-06-26 07:36:17 +00:00
|
|
|
static double lastFrameTime;
|
2013-02-18 23:44:22 +00:00
|
|
|
static double nextFrameTime;
|
2013-08-07 21:32:28 +00:00
|
|
|
static int numVBlanksSinceFlip;
|
2012-11-19 13:16:37 +00:00
|
|
|
|
2013-03-06 19:29:40 +00:00
|
|
|
static u64 frameStartTicks;
|
2013-11-18 16:12:49 +00:00
|
|
|
const int hCountPerVblank = 286;
|
2013-03-21 21:59:46 +00:00
|
|
|
|
2014-04-25 20:41:01 +00:00
|
|
|
const int PSP_DISPLAY_MODE_LCD = 0;
|
2013-03-06 19:29:40 +00:00
|
|
|
|
2012-12-28 10:22:39 +00:00
|
|
|
std::vector<WaitVBlankInfo> vblankWaitingThreads;
|
2013-09-04 06:35:39 +00:00
|
|
|
// Key is the callback id it was for, or if no callback, the thread id.
|
|
|
|
// Value is the goal vcount number (in case the callback takes >= 1 vcount to return.)
|
|
|
|
std::map<SceUID, int> vblankPausedWaits;
|
2012-12-28 10:22:39 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// STATE END
|
2012-11-19 13:16:37 +00:00
|
|
|
|
2012-12-28 10:22:39 +00:00
|
|
|
// Called when vblank happens (like an internal interrupt.) Not part of state, should be static.
|
2012-12-02 23:44:23 +00:00
|
|
|
std::vector<VblankCallback> vblankListeners;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// The vblank period is 731.5 us (0.7315 ms)
|
|
|
|
const double vblankMs = 0.7315;
|
2013-11-18 16:06:09 +00:00
|
|
|
const double frameMs = 1001.0 / 60.0;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
enum {
|
2012-11-19 13:16:37 +00:00
|
|
|
PSP_DISPLAY_SETBUF_IMMEDIATE = 0,
|
2012-11-01 15:19:01 +00:00
|
|
|
PSP_DISPLAY_SETBUF_NEXTFRAME = 1
|
|
|
|
};
|
|
|
|
|
2013-05-20 03:20:41 +00:00
|
|
|
static int lastFpsFrame = 0;
|
|
|
|
static double lastFpsTime = 0.0;
|
|
|
|
static double fps = 0.0;
|
|
|
|
static double fpsHistory[120];
|
|
|
|
static size_t fpsHistoryPos = 0;
|
|
|
|
static size_t fpsHistoryValid = 0;
|
2013-06-17 06:44:11 +00:00
|
|
|
static int lastNumFlips = 0;
|
|
|
|
static float flips = 0.0f;
|
2013-08-19 20:05:55 +00:00
|
|
|
static int actualFlips = 0; // taking frameskip into account
|
|
|
|
static int lastActualFlips = 0;
|
|
|
|
static float actualFps = 0;
|
2013-06-30 03:16:09 +00:00
|
|
|
static u64 lastFlipCycles = 0;
|
2013-08-27 03:12:26 +00:00
|
|
|
// For the "max 60 fps" setting.
|
|
|
|
static int lastFlipsTooFrequent = 0;
|
2013-05-20 03:20:41 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
void hleEnterVblank(u64 userdata, int cyclesLate);
|
|
|
|
void hleLeaveVblank(u64 userdata, int cyclesLate);
|
2013-02-18 22:25:06 +00:00
|
|
|
void hleAfterFlip(u64 userdata, int cyclesLate);
|
2014-06-01 07:52:10 +00:00
|
|
|
void hleLagSync(u64 userdata, int cyclesLate);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-09-04 06:35:39 +00:00
|
|
|
void __DisplayVblankBeginCallback(SceUID threadID, SceUID prevCallbackId);
|
|
|
|
void __DisplayVblankEndCallback(SceUID threadID, SceUID prevCallbackId);
|
2013-12-02 16:24:20 +00:00
|
|
|
int __DisplayGetFlipCount() { return actualFlips; }
|
|
|
|
int __DisplayGetVCount() { return vCount; }
|
2013-09-04 06:35:39 +00:00
|
|
|
|
2014-06-01 23:20:58 +00:00
|
|
|
static void ScheduleLagSync(int over = 0) {
|
2014-06-01 07:52:10 +00:00
|
|
|
lagSyncScheduled = g_Config.bForceLagSync;
|
|
|
|
if (lagSyncScheduled) {
|
2014-06-24 15:27:21 +00:00
|
|
|
CoreTiming::ScheduleEvent(usToCycles(1000 + over), lagSyncEvent, 0);
|
|
|
|
lastLagSync = real_time_now();
|
2014-06-01 07:52:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void __DisplayInit() {
|
2013-08-07 20:32:04 +00:00
|
|
|
gpuStats.Reset();
|
2012-11-19 23:31:19 +00:00
|
|
|
hasSetMode = false;
|
2013-03-05 13:31:13 +00:00
|
|
|
mode = 0;
|
2013-04-30 13:29:18 +00:00
|
|
|
resumeMode = 0;
|
|
|
|
holdMode = 0;
|
2014-02-04 14:22:06 +00:00
|
|
|
brightnessLevel = 100;
|
2013-03-05 13:31:13 +00:00
|
|
|
width = 480;
|
|
|
|
height = 272;
|
2013-02-18 22:44:32 +00:00
|
|
|
numSkippedFrames = 0;
|
2013-08-07 21:32:28 +00:00
|
|
|
numVBlanksSinceFlip = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
framebufIsLatched = false;
|
|
|
|
framebuf.topaddr = 0x04000000;
|
2013-07-29 15:09:33 +00:00
|
|
|
framebuf.pspFramebufFormat = GE_FORMAT_8888;
|
2012-11-01 15:19:01 +00:00
|
|
|
framebuf.pspFramebufLinesize = 480; // ??
|
2015-03-28 20:01:30 +00:00
|
|
|
memset(&latchedFramebuf, 0, sizeof(latchedFramebuf));
|
2013-06-30 03:16:09 +00:00
|
|
|
lastFlipCycles = 0;
|
2013-08-27 03:12:26 +00:00
|
|
|
lastFlipsTooFrequent = 0;
|
2014-06-26 07:36:17 +00:00
|
|
|
wasPaused = false;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
enterVblankEvent = CoreTiming::RegisterEvent("EnterVBlank", &hleEnterVblank);
|
|
|
|
leaveVblankEvent = CoreTiming::RegisterEvent("LeaveVBlank", &hleLeaveVblank);
|
2013-02-18 22:25:06 +00:00
|
|
|
afterFlipEvent = CoreTiming::RegisterEvent("AfterFlip", &hleAfterFlip);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-06-01 07:52:10 +00:00
|
|
|
lagSyncEvent = CoreTiming::RegisterEvent("LagSync", &hleLagSync);
|
|
|
|
ScheduleLagSync();
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
CoreTiming::ScheduleEvent(msToCycles(frameMs - vblankMs), enterVblankEvent, 0);
|
|
|
|
isVblank = 0;
|
2015-03-28 20:01:30 +00:00
|
|
|
frameStartTicks = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
vCount = 0;
|
2013-11-18 16:12:49 +00:00
|
|
|
hCountBase = 0;
|
2013-02-18 23:44:22 +00:00
|
|
|
curFrameTime = 0.0;
|
|
|
|
nextFrameTime = 0.0;
|
2014-06-26 07:36:17 +00:00
|
|
|
lastFrameTime = 0.0;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-19 20:05:55 +00:00
|
|
|
flips = 0;
|
|
|
|
fps = 0.0;
|
|
|
|
actualFlips = 0;
|
|
|
|
lastActualFlips = 0;
|
|
|
|
lastNumFlips = 0;
|
|
|
|
fpsHistoryValid = 0;
|
2013-05-20 03:20:41 +00:00
|
|
|
fpsHistoryPos = 0;
|
|
|
|
|
2013-09-04 06:35:39 +00:00
|
|
|
__KernelRegisterWaitTypeFuncs(WAITTYPE_VBLANK, __DisplayVblankBeginCallback, __DisplayVblankEndCallback);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 10:22:39 +00:00
|
|
|
void __DisplayDoState(PointerWrap &p) {
|
2014-12-09 05:18:56 +00:00
|
|
|
auto s = p.Section("sceDisplay", 1, 6);
|
2013-09-15 03:23:03 +00:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
2012-12-28 10:22:39 +00:00
|
|
|
p.Do(framebuf);
|
|
|
|
p.Do(latchedFramebuf);
|
|
|
|
p.Do(framebufIsLatched);
|
2013-03-06 19:29:40 +00:00
|
|
|
p.Do(frameStartTicks);
|
2012-12-28 10:22:39 +00:00
|
|
|
p.Do(vCount);
|
2013-11-18 16:12:49 +00:00
|
|
|
if (s <= 2) {
|
|
|
|
double oldHCountBase;
|
|
|
|
p.Do(oldHCountBase);
|
|
|
|
hCountBase = (int) oldHCountBase;
|
|
|
|
} else {
|
|
|
|
p.Do(hCountBase);
|
|
|
|
}
|
2012-12-28 10:22:39 +00:00
|
|
|
p.Do(isVblank);
|
|
|
|
p.Do(hasSetMode);
|
2013-03-05 13:31:13 +00:00
|
|
|
p.Do(mode);
|
2013-04-30 13:29:18 +00:00
|
|
|
p.Do(resumeMode);
|
|
|
|
p.Do(holdMode);
|
2014-02-04 16:10:46 +00:00
|
|
|
if (s >= 4) {
|
|
|
|
p.Do(brightnessLevel);
|
|
|
|
}
|
2013-03-05 13:31:13 +00:00
|
|
|
p.Do(width);
|
|
|
|
p.Do(height);
|
2012-12-28 22:33:00 +00:00
|
|
|
WaitVBlankInfo wvi(0);
|
|
|
|
p.Do(vblankWaitingThreads, wvi);
|
2013-09-04 06:35:39 +00:00
|
|
|
p.Do(vblankPausedWaits);
|
2012-12-28 10:22:39 +00:00
|
|
|
|
|
|
|
p.Do(enterVblankEvent);
|
|
|
|
CoreTiming::RestoreRegisterEvent(enterVblankEvent, "EnterVBlank", &hleEnterVblank);
|
|
|
|
p.Do(leaveVblankEvent);
|
|
|
|
CoreTiming::RestoreRegisterEvent(leaveVblankEvent, "LeaveVBlank", &hleLeaveVblank);
|
2013-02-19 00:01:40 +00:00
|
|
|
p.Do(afterFlipEvent);
|
2013-10-25 03:00:38 +00:00
|
|
|
CoreTiming::RestoreRegisterEvent(afterFlipEvent, "AfterFlip", &hleAfterFlip);
|
2012-12-28 10:22:39 +00:00
|
|
|
|
2014-06-01 07:52:10 +00:00
|
|
|
if (s >= 5) {
|
|
|
|
p.Do(lagSyncEvent);
|
|
|
|
p.Do(lagSyncScheduled);
|
|
|
|
CoreTiming::RestoreRegisterEvent(lagSyncEvent, "LagSync", &hleLagSync);
|
|
|
|
lastLagSync = real_time_now();
|
|
|
|
if (lagSyncScheduled != g_Config.bForceLagSync) {
|
|
|
|
ScheduleLagSync();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lagSyncEvent = CoreTiming::RegisterEvent("LagSync", &hleLagSync);
|
|
|
|
ScheduleLagSync();
|
|
|
|
}
|
|
|
|
|
2012-12-29 20:21:56 +00:00
|
|
|
p.Do(gstate);
|
2015-07-26 20:38:40 +00:00
|
|
|
|
|
|
|
// TODO: GPU stuff is really not the responsibility of sceDisplay.
|
|
|
|
// Display just displays the buffers the GPU has drawn, they are really completely distinct.
|
|
|
|
// Maybe a bit tricky to move at this point, though...
|
|
|
|
|
2014-04-13 21:02:00 +00:00
|
|
|
gstate_c.DoState(p);
|
2013-10-25 03:00:38 +00:00
|
|
|
#ifndef _XBOX
|
|
|
|
if (s < 2) {
|
|
|
|
// This shouldn't have been savestated anyway, but it was.
|
|
|
|
// It's unlikely to overlap with the first value in gpuStats.
|
|
|
|
p.ExpectVoid(&gl_extensions.gpuVendor, sizeof(gl_extensions.gpuVendor));
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-09 05:18:56 +00:00
|
|
|
if (s < 6) {
|
|
|
|
p.Do(gpuStats);
|
|
|
|
}
|
2012-12-29 20:21:56 +00:00
|
|
|
gpu->DoState(p);
|
|
|
|
|
|
|
|
ReapplyGfxState();
|
|
|
|
|
|
|
|
if (p.mode == p.MODE_READ) {
|
|
|
|
if (hasSetMode) {
|
|
|
|
gpu->InitClear();
|
|
|
|
}
|
|
|
|
gpu->SetDisplayFramebuffer(framebuf.topaddr, framebuf.pspFramebufLinesize, framebuf.pspFramebufFormat);
|
|
|
|
}
|
2012-12-28 10:22:39 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void __DisplayShutdown() {
|
2012-12-23 10:16:32 +00:00
|
|
|
vblankListeners.clear();
|
|
|
|
vblankWaitingThreads.clear();
|
2012-11-06 16:05:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void __DisplayListenVblank(VblankCallback callback) {
|
2012-12-02 23:44:23 +00:00
|
|
|
vblankListeners.push_back(callback);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void __DisplayFireVblank() {
|
2012-12-25 14:28:34 +00:00
|
|
|
for (std::vector<VblankCallback>::iterator iter = vblankListeners.begin(), end = vblankListeners.end(); iter != end; ++iter) {
|
2012-12-02 23:44:23 +00:00
|
|
|
VblankCallback cb = *iter;
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-04 06:35:39 +00:00
|
|
|
void __DisplayVblankBeginCallback(SceUID threadID, SceUID prevCallbackId) {
|
|
|
|
SceUID pauseKey = prevCallbackId == 0 ? threadID : prevCallbackId;
|
|
|
|
|
|
|
|
// This means two callbacks in a row. PSP crashes if the same callback waits inside itself (may need more testing.)
|
|
|
|
// TODO: Handle this better?
|
|
|
|
if (vblankPausedWaits.find(pauseKey) != vblankPausedWaits.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitVBlankInfo waitData(0);
|
|
|
|
for (size_t i = 0; i < vblankWaitingThreads.size(); i++) {
|
|
|
|
WaitVBlankInfo *t = &vblankWaitingThreads[i];
|
2015-07-24 19:48:39 +00:00
|
|
|
if (t->threadID == threadID) {
|
2013-09-04 06:35:39 +00:00
|
|
|
waitData = *t;
|
|
|
|
vblankWaitingThreads.erase(vblankWaitingThreads.begin() + i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 19:48:39 +00:00
|
|
|
if (waitData.threadID != threadID) {
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG_REPORT(SCEDISPLAY, "sceDisplayWaitVblankCB: could not find waiting thread info.");
|
2013-09-04 06:35:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vblankPausedWaits[pauseKey] = vCount + waitData.vcountUnblock;
|
2014-06-30 01:55:23 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "sceDisplayWaitVblankCB: Suspending vblank wait for callback");
|
2013-09-04 06:35:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __DisplayVblankEndCallback(SceUID threadID, SceUID prevCallbackId) {
|
|
|
|
SceUID pauseKey = prevCallbackId == 0 ? threadID : prevCallbackId;
|
|
|
|
|
|
|
|
// Probably should not be possible.
|
|
|
|
if (vblankPausedWaits.find(pauseKey) == vblankPausedWaits.end()) {
|
|
|
|
__KernelResumeThreadFromWait(threadID, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vcountUnblock = vblankPausedWaits[pauseKey];
|
2013-12-06 07:23:10 +00:00
|
|
|
vblankPausedWaits.erase(pauseKey);
|
2013-09-04 06:35:39 +00:00
|
|
|
if (vcountUnblock <= vCount) {
|
|
|
|
__KernelResumeThreadFromWait(threadID, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Still have to wait a bit longer.
|
|
|
|
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vcountUnblock - vCount));
|
2014-06-30 01:55:23 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "sceDisplayWaitVblankCB: Resuming vblank wait from callback");
|
2013-09-04 06:35:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-19 22:49:25 +00:00
|
|
|
// TODO: Also average actualFps
|
2013-08-19 20:05:55 +00:00
|
|
|
void __DisplayGetFPS(float *out_vps, float *out_fps, float *out_actual_fps) {
|
2013-06-17 06:44:11 +00:00
|
|
|
*out_vps = fps;
|
|
|
|
*out_fps = flips;
|
2013-08-19 20:05:55 +00:00
|
|
|
*out_actual_fps = actualFps;
|
2013-11-15 16:16:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __DisplayGetVPS(float *out_vps) {
|
|
|
|
*out_vps = fps;
|
2013-04-07 20:43:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-20 03:20:41 +00:00
|
|
|
void __DisplayGetAveragedFPS(float *out_vps, float *out_fps) {
|
|
|
|
float avg = 0.0;
|
|
|
|
if (fpsHistoryValid > 0) {
|
|
|
|
if (fpsHistoryValid > ARRAY_SIZE(fpsHistory)) {
|
|
|
|
fpsHistoryValid = ARRAY_SIZE(fpsHistory);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < fpsHistoryValid; ++i) {
|
|
|
|
avg += fpsHistory[i];
|
|
|
|
}
|
|
|
|
avg /= (double) fpsHistoryValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_vps = *out_fps = avg;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void CalculateFPS() {
|
2013-02-11 10:00:18 +00:00
|
|
|
time_update();
|
|
|
|
double now = time_now_d();
|
|
|
|
|
2013-08-19 22:49:25 +00:00
|
|
|
if (now >= lastFpsTime + 1.0) {
|
2013-08-07 20:32:04 +00:00
|
|
|
double frames = (gpuStats.numVBlanks - lastFpsFrame);
|
2013-08-19 20:05:55 +00:00
|
|
|
actualFps = (actualFlips - lastActualFlips);
|
|
|
|
|
2013-06-17 06:44:11 +00:00
|
|
|
fps = frames / (now - lastFpsTime);
|
2013-08-07 20:32:04 +00:00
|
|
|
flips = 60.0 * (double) (gpuStats.numFlips - lastNumFlips) / frames;
|
2013-02-11 10:00:18 +00:00
|
|
|
|
2013-08-07 20:32:04 +00:00
|
|
|
lastFpsFrame = gpuStats.numVBlanks;
|
|
|
|
lastNumFlips = gpuStats.numFlips;
|
2013-08-19 20:05:55 +00:00
|
|
|
lastActualFlips = actualFlips;
|
2013-02-11 10:00:18 +00:00
|
|
|
lastFpsTime = now;
|
2013-05-20 03:20:41 +00:00
|
|
|
|
|
|
|
fpsHistory[fpsHistoryPos++] = fps;
|
|
|
|
fpsHistoryPos = fpsHistoryPos % ARRAY_SIZE(fpsHistory);
|
|
|
|
++fpsHistoryValid;
|
2013-02-11 10:00:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-13 21:40:38 +00:00
|
|
|
void __DisplayGetDebugStats(char stats[], size_t bufsize) {
|
2013-02-18 22:25:06 +00:00
|
|
|
gpu->UpdateStats();
|
|
|
|
|
2013-05-31 17:40:16 +00:00
|
|
|
float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f;
|
|
|
|
|
2014-09-13 21:40:38 +00:00
|
|
|
snprintf(stats, bufsize - 1,
|
2013-02-18 22:25:06 +00:00
|
|
|
"Frames: %i\n"
|
|
|
|
"DL processing time: %0.2f ms\n"
|
|
|
|
"Kernel processing time: %0.2f ms\n"
|
|
|
|
"Slowest syscall: %s : %0.2f ms\n"
|
|
|
|
"Most active syscall: %s : %0.2f ms\n"
|
|
|
|
"Draw calls: %i, flushes %i\n"
|
|
|
|
"Cached Draw calls: %i\n"
|
2013-08-27 18:58:27 +00:00
|
|
|
"Alpha Tested draws: %i\n"
|
|
|
|
"Non Alpha Tested draws: %i\n"
|
2013-02-18 22:25:06 +00:00
|
|
|
"Num Tracked Vertex Arrays: %i\n"
|
2013-05-31 17:40:16 +00:00
|
|
|
"Cycles executed: %d (%f per vertex)\n"
|
2013-08-23 09:26:13 +00:00
|
|
|
"Commands per call level: %i %i %i %i\n"
|
2013-02-18 22:25:06 +00:00
|
|
|
"Vertices Submitted: %i\n"
|
|
|
|
"Cached Vertices Drawn: %i\n"
|
|
|
|
"Uncached Vertices Drawn: %i\n"
|
|
|
|
"FBOs active: %i\n"
|
|
|
|
"Textures active: %i, decoded: %i\n"
|
|
|
|
"Texture invalidations: %i\n"
|
|
|
|
"Vertex shaders loaded: %i\n"
|
|
|
|
"Fragment shaders loaded: %i\n"
|
|
|
|
"Combined shaders loaded: %i\n",
|
2013-08-07 20:32:04 +00:00
|
|
|
gpuStats.numVBlanks,
|
2013-02-18 22:25:06 +00:00
|
|
|
gpuStats.msProcessingDisplayLists * 1000.0f,
|
|
|
|
kernelStats.msInSyscalls * 1000.0f,
|
|
|
|
kernelStats.slowestSyscallName ? kernelStats.slowestSyscallName : "(none)",
|
|
|
|
kernelStats.slowestSyscallTime * 1000.0f,
|
|
|
|
kernelStats.summedSlowestSyscallName ? kernelStats.summedSlowestSyscallName : "(none)",
|
|
|
|
kernelStats.summedSlowestSyscallTime * 1000.0f,
|
|
|
|
gpuStats.numDrawCalls,
|
|
|
|
gpuStats.numFlushes,
|
|
|
|
gpuStats.numCachedDrawCalls,
|
2013-08-27 18:58:27 +00:00
|
|
|
gpuStats.numAlphaTestedDraws,
|
|
|
|
gpuStats.numNonAlphaTestedDraws,
|
2013-02-18 22:25:06 +00:00
|
|
|
gpuStats.numTrackedVertexArrays,
|
2013-05-31 17:40:16 +00:00
|
|
|
gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles,
|
|
|
|
vertexAverageCycles,
|
2013-08-23 09:26:13 +00:00
|
|
|
gpuStats.gpuCommandsAtCallLevel[0],gpuStats.gpuCommandsAtCallLevel[1],gpuStats.gpuCommandsAtCallLevel[2],gpuStats.gpuCommandsAtCallLevel[3],
|
2013-02-18 22:25:06 +00:00
|
|
|
gpuStats.numVertsSubmitted,
|
|
|
|
gpuStats.numCachedVertsDrawn,
|
|
|
|
gpuStats.numUncachedVertsDrawn,
|
|
|
|
gpuStats.numFBOs,
|
|
|
|
gpuStats.numTextures,
|
|
|
|
gpuStats.numTexturesDecoded,
|
|
|
|
gpuStats.numTextureInvalidations,
|
|
|
|
gpuStats.numVertexShaders,
|
|
|
|
gpuStats.numFragmentShaders,
|
|
|
|
gpuStats.numShaders
|
|
|
|
);
|
2014-09-13 21:40:38 +00:00
|
|
|
stats[bufsize - 1] = '\0';
|
2013-08-07 20:32:04 +00:00
|
|
|
gpuStats.ResetFrame();
|
2013-02-18 22:25:06 +00:00
|
|
|
kernelStats.ResetFrame();
|
|
|
|
}
|
|
|
|
|
2013-05-20 15:28:07 +00:00
|
|
|
enum {
|
|
|
|
FPS_LIMIT_NORMAL = 0,
|
|
|
|
FPS_LIMIT_CUSTOM = 1,
|
|
|
|
};
|
|
|
|
|
2014-06-14 21:55:16 +00:00
|
|
|
void __DisplaySetWasPaused() {
|
|
|
|
wasPaused = true;
|
|
|
|
}
|
|
|
|
|
2014-06-26 07:36:17 +00:00
|
|
|
static bool FrameTimingThrottled() {
|
|
|
|
if (PSP_CoreParameter().fpsLimit == FPS_LIMIT_CUSTOM && g_Config.iFpsLimit == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !PSP_CoreParameter().unthrottle;
|
|
|
|
}
|
|
|
|
|
2013-02-18 22:25:06 +00:00
|
|
|
// Let's collect all the throttling and frameskipping logic here.
|
2014-12-08 09:40:08 +00:00
|
|
|
static void DoFrameTiming(bool &throttle, bool &skipFrame, float timestep) {
|
2015-07-03 19:05:08 +00:00
|
|
|
PROFILE_THIS_SCOPE("timing");
|
2013-05-20 15:28:07 +00:00
|
|
|
int fpsLimiter = PSP_CoreParameter().fpsLimit;
|
2014-06-26 07:36:17 +00:00
|
|
|
throttle = FrameTimingThrottled();
|
2013-02-18 22:44:32 +00:00
|
|
|
skipFrame = false;
|
2013-02-18 22:25:06 +00:00
|
|
|
|
2013-02-18 23:44:22 +00:00
|
|
|
// Check if the frameskipping code should be enabled. If neither throttling or frameskipping is on,
|
|
|
|
// we have nothing to do here.
|
2013-05-02 14:48:28 +00:00
|
|
|
bool doFrameSkip = g_Config.iFrameSkip != 0;
|
2015-07-24 19:48:39 +00:00
|
|
|
|
2013-09-17 06:41:12 +00:00
|
|
|
if (!throttle && g_Config.bFrameSkipUnthrottle) {
|
2013-04-14 10:45:58 +00:00
|
|
|
doFrameSkip = true;
|
|
|
|
skipFrame = true;
|
2013-08-15 23:00:26 +00:00
|
|
|
if (numSkippedFrames >= 7) {
|
2013-04-14 10:45:58 +00:00
|
|
|
skipFrame = false;
|
|
|
|
}
|
2015-07-24 19:48:39 +00:00
|
|
|
return;
|
2013-04-14 10:45:58 +00:00
|
|
|
}
|
2013-09-17 06:41:12 +00:00
|
|
|
|
2013-02-18 23:44:22 +00:00
|
|
|
if (!throttle && !doFrameSkip)
|
|
|
|
return;
|
2015-07-24 19:48:39 +00:00
|
|
|
|
2013-02-18 23:44:22 +00:00
|
|
|
time_update();
|
2014-06-26 07:36:17 +00:00
|
|
|
|
|
|
|
float scaledTimestep = timestep;
|
|
|
|
if (fpsLimiter == FPS_LIMIT_CUSTOM && g_Config.iFpsLimit != 0) {
|
|
|
|
scaledTimestep *= 60.0f / g_Config.iFpsLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastFrameTime == 0.0 || wasPaused) {
|
|
|
|
nextFrameTime = time_now_d() + scaledTimestep;
|
2014-06-14 21:55:16 +00:00
|
|
|
if (wasPaused)
|
|
|
|
wasPaused = false;
|
2014-06-26 07:36:17 +00:00
|
|
|
} else {
|
|
|
|
// Advance lastFrameTime by a constant amount each frame,
|
|
|
|
// but don't let it get too far behind as things can get very jumpy.
|
|
|
|
const double maxFallBehindFrames = 5.5;
|
|
|
|
|
|
|
|
nextFrameTime = std::max(lastFrameTime + scaledTimestep, time_now_d() - maxFallBehindFrames * scaledTimestep);
|
2014-06-14 21:55:16 +00:00
|
|
|
}
|
2014-06-26 07:36:17 +00:00
|
|
|
curFrameTime = time_now_d();
|
2015-07-24 19:48:39 +00:00
|
|
|
|
2013-08-18 16:53:45 +00:00
|
|
|
// Auto-frameskip automatically if speed limit is set differently than the default.
|
2015-02-09 22:10:57 +00:00
|
|
|
bool useAutoFrameskip = g_Config.bAutoFrameSkip && g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
|
2014-01-25 16:41:39 +00:00
|
|
|
if (g_Config.bAutoFrameSkip || (g_Config.iFrameSkip == 0 && fpsLimiter == FPS_LIMIT_CUSTOM && g_Config.iFpsLimit > 60)) {
|
|
|
|
// autoframeskip
|
2014-06-14 21:55:16 +00:00
|
|
|
// Argh, we are falling behind! Let's skip a frame and see if we catch up.
|
2013-08-15 23:00:26 +00:00
|
|
|
if (curFrameTime > nextFrameTime && doFrameSkip) {
|
|
|
|
skipFrame = true;
|
|
|
|
}
|
2014-01-25 16:41:39 +00:00
|
|
|
} else if (g_Config.iFrameSkip >= 1) {
|
|
|
|
// fixed frameskip
|
|
|
|
if (numSkippedFrames >= g_Config.iFrameSkip)
|
2013-08-15 23:00:26 +00:00
|
|
|
skipFrame = false;
|
|
|
|
else
|
|
|
|
skipFrame = true;
|
2013-02-18 23:44:22 +00:00
|
|
|
}
|
2013-04-14 10:11:49 +00:00
|
|
|
|
2013-08-18 20:40:42 +00:00
|
|
|
if (curFrameTime < nextFrameTime && throttle) {
|
2013-02-18 23:44:22 +00:00
|
|
|
// If time gap is huge just jump (somebody unthrottled)
|
2014-06-26 07:36:17 +00:00
|
|
|
if (nextFrameTime - curFrameTime > 2*scaledTimestep) {
|
|
|
|
nextFrameTime = curFrameTime;
|
2013-02-18 23:44:22 +00:00
|
|
|
} else {
|
2013-05-20 15:28:07 +00:00
|
|
|
// Wait until we've caught up.
|
2013-02-18 23:44:22 +00:00
|
|
|
while (time_now_d() < nextFrameTime) {
|
2014-07-15 15:03:25 +00:00
|
|
|
#ifdef _WIN32
|
2013-11-12 16:50:35 +00:00
|
|
|
sleep_ms(1); // Sleep for 1ms on this thread
|
2014-07-15 15:03:25 +00:00
|
|
|
#else
|
|
|
|
const double left = nextFrameTime - curFrameTime;
|
|
|
|
usleep((long)(left * 1000000));
|
|
|
|
#endif
|
2013-02-18 23:44:22 +00:00
|
|
|
time_update();
|
|
|
|
}
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
2013-02-18 23:44:22 +00:00
|
|
|
curFrameTime = time_now_d();
|
|
|
|
}
|
2014-06-26 07:36:17 +00:00
|
|
|
|
|
|
|
lastFrameTime = nextFrameTime;
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static void DoFrameIdleTiming() {
|
2015-07-03 19:05:08 +00:00
|
|
|
PROFILE_THIS_SCOPE("timing");
|
2014-07-15 15:03:25 +00:00
|
|
|
if (!FrameTimingThrottled() || !g_Config.bEnableSound || wasPaused) {
|
2014-06-26 07:37:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_update();
|
|
|
|
|
|
|
|
double dist = time_now_d() - lastFrameTime;
|
|
|
|
// Ignore if the distance is just crazy. May mean wrap or pause.
|
|
|
|
if (dist < 0.0 || dist >= 15 * timePerVblank) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float scaledVblank = timePerVblank;
|
|
|
|
if (PSP_CoreParameter().fpsLimit == FPS_LIMIT_CUSTOM) {
|
|
|
|
// 0 is handled in FrameTimingThrottled().
|
|
|
|
scaledVblank *= 60.0f / g_Config.iFpsLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have over at least a vblank of spare time, maintain at least 30fps in delay.
|
|
|
|
// This prevents fast forward during loading screens.
|
|
|
|
const double thresh = lastFrameTime + (numVBlanksSinceFlip - 1) * scaledVblank;
|
|
|
|
if (numVBlanksSinceFlip >= 2 && time_now_d() < thresh) {
|
|
|
|
// Give a little extra wiggle room in case the next vblank does more work.
|
|
|
|
const double goal = lastFrameTime + numVBlanksSinceFlip * scaledVblank - 0.001;
|
|
|
|
while (time_now_d() < goal) {
|
2014-07-15 15:03:25 +00:00
|
|
|
#ifdef _WIN32
|
2014-06-26 07:37:03 +00:00
|
|
|
sleep_ms(1);
|
2014-07-15 15:03:25 +00:00
|
|
|
#else
|
|
|
|
const double left = goal - time_now_d();
|
|
|
|
usleep((long)(left * 1000000));
|
|
|
|
#endif
|
2014-06-26 07:37:03 +00:00
|
|
|
time_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 22:25:06 +00:00
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void hleEnterVblank(u64 userdata, int cyclesLate) {
|
2012-11-01 15:19:01 +00:00
|
|
|
int vbCount = userdata;
|
|
|
|
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "Enter VBlank %i", vbCount);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
isVblank = 1;
|
2013-09-03 07:09:50 +00:00
|
|
|
vCount++; // vCount increases at each VBLANK.
|
|
|
|
hCountBase += hCountPerVblank; // This is the "accumulated" hcount base.
|
|
|
|
if (hCountBase > 0x7FFFFFFF) {
|
|
|
|
hCountBase -= 0x80000000;
|
|
|
|
}
|
2013-03-08 16:26:54 +00:00
|
|
|
frameStartTicks = CoreTiming::GetTicks();
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-07-01 07:25:20 +00:00
|
|
|
CoreTiming::ScheduleEvent(msToCycles(vblankMs) - cyclesLate, leaveVblankEvent, vbCount + 1);
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// Wake up threads waiting for VBlank
|
2013-09-04 06:22:56 +00:00
|
|
|
u32 error;
|
2014-06-24 07:45:05 +00:00
|
|
|
bool wokeThreads = false;
|
2012-12-21 15:49:34 +00:00
|
|
|
for (size_t i = 0; i < vblankWaitingThreads.size(); i++) {
|
2013-02-11 03:02:00 +00:00
|
|
|
if (--vblankWaitingThreads[i].vcountUnblock == 0) {
|
2013-09-04 06:22:56 +00:00
|
|
|
// Only wake it if it wasn't already released by someone else.
|
|
|
|
SceUID waitID = __KernelGetWaitID(vblankWaitingThreads[i].threadID, WAITTYPE_VBLANK, error);
|
|
|
|
if (waitID == 1) {
|
|
|
|
__KernelResumeThreadFromWait(vblankWaitingThreads[i].threadID, 0);
|
2014-06-24 07:45:05 +00:00
|
|
|
wokeThreads = true;
|
2013-09-04 06:22:56 +00:00
|
|
|
}
|
2013-02-11 03:02:00 +00:00
|
|
|
vblankWaitingThreads.erase(vblankWaitingThreads.begin() + i--);
|
|
|
|
}
|
2012-12-17 19:14:06 +00:00
|
|
|
}
|
2014-06-24 07:45:05 +00:00
|
|
|
if (wokeThreads) {
|
|
|
|
__KernelReSchedule("entered vblank");
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-03 23:41:16 +00:00
|
|
|
// Trigger VBlank interrupt handlers.
|
|
|
|
__TriggerInterrupt(PSP_INTR_IMMEDIATE | PSP_INTR_ONLY_IF_ENABLED | PSP_INTR_ALWAYS_RESCHED, PSP_VBLANK_INTR, PSP_INTR_SUB_ALL);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-08-15 23:00:26 +00:00
|
|
|
gpuStats.numVBlanks++;
|
|
|
|
|
|
|
|
numVBlanksSinceFlip++;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
// TODO: Should this be done here or in hleLeaveVblank?
|
2012-12-25 14:28:34 +00:00
|
|
|
if (framebufIsLatched) {
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "Setting latched framebuffer %08x (prev: %08x)", latchedFramebuf.topaddr, framebuf.topaddr);
|
2013-08-16 07:00:40 +00:00
|
|
|
framebuf = latchedFramebuf;
|
|
|
|
framebufIsLatched = false;
|
|
|
|
gpu->SetDisplayFramebuffer(framebuf.topaddr, framebuf.pspFramebufLinesize, framebuf.pspFramebufFormat);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-08-10 16:36:11 +00:00
|
|
|
// We flip only if the framebuffer was dirty. This eliminates flicker when using
|
|
|
|
// non-buffered rendering. The interaction with frame skipping seems to need
|
|
|
|
// some work.
|
2014-01-25 07:55:19 +00:00
|
|
|
// But, let's flip at least once every 10 frames if possible, since there may be sound effects.
|
|
|
|
if (gpu->FramebufferDirty() || (g_Config.iRenderingMode != 0 && numVBlanksSinceFlip >= 10)) {
|
2013-10-28 04:19:27 +00:00
|
|
|
if (g_Config.iShowFPSCounter && g_Config.iShowFPSCounter < 4) {
|
2013-08-19 22:49:25 +00:00
|
|
|
CalculateFPS();
|
|
|
|
}
|
|
|
|
|
2013-08-15 23:00:26 +00:00
|
|
|
// Setting CORE_NEXTFRAME causes a swap.
|
|
|
|
// Check first though, might've just quit / been paused.
|
|
|
|
if (gpu->FramebufferReallyDirty()) {
|
|
|
|
if (coreState == CORE_RUNNING) {
|
|
|
|
coreState = CORE_NEXTFRAME;
|
|
|
|
gpu->CopyDisplayToOutput();
|
2013-08-19 20:05:55 +00:00
|
|
|
actualFlips++;
|
2013-08-15 23:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-11 20:11:51 +00:00
|
|
|
|
2013-08-15 23:00:26 +00:00
|
|
|
gpuStats.numFlips++;
|
2013-01-20 21:05:11 +00:00
|
|
|
|
2013-08-07 21:32:28 +00:00
|
|
|
bool throttle, skipFrame;
|
2014-06-26 07:36:17 +00:00
|
|
|
DoFrameTiming(throttle, skipFrame, (float)numVBlanksSinceFlip * timePerVblank);
|
2012-12-18 09:25:57 +00:00
|
|
|
|
2013-12-15 21:27:16 +00:00
|
|
|
int maxFrameskip = 8;
|
|
|
|
if (throttle) {
|
2014-01-25 16:41:39 +00:00
|
|
|
// 4 here means 1 drawn, 4 skipped - so 12 fps minimum.
|
|
|
|
maxFrameskip = g_Config.iFrameSkip;
|
2013-12-15 21:27:16 +00:00
|
|
|
}
|
2013-08-15 23:00:26 +00:00
|
|
|
if (numSkippedFrames >= maxFrameskip) {
|
|
|
|
skipFrame = false;
|
|
|
|
}
|
|
|
|
|
2013-08-07 21:32:28 +00:00
|
|
|
if (skipFrame) {
|
|
|
|
gstate_c.skipDrawReason |= SKIPDRAW_SKIPFRAME;
|
|
|
|
numSkippedFrames++;
|
|
|
|
} else {
|
2013-08-15 23:00:26 +00:00
|
|
|
gstate_c.skipDrawReason &= ~SKIPDRAW_SKIPFRAME;
|
2013-08-07 21:32:28 +00:00
|
|
|
numSkippedFrames = 0;
|
|
|
|
}
|
2013-02-18 22:44:32 +00:00
|
|
|
|
2013-08-07 21:32:28 +00:00
|
|
|
// Returning here with coreState == CORE_NEXTFRAME causes a buffer flip to happen (next frame).
|
|
|
|
// Right after, we regain control for a little bit in hleAfterFlip. I think that's a great
|
|
|
|
// place to do housekeeping.
|
|
|
|
CoreTiming::ScheduleEvent(0 - cyclesLate, afterFlipEvent, 0);
|
|
|
|
numVBlanksSinceFlip = 0;
|
2014-06-26 07:37:03 +00:00
|
|
|
} else {
|
|
|
|
// Okay, there's no new frame to draw. But audio may be playing, so we need to time still.
|
|
|
|
DoFrameIdleTiming();
|
2013-08-07 21:32:28 +00:00
|
|
|
}
|
2013-02-18 22:25:06 +00:00
|
|
|
}
|
2012-11-22 22:07:15 +00:00
|
|
|
|
2015-07-24 19:48:39 +00:00
|
|
|
void hleAfterFlip(u64 userdata, int cyclesLate) {
|
2013-02-18 22:25:06 +00:00
|
|
|
gpu->BeginFrame(); // doesn't really matter if begin or end of frame.
|
2014-06-01 07:52:10 +00:00
|
|
|
|
|
|
|
// This seems like as good a time as any to check if the config changed.
|
|
|
|
if (lagSyncScheduled != g_Config.bForceLagSync) {
|
|
|
|
ScheduleLagSync();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void hleLeaveVblank(u64 userdata, int cyclesLate) {
|
2012-11-01 15:19:01 +00:00
|
|
|
isVblank = 0;
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"Leave VBlank %i", (int)userdata - 1);
|
2012-11-01 15:19:01 +00:00
|
|
|
CoreTiming::ScheduleEvent(msToCycles(frameMs - vblankMs) - cyclesLate, enterVblankEvent, userdata);
|
2013-11-16 21:59:29 +00:00
|
|
|
|
|
|
|
// Fire the vblank listeners after the vblank completes.
|
|
|
|
__DisplayFireVblank();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-06-01 07:52:10 +00:00
|
|
|
void hleLagSync(u64 userdata, int cyclesLate) {
|
|
|
|
// The goal here is to prevent network, audio, and input lag from the real world.
|
|
|
|
// Our normal timing is very "stop and go". This is efficient, but causes real world lag.
|
|
|
|
// This event (optionally) runs every 1ms to sync with the real world.
|
2015-07-03 19:05:08 +00:00
|
|
|
PROFILE_THIS_SCOPE("timing");
|
2014-06-01 07:52:10 +00:00
|
|
|
|
2014-06-26 07:36:17 +00:00
|
|
|
if (!FrameTimingThrottled()) {
|
2014-06-01 07:52:10 +00:00
|
|
|
lagSyncScheduled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float scale = 1.0f;
|
|
|
|
if (PSP_CoreParameter().fpsLimit == FPS_LIMIT_CUSTOM) {
|
2014-06-26 07:36:17 +00:00
|
|
|
// 0 is handled in FrameTimingThrottled().
|
2014-06-03 06:42:08 +00:00
|
|
|
scale = 60.0f / g_Config.iFpsLimit;
|
2014-06-01 07:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const double goal = lastLagSync + (scale / 1000.0f);
|
|
|
|
time_update();
|
2014-06-24 15:27:21 +00:00
|
|
|
// Don't lag too long ever, if they leave it paused.
|
2014-06-25 07:44:18 +00:00
|
|
|
while (time_now_d() < goal && goal < time_now_d() + 0.01) {
|
2014-06-03 08:48:10 +00:00
|
|
|
#ifndef _WIN32
|
2014-07-15 15:03:25 +00:00
|
|
|
const double left = goal - time_now_d();
|
2014-06-01 07:52:10 +00:00
|
|
|
usleep((long)(left * 1000000));
|
2014-06-03 08:48:10 +00:00
|
|
|
#endif
|
2014-06-01 07:52:10 +00:00
|
|
|
time_update();
|
|
|
|
}
|
|
|
|
|
2014-06-01 23:20:58 +00:00
|
|
|
const int emuOver = (int)cyclesToUs(cyclesLate);
|
|
|
|
const int over = (int)((time_now_d() - goal) * 1000000);
|
|
|
|
ScheduleLagSync(over - emuOver);
|
2014-06-01 07:52:10 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayIsVblank() {
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"%i=sceDisplayIsVblank()",isVblank);
|
2013-03-05 13:34:22 +00:00
|
|
|
return isVblank;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplaySetMode(int displayMode, int displayWidth, int displayHeight) {
|
2014-04-25 20:41:01 +00:00
|
|
|
if (displayWidth <= 0 || displayHeight <= 0 || (displayWidth & 0x7) != 0) {
|
|
|
|
WARN_LOG(SCEDISPLAY, "sceDisplaySetMode INVALID SIZE (%i, %i, %i)", displayMode, displayWidth, displayHeight);
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_SIZE;
|
|
|
|
}
|
2015-07-24 19:48:39 +00:00
|
|
|
|
2014-04-25 20:41:01 +00:00
|
|
|
if (displayMode != PSP_DISPLAY_MODE_LCD) {
|
|
|
|
WARN_LOG(SCEDISPLAY, "sceDisplaySetMode INVALID MODE(%i, %i, %i)", displayMode, displayWidth, displayHeight);
|
|
|
|
return SCE_KERNEL_ERROR_INVALID_MODE;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-04-25 20:41:01 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplaySetMode(%i, %i, %i)", displayMode, displayWidth, displayHeight);
|
2012-12-25 14:28:34 +00:00
|
|
|
if (!hasSetMode) {
|
2012-11-20 09:59:23 +00:00
|
|
|
gpu->InitClear();
|
2012-11-19 23:31:19 +00:00
|
|
|
hasSetMode = true;
|
|
|
|
}
|
2013-03-05 13:31:13 +00:00
|
|
|
mode = displayMode;
|
|
|
|
width = displayWidth;
|
|
|
|
height = displayHeight;
|
2012-11-01 15:19:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-19 22:49:25 +00:00
|
|
|
// Some games (GTA) never call this during gameplay, so bad place to put a framerate counter.
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplaySetFramebuf(u32 topaddr, int linesize, int pixelformat, int sync) {
|
2012-11-19 20:23:29 +00:00
|
|
|
FrameBufferState fbstate;
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplaySetFramebuf(topaddr=%08x,linesize=%d,pixelsize=%d,sync=%d)", topaddr, linesize, pixelformat, sync);
|
2013-05-28 08:47:48 +00:00
|
|
|
hleEatCycles(290);
|
2012-12-25 14:28:34 +00:00
|
|
|
if (topaddr == 0) {
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"- screen off");
|
2012-12-25 14:28:34 +00:00
|
|
|
} else {
|
2012-11-19 20:23:29 +00:00
|
|
|
fbstate.topaddr = topaddr;
|
2013-07-29 15:09:33 +00:00
|
|
|
fbstate.pspFramebufFormat = (GEBufferFormat)pixelformat;
|
2012-11-19 20:23:29 +00:00
|
|
|
fbstate.pspFramebufLinesize = linesize;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:46:21 +00:00
|
|
|
s64 delayCycles = 0;
|
2013-08-27 03:12:26 +00:00
|
|
|
if (topaddr != framebuf.topaddr && g_Config.iForceMaxEmulatedFPS > 0) {
|
|
|
|
// Sometimes we get a small number, there's probably no need to delay the thread for this.
|
|
|
|
// sceDisplaySetFramebuf() isn't supposed to delay threads at all. This is a hack.
|
|
|
|
const int FLIP_DELAY_CYCLES_MIN = 10;
|
|
|
|
// Some games (like Final Fantasy 4) only call this too much in spurts.
|
|
|
|
// The goal is to fix games where this would result in a consistent overhead.
|
|
|
|
const int FLIP_DELAY_MIN_FLIPS = 30;
|
|
|
|
|
|
|
|
u64 now = CoreTiming::GetTicks();
|
2014-04-14 04:47:11 +00:00
|
|
|
// 1001 to account for NTSC timing (59.94 fps.)
|
|
|
|
u64 expected = msToCycles(1001) / g_Config.iForceMaxEmulatedFPS;
|
2013-08-27 03:12:26 +00:00
|
|
|
u64 actual = now - lastFlipCycles;
|
|
|
|
if (actual < expected - FLIP_DELAY_CYCLES_MIN) {
|
|
|
|
if (lastFlipsTooFrequent >= FLIP_DELAY_MIN_FLIPS) {
|
2013-08-25 16:46:21 +00:00
|
|
|
delayCycles = expected - actual;
|
2013-08-27 03:12:26 +00:00
|
|
|
} else {
|
|
|
|
++lastFlipsTooFrequent;
|
2013-08-25 16:46:21 +00:00
|
|
|
}
|
2013-08-27 03:12:26 +00:00
|
|
|
} else {
|
|
|
|
--lastFlipsTooFrequent;
|
2013-06-30 03:16:09 +00:00
|
|
|
}
|
2013-08-27 03:12:26 +00:00
|
|
|
lastFlipCycles = CoreTiming::GetTicks();
|
2013-06-17 06:44:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
if (sync == PSP_DISPLAY_SETBUF_IMMEDIATE) {
|
2012-11-19 20:23:29 +00:00
|
|
|
// Write immediately to the current framebuffer parameters
|
2013-04-08 18:59:45 +00:00
|
|
|
if (topaddr != 0) {
|
2013-08-14 15:54:58 +00:00
|
|
|
framebuf = fbstate;
|
|
|
|
gpu->SetDisplayFramebuffer(framebuf.topaddr, framebuf.pspFramebufLinesize, framebuf.pspFramebufFormat);
|
2013-04-08 18:59:45 +00:00
|
|
|
} else {
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG(SCEDISPLAY, "%s: PSP_DISPLAY_SETBUF_IMMEDIATE without topaddr?", __FUNCTION__);
|
2013-04-08 18:59:45 +00:00
|
|
|
}
|
2012-12-25 14:28:34 +00:00
|
|
|
} else if (topaddr != 0) {
|
2012-11-19 20:23:29 +00:00
|
|
|
// Delay the write until vblank
|
|
|
|
latchedFramebuf = fbstate;
|
|
|
|
framebufIsLatched = true;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2013-08-25 16:46:21 +00:00
|
|
|
|
|
|
|
if (delayCycles > 0) {
|
|
|
|
// Okay, the game is going at too high a frame rate. God of War and Fat Princess both do this.
|
|
|
|
// Simply eating the cycles works and is fast, but breaks other games (like Jeanne d'Arc.)
|
2013-08-27 03:12:26 +00:00
|
|
|
// So, instead, we delay this HLE thread only (a small deviation from correct behavior.)
|
2013-08-25 16:46:21 +00:00
|
|
|
return hleDelayResult(0, "set framebuf", cyclesToUs(delayCycles));
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 17:20:13 +00:00
|
|
|
bool __DisplayGetFramebuf(u8 **topaddr, u32 *linesize, u32 *pixelFormat, int latchedMode) {
|
|
|
|
const FrameBufferState &fbState = latchedMode == 1 ? latchedFramebuf : framebuf;
|
2013-01-14 00:35:34 +00:00
|
|
|
if (topaddr != NULL)
|
|
|
|
*topaddr = Memory::GetPointer(fbState.topaddr);
|
|
|
|
if (linesize != NULL)
|
|
|
|
*linesize = fbState.pspFramebufLinesize;
|
|
|
|
if (pixelFormat != NULL)
|
|
|
|
*pixelFormat = fbState.pspFramebufFormat;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetFramebuf(u32 topaddrPtr, u32 linesizePtr, u32 pixelFormatPtr, int latchedMode) {
|
2014-01-13 07:29:03 +00:00
|
|
|
const FrameBufferState &fbState = latchedMode == 1 && framebufIsLatched ? latchedFramebuf : framebuf;
|
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplayGetFramebuf(*%08x = %08x, *%08x = %08x, *%08x = %08x, %i)", topaddrPtr, fbState.topaddr, linesizePtr, fbState.pspFramebufLinesize, pixelFormatPtr, fbState.pspFramebufFormat, latchedMode);
|
2012-12-25 14:28:34 +00:00
|
|
|
|
2012-11-19 22:53:38 +00:00
|
|
|
if (Memory::IsValidAddress(topaddrPtr))
|
|
|
|
Memory::Write_U32(fbState.topaddr, topaddrPtr);
|
|
|
|
if (Memory::IsValidAddress(linesizePtr))
|
|
|
|
Memory::Write_U32(fbState.pspFramebufLinesize, linesizePtr);
|
|
|
|
if (Memory::IsValidAddress(pixelFormatPtr))
|
|
|
|
Memory::Write_U32(fbState.pspFramebufFormat, pixelFormatPtr);
|
|
|
|
|
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 02:31:25 +00:00
|
|
|
static void DisplayWaitForVblanks(const char *reason, int vblanks, bool callbacks = false) {
|
|
|
|
const s64 ticksIntoFrame = CoreTiming::GetTicks() - frameStartTicks;
|
|
|
|
const s64 cyclesToNextVblank = msToCycles(frameMs) - ticksIntoFrame;
|
|
|
|
|
|
|
|
// These syscalls take about 115 us, so if the next vblank is before then, we're waiting extra.
|
|
|
|
// At least, on real firmware a wait >= 16500 into the frame will wait two.
|
|
|
|
if (cyclesToNextVblank <= usToCycles(115)) {
|
|
|
|
++vblanks;
|
|
|
|
}
|
|
|
|
|
|
|
|
vblankWaitingThreads.push_back(WaitVBlankInfo(__KernelGetCurThread(), vblanks));
|
2015-03-05 16:31:59 +00:00
|
|
|
__KernelWaitCurThread(WAITTYPE_VBLANK, 1, 0, 0, callbacks, reason);
|
2015-03-02 02:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void DisplayWaitForVblanksCB(const char *reason, int vblanks) {
|
|
|
|
DisplayWaitForVblanks(reason, vblanks, true);
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblankStart() {
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"sceDisplayWaitVblankStart()");
|
2015-03-02 02:31:25 +00:00
|
|
|
DisplayWaitForVblanks("vblank start waited", 1);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblank() {
|
2013-01-12 16:53:23 +00:00
|
|
|
if (!isVblank) {
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"sceDisplayWaitVblank()");
|
2015-03-02 02:31:25 +00:00
|
|
|
DisplayWaitForVblanks("vblank waited", 1);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2013-01-12 16:53:23 +00:00
|
|
|
} else {
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplayWaitVblank() - not waiting since in vBlank");
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(1110);
|
2014-06-13 07:30:21 +00:00
|
|
|
hleReSchedule("vblank wait skipped");
|
2013-01-23 17:45:14 +00:00
|
|
|
return 1;
|
2013-01-12 16:53:23 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblankStartMulti(int vblanks) {
|
2013-05-28 14:39:28 +00:00
|
|
|
if (vblanks <= 0) {
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG(SCEDISPLAY, "sceDisplayWaitVblankStartMulti(%d): invalid number of vblanks", vblanks);
|
2013-05-28 14:39:28 +00:00
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
}
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY, "sceDisplayWaitVblankStartMulti(%d)", vblanks);
|
2013-08-28 06:19:53 +00:00
|
|
|
if (!__KernelIsDispatchEnabled())
|
|
|
|
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
|
2013-08-28 06:41:10 +00:00
|
|
|
if (__IsInInterrupt())
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
|
2015-03-02 02:31:25 +00:00
|
|
|
|
|
|
|
DisplayWaitForVblanks("vblank start multi waited", vblanks);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2012-12-06 17:44:33 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblankCB() {
|
2013-01-12 16:53:23 +00:00
|
|
|
if (!isVblank) {
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"sceDisplayWaitVblankCB()");
|
2015-03-02 02:31:25 +00:00
|
|
|
DisplayWaitForVblanksCB("vblank waited", 1);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2013-01-12 16:53:23 +00:00
|
|
|
} else {
|
2014-01-12 06:59:06 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplayWaitVblankCB() - not waiting since in vBlank");
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(1110);
|
2014-06-13 07:30:21 +00:00
|
|
|
hleReSchedule("vblank wait skipped");
|
2013-01-23 17:45:14 +00:00
|
|
|
return 1;
|
2013-01-12 16:53:23 +00:00
|
|
|
}
|
2012-11-08 15:28:45 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblankStartCB() {
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"sceDisplayWaitVblankStartCB()");
|
2015-03-02 02:31:25 +00:00
|
|
|
DisplayWaitForVblanksCB("vblank start waited", 1);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayWaitVblankStartMultiCB(int vblanks) {
|
2013-05-28 14:39:28 +00:00
|
|
|
if (vblanks <= 0) {
|
2013-09-07 19:19:21 +00:00
|
|
|
WARN_LOG(SCEDISPLAY, "sceDisplayWaitVblankStartMultiCB(%d): invalid number of vblanks", vblanks);
|
2013-05-28 14:39:28 +00:00
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
}
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"sceDisplayWaitVblankStartMultiCB(%d)", vblanks);
|
2013-08-28 06:19:53 +00:00
|
|
|
if (!__KernelIsDispatchEnabled())
|
|
|
|
return SCE_KERNEL_ERROR_CAN_NOT_WAIT;
|
2013-08-28 06:41:10 +00:00
|
|
|
if (__IsInInterrupt())
|
|
|
|
return SCE_KERNEL_ERROR_ILLEGAL_CONTEXT;
|
2015-03-02 02:31:25 +00:00
|
|
|
|
|
|
|
DisplayWaitForVblanksCB("vblank start multi waited", vblanks);
|
2013-01-23 17:45:14 +00:00
|
|
|
return 0;
|
2012-11-18 20:13:27 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetVcount() {
|
2013-09-07 19:19:21 +00:00
|
|
|
VERBOSE_LOG(SCEDISPLAY,"%i=sceDisplayGetVcount()", vCount);
|
2012-12-17 21:52:31 +00:00
|
|
|
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(150);
|
2014-06-18 23:35:16 +00:00
|
|
|
hleReSchedule("get vcount");
|
2012-12-17 21:52:31 +00:00
|
|
|
return vCount;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 __DisplayGetCurrentHcount() {
|
2013-09-03 07:12:48 +00:00
|
|
|
const static int ticksPerVblank333 = 333 * 1000000 / 60 / hCountPerVblank;
|
|
|
|
const int ticksIntoFrame = CoreTiming::GetTicks() - frameStartTicks;
|
2013-09-03 07:09:50 +00:00
|
|
|
// Can't seem to produce a 0 on real hardware, offsetting by 1 makes things look right.
|
2013-09-03 07:12:48 +00:00
|
|
|
return 1 + (ticksIntoFrame / (CoreTiming::GetClockFrequencyMHz() * ticksPerVblank333 / 333));
|
2013-09-03 07:09:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 __DisplayGetAccumulatedHcount() {
|
2013-09-03 07:09:50 +00:00
|
|
|
// The hCount is always a positive int, and wraps from 0x7FFFFFFF -> 0.
|
|
|
|
int value = hCountBase + __DisplayGetCurrentHcount();
|
|
|
|
return value & 0x7FFFFFFF;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetCurrentHcount() {
|
2013-09-03 07:09:50 +00:00
|
|
|
u32 currentHCount = __DisplayGetCurrentHcount();
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "%i=sceDisplayGetCurrentHcount()", currentHCount);
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(275);
|
2013-03-08 01:30:04 +00:00
|
|
|
return currentHCount;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceDisplayAdjustAccumulatedHcount(int value) {
|
2013-09-03 07:09:50 +00:00
|
|
|
if (value < 0) {
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG_REPORT(SCEDISPLAY, "sceDisplayAdjustAccumulatedHcount(%d): invalid value", value);
|
2013-09-03 07:09:50 +00:00
|
|
|
return SCE_KERNEL_ERROR_INVALID_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since it includes the current hCount, find the difference to apply to the base.
|
|
|
|
u32 accumHCount = __DisplayGetAccumulatedHcount();
|
|
|
|
int diff = value - accumHCount;
|
|
|
|
hCountBase += diff;
|
|
|
|
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "sceDisplayAdjustAccumulatedHcount(%d)", value);
|
2013-03-05 13:31:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static int sceDisplayGetAccumulatedHcount() {
|
2013-09-03 07:09:50 +00:00
|
|
|
u32 accumHCount = __DisplayGetAccumulatedHcount();
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY, "%d=sceDisplayGetAccumulatedHcount()", accumHCount);
|
2013-05-05 06:35:46 +00:00
|
|
|
hleEatCycles(235);
|
2013-03-05 13:31:13 +00:00
|
|
|
return accumHCount;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static float sceDisplayGetFramePerSec() {
|
2013-05-18 17:20:13 +00:00
|
|
|
const static float framePerSec = 59.9400599f;
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"%f=sceDisplayGetFramePerSec()", framePerSec);
|
2013-05-18 17:20:13 +00:00
|
|
|
return framePerSec; // (9MHz * 1)/(525 * 286)
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayIsForeground() {
|
2015-07-24 19:48:39 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"IMPL sceDisplayIsForeground()");
|
2013-04-29 17:44:14 +00:00
|
|
|
if (!hasSetMode || framebuf.topaddr == 0)
|
2013-04-30 13:29:18 +00:00
|
|
|
return 0;
|
2013-04-29 17:44:14 +00:00
|
|
|
else
|
2015-07-24 19:48:39 +00:00
|
|
|
return 1; // return value according to JPCSP comment
|
2013-03-05 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetMode(u32 modeAddr, u32 widthAddr, u32 heightAddr) {
|
2013-09-07 19:19:21 +00:00
|
|
|
DEBUG_LOG(SCEDISPLAY,"sceDisplayGetMode(%08x, %08x, %08x)", modeAddr, widthAddr, heightAddr);
|
2013-03-05 13:31:13 +00:00
|
|
|
if (Memory::IsValidAddress(modeAddr))
|
|
|
|
Memory::Write_U32(mode, modeAddr);
|
|
|
|
if (Memory::IsValidAddress(widthAddr))
|
|
|
|
Memory::Write_U32(width, widthAddr);
|
|
|
|
if (Memory::IsValidAddress(heightAddr))
|
|
|
|
Memory::Write_U32(height, heightAddr);
|
|
|
|
return 0;
|
2013-03-03 11:39:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayIsVsync() {
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"UNIMPL sceDisplayIsVsync()");
|
2013-04-30 13:29:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetResumeMode(u32 resumeModeAddr) {
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"sceDisplayGetResumeMode(%08x)", resumeModeAddr);
|
2013-04-30 13:29:18 +00:00
|
|
|
if (Memory::IsValidAddress(resumeModeAddr))
|
|
|
|
Memory::Write_U32(resumeMode, resumeModeAddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplaySetResumeMode(u32 rMode) {
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"sceDisplaySetResumeMode(%08x)", rMode);
|
2013-04-30 13:29:18 +00:00
|
|
|
resumeMode = rMode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplayGetBrightness(u32 levelAddr) {
|
2014-02-04 14:22:06 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"sceDisplayGetBrightness(%08x)", levelAddr);
|
|
|
|
if (Memory::IsValidAddress(levelAddr))
|
|
|
|
Memory::Write_U32(brightnessLevel, levelAddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplaySetBrightness(u32 bLevel) {
|
2014-02-04 14:22:06 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"sceDisplaySetBrightness(%08x)", bLevel);
|
|
|
|
brightnessLevel = bLevel;
|
2013-04-30 13:29:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 09:40:08 +00:00
|
|
|
static u32 sceDisplaySetHoldMode(u32 hMode) {
|
2013-09-07 19:19:21 +00:00
|
|
|
ERROR_LOG(SCEDISPLAY,"sceDisplaySetHoldMode(%08x)", hMode);
|
2013-04-30 13:29:18 +00:00
|
|
|
holdMode = hMode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
const HLEFunction sceDisplay[] = {
|
2015-03-22 23:57:56 +00:00
|
|
|
{0X0E20F177, &WrapU_III<sceDisplaySetMode>, "sceDisplaySetMode", 'x', "iii" },
|
|
|
|
{0X289D82FE, &WrapU_UIII<sceDisplaySetFramebuf>, "sceDisplaySetFrameBuf", 'x', "xiii"},
|
|
|
|
{0XEEDA2E54, &WrapU_UUUI<sceDisplayGetFramebuf>, "sceDisplayGetFrameBuf", 'x', "xxxi"},
|
|
|
|
{0X36CDFADE, &WrapU_V<sceDisplayWaitVblank>, "sceDisplayWaitVblank", 'x', "", HLE_NOT_DISPATCH_SUSPENDED },
|
|
|
|
{0X984C27E7, &WrapU_V<sceDisplayWaitVblankStart>, "sceDisplayWaitVblankStart", 'x', "", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
|
|
|
|
{0X40F1469C, &WrapU_I<sceDisplayWaitVblankStartMulti>, "sceDisplayWaitVblankStartMulti", 'x', "i" },
|
|
|
|
{0X8EB9EC49, &WrapU_V<sceDisplayWaitVblankCB>, "sceDisplayWaitVblankCB", 'x', "", HLE_NOT_DISPATCH_SUSPENDED },
|
|
|
|
{0X46F186C3, &WrapU_V<sceDisplayWaitVblankStartCB>, "sceDisplayWaitVblankStartCB", 'x', "", HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED },
|
|
|
|
{0X77ED8B3A, &WrapU_I<sceDisplayWaitVblankStartMultiCB>, "sceDisplayWaitVblankStartMultiCB", 'x', "i" },
|
|
|
|
{0XDBA6C4C4, &WrapF_V<sceDisplayGetFramePerSec>, "sceDisplayGetFramePerSec", 'f', "" },
|
|
|
|
{0X773DD3A3, &WrapU_V<sceDisplayGetCurrentHcount>, "sceDisplayGetCurrentHcount", 'x', "" },
|
|
|
|
{0X210EAB3A, &WrapI_V<sceDisplayGetAccumulatedHcount>, "sceDisplayGetAccumulatedHcount", 'i', "" },
|
|
|
|
{0XA83EF139, &WrapI_I<sceDisplayAdjustAccumulatedHcount>, "sceDisplayAdjustAccumulatedHcount", 'i', "i" },
|
|
|
|
{0X9C6EAAD7, &WrapU_V<sceDisplayGetVcount>, "sceDisplayGetVcount", 'x', "" },
|
|
|
|
{0XDEA197D4, &WrapU_UUU<sceDisplayGetMode>, "sceDisplayGetMode", 'x', "xxx" },
|
|
|
|
{0X7ED59BC4, &WrapU_U<sceDisplaySetHoldMode>, "sceDisplaySetHoldMode", 'x', "x" },
|
|
|
|
{0XA544C486, &WrapU_U<sceDisplaySetResumeMode>, "sceDisplaySetResumeMode", 'x', "x" },
|
|
|
|
{0XBF79F646, &WrapU_U<sceDisplayGetResumeMode>, "sceDisplayGetResumeMode", 'x', "x" },
|
|
|
|
{0XB4F378FA, &WrapU_V<sceDisplayIsForeground>, "sceDisplayIsForeground", 'x', "" },
|
|
|
|
{0X31C4BAA8, &WrapU_U<sceDisplayGetBrightness>, "sceDisplayGetBrightness", 'x', "x" },
|
|
|
|
{0X9E3C6DC6, &WrapU_U<sceDisplaySetBrightness>, "sceDisplaySetBrightness", 'x', "x" },
|
|
|
|
{0X4D4E10EC, &WrapU_V<sceDisplayIsVblank>, "sceDisplayIsVblank", 'x', "" },
|
|
|
|
{0X21038913, &WrapU_V<sceDisplayIsVsync>, "sceDisplayIsVsync", 'x', "" },
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2012-12-25 14:28:34 +00:00
|
|
|
void Register_sceDisplay() {
|
2012-11-01 15:19:01 +00:00
|
|
|
RegisterModule("sceDisplay", ARRAY_SIZE(sceDisplay), sceDisplay);
|
|
|
|
}
|
2014-02-17 12:46:57 +00:00
|
|
|
|
|
|
|
void Register_sceDisplay_driver() {
|
|
|
|
RegisterModule("sceDisplay_driver", ARRAY_SIZE(sceDisplay), sceDisplay);
|
|
|
|
}
|