1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Added VSync=wait setting

This commit is contained in:
narzoul 2024-08-23 23:17:35 +02:00
parent 76dfc38645
commit 16b062d17d
5 changed files with 65 additions and 28 deletions

View File

@ -8,13 +8,13 @@ namespace Config
namespace Settings
{
VSync::VSync()
: EnumSetting("VSync", "app", { "app", "off", "on" })
: EnumSetting("VSync", "app", { "app", "off", "on", "wait"})
{
}
Setting::ParamInfo VSync::getParamInfo() const
{
if (ON == m_value)
if (ON == m_value || WAIT == m_value)
{
return { "Interval", 1, 16, 1 };
}

View File

@ -9,7 +9,7 @@ namespace Config
class VSync : public EnumSetting
{
public:
enum Values { APP, OFF, ON };
enum Values { APP, OFF, ON, WAIT };
VSync();

View File

@ -99,10 +99,13 @@ namespace
UINT getFlipInterval(DWORD flags)
{
auto vSync = Config::vSync.get();
if (Config::Settings::VSync::APP != vSync)
switch (Config::vSync.get())
{
return Config::Settings::VSync::OFF == vSync ? 0 : Config::vSync.getParam();
case Config::Settings::VSync::OFF:
case Config::Settings::VSync::WAIT:
return 0;
case Config::Settings::VSync::ON:
return Config::vSync.getParam();
}
if (flags & DDFLIP_NOVSYNC)
@ -734,12 +737,17 @@ namespace DDraw
return true;
}
bool isUpdateReady = g_isUpdateReady;
auto qpcStart = Time::queryPerformanceCounter();
auto vsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter();
while (static_cast<int>(vsyncCount - g_flipEndVsyncCount) < 0)
{
++vsyncCount;
D3dDdi::KernelModeThunks::waitForVsyncCounter(vsyncCount);
if (isUpdateReady)
{
flush();
}
}
Compat::ScopedCriticalSection lock(g_presentCs);
@ -764,10 +772,10 @@ namespace DDraw
g_qpcPrevWaitEnd = qpcWaitEnd;
Compat::ScopedThreadPriority prio(THREAD_PRIORITY_TIME_CRITICAL);
auto qpcStart = Time::queryPerformanceCounter();
while (Time::qpcToMs(qpcWaitEnd - qpcNow) > 0)
{
Time::waitForNextTick();
flush();
qpcNow = Time::queryPerformanceCounter();
}
@ -775,12 +783,5 @@ namespace DDraw
{
qpcNow = Time::queryPerformanceCounter();
}
Compat::ScopedCriticalSection lock(g_presentCs);
auto qpcEnd = Time::queryPerformanceCounter();
if (g_isUpdatePending)
{
g_qpcUpdateStart += qpcEnd - qpcStart;
}
}
}

View File

@ -1,5 +1,6 @@
#include <Common/CompatPtr.h>
#include <Config/Settings/FpsLimiter.h>
#include <Config/Settings/VSync.h>
#include <D3dDdi/KernelModeThunks.h>
#include <D3dDdi/ScopedCriticalSection.h>
#include <DDraw/DirectDrawClipper.h>
@ -177,19 +178,23 @@ namespace DDraw
caps.dwCaps = DDSCAPS_BACKBUFFER;
getOrigVtable(This).GetAttachedSurface(This, &caps, &surfaceTargetOverride.getRef());
}
HRESULT result = Blt(This, nullptr, surfaceTargetOverride.get(), nullptr, DDBLT_WAIT, nullptr);
if (SUCCEEDED(result) && Config::Settings::FpsLimiter::FLIPEND == Config::fpsLimiter.get())
HRESULT result = SurfaceImpl::Blt(This, nullptr, surfaceTargetOverride.get(), nullptr, DDBLT_WAIT, nullptr);
if (FAILED(result))
{
RealPrimarySurface::waitForFlipFpsLimit();
}
return result;
}
dwFlags = DDFLIP_NOVSYNC;
}
else
{
HRESULT result = SurfaceImpl::Flip(This, surfaceTargetOverride, DDFLIP_WAIT);
if (FAILED(result))
{
return result;
}
}
auto statsWindow = Gdi::GuiThread::getStatsWindow();
if (statsWindow)
@ -199,10 +204,37 @@ namespace DDraw
PrimarySurface::updateFrontResource();
RealPrimarySurface::flip(surfaceTargetOverride, dwFlags);
if (Config::Settings::VSync::WAIT == Config::vSync.get())
{
static UINT lastFlipEnd = 0;
lastFlipEnd += Config::vSync.getParam();
UINT vsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter();
if (static_cast<INT>(vsyncCount - lastFlipEnd) > 0)
{
lastFlipEnd = vsyncCount;
}
RealPrimarySurface::setUpdateReady();
if (0 != RealPrimarySurface::flush())
{
PrimarySurface::waitForIdle();
}
while (static_cast<INT>(vsyncCount - lastFlipEnd) < 0)
{
++vsyncCount;
D3dDdi::KernelModeThunks::waitForVsyncCounter(vsyncCount);
RealPrimarySurface::flush();
}
}
else
{
PrimarySurface::waitForIdle();
}
if (Config::Settings::FpsLimiter::FLIPEND == Config::fpsLimiter.get())
{
DDraw::RealPrimarySurface::waitForFlip(m_data->getDDS());
RealPrimarySurface::waitForFlipFpsLimit();
}
return DD_OK;

View File

@ -22,10 +22,11 @@
# ForceD3D9On12 = off
# FpsLimiter = off
# FullscreenMode = borderless
# GdiStretchBltMode = app
# LogLevel = info
# PalettizedTextures = off
# RemoveBorders = off
# RenderColorDepth = appd8
# RenderColorDepth = 32
# ResolutionScale = app(1)
# ResolutionScaleFilter = point
# SoftwareDevice = rgb
@ -37,15 +38,18 @@
# StatsHotKey = shift+f12
# StatsPosX = right
# StatsPosY = top
# StatsRows = label, presentrate, fliprate, blitcount, lockcount, ddiusage
# StatsRows = label, presentrate, fliprate, blitcount, lockcount
# StatsTransparency = alpha(75)
# StatsUpdateRate = 5
# SupportedDepthFormats = all
# SupportedResolutions = native, 640x480, 800x600, 1024x768
# SupportedTextureFormats = all
# SurfacePatches = none
# TerminateHotKey = ctrl+alt+end
# TextureFilter = app
# ThreadPriorityBoost = off
# VSync = app
# VertexBufferMemoryType = sysmem
# VertexFixup = gpu
# ViewportEdgeFix = off
# WinVersionLie = off