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

Compare commits

..

No commits in common. "master" and "v0.5.3" have entirely different histories.

33 changed files with 166 additions and 374 deletions

View File

@ -50,7 +50,6 @@
#include <Config/Settings/ThreadPriorityBoost.h> #include <Config/Settings/ThreadPriorityBoost.h>
#include <Config/Settings/VertexBufferMemoryType.h> #include <Config/Settings/VertexBufferMemoryType.h>
#include <Config/Settings/VertexFixup.h> #include <Config/Settings/VertexFixup.h>
#include <Config/Settings/ViewportEdgeFix.h>
#include <Config/Settings/VSync.h> #include <Config/Settings/VSync.h>
#include <Config/Settings/WinVersionLie.h> #include <Config/Settings/WinVersionLie.h>
@ -108,7 +107,6 @@ namespace Config
Settings::ThreadPriorityBoost threadPriorityBoost; Settings::ThreadPriorityBoost threadPriorityBoost;
Settings::VertexBufferMemoryType vertexBufferMemoryType; Settings::VertexBufferMemoryType vertexBufferMemoryType;
Settings::VertexFixup vertexFixup; Settings::VertexFixup vertexFixup;
Settings::ViewportEdgeFix viewportEdgeFix;
Settings::VSync vSync; Settings::VSync vSync;
Settings::WinVersionLie winVersionLie; Settings::WinVersionLie winVersionLie;
} }

View File

@ -1,18 +1,16 @@
#pragma once #pragma once
#include <Config/EnumSetting.h> #include <Config/BoolSetting.h>
namespace Config namespace Config
{ {
namespace Settings namespace Settings
{ {
class ForceD3D9On12 : public EnumSetting class ForceD3D9On12 : public BoolSetting
{ {
public: public:
enum Values { FORCEOFF, OFF, ON };
ForceD3D9On12() ForceD3D9On12()
: EnumSetting("ForceD3D9On12", "off", { "forceoff", "off", "on" }) : BoolSetting("ForceD3D9On12", "off")
{ {
} }
}; };

View File

@ -23,9 +23,6 @@ namespace Config
LOCKCOUNT, LOCKCOUNT,
LOCKRATE, LOCKRATE,
LOCKTIME, LOCKTIME,
VBLANKCOUNT,
VBLANKRATE,
VBLANKTIME,
DDIUSAGE, DDIUSAGE,
GDIOBJECTS, GDIOBJECTS,
DEBUG, DEBUG,
@ -48,9 +45,6 @@ namespace Config
"lockcount", "lockcount",
"lockrate", "lockrate",
"locktime", "locktime",
"vblankcount",
"vblankrate",
"vblanktime",
"ddiusage", "ddiusage",
"gdiobjects", "gdiobjects",
"debug" "debug"

View File

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

View File

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

View File

@ -1,32 +0,0 @@
#pragma once
#include <Config/EnumSetting.h>
namespace Config
{
namespace Settings
{
class ViewportEdgeFix : public EnumSetting
{
public:
enum Values { OFF, SCALE };
ViewportEdgeFix()
: EnumSetting("ViewportEdgeFix", "off", { "off", "scale" })
{
}
virtual ParamInfo getParamInfo() const override
{
switch (m_value)
{
case SCALE:
return { "Gap", 1, 100, 50 };
}
return {};
}
};
}
extern Settings::ViewportEdgeFix viewportEdgeFix;
}

View File

@ -437,7 +437,7 @@ namespace D3dDdi
pCreateData->Interface = origInterface; pCreateData->Interface = origInterface;
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
DeviceFuncs::hookVtable(*pCreateData->pDeviceFuncs, std::min(m_runtimeVersion, m_driverVersion)); DeviceFuncs::hookVtable(*pCreateData->pDeviceFuncs, m_driverVersion);
Device::add(*this, pCreateData->hDevice); Device::add(*this, pCreateData->hDevice);
} }
return result; return result;

View File

@ -586,6 +586,33 @@ namespace D3dDdi
m_state.updateConfig(); m_state.updateConfig();
} }
void Device::waitForIdle()
{
D3dDdi::ScopedCriticalSection lock;
flushPrimitives();
D3DDDIARG_ISSUEQUERY issueQuery = {};
issueQuery.hQuery = m_eventQuery;
issueQuery.Flags.End = 1;
m_origVtable.pfnIssueQuery(m_device, &issueQuery);
if (m_origVtable.pfnFlush1)
{
m_origVtable.pfnFlush1(m_device, 0);
}
else
{
m_origVtable.pfnFlush(m_device);
}
BOOL result = FALSE;
D3DDDIARG_GETQUERYDATA getQueryData = {};
getQueryData.hQuery = m_eventQuery;
getQueryData.pData = &result;
while (S_FALSE == m_origVtable.pfnGetQueryData(m_device, &getQueryData))
{
}
}
std::map<HANDLE, Device> Device::s_devices; std::map<HANDLE, Device> Device::s_devices;
bool Device::s_isFlushEnabled = true; bool Device::s_isFlushEnabled = true;
} }

View File

@ -72,6 +72,7 @@ namespace D3dDdi
void setDepthStencil(HANDLE resource); void setDepthStencil(HANDLE resource);
void setRenderTarget(const D3DDDIARG_SETRENDERTARGET& data); void setRenderTarget(const D3DDDIARG_SETRENDERTARGET& data);
void updateConfig(); void updateConfig();
void waitForIdle();
static void add(Adapter& adapter, HANDLE device); static void add(Adapter& adapter, HANDLE device);
static Device& get(HANDLE device) { return s_devices.find(device)->second; } static Device& get(HANDLE device) { return s_devices.find(device)->second; }

View File

