From f3ea689010a925f8800284faa99efb93860cf69a Mon Sep 17 00:00:00 2001 From: jarmonik Date: Wed, 27 Dec 2023 18:31:44 +0200 Subject: [PATCH 1/2] Implemented a use of D3D9on12 driver to address issues on some intel graphics chips such as (Iris Xe Graphics) --- OVP/D3D9Client/CMakeLists.txt | 2 + OVP/D3D9Client/D3D9Client.cpp | 33 ++++++-- OVP/D3D9Client/D3D9Client.h | 1 + OVP/D3D9Client/D3D9Config.cpp | 3 + OVP/D3D9Client/D3D9Config.h | 2 +- OVP/D3D9Client/D3D9Frame.cpp | 64 +++++++-------- OVP/D3D9Client/D3D9Frame.h | 2 - OVP/D3D9Client/VideoTab.cpp | 143 +++++++++++++++++----------------- 8 files changed, 133 insertions(+), 117 deletions(-) diff --git a/OVP/D3D9Client/CMakeLists.txt b/OVP/D3D9Client/CMakeLists.txt index 8e89c0e60..84dc3b890 100644 --- a/OVP/D3D9Client/CMakeLists.txt +++ b/OVP/D3D9Client/CMakeLists.txt @@ -8,6 +8,7 @@ configure_file(D3D9ClientConfig.h.in D3D9ClientConfig.h) # set(CMAKE_CXX_STANDARD_REQUIRED True) set(DXSDK_LIB_DIR ${DXSDK_DIR}/lib/${ARCH}) +set(DXSDK_LIB_DIR2 "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/um/${ARCH}") #Must acquire d3d9.lib from here set(D3D9_SOURCE_DIR ${CMAKE_SOURCE_DIR}/OVP/D3D9Client) set(ShaderDir ${D3D9_SOURCE_DIR}/shaders) @@ -174,6 +175,7 @@ target_include_directories(D3D9Client PUBLIC target_link_directories(D3D9Client PUBLIC ${ORBITER_BINARY_SDK_DIR}/lib + ${DXSDK_LIB_DIR2} ${DXSDK_LIB_DIR} ) diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index ddb836442..787a78717 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -39,6 +39,7 @@ #include "gcCore.h" #include "gcConst.h" #include +#include #if defined(_MSC_VER) && (_MSC_VER <= 1700 ) // Microsoft Visual Studio Version 2012 and lower @@ -65,6 +66,7 @@ using namespace oapi; HINSTANCE g_hInst = 0; D3D9Client *g_client = 0; class gcConst* g_pConst = 0; +IDirect3D9* g_pD3DObject = 0; // Made valid when VideoTab is created D3D9Catalog *TileCatalog; @@ -277,6 +279,7 @@ D3D9Client::~D3D9Client() { LogAlw("D3D9Client destructor called"); SAFE_DELETE(vtab); + SAFE_RELEASE(g_pD3DObject); } @@ -313,11 +316,27 @@ bool D3D9Client::clbkInitialise() LogAlw("================ clbkInitialise ==============="); LogAlw("Orbiter Version = %d",oapiGetOrbiterVersion()); + D3D9ON12_ARGS args = {}; + args.Enable9On12 = Config->Enable9On12 != 0; + + g_pD3DObject = Direct3DCreate9On12(D3D_SDK_VERSION, &args, 1); + + if (g_pD3DObject) { + oapiWriteLog("[D3D9] DirectX9 Created..."); + if (Config->Enable9On12) oapiWriteLog("[D3D9] DX9 emulation via DX12"); + else oapiWriteLog("[D3D9] Native Interface"); + } + else { + oapiWriteLog("[D3D9][ERROR] Failed to create DirectX9"); + return false; + } + // Perform default setup if (GraphicsClient::clbkInitialise()==false) return false; //Create the Launchpad video tab interface + oapiWriteLog("[D3D9] Initialize VideoTab..."); vtab = new VideoTab(this, ModuleInstance(), OrbiterInstance(), LaunchpadVideoTab()); - + oapiWriteLog("[D3D9] VideoTab Created..."); return true; } @@ -331,6 +350,8 @@ HWND D3D9Client::clbkCreateRenderWindow() LogAlw("================ clbkCreateRenderWindow ==============="); + if (!g_pD3DObject) return NULL; + Config->WriteParams(); uEnableLog = Config->DebugLvl; @@ -378,8 +399,6 @@ HWND D3D9Client::clbkCreateRenderWindow() pFramework = new CD3DFramework9(); - if (pFramework->GetDirect3D()==NULL) return NULL; - WriteLog("[DirectX 9 Initialized]"); HRESULT hr = pFramework->Initialize(hRenderWnd, GetVideoData()); @@ -2900,10 +2919,14 @@ void D3D9Client::SplashScreen() DWORD m = d/100; d-=m*100; if (m>12) m=0; + char dataA[256]; + strcpy(dataA, "D3D9Client"); + if (Config->Enable9On12) strcat_s(dataA, 256, " via D3D9on12 emulator"); + #ifdef _DEBUG - char dataA[]={"Using D3D9Client (Debug Build)"}; + strcat_s(dataA, 256, " (Debug Build)"); #else - char dataA[]={"Using D3D9Client (Release Build)"}; + strcat_s(dataA, 256, " (Release Build)"); #endif char dataB[128]; sprintf_s(dataB,128,"Build %s %lu 20%lu [%u]", months[m], d, y, oapiGetOrbiterVersion()); diff --git a/OVP/D3D9Client/D3D9Client.h b/OVP/D3D9Client/D3D9Client.h index 22701215e..60817e59d 100644 --- a/OVP/D3D9Client/D3D9Client.h +++ b/OVP/D3D9Client/D3D9Client.h @@ -69,6 +69,7 @@ typedef class SurfNative* lpSurfNative; extern D3D9Catalog *TileCatalog; extern set MeshCatalog; extern set SurfaceCatalog; +extern IDirect3D9* g_pD3DObject; /** diff --git a/OVP/D3D9Client/D3D9Config.cpp b/OVP/D3D9Client/D3D9Config.cpp index bbdb1f92f..a3aa95d27 100644 --- a/OVP/D3D9Client/D3D9Config.cpp +++ b/OVP/D3D9Client/D3D9Config.cpp @@ -35,6 +35,7 @@ D3D9Config::~D3D9Config () void D3D9Config::Reset () { + Enable9On12 = 0; OrbitalShadowMult = 0.85; PlanetPreloadMode = 0; PlanetLoadFrequency = 20; @@ -129,6 +130,7 @@ bool D3D9Config::ReadParams () FILEHANDLE hFile = oapiOpenFile(cfgfile, FILE_IN_ZEROONFAIL, ROOT); if (!hFile) return false; + if (oapiReadItem_int (hFile, (char*)"EnableDX12Wrapper", i)) Enable9On12 = max(0, min(1, i)); if (oapiReadItem_float (hFile, (char*)"FrameRate", d)) FrameRate = max(0.0, min(300.0, d)); if (oapiReadItem_int (hFile, (char*)"EnableLimiter", i)) EnableLimiter = max(0, min(1, i)); if (oapiReadItem_int (hFile, (char*)"CustomCamMode", i)) CustomCamMode = max(0, min(1, i)); @@ -219,6 +221,7 @@ void D3D9Config::WriteParams () { FILEHANDLE hFile = oapiOpenFile (cfgfile, FILE_OUT, ROOT); + oapiWriteItem_int (hFile, (char*)"EnableDX12Wrapper", Enable9On12); oapiWriteItem_float (hFile, (char*)"FrameRate", FrameRate); oapiWriteItem_int (hFile, (char*)"EnableLimiter", EnableLimiter); oapiWriteItem_int (hFile, (char*)"CustomCamMode", CustomCamMode); diff --git a/OVP/D3D9Client/D3D9Config.h b/OVP/D3D9Client/D3D9Config.h index de2cbcedc..221079dee 100644 --- a/OVP/D3D9Client/D3D9Config.h +++ b/OVP/D3D9Client/D3D9Config.h @@ -33,7 +33,7 @@ class D3D9Config { static const int LABEL_DISPLAY_RECORD = 0x1; ///< Display label "Record" on active recording session static const int LABEL_DISPLAY_REPLAY = 0x2; ///< Display label "Replay" on active playback session - + int Enable9On12; ///< Enable DX9 through DX12 int PlanetPreloadMode; ///< Planet preload mode setting (0=load on demand, 1=preload) int PlanetLoadFrequency; ///< Load frequency for on-demand textures \[Hz\] (1...1000) int Anisotrophy; ///< Anisotropic filtering setting \[factor\] (1...16) diff --git a/OVP/D3D9Client/D3D9Frame.cpp b/OVP/D3D9Client/D3D9Frame.cpp index 5c49984be..d61333fb8 100644 --- a/OVP/D3D9Client/D3D9Frame.cpp +++ b/OVP/D3D9Client/D3D9Frame.cpp @@ -44,14 +44,9 @@ static const char *d3dmessage={"Required DirectX version (June 2010 or newer) no CD3DFramework9::CD3DFramework9() { - pD3D = NULL; Clear(); - // Create the Direct3D9 --------------------------------------------- - // - pD3D = Direct3DCreate9(D3D_SDK_VERSION); - - if (pD3D==NULL) { + if (g_pD3DObject == NULL) { LogErr("ERROR: [Direct3D9 Creation Failed]"); LogErr(d3dmessage); MessageBoxA(NULL, d3dmessage, "D3D9Client Initialization Failed",MB_OK); @@ -65,13 +60,10 @@ CD3DFramework9::CD3DFramework9() CD3DFramework9::~CD3DFramework9 () { LogAlw("Deleting Framework"); - SAFE_RELEASE(pD3D); } void CD3DFramework9::Clear() { - // NOTE: pD3D won't be cleared in here - hWnd = NULL; bIsFullscreen = false; bVertexTexture = false; @@ -172,7 +164,7 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) LogAlw("[VideoConfiguration] Adapter=%u, ModeIndex=%u", Adapter, Mode); D3DADAPTER_IDENTIFIER9 info; - pD3D->GetAdapterIdentifier(Adapter, 0, &info); + g_pD3DObject->GetAdapterIdentifier(Adapter, 0, &info); LogOapi("3D-Adapter.............. : %s",info.Description); LogAlw("dwFSMode................ : %u",dwFSMode); @@ -187,9 +179,9 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) { dwDisplayMode = 0; D3DDISPLAYMODE mode; - if (AdapterGetAdapterCount()) { - if (ModeGetAdapterModeCount(Adapter, D3DFMT_X8R8G8B8)) { - pD3D->EnumAdapterModes(Adapter, D3DFMT_X8R8G8B8, Mode, &mode); + if (AdapterGetAdapterCount()) { + if (ModeGetAdapterModeCount(Adapter, D3DFMT_X8R8G8B8)) { + g_pD3DObject->EnumAdapterModes(Adapter, D3DFMT_X8R8G8B8, Mode, &mode); dwRenderWidth = mode.Width; dwRenderHeight = mode.Height; } @@ -233,19 +225,19 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) // Hardware CAPS Checks -------------------------------------------------- // - HRESULT hr = pD3D->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps); + HRESULT hr = g_pD3DObject->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps); if (hr!=S_OK) { - LogErr("pD3D->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps)"); + LogErr("g_pD3DObject->GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, &caps)"); return hr; } // AA CAPS Checks -------------------------------------------------- // DWORD aamax = 0; - if (pD3D->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_2_SAMPLES, NULL)==S_OK) aamax=2; - if (pD3D->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_4_SAMPLES, NULL)==S_OK) aamax=4; - if (pD3D->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_8_SAMPLES, NULL)==S_OK) aamax=8; + if (g_pD3DObject->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_2_SAMPLES, NULL)==S_OK) aamax=2; + if (g_pD3DObject->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_4_SAMPLES, NULL)==S_OK) aamax=4; + if (g_pD3DObject->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_8_SAMPLES, NULL)==S_OK) aamax=8; MultiSample = min(aamax, DWORD(Config->SceneAntialias)); @@ -314,23 +306,23 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) // Check shadow mapping support // bool bShadowMap = true; - if (pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_R32F)!=S_OK) bShadowMap = false; - if (pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_R32F, D3DFMT_D24X8)!=S_OK) bShadowMap = false; + if (g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_R32F)!=S_OK) bShadowMap = false; + if (g_pD3DObject->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_R32F, D3DFMT_D24X8)!=S_OK) bShadowMap = false; if (bShadowMap) LogOapi("Shadow Mapping.......... : Yes"); else LogOapi("Shadow Mapping.......... : No"); bool bFloat16BB = true; - if (pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)!=S_OK) bFloat16BB = false; - if (pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_A16B16G16R16F, D3DFMT_D24X8)!=S_OK) bFloat16BB = false; + if (g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F)!=S_OK) bFloat16BB = false; + if (g_pD3DObject->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_A16B16G16R16F, D3DFMT_D24X8)!=S_OK) bFloat16BB = false; if (bFloat16BB) LogOapi("D3DFMT_A16B16G16R16F.... : Yes"); else LogOapi("D3DFMT_A16B16G16R16F.... : No"); - HRESULT VT16BB = pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F); - HRESULT VT32BB = pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F); - HRESULT VT16BC = pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F); - HRESULT VT32BC = pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R32F); + HRESULT VT16BB = g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A16B16G16R16F); + HRESULT VT32BB = g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F); + HRESULT VT16BC = g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R16F); + HRESULT VT32BC = g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_QUERY_VERTEXTEXTURE, D3DRTYPE_TEXTURE, D3DFMT_R32F); if (VT16BB == S_OK) LogOapi("Vertex_A16B16G16R16F.... : Yes"); else LogOapi("Vertex_A16B16G16R16F.... : No"); @@ -345,23 +337,23 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) bool bFloat32BB = true; - if (pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)!=S_OK) bFloat32BB = false; + if (g_pD3DObject->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A32B32G32R32F)!=S_OK) bFloat32BB = false; if (bFloat32BB) LogOapi("D3DFMT_A32B32G32R32F.... : Yes"); else LogOapi("D3DFMT_A32B32G32R32F.... : No"); - HRESULT D32F = pD3D->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32F_LOCKABLE); + HRESULT D32F = g_pD3DObject->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32F_LOCKABLE); if (D32F==S_OK) LogOapi("D3DFMT_D32F_LOCKABLE.... : Yes"); else LogOapi("D3DFMT_D32F_LOCKABLE.... : No"); - HRESULT AR10 = pD3D->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A2R10G10B10); + HRESULT AR10 = g_pD3DObject->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_A2R10G10B10); if (AR10==S_OK) LogOapi("D3DFMT_A2R10G10B10...... : Yes"); else LogOapi("D3DFMT_A2R10G10B10...... : No"); - HRESULT L8 = pD3D->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L8); - if (pD3D->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_L8, D3DFMT_D24X8) != S_OK) L8 = S_FALSE;//-1; + HRESULT L8 = g_pD3DObject->CheckDeviceFormat(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L8); + if (g_pD3DObject->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_L8, D3DFMT_D24X8) != S_OK) L8 = S_FALSE;//-1; if (L8 == S_OK) LogOapi("D3DFMT_L8............... : Yes"); else LogOapi("D3DFMT_L8............... : No"); @@ -486,7 +478,7 @@ HRESULT CD3DFramework9::CreateFullscreenMode() // Store the rectangle which contains the renderer SetRect(&rcScreenRect, 0, 0, dwRenderWidth, dwRenderHeight); - HR(pD3D->CheckDeviceType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false)); + HR(g_pD3DObject->CheckDeviceType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false)); LogAlw("[FULLSCREEN MODE] %u x %u, hWindow=%s", dwRenderWidth, dwRenderHeight, _PTR(hWnd)); @@ -519,7 +511,7 @@ HRESULT CD3DFramework9::CreateFullscreenMode() if (DDM) devBehaviorFlags |= D3DCREATE_DISABLE_DRIVER_MANAGEMENT; - HR(pD3D->CreateDevice( + HR(g_pD3DObject->CreateDevice( Adapter, // primary adapter D3DDEVTYPE_HAL, // device type hWnd, // window associated with device @@ -566,7 +558,7 @@ HRESULT CD3DFramework9::CreateWindowedMode() if (MultiSample) { DWORD level; - HR(pD3D->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, (D3DMULTISAMPLE_TYPE)MultiSample, &level)); + HR(g_pD3DObject->CheckDeviceMultiSampleType(Adapter, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, (D3DMULTISAMPLE_TYPE)MultiSample, &level)); d3dPP.BackBufferWidth = dwRenderWidth; d3dPP.BackBufferHeight = dwRenderHeight; @@ -614,7 +606,7 @@ HRESULT CD3DFramework9::CreateWindowedMode() LogErr("[WARNING] NVPerfHUD mode is Active (Disable from D3D9Client.cfg) [WARNING]"); - hr = pD3D->CreateDevice( + hr = g_pD3DObject->CreateDevice( Adapter, // primary adapter D3DDEVTYPE_REF, // device type hWnd, // window associated with device @@ -624,7 +616,7 @@ HRESULT CD3DFramework9::CreateWindowedMode() } else { - hr = pD3D->CreateDevice( + hr = g_pD3DObject->CreateDevice( Adapter, // primary adapter D3DDEVTYPE_HAL, // device type hWnd, // window associated with device diff --git a/OVP/D3D9Client/D3D9Frame.h b/OVP/D3D9Client/D3D9Frame.h index 6bbc72eb0..18569b3ad 100644 --- a/OVP/D3D9Client/D3D9Frame.h +++ b/OVP/D3D9Client/D3D9Frame.h @@ -57,7 +57,6 @@ class CD3DFramework9 DWORD dwRenderWidth; // Dimensions of the render target DWORD dwRenderHeight; // Dimensions of the render target DWORD dwFSMode; - LPDIRECT3D9 pD3D; // The Direct3D object LPDIRECT3DDEVICE9 pDevice; // The D3D device LPD3DXFONT pLargeFont; LPD3DXFONT pSmallFont; @@ -84,7 +83,6 @@ class CD3DFramework9 // Access functions for DirectX objects inline HWND GetRenderWindow() const { return hWnd; } - inline LPDIRECT3D9 GetDirect3D() const { return pD3D; } inline LPDIRECT3DDEVICE9 GetD3DDevice() const { return pDevice; } inline DWORD GetZBufferBitDepth() const { return dwZBufferBitDepth; } inline DWORD GetStencilBitDepth() const { return dwStencilBitDepth; } diff --git a/OVP/D3D9Client/VideoTab.cpp b/OVP/D3D9Client/VideoTab.cpp index e8cbe4119..ffb6c0ec8 100644 --- a/OVP/D3D9Client/VideoTab.cpp +++ b/OVP/D3D9Client/VideoTab.cpp @@ -174,81 +174,81 @@ void VideoTab::Initialise() SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hTab, IDC_VID_BPP, CB_RESETCONTENT, 0, 0); - ScanAtmoCfgs(); - // Create the Direct3D9 --------------------------------------------- - // - IDirect3D9* d3dObject = Direct3DCreate9(D3D_SDK_VERSION); + char cbuf[32]; + int nAdapter = g_pD3DObject->GetAdapterCount(); - if (d3dObject==NULL) LogErr("VideoTab::Initialize() Direct3DCreate9 Failed"); - else { + if (nAdapter == 0) { + LogErr("VideoTab::Initialize() No DirectX9 Adapters Found"); + return; + } - char cbuf[32]; - int nAdapter = d3dObject->GetAdapterCount(); - - if (data->deviceidx < 0 || (data->deviceidx)>=nAdapter) { - data->deviceidx = 0; - } + if (data->deviceidx < 0 || (data->deviceidx)>=nAdapter) data->deviceidx = 0; - for (int i=0;iGetAdapterIdentifier(i, 0, &info); - SendDlgItemMessageA(hTab, IDC_VID_DEVICE, CB_ADDSTRING, 0, (LPARAM)info.Description); - } + for (int i=0;iGetAdapterIdentifier(i, 0, &info)); + LogAlw("Adapter %d: %s", i, info.Description); + SendDlgItemMessageA(hTab, IDC_VID_DEVICE, CB_ADDSTRING, 0, (LPARAM)info.Description); + } - SendDlgItemMessage(hTab, IDC_VID_DEVICE, CB_SETCURSEL, data->deviceidx, 0); + SendDlgItemMessage(hTab, IDC_VID_DEVICE, CB_SETCURSEL, data->deviceidx, 0); - d3dObject->GetAdapterDisplayMode(data->deviceidx, &curMode); - UINT nModes = d3dObject->GetAdapterModeCount(data->deviceidx, D3DFMT_X8R8G8B8); - - for (UINT k=0;kEnumAdapterModes(data->deviceidx, D3DFMT_X8R8G8B8, k, &mode); - sprintf_s(cbuf,32,"%u x %u %uHz", mode.Width, mode.Height, mode.RefreshRate); - LogAlw("Index:%u %u x %u %uHz (%u)", k, mode.Width, mode.Height, mode.RefreshRate, mode.Format); - SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_ADDSTRING, 0, (LPARAM)cbuf); - SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_SETITEMDATA, k, (LPARAM)(mode.Height<<16 | mode.Width)); - } + HR(g_pD3DObject->GetAdapterDisplayMode(data->deviceidx, &curMode)); - SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"True Full Screen (no alt-tab)"); - SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Full Screen Window"); - SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Window with Taskbar"); - SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_SETCURSEL, (data->modeidx>>8)&0xFF, 0); + LogAlw("Current Mode W=%u, H=%u", curMode.Width, curMode.Height); - //SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC5), "Resolution"); - SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC6), "Full Screen Mode"); + UINT nModes = g_pD3DObject->GetAdapterModeCount(data->deviceidx, D3DFMT_X8R8G8B8); + if (nModes == 0) { + LogErr("VideoTab::Initialize() No Display Modes Available"); + } - SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0); - SendDlgItemMessage(hTab, IDC_VID_VSYNC, BM_SETCHECK, data->novsync ? BST_CHECKED : BST_UNCHECKED, 0); + for (UINT k=0;kEnumAdapterModes(data->deviceidx, D3DFMT_X8R8G8B8, k, &mode)); + sprintf_s(cbuf,32,"%u x %u %uHz", mode.Width, mode.Height, mode.RefreshRate); + LogAlw("Index:%u %u x %u %uHz (%u)", k, mode.Width, mode.Height, mode.RefreshRate, mode.Format); + SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_ADDSTRING, 0, (LPARAM)cbuf); + SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_SETITEMDATA, k, (LPARAM)(mode.Height<<16 | mode.Width)); + } + + SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"True Full Screen (no alt-tab)"); + SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Full Screen Window"); + SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_ADDSTRING, 0, (LPARAM)"Window with Taskbar"); + SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_SETCURSEL, (data->modeidx>>8)&0xFF, 0); + + //SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC5), "Resolution"); + SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC6), "Full Screen Mode"); + + + SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0); + SendDlgItemMessage(hTab, IDC_VID_VSYNC, BM_SETCHECK, data->novsync ? BST_CHECKED : BST_UNCHECKED, 0); - SetWindowText(GetDlgItem(hTab, IDC_VID_WIDTH), std::to_string(data->winw).c_str()); - SetWindowText(GetDlgItem(hTab, IDC_VID_HEIGHT), std::to_string(data->winh).c_str()); + SetWindowText(GetDlgItem(hTab, IDC_VID_WIDTH), std::to_string(data->winw).c_str()); + SetWindowText(GetDlgItem(hTab, IDC_VID_HEIGHT), std::to_string(data->winh).c_str()); - aspect_idx = 0; + aspect_idx = 0; - if (data->winw == (4*data->winh)/3 || data->winh == (3*data->winw)/4) aspect_idx = 1; - else if (data->winw == (16*data->winh)/10 || data->winh == (10*data->winw)/16) aspect_idx = 2; - else if (data->winw == (16*data->winh)/9 || data->winh == (9*data->winw)/16) aspect_idx = 3; + if (data->winw == (4*data->winh)/3 || data->winh == (3*data->winw)/4) aspect_idx = 1; + else if (data->winw == (16*data->winh)/10 || data->winh == (10*data->winw)/16) aspect_idx = 2; + else if (data->winw == (16*data->winh)/9 || data->winh == (9*data->winw)/16) aspect_idx = 3; - SendDlgItemMessage(hTab, IDC_VID_ASPECT, BM_SETCHECK, aspect_idx ? BST_CHECKED : BST_UNCHECKED, 0); - if (aspect_idx) aspect_idx--; - SendDlgItemMessage(hTab, IDC_VID_4X3+aspect_idx, BM_SETCHECK, BST_CHECKED, 0); + SendDlgItemMessage(hTab, IDC_VID_ASPECT, BM_SETCHECK, aspect_idx ? BST_CHECKED : BST_UNCHECKED, 0); + if (aspect_idx) aspect_idx--; + SendDlgItemMessage(hTab, IDC_VID_4X3+aspect_idx, BM_SETCHECK, BST_CHECKED, 0); - SendDlgItemMessage(hTab, IDC_VID_STENCIL, BM_SETCHECK, data->trystencil, 0); // GDI Compatibility mode - SendDlgItemMessage(hTab, IDC_VID_ENUM, BM_SETCHECK, data->forceenum, 0); - SendDlgItemMessage(hTab, IDC_VID_PAGEFLIP, BM_SETCHECK, data->pageflip, 0); // Full scrren Window - - SAFE_RELEASE(d3dObject); + SendDlgItemMessage(hTab, IDC_VID_STENCIL, BM_SETCHECK, data->trystencil, 0); // GDI Compatibility mode + SendDlgItemMessage(hTab, IDC_VID_ENUM, BM_SETCHECK, data->forceenum, 0); + SendDlgItemMessage(hTab, IDC_VID_PAGEFLIP, BM_SETCHECK, data->pageflip, 0); // Full scrren Window - SelectAdapter(data->deviceidx); + SelectAdapter(data->deviceidx); - SelectFullscreen(data->fullscreen); + SelectFullscreen(data->fullscreen); - ShowWindow (GetDlgItem (hTab, IDC_VID_INFO), SW_SHOW); + ShowWindow (GetDlgItem (hTab, IDC_VID_INFO), SW_SHOW); - SetWindowText(GetDlgItem(hTab, IDC_VID_INFO), "Advanced"); - } + SetWindowText(GetDlgItem(hTab, IDC_VID_INFO), "Advanced"); } @@ -274,35 +274,37 @@ void VideoTab::SelectAdapter(DWORD index) // Create the Direct3D9 --------------------------------------------- // - IDirect3D9* d3dObject = Direct3DCreate9(D3D_SDK_VERSION); - if (d3dObject==NULL) LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed",index); + if (g_pD3DObject == NULL) LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed",index); else { char cbuf[32]; D3DDISPLAYMODE mode, curMode; - if (d3dObject->GetAdapterCount()<=index) { + if (g_pD3DObject->GetAdapterCount()<=index) { LogErr("Adapter Index out of range"); return; } - d3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &curMode); + HR(g_pD3DObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &curMode)); SendDlgItemMessage(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0); - DWORD nModes = d3dObject->GetAdapterModeCount(index, D3DFMT_X8R8G8B8); + DWORD nModes = g_pD3DObject->GetAdapterModeCount(index, D3DFMT_X8R8G8B8); + + if (nModes == 0) { + LogErr("VideoTab::SelectAdapter() No Display Modes Available"); + return; + } for (DWORD k=0;kEnumAdapterModes(index, D3DFMT_X8R8G8B8, k, &mode); + HR(g_pD3DObject->EnumAdapterModes(index, D3DFMT_X8R8G8B8, k, &mode)); sprintf_s(cbuf,32,"%u x %u %uHz", mode.Width, mode.Height, mode.RefreshRate); SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_ADDSTRING, 0, (LPARAM)cbuf); SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_SETITEMDATA, k, (LPARAM)(mode.Height<<16 | mode.Width)); } SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0); - - SAFE_RELEASE(d3dObject); } } @@ -549,24 +551,21 @@ INT_PTR CALLBACK VideoTab::SetupDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPA void VideoTab::InitSetupDialog(HWND hWnd) { - // Create the Direct3D9 --------------------------------------------- - // - IDirect3D9* d3dObject = Direct3DCreate9(D3D_SDK_VERSION); char cbuf[32]; DWORD aamax = 0; D3DCAPS9 caps; - if (d3dObject==NULL) { - LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed",SelectedAdapterIdx); + if (g_pD3DObject == NULL) { + LogErr("VideoTab::SelectAdapter(%u) Direct3DCreate9 Failed", SelectedAdapterIdx); return; } - d3dObject->GetDeviceCaps(SelectedAdapterIdx, D3DDEVTYPE_HAL, &caps); + g_pD3DObject->GetDeviceCaps(SelectedAdapterIdx, D3DDEVTYPE_HAL, &caps); - if (d3dObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_2_SAMPLES, NULL)==S_OK) aamax=2; - if (d3dObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_4_SAMPLES, NULL)==S_OK) aamax=4; - if (d3dObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_8_SAMPLES, NULL)==S_OK) aamax=8; + if (g_pD3DObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_2_SAMPLES, NULL)==S_OK) aamax=2; + if (g_pD3DObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_4_SAMPLES, NULL)==S_OK) aamax=4; + if (g_pD3DObject->CheckDeviceMultiSampleType(SelectedAdapterIdx, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_8_SAMPLES, NULL)==S_OK) aamax=8; LogAlw("InitSetupDialog() Enum Device AA capability = %u",aamax); @@ -847,8 +846,6 @@ void VideoTab::InitSetupDialog(HWND hWnd) case 4: SendDlgItemMessage(hWnd, IDC_AA, CB_SETCURSEL, 2, 0); break; case 8: SendDlgItemMessage(hWnd, IDC_AA, CB_SETCURSEL, 3, 0); break; } - - SAFE_RELEASE(d3dObject); } From 21e9229815139b0893eec34313cb9e65e2c61818 Mon Sep 17 00:00:00 2001 From: jarmonik Date: Wed, 27 Dec 2023 20:09:21 +0200 Subject: [PATCH 2/2] Added a note, regarding link error with outdated d3d9.lib --- OVP/D3D9Client/D3D9Client.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index 787a78717..c73c3d587 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -319,6 +319,7 @@ bool D3D9Client::clbkInitialise() D3D9ON12_ARGS args = {}; args.Enable9On12 = Config->Enable9On12 != 0; + // NOTE: Link error 'unresolved external symbol' means that d3d9.lib is outdated, use the latest one. g_pD3DObject = Direct3DCreate9On12(D3D_SDK_VERSION, &args, 1); if (g_pD3DObject) {