From cd093f936b66c813adec44f91a5d4ba05b52fdaa Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Tue, 7 May 2024 17:09:14 -0700 Subject: [PATCH] Add more options for byte alignment #260 --- Dllmain/BuildNo.rc | 2 +- Settings/AllSettings.ini | 1 + Settings/Settings.h | 4 +++- Settings/Settings.ini | 1 + ddraw/IDirect3DDeviceX.cpp | 13 +++++++++++++ ddraw/IDirect3DDeviceX.h | 1 + ddraw/IDirectDrawSurfaceX.cpp | 3 +++ ddraw/IDirectDrawSurfaceX.h | 2 ++ ddraw/IDirectDrawTypes.cpp | 7 +++++-- 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 86b2fc93..c43ee233 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7007 +#define BUILD_NUMBER 7008 diff --git a/Settings/AllSettings.ini b/Settings/AllSettings.ini index e229b5ca..18cf6c73 100644 --- a/Settings/AllSettings.ini +++ b/Settings/AllSettings.ini @@ -61,6 +61,7 @@ DdrawEmulateSurface = 0 DdrawEmulateLock = 0 DdrawFlipFillColor = 0 DdrawFixByteAlignment = 0 +DdrawDisableByteAlignment = 0 DdrawRemoveScanlines = 0 DdrawRemoveInterlacing = 0 DdrawReadFromGDI = 0 diff --git a/Settings/Settings.h b/Settings/Settings.h index f930258f..7e94d551 100644 --- a/Settings/Settings.h +++ b/Settings/Settings.h @@ -27,6 +27,7 @@ visit(DdrawClippedHeight) \ visit(DdrawCustomWidth) \ visit(DdrawCustomHeight) \ + visit(DdrawDisableByteAlignment) \ visit(DdrawDisableDirect3DCaps) \ visit(DdrawEmulateLock) \ visit(DdrawFlipFillColor) \ @@ -206,7 +207,8 @@ struct CONFIG bool DDrawCompatDisableGDIHook = false; // Disables DDrawCompat GDI hooks bool DDrawCompatNoProcAffinity = false; // Disables DDrawCompat single processor affinity bool DdrawAutoFrameSkip = false; // Automatically skips frames to reduce input lag - bool DdrawFixByteAlignment = false; // Fixes lock with surfaces that have unaligned byte sizes + DWORD DdrawFixByteAlignment = false; // Fixes lock with surfaces that have unaligned byte sizes, 1) just byte align, 2) byte align + D3DTEXF_NONE, 3) byte align + D3DTEXF_LINEAR + bool DdrawDisableByteAlignment = false; // Disables 32bit / 64bit byte alignment DWORD DdrawResolutionHack = 0; // Removes the artificial resolution limit from Direct3D7 and below https://github.com/UCyborg/LegacyD3DResolutionHack bool DdrawRemoveScanlines = 0; // Experimental feature to removing interlaced black lines in a single frame bool DdrawRemoveInterlacing = 0; // Experimental feature to removing interlacing between frames diff --git a/Settings/Settings.ini b/Settings/Settings.ini index 8f6ad281..5f2498fc 100644 --- a/Settings/Settings.ini +++ b/Settings/Settings.ini @@ -48,6 +48,7 @@ DdrawEmulateSurface = 0 DdrawEmulateLock = 0 DdrawFlipFillColor = 0 DdrawFixByteAlignment = 0 +DdrawDisableByteAlignment = 0 DdrawRemoveScanlines = 0 DdrawRemoveInterlacing = 0 DdrawReadFromGDI = 0 diff --git a/ddraw/IDirect3DDeviceX.cpp b/ddraw/IDirect3DDeviceX.cpp index 90676117..f1408615 100644 --- a/ddraw/IDirect3DDeviceX.cpp +++ b/ddraw/IDirect3DDeviceX.cpp @@ -4194,6 +4194,14 @@ inline void m_IDirect3DDeviceX::SetDrawStates(DWORD dwVertexTypeDesc, DWORD& dwF (*d3d9Device)->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); (*d3d9Device)->SetRenderState(D3DRS_FOGENABLE, FALSE); } + else if (Config.Dd7to9 && Config.DdrawFixByteAlignment > 1 && CurrentTextureSurfaceX && CurrentTextureSurfaceX->GetWasBitAlignLocked()) + { + (*d3d9Device)->GetSamplerState(0, D3DSAMP_MINFILTER, &DrawStates.ssMinFilter); + (*d3d9Device)->GetSamplerState(0, D3DSAMP_MAGFILTER, &DrawStates.ssMagFilter); + + (*d3d9Device)->SetSamplerState(0, D3DSAMP_MINFILTER, Config.DdrawFixByteAlignment == 2 ? D3DTEXF_NONE : D3DTEXF_LINEAR); + (*d3d9Device)->SetSamplerState(0, D3DSAMP_MAGFILTER, Config.DdrawFixByteAlignment == 2 ? D3DTEXF_NONE : D3DTEXF_LINEAR); + } } inline void m_IDirect3DDeviceX::RestoreDrawStates(DWORD dwVertexTypeDesc, DWORD dwFlags, DWORD DirectXVersion) @@ -4233,6 +4241,11 @@ inline void m_IDirect3DDeviceX::RestoreDrawStates(DWORD dwVertexTypeDesc, DWORD SetTexture(0, AttachedTexture[0]); SetTexture(1, AttachedTexture[1]); } + else if (Config.Dd7to9 && Config.DdrawFixByteAlignment > 1 && CurrentTextureSurfaceX && CurrentTextureSurfaceX->GetWasBitAlignLocked()) + { + (*d3d9Device)->SetSamplerState(0, D3DSAMP_MINFILTER, DrawStates.ssMinFilter); + (*d3d9Device)->SetSamplerState(0, D3DSAMP_MAGFILTER, DrawStates.ssMagFilter); + } } inline void m_IDirect3DDeviceX::ScaleVertices(DWORD dwVertexTypeDesc, LPVOID& lpVertices, DWORD dwVertexCount) diff --git a/ddraw/IDirect3DDeviceX.h b/ddraw/IDirect3DDeviceX.h index 49d79579..6ee4621d 100644 --- a/ddraw/IDirect3DDeviceX.h +++ b/ddraw/IDirect3DDeviceX.h @@ -37,6 +37,7 @@ class m_IDirect3DDeviceX : public IUnknown, public AddressLookupTableDdrawObject DWORD rsAlphaBlendEnable = 0; DWORD rsAlphaTestEnable = 0; DWORD rsFogEnable = 0; + DWORD ssMinFilter = 0; DWORD ssMagFilter = 0; float lowColorKey[4] = {}; float highColorKey[4] = {}; diff --git a/ddraw/IDirectDrawSurfaceX.cpp b/ddraw/IDirectDrawSurfaceX.cpp index 8951191c..4618cfb1 100644 --- a/ddraw/IDirectDrawSurfaceX.cpp +++ b/ddraw/IDirectDrawSurfaceX.cpp @@ -4753,6 +4753,9 @@ void m_IDirectDrawSurfaceX::LockEmuLock(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDD OutAddr += OutPitch; } } + + // Mark as byte align locked + WasBitAlignLocked = LockByteAlign; } } diff --git a/ddraw/IDirectDrawSurfaceX.h b/ddraw/IDirectDrawSurfaceX.h index bdc80389..74ed0617 100644 --- a/ddraw/IDirectDrawSurfaceX.h +++ b/ddraw/IDirectDrawSurfaceX.h @@ -150,6 +150,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj bool IsInBlt = false; bool IsInBltBatch = false; bool IsLocked = false; + bool WasBitAlignLocked = false; DWORD LockedWithID = 0; // Thread ID of the current lock LASTLOCK LastLock; // Remember the last lock info std::vector LockRectList; // Rects used to lock the surface @@ -430,6 +431,7 @@ class m_IDirectDrawSurfaceX : public IUnknown, public AddressLookupTableDdrawObj inline DWORD GetD39MipMapLevel(DWORD MipMapLevel) { return min(MipMapLevel, MaxMipMapLevel - 1); } bool GetColorKeyForShader(float(&lowColorKey)[4], float(&highColorKey)[4]); bool GetColorKeyForPrimaryShader(float(&lowColorKey)[4], float(&highColorKey)[4]); + bool GetWasBitAlignLocked() { return WasBitAlignLocked; } inline bool GetSurfaceSetSize(DWORD& Width, DWORD& Height) { if ((surfaceDesc2.dwFlags & (DDSD_WIDTH | DDSD_HEIGHT)) == (DDSD_WIDTH | DDSD_HEIGHT) && diff --git a/ddraw/IDirectDrawTypes.cpp b/ddraw/IDirectDrawTypes.cpp index 80f5f99a..6891adc9 100644 --- a/ddraw/IDirectDrawTypes.cpp +++ b/ddraw/IDirectDrawTypes.cpp @@ -306,9 +306,12 @@ void ConvertCaps(DDCAPS &Caps7, D3DCAPS9 &Caps9) DWORD GetByteAlignedWidth(DWORD Width, DWORD BitCount) { - while ((Width * BitCount) % 64) + if (!Config.DdrawDisableByteAlignment) { - Width++; + while ((Width * BitCount) % 64) + { + Width++; + } } return Width; }