@ -16,7 +16,6 @@
#include <D3dDdi/ShaderAssembler.h> #include <D3dDdi/ShaderAssembler.h>
#include <Overlay/Steam.h> #include <Overlay/Steam.h>
#include <Shaders/VertexFixup.h> #include <Shaders/VertexFixup.h>
#include <Config/Settings/ViewportEdgeFix.h>
#define LOG_DS LOG_DEBUG << "DeviceState::" << __func__ << ": " #define LOG_DS LOG_DEBUG << "DeviceState::" << __func__ << ": "
@ -550,18 +549,10 @@ namespace D3dDdi
} }
} }
HRESULT result = m_device.getOrigVtable().pfnCreateVertexShaderDecl(m_device, data, vertexElements); HRESULT result = m_device.getOrigVtable().pfnCreateVertexShaderDecl(m_device, data, ve.data());
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
if (decl.isTransformed) m_vertexShaderDecls[data->ShaderHandle] = decl;
{
D3DDDIARG_CREATEVERTEXSHADERDECL d = *data;
d.ShaderHandle = nullptr;
m_device.getOrigVtable().pfnCreateVertexShaderDecl(m_device, &d, ve.data());
decl.untransformedDecl = std::unique_ptr<void, ResourceDeleter>(
d.ShaderHandle, ResourceDeleter(m_device, m_device.getOrigVtable().pfnDeleteVertexShaderDecl));
}
m_vertexShaderDecls.emplace(data->ShaderHandle, std::move(decl));
} }
return result; return result;
} }
@ -902,7 +893,7 @@ namespace D3dDdi
if (spriteMode != m_spriteMode) if (spriteMode != m_spriteMode)
{ {
m_spriteMode = spriteMode; m_spriteMode = spriteMode;
m_changedStates |= CS_RENDER_STATE | CS_RENDER_TARGET | CS_TEXTURE_STAGE; m_changedStates |= CS_RENDER_STATE | CS_TEXTURE_STAGE;
m_changedRenderStates.set(D3DDDIRS_MULTISAMPLEANTIALIAS); m_changedRenderStates.set(D3DDDIRS_MULTISAMPLEANTIALIAS);
if (Config::Settings::SpriteTexCoord::ROUND == Config::spriteTexCoord.get()) if (Config::Settings::SpriteTexCoord::ROUND == Config::spriteTexCoord.get())
{ {
@ -1245,17 +1236,15 @@ namespace D3dDdi
void DeviceState::updateShaders() void DeviceState::updateShaders()
{ {
setPixelShader(mapPixelShader(m_app.pixelShader)); setPixelShader(mapPixelShader(m_app.pixelShader));
setVertexShaderDecl(m_app.vertexShaderDecl);
auto& vertexDecl = getVertexDecl();
if (Config::Settings::VertexFixup::GPU == m_vertexFixupConfig && if (Config::Settings::VertexFixup::GPU == m_vertexFixupConfig &&
vertexDecl.isTransformed) getVertexDecl().isTransformed)
{ {
setVertexShaderDecl(vertexDecl.untransformedDecl.get());
setVertexShaderFunc(getVsVertexFixup()); setVertexShaderFunc(getVsVertexFixup());
} }
else else
{ {
setVertexShaderDecl(m_app.vertexShaderDecl);
setVertexShaderFunc(m_app.vertexShaderFunc); setVertexShaderFunc(m_app.vertexShaderFunc);
} }
} }
@ -1354,21 +1343,17 @@ namespace D3dDdi
const float apc = Config::alternatePixelCenter.get(); const float apc = Config::alternatePixelCenter.get();
const auto& zr = m_current.zRange; const auto& zr = m_current.zRange;
const float viewportEdgeGap = m_spriteMode ? 0 : (Config::viewportEdgeFix.getParam() / 100.0f);
const float w = width - viewportEdgeGap;
const float h = height - viewportEdgeGap;
m_vertexFixupData.texCoordAdj[2] = stc; m_vertexFixupData.texCoordAdj[2] = stc;
m_vertexFixupData.texCoordAdj[3] = stc; m_vertexFixupData.texCoordAdj[3] = stc;
if (Config::Settings::VertexFixup::GPU == m_vertexFixupConfig) if (Config::Settings::VertexFixup::GPU == m_vertexFixupConfig)
{ {
m_vertexFixupData.offset[0] = 0.5f + apc - 0.5f / sx - w / 2; m_vertexFixupData.offset[0] = 0.5f + apc - 0.5f / sx - width / 2;
m_vertexFixupData.offset[1] = 0.5f + apc - 0.5f / sy - h / 2; m_vertexFixupData.offset[1] = 0.5f + apc - 0.5f / sy - height / 2;
m_vertexFixupData.offset[2] = -zr.MinZ; m_vertexFixupData.offset[2] = -zr.MinZ;
m_vertexFixupData.multiplier[0] = 2.0f / w; m_vertexFixupData.multiplier[0] = 2.0f / width;
m_vertexFixupData.multiplier[1] = -2.0f / h; m_vertexFixupData.multiplier[1] = -2.0f / height;
m_vertexFixupData.multiplier[2] = 1.0f / (zr.MaxZ - zr.MinZ); m_vertexFixupData.multiplier[2] = 1.0f / (zr.MaxZ - zr.MinZ);
} }
else else
@ -1376,8 +1361,8 @@ namespace D3dDdi
m_vertexFixupData.offset[0] = 0.5f + apc - 0.5f / sx; m_vertexFixupData.offset[0] = 0.5f + apc - 0.5f / sx;
m_vertexFixupData.offset[1] = 0.5f + apc - 0.5f / sy; m_vertexFixupData.offset[1] = 0.5f + apc - 0.5f / sy;
m_vertexFixupData.multiplier[0] = sx * width / w; m_vertexFixupData.multiplier[0] = sx;
m_vertexFixupData.multiplier[1] = sy * height / h; m_vertexFixupData.multiplier[1] = sy;
} }
m_changedStates |= CS_VERTEX_FIXUP; m_changedStates |= CS_VERTEX_FIXUP;

View File

@ -103,7 +103,6 @@ namespace D3dDdi
struct VertexDecl struct VertexDecl
{ {
std::unique_ptr<void, ResourceDeleter> untransformedDecl;
std::vector<D3DDDIVERTEXELEMENT> elements; std::vector<D3DDDIVERTEXELEMENT> elements;
std::array<UINT, 8> texCoordOffset; std::array<UINT, 8> texCoordOffset;
std::array<UINT, 8> texCoordType; std::array<UINT, 8> texCoordType;

View File

@ -213,7 +213,7 @@ namespace D3dDdi
bool DrawPrimitive::appendPrimitives(D3DPRIMITIVETYPE primitiveType, INT baseVertexIndex, UINT primitiveCount, bool DrawPrimitive::appendPrimitives(D3DPRIMITIVETYPE primitiveType, INT baseVertexIndex, UINT primitiveCount,
const UINT16* indices, UINT minIndex, UINT maxIndex) const UINT16* indices, UINT minIndex, UINT maxIndex)
{ {
if ((m_batched.primitiveCount + primitiveCount) * 3 > D3DMAXNUMVERTICES) if (m_batched.primitiveCount + primitiveCount > D3DMAXNUMPRIMITIVES)
{ {
return false; return false;
} }

View File

@ -121,7 +121,7 @@ namespace
pOpenData->Interface = origInterface; pOpenData->Interface = origInterface;
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
D3dDdi::AdapterFuncs::hookVtable(*pOpenData->pAdapterFuncs, std::min(pOpenData->Version, pOpenData->DriverVersion)); D3dDdi::AdapterFuncs::hookVtable(*pOpenData->pAdapterFuncs, pOpenData->DriverVersion);
D3dDdi::Adapter::add(*pOpenData); D3dDdi::Adapter::add(*pOpenData);
} }
return result; return result;

View File

@ -19,10 +19,8 @@
#include <DDraw/RealPrimarySurface.h> #include <DDraw/RealPrimarySurface.h>
#include <DDraw/ScopedThreadLock.h> #include <DDraw/ScopedThreadLock.h>
#include <DDraw/Surfaces/PrimarySurface.h> #include <DDraw/Surfaces/PrimarySurface.h>
#include <Gdi/GuiThread.h>
#include <Gdi/Palette.h> #include <Gdi/Palette.h>
#include <Gdi/Window.h> #include <Gdi/Window.h>
#include <Overlay/StatsWindow.h>
#include <Win32/DisplayMode.h> #include <Win32/DisplayMode.h>
#include <Win32/DpiAwareness.h> #include <Win32/DpiAwareness.h>
@ -163,7 +161,7 @@ namespace
{ {
return -1; return -1;
} }
return data.InVerticalBlank ? 0 : data.ScanLine; return data.ScanLine;
} }
void getVidPnSource(D3DKMT_HANDLE& adapter, UINT& vidPnSourceId) void getVidPnSource(D3DKMT_HANDLE& adapter, UINT& vidPnSourceId)
@ -212,7 +210,7 @@ namespace
switch (pData->Type) switch (pData->Type)
{ {
case KMTQAITYPE_UMDRIVERNAME: case KMTQAITYPE_UMDRIVERNAME:
if (Config::Settings::ForceD3D9On12::ON == Config::forceD3D9On12.get() && if (Config::forceD3D9On12.get() &&
KMTUMDVERSION_DX9 == static_cast<D3DKMT_UMDFILENAMEINFO*>(pData->pPrivateDriverData)->Version) KMTUMDVERSION_DX9 == static_cast<D3DKMT_UMDFILENAMEINFO*>(pData->pPrivateDriverData)->Version)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
@ -239,7 +237,7 @@ namespace
} }
} }
} }
else if (Config::Settings::ForceD3D9On12::FORCEOFF == Config::forceD3D9On12.get() && else if (!Config::forceD3D9On12.get() &&
KMTQAITYPE_UMDRIVERNAME == pData->Type && KMTQAITYPE_UMDRIVERNAME == pData->Type &&
KMTUMDVERSION_DX9 == static_cast<D3DKMT_UMDFILENAMEINFO*>(pData->pPrivateDriverData)->Version) KMTUMDVERSION_DX9 == static_cast<D3DKMT_UMDFILENAMEINFO*>(pData->pPrivateDriverData)->Version)
{ {
@ -367,13 +365,6 @@ namespace
} }
WakeAllConditionVariable(&g_vsyncCounterCv); WakeAllConditionVariable(&g_vsyncCounterCv);
auto statsWindow = Gdi::GuiThread::getStatsWindow();
if (statsWindow)
{
statsWindow->m_vblank.add();
}
} }
return 0; return 0;
} }

