Skip to content

Commit

Permalink
[d3d9] Limit frame rate to display refresh as necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Jun 10, 2024
1 parent 95a905c commit 88bdabe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ namespace dxvk {
if (!m_wctx->presenter->hasSwapChain())
return D3D_OK;

UpdateTargetFrameRate(presentInterval);
PresentImage(presentInterval);
return D3D_OK;
} catch (const DxvkError& e) {
Expand Down Expand Up @@ -927,7 +928,6 @@ namespace dxvk {
presenterDesc.fullScreenExclusive = PickFullscreenMode();

m_wctx->presenter = new Presenter(m_device, m_wctx->frameLatencySignal, presenterDesc);
m_wctx->presenter->setFrameRateLimit(m_parent->GetOptions()->maxFrameRate);
}


Expand Down Expand Up @@ -1107,6 +1107,17 @@ namespace dxvk {
}


void D3D9SwapChainEx::UpdateTargetFrameRate(uint32_t SyncInterval) {
double frameRateOption = double(m_parent->GetOptions()->maxFrameRate);
double frameRate = std::max(frameRateOption, 0.0);

if (SyncInterval && frameRateOption == 0.0)
frameRate = -m_displayRefreshRate / double(SyncInterval);

m_wctx->presenter->setFrameRateLimit(frameRate);
}


void D3D9SwapChainEx::SyncFrameLatency() {
// Wait for the sync event so that we respect the maximum frame latency
m_wctx->frameLatencySignal->wait(m_wctx->frameId - GetActualFrameLatency());
Expand Down
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ namespace dxvk {

void InitRamp();

void UpdateTargetFrameRate(uint32_t SyncInterval);

uint32_t GetActualFrameLatency();

uint32_t PickFormats(
Expand Down

0 comments on commit 88bdabe

Please sign in to comment.