Skip to content

Commit

Permalink
Main: VertexCacheProfiler - add average cache miss ratio metric
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 16, 2024
1 parent 221e3f2 commit 3b430d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions OgreMain/include/OgreVertexIndexData.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ namespace Ogre {
{
public:
VertexCacheProfiler(unsigned int cachesize = 16)
: size ( cachesize ), tail (0), buffersize (0), hit (0), miss (0)
: size ( cachesize ), tail (0), buffersize (0), hit (0), miss (0), triangles(0)
{
cache = OGRE_ALLOC_T(uint32, size, MEMCATEGORY_GEOMETRY);
}
Expand All @@ -288,18 +288,25 @@ namespace Ogre {
}

void profile(const HardwareIndexBufferSharedPtr& indexBuffer);
void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; }
void reset() { hit = 0; miss = 0; tail = 0; buffersize = 0; triangles = 0; }
void flush() { tail = 0; buffersize = 0; }

unsigned int getHits() { return hit; }
unsigned int getMisses() { return miss; }
unsigned int getSize() { return size; }

/** Get the average cache miss ratio
@return ratio of vertex cache misses to the triangle count (0.5 - 3.0)
*/
float getAvgCacheMissRatio() { return (float)miss / triangles; }
private:
unsigned int size;
uint32 *cache;

unsigned int tail, buffersize;
unsigned int hit, miss;
uint32 triangles;

bool inCache(unsigned int index);
};
Expand Down
2 changes: 2 additions & 0 deletions OgreMain/src/OgreVertexIndexData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ namespace Ogre {
}

indexBuffer->unlock();

triangles += indexBuffer->getNumIndexes()/3;
}

//-----------------------------------------------------------------------
Expand Down

0 comments on commit 3b430d0

Please sign in to comment.