View File

@ -1851,46 +1851,4 @@ namespace D3dDdi
m_palettizedTexture->m_isPalettizedTextureUpToDate = true; m_palettizedTexture->m_isPalettizedTextureUpToDate = true;
m_paletteColorKeyIndex = paletteColorKeyIndex; m_paletteColorKeyIndex = paletteColorKeyIndex;
} }
void Resource::waitForIdle(UINT subResourceIndex)
{
m_device.flushPrimitives();
Resource* srcResource = this;
RECT rect = { 0, 0, 1, 1 };
if (m_lockResource)
{
if (m_lockData[subResourceIndex].isMsaaUpToDate ||
m_lockData[subResourceIndex].isMsaaResolvedUpToDate)
{
if (!m_lockData[subResourceIndex].isMsaaResolvedUpToDate)
{
copySubResourceRegion(*m_msaaResolvedSurface.resource, subResourceIndex, rect,
*m_msaaSurface.resource, subResourceIndex, rect);
}
srcResource = m_msaaResolvedSurface.resource;
}
else if (!m_lockData[subResourceIndex].isVidMemUpToDate)
{
return;
}
}
auto& syncSurface = m_device.getRepo().getSyncSurface(srcResource->m_fixedData.Format);
if (!syncSurface.resource)
{
return;
}
copySubResourceRegion(*syncSurface.resource, 0, rect, *srcResource, subResourceIndex, rect);
D3DDDIARG_LOCK lock = {};
lock.hResource = *syncSurface.resource;
lock.Flags.ReadOnly = 1;
m_device.getOrigVtable().pfnLock(m_device, &lock);
D3DDDIARG_UNLOCK unlock = {};
unlock.hResource = *syncSurface.resource;
m_device.getOrigVtable().pfnUnlock(m_device, &unlock);
}
} }

View File

@ -66,7 +66,6 @@ namespace D3dDdi
HRESULT unlock(const D3DDDIARG_UNLOCK& data); HRESULT unlock(const D3DDDIARG_UNLOCK& data);
void updateConfig(); void updateConfig();
void updatePalettizedTexture(UINT stage); void updatePalettizedTexture(UINT stage);
void waitForIdle(UINT subResourceIndex);
static void enableConfig(bool enable); static void enableConfig(bool enable);
static void setFormatOverride(D3DDDIFORMAT format); static void setFormatOverride(D3DDDIFORMAT format);

View File

@ -333,11 +333,6 @@ namespace D3dDdi
return surface; return surface;
} }
SurfaceRepository::Surface& SurfaceRepository::getSyncSurface(D3DDDIFORMAT format)
{
return getSurface(m_syncSurface[format], 16, 16, format, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY);
}
SurfaceRepository::Surface& SurfaceRepository::getTempSurface(Surface& surface, DWORD width, DWORD height, SurfaceRepository::Surface& SurfaceRepository::getTempSurface(Surface& surface, DWORD width, DWORD height,
D3DDDIFORMAT format, DWORD caps, UINT surfaceCount) D3DDDIFORMAT format, DWORD caps, UINT surfaceCount)
{ {

View File

@ -49,7 +49,6 @@ namespace D3dDdi
const Resource* currentSrcRt = nullptr, const Resource* currentDstRt = nullptr); const Resource* currentSrcRt = nullptr, const Resource* currentDstRt = nullptr);
Surface& getSurface(Surface& surface, DWORD width, DWORD height, Surface& getSurface(Surface& surface, DWORD width, DWORD height,
D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1, DWORD caps2 = 0); D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1, DWORD caps2 = 0);
Surface& getSyncSurface(D3DDDIFORMAT format);
Surface& getTempSysMemSurface(DWORD width, DWORD height); Surface& getTempSysMemSurface(DWORD width, DWORD height);
Surface& getTempSurface(Surface& surface, DWORD width, DWORD height, Surface& getTempSurface(Surface& surface, DWORD width, DWORD height,
D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1); D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1);
@ -90,7 +89,6 @@ namespace D3dDdi
std::array<Surface, 3> m_hqRenderTargets; std::array<Surface, 3> m_hqRenderTargets;
std::map<D3DDDIFORMAT, Surface> m_textures; std::map<D3DDDIFORMAT, Surface> m_textures;
std::vector<Surface> m_releasedSurfaces; std::vector<Surface> m_releasedSurfaces;
std::map<D3DDDIFORMAT, Surface> m_syncSurface;
Surface m_sysMemSurface; Surface m_sysMemSurface;
Surface m_windowedBackBuffer; Surface m_windowedBackBuffer;
CompatPtr<IDirectDrawSurface7> m_windowedPrimary; CompatPtr<IDirectDrawSurface7> m_windowedPrimary;

