Skip to content

Commit

Permalink
Add support for Direct3DCreate9On12
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Oct 26, 2022
1 parent d487e71 commit b32482c
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
@@ -1 +1 @@
#define BUILD_NUMBER 6600
#define BUILD_NUMBER 6601
2 changes: 2 additions & 0 deletions Dllmain/Dllmain.cpp
Expand Up @@ -479,6 +479,8 @@ bool APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
Logging::Log() << "Hooking d3d9.dll APIs...";
HOOK_WRAPPED_PROC(Direct3DCreate9, unused);
HOOK_WRAPPED_PROC(Direct3DCreate9Ex, unused);
HOOK_WRAPPED_PROC(Direct3DCreate9On12, unused);
HOOK_WRAPPED_PROC(Direct3DCreate9On12Ex, unused);
}
}

Expand Down
1 change: 1 addition & 0 deletions Settings/AllSettings.ini
Expand Up @@ -78,6 +78,7 @@ AntiAliasing = 0
CacheClipPlane = 0
EnableVSync = 0
EnableWindowMode = 0
ForceDirect3D9On12 = 0
ForceExclusiveFullscreen = 0
ForceMixedVertexProcessing = 0
ForceSystemMemVertexCache = 0
Expand Down
2 changes: 2 additions & 0 deletions Settings/Settings.h
Expand Up @@ -63,6 +63,7 @@
visit(EnableVSync) \
visit(EnableWindowMode) \
visit(ExcludeProcess) \
visit(ForceDirect3D9On12) \
visit(ForceExclusiveFullscreen) \
visit(ForceMixedVertexProcessing) \
visit(ForceSystemMemVertexCache) \
Expand Down Expand Up @@ -230,6 +231,7 @@ struct CONFIG
bool EnableDsoundWrapper = false; // Enables the dsound wrapper
bool EnableWindowMode = false; // Enables WndMode for d3d9 wrapper
bool EnableVSync = false; // Enables VSync for d3d9 wrapper
bool ForceDirect3D9On12 = false; // Forces Direct3D9 to use CreateDirect3D9On12
bool ForceExclusiveFullscreen = false; // Forces exclusive fullscreen mode in d3d9
bool ForceMixedVertexProcessing = false; // Forces Mixed mode for vertex processing in d3d9
bool ForceSystemMemVertexCache = false; // Forces System Memory caching for vertexes in d3d9
Expand Down
2 changes: 1 addition & 1 deletion Stub/BuildNo.rc
@@ -1 +1 @@
#define BUILD_NUMBER 229
#define BUILD_NUMBER 230
4 changes: 3 additions & 1 deletion Wrappers/d3d9.h
Expand Up @@ -9,7 +9,9 @@
visit(D3DPERF_SetOptions, jmpaddrvoid) \
visit(D3DPERF_SetRegion, jmpaddrvoid) \
visit(Direct3DCreate9, jmpaddr) \
visit(Direct3DCreate9Ex, jmpaddr)
visit(Direct3DCreate9Ex, jmpaddr) \
visit(Direct3DCreate9On12, jmpaddr) \
visit(Direct3DCreate9On12Ex, jmpaddr)

#ifdef PROC_CLASS
PROC_CLASS(d3d9, dll, VISIT_PROCS_D3D9, VISIT_PROCS_BLANK)
Expand Down
2 changes: 2 additions & 0 deletions Wrappers/wrapper.def
Expand Up @@ -198,6 +198,8 @@ D3DPERF_SetOptions
D3DPERF_SetRegion
Direct3DCreate9
Direct3DCreate9Ex
Direct3DCreate9On12
Direct3DCreate9On12Ex


; ****
Expand Down
95 changes: 92 additions & 3 deletions d3d9/d3d9.cpp
Expand Up @@ -158,7 +158,7 @@ void SetGraphicsHybridAdapter(UINT Mode)
}
}

IDirect3D9 *WINAPI d9_Direct3DCreate9(UINT SDKVersion)
IDirect3D9* WINAPI d9_Direct3DCreate9(UINT SDKVersion)
{
LOG_LIMIT(1, __FUNCTION__);

Expand All @@ -169,6 +169,17 @@ IDirect3D9 *WINAPI d9_Direct3DCreate9(UINT SDKVersion)
return nullptr;
}

if (Config.ForceDirect3D9On12 && Direct3DCreate9On12_out)
{
// Setup arguments
D3D9ON12_ARGS args;
memset(&args, 0, sizeof(args));
args.Enable9On12 = TRUE;

// Call function
return d9_Direct3DCreate9On12(SDKVersion, &args, 1);
}

