44#include " Logger.h"
55#include " ScalingWindow.h"
66#include " shaders/DuplicateFrameCS.h"
7+ #include " shaders/DuplicateFrameCS_NoBoundsChecking.h"
78
89namespace Magpie {
910
@@ -18,12 +19,16 @@ DuplicateFrameChecker::DuplicateFrameChecker() noexcept :
1819// 1. D3D11 支持 IDXGIDevice::SetGPUThreadPriority,可以提高 GPU 优先级,
1920// 而 D3D12 没有等价接口。
2021// 2. 对于小任务 D3D11 启动渲染的耗时比 D3D12 短,差距可以达到 50us 以上。
22+ //
23+ // 对于不支持脏矩形且捕获帧右下两边没有多余像素的捕获方式,可以禁用边界检查获得
24+ // 性能提升。
2125bool DuplicateFrameChecker::Initialize (
2226 ID3D11Device5* d3d11Device,
2327 ID3D11DeviceContext4* d3d11DC,
2428 const ColorInfo& colorInfo,
2529 Size frameSize,
26- uint32_t frameCount
30+ uint32_t frameCount,
31+ bool disableBoundsChecking
2732) noexcept {
2833 assert (ScalingWindow::Get ().Options ().duplicateFrameDetectionMode !=
2934 DuplicateFrameDetectionMode::Never);
@@ -32,11 +37,18 @@ bool DuplicateFrameChecker::Initialize(
3237 _deviceContext = d3d11DC;
3338 _isScRGB = colorInfo.kind != winrt::AdvancedColorKind::StandardDynamicRange;
3439 _frameSize = frameSize;
40+ #ifdef _DEBUG
41+ _isBoundsCheckingDisabled = disableBoundsChecking;
42+ #endif
3543
3644 _frameSrvs.resize (frameCount);
3745
3846 HRESULT hr = d3d11Device->CreateComputeShader (
39- DuplicateFrameCS, sizeof (DuplicateFrameCS), nullptr , _dupFrameCS.put ());
47+ disableBoundsChecking ? DuplicateFrameCS_NoBoundsChecking : DuplicateFrameCS,
48+ disableBoundsChecking ? sizeof (DuplicateFrameCS_NoBoundsChecking) : sizeof (DuplicateFrameCS),
49+ nullptr ,
50+ _dupFrameCS.put ()
51+ );
4052 if (FAILED (hr)) {
4153 Logger::Get ().ComError (" CreateComputeShader 失败" , hr);
4254 return false ;
@@ -134,6 +146,13 @@ HRESULT DuplicateFrameChecker::CheckFrame(
134146 D3D11_TEXTURE2D_DESC desc;
135147 frameResource->GetDesc (&desc);
136148 assert (desc.Width == _frameSize.width && desc.Height == _frameSize.height );
149+
150+ if (_isBoundsCheckingDisabled) {
151+ // 确保捕获帧右下两边没有多余像素
152+ for (const Rect& rect : dirtyRects) {
153+ assert (rect.right == desc.Width && rect.bottom == desc.Height );
154+ }
155+ }
137156 }
138157#endif
139158
0 commit comments