From Farshid Lashkari, "I have a scene that makes heavy use of the StateSet::compare method and my profiler showed that a lot of time was being spent inside it. I made a small change to the method so that it performs a quick size comparison between the attribute/mode lists and bin mode before iterating through all the attributes. This made a noticeable improvement in my scene. I've attached the change."

This commit is contained in:
Robert Osfield
2013-09-30 18:16:08 +00:00
parent 76edd07195
commit 8ff77c10f9

View File

@@ -274,6 +274,32 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
if (_textureAttributeList.size()<rhs._textureAttributeList.size()) return -1;
if (_textureAttributeList.size()>rhs._textureAttributeList.size()) return 1;
if (_textureModeList.size()<rhs._textureModeList.size()) return -1;
if (_textureModeList.size()>rhs._textureModeList.size()) return 1;
if (_attributeList.size()<rhs._attributeList.size()) return -1;
if (_attributeList.size()>rhs._attributeList.size()) return 1;
if (_modeList.size()<rhs._modeList.size()) return -1;
if (_modeList.size()>rhs._modeList.size()) return 1;
if (_uniformList.size()<rhs._uniformList.size()) return -1;
if (_uniformList.size()>rhs._uniformList.size()) return 1;
// check render bin details
if ( _binMode < rhs._binMode ) return -1;
else if ( _binMode > rhs._binMode ) return 1;
if ( _binMode != INHERIT_RENDERBIN_DETAILS )
{
if ( _binNum < rhs._binNum ) return -1;
else if ( _binNum > rhs._binNum ) return 1;
if ( _binName < rhs._binName ) return -1;
else if ( _binName > rhs._binName ) return 1;
}
for(unsigned int ai=0;ai<_textureAttributeList.size();++ai)
{
const AttributeList& rhs_attributeList = _textureAttributeList[ai];
@@ -373,10 +399,6 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
// we've got here so attributes must be equal...
if (_textureModeList.size()<rhs._textureModeList.size()) return -1;
if (_textureModeList.size()>rhs._textureModeList.size()) return 1;
// check to see how the modes compare.
// first check the rest of the texture modes
for(unsigned int ti=0;ti<_textureModeList.size();++ti)
@@ -441,20 +463,6 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const
}
else if (rhs_uniform_itr == rhs._uniformList.end()) return 1;
// check render bin details
if ( _binMode < rhs._binMode ) return -1;
else if ( _binMode > rhs._binMode ) return 1;
if ( _binMode != INHERIT_RENDERBIN_DETAILS )
{
if ( _binNum < rhs._binNum ) return -1;
else if ( _binNum > rhs._binNum ) return 1;
if ( _binName < rhs._binName ) return -1;
else if ( _binName > rhs._binName ) return 1;
}
return 0;
}