if (Config.GraphicsHybridAdapter)
{
SetGraphicsHybridAdapter(Config.GraphicsHybridAdapter);
Expand All @@ -177,7 +188,7 @@ IDirect3D9 *WINAPI d9_Direct3DCreate9(UINT SDKVersion)
LOG_LIMIT(3, "Redirecting 'Direct3DCreate9' ...");

// Create new d3d9 object
IDirect3D9 *pD3D9 = m_pDirect3DCreate9(SDKVersion);
IDirect3D9* pD3D9 = m_pDirect3DCreate9(SDKVersion);

if (pD3D9)
{
Expand All @@ -187,7 +198,7 @@ IDirect3D9 *WINAPI d9_Direct3DCreate9(UINT SDKVersion)
return nullptr;
}

HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex** ppD3D)
{
LOG_LIMIT(1, __FUNCTION__);

Expand All @@ -198,6 +209,17 @@ HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)
return D3DERR_INVALIDCALL;
}

if (Config.ForceDirect3D9On12 && Direct3DCreate9On12Ex_out)
{
// Setup arguments
D3D9ON12_ARGS args;
memset(&args, 0, sizeof(args));
args.Enable9On12 = TRUE;

// Call function
return d9_Direct3DCreate9On12Ex(SDKVersion, &args, 1, ppD3D);
}

if (Config.GraphicsHybridAdapter)
{
SetGraphicsHybridAdapter(Config.GraphicsHybridAdapter);
Expand All @@ -214,3 +236,70 @@ HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D)

return hr;
}

IDirect3D9* WINAPI d9_Direct3DCreate9On12(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries)
{
LOG_LIMIT(1, __FUNCTION__);

static Direct3DCreate9On12Proc m_pDirect3DCreate9On12 = (Wrapper::ValidProcAddress(Direct3DCreate9On12_out)) ? (Direct3DCreate9On12Proc)Direct3DCreate9On12_out : nullptr;

if (!m_pDirect3DCreate9On12)
{
return d9_Direct3DCreate9(SDKVersion);
}

if (Config.GraphicsHybridAdapter)
{
SetGraphicsHybridAdapter(Config.GraphicsHybridAdapter);
}

LOG_LIMIT(3, "Redirecting 'Direct3DCreate9On12' ...");

if (Config.ForceDirect3D9On12 && pOverrideList)
{
pOverrideList->Enable9On12 = TRUE;
}

// Create new d3d9 object
IDirect3D9* pD3D9 = m_pDirect3DCreate9On12(SDKVersion, pOverrideList, NumOverrideEntries);

if (pD3D9)
{
return new m_IDirect3D9Ex((IDirect3D9Ex*)pD3D9, IID_IDirect3D9);
}

return nullptr;
}

HRESULT WINAPI d9_Direct3DCreate9On12Ex(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries, IDirect3D9Ex** ppOutputInterface)
{
LOG_LIMIT(1, __FUNCTION__);

static Direct3DCreate9On12ExProc m_pDirect3DCreate9On12Ex = (Wrapper::ValidProcAddress(Direct3DCreate9On12Ex_out)) ? (Direct3DCreate9On12ExProc)Direct3DCreate9On12Ex_out : nullptr;

if (!m_pDirect3DCreate9On12Ex)
{
return d9_Direct3DCreate9Ex(SDKVersion, ppOutputInterface);
}

if (Config.GraphicsHybridAdapter)
{
SetGraphicsHybridAdapter(Config.GraphicsHybridAdapter);
}

LOG_LIMIT(3, "Redirecting 'Direct3DCreate9On12Ex' ...");

if (Config.ForceDirect3D9On12 && pOverrideList)
{
pOverrideList->Enable9On12 = TRUE;
}

HRESULT hr = m_pDirect3DCreate9On12Ex(SDKVersion, pOverrideList, NumOverrideEntries, ppOutputInterface);

if (SUCCEEDED(hr) && ppOutputInterface)
{
*ppOutputInterface = new m_IDirect3D9Ex(*ppOutputInterface, IID_IDirect3D9Ex);
}

return hr;
}
26 changes: 13 additions & 13 deletions d3d9/d3d9.h
@@ -1,8 +1,6 @@
#pragma once

#define INITGUID

#include <d3d9.h>
#include "d3d9External.h"

class m_IDirect3D9Ex;
class m_IDirect3DDevice9Ex;
Expand All @@ -24,24 +22,26 @@ class m_IDirect3DVolumeTexture9;
#include "Settings\Settings.h"
#include "Logging\Logging.h"

