Skip to content

Commit

Permalink
fix: 避免强制帧干扰重复帧检测
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Dec 31, 2024
1 parent ae42505 commit 54e1f36
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/Magpie.Core/FrameSourceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
4 changes: 2 additions & 2 deletions src/Magpie.Core/FrameSourceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,7 +76,7 @@ class FrameSourceBase {
DeviceResources* _deviceResources = nullptr;
BackendDescriptorStore* _descriptorStore = nullptr;
winrt::com_ptr<ID3D11Texture2D> _output;
ID3D11ShaderResourceView* _outputSrv;
ID3D11ShaderResourceView* _outputSrv = nullptr;

winrt::com_ptr<ID3D11Buffer> _resultBuffer;
ID3D11UnorderedAccessView* _resultBufferUav = nullptr;
Expand Down
14 changes: 10 additions & 4 deletions src/Magpie.Core/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/Magpie/HomeViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ IVector<IInspectable> 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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 54e1f36

Please sign in to comment.