mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
perf: 提高 GPU 优先级 (#1146)
This commit is contained in:
parent
b73f19c523
commit
d502ca22a9
1 changed files with 15 additions and 0 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include "OverlayDrawer.h"
|
||||
#include "CursorManager.h"
|
||||
#include "EffectsProfiler.h"
|
||||
#include <d3dkmthk.h>
|
||||
|
||||
namespace Magpie {
|
||||
|
||||
|
|
@ -84,6 +85,17 @@ static void LogAdapter(IDXGIAdapter4* adapter) noexcept {
|
|||
desc.VendorId, desc.DeviceId, StrHelper::UTF16ToUTF8(desc.Description)));
|
||||
}
|
||||
|
||||
static void SetGpuPriority() noexcept {
|
||||
// 来自 https://github.com/obsproject/obs-studio/blob/16cb051a57bb357fe866252c1360ce2c38e2deec/libobs-d3d11/d3d11-subsystem.cpp#L429
|
||||
// 不使用 REALTIME 优先级,它会造成系统不稳定,而且可能会导致源窗口卡顿。
|
||||
// OBS 还调用了 SetGPUThreadPriority,但这个接口似乎无用。
|
||||
NTSTATUS status = D3DKMTSetProcessSchedulingPriorityClass(
|
||||
GetCurrentProcess(), D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH);
|
||||
if (status != STATUS_SUCCESS) {
|
||||
Logger::Get().NTError("D3DKMTSetProcessSchedulingPriorityClass 失败", status);
|
||||
}
|
||||
}
|
||||
|
||||
ScalingError Renderer::Initialize() noexcept {
|
||||
_backendThread = std::thread(std::bind(&Renderer::_BackendThreadProc, this));
|
||||
|
||||
|
|
@ -94,6 +106,9 @@ ScalingError Renderer::Initialize() noexcept {
|
|||
|
||||
LogAdapter(_frontendResources.GetGraphicsAdapter());
|
||||
|
||||
// 每次创建 D3D 设备后尝试提高 GPU 优先级,OBS 也是这么做的
|
||||
SetGpuPriority();
|
||||
|
||||
if (!_CreateSwapChain()) {
|
||||
Logger::Get().Error("_CreateSwapChain 失败");
|
||||
return ScalingError::ScalingFailedGeneral;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue