revise texstat handling

This commit is contained in:
cxgeorge 2001-08-08 01:06:01 +00:00
parent b14baa2f65
commit 94ac0d6980
3 changed files with 112 additions and 77 deletions

View File

@ -69,13 +69,13 @@
// print out simple drawprim stats every few secs // print out simple drawprim stats every few secs
//#define COUNT_DRAWPRIMS //#define COUNT_DRAWPRIMS
//#define PRINT_TEXSTATS
//#define DISABLE_DECALING //#define DISABLE_DECALING
#define DISABLE_POLYGON_OFFSET_DECALING #define DISABLE_POLYGON_OFFSET_DECALING
// currently doesnt work well enough in toontown models for us to use // currently doesnt work well enough in toontown models for us to use
// prob is when viewer gets close to decals, they disappear into wall poly, need to investigate // prob is when viewer gets close to decals, they disappear into wall poly, need to investigate
//#define PRINT_TEXSTATS
// test non-optimized general geom pipe for all models // test non-optimized general geom pipe for all models
// apparently DPStrided faults for some color G_OVERALL cases, so comment out for now // apparently DPStrided faults for some color G_OVERALL cases, so comment out for now
// not clear that it is actually faster in practice, it may even be slightly slower // not clear that it is actually faster in practice, it may even be slightly slower
@ -132,6 +132,10 @@ static void CountDPs(DWORD nVerts,DWORD nTris) {
#define CountDPs(nv,nt) #define CountDPs(nv,nt)
#endif #endif
#if defined(DO_PSTATS) || defined(PRINT_TEXSTATS)
static bool bTexStatsRetrievalImpossible=false;
#endif
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::Constructor // Function: DXGraphicsStateGuardian::Constructor
// Access: Public // Access: Public
@ -223,9 +227,9 @@ reset() {
_issued_color_enabled = false; _issued_color_enabled = false;
_enable_all_color = true; _enable_all_color = true;
// this is incorrect for mono displays, need both right and left flags set. // this is incorrect for general mono displays, need both right and left flags set.
// stereo has not been handled yet for dx // stereo has not been handled yet for dx
// _buffer_mask &= ~RenderBuffer::T_right; // test for these later // _buffer_mask &= ~RenderBuffer::T_right;
// Set up our clear values to invalid values, so the glClear* calls // Set up our clear values to invalid values, so the glClear* calls
// will be made initially. // will be made initially.
@ -912,8 +916,11 @@ render_frame() {
} }
#endif #endif
#ifdef DO_PSTATS #if defined(DO_PSTATS)||defined(PRINT_TEXSTATS)
if (_texmgrmem_total_pcollector.is_active()) { #ifndef PRINT_TEXSTATS
if (_texmgrmem_total_pcollector.is_active())
#endif
{
#define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval #define TICKS_PER_GETTEXINFO (2.5*1000) // 2.5 second interval
static DWORD LastTickCount=0; static DWORD LastTickCount=0;
DWORD CurTickCount=GetTickCount(); DWORD CurTickCount=GetTickCount();
@ -925,26 +932,77 @@ render_frame() {
} }
#endif #endif
#ifdef GSG_VERBOSE
dxgsg_cat.debug() << "end frame ----------------------------------------------" << endl;
#endif
}
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::report_texmgr_stats
// Access: Protected
// Description: Reports the DX texture manager's activity to PStats.
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
report_texmgr_stats() {
#if defined(DO_PSTATS)||defined(PRINT_TEXSTATS)
HRESULT hr;
DWORD dwTexTotal,dwTexFree,dwVidTotal,dwVidFree;
#ifndef PRINT_TEXSTATS
if (_total_texmem_pcollector.is_active())
#endif
{
DDSCAPS2 ddsCaps;
ZeroMemory(&ddsCaps,sizeof(ddsCaps));
ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
if(FAILED( hr = _pDD->GetAvailableVidMem(&ddsCaps,&dwVidTotal,&dwVidFree))) {
dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for VIDMEM failed : result = " << ConvD3DErrorToString(hr) << endl;
exit(1);
}
ddsCaps.dwCaps = DDSCAPS_TEXTURE;
if(FAILED( hr = _pDD->GetAvailableVidMem(&ddsCaps,&dwTexTotal,&dwTexFree))) {
dxgsg_cat.debug() << "report_texmgr GetAvailableVidMem for TEXTURE failed : result = " << ConvD3DErrorToString(hr) << endl;
exit(1);
}
}
D3DDEVINFO_TEXTUREMANAGER tminfo;
ZeroMemory(&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER));
if(!bTexStatsRetrievalImpossible) {
hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER));
if (hr!=D3D_OK) {
if (hr==S_FALSE) {
static int PrintedMsg=2;
if(PrintedMsg>0) {
if(dxgsg_cat.is_debug())
dxgsg_cat.debug() << " ************ texstats GetInfo() requires debug DX DLLs to be installed!! ***********\n";
ZeroMemory(&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER));
bTexStatsRetrievalImpossible=true;
}
} else {
dxgsg_cat.error() << "d3ddev->GetInfo(TEXTUREMANAGER) failed to get tex stats: result = " << ConvD3DErrorToString(hr) << endl;
return;
}
}
}
#ifdef PRINT_TEXSTATS #ifdef PRINT_TEXSTATS
{ char tmpstr1[50],tmpstr2[50],tmpstr3[50],tmpstr4[50];
#undef TICKS_PER_GETTEXINFO sprintf(tmpstr1,"%.4g",dwVidTotal/1000000.0);
#define TICKS_PER_GETTEXINFO (3*1000) sprintf(tmpstr2,"%.4g",dwVidFree/1000000.0);
static DWORD LastTickCount=0; sprintf(tmpstr3,"%.4g",dwTexTotal/1000000.0);
DWORD CurTickCount=GetTickCount(); sprintf(tmpstr4,"%.4g",dwTexFree/1000000.0);
dxgsg_cat.debug() << "\nAvailableVidMem for RenderSurfs: (megs) total: " << tmpstr1 << " free: " << tmpstr2
<< "\nAvailableVidMem for Textures: (megs) total: " << tmpstr3 << " free: " << tmpstr4 << endl;
if (CurTickCount-LastTickCount > TICKS_PER_GETTEXINFO) { if(!bTexStatsRetrievalImpossible) {
LastTickCount=CurTickCount; dxgsg_cat.spam()
HRESULT hr;
D3DDEVINFO_TEXTUREMANAGER tminfo;
ZeroMemory(&tminfo,sizeof( D3DDEVINFO_TEXTUREMANAGER));
hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,&tminfo,sizeof(D3DDEVINFO_TEXTUREMANAGER));
if (hr!=D3D_OK) {
if (hr==S_FALSE)
dxgsg_cat.error() << "GetInfo requires debug DX7 DLLs to be installed!!\n";
else dxgsg_cat.error() << "GetInfo appinfo failed : result = " << ConvD3DErrorToString(hr) << endl;
} else
dxgsg_cat.spam()
<< "\n bThrashing:\t" << tminfo.bThrashing << "\n bThrashing:\t" << tminfo.bThrashing
<< "\n NumEvicts:\t" << tminfo.dwNumEvicts << "\n NumEvicts:\t" << tminfo.dwNumEvicts
<< "\n NumVidCreates:\t" << tminfo.dwNumVidCreates << "\n NumVidCreates:\t" << tminfo.dwNumVidCreates
@ -954,19 +1012,17 @@ render_frame() {
<< "\n WorkingSetBytes:\t" << tminfo.dwWorkingSetBytes << "\n WorkingSetBytes:\t" << tminfo.dwWorkingSetBytes
<< "\n TotalManaged:\t" << tminfo.dwTotalManaged << "\n TotalManaged:\t" << tminfo.dwTotalManaged
<< "\n TotalBytes:\t" << tminfo.dwTotalBytes << "\n TotalBytes:\t" << tminfo.dwTotalBytes
<< "\n LastPri:\t" << tminfo.dwLastPri << endl; << "\n LastPri:\t" << tminfo.dwLastPri << endl;
D3DDEVINFO_TEXTURING texappinfo; D3DDEVINFO_TEXTURING texappinfo;
ZeroMemory(&texappinfo,sizeof( D3DDEVINFO_TEXTURING)); ZeroMemory(&texappinfo,sizeof(D3DDEVINFO_TEXTURING));
hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTURING,&texappinfo,sizeof(D3DDEVINFO_TEXTURING)); hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTURING,&texappinfo,sizeof(D3DDEVINFO_TEXTURING));
if (hr!=D3D_OK) { if (hr!=D3D_OK) {
if (hr==S_FALSE) dxgsg_cat.error() << "GetInfo(TEXTURING) failed : result = " << ConvD3DErrorToString(hr) << endl;
dxgsg_cat.error() << "GetInfo requires debug DX7 DLLs to be installed!!\n"; return;
else dxgsg_cat.error() << "GetInfo appinfo failed : result = " << ConvD3DErrorToString(hr) << endl; } else {
} else
dxgsg_cat.spam() dxgsg_cat.spam()
<< "\n NumLoads:\t" << texappinfo.dwNumLoads << "\n NumTexLoads:\t" << texappinfo.dwNumLoads
<< "\n ApproxBytesLoaded:\t" << texappinfo.dwApproxBytesLoaded << "\n ApproxBytesLoaded:\t" << texappinfo.dwApproxBytesLoaded
<< "\n NumPreLoads:\t" << texappinfo.dwNumPreLoads << "\n NumPreLoads:\t" << texappinfo.dwNumPreLoads
<< "\n NumSet:\t" << texappinfo.dwNumSet << "\n NumSet:\t" << texappinfo.dwNumSet
@ -976,40 +1032,28 @@ render_frame() {
<< "\n NumSetLODs:\t" << texappinfo.dwNumSetLODs << "\n NumSetLODs:\t" << texappinfo.dwNumSetLODs
<< "\n NumLocks:\t" << texappinfo.dwNumLocks << "\n NumLocks:\t" << texappinfo.dwNumLocks
<< "\n NumGetDCs:\t" << texappinfo.dwNumGetDCs << endl; << "\n NumGetDCs:\t" << texappinfo.dwNumGetDCs << endl;
} }
} }
#endif #endif
#ifdef GSG_VERBOSE #ifdef DO_PSTATS
dxgsg_cat.debug() // Tell PStats about the state of the texture memory.
<< "end frame ----------------------------------------------" << endl;
if (_texmgrmem_total_pcollector.is_active()) {
// report zero if no debug dlls, to signal this info is invalid
_texmgrmem_total_pcollector.set_level(tminfo.dwTotalBytes);
_texmgrmem_resident_pcollector.set_level(tminfo.dwWorkingSetBytes);
}
if (_total_texmem_pcollector.is_active()) {
_total_texmem_pcollector.set_level(dwTexTotal);
_used_texmem_pcollector.set_level(dwTexTotal - dwTexFree);
}
#endif
#endif #endif
} }
#ifdef DO_PSTATS
////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::report_texmgr_stats
// Access: Protected
// Description: Reports the DX texture manager's activity to PStats.
////////////////////////////////////////////////////////////////////
void DXGraphicsStateGuardian::
report_texmgr_stats() {
HRESULT hr;
D3DDEVINFO_TEXTUREMANAGER tminfo;
ZeroMemory(&tminfo, sizeof(tminfo));
hr = _d3dDevice->GetInfo(D3DDEVINFOID_TEXTUREMANAGER,
&tminfo, sizeof(tminfo));
// Quietly ignore an error in GetInfo().
if (hr == D3D_OK) {
_texmgrmem_total_pcollector.set_level(tminfo.dwTotalBytes);
_texmgrmem_resident_pcollector.set_level(tminfo.dwWorkingSetBytes);
}
}
#endif // DO_PSTATS
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: DXGraphicsStateGuardian::render_scene // Function: DXGraphicsStateGuardian::render_scene
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -66,7 +66,8 @@ INLINE ostream &operator << (ostream &out, GLenum v) {
#define RELEASE(OBJECT) if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) {(OBJECT)->Release(); (OBJECT) = NULL;} #define RELEASE(OBJECT) if(((OBJECT)!=NULL)&&(!IsBadWritePtr((OBJECT),4))) {(OBJECT)->Release(); (OBJECT) = NULL;}
#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS)
#ifdef _DEBUG
// This function now serves both to print a debug message to the // This function now serves both to print a debug message to the
// console, as well as to notify PStats about the change in texture // console, as well as to notify PStats about the change in texture
// memory. Thus, we compile it in if we are building with support for // memory. Thus, we compile it in if we are building with support for
@ -275,9 +276,7 @@ protected:
size_t draw_prim_setup(const Geom *geom) ; size_t draw_prim_setup(const Geom *geom) ;
void draw_multitri(Geom *geom, D3DPRIMITIVETYPE tri_id); void draw_multitri(Geom *geom, D3DPRIMITIVETYPE tri_id);
#ifdef DO_PSTATS
void report_texmgr_stats(); void report_texmgr_stats();
#endif
// for drawing primitives // for drawing primitives
Colorf p_color; Colorf p_color;

View File

@ -110,15 +110,14 @@ void PrintErrorMessage(DWORD msgID) {
LocalFree( pMessageBuffer ); LocalFree( pMessageBuffer );
} }
#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS)
#ifdef _DEBUG
extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *pMsg) { extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *pMsg) {
DWORD dwTotal,dwFree; DWORD dwTotal,dwFree;
HRESULT hr; HRESULT hr;
/* // These Caps bits arent allowed to be specified when calling GetAvailVidMem.
* These Caps bits arent allowed to be specified when calling GetAvailVidMem. // They don't affect surface allocation in a vram heap.
* They don't affect surface allocation in a vram heap.
*/
#define AVAILVIDMEM_BADCAPS (DDSCAPS_BACKBUFFER | \ #define AVAILVIDMEM_BADCAPS (DDSCAPS_BACKBUFFER | \
DDSCAPS_FRONTBUFFER | \ DDSCAPS_FRONTBUFFER | \
@ -139,19 +138,12 @@ extern void dbgPrintVidMem(LPDIRECTDRAW7 pDD, LPDDSCAPS2 lpddsCaps,const char *p
exit(1); exit(1);
} }
#ifdef NOTIFY_DEBUG
// Write a debug message to the console reporting the texture memory. // Write a debug message to the console reporting the texture memory.
char tmpstr[100],tmpstr2[100]; char tmpstr[100],tmpstr2[100];
sprintf(tmpstr,"%.4g",dwTotal/1000000.0); sprintf(tmpstr,"%.4g",dwTotal/1000000.0);
sprintf(tmpstr2,"%.4g",dwFree/1000000.0); sprintf(tmpstr2,"%.4g",dwFree/1000000.0);
wdxdisplay_cat.debug() << "AvailableVidMem before creating "<< pMsg << ",(megs) total: " << tmpstr << " free:" << tmpstr2 <<endl; if(wdxdisplay_cat.is_debug())
#endif wdxdisplay_cat.debug() << "AvailableVidMem before creating "<< pMsg << ",(megs) total: " << tmpstr << " free:" << tmpstr2 <<endl;
#ifdef DO_PSTATS
// Tell PStats about the state of the texture memory.
GraphicsStateGuardian::_total_texmem_pcollector.set_level(dwTotal);
GraphicsStateGuardian::_used_texmem_pcollector.set_level(dwTotal - dwFree);
#endif
} }
#endif #endif