Skip to content

Commit

Permalink
Add more options for byte alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed May 8, 2024
1 parent 5e81e98 commit cd093f9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7007
#define BUILD_NUMBER 7008
1 change: 1 addition & 0 deletions Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ DdrawEmulateSurface = 0
DdrawEmulateLock = 0
DdrawFlipFillColor = 0
DdrawFixByteAlignment = 0
DdrawDisableByteAlignment = 0
DdrawRemoveScanlines = 0
DdrawRemoveInterlacing = 0
DdrawReadFromGDI = 0
Expand Down
4 changes: 3 additions & 1 deletion Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
visit(DdrawClippedHeight) \
visit(DdrawCustomWidth) \
visit(DdrawCustomHeight) \
visit(DdrawDisableByteAlignment) \
visit(DdrawDisableDirect3DCaps) \
visit(DdrawEmulateLock) \
visit(DdrawFlipFillColor) \
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Settings/Settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ DdrawEmulateSurface = 0
DdrawEmulateLock = 0
DdrawFlipFillColor = 0
DdrawFixByteAlignment = 0
DdrawDisableByteAlignment = 0
DdrawRemoveScanlines = 0
DdrawRemoveInterlacing = 0
DdrawReadFromGDI = 0
Expand Down
13 changes: 13 additions & 0 deletions ddraw/IDirect3DDeviceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ddraw/IDirect3DDeviceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {};
Expand Down
3 changes: 3 additions & 0 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4753,6 +4753,9 @@ void m_IDirectDrawSurfaceX::LockEmuLock(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDD
OutAddr += OutPitch;
}
}

// Mark as byte align locked
WasBitAlignLocked = LockByteAlign;
}
}

Expand Down
2 changes: 2 additions & 0 deletions ddraw/IDirectDrawSurfaceX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RECT> LockRectList; // Rects used to lock the surface
Expand Down Expand Up @@ -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) &&
Expand Down
7 changes: 5 additions & 2 deletions ddraw/IDirectDrawTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cd093f9

Please sign in to comment.