Skip to content

Commit

Permalink
Add options for Vertex Processing in d3d9
Browse files Browse the repository at this point in the history
Fix for #111
  • Loading branch information
elishacloud committed Apr 15, 2021
1 parent 30291ee commit 4728224
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 3 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 6490
#define BUILD_NUMBER 6491
2 changes: 1 addition & 1 deletion External/Hooking
Submodule Hooking updated 1 files
+1 −0 HotPatch.cpp
2 changes: 2 additions & 0 deletions Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ AntiAliasing = 0
CacheClipPlane = 0
EnableVSync = 0
EnableWindowMode = 0
ForceMixedVertexProcessing = 0
ForceSystemMemVertexCache = 0
ForceVsyncMode = 0
FullscreenWindowMode = 0
WindowModeBorder = 0
Expand Down
2 changes: 1 addition & 1 deletion Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void CONFIG::Init()
DDrawCompat = (DDrawCompat || DDrawCompat20 || DDrawCompat21 || DDrawCompatExperimental);
isDdrawWrapperEnabled = (EnableDdrawWrapper || ConvertToDirectDraw7 || ConvertToDirect3D7 || DdrawResolutionHack);
EnableWindowMode = (FullscreenWindowMode) ? true : EnableWindowMode;
isD3d9WrapperEnabled = (AnisotropicFiltering || AntiAliasing || CacheClipPlane || EnableVSync || ForceVsyncMode || EnableWindowMode);
isD3d9WrapperEnabled = (AnisotropicFiltering || AntiAliasing || CacheClipPlane || EnableVSync || ForceMixedVertexProcessing || ForceSystemMemVertexCache || ForceVsyncMode || EnableWindowMode);

// Set ddraw color bit mode
DdrawOverrideBitMode = (DdrawOverrideBitMode) ? DdrawOverrideBitMode : (Force32bitColor) ? 32 : (Force16bitColor) ? 16 : 0;
Expand Down
4 changes: 4 additions & 0 deletions Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
visit(EnableVSync) \
visit(EnableWindowMode) \
visit(ExcludeProcess) \
visit(ForceMixedVertexProcessing) \
visit(ForceSystemMemVertexCache) \
visit(FilterNonActiveInput) \
visit(FixSpeakerConfigType) \
visit(ForceExclusiveMode) \
Expand Down Expand Up @@ -205,6 +207,8 @@ struct CONFIG
bool EnableDsoundWrapper; // Enables the dsound wrapper
bool EnableWindowMode; // Enables WndMode for d3d9 wrapper
bool EnableVSync; // Enables VSync for d3d9 wrapper
bool ForceMixedVertexProcessing; // Forces Mixed mode for vertex processing in d3d9
bool ForceSystemMemVertexCache; // Forces System Memory caching for vertexes in d3d9
bool FullScreen; // Sets the main window to fullscreen
bool FullscreenWindowMode; // Enables fullscreen windowed mode, requires EnableWindowMode
bool ForceTermination; // Terminates application when main window closes
Expand Down
2 changes: 2 additions & 0 deletions Settings/Settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ AnisotropicFiltering = 0
AntiAliasing = 0
EnableVSync = 0
EnableWindowMode = 0
ForceMixedVertexProcessing = 0
ForceSystemMemVertexCache = 0
ForceVsyncMode = 0
FullscreenWindowMode = 0
WindowModeBorder = 0
Expand Down
29 changes: 29 additions & 0 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ HRESULT m_IDirect3D9Ex::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND h
return D3DERR_INVALIDCALL;
}

BehaviorFlags = UpdateBehaviorFlags(BehaviorFlags);

// Create new d3d9 device
HRESULT hr = D3DERR_INVALIDCALL;

Expand Down Expand Up @@ -271,6 +273,8 @@ HRESULT m_IDirect3D9Ex::CreateDeviceEx(THIS_ UINT Adapter, D3DDEVTYPE DeviceType
return D3DERR_INVALIDCALL;
}

BehaviorFlags = UpdateBehaviorFlags(BehaviorFlags);

// Create new d3d9 device
HRESULT hr = D3DERR_INVALIDCALL;

Expand Down Expand Up @@ -345,6 +349,31 @@ HRESULT m_IDirect3D9Ex::GetAdapterLUID(THIS_ UINT Adapter, LUID * pLUID)
return ProxyInterface->GetAdapterLUID(Adapter, pLUID);
}

DWORD UpdateBehaviorFlags(DWORD BehaviorFlags)
{
if (Config.ForceMixedVertexProcessing)
{
BehaviorFlags &= ~(D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
BehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
}
else if (BehaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING)
{
BehaviorFlags &= ~(D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MIXED_VERTEXPROCESSING);
BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
else if (BehaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING)
{
BehaviorFlags &= ~(D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
BehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
}
else if (BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
BehaviorFlags &= ~(D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING);
BehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
return BehaviorFlags;
}

// Set Presentation Parameters
void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND hFocusWindow, bool SetWindow)
{
Expand Down
25 changes: 25 additions & 0 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "d3d9.h"
#include "d3dx9.h"
#include "Utils\Utils.h"
#include <intrin.h>

HRESULT m_IDirect3DDevice9Ex::QueryInterface(REFIID riid, void** ppvObj)
{
Expand Down Expand Up @@ -294,6 +295,12 @@ HRESULT m_IDirect3DDevice9Ex::CreateVertexBuffer(THIS_ UINT Length, DWORD Usage,
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (Config.ForceSystemMemVertexCache)
{
Pool = D3DPOOL_SYSTEMMEM;
Usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
}

HRESULT hr = ProxyInterface->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle);

if (SUCCEEDED(hr) && ppVertexBuffer)
Expand Down Expand Up @@ -1720,6 +1727,24 @@ HRESULT m_IDirect3DDevice9Ex::GetSwapChain(THIS_ UINT iSwapChain, IDirect3DSwapC
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

// Add 16 bytes for Steam Overlay Fix
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();
__nop();

HRESULT hr = ProxyInterface->GetSwapChain(iSwapChain, ppSwapChain);

if (SUCCEEDED(hr) && ppSwapChain)
Expand Down
1 change: 1 addition & 0 deletions d3d9/d3d9.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef void(WINAPI *D3DPERF_SetRegionProc)(D3DCOLOR, LPCWSTR);
typedef IDirect3D9 *(WINAPI *Direct3DCreate9Proc)(UINT);
typedef HRESULT(WINAPI *Direct3DCreate9ExProc)(UINT, IDirect3D9Ex **);

DWORD UpdateBehaviorFlags(DWORD BehaviorFlags);
void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND hFocusWindow, bool SetWindow);
void UpdatePresentParameterForMultisample(D3DPRESENT_PARAMETERS* pPresentationParameters, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD MultiSampleQuality);

Expand Down

0 comments on commit 4728224

Please sign in to comment.