From 185118d21cddddd338d278025f55f2d5daf4e200 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 30 Nov 2013 22:51:23 -0500 Subject: [PATCH] Better management of TnLEnums and Direct3D9 object Two of the big nasties, according to profiling, are the TnL enum and creation of Direct3D objects. It turned out we were doing these things several times (3 and 4 respectively) during the init process. So, now we have an hsGDirect3D namespace and some smart pointers to manage them! --- .../PubUtilLib/plPipeline/CMakeLists.txt | 2 + .../PubUtilLib/plPipeline/DX/hsGDirect3D.cpp | 82 ++++++++++ .../PubUtilLib/plPipeline/DX/hsGDirect3D.h | 60 ++++++++ .../plPipeline/DX/plDXEnumerate.cpp | 10 +- .../PubUtilLib/plPipeline/DX/plDXEnumerate.h | 2 - .../PubUtilLib/plPipeline/DX/plDXPipeline.cpp | 142 +++++++----------- .../PubUtilLib/plPipeline/DX/plDXPipeline.h | 2 - 7 files changed, 205 insertions(+), 95 deletions(-) create mode 100644 Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp create mode 100644 Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h diff --git a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt index 45a5fa6c..2f7012f0 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt @@ -32,6 +32,7 @@ set(plPipeline_SOURCES ) set(plDXPipeline_SOURCES + DX/hsGDirect3D.cpp DX/plDXDeviceRefs.cpp DX/plDXEnumerate.cpp DX/plDXPipeline.cpp @@ -73,6 +74,7 @@ set(plPipeline_HEADERS ) set(plDXPipeline_HEADERS + DX/hsGDirect3D.h DX/plDXBufferRefs.h DX/plDXDeviceRef.h DX/plDXEnumerate.h diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp new file mode 100644 index 00000000..75e27227 --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp @@ -0,0 +1,82 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "hsGDirect3D.h" +#include "plDXEnumerate.h" + +#include +#include +#include + +static std::unique_ptr s_tnlEnum; +hsGDirect3DTnLEnumerate& hsGDirect3D::EnumerateTnL(bool reenum) +{ + if (reenum || !s_tnlEnum.get()) + s_tnlEnum.reset(new hsGDirect3DTnLEnumerate()); + + // Be nice to legacy code and return a reference... + hsGDirect3DTnLEnumerate* ptr = s_tnlEnum.get(); + return *ptr; +} + +void hsGDirect3D::ReleaseTnLEnum() +{ + s_tnlEnum.release(); +} + +static void IDeleteDirect3D(IDirect3D9* d3d) +{ + while (d3d->Release()) { } +} + +static std::unique_ptr> s_direct3d(nullptr, IDeleteDirect3D); +IDirect3D9* hsGDirect3D::GetDirect3D(bool recreate) +{ + if (recreate || !s_direct3d.get()) { + IDirect3D9* ptr = Direct3DCreate9(D3D_SDK_VERSION); + hsAssert(ptr, "failed to create Direct3D"); + + s_direct3d.reset(ptr); + } + return s_direct3d.get(); +} + diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h new file mode 100644 index 00000000..4088514c --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h @@ -0,0 +1,60 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#ifndef _hsGDirect3D_inc_ +#define _hsGDirect3D_inc_ + +class hsGDirect3DTnLEnumerate; +struct IDirect3D9; + +namespace hsGDirect3D +{ + hsGDirect3DTnLEnumerate& EnumerateTnL(bool reenum=false); + void ReleaseTnLEnum(); + + /** Get a root Direct3D object. + * \remarks You should not hold this pointer. + */ + IDirect3D9* GetDirect3D(bool recreate=false); +} + +#endif // _hsGDirect3D_inc_ diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp index 8588b545..de401b52 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plDXEnumerate.h" #include "plPipeline/hsG3DDeviceSelector.h" +#include "hsGDirect3D.h" //// Local Typedefs /////////////////////////////////////////////////////////// @@ -281,8 +282,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() fDrivers.Reset(); // List of DD drivers // Create a D3D object to use - IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - if( pD3D == nil ) + IDirect3D9* pD3D = hsGDirect3D::GetDirect3D(); + if (!pD3D) { strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); return; @@ -309,9 +310,6 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate() /// Do the mode and device enumeration for this adapter IEnumAdapterDevices( pD3D, iAdapter, newDriver ); } - - // Cleanup - pD3D->Release(); } //// IEnumAdapterDevices ////////////////////////////////////////////////////// @@ -645,7 +643,7 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record, void hsG3DDeviceSelector::ITryDirect3DTnL(hsWinRef winRef) { - hsGDirect3DTnLEnumerate d3dEnum; + hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL(); int i; for( i = 0; i < d3dEnum.GetNumDrivers(); i++ ) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h index 5a65803f..0a1e0e18 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h @@ -121,8 +121,6 @@ class hsG3DDeviceMode; class hsGDirect3DTnLEnumerate { protected: - HMODULE fDDrawDLL; - char fEnumeErrorStr[128]; // ドライバ、デバイス列挙エラーメッセージ格納バッファ hsTArray fDrivers; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp index 496cc6cf..7fee0784 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp @@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +#include "hsGDirect3D.h" #if defined(DX_OLD_SDK) || defined(__MINGW32__) #include @@ -623,7 +624,7 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR else fSettings.fNumAASamples = devMode->GetFSAAType( devRec->GetAASetting() - 1 ); - hsGDirect3DTnLEnumerate d3dEnum; + hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL(); if( d3dEnum.GetEnumeErrorStr()[ 0 ] ) { IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() ); @@ -636,16 +637,6 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR return; } - // Gotta create this very first, so that the device/driver init works - if( !fD3DObject ) - { - if( ICreateMaster() ) - { - IShowErrorMessage( "Cannot create D3D master object" ); - return; - } - } - // Record the requested mode/setup. ISetCurrentDriver( d3dEnum.GetCurrentDriver() ); ISetCurrentDevice( d3dEnum.GetCurrentDevice() ); @@ -693,6 +684,8 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR plStatusLog::AddLineS("pipeline.log", "%d, %d, %d", temp[i].Width, temp[i].Height, 32); }*/ + // We don't need the TnL enumeration for the lifetime of the game, so say goodbye! + hsGDirect3D::ReleaseTnLEnum(); } // Cleanup - Most happens in IReleaseDeviceObject(). @@ -720,7 +713,7 @@ plDXPipeline::~plDXPipeline() // built from. For example, the fD3DObject pointer is set to nil so that it's safe // to delete or set to a valid pointer. It must be set to a valid pointer // before the pipeline can be used for much. -// After the core initialization is done (in ICreateMaster and ICreateDeviceObjects) +// After the core initialization is done (in ICreateDeviceObjects) // render state will be initialized in IInitDeviceState. void plDXPipeline::IClearMembers() @@ -772,7 +765,6 @@ void plDXPipeline::IClearMembers() fBlurVBuffers[i] = nil; fBlurVSHandle = 0; - fD3DObject = nil; fD3DDevice = nil; fD3DBackBuff = nil; fD3DDepthSurface = nil; @@ -1388,11 +1380,13 @@ void plDXPipeline::ISetCurrentDriver( D3DEnum_DriverInfo *driv ) fCurrentDriver->fCurrentDevice = nil; /// Go looking for an adapter to match this one + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); UINT iAdapter; - for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < fD3DObject->GetAdapterCount(); iAdapter++ ) + + for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < d3d->GetAdapterCount(); iAdapter++ ) { D3DADAPTER_IDENTIFIER9 adapterInfo; - fD3DObject->GetAdapterIdentifier( iAdapter, 0, &adapterInfo ); + d3d->GetAdapterIdentifier( iAdapter, 0, &adapterInfo ); if( adapterInfo.DeviceIdentifier == fCurrentDriver->fAdapterInfo.DeviceIdentifier ) { @@ -1469,9 +1463,9 @@ bool plDXPipeline::IFindCompressedFormats() for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) + if( FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) return false; } @@ -1491,9 +1485,9 @@ bool plDXPipeline::IFindLuminanceFormats() for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) + if (FAILED(hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) return false; } @@ -1508,9 +1502,9 @@ bool plDXPipeline::IFindLuminanceFormats() bool plDXPipeline::ITextureFormatAllowed( D3DFORMAT format ) { - if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, - fCurrentMode->fDDmode.Format, - 0, D3DRTYPE_TEXTURE, format ) ) ) + if (FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType, + fCurrentMode->fDDmode.Format, + 0, D3DRTYPE_TEXTURE, format ) ) ) return false; return true; @@ -1555,23 +1549,6 @@ bool plDXPipeline::IsDebugFlagSet( uint32_t flag ) const //// Device Creation ////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -//// ICreateMaster //////////////////////////////////////////////////////////// -// Creates the master Direct3D objects. I guess just in case you want -// multiple Direct3D devices.... :~ - -bool plDXPipeline::ICreateMaster() -{ - hsAssert( !fD3DObject, "ICreateMaster() should only be called for Master Direct3DDevice" ); - - /// The new DirectX Way: Create a Direct3D object, out of which everything else springs - fD3DObject = Direct3DCreate9( D3D_SDK_VERSION ); - - if( fD3DObject == nil ) - return ICreateFail( "Cannot create Direct3D object" ); - - return false; -} - //// ICreateDevice //////////////////////////////////////////////////// // // Creates the device. Surfaces, buffers, etc. created separately (in case of lost device). @@ -1587,7 +1564,11 @@ bool plDXPipeline::ICreateDevice(bool windowed) char msg[ 256 ]; #endif // DBG_WRITE_FORMATS - INIT_ERROR_CHECK( fD3DObject->GetAdapterDisplayMode( fCurrentAdapter, &dispMode ), + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); + if (!d3d) + return ICreateFail("Failed to get Direct3D Object"); + + INIT_ERROR_CHECK( d3d->GetAdapterDisplayMode( fCurrentAdapter, &dispMode ), "Cannot get desktop display mode" ); // save desktop properties @@ -1684,10 +1665,10 @@ bool plDXPipeline::ICreateDevice(bool windowed) #ifndef PLASMA_EXTERNAL_RELEASE UINT adapter; - for (adapter = 0; adapter < fD3DObject->GetAdapterCount(); adapter++) + for (adapter = 0; adapter < d3d->GetAdapterCount(); adapter++) { D3DADAPTER_IDENTIFIER9 id; - fD3DObject->GetAdapterIdentifier(adapter, 0, &id); + d3d->GetAdapterIdentifier(adapter, 0, &id); // We should be matching against "NVIDIA NVPerfHUD", but the space // in the description seems to be bogus. This seems to be a fair @@ -1705,9 +1686,9 @@ bool plDXPipeline::ICreateDevice(bool windowed) } #endif // PLASMA_EXTERNAL_RELEASE - INIT_ERROR_CHECK( fD3DObject->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType, - fSettings.fHWnd, fCurrentMode->fDDBehavior, - ¶ms, &fD3DDevice ), + INIT_ERROR_CHECK( d3d->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType, + fSettings.fHWnd, fCurrentMode->fDDBehavior, + ¶ms, &fD3DDevice ), "Cannot create primary display surface via CreateDevice()" ); fSettings.fPresentParams = params; @@ -1736,6 +1717,8 @@ bool plDXPipeline::ICreateDevice(bool windowed) // will work. bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) { + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); + // Okay, we're not using the stencil buffer right now, and it's bringing out // some painful driver bugs on the GeForce2. So rather than go out of our way // looking for trouble, we're going to look for a depth buffer with NO STENCIL. @@ -1747,11 +1730,11 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) ||(fmt == D3DFMT_D24X8) ||(fmt == D3DFMT_D16) ) { - HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, - fCurrentDevice->fDDType, - fmt, - fCurrentMode->fWindowed ? TRUE : FALSE, - params.MultiSampleType, NULL); + HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter, + fCurrentDevice->fDDType, + fmt, + fCurrentMode->fWindowed ? TRUE : FALSE, + params.MultiSampleType, NULL); if( !FAILED(hr) ) { params.AutoDepthStencilFormat = fmt; @@ -1767,11 +1750,11 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) D3DFORMAT fmt = fCurrentMode->fDepthFormats[ i ]; if( fmt == D3DFMT_D15S1 || fmt == D3DFMT_D24X4S4 || fmt == D3DFMT_D24S8 ) { - HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, - fCurrentDevice->fDDType, - fmt, - fCurrentMode->fWindowed ? TRUE : FALSE, - params.MultiSampleType, NULL); + HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter, + fCurrentDevice->fDDType, + fmt, + fCurrentMode->fWindowed ? TRUE : FALSE, + params.MultiSampleType, NULL); if( !FAILED(hr) ) { params.AutoDepthStencilFormat = fmt; @@ -2033,16 +2016,6 @@ void plDXPipeline::IReleaseDeviceObjects() fD3DDevice = nil; } - if( fD3DObject != nil ) - { - LONG ret; - while( ret = fD3DObject->Release() ) - { - hsStatusMessageF("%d - Error releasing Direct3D Object", ret); - } - fD3DObject = nil; - } - fManagedAlloced = false; fAllocUnManaged = false; } @@ -2541,13 +2514,10 @@ void plDXPipeline::Resize( uint32_t width, uint32_t height ) } // Recreate - if( !fD3DObject ) + if( hsGDirect3D::GetDirect3D(true) ) { - if( ICreateMaster() ) - { - IShowErrorMessage( "Cannot create D3D master object" ); - return; - } + IShowErrorMessage( "Cannot create D3D master object" ); + return; } // Go recreate surfaces and DX-dependent objects @@ -4780,6 +4750,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur uint16_t flags, width, height; int8_t bitDepth, zDepth, stencilDepth, stencilIndex; D3DFORMAT depthFormats[] = { D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D24S8 }; + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); flags = owner->GetFlags(); @@ -4846,8 +4817,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } /// Check the device format - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { if( bitDepth == 16 ) { @@ -4859,8 +4830,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur bitDepth = 16; surfFormat = D3DFMT_A4R4G4B4; } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { IGetD3DError(); return false; @@ -4869,8 +4840,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur if( zDepth ) { - while( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) ) + while( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) ) { if( stencilIndex < sizeof( depthFormats ) / sizeof( depthFormats[ 0 ] ) - 1 ) { @@ -4884,8 +4855,8 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - surfFormat, depthFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + surfFormat, depthFormat ) ) ) { IGetD3DError(); return false; @@ -4912,6 +4883,7 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur height = owner->GetHeight(); bitDepth = owner->GetPixelSize(); + IDirect3D9* d3d = hsGDirect3D::GetDirect3D(); if( flags != 0 ) { if( flags & plRenderTarget::kIsTexture ) @@ -4932,8 +4904,8 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur } /// Check the device format - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { if( bitDepth == 16 ) { @@ -4945,8 +4917,8 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur bitDepth = 16; surfFormat = D3DFMT_A4R4G4B4; } - if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, - D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) + if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, + D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) { IGetD3DError(); return false; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h index d0f933fe..46d40412 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h @@ -208,7 +208,6 @@ protected: plDXPlateManager* fPlateMgr; // The main D3D interfaces - LPDIRECT3D9 fD3DObject; // The main D3D object LPDIRECT3DDEVICE9 fD3DDevice; // The D3D rendering device IDirect3DSurface9* fD3DMainSurface; IDirect3DSurface9* fD3DDepthSurface; @@ -502,7 +501,6 @@ protected: void ISetCurrentDevice( D3DEnum_DeviceInfo *dev ); void ISetCurrentMode( D3DEnum_ModeInfo *mode ); - bool ICreateMaster(); bool ICreateDevice(bool windowed); bool ICreateNormalSurfaces();