Disable the GPU mutex in single core mode. On some platforms it's expensive enough to show up in profiles even though it's useless.

This commit is contained in:
Henrik Rydgard
2017-01-27 10:17:44 +01:00
parent bf104f134c
commit 52a4467a46
3 changed files with 41 additions and 6 deletions

View File

@@ -41,6 +41,7 @@ GPUCommon::GPUCommon() :
// The compiler was not rounding the struct size up to an 8 byte boundary, which
// you'd expect due to the int64 field, but the Linux ABI apparently does not require that.
static_assert(sizeof(DisplayList) == 456, "Bad DisplayList size");
listLock.set_enabled(g_Config.bSeparateCPUThread);
Reinitialize();
SetupColorConv();
@@ -136,7 +137,7 @@ void GPUCommon::PopDLQueue() {
bool GPUCommon::BusyDrawing() {
u32 state = DrawSync(1);
if (state == PSP_GE_LIST_DRAWING || state == PSP_GE_LIST_STALLING) {
lock_guard guard(listLock);
easy_guard guard(listLock);
if (currentList && currentList->state != PSP_GE_DL_STATE_PAUSED) {
return true;
}

View File

@@ -216,12 +216,21 @@ protected:
// Allows early unlocking with a guard. Do not double unlock.
class easy_guard {
public:
easy_guard(recursive_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); }
~easy_guard() { if (locked_) mtx_.unlock(); }
void unlock() { if (locked_) mtx_.unlock(); else Crash(); locked_ = false; }
easy_guard(optional_recursive_mutex &mtx) : mtx_(mtx), locked_(true) { mtx_.lock(); }
~easy_guard() {
if (locked_)
mtx_.unlock();
}
void unlock() {
if (locked_)
mtx_.unlock();
else
Crash();
locked_ = false;
}
private:
recursive_mutex &mtx_;
optional_recursive_mutex &mtx_;
bool locked_;
};
@@ -236,7 +245,7 @@ protected:
DisplayList dls[DisplayListMaxCount];
DisplayList *currentList;
DisplayListQueue dlQueue;
recursive_mutex listLock;
optional_recursive_mutex listLock;
bool interruptRunning;
GPURunState gpuState;

View File

@@ -139,6 +139,31 @@ private:
recursive_mutex &mtx_;
};
// This mutex can be disabled, which is useful for single core mode.
class optional_recursive_mutex {
public:
optional_recursive_mutex() : enabled_(true) {}
void set_enabled(bool enabled) {
enabled_ = enabled;
}
void lock() {
if (enabled_)
mutex_.lock();
}
void unlock() {
if (enabled_)
mutex_.unlock();
}
bool trylock() {
if (enabled_)
return mutex_.trylock();
else
return true;
}
private:
recursive_mutex mutex_;
bool enabled_;
};
// Like a Windows event, or a modern condition variable.