Skip to content

Commit

Permalink
[d3d9] Pass display refresh rate around in windowed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Jan 18, 2025
1 parent 75594db commit 28f284f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
47 changes: 37 additions & 10 deletions src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ namespace dxvk {
// We aren't going to device loss simply because
// 99% of D3D9 games don't handle this properly and
// just end up crashing (like with alt-tab loss)
UpdateDisplayRefreshRate();
UpdateTargetFrameRate(presentInterval);
PresentImage(presentInterval);
return D3D_OK;
Expand Down Expand Up @@ -980,7 +981,11 @@ namespace dxvk {
m_latencyTracker = m_device->createLatencyTracker(entry->second.presenter);
}

m_wctx = &entry->second;
if (m_wctx != &entry->second) {
m_wctx = &entry->second;
m_displayRefreshRateDirty = true;
}

return true;
}

Expand Down Expand Up @@ -1168,9 +1173,35 @@ namespace dxvk {
}


void D3D9SwapChainEx::NotifyDisplayRefreshRate(
double RefreshRate) {
m_displayRefreshRate = RefreshRate;
void D3D9SwapChainEx::UpdateDisplayRefreshRate() {
if (!m_displayRefreshRateDirty)
return;

m_displayRefreshRateDirty = false;

if (!m_monitor && m_window != m_presentParams.hDeviceWindow) {
m_displayRefreshRate = 0.0;
return;
}

HMONITOR monitor = m_monitor;

if (!monitor)
monitor = wsi::getWindowMonitor(m_window);

if (!monitor) {
m_displayRefreshRate = 0.0;
return;
}

wsi::WsiMode wsiMode = { };

if (wsi::getCurrentDisplayMode(monitor, &wsiMode)) {
m_displayRefreshRate = double(wsiMode.refreshRate.numerator)
/ double(wsiMode.refreshRate.denominator);
} else {
m_displayRefreshRate = 0.0;
}
}


Expand Down Expand Up @@ -1250,11 +1281,7 @@ namespace dxvk {
if (!wsi::setWindowMode(monitor, m_window, &m_windowState, wsiMode))
return D3DERR_NOTAVAILABLE;

if (wsi::getCurrentDisplayMode(monitor, &wsiMode))
NotifyDisplayRefreshRate(double(wsiMode.refreshRate.numerator) / double(wsiMode.refreshRate.denominator));
else
NotifyDisplayRefreshRate(0.0);

m_displayRefreshRateDirty = true;
return D3D_OK;
}

Expand All @@ -1266,7 +1293,7 @@ namespace dxvk {
if (!wsi::restoreDisplayMode())
return D3DERR_NOTAVAILABLE;

NotifyDisplayRefreshRate(0.0);
m_displayRefreshRateDirty = true;
return D3D_OK;
}

Expand Down
4 changes: 2 additions & 2 deletions src/d3d9/d3d9_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace dxvk {

wsi::DxvkWindowState m_windowState;

bool m_displayRefreshRateDirty = true;
double m_displayRefreshRate = 0.0;
double m_targetFrameRate = 0.0;

Expand Down Expand Up @@ -215,8 +216,7 @@ namespace dxvk {

void NormalizePresentParameters(D3DPRESENT_PARAMETERS* pPresentParams);

void NotifyDisplayRefreshRate(
double RefreshRate);
void UpdateDisplayRefreshRate();

HRESULT EnterFullscreenMode(
D3DPRESENT_PARAMETERS* pPresentParams,
Expand Down

0 comments on commit 28f284f

Please sign in to comment.