driver_direct3d_profile.cpp

Go to the documentation of this file.
00001 
00006 /* Copyright, 2000 Nevrax Ltd.
00007  *
00008  * This file is part of NEVRAX NEL.
00009  * NEVRAX NEL is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2, or (at your option)
00012  * any later version.
00013 
00014  * NEVRAX NEL is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * General Public License for more details.
00018 
00019  * You should have received a copy of the GNU General Public License
00020  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00022  * MA 02111-1307, USA.
00023  */
00024 
00025 #include "stddirect3d.h"
00026 
00027 #include "driver_direct3d.h"
00028 #include "nel/misc/hierarchical_timer.h"
00029 
00030 using namespace std;
00031 using namespace NLMISC;
00032 
00033 namespace NL3D
00034 {
00035 
00036 // ***************************************************************************
00037 
00038 void CDriverD3D::profileRenderedPrimitives(CPrimitiveProfile &pIn, CPrimitiveProfile &pOut)
00039 {
00040     pIn= _PrimitiveProfileIn;
00041     pOut= _PrimitiveProfileOut;
00042 }
00043 
00044 // ***************************************************************************
00045 
00046 uint32 CDriverD3D::profileAllocatedTextureMemory()
00047 {
00048     return _AllocatedTextureMemory;
00049 }
00050 
00051 // ***************************************************************************
00052 
00053 uint32 CDriverD3D::profileSetupedMaterials() const
00054 {
00055     return _NbSetupMaterialCall;
00056 }
00057 
00058 // ***************************************************************************
00059 
00060 uint32 CDriverD3D::profileSetupedModelMatrix() const
00061 {
00062     return _NbSetupModelMatrixCall;
00063 }
00064 
00065 // ***************************************************************************
00066 
00067 void CDriverD3D::enableUsedTextureMemorySum (bool enable)
00068 {
00069     if (enable)
00070         nlinfo ("PERFORMANCE INFO: enableUsedTextureMemorySum has been set to true in CDriverD3D\n");
00071     _SumTextureMemoryUsed=enable;
00072 }
00073 
00074 // ***************************************************************************
00075 
00076 uint32 CDriverD3D::getUsedTextureMemory() const
00077 {
00078     // Sum memory used
00079     uint32 memory=0;
00080 
00081     // For each texture used
00082     set<CTextureDrvInfosD3D*>::const_iterator ite=_TextureUsed.begin();
00083     while (ite!=_TextureUsed.end())
00084     {
00085         // Get the d3d texture
00086         CTextureDrvInfosD3D*    d3dtext;
00087         d3dtext= (*ite);
00088 
00089         // Sum the memory used by this texture
00090         memory+=d3dtext->TextureMemory;
00091 
00092         // Next texture
00093         ite++;
00094     }
00095 
00096     // Return the count
00097     return memory;
00098 }
00099 
00100 // ***************************************************************************
00101 void CDriverD3D::startProfileVBHardLock()
00102 {
00103     if(_VBHardProfiling)
00104         return;
00105 
00106     // start
00107     _VBHardProfiles.clear();
00108     _VBHardProfiles.reserve(50);
00109     _VBHardProfiling= true;
00110     _CurVBHardLockCount= 0;
00111     _NumVBHardProfileFrame= 0;
00112     _VolatileVBLockTime = 0;
00113 }
00114 
00115 // ***************************************************************************
00116 
00117 void CDriverD3D::endProfileVBHardLock(std::vector<std::string> &result)
00118 {
00119     if(!_VBHardProfiling)
00120         return;
00121 
00122     // Fill infos.
00123     result.clear();
00124     result.resize(_VBHardProfiles.size() + 2);
00125     float   total= 0;
00126     for(uint i=0;i<_VBHardProfiles.size();i++)
00127     {
00128         const   uint tmpSize= 256;
00129         char    tmp[tmpSize];
00130         CVBHardProfile  &vbProf= _VBHardProfiles[i];
00131         const char  *vbName;
00132         if(vbProf.VBHard && !vbProf.VBHard->getName().empty())
00133         {
00134             vbName= vbProf.VBHard->getName().c_str();
00135         }
00136         else
00137         {
00138             vbName= "????";
00139         }
00140         // Display in ms.
00141         float   timeLock= (float)CTime::ticksToSecond(vbProf.AccumTime)*1000 / max(_NumVBHardProfileFrame,1U);
00142         smprintf(tmp, tmpSize, "%16s%c: %2.3f ms", vbName, vbProf.Change?'*':' ', timeLock );
00143         total+= timeLock;
00144 
00145         result[i]= tmp;
00146     }
00147     result[_VBHardProfiles.size()]= toString("Total: %2.3f", total);
00148 //  float   volatileVBTimeLock = (float)CTime::ticksToSecond(_VolatileVBLockTime)*1000 / max(_NumVBHardProfileFrame,1U);
00149     result[_VBHardProfiles.size() + 1]= toString("Volatile Vertex Buffer lock time = %2.3f", _VolatileVBLockTime);
00150 
00151     // clear.
00152     _VBHardProfiling= false;
00153     contReset(_VBHardProfiles);
00154 }
00155 
00156 // ***************************************************************************
00157 
00158 void CDriverD3D::appendVBHardLockProfile(NLMISC::TTicks time, CVertexBuffer *vb)
00159 {
00160     // must allocate a new place?
00161     if(_CurVBHardLockCount>=_VBHardProfiles.size())
00162     {
00163         _VBHardProfiles.resize(_VBHardProfiles.size()+1);
00164         // set the original VBHard
00165         _VBHardProfiles[_CurVBHardLockCount].VBHard= vb;
00166     }
00167 
00168     // Accumulate.
00169     _VBHardProfiles[_CurVBHardLockCount].AccumTime+= time;
00170     // if change of VBHard for this chrono place
00171     if(_VBHardProfiles[_CurVBHardLockCount].VBHard != vb)
00172     {
00173         // flag, and set new
00174         _VBHardProfiles[_CurVBHardLockCount].VBHard= vb;
00175         _VBHardProfiles[_CurVBHardLockCount].Change= true;
00176     }
00177 
00178     // next!
00179     _CurVBHardLockCount++;
00180 }
00181 
00182 // ***************************************************************************
00183 void CDriverD3D::startProfileIBLock()
00184 {
00185     if(_IBProfiling)
00186         return;
00187 
00188     // start
00189     _IBProfiles.clear();
00190     _IBProfiles.reserve(50);
00191     _IBProfiling= true;
00192     _CurIBLockCount= 0;
00193     _NumIBProfileFrame= 0;
00194     _VolatileIBLockTime = 0;
00195 }
00196 
00197 // ***************************************************************************
00198 
00199 void CDriverD3D::endProfileIBLock(std::vector<std::string> &result)
00200 {
00201     if(!_IBProfiling)
00202         return;
00203 
00204     // Fill infos.
00205     result.clear();
00206     result.resize(_IBProfiles.size() + 2);
00207     float   total= 0;
00208     for(uint i=0;i<_IBProfiles.size();i++)
00209     {
00210         const   uint tmpSize= 256;
00211         char    tmp[tmpSize];
00212         CIBProfile  &ibProf= _IBProfiles[i];
00213         const char  *ibName;
00214         if(ibProf.IB && !ibProf.IB->getName().empty())
00215         {
00216             ibName= ibProf.IB->getName().c_str();
00217         }
00218         else
00219         {
00220             ibName= "????";
00221         }
00222         // Display in ms.
00223         float   timeLock= (float)CTime::ticksToSecond(ibProf.AccumTime)*1000 / max(_NumIBProfileFrame,1U);
00224         smprintf(tmp, tmpSize, "%16s%c: %2.3f ms", ibName, ibProf.Change?'*':' ', timeLock );
00225         total+= timeLock;
00226 
00227         result[i]= tmp;
00228     }
00229     result[_IBProfiles.size()]= toString("Total: %2.3f", total);
00230     float   volatileIBTimeLock = (float)CTime::ticksToSecond(_VolatileIBLockTime)*1000 / max(_NumIBProfileFrame,1U);
00231     result[_IBProfiles.size() + 1]= toString("Volatile Index Buffer lock time = %2.3f", volatileIBTimeLock);
00232     nlwarning("IB lock time = %2.3f", total);
00233     nlwarning("Volatile IB lock time = %2.3f", volatileIBTimeLock);
00234 
00235     // clear.
00236     _IBProfiling= false;
00237     contReset(_IBProfiles);
00238 }
00239 
00240 // ***************************************************************************
00241 
00242 void CDriverD3D::appendIBLockProfile(NLMISC::TTicks time, CIndexBuffer *ib)
00243 {
00244     // must allocate a new place?
00245     if(_CurIBLockCount>=_IBProfiles.size())
00246     {
00247         _IBProfiles.resize(_IBProfiles.size()+1);
00248         _IBProfiles[_CurIBLockCount].IB= ib;
00249     }
00250 
00251     // Accumulate.
00252     _IBProfiles[_CurIBLockCount].AccumTime+= time;
00253     // if change of VBHard for this chrono place
00254     if(_IBProfiles[_CurIBLockCount].IB != ib)
00255     {
00256         // flag, and set new
00257         _IBProfiles[_CurIBLockCount].IB= ib;
00258         _IBProfiles[_CurIBLockCount].Change= true;
00259     }
00260 
00261     // next!
00262     _CurIBLockCount++;
00263 }
00264 
00265 // ***************************************************************************
00266 void CDriverD3D::profileVBHardAllocation(std::vector<std::string> &result)
00267 {
00268     result.clear();
00269     result.reserve(1000);
00270     result.push_back(toString("Memory Allocated: %4d Ko in AGP / %4d Ko in VRAM",
00271         getAvailableVertexAGPMemory()/1000, getAvailableVertexVRAMMemory()/1000 ));
00272     result.push_back(toString("Num VBHard: %d", _VertexBufferHardSet.size()));
00273 
00274     uint    totalMemUsed= 0;
00275     set<CVBDrvInfosD3D*>::iterator  it;
00276     for(it= _VertexBufferHardSet.begin(); it!=_VertexBufferHardSet.end(); it++)
00277     {
00278         CVBDrvInfosD3D  *vbHard= *it;
00279         if(vbHard)
00280         {
00281             uint    vSize= vbHard->VertexBufferPtr->getVertexSize();
00282             uint    numVerts= vbHard->VertexBufferPtr->getNumVertices();
00283             totalMemUsed+= vSize*numVerts;
00284         }
00285     }
00286     result.push_back(toString("Mem Used: %4d Ko", totalMemUsed/1000) );
00287 
00288     for(it= _VertexBufferHardSet.begin(); it!=_VertexBufferHardSet.end(); it++)
00289     {
00290         CVBDrvInfosD3D  *vbHard= *it;
00291         if(vbHard)
00292         {
00293             uint    vSize= vbHard->VertexBufferPtr->getVertexSize();
00294             uint    numVerts= vbHard->VertexBufferPtr->getNumVertices();
00295             result.push_back(toString("  %16s: %4d ko (format: %d / numVerts: %d)",
00296                 vbHard->VertexBufferPtr->getName().c_str(), vSize*numVerts/1000, vSize, numVerts ));
00297         }
00298     }
00299 }
00300 
00301 // ***************************************************************************
00302 void CDriverD3D::profileIBAllocation(std::vector<std::string> &result)
00303 {
00304     result.clear();
00305     result.reserve(1000);
00306     result.push_back(toString("Memory Allocated: %4d Ko in AGP / %4d Ko in VRAM",
00307         getAvailableVertexAGPMemory()/1000, getAvailableVertexVRAMMemory()/1000 ));
00308     result.push_back(toString("Num Index buffers : %d", _IBDrvInfos.size()));
00309 
00310     uint    totalMemUsed= 0;
00311     for(TIBDrvInfoPtrList::iterator it = _IBDrvInfos.begin(); it != _IBDrvInfos.end(); ++it)
00312     {
00313         CIBDrvInfosD3D  *ib =  NLMISC::safe_cast<CIBDrvInfosD3D *>(*it);
00314         if(ib)
00315         {
00316             uint    numIndex= ib->IndexBufferPtr->getNumIndexes();
00317             totalMemUsed+= sizeof(uint32)*numIndex;
00318         }
00319     }
00320     result.push_back(toString("Mem Used: %4d Ko", totalMemUsed/1000) );
00321 
00322     for(TIBDrvInfoPtrList::iterator it = _IBDrvInfos.begin(); it != _IBDrvInfos.end(); ++it)
00323     {
00324         CIBDrvInfosD3D  *ib =  NLMISC::safe_cast<CIBDrvInfosD3D *>(*it);
00325         if(ib)
00326         {
00327             uint    numIndex= ib->IndexBufferPtr->getNumIndexes();
00328             result.push_back(toString("  %16s: %4d ko ",
00329                 ib->IndexBufferPtr->getName().c_str(), sizeof(uint32) * numIndex));
00330         }
00331     }
00332 }
00333 
00334 // ***************************************************************************
00335 
00336 void CDriverD3D::startBench (bool wantStandardDeviation, bool quick, bool reset)
00337 {
00338     CHTimer::startBench (wantStandardDeviation, quick, reset);
00339 }
00340 
00341 // ***************************************************************************
00342 
00343 void CDriverD3D::endBench ()
00344 {
00345     CHTimer::endBench ();
00346 }
00347 
00348 // ***************************************************************************
00349 
00350 void CDriverD3D::displayBench (class NLMISC::CLog *log)
00351 {
00352     // diplay
00353     CHTimer::displayHierarchicalByExecutionPathSorted(log, CHTimer::TotalTime, true, 48, 2);
00354     CHTimer::displayHierarchical(log, true, 48, 2);
00355     CHTimer::displayByExecutionPath(log, CHTimer::TotalTime);
00356     CHTimer::display(log, CHTimer::TotalTime);
00357     CHTimer::display(log, CHTimer::TotalTimeWithoutSons);
00358 }
00359 
00360 // ***************************************************************************
00361 
00362 } // NL3D

Generated on Thu Jan 7 08:26:25 2010 for NeL by  doxygen 1.6.1