View File

@ -99,13 +99,10 @@ namespace
UINT getFlipInterval(DWORD flags) UINT getFlipInterval(DWORD flags)
{ {
switch (Config::vSync.get()) auto vSync = Config::vSync.get();
if (Config::Settings::VSync::APP != vSync)
{ {
case Config::Settings::VSync::OFF: return Config::Settings::VSync::OFF == vSync ? 0 : Config::vSync.getParam();
case Config::Settings::VSync::WAIT:
return 0;
case Config::Settings::VSync::ON:
return Config::vSync.getParam();
} }
if (flags & DDFLIP_NOVSYNC) if (flags & DDFLIP_NOVSYNC)
@ -512,9 +509,10 @@ namespace DDraw
return DD_OK; return DD_OK;
} }
void RealPrimarySurface::flip(CompatPtr<IDirectDrawSurface7> surfaceTargetOverride, DWORD flags) HRESULT RealPrimarySurface::flip(CompatPtr<IDirectDrawSurface7> surfaceTargetOverride, DWORD flags)
{ {
const DWORD flipInterval = getFlipInterval(flags); const DWORD flipInterval = getFlipInterval(flags);
PrimarySurface::waitForIdle();
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);
scheduleUpdate(); scheduleUpdate();
@ -529,6 +527,8 @@ namespace DDraw
{ {
g_lastFlipSurface = nullptr; g_lastFlipSurface = nullptr;
} }
return DD_OK;
} }
int RealPrimarySurface::flush() int RealPrimarySurface::flush()
@ -737,17 +737,12 @@ namespace DDraw
return true; return true;
} }
bool isUpdateReady = g_isUpdateReady;
auto qpcStart = Time::queryPerformanceCounter(); auto qpcStart = Time::queryPerformanceCounter();
auto vsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter(); auto vsyncCount = D3dDdi::KernelModeThunks::getVsyncCounter();
while (static_cast<int>(vsyncCount - g_flipEndVsyncCount) < 0) while (static_cast<int>(vsyncCount - g_flipEndVsyncCount) < 0)
{ {
++vsyncCount; ++vsyncCount;
D3dDdi::KernelModeThunks::waitForVsyncCounter(vsyncCount); D3dDdi::KernelModeThunks::waitForVsyncCounter(vsyncCount);
if (isUpdateReady)
{
flush();
}
} }
Compat::ScopedCriticalSection lock(g_presentCs); Compat::ScopedCriticalSection lock(g_presentCs);
@ -772,10 +767,10 @@ namespace DDraw
g_qpcPrevWaitEnd = qpcWaitEnd; g_qpcPrevWaitEnd = qpcWaitEnd;
Compat::ScopedThreadPriority prio(THREAD_PRIORITY_TIME_CRITICAL); Compat::ScopedThreadPriority prio(THREAD_PRIORITY_TIME_CRITICAL);
auto qpcStart = Time::queryPerformanceCounter();
while (Time::qpcToMs(qpcWaitEnd - qpcNow) > 0) while (Time::qpcToMs(qpcWaitEnd - qpcNow) > 0)
{ {
Time::waitForNextTick(); Time::waitForNextTick();
flush();
qpcNow = Time::queryPerformanceCounter(); qpcNow = Time::queryPerformanceCounter();
} }
@ -783,5 +778,12 @@ namespace DDraw
{ {
qpcNow = Time::queryPerformanceCounter(); qpcNow = Time::queryPerformanceCounter();
} }
Compat::ScopedCriticalSection lock(g_presentCs);
auto qpcEnd = Time::queryPerformanceCounter();
if (g_isUpdatePending)
{
g_qpcUpdateStart += qpcEnd - qpcStart;
}
} }
} }

View File

