From b6f6f2acf068aa11a518cede9fd5abbd14ea5672 Mon Sep 17 00:00:00 2001 From: narzoul Date: Mon, 29 Jul 2019 23:13:52 +0200 Subject: [PATCH] Limit maximum video memory Fixes blurry textures in Rayman 2 and crash in Settlers 4 --- DDrawCompat/D3dDdi/KernelModeThunks.cpp | 32 +++++++++++++++++-- .../D3dDdi/Log/KernelModeThunksLog.cpp | 9 ++++++ DDrawCompat/D3dDdi/Log/KernelModeThunksLog.h | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/DDrawCompat/D3dDdi/KernelModeThunks.cpp b/DDrawCompat/D3dDdi/KernelModeThunks.cpp index 1b78a2b..549fa29 100644 --- a/DDrawCompat/D3dDdi/KernelModeThunks.cpp +++ b/DDrawCompat/D3dDdi/KernelModeThunks.cpp @@ -219,10 +219,36 @@ namespace { LOG_FUNC("D3DKMTQueryAdapterInfo", pData); NTSTATUS result = CALL_ORIG_FUNC(D3DKMTQueryAdapterInfo)(pData); - if (SUCCEEDED(result) && KMTQAITYPE_UMDRIVERNAME == pData->Type) + if (SUCCEEDED(result)) { - auto info = static_cast(pData->pPrivateDriverData); - D3dDdi::onUmdFileNameQueried(info->UmdFileName); + switch (pData->Type) + { + case KMTQAITYPE_UMDRIVERNAME: + { + auto info = static_cast(pData->pPrivateDriverData); + D3dDdi::onUmdFileNameQueried(info->UmdFileName); + } + break; + + case KMTQAITYPE_GETSEGMENTSIZE: + { + auto info = static_cast(pData->pPrivateDriverData); + const ULONGLONG maxMem = 0x3FFF0000; + if (info->DedicatedVideoMemorySize > maxMem) + { + info->DedicatedVideoMemorySize = maxMem; + } + if (info->DedicatedVideoMemorySize + info->DedicatedSystemMemorySize > maxMem) + { + info->DedicatedSystemMemorySize = maxMem - info->DedicatedVideoMemorySize; + } + if (info->SharedSystemMemorySize > maxMem) + { + info->SharedSystemMemorySize = maxMem; + } + } + break; + } } return LOG_RESULT(result); } diff --git a/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.cpp b/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.cpp index 4dddd6e..52798fe 100644 --- a/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.cpp +++ b/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.cpp @@ -120,6 +120,15 @@ std::ostream& operator<<(std::ostream& os, const D3DKMT_PRESENT& data) << static_cast(data.bOptimizeForComposition); } +std::ostream& operator<<(std::ostream& os, const D3DKMT_QUERYADAPTERINFO& data) +{ + return Compat::LogStruct(os) + << Compat::hex(data.hAdapter) + << data.Type + << data.pPrivateDriverData + << data.PrivateDriverDataSize; +} + std::ostream& operator<<(std::ostream& os, const D3DKMT_SETQUEUEDLIMIT& data) { return Compat::LogStruct(os) diff --git a/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.h b/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.h index d80ae99..91b653b 100644 --- a/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.h +++ b/DDrawCompat/D3dDdi/Log/KernelModeThunksLog.h @@ -15,6 +15,7 @@ std::ostream& operator<<(std::ostream& os, const D3DKMT_DESTROYCONTEXT& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_DESTROYDEVICE& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_OPENADAPTERFROMHDC& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_PRESENT& data); +std::ostream& operator<<(std::ostream& os, const D3DKMT_QUERYADAPTERINFO& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_SETQUEUEDLIMIT& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_SETVIDPNSOURCEOWNER& data); std::ostream& operator<<(std::ostream& os, const D3DKMT_SETVIDPNSOURCEOWNER1& data);