Never change the thread priority on the host and the disable boost flag too

This fixes almost all the games that were broken in this branch
This commit is contained in:
ergo720 2023-04-05 17:48:31 +02:00 committed by RadWolfie
parent 0e63131fc3
commit ad6769bbf3
1 changed files with 3 additions and 40 deletions

View File

@ -1404,13 +1404,7 @@ XBSYSAPI EXPORTNUM(124) xbox::long_xt NTAPI xbox::KeQueryBasePriorityThread
KIRQL OldIrql;
KiLockDispatcherDatabase(&OldIrql);
long_xt ret;
if (const auto &nativeHandle = GetNativeHandle<true>(reinterpret_cast<PETHREAD>(Thread)->UniqueThread)) {
ret = GetThreadPriority(*nativeHandle);
}
else {
ret = Thread->Priority;
}
long_xt ret = Thread->Priority;
KiUnlockDispatcherDatabase(OldIrql);
@ -1855,32 +1849,8 @@ XBSYSAPI EXPORTNUM(143) xbox::long_xt NTAPI xbox::KeSetBasePriorityThread
KIRQL oldIRQL;
KiLockDispatcherDatabase(&oldIRQL);
long_xt ret;
if (const auto &nativeHandle = GetNativeHandle<true>(reinterpret_cast<PETHREAD>(Thread)->UniqueThread)) {
ret = GetThreadPriority(*nativeHandle);
if (Priority == 16) {
Priority = THREAD_PRIORITY_TIME_CRITICAL;
}
else if (Priority == -16) {
Priority = THREAD_PRIORITY_IDLE;
}
// HACK: only change the priority if set above normal. Test case: Black. It calls this to set the priority of a thread to THREAD_PRIORITY_LOWEST, and that same
// thread calls D3DDevice_BlockUntilVerticalBlank. The problem arises because there is also another thread that runs at higher priority and calls D3DDevice_BlockUntilVerticalBlank
// too to wait on the vblank kevent. When the vblank does occur, this other thread will satisfy the wait first, and set the kevent back to non-signalled. Thus, the other
// thread will miss the signal because typically, Windows won't re-schedule it after many more vblank have already occured. The proper solution is to boost the priority of
// the thread when the kevent is signalled, with the increment argument specified in KeSetEvent. Such boosts should also be appiled whenever a thread satisfies a wait.
if (Priority <= THREAD_PRIORITY_NORMAL) {
BOOL result = SetThreadPriority(*nativeHandle, Priority);
if (!result) {
EmuLog(LOG_LEVEL::WARNING, "SetThreadPriority failed: %s", WinError2Str().c_str());
}
}
}
else {
ret = Thread->Priority;
}
Thread->Priority = Priority;
long_xt ret = Thread->Priority;
KiUnlockDispatcherDatabase(oldIRQL);
@ -1901,13 +1871,6 @@ XBSYSAPI EXPORTNUM(144) xbox::boolean_xt NTAPI xbox::KeSetDisableBoostThread
KIRQL oldIRQL;
KiLockDispatcherDatabase(&oldIRQL);
if (const auto &nativeHandle = GetNativeHandle<true>(reinterpret_cast<PETHREAD>(Thread)->UniqueThread)) {
BOOL bRet = SetThreadPriorityBoost(*nativeHandle, Disable);
if (!bRet) {
EmuLog(LOG_LEVEL::WARNING, "SetThreadPriorityBoost failed: %s", WinError2Str().c_str());
}
}
boolean_xt prevDisableBoost = Thread->DisableBoost;
Thread->DisableBoost = (CHAR)Disable;