From 54e1f36cd08e62d904f2ad4f27a207c9501c2523 Mon Sep 17 00:00:00 2001 From: Xu Date: Tue, 31 Dec 2024 16:53:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8D=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=B8=A7=E5=B9=B2=E6=89=B0=E9=87=8D=E5=A4=8D=E5=B8=A7=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Magpie.Core/FrameSourceBase.cpp | 6 +----- src/Magpie.Core/FrameSourceBase.h | 4 ++-- src/Magpie.Core/Renderer.cpp | 14 ++++++++++---- src/Magpie/HomeViewModel.cpp | 9 ++++++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Magpie.Core/FrameSourceBase.cpp b/src/Magpie.Core/FrameSourceBase.cpp index ffa6935e..0a6a5243 100644 --- a/src/Magpie.Core/FrameSourceBase.cpp +++ b/src/Magpie.Core/FrameSourceBase.cpp @@ -110,13 +110,9 @@ bool FrameSourceBase::Initialize(DeviceResources& deviceResources, BackendDescri return true; } -FrameSourceState FrameSourceBase::Update(bool forceNewFrame) noexcept { +FrameSourceState FrameSourceBase::Update() noexcept { const FrameSourceState state = _Update(); - if (forceNewFrame) { - return FrameSourceState::NewFrame; - } - const ScalingOptions& options = ScalingWindow::Get().Options(); const auto duplicateFrameDetectionMode = options.duplicateFrameDetectionMode; if (state != FrameSourceState::NewFrame || options.Is3DGameMode() || diff --git a/src/Magpie.Core/FrameSourceBase.h b/src/Magpie.Core/FrameSourceBase.h index efe9160f..44a8c974 100644 --- a/src/Magpie.Core/FrameSourceBase.h +++ b/src/Magpie.Core/FrameSourceBase.h @@ -29,7 +29,7 @@ class FrameSourceBase { bool Initialize(DeviceResources& deviceResources, BackendDescriptorStore& descriptorStore) noexcept; - FrameSourceState Update(bool forceNewFrame) noexcept; + FrameSourceState Update() noexcept; ID3D11Texture2D* GetOutput() noexcept { return _output.get(); @@ -76,7 +76,7 @@ class FrameSourceBase { DeviceResources* _deviceResources = nullptr; BackendDescriptorStore* _descriptorStore = nullptr; winrt::com_ptr _output; - ID3D11ShaderResourceView* _outputSrv; + ID3D11ShaderResourceView* _outputSrv = nullptr; winrt::com_ptr _resultBuffer; ID3D11UnorderedAccessView* _resultBufferUav = nullptr; diff --git a/src/Magpie.Core/Renderer.cpp b/src/Magpie.Core/Renderer.cpp index a2a7d16a..515b91b0 100644 --- a/src/Magpie.Core/Renderer.cpp +++ b/src/Magpie.Core/Renderer.cpp @@ -687,12 +687,18 @@ void Renderer::_BackendThreadProc() noexcept { continue; } - FrameSourceState state = _frameSource->Update(stepTimerStatus == StepTimerStatus::ForceNewFrame); - - if (state == FrameSourceState::NewFrame) { + switch (_frameSource->Update()) { + case FrameSourceState::Waiting: + if (stepTimerStatus != StepTimerStatus::ForceNewFrame) { + break; + } + // 强制帧 + [[fallthrough]]; + case FrameSourceState::NewFrame: _stepTimer.PrepareForRender(); _BackendRender(outputTexture); - } else if (state == FrameSourceState::Error) [[unlikely]] { + break; + case FrameSourceState::Error: // 捕获出错,退出缩放 ScalingWindow::Get().Dispatcher().TryEnqueue([]() { ScalingWindow::Get().RuntimeError(ScalingError::CaptureFailed); diff --git a/src/Magpie/HomeViewModel.cpp b/src/Magpie/HomeViewModel.cpp index 8773a0e7..57475577 100644 --- a/src/Magpie/HomeViewModel.cpp +++ b/src/Magpie/HomeViewModel.cpp @@ -285,8 +285,11 @@ IVector HomeViewModel::MinFrameRateOptions() const { int HomeViewModel::MinFrameRateIndex() const noexcept { float minFrameRate = AppSettings::Get().MinFrameRate(); - auto it = std::find( - MIN_FRAME_RATE_OPTIONS.begin(), MIN_FRAME_RATE_OPTIONS.end(), minFrameRate); + auto it = std::find_if( + MIN_FRAME_RATE_OPTIONS.begin(), + MIN_FRAME_RATE_OPTIONS.end(), + [&](int value) { return std::abs(minFrameRate - value) < 1e-5f; } + ); if (it == MIN_FRAME_RATE_OPTIONS.end()) { return -1; } else { @@ -299,7 +302,7 @@ void HomeViewModel::MinFrameRateIndex(int value) { return; } - AppSettings::Get().MinFrameRate(MIN_FRAME_RATE_OPTIONS[value]); + AppSettings::Get().MinFrameRate((float)MIN_FRAME_RATE_OPTIONS[value]); } bool HomeViewModel::IsDeveloperMode() const noexcept {