@ -13,7 +13,7 @@ namespace DDraw
{ {
public: public:
static HRESULT create(CompatRef<IDirectDraw> dd); static HRESULT create(CompatRef<IDirectDraw> dd);
static void flip(CompatPtr<IDirectDrawSurface7> surfaceTargetOverride, DWORD flags); static HRESULT flip(CompatPtr<IDirectDrawSurface7> surfaceTargetOverride, DWORD flags);
static int flush(); static int flush();
static HRESULT getGammaRamp(DDGAMMARAMP* rampData); static HRESULT getGammaRamp(DDGAMMARAMP* rampData);
static HWND getPresentationWindow(); static HWND getPresentationWindow();

View File

@ -3,7 +3,6 @@
#include <D3dDdi/Device.h> #include <D3dDdi/Device.h>
#include <D3dDdi/KernelModeThunks.h> #include <D3dDdi/KernelModeThunks.h>
#include <D3dDdi/Resource.h> #include <D3dDdi/Resource.h>
#include <D3dDdi/ScopedCriticalSection.h>
#include <D3dDdi/SurfaceRepository.h> #include <D3dDdi/SurfaceRepository.h>
#include <DDraw/DirectDraw.h> #include <DDraw/DirectDraw.h>
#include <DDraw/DirectDrawSurface.h> #include <DDraw/DirectDrawSurface.h>
@ -18,10 +17,10 @@
namespace namespace
{ {
CompatWeakPtr<IDirectDrawSurface7> g_primarySurface; CompatWeakPtr<IDirectDrawSurface7> g_primarySurface;
D3dDdi::Device* g_device = nullptr;
HANDLE g_gdiDriverResource = nullptr; HANDLE g_gdiDriverResource = nullptr;
HANDLE g_gdiRuntimeResource = nullptr; HANDLE g_gdiRuntimeResource = nullptr;
D3dDdi::Resource* g_frontResource = nullptr; HANDLE g_frontResource = nullptr;
UINT g_frontResourceIndex = 0;
DWORD g_origCaps = 0; DWORD g_origCaps = 0;
HWND g_deviceWindow = nullptr; HWND g_deviceWindow = nullptr;
HPALETTE g_palette = nullptr; HPALETTE g_palette = nullptr;
@ -35,10 +34,10 @@ namespace DDraw
{ {
LOG_FUNC("PrimarySurface::~PrimarySurface"); LOG_FUNC("PrimarySurface::~PrimarySurface");
g_device = nullptr;
g_gdiRuntimeResource = nullptr; g_gdiRuntimeResource = nullptr;
g_gdiDriverResource = nullptr; g_gdiDriverResource = nullptr;
g_frontResource = nullptr; g_frontResource = nullptr;
g_frontResourceIndex = 0;
g_primarySurface = nullptr; g_primarySurface = nullptr;
g_origCaps = 0; g_origCaps = 0;
g_deviceWindow = nullptr; g_deviceWindow = nullptr;
@ -112,6 +111,7 @@ namespace DDraw
ResizePalette(g_palette, 256); ResizePalette(g_palette, 256);
} }
g_device = D3dDdi::Device::findDeviceByResource(DirectDrawSurface::getDriverResourceHandle(*surface));
data->restore(); data->restore();
D3dDdi::Device::updateAllConfig(); D3dDdi::Device::updateAllConfig();
return LOG_RESULT(DD_OK); return LOG_RESULT(DD_OK);
@ -215,7 +215,7 @@ namespace DDraw
HANDLE PrimarySurface::getFrontResource() HANDLE PrimarySurface::getFrontResource()
{ {
return *g_frontResource; return g_frontResource;
} }
HANDLE PrimarySurface::getGdiResource() HANDLE PrimarySurface::getGdiResource()
@ -260,7 +260,7 @@ namespace DDraw
g_gdiRuntimeResource = DirectDrawSurface::getRuntimeResourceHandle(*g_primarySurface); g_gdiRuntimeResource = DirectDrawSurface::getRuntimeResourceHandle(*g_primarySurface);
updateFrontResource(); updateFrontResource();
g_gdiDriverResource = *g_frontResource; g_gdiDriverResource = g_frontResource;
D3dDdi::Device::setGdiResourceHandle(g_gdiDriverResource); D3dDdi::Device::setGdiResourceHandle(g_gdiDriverResource);
DDSCAPS2 caps = {}; DDSCAPS2 caps = {};
@ -324,8 +324,7 @@ namespace DDraw
void PrimarySurface::updateFrontResource() void PrimarySurface::updateFrontResource()
{ {
g_frontResource = D3dDdi::Device::findResource(DirectDrawSurface::getDriverResourceHandle(*g_primarySurface)); g_frontResource = DirectDrawSurface::getDriverResourceHandle(*g_primarySurface);
g_frontResourceIndex = DirectDrawSurface::getSubResourceIndex(*g_primarySurface);
} }
void PrimarySurface::updatePalette() void PrimarySurface::updatePalette()
@ -361,8 +360,10 @@ namespace DDraw
void PrimarySurface::waitForIdle() void PrimarySurface::waitForIdle()
{ {
D3dDdi::ScopedCriticalSection lock; if (g_device)
g_frontResource->waitForIdle(g_frontResourceIndex); {
g_device->waitForIdle();
}
} }
CompatWeakPtr<IDirectDrawPalette> PrimarySurface::s_palette; CompatWeakPtr<IDirectDrawPalette> PrimarySurface::s_palette;

View File

@ -1,6 +1,5 @@
#include <Common/CompatPtr.h> #include <Common/CompatPtr.h>
#include <Config/Settings/FpsLimiter.h> #include <Config/Settings/FpsLimiter.h>
#include <Config/Settings/VSync.h>
#include <D3dDdi/KernelModeThunks.h> #include <D3dDdi/KernelModeThunks.h>
#include <D3dDdi/ScopedCriticalSection.h> #include <D3dDdi/ScopedCriticalSection.h>
#include <DDraw/DirectDrawClipper.h> #include <DDraw/DirectDrawClipper.h>
@ -178,22 +177,18 @@ namespace DDraw
caps.dwCaps = DDSCAPS_BACKBUFFER; caps.dwCaps = DDSCAPS_BACKBUFFER;
getOrigVtable(This).GetAttachedSurface(This, &caps, &surfaceTargetOverride.getRef()); getOrigVtable(This).GetAttachedSurface(This, &caps, &surfaceTargetOverride.getRef());
} }
HRESULT result = Blt(This, nullptr, surfaceTargetOverride.get(), nullptr, DDBLT_WAIT, nullptr);
HRESULT result = SurfaceImpl::Blt(This, nullptr, surfaceTargetOverride.get(), nullptr, DDBLT_WAIT, nullptr); if (SUCCEEDED(result) && Config::Settings::FpsLimiter::FLIPEND == Config::fpsLimiter.get())
if (FAILED(result))
{ {
return result; RealPrimarySurface::waitForFlipFpsLimit();
} }
return result;
dwFlags = DDFLIP_NOVSYNC;
} }
else
HRESULT result = SurfaceImpl::Flip(This, surfaceTargetOverride, DDFLIP_WAIT);
if (FAILED(result))
{ {
HRESULT result = SurfaceImpl::Flip(This, surfaceTargetOverride, DDFLIP_WAIT); return result;
if (FAILED(result))
{
return result;
}
} }
auto statsWindow = Gdi::GuiThread::getStatsWindow(); auto statsWindow = Gdi::GuiThread::getStatsWindow();
@ -203,41 +198,13 @@ namespace DDraw
} }
PrimarySurface::updateFrontResource(); PrimarySurface::updateFrontResource();
RealPrimarySurface::flip(surfaceTargetOverride, dwFlags); result = RealPrimarySurface::flip(surfaceTargetOverride, dwFlags);
if (SUCCEEDED(result) && Config::Settings::FpsLimiter::FLIPEND == Config::fpsLimiter.get())
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(); RealPrimarySurface::waitForFlipFpsLimit();
} }
return DD_OK; return result;
} }
template <typename TSurface> template <typename TSurface>

View File

@ -72,7 +72,7 @@
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
@ -110,7 +110,7 @@
<AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir);$(IntDir)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;version.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>dwmapi.lib;dxguid.lib;imm32.lib;msimg32.lib;oleacc.lib;uxtheme.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary> <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
@ -216,7 +216,6 @@
<ClInclude Include="Config\Settings\ThreadPriorityBoost.h" /> <ClInclude Include="Config\Settings\ThreadPriorityBoost.h" />
<ClInclude Include="Config\Settings\VertexBufferMemoryType.h" /> <ClInclude Include="Config\Settings\VertexBufferMemoryType.h" />
<ClInclude Include="Config\Settings\VertexFixup.h" /> <ClInclude Include="Config\Settings\VertexFixup.h" />
<ClInclude Include="Config\Settings\ViewportEdgeFix.h" />
<ClInclude Include="Config\Settings\VSync.h" /> <ClInclude Include="Config\Settings\VSync.h" />
<ClInclude Include="Config\Settings\WinVersionLie.h" /> <ClInclude Include="Config\Settings\WinVersionLie.h" />
<ClInclude Include="D3dDdi\Adapter.h" /> <ClInclude Include="D3dDdi\Adapter.h" />

