Skip to content

Commit 8cfdbb2

Browse files
committed
Present mode override for native D3D (Windows): FIFO, Mailbox and Immediate through the DXGI present
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016GbUfLURPGYGYjaYFdWw5X
1 parent 33f2595 commit 8cfdbb2

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

‎OptiScaler/hooks/FG_Hooks.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,43 @@ HRESULT FGHooks::FGPresent(IDXGISwapChain* This, UINT SyncInterval, UINT Flags,
15391539
LOG_DEBUG("Final SyncInterval: {}", SyncInterval);
15401540
}
15411541

1542+
// Present mode on native D3D (no dxvk/vkd3d-proton swapchain underneath, Windows): FIFO is V-Sync, Mailbox is
1543+
// no V-Sync without tearing (the compositor shows the newest frame), Immediate is no V-Sync with tearing.
1544+
// Takes priority over ForceVsync, applies at the next present.
1545+
if (willPresent && config->VulkanPresentMode.has_value() && state.vkPresentModeMask == 0)
1546+
{
1547+
const int mode = config->VulkanPresentMode.value();
1548+
const int IMMEDIATE = 0, MAILBOX = 1, FIFO = 2;
1549+
1550+
if (mode == FIFO)
1551+
{
1552+
SyncInterval = 1;
1553+
Flags &= ~DXGI_PRESENT_ALLOW_TEARING;
1554+
}
1555+
else if (mode == MAILBOX)
1556+
{
1557+
SyncInterval = 0;
1558+
Flags &= ~DXGI_PRESENT_ALLOW_TEARING;
1559+
}
1560+
else if (mode == IMMEDIATE)
1561+
{
1562+
SyncInterval = 0;
1563+
1564+
DXGI_SWAP_CHAIN_DESC scDesc {};
1565+
if (This->GetDesc(&scDesc) == S_OK && (scDesc.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) != 0 &&
1566+
scDesc.Windowed)
1567+
Flags |= DXGI_PRESENT_ALLOW_TEARING;
1568+
}
1569+
1570+
static int lastMode = -1;
1571+
if (mode != lastMode)
1572+
{
1573+
LOG_INFO("Present mode {} on DXGI: SyncInterval {}, tearing {}", mode, SyncInterval,
1574+
(Flags & DXGI_PRESENT_ALLOW_TEARING) != 0);
1575+
lastMode = mode;
1576+
}
1577+
}
1578+
15421579
// FSR-FG and XeFG with the Reflex output: the game's present as DLSSG reports it
15431580
ID3D12CommandQueue* gameQueue = nullptr;
15441581
uint32_t frameMultiplier = 1;

‎OptiScaler/menu/menu_common.cpp‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9371,11 +9371,12 @@ void MenuCommon::RenderVsyncSettings(RenderMenuContext& ctx)
93719371
}
93729372
}
93739373

9374-
// Vulkan games, and D3D games under Proton once dxvk/vkd3d-proton's swapchain is seen (its present mode list)
9375-
if (state.swapchainApi == Vulkan || state.vkPresentModeMask != 0)
9374+
// Vulkan games, D3D games under Proton once dxvk/vkd3d-proton's swapchain is seen (its present mode list), and
9375+
// native D3D games (Windows), where FIFO, Mailbox and Immediate map to the DXGI present's sync interval and tearing
93769376
{
9377-
const bool underProton = state.swapchainApi != Vulkan;
9378-
SectionTitle(underProton ? "Present Mode (Proton)" : "V-Sync Settings");
9377+
const bool underProton = state.swapchainApi != Vulkan && state.vkPresentModeMask != 0;
9378+
const bool nativeDxgi = state.swapchainApi != Vulkan && state.vkPresentModeMask == 0;
9379+
SectionTitle(underProton ? "Present Mode (Proton)" : (nativeDxgi ? "Present Mode" : "V-Sync Settings"));
93799380
{
93809381
ScopedID sectionId { "Vulkan Present Mode" };
93819382

@@ -9395,7 +9396,9 @@ void MenuCommon::RenderVsyncSettings(RenderMenuContext& ctx)
93959396
{
93969397
const auto& entry = VulkanHooks::PresentModes[i];
93979398

9398-
if ((state.vkPresentModeMask & (1u << i)) == 0)
9399+
if (nativeDxgi ? (entry.mode != VK_PRESENT_MODE_IMMEDIATE_KHR && entry.mode != VK_PRESENT_MODE_MAILBOX_KHR &&
9400+
entry.mode != VK_PRESENT_MODE_FIFO_KHR)
9401+
: (state.vkPresentModeMask & (1u << i)) == 0)
93999402
continue;
94009403

94019404
if (ImGui::Selectable(entry.name, forced.has_value() && forced.value() == entry.mode))
@@ -9415,7 +9418,10 @@ void MenuCommon::RenderVsyncSettings(RenderMenuContext& ctx)
94159418
"FIFO Relaxed: V-Sync, tears when below the refresh rate.\n"
94169419
"FIFO Latest Ready: V-Sync, shows the newest ready frame at each refresh.\n\n"
94179420
"Mailbox and FIFO Latest Ready can drop generated frames above the refresh rate.\n"
9418-
"Only modes the display supports are listed.");
9421+
"Only modes the display supports are listed.\n\n"
9422+
"D3D games on Windows: FIFO is V-Sync, Mailbox is no V-Sync without tearing (windowed or\n"
9423+
"borderless), Immediate is no V-Sync with tearing. Applies at the next frame and takes\n"
9424+
"priority over Override Vsync.");
94199425

94209426
if (state.vkGamePresentMode >= 0)
94219427
ImGui::Text("Game's present mode: %s", VulkanHooks::PresentModeName(state.vkGamePresentMode));

0 commit comments

Comments
 (0)