typedef int(WINAPI *D3DPERF_BeginEventProc)(D3DCOLOR, LPCWSTR);
typedef int(WINAPI *D3DPERF_EndEventProc)();
typedef DWORD(WINAPI *D3DPERF_GetStatusProc)();
typedef BOOL(WINAPI *D3DPERF_QueryRepeatFrameProc)();
typedef void(WINAPI *D3DPERF_SetMarkerProc)(D3DCOLOR, LPCWSTR);
typedef void(WINAPI *D3DPERF_SetOptionsProc)(DWORD);
typedef void(WINAPI *D3DPERF_SetRegionProc)(D3DCOLOR, LPCWSTR);
typedef IDirect3D9 *(WINAPI *Direct3DCreate9Proc)(UINT);
typedef HRESULT(WINAPI *Direct3DCreate9ExProc)(UINT, IDirect3D9Ex **);
typedef int(WINAPI* D3DPERF_BeginEventProc)(D3DCOLOR, LPCWSTR);
typedef int(WINAPI* D3DPERF_EndEventProc)();
typedef DWORD(WINAPI* D3DPERF_GetStatusProc)();
typedef BOOL(WINAPI* D3DPERF_QueryRepeatFrameProc)();
typedef void(WINAPI* D3DPERF_SetMarkerProc)(D3DCOLOR, LPCWSTR);
typedef void(WINAPI* D3DPERF_SetOptionsProc)(DWORD);
typedef void(WINAPI* D3DPERF_SetRegionProc)(D3DCOLOR, LPCWSTR);
typedef void(WINAPI* Direct3D9ForceHybridEnumerationProc)(UINT Mode);
typedef IDirect3D9* (WINAPI* Direct3DCreate9Proc)(UINT);
typedef HRESULT(WINAPI* Direct3DCreate9ExProc)(UINT, IDirect3D9Ex**);
typedef IDirect3D9* (WINAPI* Direct3DCreate9On12Proc)(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries);
typedef HRESULT(WINAPI* Direct3DCreate9On12ExProc)(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries, IDirect3D9Ex** ppOutputInterface);

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

namespace D3d9Wrapper
{
void WINAPI genericQueryInterface(REFIID riid, LPVOID *ppvObj, m_IDirect3DDevice9Ex* m_pDeviceEx);
void WINAPI genericQueryInterface(REFIID riid, LPVOID* ppvObj, m_IDirect3DDevice9Ex* m_pDeviceEx);
}

extern HWND DeviceWindow;
Expand Down
20 changes: 18 additions & 2 deletions d3d9/d3d9External.h
@@ -1,20 +1,36 @@
#pragma once

#define INITGUID

#include <d3d9.h>
#include "Wrappers\wrapper.h"

typedef DWORD D3DCOLOR;
struct __declspec(uuid("81BDCBCA-64D4-426d-AE8D-AD0147F4275C")) IDirect3D9;
struct __declspec(uuid("02177241-69FC-400C-8FF1-93A44DF6861D")) IDirect3D9Ex;

#define MAX_D3D9ON12_QUEUES 2

typedef struct _D3D9ON12_ARGS
{
BOOL Enable9On12;
IUnknown* pD3D12Device;
IUnknown* ppD3D12Queues[MAX_D3D9ON12_QUEUES];
UINT NumQueues;
UINT NodeMask;
} D3D9ON12_ARGS;

int WINAPI d9_D3DPERF_BeginEvent(D3DCOLOR col, LPCWSTR wszName);
int WINAPI d9_D3DPERF_EndEvent();
DWORD WINAPI d9_D3DPERF_GetStatus();
BOOL WINAPI d9_D3DPERF_QueryRepeatFrame();
void WINAPI d9_D3DPERF_SetMarker(D3DCOLOR col, LPCWSTR wszName);
void WINAPI d9_D3DPERF_SetOptions(DWORD dwOptions);
void WINAPI d9_D3DPERF_SetRegion(D3DCOLOR col, LPCWSTR wszName);
IDirect3D9 *WINAPI d9_Direct3DCreate9(UINT SDKVersion);
HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex **ppD3D);
IDirect3D9* WINAPI d9_Direct3DCreate9(UINT SDKVersion);
HRESULT WINAPI d9_Direct3DCreate9Ex(UINT SDKVersion, IDirect3D9Ex** ppD3D);
IDirect3D9* WINAPI d9_Direct3DCreate9On12(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries);
HRESULT WINAPI d9_Direct3DCreate9On12Ex(UINT SDKVersion, D3D9ON12_ARGS* pOverrideList, UINT NumOverrideEntries, IDirect3D9Ex** ppOutputInterface);

#define DECLARE_IN_WRAPPED_PROC(procName, unused) \
const FARPROC procName ## _in = (FARPROC)*d9_ ## procName;
Expand Down

0 comments on commit b32482c

Please sign in to comment.