View File

@ -723,9 +723,6 @@
<ClInclude Include="Config\Settings\GdiStretchBltMode.h"> <ClInclude Include="Config\Settings\GdiStretchBltMode.h">
<Filter>Header Files\Config\Settings</Filter> <Filter>Header Files\Config\Settings</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Config\Settings\ViewportEdgeFix.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Gdi\Gdi.cpp"> <ClCompile Include="Gdi\Gdi.cpp">

View File

@ -215,7 +215,7 @@ namespace Gdi
POINT pos = {}; POINT pos = {};
CALL_ORIG_FUNC(GetCursorPos)(&pos); CALL_ORIG_FUNC(GetCursorPos)(&pos);
SetCursorPos(pos.x, pos.y); CALL_ORIG_FUNC(SetCursorPos)(pos.x, pos.y);
} }
void setMonitorClipRect(const RECT& rect) void setMonitorClipRect(const RECT& rect)

View File

@ -23,8 +23,6 @@ namespace
case SPI_SETFONTSMOOTHING: case SPI_SETFONTSMOOTHING:
g_isFontSmoothingEnabled = 0 != uiParam; g_isFontSmoothingEnabled = 0 != uiParam;
return TRUE; return TRUE;
case SPI_SETSHOWIMEUI:
return TRUE;
} }
return LOG_RESULT(origSystemParametersInfo(uiAction, uiParam, pvParam, fWinIni)); return LOG_RESULT(origSystemParametersInfo(uiAction, uiParam, pvParam, fWinIni));
} }

View File

@ -21,7 +21,6 @@
#include <Overlay/Steam.h> #include <Overlay/Steam.h>
#include <Overlay/Window.h> #include <Overlay/Window.h>
#include <Win32/DisplayMode.h> #include <Win32/DisplayMode.h>
#include <Win32/DpiAwareness.h>
namespace namespace
{ {
@ -30,6 +29,7 @@ namespace
HOOKPROC origHookProc; HOOKPROC origHookProc;
LPARAM origHookStruct; LPARAM origHookStruct;
MSLLHOOKSTRUCT hookStruct; MSLLHOOKSTRUCT hookStruct;
DWORD dpiScale;
}; };
struct HotKeyData struct HotKeyData
@ -43,6 +43,7 @@ namespace
SIZE g_bmpArrowSize = {}; SIZE g_bmpArrowSize = {};
Overlay::Control* g_capture = nullptr; Overlay::Control* g_capture = nullptr;
POINT g_cursorPos = {}; POINT g_cursorPos = {};
POINT g_origCursorPos = { MAXLONG, MAXLONG };
HWND g_cursorWindow = nullptr; HWND g_cursorWindow = nullptr;
std::map<Input::HotKey, HotKeyData> g_hotKeys; std::map<Input::HotKey, HotKeyData> g_hotKeys;
RECT g_monitorRect = {}; RECT g_monitorRect = {};
@ -55,7 +56,7 @@ namespace
LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK lowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK lowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam);
POINT physicalToLogicalPoint(POINT pt); POINT physicalToLogicalPoint(POINT pt, DWORD dpiScale);
LRESULT CALLBACK cursorWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK cursorWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
@ -105,22 +106,7 @@ namespace
if (WM_MOUSEMOVE == wParam) if (WM_MOUSEMOVE == wParam)
{ {
if (Win32::DpiAwareness::isMixedModeSupported()) data.hookStruct.pt = physicalToLogicalPoint(data.hookStruct.pt, data.dpiScale);
{
POINT logicalCursorPos = {};
GetCursorPos(&logicalCursorPos);
Win32::ScopedDpiAwareness dpiAwareness;
POINT physicalCursorPos = {};
GetCursorPos(&physicalCursorPos);
data.hookStruct.pt.x = logicalCursorPos.x + data.hookStruct.pt.x - physicalCursorPos.x;
data.hookStruct.pt.y = logicalCursorPos.y + data.hookStruct.pt.y - physicalCursorPos.y;
}
else
{
data.hookStruct.pt = physicalToLogicalPoint(data.hookStruct.pt);
}
} }
else else
{ {
@ -132,6 +118,13 @@ namespace
return g_dinputMouseHookData.origHookProc(nCode, wParam, lParam); return g_dinputMouseHookData.origHookProc(nCode, wParam, lParam);
} }
DWORD getDpiScaleForCursorPos()
{
POINT cp = {};
CALL_ORIG_FUNC(GetCursorPos)(&cp);
return Win32::DisplayMode::getMonitorInfo(cp).dpiScale;
}
LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{ {
if (HC_ACTION == nCode && if (HC_ACTION == nCode &&
@ -185,23 +178,25 @@ namespace
if (WM_MOUSEMOVE == wParam) if (WM_MOUSEMOVE == wParam)
{ {
POINT origCursorPos = {}; if (MAXLONG == g_origCursorPos.y)
POINT newCursorPos = llHook.pt;
if (Win32::DpiAwareness::isMixedModeSupported())
{ {
Win32::ScopedDpiAwareness dpiAwareness; if (llHook.flags & LLMHF_INJECTED)
CALL_ORIG_FUNC(GetCursorPos)(&origCursorPos); {
llHook.pt = {}; if (MAXLONG == g_origCursorPos.x)
} {
else g_origCursorPos.x = llHook.pt.x;
{ }
CALL_ORIG_FUNC(GetCursorPos)(&origCursorPos); else
newCursorPos = physicalToLogicalPoint(llHook.pt); {
g_origCursorPos.y = llHook.pt.y;
}
}
return 1;
} }
POINT cp = g_cursorPos; POINT cp = g_cursorPos;
cp.x += newCursorPos.x - origCursorPos.x; cp.x += llHook.pt.x - g_origCursorPos.x;
cp.y += newCursorPos.y - origCursorPos.y; cp.y += llHook.pt.y - g_origCursorPos.y;
cp.x = std::min(std::max(g_monitorRect.left, cp.x), g_monitorRect.right); cp.x = std::min(std::max(g_monitorRect.left, cp.x), g_monitorRect.right);
cp.y = std::min(std::max(g_monitorRect.top, cp.y), g_monitorRect.bottom); cp.y = std::min(std::max(g_monitorRect.top, cp.y), g_monitorRect.bottom);
g_cursorPos = cp; g_cursorPos = cp;
@ -245,14 +240,13 @@ namespace
TerminateProcess(GetCurrentProcess(), 0); TerminateProcess(GetCurrentProcess(), 0);
} }
POINT physicalToLogicalPoint(POINT pt) POINT physicalToLogicalPoint(POINT pt, DWORD dpiScale)
{ {
if (g_physicalToLogicalPointForPerMonitorDPI) if (g_physicalToLogicalPointForPerMonitorDPI)
{ {
g_physicalToLogicalPointForPerMonitorDPI(nullptr, &pt); g_physicalToLogicalPointForPerMonitorDPI(nullptr, &pt);
return pt; return pt;
} }
auto dpiScale = Win32::DisplayMode::getMonitorInfo(pt).dpiScale;
return { MulDiv(pt.x, 100, dpiScale), MulDiv(pt.y, 100, dpiScale) }; return { MulDiv(pt.x, 100, dpiScale), MulDiv(pt.y, 100, dpiScale) };
} }
@ -293,28 +287,46 @@ namespace
}); });
} }
void resetMouseHookFunc()
{
if (g_mouseHook)
{
UnhookWindowsHookEx(g_mouseHook);
}
g_origCursorPos = { MAXLONG, MAXLONG };
g_mouseHook = CALL_ORIG_FUNC(SetWindowsHookExA)(
WH_MOUSE_LL, &lowLevelMouseProc, Dll::g_origDDrawModule, 0);
if (g_mouseHook)
{
INPUT inputs[2] = {};
inputs[0].mi.dy = 1;
inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE;
inputs[1].mi.dx = 1;
inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(2, inputs, sizeof(INPUT));
}
else
{
LOG_ONCE("ERROR: Failed to install low level mouse hook, error code: " << GetLastError());
}
}
void resetMouseHook() void resetMouseHook()
{ {
Gdi::GuiThread::execute([]() Gdi::GuiThread::executeAsyncFunc(resetMouseHookFunc);
{ }
if (!g_capture)
{
return;
}
if (g_mouseHook) BOOL WINAPI setCursorPos(int X, int Y)
{ {
UnhookWindowsHookEx(g_mouseHook); LOG_FUNC("SetCursorPos", X, Y);
} auto result = CALL_ORIG_FUNC(SetCursorPos)(X, Y);
if (result && g_mouseHook)
g_mouseHook = CALL_ORIG_FUNC(SetWindowsHookExA)( {
WH_MOUSE_LL, &lowLevelMouseProc, Dll::g_origDDrawModule, 0); resetMouseHook();
}
if (!g_mouseHook) return LOG_RESULT(result);
{
LOG_ONCE("ERROR: Failed to install low level mouse hook, error code: " << GetLastError());
}
});
} }
HHOOK setWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId, HHOOK setWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId,
@ -333,6 +345,11 @@ namespace
(0 == _stricmp(moduleName.c_str(), "dinput") || 0 == _stricmp(moduleName.c_str(), "dinput8"))) (0 == _stricmp(moduleName.c_str(), "dinput") || 0 == _stricmp(moduleName.c_str(), "dinput8")))
{ {
g_dinputMouseHookData.origHookProc = lpfn; g_dinputMouseHookData.origHookProc = lpfn;
if (!g_physicalToLogicalPointForPerMonitorDPI)
{
g_dinputMouseHookData.dpiScale = getDpiScaleForCursorPos();
}
lpfn = dinputLowLevelMouseProc; lpfn = dinputLowLevelMouseProc;
Compat::hookIatFunction(hmod, "CallNextHookEx", dinputCallNextHookEx); Compat::hookIatFunction(hmod, "CallNextHookEx", dinputCallNextHookEx);
} }
@ -424,6 +441,7 @@ namespace Input
GetProcAddress(GetModuleHandle("user32"), "PhysicalToLogicalPointForPerMonitorDPI")); GetProcAddress(GetModuleHandle("user32"), "PhysicalToLogicalPointForPerMonitorDPI"));
HOOK_FUNCTION(user32, RegisterRawInputDevices, registerRawInputDevices); HOOK_FUNCTION(user32, RegisterRawInputDevices, registerRawInputDevices);
HOOK_FUNCTION(user32, SetCursorPos, setCursorPos);
HOOK_FUNCTION(user32, SetWindowsHookExA, setWindowsHookExA); HOOK_FUNCTION(user32, SetWindowsHookExA, setWindowsHookExA);
HOOK_FUNCTION(user32, SetWindowsHookExW, setWindowsHookExW); HOOK_FUNCTION(user32, SetWindowsHookExW, setWindowsHookExW);

