Browse Source

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!
Adam Johnson 11 years ago
parent
commit
185118d21c
  1. 2
      Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt
  2. 82
      Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.cpp
  3. 60
      Sources/Plasma/PubUtilLib/plPipeline/DX/hsGDirect3D.h
  4. 10
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.cpp
  5. 2
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h
  6. 94
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp
  7. 2
      Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h

2
Sources/Plasma/PubUtilLib/plPipeline/CMakeLists.txt

@ -32,6 +32,7 @@ set(plPipeline_SOURCES
) )
set(plDXPipeline_SOURCES set(plDXPipeline_SOURCES
DX/hsGDirect3D.cpp
DX/plDXDeviceRefs.cpp DX/plDXDeviceRefs.cpp
DX/plDXEnumerate.cpp DX/plDXEnumerate.cpp
DX/plDXPipeline.cpp DX/plDXPipeline.cpp
@ -73,6 +74,7 @@ set(plPipeline_HEADERS
) )
set(plDXPipeline_HEADERS set(plDXPipeline_HEADERS
DX/hsGDirect3D.h
DX/plDXBufferRefs.h DX/plDXBufferRefs.h
DX/plDXDeviceRef.h DX/plDXDeviceRef.h
DX/plDXEnumerate.h DX/plDXEnumerate.h

82
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 <http://www.gnu.org/licenses/>.
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 <d3d9.h>
#include <functional>
#include <memory>
static std::unique_ptr<hsGDirect3DTnLEnumerate> 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<IDirect3D9, std::function<void(IDirect3D9*)>> 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();
}

60
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 <http://www.gnu.org/licenses/>.
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_

10
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 "plDXEnumerate.h"
#include "plPipeline/hsG3DDeviceSelector.h" #include "plPipeline/hsG3DDeviceSelector.h"
#include "hsGDirect3D.h"
//// Local Typedefs /////////////////////////////////////////////////////////// //// Local Typedefs ///////////////////////////////////////////////////////////
@ -281,8 +282,8 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate()
fDrivers.Reset(); // List of DD drivers fDrivers.Reset(); // List of DD drivers
// Create a D3D object to use // Create a D3D object to use
IDirect3D9 *pD3D = Direct3DCreate9( D3D_SDK_VERSION ); IDirect3D9* pD3D = hsGDirect3D::GetDirect3D();
if( pD3D == nil ) if (!pD3D)
{ {
strcpy( fEnumeErrorStr, "Cannot load DirectX!" ); strcpy( fEnumeErrorStr, "Cannot load DirectX!" );
return; return;
@ -309,9 +310,6 @@ hsGDirect3DTnLEnumerate::hsGDirect3DTnLEnumerate()
/// Do the mode and device enumeration for this adapter /// Do the mode and device enumeration for this adapter
IEnumAdapterDevices( pD3D, iAdapter, newDriver ); IEnumAdapterDevices( pD3D, iAdapter, newDriver );
} }
// Cleanup
pD3D->Release();
} }
//// IEnumAdapterDevices ////////////////////////////////////////////////////// //// IEnumAdapterDevices //////////////////////////////////////////////////////
@ -645,7 +643,7 @@ bool hsG3DDeviceSelector::IGetD3DCardInfo( hsG3DDeviceRecord &record,
void hsG3DDeviceSelector::ITryDirect3DTnL(hsWinRef winRef) void hsG3DDeviceSelector::ITryDirect3DTnL(hsWinRef winRef)
{ {
hsGDirect3DTnLEnumerate d3dEnum; hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL();
int i; int i;
for( i = 0; i < d3dEnum.GetNumDrivers(); i++ ) for( i = 0; i < d3dEnum.GetNumDrivers(); i++ )

2
Sources/Plasma/PubUtilLib/plPipeline/DX/plDXEnumerate.h

@ -121,8 +121,6 @@ class hsG3DDeviceMode;
class hsGDirect3DTnLEnumerate class hsGDirect3DTnLEnumerate
{ {
protected: protected:
HMODULE fDDrawDLL;
char fEnumeErrorStr[128]; // ドライバ、デバイス列挙エラーメッセージ格納バッファ char fEnumeErrorStr[128]; // ドライバ、デバイス列挙エラーメッセージ格納バッファ
hsTArray<D3DEnum_DriverInfo> fDrivers; hsTArray<D3DEnum_DriverInfo> fDrivers;

94
Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.cpp

@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <d3d9.h> #include <d3d9.h>
#include <d3dx9mesh.h> #include <d3dx9mesh.h>
#include "hsGDirect3D.h"
#if defined(DX_OLD_SDK) || defined(__MINGW32__) #if defined(DX_OLD_SDK) || defined(__MINGW32__)
#include <dxerr9.h> #include <dxerr9.h>
@ -623,7 +624,7 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR
else else
fSettings.fNumAASamples = devMode->GetFSAAType( devRec->GetAASetting() - 1 ); fSettings.fNumAASamples = devMode->GetFSAAType( devRec->GetAASetting() - 1 );
hsGDirect3DTnLEnumerate d3dEnum; hsGDirect3DTnLEnumerate& d3dEnum = hsGDirect3D::EnumerateTnL();
if( d3dEnum.GetEnumeErrorStr()[ 0 ] ) if( d3dEnum.GetEnumeErrorStr()[ 0 ] )
{ {
IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() ); IShowErrorMessage( (char *)d3dEnum.GetEnumeErrorStr() );
@ -636,16 +637,6 @@ plDXPipeline::plDXPipeline( hsWinRef hWnd, const hsG3DDeviceModeRecord *devModeR
return; 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. // Record the requested mode/setup.
ISetCurrentDriver( d3dEnum.GetCurrentDriver() ); ISetCurrentDriver( d3dEnum.GetCurrentDriver() );
ISetCurrentDevice( d3dEnum.GetCurrentDevice() ); 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); 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(). // 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 // 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 // to delete or set to a valid pointer. It must be set to a valid pointer
// before the pipeline can be used for much. // 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. // render state will be initialized in IInitDeviceState.
void plDXPipeline::IClearMembers() void plDXPipeline::IClearMembers()
@ -772,7 +765,6 @@ void plDXPipeline::IClearMembers()
fBlurVBuffers[i] = nil; fBlurVBuffers[i] = nil;
fBlurVSHandle = 0; fBlurVSHandle = 0;
fD3DObject = nil;
fD3DDevice = nil; fD3DDevice = nil;
fD3DBackBuff = nil; fD3DBackBuff = nil;
fD3DDepthSurface = nil; fD3DDepthSurface = nil;
@ -1388,11 +1380,13 @@ void plDXPipeline::ISetCurrentDriver( D3DEnum_DriverInfo *driv )
fCurrentDriver->fCurrentDevice = nil; fCurrentDriver->fCurrentDevice = nil;
/// Go looking for an adapter to match this one /// Go looking for an adapter to match this one
IDirect3D9* d3d = hsGDirect3D::GetDirect3D();
UINT iAdapter; UINT iAdapter;
for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < fD3DObject->GetAdapterCount(); iAdapter++ )
for( fCurrentAdapter = 0, iAdapter = 0; iAdapter < d3d->GetAdapterCount(); iAdapter++ )
{ {
D3DADAPTER_IDENTIFIER9 adapterInfo; D3DADAPTER_IDENTIFIER9 adapterInfo;
fD3DObject->GetAdapterIdentifier( iAdapter, 0, &adapterInfo ); d3d->GetAdapterIdentifier( iAdapter, 0, &adapterInfo );
if( adapterInfo.DeviceIdentifier == fCurrentDriver->fAdapterInfo.DeviceIdentifier ) if( adapterInfo.DeviceIdentifier == fCurrentDriver->fAdapterInfo.DeviceIdentifier )
{ {
@ -1469,7 +1463,7 @@ bool plDXPipeline::IFindCompressedFormats()
for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ )
{ {
if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, if( FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType,
fCurrentMode->fDDmode.Format, fCurrentMode->fDDmode.Format,
0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) )
return false; return false;
@ -1491,7 +1485,7 @@ bool plDXPipeline::IFindLuminanceFormats()
for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ ) for( i = 0; toCheckFor[ i ] != D3DFMT_UNKNOWN; i++ )
{ {
if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, if (FAILED(hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType,
fCurrentMode->fDDmode.Format, fCurrentMode->fDDmode.Format,
0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) ) 0, D3DRTYPE_TEXTURE, toCheckFor[ i ] ) ) )
return false; return false;
@ -1508,7 +1502,7 @@ bool plDXPipeline::IFindLuminanceFormats()
bool plDXPipeline::ITextureFormatAllowed( D3DFORMAT format ) bool plDXPipeline::ITextureFormatAllowed( D3DFORMAT format )
{ {
if( FAILED( fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, if (FAILED( hsGDirect3D::GetDirect3D()->CheckDeviceFormat(fCurrentAdapter, fCurrentDevice->fDDType,
fCurrentMode->fDDmode.Format, fCurrentMode->fDDmode.Format,
0, D3DRTYPE_TEXTURE, format ) ) ) 0, D3DRTYPE_TEXTURE, format ) ) )
return false; return false;
@ -1555,23 +1549,6 @@ bool plDXPipeline::IsDebugFlagSet( uint32_t flag ) const
//// Device Creation ////////////////////////////////////////////////////////// //// 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 //////////////////////////////////////////////////// //// ICreateDevice ////////////////////////////////////////////////////
// //
// Creates the device. Surfaces, buffers, etc. created separately (in case of lost device). // 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 ]; char msg[ 256 ];
#endif // DBG_WRITE_FORMATS #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" ); "Cannot get desktop display mode" );
// save desktop properties // save desktop properties
@ -1684,10 +1665,10 @@ bool plDXPipeline::ICreateDevice(bool windowed)
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
UINT adapter; UINT adapter;
for (adapter = 0; adapter < fD3DObject->GetAdapterCount(); adapter++) for (adapter = 0; adapter < d3d->GetAdapterCount(); adapter++)
{ {
D3DADAPTER_IDENTIFIER9 id; D3DADAPTER_IDENTIFIER9 id;
fD3DObject->GetAdapterIdentifier(adapter, 0, &id); d3d->GetAdapterIdentifier(adapter, 0, &id);
// We should be matching against "NVIDIA NVPerfHUD", but the space // We should be matching against "NVIDIA NVPerfHUD", but the space
// in the description seems to be bogus. This seems to be a fair // in the description seems to be bogus. This seems to be a fair
@ -1705,7 +1686,7 @@ bool plDXPipeline::ICreateDevice(bool windowed)
} }
#endif // PLASMA_EXTERNAL_RELEASE #endif // PLASMA_EXTERNAL_RELEASE
INIT_ERROR_CHECK( fD3DObject->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType, INIT_ERROR_CHECK( d3d->CreateDevice( fCurrentAdapter, fCurrentDevice->fDDType,
fSettings.fHWnd, fCurrentMode->fDDBehavior, fSettings.fHWnd, fCurrentMode->fDDBehavior,
&params, &fD3DDevice ), &params, &fD3DDevice ),
"Cannot create primary display surface via CreateDevice()" ); "Cannot create primary display surface via CreateDevice()" );
@ -1736,6 +1717,8 @@ bool plDXPipeline::ICreateDevice(bool windowed)
// will work. // will work.
bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params) 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 // 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 // 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. // looking for trouble, we're going to look for a depth buffer with NO STENCIL.
@ -1747,7 +1730,7 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params)
||(fmt == D3DFMT_D24X8) ||(fmt == D3DFMT_D24X8)
||(fmt == D3DFMT_D16) ) ||(fmt == D3DFMT_D16) )
{ {
HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter,
fCurrentDevice->fDDType, fCurrentDevice->fDDType,
fmt, fmt,
fCurrentMode->fWindowed ? TRUE : FALSE, fCurrentMode->fWindowed ? TRUE : FALSE,
@ -1767,7 +1750,7 @@ bool plDXPipeline::IFindDepthFormat(D3DPRESENT_PARAMETERS& params)
D3DFORMAT fmt = fCurrentMode->fDepthFormats[ i ]; D3DFORMAT fmt = fCurrentMode->fDepthFormats[ i ];
if( fmt == D3DFMT_D15S1 || fmt == D3DFMT_D24X4S4 || fmt == D3DFMT_D24S8 ) if( fmt == D3DFMT_D15S1 || fmt == D3DFMT_D24X4S4 || fmt == D3DFMT_D24S8 )
{ {
HRESULT hr = fD3DObject->CheckDeviceMultiSampleType(fCurrentAdapter, HRESULT hr = d3d->CheckDeviceMultiSampleType(fCurrentAdapter,
fCurrentDevice->fDDType, fCurrentDevice->fDDType,
fmt, fmt,
fCurrentMode->fWindowed ? TRUE : FALSE, fCurrentMode->fWindowed ? TRUE : FALSE,
@ -2033,16 +2016,6 @@ void plDXPipeline::IReleaseDeviceObjects()
fD3DDevice = nil; fD3DDevice = nil;
} }
if( fD3DObject != nil )
{
LONG ret;
while( ret = fD3DObject->Release() )
{
hsStatusMessageF("%d - Error releasing Direct3D Object", ret);
}
fD3DObject = nil;
}
fManagedAlloced = false; fManagedAlloced = false;
fAllocUnManaged = false; fAllocUnManaged = false;
} }
@ -2541,14 +2514,11 @@ void plDXPipeline::Resize( uint32_t width, uint32_t height )
} }
// Recreate // Recreate
if( !fD3DObject ) if( hsGDirect3D::GetDirect3D(true) )
{
if( ICreateMaster() )
{ {
IShowErrorMessage( "Cannot create D3D master object" ); IShowErrorMessage( "Cannot create D3D master object" );
return; return;
} }
}
// Go recreate surfaces and DX-dependent objects // Go recreate surfaces and DX-dependent objects
if( ICreateDeviceObjects() ) if( ICreateDeviceObjects() )
@ -4780,6 +4750,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
uint16_t flags, width, height; uint16_t flags, width, height;
int8_t bitDepth, zDepth, stencilDepth, stencilIndex; int8_t bitDepth, zDepth, stencilDepth, stencilIndex;
D3DFORMAT depthFormats[] = { D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D24S8 }; D3DFORMAT depthFormats[] = { D3DFMT_D24X8, D3DFMT_D24X4S4, D3DFMT_D24S8 };
IDirect3D9* d3d = hsGDirect3D::GetDirect3D();
flags = owner->GetFlags(); flags = owner->GetFlags();
@ -4846,7 +4817,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
} }
/// Check the device format /// Check the device format
if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) )
{ {
if( bitDepth == 16 ) if( bitDepth == 16 )
@ -4859,7 +4830,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
bitDepth = 16; bitDepth = 16;
surfFormat = D3DFMT_A4R4G4B4; surfFormat = D3DFMT_A4R4G4B4;
} }
if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) )
{ {
IGetD3DError(); IGetD3DError();
@ -4869,7 +4840,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
if( zDepth ) if( zDepth )
{ {
while( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, while( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) ) D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, depthFormat ) ) )
{ {
if( stencilIndex < sizeof( depthFormats ) / sizeof( depthFormats[ 0 ] ) - 1 ) if( stencilIndex < sizeof( depthFormats ) / sizeof( depthFormats[ 0 ] ) - 1 )
@ -4884,7 +4855,7 @@ bool plDXPipeline::IPrepRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
} }
} }
if( FAILED( fSettings.fDXError = fD3DObject->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, if( FAILED( fSettings.fDXError = d3d->CheckDepthStencilMatch( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
surfFormat, depthFormat ) ) ) surfFormat, depthFormat ) ) )
{ {
IGetD3DError(); IGetD3DError();
@ -4912,6 +4883,7 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
height = owner->GetHeight(); height = owner->GetHeight();
bitDepth = owner->GetPixelSize(); bitDepth = owner->GetPixelSize();
IDirect3D9* d3d = hsGDirect3D::GetDirect3D();
if( flags != 0 ) if( flags != 0 )
{ {
if( flags & plRenderTarget::kIsTexture ) if( flags & plRenderTarget::kIsTexture )
@ -4932,7 +4904,7 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
} }
/// Check the device format /// Check the device format
if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) )
{ {
if( bitDepth == 16 ) if( bitDepth == 16 )
@ -4945,7 +4917,7 @@ bool plDXPipeline::IFindRenderTargetInfo( plRenderTarget *owner, D3DFORMAT &sur
bitDepth = 16; bitDepth = 16;
surfFormat = D3DFMT_A4R4G4B4; surfFormat = D3DFMT_A4R4G4B4;
} }
if( FAILED( fSettings.fDXError = fD3DObject->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format, if( FAILED( fSettings.fDXError = d3d->CheckDeviceFormat( fCurrentAdapter, fCurrentDevice->fDDType, fCurrentMode->fDDmode.Format,
D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) ) D3DUSAGE_RENDERTARGET, resType, surfFormat ) ) )
{ {
IGetD3DError(); IGetD3DError();

2
Sources/Plasma/PubUtilLib/plPipeline/DX/plDXPipeline.h

@ -208,7 +208,6 @@ protected:
plDXPlateManager* fPlateMgr; plDXPlateManager* fPlateMgr;
// The main D3D interfaces // The main D3D interfaces
LPDIRECT3D9 fD3DObject; // The main D3D object
LPDIRECT3DDEVICE9 fD3DDevice; // The D3D rendering device LPDIRECT3DDEVICE9 fD3DDevice; // The D3D rendering device
IDirect3DSurface9* fD3DMainSurface; IDirect3DSurface9* fD3DMainSurface;
IDirect3DSurface9* fD3DDepthSurface; IDirect3DSurface9* fD3DDepthSurface;
@ -502,7 +501,6 @@ protected:
void ISetCurrentDevice( D3DEnum_DeviceInfo *dev ); void ISetCurrentDevice( D3DEnum_DeviceInfo *dev );
void ISetCurrentMode( D3DEnum_ModeInfo *mode ); void ISetCurrentMode( D3DEnum_ModeInfo *mode );
bool ICreateMaster();
bool ICreateDevice(bool windowed); bool ICreateDevice(bool windowed);
bool ICreateNormalSurfaces(); bool ICreateNormalSurfaces();

Loading…
Cancel
Save