Permalink
Browse files

Merge pull request #10420 from hrydgard/core-cleanup

Some core cleanup
  • Loading branch information...
hrydgard committed Dec 20, 2017
2 parents e882566 + 4f1e0de commit 2bdae5b338dda7cf543a189e3c3fa5f52c1ba869
@@ -699,8 +699,8 @@ elseif(USING_QT_UI)
qt5_wrap_ui(QT_UI_GEN ${Qt_UI}) qt5_wrap_ui(QT_UI_GEN ${Qt_UI})
list(APPEND NativeAppSource list(APPEND NativeAppSource
${QT_UI_GEN} ${QT_UI_GEN}
ext/native/base/QtMain.cpp Qt/QtMain.cpp
ext/native/base/QtMain.h Qt/QtMain.h
Qt/mainwindow.cpp Qt/mainwindow.cpp
Qt/mainwindow.h Qt/mainwindow.h
Qt/Debugger/ctrldisasmview.cpp Qt/Debugger/ctrldisasmview.cpp
@@ -745,7 +745,7 @@ elseif(TARGET SDL2::SDL2)
set(nativeExtra ${nativeExtra} set(nativeExtra ${nativeExtra}
SDL/SDLJoystick.h SDL/SDLJoystick.h
SDL/SDLJoystick.cpp SDL/SDLJoystick.cpp
ext/native/base/PCMain.cpp) SDL/SDLMain.cpp)
set(nativeExtraLibs ${nativeExtraLibs} SDL2::SDL2) set(nativeExtraLibs ${nativeExtraLibs} SDL2::SDL2)
if(APPLE) if(APPLE)
set(nativeExtra ${nativeExtra} SDL/SDLMain.h SDL/SDLMain.mm) set(nativeExtra ${nativeExtra} SDL/SDLMain.h SDL/SDLMain.mm)
@@ -525,12 +525,9 @@ static ConfigSetting graphicsSettings[] = {
#endif #endif
ReportedConfigSetting("ForceMaxEmulatedFPS", &g_Config.iForceMaxEmulatedFPS, 60, true, true), ReportedConfigSetting("ForceMaxEmulatedFPS", &g_Config.iForceMaxEmulatedFPS, 60, true, true),
// TODO: Hm, on fast mobile GPUs we should definitely default to at least 4 (setting = 2)... // Most low-performance (and many high performance) mobile GPUs do not support aniso anyway so defaulting to 4 is fine.
#ifdef MOBILE_DEVICE
ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 0, true, true),
#else
ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 4, true, true), ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 4, true, true),
#endif
ReportedConfigSetting("VertexDecCache", &g_Config.bVertexCache, &DefaultVertexCache, true, true), ReportedConfigSetting("VertexDecCache", &g_Config.bVertexCache, &DefaultVertexCache, true, true),
ReportedConfigSetting("TextureBackoffCache", &g_Config.bTextureBackoffCache, false, true, true), ReportedConfigSetting("TextureBackoffCache", &g_Config.bTextureBackoffCache, false, true, true),
ReportedConfigSetting("TextureSecondaryCache", &g_Config.bTextureSecondaryCache, false, true, true), ReportedConfigSetting("TextureSecondaryCache", &g_Config.bTextureSecondaryCache, false, true, true),
@@ -18,7 +18,9 @@
#include "ppsspp_config.h" #include "ppsspp_config.h"
#include <set> #include <set>
#include <chrono>
#include <mutex> #include <mutex>
#include <condition_variable>
#include "base/NativeApp.h" #include "base/NativeApp.h"
#include "base/display.h" #include "base/display.h"
@@ -46,9 +48,9 @@
// Should this be configurable? 2 hours currently. // Should this be configurable? 2 hours currently.
static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0; static const double ACTIVITY_IDLE_TIMEOUT = 2.0 * 3600.0;
static event m_hStepEvent; static std::condition_variable m_StepCond;
static std::mutex m_hStepMutex; static std::mutex m_hStepMutex;
static event m_hInactiveEvent; static std::condition_variable m_InactiveCond;
static std::mutex m_hInactiveMutex; static std::mutex m_hInactiveMutex;
static bool singleStepPending = false; static bool singleStepPending = false;
static std::set<Core_ShutdownFunc> shutdownFuncs; static std::set<Core_ShutdownFunc> shutdownFuncs;
@@ -95,7 +97,7 @@ void Core_Halt(const char *msg) {
void Core_Stop() { void Core_Stop() {
Core_UpdateState(CORE_POWERDOWN); Core_UpdateState(CORE_POWERDOWN);
Core_NotifyShutdown(); Core_NotifyShutdown();
m_hStepEvent.notify_one(); m_StepCond.notify_one();
} }
bool Core_IsStepping() { bool Core_IsStepping() {
@@ -112,13 +114,15 @@ bool Core_IsInactive() {
void Core_WaitInactive() { void Core_WaitInactive() {
while (Core_IsActive()) { while (Core_IsActive()) {
m_hInactiveEvent.wait(m_hInactiveMutex); std::unique_lock<std::mutex> guard(m_hInactiveMutex);
m_InactiveCond.wait(guard);
} }
} }
void Core_WaitInactive(int milliseconds) { void Core_WaitInactive(int milliseconds) {
if (Core_IsActive()) { if (Core_IsActive()) {
m_hInactiveEvent.wait_for(m_hInactiveMutex, milliseconds); std::unique_lock<std::mutex> guard(m_hInactiveMutex);
m_InactiveCond.wait_for(guard, std::chrono::milliseconds(milliseconds));
} }
} }
@@ -191,11 +195,16 @@ void UpdateRunLoop() {
} }
} }
void KeepScreenAwake() {
#ifdef _WIN32
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
#endif
}
void Core_RunLoop(GraphicsContext *ctx) { void Core_RunLoop(GraphicsContext *ctx) {
graphicsContext = ctx; graphicsContext = ctx;
while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) { while ((GetUIState() != UISTATE_INGAME || !PSP_IsInited()) && GetUIState() != UISTATE_EXIT) {
time_update(); time_update();
#if defined(USING_WIN_UI)
double startTime = time_now_d(); double startTime = time_now_d();
UpdateRunLoop(); UpdateRunLoop();
@@ -204,19 +213,15 @@ void Core_RunLoop(GraphicsContext *ctx) {
double diffTime = time_now_d() - startTime; double diffTime = time_now_d() - startTime;
int sleepTime = (int)(1000.0 / 60.0) - (int)(diffTime * 1000.0); int sleepTime = (int)(1000.0 / 60.0) - (int)(diffTime * 1000.0);
if (sleepTime > 0) if (sleepTime > 0)
Sleep(sleepTime); sleep_ms(sleepTime);
if (!windowHidden) { if (!windowHidden) {
ctx->SwapBuffers(); ctx->SwapBuffers();
} }
#else
UpdateRunLoop();
#endif
} }
while (!coreState && GetUIState() == UISTATE_INGAME) { while (!coreState && GetUIState() == UISTATE_INGAME) {
time_update(); time_update();
UpdateRunLoop(); UpdateRunLoop();
#if defined(USING_WIN_UI)
if (!windowHidden && !Core_IsStepping()) { if (!windowHidden && !Core_IsStepping()) {
ctx->SwapBuffers(); ctx->SwapBuffers();
@@ -226,22 +231,21 @@ void Core_RunLoop(GraphicsContext *ctx) {
// Only resetting it ever prime number seconds in case the call is expensive. // Only resetting it ever prime number seconds in case the call is expensive.
// Using a prime number to ensure there's no interaction with other periodic events. // Using a prime number to ensure there's no interaction with other periodic events.
if (now - lastKeepAwake > 89.0 || now < lastKeepAwake) { if (now - lastKeepAwake > 89.0 || now < lastKeepAwake) {
SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED); KeepScreenAwake();
lastKeepAwake = now; lastKeepAwake = now;
} }
} }
} }
#endif
} }
} }
void Core_DoSingleStep() { void Core_DoSingleStep() {
singleStepPending = true; singleStepPending = true;
m_hStepEvent.notify_one(); m_StepCond.notify_one();
} }
void Core_UpdateSingleStep() { void Core_UpdateSingleStep() {
m_hStepEvent.notify_one(); m_StepCond.notify_one();
} }
void Core_SingleStep() { void Core_SingleStep() {
@@ -251,36 +255,26 @@ void Core_SingleStep() {
static inline void CoreStateProcessed() { static inline void CoreStateProcessed() {
if (coreStatePending) { if (coreStatePending) {
coreStatePending = false; coreStatePending = false;
m_hInactiveEvent.notify_one(); m_InactiveCond.notify_one();
} }
} }
// Some platforms, like Android, do not call this function but handle things on their own. // Many platforms, like Android, do not call this function but handle things on their own.
void Core_Run(GraphicsContext *ctx) // Instead they simply call NativeRender and NativeUpdate directly.
{ void Core_Run(GraphicsContext *ctx) {
#if defined(_DEBUG)
host->UpdateDisassembly(); host->UpdateDisassembly();
#endif while (true) {
#if !defined(USING_QT_UI) || defined(MOBILE_DEVICE)
while (true)
#endif
{
reswitch: reswitch:
if (GetUIState() != UISTATE_INGAME) { if (GetUIState() != UISTATE_INGAME) {
CoreStateProcessed(); CoreStateProcessed();
if (GetUIState() == UISTATE_EXIT) { if (GetUIState() == UISTATE_EXIT) {
return; return;
} }
Core_RunLoop(ctx); Core_RunLoop(ctx);
#if defined(USING_QT_UI) && !defined(MOBILE_DEVICE)
return;
#else
continue; continue;
#endif
} }
switch (coreState) switch (coreState) {
{
case CORE_RUNNING: case CORE_RUNNING:
// enter a fast runloop // enter a fast runloop
Core_RunLoop(ctx); Core_RunLoop(ctx);
@@ -298,21 +292,16 @@ void Core_Run(GraphicsContext *ctx)
} }
// wait for step command.. // wait for step command..
#if defined(USING_QT_UI) || defined(_DEBUG)
host->UpdateDisassembly(); host->UpdateDisassembly();
host->UpdateMemView(); host->UpdateMemView();
host->SendCoreWait(true); host->SendCoreWait(true);
#endif
m_hStepEvent.wait(m_hStepMutex); {
std::unique_lock<std::mutex> guard(m_hStepMutex);
m_StepCond.wait(guard);
}
#if defined(USING_QT_UI) || defined(_DEBUG)
host->SendCoreWait(false); host->SendCoreWait(false);
#endif
#if defined(USING_QT_UI) && !defined(MOBILE_DEVICE)
if (coreState != CORE_STEPPING)
return;
#endif
// No step pending? Let's go back to the wait. // No step pending? Let's go back to the wait.
if (!singleStepPending || coreState != CORE_STEPPING) { if (!singleStepPending || coreState != CORE_STEPPING) {
if (coreState == CORE_POWERDOWN) { if (coreState == CORE_POWERDOWN) {
@@ -323,10 +312,8 @@ void Core_Run(GraphicsContext *ctx)
Core_SingleStep(); Core_SingleStep();
// update disasm dialog // update disasm dialog
#if defined(USING_QT_UI) || defined(_DEBUG)
host->UpdateDisassembly(); host->UpdateDisassembly();
host->UpdateMemView(); host->UpdateMemView();
#endif
break; break;
case CORE_POWERUP: case CORE_POWERUP:
@@ -346,17 +333,12 @@ void Core_Run(GraphicsContext *ctx)
void Core_EnableStepping(bool step) { void Core_EnableStepping(bool step) {
if (step) { if (step) {
sleep_ms(1); sleep_ms(1);
#if defined(_DEBUG)
host->SetDebugMode(true); host->SetDebugMode(true);
#endif
m_hStepEvent.reset();
Core_UpdateState(CORE_STEPPING); Core_UpdateState(CORE_STEPPING);
} else { } else {
#if defined(_DEBUG)
host->SetDebugMode(false); host->SetDebugMode(false);
#endif
coreState = CORE_RUNNING; coreState = CORE_RUNNING;
coreStatePending = false; coreStatePending = false;
m_hStepEvent.notify_one(); m_StepCond.notify_one();
} }
} }
@@ -30,6 +30,7 @@
#include <functional> #include <functional>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <condition_variable>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "profiler/profiler.h" #include "profiler/profiler.h"
@@ -16,6 +16,8 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include <thread> #include <thread>
#include <mutex>
#include <condition_variable>
#include "Core/Reporting.h" #include "Core/Reporting.h"
@@ -24,8 +24,10 @@
#include <string> #include <string>
#include <codecvt> #include <codecvt>
#endif #endif
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <condition_variable>
#include "math/math_util.h" #include "math/math_util.h"
#include "thread/threadutil.h" #include "thread/threadutil.h"
@@ -910,12 +910,7 @@ void TextureCacheCommon::NotifyConfigChanged() {
} }
} }
// Mobile devices don't get the higher scale factors, too expensive. Very rough way to decide though... scaleFactor = std::min(5, scaleFactor);
if (!gstate_c.Supports(GPU_IS_MOBILE)) {
scaleFactor = std::min(5, scaleFactor);
} else {
scaleFactor = std::min(3, scaleFactor);
}
} else { } else {
scaleFactor = g_Config.iTexScalingLevel; scaleFactor = g_Config.iTexScalingLevel;
} }
@@ -342,11 +342,6 @@ void GPU_GLES::CheckGPUFeatures() {
features |= GPU_USE_CLEAR_RAM_HACK; features |= GPU_USE_CLEAR_RAM_HACK;
} }
#ifdef MOBILE_DEVICE
// Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc.
features |= GPU_IS_MOBILE;
#endif
gstate_c.featureFlags = features; gstate_c.featureFlags = features;
} }
@@ -490,7 +490,6 @@ enum {
GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26), GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26),
GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27), GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27),
GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(28), GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(28),
GPU_IS_MOBILE = FLAG_BIT(29),
GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30), GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30),
GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31), GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31),
}; };
File renamed without changes.
File renamed without changes.
@@ -14,7 +14,7 @@
#include "Debugger/debugger_memory.h" #include "Debugger/debugger_memory.h"
#include "Debugger/debugger_memorytex.h" #include "Debugger/debugger_memorytex.h"
#include "Debugger/debugger_displaylist.h" #include "Debugger/debugger_displaylist.h"
#include "base/QtMain.h" #include "Qt/QtMain.h"
extern bool g_TakeScreenshot; extern bool g_TakeScreenshot;
File renamed without changes.
@@ -17,6 +17,8 @@
#include <algorithm> #include <algorithm>
#include <thread> #include <thread>
#include <mutex>
#include <condition_variable>
#include "base/timeutil.h" #include "base/timeutil.h"
#include "ext/vjson/json.h" #include "ext/vjson/json.h"
@@ -19,6 +19,7 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <condition_variable>
#include "input/input_state.h" #include "input/input_state.h"
#include "thread/threadutil.h" #include "thread/threadutil.h"
@@ -111,7 +111,7 @@ void NativeSaveState(); // onDestroy
void NativePermissionStatus(SystemPermission permission, PermissionStatus status); void NativePermissionStatus(SystemPermission permission, PermissionStatus status);
// Calls back into Java / SDL // Calls back into Java / SDL
// These APIs must be implemented by every port (for example app-android.cpp, PCMain.cpp). // These APIs must be implemented by every port (for example app-android.cpp, SDLMain.cpp).
// You are free to call these. // You are free to call these.
void SystemToast(const char *text); void SystemToast(const char *text);
void ShowKeyboard(); void ShowKeyboard();
@@ -299,13 +299,13 @@
<ClCompile Include="base\colorutil.cpp" /> <ClCompile Include="base\colorutil.cpp" />
<ClCompile Include="base\display.cpp" /> <ClCompile Include="base\display.cpp" />
<ClCompile Include="base\logging.cpp" /> <ClCompile Include="base\logging.cpp" />
<ClCompile Include="base\PCMain.cpp"> <ClCompile Include="..\..\SDL\SDLMain.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="base\QtMain.cpp"> <ClCompile Include="..\..\Qt\QtMain.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -761,4 +761,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>
@@ -739,10 +739,10 @@
<ClCompile Include="thread\executor.cpp"> <ClCompile Include="thread\executor.cpp">
<Filter>thread</Filter> <Filter>thread</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="base\PCMain.cpp"> <ClCompile Include="..\..\SDL\SDLMain.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="base\QtMain.cpp"> <ClCompile Include="..\..\Qt\QtMain.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="file\free.cpp"> <ClCompile Include="file\free.cpp">
@@ -868,4 +868,4 @@
<UniqueIdentifier>{06c6305a-a646-485b-85b9-645a24dd6553}</UniqueIdentifier> <UniqueIdentifier>{06c6305a-a646-485b-85b9-645a24dd6553}</UniqueIdentifier>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <limits> #include <limits>
#include <mutex> #include <mutex>
#include <condition_variable>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "thread/threadutil.h" #include "thread/threadutil.h"
Oops, something went wrong.

0 comments on commit 2bdae5b

Please sign in to comment.