View File

@ -27,7 +27,6 @@
#include <Config/Settings/StatsTransparency.h> #include <Config/Settings/StatsTransparency.h>
#include <Config/Settings/TextureFilter.h> #include <Config/Settings/TextureFilter.h>
#include <Config/Settings/VertexFixup.h> #include <Config/Settings/VertexFixup.h>
#include <Config/Settings/ViewportEdgeFix.h>
#include <Config/Settings/VSync.h> #include <Config/Settings/VSync.h>
#include <D3dDdi/Device.h> #include <D3dDdi/Device.h>
#include <Gdi/Gdi.h> #include <Gdi/Gdi.h>
@ -72,7 +71,6 @@ namespace
{ &Config::statsTransparency, [&]() { Gdi::GuiThread::getStatsWindow()->setAlpha(Config::statsTransparency.get()); }}, { &Config::statsTransparency, [&]() { Gdi::GuiThread::getStatsWindow()->setAlpha(Config::statsTransparency.get()); }},
{ &Config::textureFilter, &D3dDdi::Device::updateAllConfig }, { &Config::textureFilter, &D3dDdi::Device::updateAllConfig },
{ &Config::vertexFixup, &D3dDdi::Device::updateAllConfig }, { &Config::vertexFixup, &D3dDdi::Device::updateAllConfig },
{ &Config::viewportEdgeFix },
{ &Config::vSync } { &Config::vSync }
}; };
} }

View File

