From 7237acb11ce01f2e2b6d4263eed419eb59e2c326 Mon Sep 17 00:00:00 2001 From: narzoul Date: Wed, 26 Jun 2024 20:10:32 +0200 Subject: [PATCH] Fixed a performance issue with windowed fullscreen GDI presentation See issue #273. --- DDrawCompat/D3dDdi/Resource.cpp | 3 ++- DDrawCompat/D3dDdi/SurfaceRepository.cpp | 6 +++++- DDrawCompat/D3dDdi/SurfaceRepository.h | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DDrawCompat/D3dDdi/Resource.cpp b/DDrawCompat/D3dDdi/Resource.cpp index d182517..cea5fbd 100644 --- a/DDrawCompat/D3dDdi/Resource.cpp +++ b/DDrawCompat/D3dDdi/Resource.cpp @@ -598,7 +598,7 @@ namespace D3dDdi flags.ZBuffer = 0; } if (D3DDDIPOOL_SYSTEMMEM == m_fixedData.Pool || - m_isSurfaceRepoResource || + m_isSurfaceRepoResource && !SurfaceRepository::isLockResourceEnabled() || 0 == m_formatInfo.bytesPerPixel || 0 != (m_fixedData.Flags.Value & flags.Value) || m_fixedData.Flags.Texture && (DDraw::Surface::getCurrentSurfaceCaps().dwCaps2 & 0x100000)) // managed texture @@ -1304,6 +1304,7 @@ namespace D3dDdi srcResource = &srcResource->prepareForGpuRead(data.SrcSubResourceIndex); } + prepareForGpuWrite(data.DstSubResourceIndex); LONG srcWidth = srcResource->m_fixedData.pSurfList[data.SrcSubResourceIndex].Width; LONG srcHeight = srcResource->m_fixedData.pSurfList[data.SrcSubResourceIndex].Height; diff --git a/DDrawCompat/D3dDdi/SurfaceRepository.cpp b/DDrawCompat/D3dDdi/SurfaceRepository.cpp index ff1d646..d4210e7 100644 --- a/DDrawCompat/D3dDdi/SurfaceRepository.cpp +++ b/DDrawCompat/D3dDdi/SurfaceRepository.cpp @@ -354,8 +354,11 @@ namespace D3dDdi CompatPtr SurfaceRepository::getWindowedBackBuffer(DWORD width, DWORD height) { - return getSurface(m_windowedBackBuffer, width, height, D3DDDIFMT_X8R8G8B8, + s_isLockResourceEnabled = true; + auto surface = getSurface(m_windowedBackBuffer, width, height, D3DDDIFMT_X8R8G8B8, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY).surface; + s_isLockResourceEnabled = false; + return surface; } CompatWeakPtr SurfaceRepository::getWindowedPrimary() @@ -441,4 +444,5 @@ namespace D3dDdi } bool SurfaceRepository::s_inCreateSurface = false; + bool SurfaceRepository::s_isLockResourceEnabled = false; } diff --git a/DDrawCompat/D3dDdi/SurfaceRepository.h b/DDrawCompat/D3dDdi/SurfaceRepository.h index 4946cda..0f3d412 100644 --- a/DDrawCompat/D3dDdi/SurfaceRepository.h +++ b/DDrawCompat/D3dDdi/SurfaceRepository.h @@ -62,6 +62,7 @@ namespace D3dDdi static SurfaceRepository& get(const Adapter& adapter); static SurfaceRepository& getPrimaryRepo(); static bool inCreateSurface() { return s_inCreateSurface; } + static bool isLockResourceEnabled() { return s_isLockResourceEnabled; } static void enableSurfaceCheck(bool enable); private: @@ -93,5 +94,6 @@ namespace D3dDdi CompatPtr m_windowedPrimary; static bool s_inCreateSurface; + static bool s_isLockResourceEnabled; }; }