@ -110,9 +110,6 @@ namespace Overlay
m_statsRows.push_back({ "Lock count", UpdateStats(m_lock.m_count), &m_lock.m_count }); m_statsRows.push_back({ "Lock count", UpdateStats(m_lock.m_count), &m_lock.m_count });
m_statsRows.push_back({ "Lock rate", UpdateStats(m_lock.m_rate), &m_lock.m_rate }); m_statsRows.push_back({ "Lock rate", UpdateStats(m_lock.m_rate), &m_lock.m_rate });
m_statsRows.push_back({ "Lock time", UpdateStats(m_lock.m_time), &m_lock.m_time }); m_statsRows.push_back({ "Lock time", UpdateStats(m_lock.m_time), &m_lock.m_time });
m_statsRows.push_back({ "VBlank count", UpdateStats(m_vblank.m_count), &m_vblank.m_count });
m_statsRows.push_back({ "VBlank rate", UpdateStats(m_vblank.m_rate), &m_vblank.m_rate });
m_statsRows.push_back({ "VBlank time", UpdateStats(m_vblank.m_time), &m_vblank.m_time });
m_statsRows.push_back({ "DDI usage", UpdateStats(m_ddiUsage), &m_ddiUsage }); m_statsRows.push_back({ "DDI usage", UpdateStats(m_ddiUsage), &m_ddiUsage });
m_statsRows.push_back({ "GDI objects", UpdateStats(m_gdiObjects), &m_gdiObjects }); m_statsRows.push_back({ "GDI objects", UpdateStats(m_gdiObjects), &m_gdiObjects });
m_statsRows.push_back({ "", &getDebugInfo, nullptr, WS_VISIBLE | WS_GROUP }); m_statsRows.push_back({ "", &getDebugInfo, nullptr, WS_VISIBLE | WS_GROUP });
@ -138,7 +135,6 @@ namespace Overlay
m_flip.enable(); m_flip.enable();
m_blit.enable(); m_blit.enable();
m_lock.enable(); m_lock.enable();
m_vblank.enable();
} }
StatsControl& StatsWindow::addControl(const std::string& name, StatsControl::UpdateFunc updateFunc, DWORD style) StatsControl& StatsWindow::addControl(const std::string& name, StatsControl::UpdateFunc updateFunc, DWORD style)

View File

@ -28,7 +28,6 @@ namespace Overlay
StatsEventGroup m_flip; StatsEventGroup m_flip;
StatsEventGroup m_blit; StatsEventGroup m_blit;
StatsEventGroup m_lock; StatsEventGroup m_lock;
StatsEventGroup m_vblank;
StatsTimer m_ddiUsage; StatsTimer m_ddiUsage;
StatsQueue m_gdiObjects; StatsQueue m_gdiObjects;

View File

@ -318,7 +318,7 @@ namespace
LSTATUS WINAPI regEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName, LSTATUS WINAPI regEnumValueW(HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName,
LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
{ {
LOG_FUNC("RegEnumValueW", hKey, dwIndex, Compat::out(lpValueName), lpcchValueName, lpReserved, lpType, lpData, lpcbData); LOG_FUNC("RegEnumValueW", hKey, dwIndex, lpValueName, lpcchValueName, lpReserved, lpType, lpData, lpcbData);
if (lpValueName && lpcchValueName && !lpReserved && !lpType && !lpData && !lpcbData) if (lpValueName && lpcchValueName && !lpReserved && !lpType && !lpData && !lpcbData)
{ {
auto keyName(getKeyName(hKey)); auto keyName(getKeyName(hKey));

View File

@ -2,9 +2,7 @@
#include <Common/Hook.h> #include <Common/Hook.h>
#include <Common/Log.h> #include <Common/Log.h>
#include <Common/Path.h>
#include <Config/Settings/WinVersionLie.h> #include <Config/Settings/WinVersionLie.h>
#include <Dll/Dll.h>
#include <Win32/Version.h> #include <Win32/Version.h>
@ -12,55 +10,6 @@
namespace namespace
{ {
DWORD getModuleFileName(HMODULE mod, char* filename, DWORD size)
{
return GetModuleFileNameA(mod, filename, size);
}
DWORD getModuleFileName(HMODULE mod, wchar_t* filename, DWORD size)
{
return GetModuleFileNameW(mod, filename, size);
}
HMODULE getModuleHandle(const char* moduleName)
{
return GetModuleHandleA(moduleName);
}
HMODULE getModuleHandle(const wchar_t* moduleName)
{
return GetModuleHandleW(moduleName);
}
template <typename Char>
void fixVersionInfoFileName(const Char*& filename)
{
if (getModuleHandle(filename) == Dll::g_currentModule)
{
static Char path[MAX_PATH];
if (0 != getModuleFileName(Dll::g_origDDrawModule, path, MAX_PATH))
{
filename = path;
}
}
}
template <auto func, typename Result, typename Char, typename... Params>
Result WINAPI getFileVersionInfoFunc(const Char* filename ,Params... params)
{
LOG_FUNC(Compat::g_origFuncName<func>.c_str(), filename, params...);
fixVersionInfoFileName(filename);
return LOG_RESULT(CALL_ORIG_FUNC(func)(filename, params...));
}
template <auto func, typename Result, typename Char, typename... Params>
Result WINAPI getFileVersionInfoFunc(DWORD flags, const Char* filename, Params... params)
{
LOG_FUNC(Compat::g_origFuncName<func>.c_str(), filename, params...);
fixVersionInfoFileName(filename);
return LOG_RESULT(CALL_ORIG_FUNC(func)(flags, filename, params...));
}
DWORD WINAPI getVersion() DWORD WINAPI getVersion()
{ {
LOG_FUNC("GetVersion"); LOG_FUNC("GetVersion");
@ -115,53 +64,14 @@ namespace
{ {
return getVersionInfo<OSVERSIONINFOEXW>(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW"); return getVersionInfo<OSVERSIONINFOEXW>(lpVersionInformation, CALL_ORIG_FUNC(GetVersionExW), "GetVersionExW");
} }
template <auto origFunc>
bool hookVersionInfoFunc(const char* moduleName, const char* funcName)
{
HMODULE mod = GetModuleHandle(moduleName);
if (mod)
{
FARPROC func = Compat::getProcAddress(mod, funcName);
if (func)
{
Compat::hookFunction<origFunc>(moduleName, funcName, getFileVersionInfoFunc<origFunc>);
return true;
}
}
return false;
}
template <auto origFunc>
void hookVersionInfoFunc(const char* funcName)
{
hookVersionInfoFunc<origFunc>("kernelbase", funcName) || hookVersionInfoFunc<origFunc>("version", funcName);
}
} }
namespace Compat
{
template<> decltype(&GetFileVersionInfoExA) g_origFuncPtr<GetFileVersionInfoExA> = nullptr;
template<> decltype(&GetFileVersionInfoSizeExA) g_origFuncPtr<GetFileVersionInfoSizeExA> = nullptr;
}
#define HOOK_VERSION_INFO_FUNCTION(func) hookVersionInfoFunc<func>(#func)
namespace Win32 namespace Win32
{ {
namespace Version namespace Version
{ {
void installHooks() void installHooks()
{ {
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoA);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoW);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoExA);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoExW);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeA);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeW);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeExA);
HOOK_VERSION_INFO_FUNCTION(GetFileVersionInfoSizeExW);
HOOK_FUNCTION(kernel32, GetVersion, getVersion); HOOK_FUNCTION(kernel32, GetVersion, getVersion);
HOOK_FUNCTION(kernel32, GetVersionExA, getVersionExA); HOOK_FUNCTION(kernel32, GetVersionExA, getVersionExA);
HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW); HOOK_FUNCTION(kernel32, GetVersionExW, getVersionExW);

View File

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